You are viewing a plain text version of this content. The canonical link for it is here.
Posted to easyant-commits@incubator.apache.org by jl...@apache.org on 2012/10/23 18:04:06 UTC

svn commit: r1401371 - in /incubator/easyant/core/trunk/src/main/java/org/apache/easyant: core/descriptor/ core/parser/ core/services/impl/ tasks/

Author: jlboudart
Date: Tue Oct 23 18:04:06 2012
New Revision: 1401371

URL: http://svn.apache.org/viewvc?rev=1401371&view=rev
Log:
refactor  easyantModuleDescriptor
buildtype should be a PluginDescriptor instead of a string

Added:
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/PluginType.java
Modified:
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/DefaultEasyAntDescriptor.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/EasyAntModuleDescriptor.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/DefaultEasyAntXmlModuleDescriptorParser.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/DefaultEasyAntDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/DefaultEasyAntDescriptor.java?rev=1401371&r1=1401370&r2=1401371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/DefaultEasyAntDescriptor.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/DefaultEasyAntDescriptor.java Tue Oct 23 18:04:06 2012
@@ -31,46 +31,45 @@ public class DefaultEasyAntDescriptor im
 
     public DefaultEasyAntDescriptor() {
         // super(md);
-        properties = new HashMap<String,PropertyDescriptor>();
+        properties = new HashMap<String, PropertyDescriptor>();
         plugins = new ArrayList<PluginDescriptor>();
         buildConfigurations = new ArrayList<String>();
         extensionPointsMappings = new ArrayList<ExtensionPointMappingDescriptor>();
     }
 
     private ModuleDescriptor ivyModuleDescriptor;
-    private String buildType;
-    private Map<String,PropertyDescriptor> properties;
+    private PluginDescriptor buildType;
+    private Map<String, PropertyDescriptor> properties;
     private List<PluginDescriptor> plugins;
     private List<String> buildConfigurations;
-    
+
     private List<ExtensionPointMappingDescriptor> extensionPointsMappings;
 
-    public String getBuildType() {
+    public PluginDescriptor getBuildType() {
         return buildType;
     }
 
-    public Map<String,PropertyDescriptor> getProperties() {
+    public Map<String, PropertyDescriptor> getProperties() {
         return properties;
     }
 
-    public void setBuildType(String buildType) {
+    public void setBuildType(PluginDescriptor buildType) {
         this.buildType = buildType;
 
     }
 
-    public void setProperties(Map<String,PropertyDescriptor> properties) {
+    public void setProperties(Map<String, PropertyDescriptor> properties) {
         this.properties = properties;
 
     }
-    
+
     public void addPlugin(PluginDescriptor pluginDescriptor) {
         if (pluginDescriptor == null) {
             throw new IllegalArgumentException("pluginDescriptor argument can't be null");
         }
         this.plugins.add(pluginDescriptor);
     }
-    
-    
+
     public List<PluginDescriptor> getPlugins() {
         return plugins;
     }
@@ -82,19 +81,19 @@ public class DefaultEasyAntDescriptor im
     public List<String> getBuildConfigurations() {
         return buildConfigurations;
     }
-    
+
     public void setIvyModuleDescriptor(ModuleDescriptor ivyModuleDescriptor) {
         this.ivyModuleDescriptor = ivyModuleDescriptor;
     }
 
-    public ModuleDescriptor getIvyModuleDescriptor() {      
+    public ModuleDescriptor getIvyModuleDescriptor() {
         return this.ivyModuleDescriptor;
     }
-    
+
     public String getName() {
         return getIvyModuleDescriptor().getModuleRevisionId().getName();
     }
-    
+
     public String getDescription() {
         return getIvyModuleDescriptor().getDescription();
     }
@@ -102,11 +101,9 @@ public class DefaultEasyAntDescriptor im
     public List<ExtensionPointMappingDescriptor> getExtensionPointsMappings() {
         return extensionPointsMappings;
     }
-    
+
     public void addExtensionPointMapping(ExtensionPointMappingDescriptor extensionPointMappingDescriptor) {
         this.extensionPointsMappings.add(extensionPointMappingDescriptor);
     }
-    
-    
 
 }

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/EasyAntModuleDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/EasyAntModuleDescriptor.java?rev=1401371&r1=1401370&r2=1401371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/EasyAntModuleDescriptor.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/EasyAntModuleDescriptor.java Tue Oct 23 18:04:06 2012
@@ -23,8 +23,7 @@ import java.util.Map;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 
 /**
- * This interface is used to access to all metadata provided in &lt;easyant&gt;
- * tag in a module descriptor
+ * This interface is used to access to all metadata provided in &lt;easyant&gt; tag in a module descriptor
  */
 public interface EasyAntModuleDescriptor {
 
@@ -45,19 +44,17 @@ public interface EasyAntModuleDescriptor
     /**
      * Get the build type defined in the module descriptor
      * 
-     * @return a string that represent the build type module revision id
-     *         (example org.apache.easyant#build-std-java;0.1)
+     * @return a {@link PluginDescriptor} of build type module
      */
-    String getBuildType();
+    PluginDescriptor getBuildType();
 
     /**
      * Set the build type that should be used
      * 
      * @param buildType
-     *            a string that represent the build type module revision id
-     *            (example org.apache.easyant#build-std-java;0.1)
+     *            a {@link PluginDescriptor} of build type module
      */
-    void setBuildType(String buildType);
+    void setBuildType(PluginDescriptor buildType);
 
     /**
      * Get all plugins defined in the module descriptor
@@ -102,16 +99,19 @@ public interface EasyAntModuleDescriptor
      * @return a string representing the module description
      */
     String getDescription();
-    
+
     /**
      * Get all registered extension points mappings
+     * 
      * @return a list of {@link ExtensionPointMappingDescriptor}
      */
     public List<ExtensionPointMappingDescriptor> getExtensionPointsMappings();
-    
+
     /**
-     * Add a {@link ExtensionPointMappingDescriptor} to the list of all registered extension points mappings 
-     * @param extensionPointMappingDescriptor a {@link ExtensionPointMappingDescriptor}
+     * Add a {@link ExtensionPointMappingDescriptor} to the list of all registered extension points mappings
+     * 
+     * @param extensionPointMappingDescriptor
+     *            a {@link ExtensionPointMappingDescriptor}
      */
     public void addExtensionPointMapping(ExtensionPointMappingDescriptor extensionPointMappingDescriptor);
 

Added: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/PluginType.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/PluginType.java?rev=1401371&view=auto
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/PluginType.java (added)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/PluginType.java Tue Oct 23 18:04:06 2012
@@ -0,0 +1,22 @@
+/*
+ *  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.easyant.core.descriptor;
+
+public enum PluginType {
+    BUILDTYPE, PLUGIN
+}

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/DefaultEasyAntXmlModuleDescriptorParser.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/DefaultEasyAntXmlModuleDescriptorParser.java?rev=1401371&r1=1401370&r2=1401371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/DefaultEasyAntXmlModuleDescriptorParser.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/DefaultEasyAntXmlModuleDescriptorParser.java Tue Oct 23 18:04:06 2012
@@ -34,6 +34,7 @@ import org.apache.easyant.core.descripto
 import org.apache.easyant.core.descriptor.EasyAntModuleDescriptor;
 import org.apache.easyant.core.descriptor.ExtensionPointMappingDescriptor;
 import org.apache.easyant.core.descriptor.PluginDescriptor;
+import org.apache.easyant.core.descriptor.PluginType;
 import org.apache.easyant.core.descriptor.PropertyDescriptor;
 import org.apache.easyant.core.ivy.InheritableScope;
 import org.apache.ivy.ant.IvyConflict;
@@ -46,7 +47,6 @@ import org.apache.ivy.ant.IvyExclude;
 import org.apache.ivy.core.IvyContext;
 import org.apache.ivy.core.module.descriptor.Configuration;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
-import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.plugins.parser.ModuleDescriptorParser;
 import org.apache.ivy.plugins.parser.ParserSettings;
 import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser;
@@ -98,20 +98,13 @@ public class DefaultEasyAntXmlModuleDesc
         return parser.getModuleDescriptor();
     }
 
-    public class EasyAntParser extends Parser {
-
-        public final class EasyAntState {
-            public static final int NONE = 0;
-            public static final int EASYANT = 1;
-            public static final int PLUGIN = 2;
-            public static final int PLUGIN_DEPENDENCY = 3;
-
-            private EasyAntState() {
-            }
+    private enum EasyAntState {
+        NONE, EASYANT, PLUGIN, PLUGIN_DEPENDENCY
+    }
 
-        }
+    public class EasyAntParser extends Parser {
 
-        private int easyAntState;
+        private EasyAntState easyAntState;
 
         private DefaultEasyAntDescriptor easyAntModuleDescriptor;
 
@@ -227,54 +220,79 @@ public class DefaultEasyAntXmlModuleDesc
          *            reprensents the plugins attributes
          */
         protected void pluginStarted(Attributes attributes) {
+            easyAntState = EasyAntState.PLUGIN;
+            PluginDescriptor plugin = handleCommonPluginDescriptorAttributes(attributes, PluginType.PLUGIN);
+            // plugin specific attribute
             boolean mandatory = false;
-
             String mandatoryValue = getSettings().substitute(attributes.getValue("mandatory"));
             if (mandatoryValue != null && "true".equals(mandatoryValue)) {
                 mandatory = true;
             }
-            String conf = getSettings().substitute(attributes.getValue("conf"));
+            plugin.setMandatory(mandatory);
+            handleInheritedScopeAttribute(attributes, plugin);
 
-            easyAntState = EasyAntState.PLUGIN;
-            PluginDescriptor plugin = new PluginDescriptor(getMd().getModuleRevisionId());
+            currentPluginDescriptor = plugin;
+            easyAntModuleDescriptor.addPlugin(plugin);
+
+        }
 
+        /**
+         * Parsing the easyant tag
+         * 
+         * @param attributes
+         *            reprensents the easyant attributes
+         */
+        protected void eaBuildStarted(Attributes attributes) {
+            easyAntState = EasyAntState.EASYANT;
+            PluginDescriptor buildtype = handleCommonPluginDescriptorAttributes(attributes, PluginType.BUILDTYPE);
+            // a build type cannot be skipped
+            buildtype.setMandatory(true);
+            easyAntModuleDescriptor.setBuildType(buildtype);
+        }
+
+        private PluginDescriptor handleCommonPluginDescriptorAttributes(Attributes attributes, PluginType pluginType) {
+            PluginDescriptor pluginDescriptor = new PluginDescriptor();
             String mrid = getSettings().substitute(attributes.getValue("mrid"));
             if (mrid != null) {
                 if (!mrid.matches(".*#.*")) {
-                    Message.debug("No organisation specified for plugin " + mrid + " using the default one");
-                    mrid = EasyAntConstants.EASYANT_PLUGIN_ORGANISATION + "#" + mrid;
+                    if (pluginType == PluginType.BUILDTYPE) {
+                        Message.debug("No organisation specified for buildtype " + mrid + " using the default one");
+                        mrid = EasyAntConstants.EASYANT_BUILDTYPES_ORGANISATION + "#" + mrid;
+                    } else {
+                        Message.debug("No organisation specified for plugin " + mrid + " using the default one");
+                        mrid = EasyAntConstants.EASYANT_PLUGIN_ORGANISATION + "#" + mrid;
+                    }
                 }
-                plugin.setMrid(mrid);
+                pluginDescriptor.setMrid(mrid);
             } else {
                 String org = attributes.getValue("org") != null ? attributes.getValue("org") : attributes
                         .getValue("organisation");
                 org = getSettings().substitute(org);
                 if (org == null) {
-                    Message.debug("No organisation specified for plugin " + mrid + " using the default one");
-                    org = EasyAntConstants.EASYANT_PLUGIN_ORGANISATION;
-
+                    if (pluginType == PluginType.BUILDTYPE) {
+                        Message.debug("No organisation specified for buildtype " + mrid + " using the default one");
+                        org = EasyAntConstants.EASYANT_BUILDTYPES_ORGANISATION;
+                    } else {
+                        Message.debug("No organisation specified for plugin " + mrid + " using the default one");
+                        org = EasyAntConstants.EASYANT_PLUGIN_ORGANISATION;
+                    }
                 }
                 String module = getSettings().substitute(attributes.getValue("module"));
                 String revision = attributes.getValue("rev") != null ? attributes.getValue("rev") : attributes
                         .getValue("revision");
                 revision = getSettings().substitute(revision);
-                plugin.setOrganisation(org);
-                plugin.setModule(module);
-                plugin.setRevision(revision);
-
+                pluginDescriptor.setOrganisation(org);
+                pluginDescriptor.setModule(module);
+                pluginDescriptor.setRevision(revision);
             }
-            plugin.setMode(getSettings().substitute(attributes.getValue("mode")));
-
-            plugin.setMandatory(mandatory);
-            plugin.setAs(getSettings().substitute(attributes.getValue("as")));
-            plugin.setBuildConfigurations(conf);
 
-            handleInheritedScopeAttribute(attributes, plugin);
-
-            currentPluginDescriptor = plugin;
-            easyAntModuleDescriptor.addPlugin(plugin);
+            String conf = getSettings().substitute(attributes.getValue("conf"));
+            pluginDescriptor.setBuildConfigurations(conf);
 
+            pluginDescriptor.setMode(getSettings().substitute(attributes.getValue("mode")));
+            pluginDescriptor.setAs(getSettings().substitute(attributes.getValue("as")));
             handlePropertyAsAttribute(attributes, conf);
+            return pluginDescriptor;
         }
 
         public void pluginDependencyStarted(Attributes attributes) {
@@ -397,42 +415,6 @@ public class DefaultEasyAntXmlModuleDesc
         }
 
         /**
-         * Parsing the easyant tag
-         * 
-         * @param attributes
-         *            reprensents the easyant attributes
-         */
-        protected void eaBuildStarted(Attributes attributes) {
-            easyAntState = EasyAntState.EASYANT;
-            String mrid = getSettings().substitute(attributes.getValue("mrid"));
-            if (mrid != null) {
-                if (!mrid.matches(".*#.*")) {
-                    Message.debug("No organisation specified for buildtype " + mrid + " using the default one");
-                    mrid = EasyAntConstants.EASYANT_BUILDTYPES_ORGANISATION + "#" + mrid;
-                }
-                easyAntModuleDescriptor.setBuildType(mrid);
-            } else {
-                String org = attributes.getValue("org") != null ? attributes.getValue("org") : attributes
-                        .getValue("organisation");
-                org = getSettings().substitute(org);
-                if (org == null) {
-                    Message.debug("No organisation specified for buildtype " + mrid + " using the default one");
-                    org = EasyAntConstants.EASYANT_BUILDTYPES_ORGANISATION;
-
-                }
-                String module = getSettings().substitute(attributes.getValue("module"));
-                String revision = attributes.getValue("rev") != null ? attributes.getValue("rev") : attributes
-                        .getValue("revision");
-                revision = getSettings().substitute(revision);
-                ModuleRevisionId moduleRevisionId = ModuleRevisionId.newInstance(org, module, revision);
-
-                easyAntModuleDescriptor.setBuildType(moduleRevisionId.toString());
-            }
-
-            handlePropertyAsAttribute(attributes, null);
-        }
-
-        /**
          * Parsing the bindtarget tag
          * 
          * @param attributes
@@ -570,7 +552,8 @@ public class DefaultEasyAntXmlModuleDesc
          *            an other module descriptor
          * @throws ParseException
          */
-        protected void mergeWithOtherModuleDescriptor(List extendTypes, ModuleDescriptor parent) throws ParseException {
+        protected void mergeWithOtherModuleDescriptor(@SuppressWarnings("rawtypes") List extendTypes,
+                ModuleDescriptor parent) throws ParseException {
             super.mergeWithOtherModuleDescriptor(extendTypes, parent);
             if (parent.getParser() instanceof DefaultEasyAntXmlModuleDescriptorParser) {
                 DefaultEasyAntXmlModuleDescriptorParser parser = (DefaultEasyAntXmlModuleDescriptorParser) parent

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java?rev=1401371&r1=1401370&r2=1401371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java Tue Oct 23 18:04:06 2012
@@ -30,6 +30,7 @@ import org.apache.easyant.core.EasyAntCo
 import org.apache.easyant.core.EasyAntMagicNames;
 import org.apache.easyant.core.ant.ProjectUtils;
 import org.apache.easyant.core.descriptor.EasyAntModuleDescriptor;
+import org.apache.easyant.core.descriptor.PluginType;
 import org.apache.easyant.core.descriptor.PropertyDescriptor;
 import org.apache.easyant.core.parser.DefaultEasyAntXmlModuleDescriptorParser;
 import org.apache.easyant.core.parser.EasyAntModuleDescriptorParser;
@@ -521,9 +522,4 @@ public class DefaultPluginServiceImpl im
     public EasyAntReport generateEasyAntReport(File moduleDescriptor) throws Exception {
         return generateEasyAntReport(moduleDescriptor, null, null);
     }
-
-    private enum PluginType {
-        BUILDTYPE, PLUGIN
-    }
-
 }

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java?rev=1401371&r1=1401370&r2=1401371&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/LoadModule.java Tue Oct 23 18:04:06 2012
@@ -284,11 +284,21 @@ public class LoadModule extends Abstract
                 }
             }
             if (md.getBuildType() != null) {
-                Import importTask = new Import();
-                importTask.setMrid(md.getBuildType());
-                importTask.setTaskType("antlib:org.apache.easyant:import");
-                getOwningTarget().addTask(importTask);
-                initTask(importTask).execute();
+                if (canInherit(md.getBuildType(), currentModule)) {
+                    Import importTask = new Import();
+                    importTask.setMrid(md.getBuildType().getMrid());
+                    importTask.setMode(md.getBuildType().getMode());
+                    importTask.setAs(md.getBuildType().getAs());
+                    importTask.setMandatory(md.getBuildType().isMandatory());
+                    importTask.setBuildConfigurations(md.getBuildType().getBuildConfigurations());
+                    importTask.setDependencies(md.getBuildType().getDependencies());
+                    importTask.setConflicts(md.getBuildType().getConflicts());
+                    importTask.setExcludes(md.getBuildType().getExcludes());
+
+                    importTask.setTaskType("antlib:org.apache.easyant:import");
+                    getOwningTarget().addTask(importTask);
+                    initTask(importTask).execute();
+                }
             }
             for (Iterator<?> iterator = md.getPlugins().iterator(); iterator.hasNext();) {
                 PluginDescriptor plugin = (PluginDescriptor) iterator.next();