cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [07/32] cayenne git commit: Add merge pom config with dataMap config
Date Wed, 14 Nov 2018 14:27:38 GMT
Add merge pom config with dataMap config


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

Branch: refs/heads/master
Commit: b10cd803a005065ed55f07ba57eb9dce3b5addbf
Parents: e41f1e4
Author: Arseni Bulatski <ancarseni@gmail.com>
Authored: Tue Jun 26 13:45:41 2018 +0300
Committer: Arseni Bulatski <ancarseni@gmail.com>
Committed: Wed Oct 24 13:42:16 2018 +0300

----------------------------------------------------------------------
 .../java/org/apache/cayenne/gen/CgenModule.java | 13 ++++
 .../cayenne/gen/ClassGenerationAction.java      | 46 ++++++++-----
 .../cayenne/tools/CayenneGeneratorMojo.java     | 69 +++++++++++---------
 .../editor/cgen/CustomModeController.java       |  1 +
 4 files changed, 82 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/b10cd803/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenModule.java
----------------------------------------------------------------------
diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenModule.java b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenModule.java
new file mode 100644
index 0000000..79e411e
--- /dev/null
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenModule.java
@@ -0,0 +1,13 @@
+package org.apache.cayenne.gen;
+
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.gen.xml.CgenExtension;
+import org.apache.cayenne.project.ProjectModule;
+
+public class CgenModule implements Module{
+    @Override
+    public void configure(Binder binder) {
+        ProjectModule.contributeExtensions(binder).add(CgenExtension.class);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b10cd803/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
----------------------------------------------------------------------
diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
index 5b10a07..afd58e0 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
@@ -91,29 +91,39 @@ public class ClassGenerationAction implements Serializable, XMLSerializable
{
 	protected VelocityContext context;
 	protected Map<String, Template> templateCache;
 
+
 	public ClassGenerationAction() {
-		this.outputPattern = "*.java";
-		this.timestamp = 0L;
-		this.usePkgPath = true;
-		this.makePairs = true;
-		this.context = new VelocityContext();
-		this.templateCache = new HashMap<>(5);
+        this.outputPattern = "*.java";
+        this.timestamp = 0L;
+        this.usePkgPath = true;
+        this.makePairs = true;
+        this.context = new VelocityContext();
+        this.templateCache = new HashMap<>(5);
 
-		this.template = SUBCLASS_TEMPLATE;
-		this.superTemplate = SUPERCLASS_TEMPLATE;
+        this.artifacts = new ArrayList<>();
+        this.entityArtifacts = new ArrayList<>();
+        this.embeddableArtifacts = new ArrayList<>();
+	}
 
-		this.embeddableTemplate = EMBEDDABLE_SUBCLASS_TEMPLATE;
-		this.embeddableSuperTemplate = EMBEDDABLE_SUPERCLASS_TEMPLATE;
+	public void setDefaults() {
+        this.outputPattern = "*.java";
+        this.timestamp = 0L;
+        this.usePkgPath = true;
+        this.makePairs = true;
+        this.context = new VelocityContext();
+        this.templateCache = new HashMap<>(5);
 
-		this.queryTemplate = DATAMAP_SUBCLASS_TEMPLATE;
-		this.querySuperTemplate = DATAMAP_SUPERCLASS_TEMPLATE;
+        this.template = SUBCLASS_TEMPLATE;
+        this.superTemplate = SUPERCLASS_TEMPLATE;
 
-		this.artifactsGenerationMode = ArtifactsGenerationMode.ENTITY;
+        this.embeddableTemplate = EMBEDDABLE_SUBCLASS_TEMPLATE;
+        this.embeddableSuperTemplate = EMBEDDABLE_SUPERCLASS_TEMPLATE;
 
-		this.artifacts = new ArrayList<>();
-		this.entityArtifacts = new ArrayList<>();
-		this.embeddableArtifacts = new ArrayList<>();
-	}
+        this.queryTemplate = DATAMAP_SUBCLASS_TEMPLATE;
+        this.querySuperTemplate = DATAMAP_SUPERCLASS_TEMPLATE;
+
+        this.artifactsGenerationMode = ArtifactsGenerationMode.ENTITY;
+    }
 
 	protected String defaultTemplateName(TemplateType type) {
 		switch (type) {
@@ -704,6 +714,8 @@ public class ClassGenerationAction implements Serializable, XMLSerializable
{
 		return destDir.getAbsolutePath();
 	}
 
+	public File getDestDir() { return destDir; }
+
 	public String getTemplate() {
 		return template;
 	}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b10cd803/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 d043c30..42a2e8d 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
@@ -19,10 +19,12 @@
 
 package org.apache.cayenne.tools;
 
+import org.apache.cayenne.configuration.xml.DataChannelMetaData;
 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.CgenModule;
 import org.apache.cayenne.gen.ClassGenerationAction;
 import org.apache.cayenne.gen.ClientClassGenerationAction;
 import org.apache.cayenne.map.DataMap;
@@ -96,8 +98,8 @@ public class CayenneGeneratorMojo extends AbstractMojo {
 	 * with all generated code included in superclass (default is
 	 * <code>true</code>).
 	 */
-	@Parameter(defaultValue = "true")
-	private boolean makePairs;
+	@Parameter
+	private String makePairs;
 
 	/**
 	 * DataMap XML file to use as a base for class generation.
@@ -117,15 +119,15 @@ public class CayenneGeneratorMojo extends AbstractMojo {
 	/**
 	 * Name of file for generated output. (Default is &quot;*.java&quot;)
 	 */
-	@Parameter(defaultValue = "*.java")
+	@Parameter
 	private String outputPattern;
 
 	/**
 	 * If set to <code>true</code>, will overwrite older versions of generated
 	 * classes. Ignored unless makepairs is set to <code>false</code>.
 	 */
-	@Parameter(defaultValue = "false")
-	private boolean overwrite;
+	@Parameter
+	private String overwrite;
 
 	/**
 	 * Java package name of generated superclasses. Ignored unless
@@ -174,15 +176,15 @@ public class CayenneGeneratorMojo extends AbstractMojo {
 	 * <code>false</code>, classes will be generated in &quot;destDir&quot;
 	 * ignoring their package.
 	 */
-	@Parameter(defaultValue = "true")
-	private boolean usePkgPath;
+	@Parameter
+	private String usePkgPath;
 
     /**
      * If set to <code>true</code>, will generate String Property names.
      * Default is <code>false</code>.
      */
-    @Parameter(defaultValue = "false")
-    private boolean createPropertyNames;
+    @Parameter
+    private String createPropertyNames;
 
 	/**
 	 * If set to <code>true</code>, will skip file modification time validation
and regenerate all.
@@ -203,6 +205,8 @@ public class CayenneGeneratorMojo extends AbstractMojo {
 
 	private transient Injector injector;
 
+    private static final Logger logger = LoggerFactory.getLogger(CayenneGeneratorMojo.class);
+
 	public void execute() throws MojoExecutionException, MojoFailureException {
 		// Create the destination directory if necessary.
 		// TODO: (KJM 11/2/06) The destDir really should be added as a
@@ -211,7 +215,7 @@ public class CayenneGeneratorMojo extends AbstractMojo {
 			destDir.mkdirs();
 		}
 
-		injector = DIBootstrap.createInjector(new ToolsModule(LoggerFactory.getLogger(CayenneGeneratorMojo.class)));
+		injector = DIBootstrap.createInjector(new CgenModule(), new ToolsModule(LoggerFactory.getLogger(CayenneGeneratorMojo.class)));
 
 		Logger logger = new MavenLogger(this);
 		CayenneGeneratorMapLoaderAction loaderAction = new CayenneGeneratorMapLoaderAction(injector);
@@ -226,7 +230,7 @@ public class CayenneGeneratorMojo extends AbstractMojo {
 
 			DataMap dataMap = loaderAction.getMainDataMap();
 
-			ClassGenerationAction generator = createGenerator();
+			ClassGenerationAction generator = createGenerator(dataMap);
 			generator.setLogger(logger);
 			if(force) {
 				// will (re-)generate all files
@@ -234,9 +238,13 @@ public class CayenneGeneratorMojo extends AbstractMojo {
 			}
 			generator.setTimestamp(map.lastModified());
 			generator.setDataMap(dataMap);
-			generator.addEntities(filterAction.getFilteredEntities(dataMap));
-			generator.addEmbeddables(dataMap.getEmbeddables());
-			generator.addQueries(dataMap.getQueryDescriptors());
+			if(!generator.getEntities().isEmpty() || !generator.getEmbeddables().isEmpty()){
+				generator.prepareArtifacts();
+			} else {
+				generator.addEntities(filterAction.getFilteredEntities(dataMap));
+				generator.addEmbeddables(dataMap.getEmbeddables());
+				generator.addQueries(dataMap.getQueryDescriptors());
+			}
 			generator.execute();
 		} catch (Exception e) {
 			throw new MojoExecutionException("Error generating classes: ", e);
@@ -265,32 +273,33 @@ public class CayenneGeneratorMojo extends AbstractMojo {
 	 * Factory method to create internal class generator. Called from
 	 * constructor.
 	 */
-	protected ClassGenerationAction createGenerator() {
+	protected ClassGenerationAction createGenerator(DataMap dataMap) {
+
+	    ClassGenerationAction action = injector.getInstance(DataChannelMetaData.class).get(dataMap,
ClassGenerationAction.class);
 
-		ClassGenerationAction action;
 		if (client) {
 			action = new ClientClassGenerationAction();
 		} else {
-			action = new ClassGenerationAction();
+            if(action == null) {
+                action = new ClassGenerationAction();
+            }
 		}
 
 		injector.injectMembers(action);
 
 		action.setDestDir(destDir);
-		action.setEncoding(encoding);
-		action.setMakePairs(makePairs);
+		action.setEncoding(encoding != null ? encoding : action.getEncoding());
+		action.setMakePairs(makePairs != null ? Boolean.valueOf(makePairs) : action.isMakePairs());
 		action.setArtifactsGenerationMode(mode);
-		action.setOutputPattern(outputPattern);
-		action.setOverwrite(overwrite);
-		action.setSuperPkg(superPkg);
-		action.setSuperTemplate(superTemplate);
-		action.setTemplate(template);
-		action.setEmbeddableSuperTemplate(embeddableSuperTemplate);
-		action.setEmbeddableTemplate(embeddableTemplate);
-		action.setUsePkgPath(usePkgPath);
-		action.setCreatePropertyNames(createPropertyNames);
-        action.setCreatePKProperties(createPKProperties);
-
+		action.setOutputPattern(outputPattern != null ? outputPattern : action.getOutputPattern());
+		action.setOverwrite(overwrite != null ? Boolean.valueOf(overwrite) : action.isOverwrite());
+		action.setSuperPkg(superPkg != null ? superPkg : action.getSuperPkg());
+		action.setSuperTemplate(superTemplate != null ? superTemplate : action.getSuperclassTemplate());
+		action.setTemplate(template != null ? template : action.getTemplate());
+		action.setEmbeddableSuperTemplate(embeddableSuperTemplate != null ? embeddableSuperTemplate
: action.getEmbeddableSuperTemplate());
+		action.setEmbeddableTemplate(embeddableTemplate != null ? embeddableTemplate : action.getEmbeddableTemplate());
+		action.setUsePkgPath(usePkgPath != null ? Boolean.valueOf(usePkgPath) : action.isUsePkgPath());
+		action.setCreatePropertyNames(createPropertyNames != null ? Boolean.valueOf(createPropertyNames)
: action.isCreatePropertyNames());
 		return action;
 	}
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b10cd803/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModeController.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModeController.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModeController.java
index 2559657..5666355 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModeController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModeController.java
@@ -143,6 +143,7 @@ public class CustomModeController extends GeneratorController {
     @Override
     protected ClassGenerationAction newGenerator() {
         ClassGenerationAction action = new ClassGenerationAction();
+        action.setDefaults();
         getApplication().getInjector().injectMembers(action);
         return action;
     }


Mime
View raw message