Repository: cayenne
Updated Branches:
  refs/heads/master 0b1ab617f -> 835d1d451


CAY-2510 Create builder to load custom modules into plugins and modeler


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

Branch: refs/heads/master
Commit: 0cc27d6f20a8523dcf8f394895106531d7122bbe
Parents: 4d42e26
Author: Arseni Bulatski <ancars...@gmail.com>
Authored: Thu Jan 10 18:12:48 2019 +0300
Committer: Arseni Bulatski <ancars...@gmail.com>
Committed: Thu Jan 10 18:59:43 2019 +0300

----------------------------------------------------------------------
 RELEASE-NOTES.txt                               |  1 +
 .../cayenne/tools/CayenneGeneratorTask.java     | 17 +++---
 cayenne-cgen/pom.xml                            |  8 +++
 .../java/org/apache/cayenne/gen/CgenModule.java |  1 +
 .../cayenne/gen/CgenToolsModuleProvider.java    | 46 +++++++++++++++
 .../cayenne/gen/ClassGenerationAction.java      | 21 ++++---
 .../gen/ClassGenerationActionFactory.java       | 27 +++++++++
 .../gen/ClientClassGenerationAction.java        | 20 ++++---
 .../DefaultClassGenerationActionFactory.java    | 36 ++++++++++++
 .../tools/CayenneToolsModuleProvider.java       | 28 ++++++++++
 .../cayenne/tools/ToolsInjectorBuilder.java     | 59 ++++++++++++++++++++
 ...che.cayenne.tools.CayenneToolsModuleProvider | 20 +++++++
 .../cayenne/gen/CgenModuleProviderTest.java     | 34 +++++++++++
 .../cayenne/gen/ClassGenerationActionTest.java  | 21 +++----
 .../java/org/apache/cayenne/tools/CgenTask.java | 14 +++--
 .../org/apache/cayenne/tools/CgenTaskTest.java  |  4 +-
 .../cayenne/tools/CayenneGeneratorMojo.java     | 17 +++---
 .../editor/cgen/CodeGeneratorController.java    | 22 ++++----
 .../editor/cgen/domain/CgenTabController.java   | 25 +++++----
 19 files changed, 344 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 80c522b..41f609d 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -16,6 +16,7 @@ Changes/New Features:
 CAY-2467 New type-aware Property API
 CAY-2507 Property API to use path aliases
 CAY-2508 Create api to add aliases in expressions
+CAY-2510 Create builder to load custom modules into plugins and modeler
 
 Bug Fixes:
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/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 f8b43d5..dbbd9e3 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
@@ -18,16 +18,17 @@
  ****************************************************************/
 package org.apache.cayenne.tools;
 
+import java.io.File;
+
 import foundrylogic.vpp.VPPConfig;
 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.ArtifactsGenerationMode;
 import org.apache.cayenne.gen.CgenConfiguration;
-import org.apache.cayenne.gen.CgenModule;
 import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.ClassGenerationActionFactory;
 import org.apache.cayenne.gen.ClientClassGenerationAction;
 import org.apache.cayenne.map.DataMap;
 import org.apache.tools.ant.BuildException;
@@ -35,8 +36,6 @@ import org.apache.tools.ant.types.Path;
 import org.apache.velocity.VelocityContext;
 import org.slf4j.LoggerFactory;
 
-import java.io.File;
-
 /**
  * An Ant task to perform class generation based on CayenneDataMap.
  * 
@@ -104,7 +103,9 @@ public class CayenneGeneratorTask extends CayenneTask {
     public void execute() throws BuildException {
         validateAttributes();
 
-        injector = DIBootstrap.createInjector(new CgenModule(), new 
ToolsModule(LoggerFactory.getLogger(CayenneGeneratorTask.class)));
+        injector = new ToolsInjectorBuilder()
+                .addModule(new 
ToolsModule(LoggerFactory.getLogger(CayenneGeneratorTask.class)))
+                .create();
 
         logger = new AntLogger(this);
         CayenneGeneratorMapLoaderAction loadAction = new 
CayenneGeneratorMapLoaderAction(injector);
@@ -144,11 +145,7 @@ public class CayenneGeneratorTask extends CayenneTask {
 
     private ClassGenerationAction createGenerator(DataMap dataMap) {
         CgenConfiguration cgenConfiguration = buildConfiguration(dataMap);
-        ClassGenerationAction classGenerationAction = 
cgenConfiguration.isClient() ? new 
ClientClassGenerationAction(cgenConfiguration) :
-                new ClassGenerationAction(cgenConfiguration);
-        injector.injectMembers(classGenerationAction);
-
-        return classGenerationAction;
+        return 
injector.getInstance(ClassGenerationActionFactory.class).createAction(cgenConfiguration);
     }
 
     private boolean hasConfig() {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/cayenne-cgen/pom.xml
----------------------------------------------------------------------
diff --git a/cayenne-cgen/pom.xml b/cayenne-cgen/pom.xml
index 1747391..55b625f 100644
--- a/cayenne-cgen/pom.xml
+++ b/cayenne-cgen/pom.xml
@@ -55,6 +55,14 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.cayenne</groupId>
+            <artifactId>cayenne-server</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/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
index 44b6cd7..7a08ce7 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenModule.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenModule.java
@@ -29,6 +29,7 @@ import org.apache.cayenne.project.ProjectModule;
 public class CgenModule implements Module{
     @Override
     public void configure(Binder binder) {
+        
binder.bind(ClassGenerationActionFactory.class).to(DefaultClassGenerationActionFactory.class);
         ProjectModule.contributeExtensions(binder).add(CgenExtension.class);
     }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenToolsModuleProvider.java
----------------------------------------------------------------------
diff --git 
a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenToolsModuleProvider.java
 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenToolsModuleProvider.java
new file mode 100644
index 0000000..dc309c6
--- /dev/null
+++ 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenToolsModuleProvider.java
@@ -0,0 +1,46 @@
+/*****************************************************************
+ *   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.
+ ****************************************************************/
+
+package org.apache.cayenne.gen;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.tools.CayenneToolsModuleProvider;
+
+/**
+ * @since 4.2
+ */
+public class CgenToolsModuleProvider implements CayenneToolsModuleProvider {
+    @Override
+    public Module module() {
+        return new CgenModule();
+    }
+
+    @Override
+    public Class<? extends Module> moduleType() {
+        return CgenModule.class;
+    }
+
+    @Override
+    public Collection<Class<? extends Module>> overrides() {
+        return Collections.emptyList();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/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 008fc3b..e4a9870 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
@@ -19,15 +19,6 @@
 
 package org.apache.cayenne.gen;
 
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.map.Embeddable;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.map.QueryDescriptor;
-import org.apache.velocity.Template;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.app.VelocityEngine;
-import org.slf4j.Logger;
-
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -42,6 +33,15 @@ import java.util.Objects;
 import java.util.Properties;
 import java.util.stream.Collectors;
 
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.map.Embeddable;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.QueryDescriptor;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.slf4j.Logger;
+
 public class ClassGenerationAction {
 
        private static final String TEMPLATES_DIR_NAME = "templates/v4_1/";
@@ -71,10 +71,9 @@ public class ClassGenerationAction {
     protected VelocityContext context;
     protected Map<String, Template> templateCache;
 
-       public ClassGenerationAction(CgenConfiguration cgenConfiguration) {
+       public ClassGenerationAction() {
                this.context = new VelocityContext();
                this.templateCache = new HashMap<>(5);
-               this.cgenConfiguration = cgenConfiguration;
        }
 
        public String defaultTemplateName(TemplateType type) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationActionFactory.java
----------------------------------------------------------------------
diff --git 
a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationActionFactory.java
 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationActionFactory.java
new file mode 100644
index 0000000..dcad897
--- /dev/null
+++ 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationActionFactory.java
@@ -0,0 +1,27 @@
+/*****************************************************************
+ *   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.
+ ****************************************************************/
+package org.apache.cayenne.gen;
+
+/**
+ * @since 4.2
+ */
+public interface ClassGenerationActionFactory {
+
+    ClassGenerationAction createAction(CgenConfiguration cgenConfiguration);
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
----------------------------------------------------------------------
diff --git 
a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
index b823c85..161e850 100644
--- 
a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
+++ 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
@@ -19,12 +19,12 @@
 
 package org.apache.cayenne.gen;
 
+import java.util.Collection;
+
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.QueryDescriptor;
 
-import java.util.Collection;
-
 /**
  * @since 3.0
  */
@@ -41,12 +41,8 @@ public class ClientClassGenerationAction extends 
ClassGenerationAction {
 
     public static final String CLIENT_SUPERCLASS_PREFIX = "_Client";
 
-    public ClientClassGenerationAction(CgenConfiguration cgenConfiguration) {
-        super(cgenConfiguration);
-        cgenConfiguration.setTemplate(SUBCLASS_TEMPLATE);
-        cgenConfiguration.setSuperTemplate(SUPERCLASS_TEMPLATE);
-        cgenConfiguration.setQueryTemplate(DMAP_SUBCLASS_TEMPLATE);
-        cgenConfiguration.setQuerySuperTemplate(DMAP_SUPERCLASS_TEMPLATE);
+    public ClientClassGenerationAction() {
+        super();
     }
 
     @Override
@@ -103,4 +99,12 @@ public class ClientClassGenerationAction extends 
ClassGenerationAction {
             }
         }
     }
+
+    public void setCgenConfiguration(CgenConfiguration cgenConfiguration) {
+        super.setCgenConfiguration(cgenConfiguration);
+        cgenConfiguration.setTemplate(SUBCLASS_TEMPLATE);
+        cgenConfiguration.setSuperTemplate(SUPERCLASS_TEMPLATE);
+        cgenConfiguration.setQueryTemplate(DMAP_SUBCLASS_TEMPLATE);
+        cgenConfiguration.setQuerySuperTemplate(DMAP_SUPERCLASS_TEMPLATE);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/cayenne-cgen/src/main/java/org/apache/cayenne/gen/DefaultClassGenerationActionFactory.java
----------------------------------------------------------------------
diff --git 
a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/DefaultClassGenerationActionFactory.java
 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/DefaultClassGenerationActionFactory.java
new file mode 100644
index 0000000..8f409ec
--- /dev/null
+++ 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/DefaultClassGenerationActionFactory.java
@@ -0,0 +1,36 @@
+/*****************************************************************
+ *   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.
+ ****************************************************************/
+
+package org.apache.cayenne.gen;
+
+/**
+ * @since 4.2
+ */
+public class DefaultClassGenerationActionFactory implements 
ClassGenerationActionFactory {
+
+    @Override
+    public ClassGenerationAction createAction(CgenConfiguration 
cgenConfiguration) {
+        ClassGenerationAction classGenerationAction = 
cgenConfiguration.isClient() ?
+                new ClientClassGenerationAction() :
+                new ClassGenerationAction();
+        classGenerationAction.setCgenConfiguration(cgenConfiguration);
+        return classGenerationAction;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/cayenne-cgen/src/main/java/org/apache/cayenne/tools/CayenneToolsModuleProvider.java
----------------------------------------------------------------------
diff --git 
a/cayenne-cgen/src/main/java/org/apache/cayenne/tools/CayenneToolsModuleProvider.java
 
b/cayenne-cgen/src/main/java/org/apache/cayenne/tools/CayenneToolsModuleProvider.java
new file mode 100644
index 0000000..500f692
--- /dev/null
+++ 
b/cayenne-cgen/src/main/java/org/apache/cayenne/tools/CayenneToolsModuleProvider.java
@@ -0,0 +1,28 @@
+/*****************************************************************
+ *   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.
+ ****************************************************************/
+
+package org.apache.cayenne.tools;
+
+import org.apache.cayenne.di.spi.ModuleProvider;
+
+/**
+ * @since 4.2
+ */
+public interface CayenneToolsModuleProvider extends ModuleProvider {
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/cayenne-cgen/src/main/java/org/apache/cayenne/tools/ToolsInjectorBuilder.java
----------------------------------------------------------------------
diff --git 
a/cayenne-cgen/src/main/java/org/apache/cayenne/tools/ToolsInjectorBuilder.java 
b/cayenne-cgen/src/main/java/org/apache/cayenne/tools/ToolsInjectorBuilder.java
new file mode 100644
index 0000000..e1fea9f
--- /dev/null
+++ 
b/cayenne-cgen/src/main/java/org/apache/cayenne/tools/ToolsInjectorBuilder.java
@@ -0,0 +1,59 @@
+/*****************************************************************
+ *   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.
+ ****************************************************************/
+package org.apache.cayenne.tools;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.cayenne.di.DIBootstrap;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.di.spi.ModuleLoader;
+
+/**
+ * @since 4.2
+ */
+public class ToolsInjectorBuilder {
+
+    private Collection<Module> modules;
+
+    public ToolsInjectorBuilder() {
+        this.modules = new ArrayList<>();
+    }
+
+    public ToolsInjectorBuilder addModule(Module module) {
+        modules.add(module);
+        return this;
+    }
+
+    public ToolsInjectorBuilder addModules(Collection<Module> modules) {
+        this.modules.addAll(modules);
+        return this;
+    }
+
+    private Collection<? extends Module> autoLoadedModules() {
+        return new ModuleLoader().load(CayenneToolsModuleProvider.class);
+    }
+
+    public Injector create() {
+        Collection<Module> allModules = new ArrayList<>(autoLoadedModules());
+        allModules.addAll(modules);
+        return DIBootstrap.createInjector(allModules);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/cayenne-cgen/src/main/resources/META-INF/services/org.apache.cayenne.tools.CayenneToolsModuleProvider
----------------------------------------------------------------------
diff --git 
a/cayenne-cgen/src/main/resources/META-INF/services/org.apache.cayenne.tools.CayenneToolsModuleProvider
 
b/cayenne-cgen/src/main/resources/META-INF/services/org.apache.cayenne.tools.CayenneToolsModuleProvider
new file mode 100644
index 0000000..c14b835
--- /dev/null
+++ 
b/cayenne-cgen/src/main/resources/META-INF/services/org.apache.cayenne.tools.CayenneToolsModuleProvider
@@ -0,0 +1,20 @@
+##################################################################
+#   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.
+##################################################################
+
+org.apache.cayenne.gen.CgenToolsModuleProvider
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/cayenne-cgen/src/test/java/org/apache/cayenne/gen/CgenModuleProviderTest.java
----------------------------------------------------------------------
diff --git 
a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/CgenModuleProviderTest.java 
b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/CgenModuleProviderTest.java
new file mode 100644
index 0000000..6fdbfba
--- /dev/null
+++ 
b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/CgenModuleProviderTest.java
@@ -0,0 +1,34 @@
+/*****************************************************************
+ *   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.
+ ****************************************************************/
+
+package org.apache.cayenne.gen;
+
+import org.apache.cayenne.tools.CayenneToolsModuleProvider;
+import org.apache.cayenne.unit.util.ModuleProviderChecker;
+import org.junit.Test;
+
+/**
+ * @since 4.2
+ */
+public class CgenModuleProviderTest {
+    @Test
+    public void testProviderPresent() {
+        
ModuleProviderChecker.testProviderPresent(CgenToolsModuleProvider.class, 
CayenneToolsModuleProvider.class);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
----------------------------------------------------------------------
diff --git 
a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
 
b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
index 89dfaaa..991a3a7 100644
--- 
a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
+++ 
b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
@@ -19,6 +19,13 @@
 
 package org.apache.cayenne.gen;
 
+import java.io.File;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
 import org.apache.cayenne.map.CallbackDescriptor;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.ObjAttribute;
@@ -29,13 +36,6 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.io.File;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -54,7 +54,7 @@ public class ClassGenerationActionTest {
        public void setUp() throws Exception {
                writers = new ArrayList<>(3);
                cgenConfiguration = new CgenConfiguration();
-               action = new ClassGenerationAction(cgenConfiguration) {
+               action = new ClassGenerationAction() {
 
                        @Override
                        protected Writer openWriter(TemplateType templateType) 
throws Exception {
@@ -63,6 +63,7 @@ public class ClassGenerationActionTest {
                                return writer;
                        }
                };
+               action.setCgenConfiguration(cgenConfiguration);
        }
 
        @After
@@ -216,7 +217,7 @@ public class ClassGenerationActionTest {
 
                if (isClient) {
 
-                       action = new 
ClientClassGenerationAction(cgenConfiguration) {
+                       action = new ClientClassGenerationAction() {
                                @Override
                                protected Writer openWriter(TemplateType 
templateType) throws Exception {
                                        StringWriter writer = new 
StringWriter();
@@ -225,7 +226,7 @@ public class ClassGenerationActionTest {
                                }
 
                        };
-
+                       action.setCgenConfiguration(cgenConfiguration);
                }
 
                cgenConfiguration.setMakePairs(true);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/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 234030f..3571a4a 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
@@ -23,12 +23,11 @@ import groovy.lang.Reference;
 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.ArtifactsGenerationMode;
 import org.apache.cayenne.gen.CgenConfiguration;
-import org.apache.cayenne.gen.CgenModule;
 import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.ClassGenerationActionFactory;
 import org.apache.cayenne.gen.ClientClassGenerationAction;
 import org.apache.cayenne.map.DataMap;
 import org.gradle.api.Action;
@@ -36,7 +35,6 @@ import org.gradle.api.GradleException;
 import org.gradle.api.InvalidUserDataException;
 import org.gradle.api.plugins.JavaPlugin;
 import org.gradle.api.tasks.*;
-import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.File;
@@ -150,11 +148,16 @@ public class CgenTask extends BaseCayenneTask {
 
     private boolean useConfigFromDataMap;
 
+    private transient Injector injector;
+
     @TaskAction
     public void generate() {
         File dataMapFile = getDataMapFile();
 
-        final Injector injector = DIBootstrap.createInjector(new CgenModule(), 
new ToolsModule(LoggerFactory.getLogger(CgenTask.class)));
+        injector = new ToolsInjectorBuilder()
+                .addModule(new 
ToolsModule(LoggerFactory.getLogger(CgenTask.class)))
+                .create();
+
         metaData = injector.getInstance(DataChannelMetaData.class);
 
         CayenneGeneratorMapLoaderAction loaderAction = new 
CayenneGeneratorMapLoaderAction(injector);
@@ -206,8 +209,7 @@ public class CgenTask extends BaseCayenneTask {
 
     ClassGenerationAction createGenerator(DataMap dataMap) {
         CgenConfiguration cgenConfiguration = buildConfiguration(dataMap);
-        return cgenConfiguration.isClient() ? new 
ClientClassGenerationAction(cgenConfiguration) :
-                new ClassGenerationAction(cgenConfiguration);
+        return 
injector.getInstance(ClassGenerationActionFactory.class).createAction(cgenConfiguration);
     }
 
     CgenConfiguration buildConfiguration(DataMap dataMap) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/CgenTaskTest.java
----------------------------------------------------------------------
diff --git 
a/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/CgenTaskTest.java
 
b/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/CgenTaskTest.java
index 00d090e..fd6970b 100644
--- 
a/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/CgenTaskTest.java
+++ 
b/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/CgenTaskTest.java
@@ -87,7 +87,9 @@ public class CgenTaskTest {
         task.setOverwrite(true);
         task.setUsePkgPath(true);
 
-        ClassGenerationAction createdAction = task.createGenerator(dataMap);
+        CgenConfiguration configuration = task.buildConfiguration(dataMap);
+        ClassGenerationAction createdAction = new ClassGenerationAction();
+        createdAction.setCgenConfiguration(configuration);
 
         CgenConfiguration cgenConfiguration = 
createdAction.getCgenConfiguration();
         assertEquals(cgenConfiguration.getEmbeddableSuperTemplate(), 
"superTemplate");

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/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 74f92ce..eab0137 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,15 +19,16 @@
 
 package org.apache.cayenne.tools;
 
+import java.io.File;
+
 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.ArtifactsGenerationMode;
 import org.apache.cayenne.gen.CgenConfiguration;
-import org.apache.cayenne.gen.CgenModule;
 import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.ClassGenerationActionFactory;
 import org.apache.cayenne.gen.ClientClassGenerationAction;
 import org.apache.cayenne.map.DataMap;
 import org.apache.maven.plugin.AbstractMojo;
@@ -39,8 +40,6 @@ import org.apache.maven.plugins.annotations.Parameter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.File;
-
 /**
  * Maven mojo to perform class generation from data cgenConfiguration. This 
class is an Maven
  * adapter to DefaultClassGenerator class.
@@ -236,7 +235,9 @@ public class CayenneGeneratorMojo extends AbstractMojo {
                // TODO: (KJM 11/2/06) The destDir really should be added as a
                // compilation resource for maven.
 
-               injector = DIBootstrap.createInjector(new CgenModule(), new 
ToolsModule(LoggerFactory.getLogger(CayenneGeneratorMojo.class)));
+               injector = new ToolsInjectorBuilder()
+                               .addModule(new 
ToolsModule(LoggerFactory.getLogger(CayenneGeneratorMojo.class)))
+                               .create();
 
                Logger logger = new MavenLogger(this);
                CayenneGeneratorMapLoaderAction loaderAction = new 
CayenneGeneratorMapLoaderAction(injector);
@@ -305,11 +306,7 @@ public class CayenneGeneratorMojo extends AbstractMojo {
         */
        private ClassGenerationAction createGenerator(DataMap dataMap) {
                CgenConfiguration cgenConfiguration = 
buildConfiguration(dataMap);
-               ClassGenerationAction classGenerationAction = 
cgenConfiguration.isClient() ? new 
ClientClassGenerationAction(cgenConfiguration) :
-                               new ClassGenerationAction(cgenConfiguration);
-               injector.injectMembers(classGenerationAction);
-
-               return classGenerationAction;
+               return 
injector.getInstance(ClassGenerationActionFactory.class).createAction(cgenConfiguration);
        }
 
        private CgenConfiguration buildConfiguration(DataMap dataMap) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java
----------------------------------------------------------------------
diff --git 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java
 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java
index cb7b50b..ba6ab60 100644
--- 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java
+++ 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java
@@ -19,11 +19,17 @@
 
 package org.apache.cayenne.modeler.editor.cgen;
 
+import javax.swing.*;
+import java.awt.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Predicate;
+
 import org.apache.cayenne.configuration.event.DataMapEvent;
 import org.apache.cayenne.configuration.event.DataMapListener;
 import org.apache.cayenne.gen.CgenConfiguration;
 import org.apache.cayenne.gen.ClassGenerationAction;
-import org.apache.cayenne.gen.ClientClassGenerationAction;
+import org.apache.cayenne.gen.ClassGenerationActionFactory;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.event.EmbeddableEvent;
@@ -35,15 +41,10 @@ import org.apache.cayenne.modeler.dialog.ErrorDebugDialog;
 import org.apache.cayenne.modeler.editor.DbImportController;
 import org.apache.cayenne.modeler.util.CayenneController;
 import org.apache.cayenne.swing.BindingBuilder;
+import org.apache.cayenne.tools.ToolsInjectorBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.swing.JOptionPane;
-import java.awt.Component;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.function.Predicate;
-
 /**
  * @since 4.1
  * A controller for the class generator dialog.
@@ -137,9 +138,10 @@ public class CodeGeneratorController extends 
CodeGeneratorControllerBase impleme
 
     public void generateAction() {
         CgenConfiguration cgenConfiguration = createConfiguration();
-        ClassGenerationAction generator = cgenConfiguration.isClient() ?
-                new ClientClassGenerationAction(cgenConfiguration) :
-                new ClassGenerationAction(cgenConfiguration);
+        ClassGenerationAction generator = new ToolsInjectorBuilder()
+                .create()
+                .getInstance(ClassGenerationActionFactory.class)
+                .createAction(cgenConfiguration);
 
         try {
             generator.prepareArtifacts();

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0cc27d6f/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTabController.java
----------------------------------------------------------------------
diff --git 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTabController.java
 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTabController.java
index ff68804..af1505b 100644
--- 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTabController.java
+++ 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTabController.java
@@ -19,10 +19,18 @@
 
 package org.apache.cayenne.modeler.editor.cgen.domain;
 
+import javax.swing.*;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Set;
+import java.util.prefs.Preferences;
+
 import org.apache.cayenne.configuration.xml.DataChannelMetaData;
 import org.apache.cayenne.gen.CgenConfiguration;
 import org.apache.cayenne.gen.ClassGenerationAction;
-import org.apache.cayenne.gen.ClientClassGenerationAction;
+import org.apache.cayenne.gen.ClassGenerationActionFactory;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
@@ -30,14 +38,7 @@ import 
org.apache.cayenne.modeler.dialog.pref.GeneralPreferences;
 import org.apache.cayenne.modeler.editor.GeneratorsTabController;
 import org.apache.cayenne.modeler.event.DataMapDisplayEvent;
 import org.apache.cayenne.modeler.util.ModelerUtil;
-
-import javax.swing.JOptionPane;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Set;
-import java.util.prefs.Preferences;
+import org.apache.cayenne.tools.ToolsInjectorBuilder;
 
 /**
  * @since 4.1
@@ -63,8 +64,10 @@ public class CgenTabController extends 
GeneratorsTabController {
                 if(cgenConfiguration == null) {
                     cgenConfiguration = createConfiguration(dataMap);
                 }
-                ClassGenerationAction classGenerationAction = 
cgenConfiguration.isClient() ? new 
ClientClassGenerationAction(cgenConfiguration) :
-                        new ClassGenerationAction(cgenConfiguration);
+                ClassGenerationAction classGenerationAction = new 
ToolsInjectorBuilder()
+                        .create()
+                        .getInstance(ClassGenerationActionFactory.class)
+                        .createAction(cgenConfiguration);
                 classGenerationAction.prepareArtifacts();
                 classGenerationAction.execute();
             } catch (Exception e) {

Reply via email to