incubator-easyant-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlboud...@apache.org
Subject svn commit: r1387033 - in /incubator/easyant/core/trunk/src/main/java/org/apache/easyant: core/descriptor/PluginDescriptor.java core/parser/DefaultEasyAntXmlModuleDescriptorParser.java tasks/Import.java tasks/LoadModule.java
Date Tue, 18 Sep 2012 08:04:11 GMT
Author: jlboudart
Date: Tue Sep 18 08:04:10 2012
New Revision: 1387033

URL: http://svn.apache.org/viewvc?rev=1387033&view=rev
Log:
Add support for nested elements in plugins (dependency/exclude/conflict)
We can now override a plugin classpath (use a more recent revision of a given dependency,
or add new dependencies)

Modified:
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/PluginDescriptor.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/tasks/Import.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/PluginDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/PluginDescriptor.java?rev=1387033&r1=1387032&r2=1387033&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/PluginDescriptor.java
(original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/descriptor/PluginDescriptor.java
Tue Sep 18 08:04:10 2012
@@ -17,7 +17,13 @@
  */
 package org.apache.easyant.core.descriptor;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.easyant.core.ivy.InheritableScope;
+import org.apache.ivy.ant.IvyConflict;
+import org.apache.ivy.ant.IvyDependency;
+import org.apache.ivy.ant.IvyExclude;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
 
 /**
@@ -28,32 +34,40 @@ public class PluginDescriptor implements
     private String organisation;
     private String module;
     private String revision;
-    
+
     private String mrid;
-    
+
     private String mode;
     private String as;
-    
+
     private boolean mandatory;
     private String buildConfigurations;
     private InheritableScope inheritScope = InheritableScope.BOTH;
 
     private final ModuleRevisionId sourceModule;
-    private boolean inheritable=true;
-    
+    private boolean inheritable = true;
+
+    private List<IvyDependency> dependencies = new ArrayList<IvyDependency>();
+
+    private List<IvyExclude> excludes = new ArrayList<IvyExclude>();
+
+    private List<IvyConflict> conflicts = new ArrayList<IvyConflict>();
+
     /**
      * Default constructor
      */
     public PluginDescriptor() {
-        sourceModule=null;
+        sourceModule = null;
     }
-    
+
     /**
      * Constructor specifying the source module which was defining the plugin
-     * @param sourceModule a source module
+     * 
+     * @param sourceModule
+     *            a source module
      */
     public PluginDescriptor(ModuleRevisionId sourceModule) {
-        this.sourceModule=sourceModule;
+        this.sourceModule = sourceModule;
     }
 
     /**
@@ -74,8 +88,7 @@ public class PluginDescriptor implements
     public void setModule(String module) {
         this.module = module;
     }
-    
-    
+
     /**
      * Get the organisation of the module to import
      * 
@@ -133,11 +146,10 @@ public class PluginDescriptor implements
         this.mrid = mrid;
     }
 
-
     /**
-     * Get the import mode of a plugin 
+     * Get the import mode of a plugin
      * 
-     * @return a string that represent the import mode (import / include) 
+     * @return a string that represent the import mode (import / include)
      */
     public String getMode() {
         return mode;
@@ -145,7 +157,9 @@ public class PluginDescriptor implements
 
     /**
      * Set the import mode of a plugin
-     * @param mode a string that represent the import mode (import / include)
+     * 
+     * @param mode
+     *            a string that represent the import mode (import / include)
      */
     public void setMode(String mode) {
         this.mode = mode;
@@ -153,6 +167,7 @@ public class PluginDescriptor implements
 
     /**
      * Get the alias name
+     * 
      * @return the alias name
      */
     public String getAs() {
@@ -161,14 +176,17 @@ public class PluginDescriptor implements
 
     /**
      * Set the alias name
-     * @param as the alias name
+     * 
+     * @param as
+     *            the alias name
      */
     public void setAs(String as) {
         this.as = as;
     }
 
     /**
-     * is this plugin mandatory?  
+     * is this plugin mandatory?
+     * 
      * @return true if the plugin is mandatory, false if the plugin can be skipped
      */
     public boolean isMandatory() {
@@ -177,7 +195,9 @@ public class PluginDescriptor implements
 
     /**
      * is this plugin mandatory?
-     * @param mandatory true if the plugin is mandatory, false if the plugin can be skipped
+     * 
+     * @param mandatory
+     *            true if the plugin is mandatory, false if the plugin can be skipped
      */
     public void setMandatory(boolean mandatory) {
         this.mandatory = mandatory;
@@ -185,7 +205,9 @@ public class PluginDescriptor implements
 
     /**
      * set a build configuration name bound to this plugin
-     * @param buildConfigurationName a build configuration name
+     * 
+     * @param buildConfigurationName
+     *            a build configuration name
      */
     public void setBuildConfigurations(String buildConfigurationName) {
         this.buildConfigurations = buildConfigurationName;
@@ -193,6 +215,7 @@ public class PluginDescriptor implements
 
     /**
      * Return a build configuration name bound to this plugin
+     * 
      * @return a build configuration name
      */
     public String getBuildConfigurations() {
@@ -200,7 +223,7 @@ public class PluginDescriptor implements
     }
 
     /**
-     * {@inheritDoc} 
+     * {@inheritDoc}
      */
     public ModuleRevisionId getSourceModule() {
         return sourceModule;
@@ -219,9 +242,32 @@ public class PluginDescriptor implements
     }
 
     public void setInheritable(boolean isIneritable) {
-        this.inheritable=isIneritable;
-        
+        this.inheritable = isIneritable;
+
+    }
+
+    public List<IvyDependency> getDependencies() {
+        return dependencies;
+    }
+
+    public List<IvyExclude> getExcludes() {
+        return excludes;
+    }
+
+    public List<IvyConflict> getConflicts() {
+        return conflicts;
+    }
+
+    public boolean addDependency(IvyDependency dependency) {
+        return dependencies.add(dependency);
+    }
+
+    public boolean addExcludes(IvyExclude exclude) {
+        return excludes.add(exclude);
+    }
+
+    public boolean addConflict(IvyConflict conflict) {
+        return conflicts.add(conflict);
     }
 
-    
 }

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=1387033&r1=1387032&r2=1387033&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 Sep 18 08:04:10 2012
@@ -37,6 +37,9 @@ import org.apache.easyant.core.descripto
 import org.apache.easyant.core.descriptor.PluginDescriptor;
 import org.apache.easyant.core.descriptor.PropertyDescriptor;
 import org.apache.easyant.core.ivy.InheritableScope;
+import org.apache.ivy.ant.IvyConflict;
+import org.apache.ivy.ant.IvyDependency;
+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;
@@ -136,6 +139,15 @@ public class DefaultEasyAntXmlModuleDesc
                 bindTargetStarted(attributes);
             }
 
+            if (name.equals(easyantPrefix + ":dependency") && easyAntState == EasyAntState.PLUGIN)
{
+                pluginDependencyStarted(attributes);
+            }
+            if (name.equals(easyantPrefix + ":exclude") && easyAntState == EasyAntState.PLUGIN)
{
+                pluginExcludeStarted(attributes);
+            }
+            if (name.equals(easyantPrefix + ":conflict") && easyAntState == EasyAntState.PLUGIN)
{
+                pluginConflictStarted(attributes);
+            }
         }
 
         @Override
@@ -240,6 +252,58 @@ public class DefaultEasyAntXmlModuleDesc
             handlePropertyAsAttribute(attributes, conf);
         }
 
+        public void pluginDependencyStarted(Attributes attributes) {
+            IvyDependency ivyDependency = new IvyDependency();
+            String org = getSettings().substitute(attributes.getValue("org"));
+            if (org == null) {
+                org = currentPluginDescriptor.getOrganisation();
+            }
+            ivyDependency.setOrg(org);
+            ivyDependency.setForce(Boolean.valueOf(getSettings().substitute(attributes.getValue("force")))
+                    .booleanValue());
+            ivyDependency.setChanging(Boolean.valueOf(getSettings().substitute(attributes.getValue("changing")))
+                    .booleanValue());
+            String transitiveValue = getSettings().substitute(attributes.getValue("transitive"));
+            boolean transitive = (transitiveValue == null) ? true : Boolean.valueOf(attributes.getValue("transitive"))
+                    .booleanValue();
+            ivyDependency.setTransitive(transitive);
+
+            ivyDependency.setName(getSettings().substitute(attributes.getValue("name")));
+            ivyDependency.setBranch(getSettings().substitute(attributes.getValue("branch")));
+
+            ivyDependency.setRev(getSettings().substitute(attributes.getValue("rev")));
+            currentPluginDescriptor.addDependency(ivyDependency);
+        }
+
+        public void pluginConflictStarted(Attributes attributes) {
+            IvyConflict ivyConflict = new IvyConflict();
+            String org = getSettings().substitute(attributes.getValue("org"));
+            if (org == null) {
+                org = currentPluginDescriptor.getOrganisation();
+            }
+            ivyConflict.setOrg(org);
+            ivyConflict.setModule(getSettings().substitute(attributes.getValue("module")));
+            ivyConflict.setRev(getSettings().substitute(attributes.getValue("rev")));
+            ivyConflict.setManager(getSettings().substitute(attributes.getValue("manager")));
+            ivyConflict.setMatcher(getSettings().substitute(attributes.getValue("matcher")));
+            currentPluginDescriptor.addConflict(ivyConflict);
+        }
+
+        public void pluginExcludeStarted(Attributes attributes) {
+            IvyExclude ivyExclude = new IvyExclude();
+            String org = getSettings().substitute(attributes.getValue("org"));
+            if (org == null) {
+                org = currentPluginDescriptor.getOrganisation();
+            }
+            ivyExclude.setOrg(org);
+            ivyExclude.setModule(getSettings().substitute(attributes.getValue("module")));
+            ivyExclude.setArtifact(getSettings().substitute(attributes.getValue("artifact")));
+            ivyExclude.setType(getSettings().substitute(attributes.getValue("type")));
+            ivyExclude.setExt(getSettings().substitute(attributes.getValue("ext")));
+            ivyExclude.setMatcher(getSettings().substitute(attributes.getValue("matcher")));
+            currentPluginDescriptor.addExcludes(ivyExclude);
+        }
+
         /**
          * handle properties as attribute
          * 

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/Import.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/Import.java?rev=1387033&r1=1387032&r2=1387033&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/Import.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/Import.java Tue Sep
18 08:04:10 2012
@@ -19,10 +19,18 @@ package org.apache.easyant.tasks;
 
 import java.io.IOException;
 import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.easyant.core.BuildConfigurationHelper;
+import org.apache.ivy.ant.EasyAntPluginBridge;
+import org.apache.ivy.ant.IvyConflict;
+import org.apache.ivy.ant.IvyDependency;
+import org.apache.ivy.ant.IvyExclude;
+import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.core.report.ResolveReport;
+import org.apache.ivy.core.settings.IvySettings;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DynamicAttribute;
 import org.apache.tools.ant.Project;
@@ -54,6 +62,12 @@ public class Import extends AbstractImpo
 
     private String mrid;
 
+    private List<IvyDependency> dependencies = new ArrayList<IvyDependency>();
+
+    private List<IvyExclude> excludes = new ArrayList<IvyExclude>();
+
+    private List<IvyConflict> conflicts = new ArrayList<IvyConflict>();
+
     public void execute() {
         ModuleRevisionId moduleRevisionId = null;
         if (mrid != null) {
@@ -96,9 +110,17 @@ public class Import extends AbstractImpo
             log(moduleName + " skipped !");
         } else {
             try {
-                ResolveReport report = getEasyAntIvyInstance().getResolveEngine().resolve(moduleRevisionId,
-                        configureResolveOptions(), isChanging());
-                importModule(moduleRevisionId,report);
+                DefaultModuleDescriptor md = DefaultModuleDescriptor.newCallerInstance(moduleRevisionId,
getMainConf()
+                        .split(","), true, isChanging());
+
+                IvySettings settings = getEasyAntIvyInstance().getSettings();
+                // FIXME: If additionnal dependency are loaded or a superior version of a
dependency is defined it works
+                // as expected
+                // But it doesn't work if you specify a revision lower to original one
+                md = EasyAntPluginBridge.computeModuleDescriptor(md, settings, dependencies,
conflicts, excludes);
+                ResolveReport report = getEasyAntIvyInstance().getResolveEngine()
+                        .resolve(md, configureResolveOptions());
+                importModule(moduleRevisionId, report);
             } catch (ParseException e) {
                 throw new BuildException("Can't parse module descriptor", e);
             } catch (IOException e) {
@@ -203,5 +225,47 @@ public class Import extends AbstractImpo
     public void setMrid(String mrid) {
         this.mrid = mrid;
     }
-    
+
+    public IvyDependency createDependency() {
+        IvyDependency dep = new IvyDependency();
+        dependencies.add(dep);
+        return dep;
+    }
+
+    public IvyExclude createExclude() {
+        IvyExclude ex = new IvyExclude();
+        excludes.add(ex);
+        return ex;
+    }
+
+    public IvyConflict createConflict() {
+        IvyConflict c = new IvyConflict();
+        conflicts.add(c);
+        return c;
+    }
+
+    public List<IvyDependency> getDependencies() {
+        return dependencies;
+    }
+
+    public void setDependencies(List<IvyDependency> dependencies) {
+        this.dependencies = dependencies;
+    }
+
+    public List<IvyExclude> getExcludes() {
+        return excludes;
+    }
+
+    public void setExcludes(List<IvyExclude> excludes) {
+        this.excludes = excludes;
+    }
+
+    public List<IvyConflict> getConflicts() {
+        return conflicts;
+    }
+
+    public void setConflicts(List<IvyConflict> conflicts) {
+        this.conflicts = conflicts;
+    }
+
 }

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=1387033&r1=1387032&r2=1387033&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
Sep 18 08:04:10 2012
@@ -296,6 +296,9 @@ public class LoadModule extends Abstract
                     importTask.setAs(plugin.getAs());
                     importTask.setMandatory(plugin.isMandatory());
                     importTask.setBuildConfigurations(plugin.getBuildConfigurations());
+                    importTask.setDependencies(plugin.getDependencies());
+                    importTask.setConflicts(plugin.getConflicts());
+                    importTask.setExcludes(plugin.getExcludes());
                     initTask(importTask).execute();
                 }
             }



Mime
View raw message