You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2014/05/06 17:23:03 UTC

svn commit: r1592775 - in /felix/trunk/ipojo/manipulator/ipojo-ant-task: pom.xml src/main/java/org/apache/felix/ipojo/task/IPojoTask.java

Author: clement
Date: Tue May  6 15:23:03 2014
New Revision: 1592775

URL: http://svn.apache.org/r1592775
Log:
Migrate the Ant task to the new manipulator API. The classloader is built from a classpath element (new Ant task parameter). (FELIX-4509)

Modified:
    felix/trunk/ipojo/manipulator/ipojo-ant-task/pom.xml
    felix/trunk/ipojo/manipulator/ipojo-ant-task/src/main/java/org/apache/felix/ipojo/task/IPojoTask.java

Modified: felix/trunk/ipojo/manipulator/ipojo-ant-task/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/ipojo-ant-task/pom.xml?rev=1592775&r1=1592774&r2=1592775&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/ipojo-ant-task/pom.xml (original)
+++ felix/trunk/ipojo/manipulator/ipojo-ant-task/pom.xml Tue May  6 15:23:03 2014
@@ -106,7 +106,7 @@
               org.objectweb.asm.util;-split-package:=merge-first,
               org.objectweb.asm;-split-package:=merge-first,
               org.objectweb.asm.commons;-split-package:=merge-first,
-              org.objectweb.asm.tree;-split-package:=merge-first,
+              org.objectweb.asm.tree*;-split-package:=merge-first,
               org.apache.xerces.parsers, org.apache.xerces.xni*,
               org.apache.xerces.impl*, org.apache.xerces.util.*,
               org.apache.xerces.dom.*, org.apache.xerces.dom3.*,

Modified: felix/trunk/ipojo/manipulator/ipojo-ant-task/src/main/java/org/apache/felix/ipojo/task/IPojoTask.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/ipojo-ant-task/src/main/java/org/apache/felix/ipojo/task/IPojoTask.java?rev=1592775&r1=1592774&r2=1592775&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/ipojo-ant-task/src/main/java/org/apache/felix/ipojo/task/IPojoTask.java (original)
+++ felix/trunk/ipojo/manipulator/ipojo-ant-task/src/main/java/org/apache/felix/ipojo/task/IPojoTask.java Tue May  6 15:23:03 2014
@@ -18,37 +18,53 @@
  */
 package org.apache.felix.ipojo.task;
 
-import java.io.File;
-
 import org.apache.felix.ipojo.manipulator.Pojoization;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
+
+import java.io.File;
 
 /**
  * iPOJO Ant Task. This Ant task manipulates an input bundle.
+ *
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 public class IPojoTask extends Task {
 
-    /** Metadata file. */
+    /**
+     * Metadata file.
+     */
     private File m_metadata;
 
-    /** Input bundle. */
+    /**
+     * Input bundle.
+     */
     private File m_input;
 
-    /** Output bundle. */
+    /**
+     * Output bundle.
+     */
     private File m_output;
 
-    /** Input directory. */
+    /**
+     * Input directory.
+     */
     private File m_directory;
 
-    /** Input manifest. */
+    /**
+     * Input manifest.
+     */
     private File m_manifest;
 
-    /** Flag describing if we need to ignore annotation of not. */
+    /**
+     * Flag describing if we need to ignore annotation of not.
+     */
     private boolean m_ignoreAnnotations = false;
 
+
     /**
      * Flag describing if we need or not use local XSD files
      * (i.e. use the {@link org.apache.felix.ipojo.xml.parser.SchemaResolver} or not).
@@ -57,7 +73,13 @@ public class IPojoTask extends Task {
     private boolean m_ignoreLocalXSD = false;
 
     /**
+     * The classpath.
+     */
+    private Path m_classpath;
+
+    /**
      * Set the metadata file.
+     *
      * @param meta : the metadata file.
      */
     public void setMetadata(File meta) {
@@ -66,6 +88,7 @@ public class IPojoTask extends Task {
 
     /**
      * Set the manifest file.
+     *
      * @param manifest : the manifest file.
      */
     public void setManifest(File manifest) {
@@ -74,6 +97,7 @@ public class IPojoTask extends Task {
 
     /**
      * Set the input bundle.
+     *
      * @param in : the input bundle
      */
     public void setInput(File in) {
@@ -82,14 +106,16 @@ public class IPojoTask extends Task {
 
     /**
      * Set the input directory.
+     *
      * @param dir : the input directory
      */
     public void setDir(File dir) {
-        m_directory  = dir;
+        m_directory = dir;
     }
 
     /**
      * Set the output bundle.
+     *
      * @param out : the output bundle
      */
     public void setOutput(File out) {
@@ -98,6 +124,7 @@ public class IPojoTask extends Task {
 
     /**
      * Set if we need to ignore annotations or not.
+     *
      * @param flag : true if we need to ignore annotations.
      */
     public void setIgnoreAnnotations(boolean flag) {
@@ -106,6 +133,7 @@ public class IPojoTask extends Task {
 
     /**
      * Set if we need to use embedded XSD files or not.
+     *
      * @param flag : true if we need to ignore embedded XSD files.
      */
     public void setIgnoreEmbeddedSchemas(boolean flag) {
@@ -114,11 +142,12 @@ public class IPojoTask extends Task {
 
     /**
      * Execute the Ant Task.
+     *
      * @see org.apache.tools.ant.Task#execute()
      */
     public void execute() {
 
-        if (m_input == null  && m_directory == null) {
+        if (m_input == null && m_directory == null) {
             throw new BuildException("Neither input bundle nor directory specified");
         }
 
@@ -144,7 +173,7 @@ public class IPojoTask extends Task {
             if (m_input != null) {
                 throw new BuildException("The manifest location cannot be used when manipulating an existing bundle");
             }
-            if (! m_manifest.exists()) {
+            if (!m_manifest.exists()) {
                 throw new BuildException("The manifest file " + m_manifest.getAbsolutePath() + " does not exist");
             }
         }
@@ -153,7 +182,7 @@ public class IPojoTask extends Task {
         if (m_metadata == null) {
             m_metadata = new File("./metadata.xml");
             if (!m_metadata.exists()) {
-             // Verify if annotations are ignored
+                // Verify if annotations are ignored
                 if (m_ignoreAnnotations) {
                     log("No metadata file found & annotations ignored : nothing to do");
                     return;
@@ -169,11 +198,11 @@ public class IPojoTask extends Task {
             if (!m_metadata.exists()) {
                 throw new BuildException("No metadata file found - the file " + m_metadata.getAbsolutePath() + " does not exist");
             } else {
-            	if (m_metadata.isDirectory()) {
-            		log("Metadata directory : " + m_metadata.getAbsolutePath());
-            	} else {
-            		log("Metadata file : " + m_metadata.getAbsolutePath());
-            	}
+                if (m_metadata.isDirectory()) {
+                    log("Metadata directory : " + m_metadata.getAbsolutePath());
+                } else {
+                    log("Metadata file : " + m_metadata.getAbsolutePath());
+                }
             }
         }
 
@@ -188,7 +217,9 @@ public class IPojoTask extends Task {
             }
             if (m_output.exists()) {
                 boolean r = m_output.delete();
-                if (!r) { throw new BuildException("The file " + m_output.getAbsolutePath() + " cannot be deleted"); }
+                if (!r) {
+                    throw new BuildException("The file " + m_output.getAbsolutePath() + " cannot be deleted");
+                }
             }
         }
 
@@ -197,13 +228,30 @@ public class IPojoTask extends Task {
         if (m_ignoreAnnotations) {
             pojo.disableAnnotationProcessing();
         }
-        if (! m_ignoreLocalXSD) {
+        if (!m_ignoreLocalXSD) {
             pojo.setUseLocalXSD();
         }
+
+        Path classpath = getClasspath();
+        classpath.addJavaRuntime();
+
+        // Adding the input jar or directory
+        if (m_classpath == null) {
+            m_classpath = createClasspath();
+        }
+        Path element = m_classpath.createPath();
+        if (m_input != null) {
+            element.setLocation(m_input.getAbsoluteFile());
+        } else if (m_directory != null) {
+            element.setLocation(m_directory.getAbsoluteFile());
+        }
+        m_classpath.add(element);
+
+        ClassLoader loader = getProject().createClassLoader(getClasspath());
         if (m_input != null) {
-            pojo.pojoization(m_input, m_output, m_metadata);
+            pojo.pojoization(m_input, m_output, m_metadata, loader);
         } else {
-            pojo.directoryPojoization(m_directory, m_metadata, m_manifest);
+            pojo.directoryPojoization(m_directory, m_metadata, m_manifest, loader);
         }
         for (int i = 0; i < reporter.getWarnings().size(); i++) {
             log((String) reporter.getWarnings().get(i), Project.MSG_WARN);
@@ -216,7 +264,7 @@ public class IPojoTask extends Task {
             String out;
             if (m_output.getName().equals("_out.jar")) {
                 if (m_input.delete()) {
-                    if (! m_output.renameTo(m_input)) {
+                    if (!m_output.renameTo(m_input)) {
                         log("Cannot rename the output jar to " + m_input.getAbsolutePath(), Project.MSG_WARN);
                     }
                 } else {
@@ -252,5 +300,49 @@ public class IPojoTask extends Task {
         }
     }
 
+    /**
+     * Set the classpath to be used for this packaging.
+     *
+     * @param classpath the classpath used for this packaging
+     */
+    public synchronized void setClasspath(Path classpath) {
+        if (m_classpath == null) {
+            m_classpath = createClasspath();
+        }
+        m_classpath.append(classpath);
+    }
+
+    /**
+     * Creates a nested classpath element.
+     *
+     * @return classpath
+     */
+    public synchronized Path createClasspath() {
+        if (m_classpath == null) {
+            m_classpath = new Path(getProject());
+        }
+        return m_classpath.createPath();
+    }
+
+    /**
+     * Adds to the classpath a reference to
+     * a &lt;path&gt; defined elsewhere.
+     *
+     * @param pathRef the reference to add to the classpath
+     */
+    public void setClasspathRef(Reference pathRef) {
+        createClasspath().setRefid(pathRef);
+    }
+
+    /**
+     * Gets the classpath.
+     *
+     * @return the classpath
+     */
+    public Path getClasspath() {
+        return m_classpath;
+    }
+
+
 }