You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2018/11/14 14:27:55 UTC

[24/32] cayenne git commit: Add replacement to datamap generation mode.

Add replacement to datamap generation mode.


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

Branch: refs/heads/master
Commit: ac6819f330415205cb6ccacc6bdf3013937ef13e
Parents: 3ae4973
Author: Arseni Bulatski <an...@gmail.com>
Authored: Mon Nov 12 15:58:58 2018 +0300
Committer: Arseni Bulatski <an...@gmail.com>
Committed: Mon Nov 12 16:01:26 2018 +0300

----------------------------------------------------------------------
 UPGRADE.txt                                     |  4 --
 .../cayenne/tools/CayenneGeneratorTask.java     | 22 +++++---
 .../cayenne/tools/CgenWithConfigTest.java       | 38 +++++++++++++-
 .../java/org/apache/cayenne/tools/CgenTask.java | 23 ++++++---
 .../org/apache/cayenne/tools/CgenTaskIT.java    | 35 +++++++++++++
 .../tools/cgen_replaceDatamapMode.gradle        | 31 ++++++++++++
 .../cayenne/tools/CayenneGeneratorMojo.java     | 22 +++++---
 .../cayenne/tools/CayenneGeneratorMojoTest.java | 26 +++++++++-
 .../cgen/project-to-test/datamap-and-pom.xml    |  1 -
 .../project-to-test/replaceDatamapMode-pom.xml  | 53 ++++++++++++++++++++
 10 files changed, 227 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/ac6819f3/UPGRADE.txt
----------------------------------------------------------------------
diff --git a/UPGRADE.txt b/UPGRADE.txt
index 83bcc5a..bd660d3 100644
--- a/UPGRADE.txt
+++ b/UPGRADE.txt
@@ -4,10 +4,6 @@ Apache Cayenne Upgrade Information
 IMPORTANT: be sure to read all notes for the intermediate releases between your
            current release and the release you are upgrading to.
 -------------------------------------------------------------------------------
-UPGRADING TO 4.1.M3
-
-* Per CAY-2493 'datamap' generation mode in cgen replaced with 'all' generation mode with
-      <excludeEntities>*</excludeEntities> and <excludeEmbeddables>*</excludeEmbeddables> patterns.
 
 UPGRADING TO 4.1.M2
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/ac6819f3/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
----------------------------------------------------------------------
diff --git a/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java b/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
index 6291a6d..8d5a151 100644
--- a/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
+++ b/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
@@ -24,6 +24,7 @@ import org.apache.cayenne.dbsync.filter.NamePatternMatcher;
 import org.apache.cayenne.dbsync.reverse.configuration.ToolsModule;
 import org.apache.cayenne.di.DIBootstrap;
 import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.gen.ArtifactsGenerationMode;
 import org.apache.cayenne.gen.CgenConfiguration;
 import org.apache.cayenne.gen.CgenModule;
 import org.apache.cayenne.gen.ClassGenerationAction;
@@ -108,17 +109,16 @@ public class CayenneGeneratorTask extends CayenneTask {
 
         loadAction.setMainDataMapFile(map);
         loadAction.setAdditionalDataMapFiles(additionalMaps);
-
-        CayenneGeneratorEntityFilterAction filterEntityAction = new CayenneGeneratorEntityFilterAction();
-        filterEntityAction.setNameFilter(NamePatternMatcher.build(logger, includeEntitiesPattern, excludeEntitiesPattern));
-
-        CayenneGeneratorEmbeddableFilterAction filterEmbeddableAction = new CayenneGeneratorEmbeddableFilterAction();
-        filterEmbeddableAction.setNameFilter(NamePatternMatcher.build(logger, null, excludeEmbeddablesPattern));
         try {
 
             DataMap dataMap = loadAction.getMainDataMap();
 
             ClassGenerationAction generatorAction = createGenerator(dataMap);
+            CayenneGeneratorEntityFilterAction filterEntityAction = new CayenneGeneratorEntityFilterAction();
+            filterEntityAction.setNameFilter(NamePatternMatcher.build(logger, includeEntitiesPattern, excludeEntitiesPattern));
+
+            CayenneGeneratorEmbeddableFilterAction filterEmbeddableAction = new CayenneGeneratorEmbeddableFilterAction();
+            filterEmbeddableAction.setNameFilter(NamePatternMatcher.build(logger, null, excludeEmbeddablesPattern));
             filterEntityAction.setClient(generatorAction.getCgenConfiguration().isClient());
             generatorAction.setLogger(logger);
             if(force) {
@@ -177,6 +177,9 @@ public class CayenneGeneratorTask extends CayenneTask {
         cgenConfiguration.setRelPath(destDir != null ? destDir.toPath() : cgenConfiguration.getRelPath());
         cgenConfiguration.setEncoding(encoding != null ? encoding : cgenConfiguration.getEncoding());
         cgenConfiguration.setMakePairs(makepairs != null ? makepairs : cgenConfiguration.isMakePairs());
+        if(mode != null && mode.equals("datamap")) {
+            replaceDatamapGenerationMode();
+        }
         cgenConfiguration.setArtifactsGenerationMode(mode != null ? mode : cgenConfiguration.getArtifactsGenerationMode());
         cgenConfiguration.setOutputPattern(outputPattern != null ? outputPattern : cgenConfiguration.getOutputPattern());
         cgenConfiguration.setOverwrite(overwrite != null ? overwrite : cgenConfiguration.isOverwrite());
@@ -205,6 +208,13 @@ public class CayenneGeneratorTask extends CayenneTask {
         return cgenConfiguration;
     }
 
+    private void replaceDatamapGenerationMode() {
+        this.mode = ArtifactsGenerationMode.ALL.getLabel();
+        this.excludeEntitiesPattern = "*";
+        this.excludeEmbeddablesPattern = "*";
+        this.includeEntitiesPattern = "";
+    }
+
     /**
      * Validates attributes that are not related to internal DefaultClassGenerator. Throws
      * BuildException if attributes are invalid.

http://git-wip-us.apache.org/repos/asf/cayenne/blob/ac6819f3/cayenne-ant/src/test/java/org/apache/cayenne/tools/CgenWithConfigTest.java
----------------------------------------------------------------------
diff --git a/cayenne-ant/src/test/java/org/apache/cayenne/tools/CgenWithConfigTest.java b/cayenne-ant/src/test/java/org/apache/cayenne/tools/CgenWithConfigTest.java
index b51a1e0..ce8fd10 100644
--- a/cayenne-ant/src/test/java/org/apache/cayenne/tools/CgenWithConfigTest.java
+++ b/cayenne-ant/src/test/java/org/apache/cayenne/tools/CgenWithConfigTest.java
@@ -79,7 +79,7 @@ public class CgenWithConfigTest {
         File notIncludedEntity = new File(mapDir, "ObjEntity.txt");
         assertFalse(notIncludedEntity.exists());
 
-        File notIncludeSuperDatamap = new File("_Antmap_cgen_xml.txt");
+        File notIncludeSuperDatamap = new File(mapDir, convertPath("auto/_Antmap_cgen_xml.txt"));
         assertFalse(notIncludeSuperDatamap.exists());
     }
 
@@ -111,13 +111,47 @@ public class CgenWithConfigTest {
         File notIncludedEntity = new File(mapDir, "ObjEntity1.txt");
         assertFalse(notIncludedEntity.exists());
 
-        File notIncludeSuperDatamap = new File("_Antmap_cgen_xml.txt");
+        File notIncludeSuperDatamap = new File(mapDir, convertPath("_Antmap_cgen_xml.txt"));
         assertFalse(notIncludeSuperDatamap.exists());
 
         File notIncludedSuperEntity = new File(mapDir, convertPath("_ObjEntity.txt"));
         assertFalse(notIncludedSuperEntity.exists());
     }
 
+    @Test
+    public void testReplaceDatamapMode() {
+        File mapDir = new File(baseDir, "cgenReplaceMode");
+        assertTrue(mapDir.mkdirs());
+
+        task.setDestDir(mapDir);
+        task.setMap(map);
+        task.setMode("datamap");
+        task.setMakepairs(true);
+        task.setOutputPattern("*.txt");
+
+        // run task
+        task.execute();
+
+        // check results
+        File notIncludedEntity = new File(mapDir, convertPath("ObjEntity.txt"));
+        assertFalse(notIncludedEntity.isFile());
+
+        File notIncludedEmbeddable = new File(mapDir, convertPath("Embeddable.txt"));
+        assertFalse(notIncludedEmbeddable.isFile());
+
+        File datamap = new File(mapDir, convertPath("Antmap_cgen_xml.txt"));
+        assertTrue(datamap.exists());
+
+        File notIncludedEntity1 = new File(mapDir, "ObjEntity1.txt");
+        assertFalse(notIncludedEntity1.exists());
+
+        File includeSuperDatamap = new File(mapDir, convertPath("auto/_Antmap_cgen_xml.txt"));
+        assertTrue(includeSuperDatamap.exists());
+
+        File notIncludedSuperEntity = new File(mapDir, convertPath("auto/_ObjEntity.txt"));
+        assertFalse(notIncludedSuperEntity.exists());
+    }
+
     private String convertPath(String unixPath) {
         return unixPath.replace('/', File.separatorChar);
     }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/ac6819f3/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/CgenTask.java
----------------------------------------------------------------------
diff --git a/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/CgenTask.java b/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/CgenTask.java
index 0e63c53..818b592 100644
--- a/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/CgenTask.java
+++ b/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/CgenTask.java
@@ -31,6 +31,7 @@ import org.apache.cayenne.dbsync.filter.NamePatternMatcher;
 import org.apache.cayenne.dbsync.reverse.configuration.ToolsModule;
 import org.apache.cayenne.di.DIBootstrap;
 import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.gen.ArtifactsGenerationMode;
 import org.apache.cayenne.gen.CgenConfiguration;
 import org.apache.cayenne.gen.CgenModule;
 import org.apache.cayenne.gen.ClassGenerationAction;
@@ -166,18 +167,16 @@ public class CgenTask extends BaseCayenneTask {
 
         CayenneGeneratorMapLoaderAction loaderAction = new CayenneGeneratorMapLoaderAction(injector);
         loaderAction.setMainDataMapFile(dataMapFile);
-
-        CayenneGeneratorEntityFilterAction filterEntityAction = new CayenneGeneratorEntityFilterAction();
-        filterEntityAction.setNameFilter(NamePatternMatcher.build(getLogger(), includeEntities, excludeEntities));
-
-        CayenneGeneratorEmbeddableFilterAction filterEmbeddableAction = new CayenneGeneratorEmbeddableFilterAction();
-        filterEmbeddableAction.setNameFilter(NamePatternMatcher.build(getLogger(), null, excludeEmbeddables));
-
         try {
             loaderAction.setAdditionalDataMapFiles(convertAdditionalDataMaps());
 
             DataMap dataMap = loaderAction.getMainDataMap();
             ClassGenerationAction generator = this.createGenerator(dataMap);
+            CayenneGeneratorEntityFilterAction filterEntityAction = new CayenneGeneratorEntityFilterAction();
+            filterEntityAction.setNameFilter(NamePatternMatcher.build(getLogger(), includeEntities, excludeEntities));
+
+            CayenneGeneratorEmbeddableFilterAction filterEmbeddableAction = new CayenneGeneratorEmbeddableFilterAction();
+            filterEmbeddableAction.setNameFilter(NamePatternMatcher.build(getLogger(), null, excludeEmbeddables));
             filterEntityAction.setClient(generator.getCgenConfiguration().isClient());
             generator.setLogger(getLogger());
 
@@ -241,6 +240,9 @@ public class CgenTask extends BaseCayenneTask {
         cgenConfiguration.setRelPath(getDestDirFile() != null ? getDestDirFile().toPath() : cgenConfiguration.getRelPath());
         cgenConfiguration.setEncoding(encoding != null ? encoding : cgenConfiguration.getEncoding());
         cgenConfiguration.setMakePairs(makePairs != null ? makePairs : cgenConfiguration.isMakePairs());
+        if(mode != null && mode.equals("datamap")) {
+            replaceDatamapGenerationMode();
+        }
         cgenConfiguration.setArtifactsGenerationMode(mode != null ? mode : cgenConfiguration.getArtifactsGenerationMode());
         cgenConfiguration.setOutputPattern(outputPattern != null ? outputPattern : cgenConfiguration.getOutputPattern());
         cgenConfiguration.setOverwrite(overwrite != null ? overwrite : cgenConfiguration.isOverwrite());
@@ -269,6 +271,13 @@ public class CgenTask extends BaseCayenneTask {
         return cgenConfiguration;
     }
 
+    private void replaceDatamapGenerationMode() {
+        this.mode = ArtifactsGenerationMode.ALL.getLabel();
+        this.excludeEntities = "*";
+        this.excludeEmbeddables = "*";
+        this.includeEntities = "";
+    }
+
     private boolean hasConfig() {
         return destDir != null || destDirName != null || encoding != null || client != null || excludeEntities != null || excludeEmbeddables != null || includeEntities != null ||
                 makePairs != null || mode != null || outputPattern != null || overwrite != null || superPkg != null ||

http://git-wip-us.apache.org/repos/asf/cayenne/blob/ac6819f3/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/CgenTaskIT.java
----------------------------------------------------------------------
diff --git a/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/CgenTaskIT.java b/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/CgenTaskIT.java
index c3879ac..9758e51 100644
--- a/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/CgenTaskIT.java
+++ b/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/CgenTaskIT.java
@@ -146,4 +146,39 @@ public class CgenTaskIT extends BaseTaskIT {
 
         assertEquals(TaskOutcome.SUCCESS, result.task(":cgen").getOutcome());
     }
+
+    @Test
+    public void testReplaceDatamapMode() throws Exception {
+        GradleRunner runner = createRunner(
+                "cgen_replaceDatamapMode",
+                "cgen",
+                "-PdataMap=cgenMap.map.xml"
+        );
+
+        BuildResult result = runner.forwardOutput().build();
+
+        String generatedDirectoryPath = projectDir.getAbsolutePath() + "/customDirectory/";
+
+        String notIncludedEntity = generatedDirectoryPath + "ObjEntity.txt";
+        Path generatedNotIncludedEntity = Paths.get(notIncludedEntity);
+        assertFalse(Files.exists(generatedNotIncludedEntity));
+
+        String notIncludedEntity1 = generatedDirectoryPath + "ObjEntity1.txt";
+        Path generatedNotIncludedEntity1 = Paths.get(notIncludedEntity1);
+        assertFalse(Files.exists(generatedNotIncludedEntity1));
+
+        String notIncludedEmbeddable = generatedDirectoryPath + "Embeddable.txt";
+        Path generatedNotIncludedEmbeddable = Paths.get(notIncludedEmbeddable);
+        assertFalse(Files.exists(generatedNotIncludedEmbeddable));
+
+        String includedDataMap = generatedDirectoryPath + "CgenMap.txt";
+        Path generatedIncludedDataMap = Paths.get(includedDataMap);
+        assertTrue(Files.exists(generatedIncludedDataMap));
+
+        String includedSuperDataMap = generatedDirectoryPath + "auto/_CgenMap.txt";
+        Path generatedIncludedSuperDataMap = Paths.get(includedSuperDataMap);
+        assertTrue(Files.exists(generatedIncludedSuperDataMap));
+
+        assertEquals(TaskOutcome.SUCCESS, result.task(":cgen").getOutcome());
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/ac6819f3/cayenne-gradle-plugin/src/test/resources/org/apache/cayenne/tools/cgen_replaceDatamapMode.gradle
----------------------------------------------------------------------
diff --git a/cayenne-gradle-plugin/src/test/resources/org/apache/cayenne/tools/cgen_replaceDatamapMode.gradle b/cayenne-gradle-plugin/src/test/resources/org/apache/cayenne/tools/cgen_replaceDatamapMode.gradle
new file mode 100644
index 0000000..6486a95
--- /dev/null
+++ b/cayenne-gradle-plugin/src/test/resources/org/apache/cayenne/tools/cgen_replaceDatamapMode.gradle
@@ -0,0 +1,31 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+plugins {
+    id 'org.apache.cayenne'
+}
+
+cgen {
+    map dataMap
+    destDir = './customDirectory'
+    makePairs true
+    outputPattern = '*.txt'
+    overwrite = false
+    mode = "datamap"
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/ac6819f3/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java b/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
index 647f363..f3abbe5 100644
--- a/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
+++ b/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
@@ -24,6 +24,7 @@ import org.apache.cayenne.dbsync.filter.NamePatternMatcher;
 import org.apache.cayenne.dbsync.reverse.configuration.ToolsModule;
 import org.apache.cayenne.di.DIBootstrap;
 import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.gen.ArtifactsGenerationMode;
 import org.apache.cayenne.gen.CgenConfiguration;
 import org.apache.cayenne.gen.CgenModule;
 import org.apache.cayenne.gen.ClassGenerationAction;
@@ -241,17 +242,16 @@ public class CayenneGeneratorMojo extends AbstractMojo {
 		CayenneGeneratorMapLoaderAction loaderAction = new CayenneGeneratorMapLoaderAction(injector);
 		loaderAction.setMainDataMapFile(map);
 
-		CayenneGeneratorEntityFilterAction filterEntityAction = new CayenneGeneratorEntityFilterAction();
-		filterEntityAction.setNameFilter(NamePatternMatcher.build(logger, includeEntities, excludeEntities));
-
-		CayenneGeneratorEmbeddableFilterAction filterEmbeddableAction = new CayenneGeneratorEmbeddableFilterAction();
-		filterEmbeddableAction.setNameFilter(NamePatternMatcher.build(logger, null, excludeEmbeddables));
-
 		try {
 			loaderAction.setAdditionalDataMapFiles(convertAdditionalDataMaps());
 
 			DataMap dataMap = loaderAction.getMainDataMap();
 			ClassGenerationAction generator = createGenerator(dataMap);
+			CayenneGeneratorEntityFilterAction filterEntityAction = new CayenneGeneratorEntityFilterAction();
+			filterEntityAction.setNameFilter(NamePatternMatcher.build(logger, includeEntities, excludeEntities));
+
+			CayenneGeneratorEmbeddableFilterAction filterEmbeddableAction = new CayenneGeneratorEmbeddableFilterAction();
+			filterEmbeddableAction.setNameFilter(NamePatternMatcher.build(logger, null, excludeEmbeddables));
 			filterEntityAction.setClient(generator.getCgenConfiguration().isClient());
 			generator.setLogger(logger);
 
@@ -333,6 +333,9 @@ public class CayenneGeneratorMojo extends AbstractMojo {
 		cgenConfiguration.setRelPath(destDir != null ? destDir.getPath() : defaultDir.getPath());
 		cgenConfiguration.setEncoding(encoding != null ? encoding : cgenConfiguration.getEncoding());
 		cgenConfiguration.setMakePairs(makePairs != null ? makePairs : cgenConfiguration.isMakePairs());
+		if(mode != null && mode.equals("datamap")) {
+			replaceDatamapGenerationMode();
+		}
 		cgenConfiguration.setArtifactsGenerationMode(mode != null ? mode : cgenConfiguration.getArtifactsGenerationMode());
 		cgenConfiguration.setOutputPattern(outputPattern != null ? outputPattern : cgenConfiguration.getOutputPattern());
 		cgenConfiguration.setOverwrite(overwrite != null ? overwrite : cgenConfiguration.isOverwrite());
@@ -360,4 +363,11 @@ public class CayenneGeneratorMojo extends AbstractMojo {
 		}
 		return cgenConfiguration;
 	}
+
+	private void replaceDatamapGenerationMode() {
+		this.mode = ArtifactsGenerationMode.ALL.getLabel();
+		this.excludeEntities = "*";
+		this.excludeEmbeddables = "*";
+		this.includeEntities = "";
+	}
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/ac6819f3/maven-plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
----------------------------------------------------------------------
diff --git a/maven-plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java b/maven-plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
index 8454c32..ef1e1c9 100644
--- a/maven-plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
+++ b/maven-plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
@@ -108,9 +108,31 @@ public class CayenneGeneratorMojoTest extends AbstractMojoTestCase {
 
         File objEntity = new File("target/resultClasses/ObjEntity.txt");
         assertFalse(objEntity.exists());
-        File superObjEntity1 = new File("target/resultClasses/superPkg/_ObjEntity.txt");
+        File superObjEntity1 = new File("target/resultClasses/auto/_ObjEntity.txt");
         assertFalse(superObjEntity1.exists());
-        File superDataMap = new File("target/resultClasses/superPkg/_TestCgen.txt");
+        File superDataMap = new File("target/resultClasses/auto/_TestCgen.txt");
         assertFalse(superDataMap.exists());
     }
+
+    public void testDatamapModeReplace() throws Exception {
+        File pom = getTestFile("src/test/resources/cgen/project-to-test/replaceDatamapMode-pom.xml");
+        assertNotNull(pom);
+        assertTrue(pom.exists());
+
+        CayenneGeneratorMojo myMojo = (CayenneGeneratorMojo) lookupMojo("cgen", pom);
+        assertNotNull(myMojo);
+        myMojo.execute();
+
+        File objEntity1 = new File("target/testForMode/ObjEntity1.txt");
+        assertFalse(objEntity1.exists());
+        File embeddable = new File("target/testForMode/Embeddable.txt");
+        assertFalse(embeddable.exists());
+        File objEntity = new File("target/testForMode/ObjEntity.txt");
+        assertFalse(objEntity.exists());
+        File dataMap = new File("target/testForMode/TestCgen.txt");
+        assertTrue(dataMap.exists());
+
+        File superDataMap = new File("target/testForMode/superPkg/_TestCgen.txt");
+        assertTrue(superDataMap.exists());
+    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/ac6819f3/maven-plugins/cayenne-maven-plugin/src/test/resources/cgen/project-to-test/datamap-and-pom.xml
----------------------------------------------------------------------
diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/cgen/project-to-test/datamap-and-pom.xml b/maven-plugins/cayenne-maven-plugin/src/test/resources/cgen/project-to-test/datamap-and-pom.xml
index 620a6d0..a5b90fd 100644
--- a/maven-plugins/cayenne-maven-plugin/src/test/resources/cgen/project-to-test/datamap-and-pom.xml
+++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/cgen/project-to-test/datamap-and-pom.xml
@@ -42,7 +42,6 @@
                     <outputPattern>*.txt</outputPattern>
                     <makePairs>false</makePairs>
                     <usePkgPath>true</usePkgPath>
-                    <superPkg>superPkg</superPkg>
                     <encoding>UTF-8</encoding>
                     <excludeEntities>ObjEntity</excludeEntities>
                     <mode>all</mode>

http://git-wip-us.apache.org/repos/asf/cayenne/blob/ac6819f3/maven-plugins/cayenne-maven-plugin/src/test/resources/cgen/project-to-test/replaceDatamapMode-pom.xml
----------------------------------------------------------------------
diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/cgen/project-to-test/replaceDatamapMode-pom.xml b/maven-plugins/cayenne-maven-plugin/src/test/resources/cgen/project-to-test/replaceDatamapMode-pom.xml
new file mode 100644
index 0000000..8480f85
--- /dev/null
+++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/cgen/project-to-test/replaceDatamapMode-pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+	Licensed to the Apache Software Foundation (ASF) under one
+	or more contributor license agreements.  See the NOTICE file
+	distributed with this work for additional information
+	regarding copyright ownership.  The ASF licenses this file
+	to you under the Apache License, Version 2.0 (the
+	"License"); you may not use this file except in compliance
+	with the License.  You may obtain a copy of the License at
+
+	http://www.apache.org/licenses/LICENSE-2.0
+
+	Unless required by applicable law or agreed to in writing,
+	software distributed under the License is distributed on an
+	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	KIND, either express or implied.  See the License for the
+	specific language governing permissions and limitations
+	under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+	http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <name>Test CayenneGeneratorMojo</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>cayenne-maven-plugin</artifactId>
+                <configuration>
+                    <map>src/test/resources/cgen/testCgen.map.xml</map>
+                    <destDir>target/testForMode</destDir>
+                    <outputPattern>*.txt</outputPattern>
+                    <makePairs>true</makePairs>
+                    <usePkgPath>true</usePkgPath>
+                    <superPkg>superPkg</superPkg>
+                    <encoding>UTF-8</encoding>
+                    <mode>datamap</mode>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>