You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2014/12/19 09:07:27 UTC

[04/11] isis git commit: ISIS-284: renaming of mojo classes to better capture intent (IsisRunnable -> MetaModelProcessor, IsisMojoReporter -> MetaModelProcessor.Context).

ISIS-284: renaming of mojo classes to better capture intent (IsisRunnable -> MetaModelProcessor, IsisMojoReporter -> MetaModelProcessor.Context).

Also add the MavenProject into the MetaModelValidator.Context interface, and make private in IsisMojoAbstract.  That way all the stuff that the subclasses (eg IsisMojoValidate) needs is available in the MetaModelProcessor.Context API)


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

Branch: refs/heads/master
Commit: b1c643aed072fdaa88c3b8e41ba115d38be03899
Parents: f4197f1
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Dec 19 07:02:01 2014 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Dec 19 07:02:01 2014 +0000

----------------------------------------------------------------------
 .../isis/tool/mavenplugin/IsisMojoAbstract.java | 40 ++++++++++-------
 .../isis/tool/mavenplugin/IsisMojoReporter.java | 18 --------
 .../isis/tool/mavenplugin/IsisMojoValidate.java | 10 ++---
 .../isis/tool/mavenplugin/IsisRunnable.java     | 27 ------------
 .../tool/mavenplugin/MetaModelProcessor.java    | 46 ++++++++++++++++++++
 5 files changed, 76 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/b1c643ae/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java
----------------------------------------------------------------------
diff --git a/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java b/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java
index bd3634c..09de280 100644
--- a/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java
+++ b/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java
@@ -45,15 +45,16 @@ import org.apache.isis.tool.mavenplugin.util.Xpp3Doms;
 public abstract class IsisMojoAbstract extends AbstractMojo {
 
     protected static final String CURRENT_PLUGIN_KEY = "org.apache.isis.tool:isis-maven-plugin";
-    private final IsisRunnable isisRunnable;
 
     @Component
-    protected MavenProject mavenProject;
-    private IsisMojoReporterWithLog reporter;
+    private MavenProject mavenProject;
 
-    protected IsisMojoAbstract(final IsisRunnable isisRunnable) {
-        this.isisRunnable = isisRunnable;
-        this.reporter = new IsisMojoReporterWithLog(getLog());
+    private final MetaModelProcessor metaModelProcessor;
+    private final ContextForMojo context;
+
+    protected IsisMojoAbstract(final MetaModelProcessor metaModelProcessor) {
+        this.metaModelProcessor = metaModelProcessor;
+        this.context = new ContextForMojo(mavenProject, getLog());
     }
 
     public void execute() throws MojoExecutionException, MojoFailureException {
@@ -65,15 +66,17 @@ public abstract class IsisMojoAbstract extends AbstractMojo {
         }
         getLog().info("Found " + serviceList.size() + " services");
 
-        usingIsisMetaModel(serviceList, isisRunnable);
+        usingIsisMetaModel(serviceList, metaModelProcessor);
     }
 
-    private void usingIsisMetaModel(List<Object> serviceList, IsisRunnable isisRunnable) throws MojoExecutionException, MojoFailureException {
+    private void usingIsisMetaModel(
+            final List<Object> serviceList,
+            final MetaModelProcessor metaModelProcessor) throws MojoExecutionException, MojoFailureException {
 
         IsisMetaModel isisMetaModel = null;
         try {
             isisMetaModel = bootstrapIsis(serviceList);
-            isisRunnable.run(isisMetaModel, reporter);
+            metaModelProcessor.process(isisMetaModel, context);
         } finally {
             IsisMetaModels.disposeSafely(isisMetaModel);
         }
@@ -100,12 +103,12 @@ public abstract class IsisMojoAbstract extends AbstractMojo {
     private IsisConfiguration isisConfigurationFor(final Plugin plugin) throws MojoFailureException {
         final Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
         if (configuration == null) {
-            reporter.throwFailureException("Configuration error", "No <configuration> element found");
+            context.throwFailureException("Configuration error", "No <configuration> element found");
         }
 
         final Xpp3Dom servicesEl = configuration.getChild("isisConfigDir");
         if (servicesEl == null) {
-            reporter.throwFailureException("Configuration error", "No <configuration>/<isisConfigDir> element found");
+            context.throwFailureException("Configuration error", "No <configuration>/<isisConfigDir> element found");
         }
         final String isisConfigDir = Xpp3Doms.GET_VALUE.apply(servicesEl);
 
@@ -113,7 +116,7 @@ public abstract class IsisMojoAbstract extends AbstractMojo {
         final File file = new File(basedir, isisConfigDir);
         final String absoluteConfigDir = file.getAbsolutePath();
         if(!file.exists() || !file.isDirectory()) {
-            reporter.throwFailureException("Configuration error",
+            context.throwFailureException("Configuration error",
                     String.format("isisConfigDir (%s) does not exist or is not a directory", absoluteConfigDir));
         }
         final IsisConfigurationBuilderDefault configBuilder = new IsisConfigurationBuilderDefault(absoluteConfigDir);
@@ -130,16 +133,23 @@ public abstract class IsisMojoAbstract extends AbstractMojo {
         return isisMetaModel;
     }
 
-    //region > IsisMojoReporter
-    static class IsisMojoReporterWithLog implements IsisMojoReporter {
+    //region > Context
+    static class ContextForMojo implements MetaModelProcessor.Context {
 
+        private final MavenProject mavenProject;
         private final Log log;
 
-        public IsisMojoReporterWithLog(final Log log) {
+        public ContextForMojo(final MavenProject mavenProject, final Log log) {
+            this.mavenProject = mavenProject;
             this.log = log;
         }
 
         @Override
+        public MavenProject getMavenProject() {
+            return mavenProject;
+        }
+
+        @Override
         public Log getLog() {
             return log;
         }

http://git-wip-us.apache.org/repos/asf/isis/blob/b1c643ae/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoReporter.java
----------------------------------------------------------------------
diff --git a/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoReporter.java b/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoReporter.java
deleted file mode 100644
index 5f7e2ea..0000000
--- a/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoReporter.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.apache.isis.tool.mavenplugin;
-
-import java.util.Set;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugin.logging.Log;
-
-public interface IsisMojoReporter {
-    Log getLog();
-
-    void logErrors(String... logMessages);
-
-    void throwFailureException(String errorMessage, Set<String> logMessages) throws MojoFailureException;
-
-    void throwFailureException(String errorMessage, String... logMessages) throws MojoFailureException;
-
-    void throwExecutionException(String errorMessage, Exception e) throws MojoExecutionException;
-}

http://git-wip-us.apache.org/repos/asf/isis/blob/b1c643ae/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoValidate.java
----------------------------------------------------------------------
diff --git a/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoValidate.java b/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoValidate.java
index eede660..e8bf8fa 100644
--- a/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoValidate.java
+++ b/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoValidate.java
@@ -38,20 +38,20 @@ import org.apache.isis.core.metamodel.specloader.validator.ValidationFailures;
 public class IsisMojoValidate extends IsisMojoAbstract {
 
     protected IsisMojoValidate() {
-        super(new Validate());
+        super(new ValidateMetaModelProcessor());
     }
 
-    static class Validate implements IsisRunnable {
+    static class ValidateMetaModelProcessor implements MetaModelProcessor {
         @Override
-        public void run(final IsisMetaModel isisMetaModel, final IsisMojoReporter reporter) throws MojoFailureException, MojoExecutionException {
+        public void process(final IsisMetaModel isisMetaModel, final Context context) throws MojoFailureException, MojoExecutionException {
             final Collection<ObjectSpecification> objectSpecifications = isisMetaModel.getSpecificationLoader().allSpecifications();
             for (ObjectSpecification objectSpecification : objectSpecifications) {
-                reporter.getLog().debug("loaded: " + objectSpecification.getFullIdentifier());
+                context.getLog().debug("loaded: " + objectSpecification.getFullIdentifier());
             }
 
             final ValidationFailures validationFailures = isisMetaModel.getValidationFailures();
             if (validationFailures.occurred()) {
-                reporter.throwFailureException(validationFailures.getNumberOfMessages() + " problems found.", validationFailures.getMessages());
+                context.throwFailureException(validationFailures.getNumberOfMessages() + " problems found.", validationFailures.getMessages());
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/isis/blob/b1c643ae/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisRunnable.java
----------------------------------------------------------------------
diff --git a/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisRunnable.java b/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisRunnable.java
deleted file mode 100644
index 4298bae..0000000
--- a/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisRunnable.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- *  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.isis.tool.mavenplugin;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.isis.core.metamodel.app.IsisMetaModel;
-
-interface IsisRunnable {
-    public void run(IsisMetaModel isisMetaModel, IsisMojoReporter isisMojo) throws MojoFailureException, MojoExecutionException;
-}

http://git-wip-us.apache.org/repos/asf/isis/blob/b1c643ae/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/MetaModelProcessor.java
----------------------------------------------------------------------
diff --git a/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/MetaModelProcessor.java b/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/MetaModelProcessor.java
new file mode 100644
index 0000000..2b2c688
--- /dev/null
+++ b/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/MetaModelProcessor.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.isis.tool.mavenplugin;
+
+import java.util.Set;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.apache.isis.core.metamodel.app.IsisMetaModel;
+
+interface MetaModelProcessor {
+
+    public interface Context {
+
+        MavenProject getMavenProject();
+
+        Log getLog();
+
+        void logErrors(final String... logMessages);
+
+        void throwFailureException(final String errorMessage, final Set<String> logMessages) throws MojoFailureException;
+
+        void throwFailureException(final String errorMessage, final String... logMessages) throws MojoFailureException;
+
+        void throwExecutionException(final String errorMessage, final Exception e) throws MojoExecutionException;
+    }
+
+    public void process(final IsisMetaModel isisMetaModel, final Context context) throws MojoFailureException, MojoExecutionException;
+}