cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject git commit: CAY-1964 | Fix convertAdditionalDataMaps() in CayenneGeneratorMojo.java
Date Thu, 30 Oct 2014 15:17:52 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 5be9a2eb4 -> 5b6b60c9b


CAY-1964 | Fix convertAdditionalDataMaps() in CayenneGeneratorMojo.java


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/5b6b60c9
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/5b6b60c9
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/5b6b60c9

Branch: refs/heads/master
Commit: 5b6b60c9b7ae8193457e93739a307416cd338db8
Parents: 5be9a2e
Author: Savva Kolbechev <s.kolbachev@gmail.com>
Authored: Thu Oct 30 16:01:29 2014 +0300
Committer: Savva Kolbechev <s.kolbachev@gmail.com>
Committed: Thu Oct 30 16:01:29 2014 +0300

----------------------------------------------------------------------
 .../cayenne/tools/CayenneGeneratorMojo.java     | 25 +++++++++++++-------
 .../cayenne/tools/CayenneGeneratorMojoTest.java | 10 ++++++--
 .../test/resources/cgen/cayenne-testDomain.xml  |  1 +
 .../test/resources/cgen/project-to-test/pom.xml |  1 +
 .../resources/cgen/testAdditionalMap.map.xml    | 18 ++++++++++++++
 .../test/resources/cgen/testDomainMap.map.xml   |  5 ++++
 6 files changed, 49 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/5b6b60c9/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
b/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
index 12b4468..7ed907a 100644
--- a/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
+++ b/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
@@ -19,8 +19,6 @@
 
 package org.apache.cayenne.tools;
 
-import java.io.File;
-
 import org.apache.cayenne.gen.ClassGenerationAction;
 import org.apache.cayenne.gen.ClientClassGenerationAction;
 import org.apache.cayenne.map.DataMap;
@@ -29,6 +27,9 @@ import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 
+import java.io.File;
+import java.io.FilenameFilter;
+
 /**
  * Maven mojo to perform class generation from data map. This class is an Maven
  * adapter to DefaultClassGenerator class.
@@ -238,15 +239,21 @@ public class CayenneGeneratorMojo extends AbstractMojo {
 
 		if (!additionalMaps.isDirectory()) {
 			throw new MojoFailureException(
-					"'additionalMaps' must be a directory containing only datamap files.");
+					"'additionalMaps' must be a directory.");
 		}
 
-		String[] maps = additionalMaps.list();
-		File[] dataMaps = new File[maps.length];
-		for (int i = 0; i < maps.length; i++) {
-			dataMaps[i] = new File(maps[i]);
-		}
-		return dataMaps;
+        FilenameFilter mapFilter = new FilenameFilter() {
+            @Override
+            public boolean accept(File dir, String name) {
+                if (name != null &&
+                        name.toLowerCase().endsWith(".map.xml")) {
+                    return true;
+                } else {
+                    return false;
+                }
+            }
+        };
+        return additionalMaps.listFiles(mapFilter);
 	}
 
 	/**

http://git-wip-us.apache.org/repos/asf/cayenne/blob/5b6b60c9/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
b/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
index 839b5de..ab9ffdf 100644
--- a/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
+++ b/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
@@ -18,10 +18,11 @@
  ****************************************************************/
 package org.apache.cayenne.tools;
 
-import java.io.File;
-
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 
+import java.io.File;
+import java.nio.file.Files;
+
 public class CayenneGeneratorMojoTest extends AbstractMojoTestCase {
 
     public void testCgenExecution() throws Exception {
@@ -68,5 +69,10 @@ public class CayenneGeneratorMojoTest extends AbstractMojoTestCase {
         assertFalse(superExcludedEntity.exists());
         assertFalse(excludedEntity.exists());
 
+        String content = new String(Files.readAllBytes(superTestEntity.toPath()));
+        assertTrue(content.contains("public static final Property<List<TestRelEntity>>
ADDITIONAL_REL = new Property<List<TestRelEntity>>(\"additionalRel\");"));
+        assertTrue(content.contains("public void addToAdditionalRel(TestRelEntity obj)"));
+        assertTrue(content.contains("public void removeFromAdditionalRel(TestRelEntity obj)"));
+
     }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/5b6b60c9/plugins/maven-cayenne-plugin/src/test/resources/cgen/cayenne-testDomain.xml
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/test/resources/cgen/cayenne-testDomain.xml b/plugins/maven-cayenne-plugin/src/test/resources/cgen/cayenne-testDomain.xml
index c47fa5e..3f63c14 100644
--- a/plugins/maven-cayenne-plugin/src/test/resources/cgen/cayenne-testDomain.xml
+++ b/plugins/maven-cayenne-plugin/src/test/resources/cgen/cayenne-testDomain.xml
@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <domain project-version="6">
 	<map name="testDomainMap"/>
+    <map name="testAdditionalMap"/>
 </domain>

http://git-wip-us.apache.org/repos/asf/cayenne/blob/5b6b60c9/plugins/maven-cayenne-plugin/src/test/resources/cgen/project-to-test/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/test/resources/cgen/project-to-test/pom.xml
b/plugins/maven-cayenne-plugin/src/test/resources/cgen/project-to-test/pom.xml
index 9646937..41d545c 100644
--- a/plugins/maven-cayenne-plugin/src/test/resources/cgen/project-to-test/pom.xml
+++ b/plugins/maven-cayenne-plugin/src/test/resources/cgen/project-to-test/pom.xml
@@ -39,6 +39,7 @@
 				<configuration>
 					<map>src/test/resources/cgen/testDomainMap.map.xml</map>
 					<destDir>target/cayenneGeneratedClasses</destDir>
+                    <additionalMaps>src/test/resources/cgen/</additionalMaps>
 					<outputPattern>*.txt</outputPattern>
 					<makePairs>true</makePairs>
 					<usePkgPath>true</usePkgPath>

http://git-wip-us.apache.org/repos/asf/cayenne/blob/5b6b60c9/plugins/maven-cayenne-plugin/src/test/resources/cgen/testAdditionalMap.map.xml
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/test/resources/cgen/testAdditionalMap.map.xml
b/plugins/maven-cayenne-plugin/src/test/resources/cgen/testAdditionalMap.map.xml
new file mode 100644
index 0000000..f9a80fb
--- /dev/null
+++ b/plugins/maven-cayenne-plugin/src/test/resources/cgen/testAdditionalMap.map.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap http://cayenne.apache.org/schema/3.0/modelMap.xsd"
+          project-version="6">
+    <property name="defaultPackage" value="pack"/>
+    <db-entity name="TestRelEntity">
+        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+        <db-attribute name="NAME" type="VARCHAR" length="200"/>
+    </db-entity>
+    <obj-entity name="TestRelEntity" className="pack.TestRelEntity" dbEntityName="TestRelEntity">
+        <obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
+    </obj-entity>
+    <db-relationship name="additionalRel" source="TestRelEntity" target="TestEntity" toMany="false">
+        <db-attribute-pair source="ID" target="TestRelEntity_ID"/>
+    </db-relationship>
+    <obj-relationship name="additionalRel" source="TestRelEntity" target="TestEntity"
deleteRule="Nullify" db-relationship-path="additionalRel"/>
+</data-map>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/5b6b60c9/plugins/maven-cayenne-plugin/src/test/resources/cgen/testDomainMap.map.xml
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/test/resources/cgen/testDomainMap.map.xml b/plugins/maven-cayenne-plugin/src/test/resources/cgen/testDomainMap.map.xml
index 922bd0f..d0ff3f5 100644
--- a/plugins/maven-cayenne-plugin/src/test/resources/cgen/testDomainMap.map.xml
+++ b/plugins/maven-cayenne-plugin/src/test/resources/cgen/testDomainMap.map.xml
@@ -14,6 +14,7 @@
 	<db-entity name="TestEntity">
 		<db-attribute name="id" type="BIGINT" isPrimaryKey="true" isMandatory="true"/>
 		<db-attribute name="testAttr" type="VARCHAR" length="255"/>
+        <db-attribute name="TestRelEntity_ID" type="INTEGER"/>
 	</db-entity>
 	<db-entity name="TestExcludedEntity">
 		<db-attribute name="id" type="BIGINT" isPrimaryKey="true" isMandatory="true"/>
@@ -35,6 +36,10 @@
 	<db-relationship name="parentRel" source="TestEntity" target="TestEntity" toMany="false">
 		<db-attribute-pair source="id" target="id"/>
 	</db-relationship>
+    <db-relationship name="additionalRel" source="TestEntity" target="TestRelEntity" toMany="true">
+        <db-attribute-pair source="TestRelEntity_ID" target="ID"/>
+    </db-relationship>
 	<obj-relationship name="childrenRel" source="TestEntity" target="TestEntity" deleteRule="Deny"
db-relationship-path="childrenRel"/>
 	<obj-relationship name="parentRel" source="TestEntity" target="TestEntity" deleteRule="Nullify"
db-relationship-path="parentRel"/>
+    <obj-relationship name="additionalRel" source="TestEntity" target="TestRelEntity"
deleteRule="Deny" db-relationship-path="additionalRel"/>
 </data-map>


Mime
View raw message