incubator-easyant-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlboud...@apache.org
Subject svn commit: r1404027 - in /incubator/easyant/core/trunk/src: main/java/org/apache/easyant/core/descriptor/ main/java/org/apache/easyant/core/parser/ main/java/org/apache/easyant/tasks/ main/resources/org/apache/easyant/ test/java/org/apache/easyant/cor...
Date Wed, 31 Oct 2012 08:30:55 GMT
Author: jlboudart
Date: Wed Oct 31 08:30:54 2012
New Revision: 1404027

URL: http://svn.apache.org/viewvc?rev=1404027&view=rev
Log:
add a new easyant element : configure-project
this new element can define for the moment defaulttarget / basedir

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/tasks/LoadModule.java
    incubator/easyant/core/trunk/src/main/resources/org/apache/easyant/antlib.xml
    incubator/easyant/core/trunk/src/test/java/org/apache/easyant/core/PropertiesAsAttributesTest.java
    incubator/easyant/core/trunk/src/test/resources/org/apache/easyant/core/propertiesAsAttributes.ivy

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=1404027&r1=1404026&r2=1404027&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
Wed Oct 31 08:30:54 2012
@@ -45,6 +45,8 @@ public class DefaultEasyAntDescriptor im
 
     private List<ExtensionPointMappingDescriptor> extensionPointsMappings;
 
+    private ConfigureProjectDescriptor configureProjectDescriptor;
+
     public PluginDescriptor getBuildType() {
         return buildType;
     }
@@ -106,4 +108,11 @@ public class DefaultEasyAntDescriptor im
         this.extensionPointsMappings.add(extensionPointMappingDescriptor);
     }
 
+    public ConfigureProjectDescriptor getConfigureProjectDescriptor() {
+        return configureProjectDescriptor;
+    }
+
+    public void setConfigureProjectDescriptor(ConfigureProjectDescriptor configureProjectDescriptor)
{
+        this.configureProjectDescriptor = configureProjectDescriptor;
+    }
 }

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=1404027&r1=1404026&r2=1404027&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
Wed Oct 31 08:30:54 2012
@@ -115,4 +115,18 @@ public interface EasyAntModuleDescriptor
      */
     public void addExtensionPointMapping(ExtensionPointMappingDescriptor extensionPointMappingDescriptor);
 
-}
+    /**
+     * Get configure project descriptor (defining basedir/defaulttarget etc...)
+     * 
+     * @return a {@link ConfigureProjectDescriptor}
+     */
+    public ConfigureProjectDescriptor getConfigureProjectDescriptor();
+
+    /**
+     * Set configure project descriptor (defining basedir/defaulttarget etc...)
+     * 
+     * @param configureProjectDescriptor
+     *            a {@link ConfigureProjectDescriptor}
+     */
+    public void setConfigureProjectDescriptor(ConfigureProjectDescriptor configureProjectDescriptor);
+}
\ No newline at end of file

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=1404027&r1=1404026&r2=1404027&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
Wed Oct 31 08:30:54 2012
@@ -30,6 +30,7 @@ import java.util.Map.Entry;
 
 import org.apache.easyant.core.EasyAntConstants;
 import org.apache.easyant.core.descriptor.AdvancedInheritableItem;
+import org.apache.easyant.core.descriptor.ConfigureProjectDescriptor;
 import org.apache.easyant.core.descriptor.DefaultEasyAntDescriptor;
 import org.apache.easyant.core.descriptor.EasyAntModuleDescriptor;
 import org.apache.easyant.core.descriptor.ExtensionPointMappingDescriptor;
@@ -99,7 +100,7 @@ public class DefaultEasyAntXmlModuleDesc
     }
 
     private enum EasyAntState {
-        NONE, EASYANT, PLUGIN, PLUGIN_DEPENDENCY
+        NONE, BUILDTYPE, PLUGIN, PLUGIN_DEPENDENCY, CONFIGURE_PROJECT
     }
 
     public class EasyAntParser extends Parser {
@@ -134,6 +135,12 @@ public class DefaultEasyAntXmlModuleDesc
             if (name.equals(easyantPrefix + ":bindtarget") && State.EXTRA_INFO ==
getState()) {
                 bindTargetStarted(attributes);
             }
+            if (name.equals(easyantPrefix + ":configure-project") && State.EXTRA_INFO
== getState()) {
+                if (easyAntState != EasyAntState.NONE) {
+                    throw new SAXException("configure-project is not supported as a nested
element");
+                }
+                configureProjectStarted(attributes);
+            }
 
             if (name.equals(easyantPrefix + ":dependency") && easyAntState == EasyAntState.PLUGIN)
{
                 pluginDependencyStarted(attributes);
@@ -169,6 +176,10 @@ public class DefaultEasyAntXmlModuleDesc
             if (name.equals(easyantPrefix + ":dependency") && easyAntState == EasyAntState.PLUGIN_DEPENDENCY)
{
                 endPluginDependency();
             }
+
+            if (name.equals(easyantPrefix + ":configure-project") && easyAntState
== EasyAntState.CONFIGURE_PROJECT) {
+                easyAntState = EasyAntState.NONE;
+            }
         }
 
         protected void endPlugin() {
@@ -193,7 +204,6 @@ public class DefaultEasyAntXmlModuleDesc
                     easyantPrefix = (String) namespace.getKey();
                 }
             }
-
         }
 
         @Override
@@ -214,6 +224,25 @@ public class DefaultEasyAntXmlModuleDesc
         }
 
         /**
+         * Parses configure-project tag
+         * 
+         * @param attributes
+         *            represents configure project attributes
+         */
+        protected void configureProjectStarted(Attributes attributes) {
+            easyAntState = EasyAntState.CONFIGURE_PROJECT;
+            ConfigureProjectDescriptor configureProjectDescriptor = new ConfigureProjectDescriptor();
+            String basedir = getSettings().substitute(attributes.getValue("basedir"));
+            String defaultTarget = getSettings().substitute(attributes.getValue("defaulttarget"));
+            configureProjectDescriptor.setBasedir(basedir);
+            configureProjectDescriptor.setDefaultTarget(defaultTarget);
+            handlePropertyAsAttribute(attributes, Arrays.asList("basedir", "defaulttarget"),
+                    configureProjectDescriptor, null);
+            handleInheritedScopeAttribute(attributes, configureProjectDescriptor);
+            easyAntModuleDescriptor.setConfigureProjectDescriptor(configureProjectDescriptor);
+        }
+
+        /**
          * Parsing the plugin tag
          * 
          * @param attributes
@@ -243,7 +272,7 @@ public class DefaultEasyAntXmlModuleDesc
          *            reprensents the easyant attributes
          */
         protected void eaBuildStarted(Attributes attributes) {
-            easyAntState = EasyAntState.EASYANT;
+            easyAntState = EasyAntState.BUILDTYPE;
             PluginDescriptor buildtype = handleCommonPluginDescriptorAttributes(attributes,
PluginType.BUILDTYPE);
             // a build type cannot be skipped
             buildtype.setMandatory(true);
@@ -291,7 +320,7 @@ public class DefaultEasyAntXmlModuleDesc
 
             pluginDescriptor.setMode(getSettings().substitute(attributes.getValue("mode")));
             pluginDescriptor.setAs(getSettings().substitute(attributes.getValue("as")));
-            handlePropertyAsAttribute(attributes, conf);
+            handlePropertyAsAttribute(attributes, Arrays.asList(PLUGIN_REGULAR_ATTRIBUTES),
pluginDescriptor, conf);
             return pluginDescriptor;
         }
 
@@ -374,19 +403,27 @@ public class DefaultEasyAntXmlModuleDesc
          * 
          * @param attributes
          *            a set of attributes
-         * @param conf
+         * @param ignoredAttributes
+         *            a list of ignored attributes
+         * @param parentNode
+         *            parent node used to apply some attributes to subelements (can be null)
+         * @param buildConf
          *            build configurations where this property should be applied (can be
null)
+         * 
          */
-        protected void handlePropertyAsAttribute(Attributes attributes, String conf) {
-            List<String> ignored = Arrays.asList(PLUGIN_REGULAR_ATTRIBUTES);
+        private void handlePropertyAsAttribute(Attributes attributes, List<String>
ignoredAttributes,
+                AdvancedInheritableItem parentNode, String buildConf) {
             for (int i = 0; i < attributes.getLength(); i++) {
-                if (!ignored.contains(attributes.getQName(i))) {
+                if (!ignoredAttributes.contains(attributes.getQName(i))) {
                     String propertyName = attributes.getQName(i);
                     String value = IvyContext.getContext().getSettings().substitute(attributes.getValue(i));
                     PropertyDescriptor property = new PropertyDescriptor(propertyName);
                     property.setValue(value);
-                    property.setBuildConfigurations(conf);
-                    applyInheritableItemAttributesFromPlugin(property);
+                    property.setBuildConfigurations(buildConf);
+                    if (parentNode != null) {
+                        property.setInheritScope(parentNode.getInheritScope());
+                        property.setInheritable(parentNode.isInheritable());
+                    }
                     easyAntModuleDescriptor.getProperties().put(propertyName, property);
                 }
             }
@@ -487,7 +524,7 @@ public class DefaultEasyAntXmlModuleDesc
                     property.setValue(value);
                     property.setBuildConfigurations(conf);
 
-                    applyInheritableItemAttributesFromPlugin(property);
+                    applyInheritableItemAttributesFromParentNode(property);
                     // override with explicit inherited scope attributes
                     handleInheritedScopeAttribute(attributes, property);
 
@@ -506,7 +543,7 @@ public class DefaultEasyAntXmlModuleDesc
                 property.setValue(value);
                 property.setBuildConfigurations(conf);
 
-                applyInheritableItemAttributesFromPlugin(property);
+                applyInheritableItemAttributesFromParentNode(property);
                 // override with explicit inherited scope attributes
                 handleInheritedScopeAttribute(attributes, property);
 
@@ -517,12 +554,19 @@ public class DefaultEasyAntXmlModuleDesc
         /**
          * Apply {@link AdvancedInheritableItem} attributes from current plugin
          * 
-         * @param property
+         * @param currentItem
          */
-        private void applyInheritableItemAttributesFromPlugin(PropertyDescriptor property)
{
-            if (EasyAntState.PLUGIN == easyAntState) {
-                property.setInheritable(currentPluginDescriptor.isInheritable());
-                property.setInheritScope(currentPluginDescriptor.getInheritScope());
+        private void applyInheritableItemAttributesFromParentNode(AdvancedInheritableItem
currentItem) {
+            AdvancedInheritableItem parentNode = null;
+            if (easyAntState == EasyAntState.PLUGIN) {
+                parentNode = currentPluginDescriptor;
+            } else if (easyAntState == EasyAntState.CONFIGURE_PROJECT) {
+                parentNode = easyAntModuleDescriptor.getConfigureProjectDescriptor();
+            }
+
+            if (parentNode != null) {
+                currentItem.setInheritable(parentNode.isInheritable());
+                currentItem.setInheritScope(parentNode.getInheritScope());
             }
         }
 
@@ -540,6 +584,7 @@ public class DefaultEasyAntXmlModuleDesc
                 mergeEasyantProperties(parser.getEasyAntModuleDescriptor().getProperties());
                 mergeEasyantPlugins(parser.getEasyAntModuleDescriptor().getPlugins());
                 mergeBindTargets(parser.getEasyAntModuleDescriptor().getExtensionPointsMappings());
+                mergeConfigureProject(parser.getEasyAntModuleDescriptor().getConfigureProjectDescriptor());
             }
         }
 
@@ -568,6 +613,9 @@ public class DefaultEasyAntXmlModuleDesc
                 if (extendTypes.contains("bindtarget")) {
                     mergeBindTargets(parser.getEasyAntModuleDescriptor().getExtensionPointsMappings());
                 }
+                if (extendTypes.contains("configure-project")) {
+                    mergeConfigureProject(parser.getEasyAntModuleDescriptor().getConfigureProjectDescriptor());
+                }
             }
 
         }
@@ -631,6 +679,31 @@ public class DefaultEasyAntXmlModuleDesc
         }
 
         /**
+         * Merge configure project
+         * 
+         * @param configureProjectDescriptor
+         *            {@link ConfigureProjectDescriptor} that will be merged with current
one
+         */
+        protected void mergeConfigureProject(ConfigureProjectDescriptor configureProjectDescriptor)
{
+            if (configureProjectDescriptor != null && configureProjectDescriptor.isInheritable())
{
+                StringBuilder sb = new StringBuilder("Merging configure project : ");
+                sb.append(configureProjectDescriptor.toString());
+                if (configureProjectDescriptor.getSourceModule() != null) {
+                    sb.append(" from ").append(configureProjectDescriptor.getSourceModule().toString());
+                }
+                Message.debug(sb.toString());
+
+                ConfigureProjectDescriptor currentDescriptor = easyAntModuleDescriptor.getConfigureProjectDescriptor();
+                if (currentDescriptor == null) {
+                    currentDescriptor = new ConfigureProjectDescriptor();
+                    easyAntModuleDescriptor.setConfigureProjectDescriptor(configureProjectDescriptor);
+                }
+                currentDescriptor.setDefaultTarget(configureProjectDescriptor.getDefaultTarget());
+            }
+
+        }
+
+        /**
          * Get the default parent location
          * 
          * @return a string that represents the default parent location

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=1404027&r1=1404026&r2=1404027&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 Wed
Oct 31 08:30:54 2012
@@ -28,6 +28,7 @@ import org.apache.easyant.core.BuildConf
 import org.apache.easyant.core.EasyAntConstants;
 import org.apache.easyant.core.EasyAntMagicNames;
 import org.apache.easyant.core.descriptor.AdvancedInheritableItem;
+import org.apache.easyant.core.descriptor.ConfigureProjectDescriptor;
 import org.apache.easyant.core.descriptor.EasyAntModuleDescriptor;
 import org.apache.easyant.core.descriptor.ExtensionPointMappingDescriptor;
 import org.apache.easyant.core.descriptor.PluginDescriptor;
@@ -283,6 +284,16 @@ public class LoadModule extends Abstract
                     initTask(propTask).execute();
                 }
             }
+            if (md.getConfigureProjectDescriptor() != null) {
+                ConfigureProjectDescriptor descriptor = md.getConfigureProjectDescriptor();
+                ConfigureProject configureProject = new ConfigureProject();
+                configureProject.setDefaultTarget(descriptor.getDefaultTarget());
+                configureProject.setBasedir(descriptor.getBasedir());
+                configureProject.setTaskType("antlib:org.apache.easyant:configure-project");
+                getOwningTarget().addTask(configureProject);
+                initTask(configureProject).execute();
+            }
+
             if (md.getBuildType() != null) {
                 if (canInherit(md.getBuildType(), currentModule)) {
                     Import importTask = new Import();
@@ -385,7 +396,7 @@ public class LoadModule extends Abstract
         ModuleDescriptorParser mdp = null;
         EasyAntModuleDescriptorParser parser = null;
         try {
-            mdp = ModuleDescriptorParserRegistry.getInstance().getParser(new URLResource(file.toURL()));
+            mdp = ModuleDescriptorParserRegistry.getInstance().getParser(new URLResource(file.toURI().toURL()));
         } catch (MalformedURLException e) {
             throw new BuildException("Impossible to find a parser for " + file.getName());
         }

Modified: incubator/easyant/core/trunk/src/main/resources/org/apache/easyant/antlib.xml
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/resources/org/apache/easyant/antlib.xml?rev=1404027&r1=1404026&r2=1404027&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/resources/org/apache/easyant/antlib.xml (original)
+++ incubator/easyant/core/trunk/src/main/resources/org/apache/easyant/antlib.xml Wed Oct
31 08:30:54 2012
@@ -30,6 +30,8 @@
     <taskdef name="searchmodule" classname="org.apache.easyant.tasks.SearchModule"/>
     
     <taskdef name="configure-build-scoped-repository" classname="org.apache.easyant.tasks.ConfigureBuildScopedRepository"/>

+    <taskdef name="configure-project" classname="org.apache.easyant.tasks.ConfigureProject"/>

+
     
     <taskdef name="findclasspath" classname="org.apache.easyant.tasks.findclasspath.FindClasspathTask"/>
     <typedef name="environment-strategy" classname="org.apache.easyant.tasks.findclasspath.EnvironmentStrategy"/>

Modified: incubator/easyant/core/trunk/src/test/java/org/apache/easyant/core/PropertiesAsAttributesTest.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/test/java/org/apache/easyant/core/PropertiesAsAttributesTest.java?rev=1404027&r1=1404026&r2=1404027&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/test/java/org/apache/easyant/core/PropertiesAsAttributesTest.java
(original)
+++ incubator/easyant/core/trunk/src/test/java/org/apache/easyant/core/PropertiesAsAttributesTest.java
Wed Oct 31 08:30:54 2012
@@ -17,6 +17,8 @@
  */
 package org.apache.easyant.core;
 
+import junit.framework.Assert;
+
 import org.apache.tools.ant.Project;
 import org.junit.Before;
 import org.junit.Test;
@@ -44,6 +46,12 @@ public class PropertiesAsAttributesTest 
     }
 
     @Test
+    public void shouldHandlePropertiesInConfigureProject() {
+        Assert.assertEquals("package", project.getDefaultTarget());
+        assertPropertyEquals("my.property.inconfigureproject", "true");
+    }
+
+    @Test
     public void shouldHandlePropertiesInBuildConfiguration() {
         conf.getActiveBuildConfigurations().add("myBuild");
 

Modified: incubator/easyant/core/trunk/src/test/resources/org/apache/easyant/core/propertiesAsAttributes.ivy
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/test/resources/org/apache/easyant/core/propertiesAsAttributes.ivy?rev=1404027&r1=1404026&r2=1404027&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/test/resources/org/apache/easyant/core/propertiesAsAttributes.ivy
(original)
+++ incubator/easyant/core/trunk/src/test/resources/org/apache/easyant/core/propertiesAsAttributes.ivy
Wed Oct 31 08:30:54 2012
@@ -19,7 +19,7 @@
         <ea:build mrid="org.apache.easyant.buildtypes#build-std-java;0.9" my.property.inbuildtype="true"/>
         <ea:plugin module="javadoc" revision="0.9" my.property.inplugin="true"/>
         <ea:plugin module="javadoc" revision="0.9" my-dashes="true" my.property.inconf="true"
conf="myBuild"/>
-        
+        <ea:configure-project defaulttarget="package" my.property.inconfigureproject="true"/>
      
     </info>
     <configurations>
         <conf name="default" visibility="public" description="runtime dependencies and
master artifact can be used with this conf"/>



Mime
View raw message