incubator-easyant-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlboud...@apache.org
Subject svn commit: r1390738 - in /incubator/easyant/core/trunk/src: main/java/org/apache/easyant/core/ant/ main/java/org/apache/easyant/core/report/ main/java/org/apache/easyant/core/services/impl/ main/java/org/apache/easyant/tasks/ test/java/org/apache/easy...
Date Wed, 26 Sep 2012 21:31:32 GMT
Author: jlboudart
Date: Wed Sep 26 21:31:32 2012
New Revision: 1390738

URL: http://svn.apache.org/viewvc?rev=1390738&view=rev
Log:
Update PluginServiceTest and fix various bug with our new implementation of PluginService.
All tests are green

Modified:
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/ProjectUtils.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/EasyAntReport.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/ImportedModuleReport.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/XMLEasyAntReportWriter.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/AbstractEasyAntTask.java
    incubator/easyant/core/trunk/src/test/java/org/apache/easyant/core/services/PluginServiceTest.java

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/ProjectUtils.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/ProjectUtils.java?rev=1390738&r1=1390737&r2=1390738&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/ProjectUtils.java
(original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/ProjectUtils.java
Wed Sep 26 21:31:32 2012
@@ -185,5 +185,4 @@ public class ProjectUtils {
             }
         }
     }
-
 }

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/EasyAntReport.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/EasyAntReport.java?rev=1390738&r1=1390737&r2=1390738&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/EasyAntReport.java
(original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/EasyAntReport.java
Wed Sep 26 21:31:32 2012
@@ -257,7 +257,7 @@ public class EasyAntReport {
         if (propertyName == null || propertyDescriptor == null) {
             throw new IllegalArgumentException("propertyName and propertyDescriptor cannot
be null");
         }
-        this.propertyReports.put(propertyName, propertyDescriptor);
+        addProperty(propertyDescriptor, propertyReports);
     }
 
     /**
@@ -298,22 +298,8 @@ public class EasyAntReport {
                 if (importedModuleReport.getEasyantReport() != null) {
                     Map<String, PropertyDescriptor> subproperties = importedModuleReport.getEasyantReport()
                             .getAvailableProperties();
-                    for (String propName : subproperties.keySet()) {
-                        PropertyDescriptor propertyToInsert = subproperties.get(propName);
-                        if (availableProperties.containsKey(propName)) {
-                            PropertyDescriptor propertyDescriptor = (PropertyDescriptor)
availableProperties
-                                    .get(propName);
-
-                            if (propertyDescriptor.getDescription() == null
-                                    && propertyToInsert.getDescription() != null)
{
-                                propertyDescriptor.setDescription(propertyToInsert.getDescription());
-                                propertyDescriptor.setRequired(propertyToInsert.isRequired());
-                                propertyDescriptor.setDefaultValue(propertyToInsert.getDefaultValue());
-                                availableProperties.put(propName, propertyDescriptor);
-                            }
-
-                        } else
-                            availableProperties.put(propName, propertyToInsert);
+                    for (PropertyDescriptor propertyDescriptor : subproperties.values())
{
+                        addProperty(propertyDescriptor, availableProperties);
                     }
                 }
             }
@@ -321,6 +307,27 @@ public class EasyAntReport {
         return availableProperties;
     }
 
+    private void addProperty(PropertyDescriptor propertyDescriptor, Map<String, PropertyDescriptor>
availableProperties) {
+        if (availableProperties.containsKey(propertyDescriptor.getName())) {
+            PropertyDescriptor existingProperty = availableProperties.get(propertyDescriptor.getName());
+            if (existingProperty.getDescription() == null) {
+                existingProperty.setDescription(propertyDescriptor.getDescription());
+            }
+            if (existingProperty.getBuildConfigurations() == null) {
+                existingProperty.setBuildConfigurations(propertyDescriptor.getBuildConfigurations());
+            }
+            if (existingProperty.getDefaultValue() == null) {
+                existingProperty.setDefaultValue(propertyDescriptor.getDefaultValue());
+            }
+            if (existingProperty.getValue() == null) {
+                existingProperty.setValue(propertyDescriptor.getValue());
+            }
+            availableProperties.put(propertyDescriptor.getName(), existingProperty);
+        } else {
+            availableProperties.put(propertyDescriptor.getName(), propertyDescriptor);
+        }
+    }
+
     /**
      * This utilitary function allow us to retrieve a list of all targetReport available
in this module and in all
      * imported subModules
@@ -392,7 +399,7 @@ public class EasyAntReport {
         for (int i = 0; i < extensionPoints.size(); i++) {
             ExtensionPointReport extensionPoint = extensionPoints.get(i);
             for (TargetReport target : targets) {
-                if (target.getExtensionPoint() != null && target.getExtensionPoint().equals(extensionPoint.getName()))
{
+                if (extensionPoint.getName().equals(target.getExtensionPoint())) {
                     extensionPoint.addTargetReport(target);
                     extensionPoints.set(i, extensionPoint);
                 }

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/ImportedModuleReport.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/ImportedModuleReport.java?rev=1390738&r1=1390737&r2=1390738&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/ImportedModuleReport.java
(original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/ImportedModuleReport.java
Wed Sep 26 21:31:32 2012
@@ -67,11 +67,11 @@ public class ImportedModuleReport {
         this.moduleMrid = moduleMrid;
     }
 
-    public String getType() {
+    public String getMode() {
         return type;
     }
 
-    public void setType(String type) {
+    public void setMode(String type) {
         this.type = type;
     }
 

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/XMLEasyAntReportWriter.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/XMLEasyAntReportWriter.java?rev=1390738&r1=1390737&r2=1390738&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/XMLEasyAntReportWriter.java
(original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/report/XMLEasyAntReportWriter.java
Wed Sep 26 21:31:32 2012
@@ -413,7 +413,7 @@ public class XMLEasyAntReportWriter {
                 ModuleRevisionId mrid = ModuleRevisionId.parse(importedModuleReport.getModuleMrid());
                 importedModule.append("\t\t\t<import organisation=\"").append(mrid.getOrganisation())
                         .append("\" name=\"").append(mrid.getName()).append("\" revision=\"")
-                        .append(mrid.getRevision()).append("\" type=\"").append(importedModuleReport.getType())
+                        .append(mrid.getRevision()).append("\" type=\"").append(importedModuleReport.getMode())
                         .append("\"");
 
             } catch (IllegalArgumentException e) {
@@ -421,7 +421,7 @@ public class XMLEasyAntReportWriter {
                 importedModule.append("                        <import organisation=\"")
                         .append(importedModuleReport.getModuleMrid()).append("\" name=\"").append("null")
                         .append("\" revision=\"").append("null").append("\" type=\"")
-                        .append(importedModuleReport.getType()).append("\"");
+                        .append(importedModuleReport.getMode()).append("\"");
 
             }
             importedModule.append(" mandatory=\"");

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=1390738&r1=1390737&r2=1390738&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
Wed Sep 26 21:31:32 2012
@@ -66,9 +66,9 @@ import org.apache.tools.ant.ExtensionPoi
 import org.apache.tools.ant.Location;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.ProjectHelper;
-import org.apache.tools.ant.PropertyHelper;
 import org.apache.tools.ant.Target;
 import org.apache.tools.ant.Task;
+import org.apache.tools.ant.UnknownElement;
 import org.apache.tools.ant.taskdefs.Property;
 import org.apache.tools.ant.types.Path;
 
@@ -225,57 +225,59 @@ public class DefaultPluginServiceImpl im
                 if (taskClass == null) {
                     continue;
                 }
-                if (ParameterTask.class.getName().equals(taskClass.getName())) {
-                    handleParameterTask(task, eaReport);
+                if (ParameterTask.class.isAssignableFrom(taskClass)) {
+                    ParameterTask parameterTask = (ParameterTask) maybeConfigureTask(task);
+                    handleParameterTask(parameterTask, eaReport);
                 }
-                if (Property.class.getName().equals(taskClass.getName())) {
-                    handleProperty(task, eaReport);
+                if (Property.class.isAssignableFrom(taskClass)) {
+                    Property propertyTask = (Property) maybeConfigureTask(task);
+                    handleProperty(propertyTask, eaReport);
                 }
-                if (Import.class.getName().equals(taskClass.getName())) {
-                    handleImport(task, eaReport, conf);
+                if (Import.class.isAssignableFrom(taskClass)) {
+                    Import importTask = (Import) maybeConfigureTask(task);
+                    handleImport(importTask, eaReport, conf);
                 }
             }
         }
     }
 
-    private void handleImport(Task task, EasyAntReport eaReport, String conf) throws Exception
{
-        Map<String, String> attributes = task.getRuntimeConfigurableWrapper().getAttributeMap();
+    private Object maybeConfigureTask(Task task) {
+        if (task.getRuntimeConfigurableWrapper().getProxy() instanceof UnknownElement) {
+            UnknownElement ue = (UnknownElement) task.getRuntimeConfigurableWrapper().getProxy();
+            ue.maybeConfigure();
+            return ue.getRealThing();
+        } else if (task instanceof UnknownElement) {
+            UnknownElement ue = (UnknownElement) task;
+            ue.maybeConfigure();
+            return ue.getRealThing();
+        } else {
+            return task;
+        }
+    }
+
+    private void handleImport(Import importTask, EasyAntReport eaReport, String conf) throws
Exception {
         ImportedModuleReport importedModuleReport = new ImportedModuleReport();
-        PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(task.getProject());
 
-        importedModuleReport.setModuleMrid(propertyHelper.replaceProperties(attributes.get("mrid")));
-        importedModuleReport.setModule(propertyHelper.replaceProperties(attributes.get("module")));
-        String org = attributes.get("org") != null ? attributes.get("org") : attributes.get("organisation");
-        importedModuleReport.setOrganisation(propertyHelper.replaceProperties(org));
-
-        String rev = attributes.get("rev") != null ? attributes.get("rev") : attributes.get("revision");
-        importedModuleReport.setRevision(propertyHelper.replaceProperties(rev));
-
-        importedModuleReport.setType(propertyHelper.replaceProperties(attributes.get("type")));
-        importedModuleReport.setAs(propertyHelper.replaceProperties(attributes.get("as")));
-        if (attributes.get("mandatory") != null) {
-            importedModuleReport.setMandatory(Boolean.parseBoolean(propertyHelper.replaceProperties(attributes
-                    .get("mandatory"))));
-        }
+        importedModuleReport.setModuleMrid(importTask.getMrid());
+        importedModuleReport.setOrganisation(importTask.getOrganisation());
+        importedModuleReport.setModule(importTask.getModule());
+        importedModuleReport.setRevision(importTask.getRevision());
+        importedModuleReport.setMandatory(importTask.isMandatory());
+        importedModuleReport.setMode(importTask.getMode());
+        importedModuleReport.setAs(importTask.getAs());
         importedModuleReport
                 .setEasyantReport(getPluginInfo(ModuleRevisionId.parse(importedModuleReport.getModuleMrid())));
-
         eaReport.addImportedModuleReport(importedModuleReport);
+
         Message.debug("Ant file import another module called : " + importedModuleReport.getModuleMrid()
+ " with mode "
-                + importedModuleReport.getType());
+                + importedModuleReport.getMode());
     }
 
-    /**
-     * @param task
-     * @param eaReport
-     * @throws IOException
-     */
-    private void handleProperty(Task task, EasyAntReport eaReport) throws IOException {
-        Map<String, String> attributes = task.getRuntimeConfigurableWrapper().getAttributeMap();
-        if (attributes.get("file") != null) {
+    private void handleProperty(Property property, EasyAntReport eaReport) throws IOException
{
+
+        if (property.getFile() != null) {
             Properties propToLoad = new Properties();
-            File f = new File(PropertyHelper.getPropertyHelper(task.getProject()).replaceProperties(
-                    attributes.get("file")));
+            File f = property.getFile();
             if (f.exists()) {
                 try {
                     propToLoad.load(new FileInputStream(f));
@@ -287,43 +289,32 @@ public class DefaultPluginServiceImpl im
                     }
 
                 } catch (IOException e) {
-                    IOException ioe = new IOException("Unable to parse the property file
:" + attributes.get("file"));
+                    IOException ioe = new IOException("Unable to parse the property file
:" + property.getFile());
                     ioe.initCause(e);
                     throw ioe;
                 }
             }
         }
+        if (property.getName() != null) {
+            PropertyDescriptor propertyDescriptor = new PropertyDescriptor(property.getName());
+            propertyDescriptor.setValue(property.getValue());
+            eaReport.addPropertyDescriptor(property.getName(), propertyDescriptor);
+        }
     }
 
-    /**
-     * @param task
-     * @param eaReport
-     */
-    private void handleParameterTask(Task task, EasyAntReport eaReport) {
-        Map<String, String> attributes = task.getRuntimeConfigurableWrapper().getAttributeMap();
-        PropertyDescriptor propertyDescriptor = null;
-
-        if (attributes.get("property") != null) {
-            propertyDescriptor = new PropertyDescriptor(attributes.get("property"));
-            propertyDescriptor.setDefaultValue(attributes.get("default"));
-            if (attributes.get("required") == null)
-                propertyDescriptor.setRequired(false);
-            else
-                propertyDescriptor.setRequired(new Boolean(attributes.get("required")));
-            if (attributes.get("description") != null) {
-                propertyDescriptor.setDescription(attributes.get("description"));
-            }
-            if (task.getRuntimeConfigurableWrapper().getText() != null
-                    && task.getRuntimeConfigurableWrapper().getText().length() >
0) {
-                propertyDescriptor.setDescription(task.getRuntimeConfigurableWrapper().getText().toString());
-            }
+    private void handleParameterTask(ParameterTask parameterTask, EasyAntReport eaReport)
{
+        if (parameterTask.getProperty() != null) {
+            PropertyDescriptor propertyDescriptor = new PropertyDescriptor(parameterTask.getProperty());
+            propertyDescriptor.setDefaultValue(parameterTask.getDefault());
+            propertyDescriptor.setRequired(parameterTask.isRequired());
+            propertyDescriptor.setDescription(parameterTask.getDescription());
             Message.debug("Ant file has a property called : " + propertyDescriptor.getName());
             eaReport.addPropertyDescriptor(propertyDescriptor.getName(), propertyDescriptor);
-        } else if (attributes.get("path") != null) {
+        } else if (parameterTask.getPath() != null) {
             ParameterReport parameterReport = new ParameterReport(ParameterType.PATH);
-            parameterReport.setName(attributes.get("path"));
-            parameterReport.setDefaultValue(attributes.get("default"));
-            parameterReport.setRequired(new Boolean(attributes.get("required")));
+            parameterReport.setName(parameterTask.getPath());
+            parameterReport.setRequired(parameterTask.isRequired());
+            parameterReport.setDescription(parameterTask.getDescription());
             eaReport.addParameterReport(parameterReport);
             Message.debug("Ant file has a path called : " + parameterReport.getName());
         }
@@ -431,6 +422,8 @@ public class DefaultPluginServiceImpl im
         loadModule.setLocation(new Location(ProjectUtils.emulateMainScript(p).getAbsolutePath()));
         loadModule.setProject(p);
         loadModule.execute();
+        ProjectHelper projectHelper = (ProjectHelper) p.getReference(ProjectHelper.PROJECTHELPER_REFERENCE);
+        ProjectUtils.injectTargetIntoExtensionPoint(p, projectHelper);
         analyseProject(p, eaReport, "default");
 
         return eaReport;
@@ -534,7 +527,6 @@ public class DefaultPluginServiceImpl im
 
     private enum PluginType {
         BUILDTYPE, PLUGIN
-
     }
 
 }

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/AbstractEasyAntTask.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/AbstractEasyAntTask.java?rev=1390738&r1=1390737&r2=1390738&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/AbstractEasyAntTask.java
(original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/AbstractEasyAntTask.java
Wed Sep 26 21:31:32 2012
@@ -30,25 +30,28 @@ import org.apache.tools.ant.types.Refere
 public class AbstractEasyAntTask extends Task {
 
     /**
-     * Get the easyant ivy ant settings.
-     * Usefull if you want to bind a subtask to easyant ivy instance
+     * Get the easyant ivy ant settings. Usefull if you want to bind a subtask to easyant
ivy instance
+     * 
      * @return an ivyAntSettings
      */
     protected IvyAntSettings getEasyAntIvyAntSettings() {
         return IvyInstanceHelper.getEasyAntIvyAntSettings(getProject());
     }
-    
+
     /**
      * Get the configured ivy instance
+     * 
      * @return a configured ivy instance
      */
     protected Ivy getEasyAntIvyInstance() {
         return getEasyAntIvyAntSettings().getConfiguredIvyInstance(this);
     }
-    
+
     /**
      * Utilitary method to configure a task with the current one
-     * @param task task to configure
+     * 
+     * @param task
+     *            task to configure
      * @return the configured task
      */
     protected Task initTask(Task task) {
@@ -61,6 +64,7 @@ public class AbstractEasyAntTask extends
 
     /**
      * Get a reference of the project ivy instance
+     * 
      * @return a reference of the project ivy instance
      */
     protected Reference getProjectIvyReference() {

Modified: incubator/easyant/core/trunk/src/test/java/org/apache/easyant/core/services/PluginServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/test/java/org/apache/easyant/core/services/PluginServiceTest.java?rev=1390738&r1=1390737&r2=1390738&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/test/java/org/apache/easyant/core/services/PluginServiceTest.java
(original)
+++ incubator/easyant/core/trunk/src/test/java/org/apache/easyant/core/services/PluginServiceTest.java
Wed Sep 26 21:31:32 2012
@@ -97,7 +97,7 @@ public class PluginServiceTest {
             if (importedModule.getModuleMrid().equals("org.apache.easyant.buildtypes#build-std-java;0.9"))
{
                 containsBuildType = true;
             }
-            if (importedModule.getModuleMrid().equals("org.apache.easyant.plugins#run;0.9"))
{
+            if (importedModule.getModuleMrid().equals("org.apache.easyant.plugins#run-java;0.9"))
{
                 containsPlugin = true;
             }
         }
@@ -133,21 +133,17 @@ public class PluginServiceTest {
                 break;
             }
         }
-
         Assert.assertNotNull(packageEP);
+        Assert.assertEquals("compile,abstract-package:package-finished,hello-world", packageEP.getDepends());
+
         List<TargetReport> targets = packageEP.getTargetReports();
-        Set<String> expectedTargets = new HashSet<String>(Arrays.asList("jar:jar",
"test-jar:jar"));
-        Assert.assertEquals("test and main jars included in package phase", expectedTargets.size(),
targets.size());
+        Set<String> expectedTargets = new HashSet<String>(Arrays.asList("hello-world"));
+        Assert.assertEquals(expectedTargets.size(), targets.size());
 
         for (TargetReport target : packageEP.getTargetReports()) {
             Assert.assertTrue("expected to find " + target.getName(), expectedTargets.remove(target.getName()));
         }
 
-    }
-
-    @Test
-    public void shouldHaveModuleAntFile() throws Exception {
-        EasyAntReport eaReport = generateReport();
         boolean hasHelloWorldTarget = false;
         for (TargetReport targetReport : eaReport.getAvailableTargets()) {
             if ("hello-world".equals(targetReport.getName())) {



Mime
View raw message