Author: clement
Date: Tue Aug 14 06:45:19 2007
New Revision: 565750

URL: http://svn.apache.org/viewvc?view=rev&rev=565750
Log:
Defines an Ant Task to create iPOJO Bundles.

Added:
    felix/trunk/ipojo/ant/   (with props)
    felix/trunk/ipojo/ant/pom.xml
    felix/trunk/ipojo/ant/src/
    felix/trunk/ipojo/ant/src/main/
    felix/trunk/ipojo/ant/src/main/java/
    felix/trunk/ipojo/ant/src/main/java/org/
    felix/trunk/ipojo/ant/src/main/java/org/apache/
    felix/trunk/ipojo/ant/src/main/java/org/apache/felix/
    felix/trunk/ipojo/ant/src/main/java/org/apache/felix/ipojo/
    felix/trunk/ipojo/ant/src/main/java/org/apache/felix/ipojo/task/
    
felix/trunk/ipojo/ant/src/main/java/org/apache/felix/ipojo/task/IPojoTask.java
    felix/trunk/ipojo/ant/src/main/resources/

Propchange: felix/trunk/ipojo/ant/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Aug 14 06:45:19 2007
@@ -0,0 +1,6 @@
+target
+bin
+.settings
+.checkstyle
+.classpath
+.project

Added: felix/trunk/ipojo/ant/pom.xml
URL: 
http://svn.apache.org/viewvc/felix/trunk/ipojo/ant/pom.xml?view=auto&rev=565750
==============================================================================
--- felix/trunk/ipojo/ant/pom.xml (added)
+++ felix/trunk/ipojo/ant/pom.xml Tue Aug 14 06:45:19 2007
@@ -0,0 +1,56 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+ <parent>
+    <groupId>org.apache.felix</groupId>
+    <artifactId>felix</artifactId>
+    <version>1.1.0-SNAPSHOT</version>
+    <relativePath>../../pom/pom.xml</relativePath>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>org.apache.felix.ipojo.ant</artifactId>
+  <packaging>bundle</packaging>
+  <version>0.7.3-SNAPSHOT</version>
+  <name>iPOJO Ant Task</name>
+  <dependencies>
+       <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.apache.felix.ipojo.metadata</artifactId>
+      <version>0.7.3-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.apache.felix.ipojo.manipulator</artifactId>
+      <version>0.7.3-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>xerces</groupId>
+      <artifactId>xercesImpl</artifactId>
+      <version>2.4.0</version>
+    </dependency>
+    <dependency>
+       <groupId>ant</groupId>
+       <artifactId>ant</artifactId>
+       <version>1.6.5</version>
+    </dependency>
+  </dependencies>
+  
+  <build>
+  <plugins>
+       <plugin>
+       <groupId>org.apache.felix</groupId>
+       <artifactId>maven-bundle-plugin</artifactId>
+       <version>1.1.0-SNAPSHOT</version>
+       <extensions>true</extensions>
+       <configuration>
+               <instructions>          
+                       <Bundle-Name>iPOJO Ant Task</Bundle-Name>
+                       <Bundle-Vendor>Clement ESCOFFIER</Bundle-Vendor>
+                       <Bundle-Description> iPOJO Ant Task 
</Bundle-Description>
+                       <Private-Package>org.apache.felix.ipojo.metadata, 
org.apache.felix.ipojo.manipulator, org.apache.felix.ipojo.xml.parser, 
org.apache.felix.ipojo.manipulation*, org.objectweb.asm, 
org.objectweb.asm.commons, org.apache.xerces.parsers, org.apache.xerces.xni*, 
org.apache.xerces.impl*, org.apache.xerces.util.*</Private-Package>
+                       
<Export-Package>org.apache.felix.ipojo.task</Export-Package>
+               </instructions>
+       </configuration>
+       </plugin>
+  </plugins>
+  </build>
+</project>
\ No newline at end of file

Added: 
felix/trunk/ipojo/ant/src/main/java/org/apache/felix/ipojo/task/IPojoTask.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/ipojo/ant/src/main/java/org/apache/felix/ipojo/task/IPojoTask.java?view=auto&rev=565750
==============================================================================
--- 
felix/trunk/ipojo/ant/src/main/java/org/apache/felix/ipojo/task/IPojoTask.java 
(added)
+++ 
felix/trunk/ipojo/ant/src/main/java/org/apache/felix/ipojo/task/IPojoTask.java 
Tue Aug 14 06:45:19 2007
@@ -0,0 +1,141 @@
+/* 
+ * 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.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.Task;
+
+/**
+* iPOJO Ant Task.
+* This Ant taks manipulate an input bundle.
+* @author <a href="mailto:[EMAIL PROTECTED]">Felix Project Team</a>
+*/
+public class IPojoTask extends Task {
+    
+    /**
+     * Metadata file.
+     */
+    private File m_metadata;
+    
+    /**
+     * Input bundle.
+     */
+    private File m_input;
+    
+    /**
+     * Output bundle.
+     */
+    private File m_output;
+    
+    /**
+     * Set the metadata file.
+     * @param meta : the metadata file.
+     */
+    public void setMetadata(File meta) {
+        m_metadata = meta;
+    }
+    
+    /**
+     * Set the input bundle.
+     * @param in : the input bundle
+     */
+    public void setInput(File in) {
+        m_input = in;
+    }
+    
+    /**
+     * Set the output bundle.
+     * @param out : the output bundle
+     */
+    public void setOutput(File out) {
+        m_output = out;
+    }
+    
+    /**
+     * Execute the Ant Task.
+     * @see org.apache.tools.ant.Task#execute()
+     */
+    public void execute() {
+        
+        if (m_input == null) {
+            throw new BuildException("No input bundle specified");
+        }
+        if (!m_input.exists()) {
+            throw new BuildException("The input bundle " + 
m_input.getAbsolutePath() + " does not exist");
+        }
+        
+        System.out.println("Input Bundle File : " + m_input.getAbsolutePath());
+        
+        // Get metadata file
+        if (m_metadata == null) {
+            m_metadata = new File("./metadata.xml");
+            if (!m_metadata.exists()) {
+                System.out.println("No metadata file found - try to use only 
annotations");
+                m_metadata = null;
+            } else {
+                System.out.println("Metadata File : " + 
m_metadata.getAbsolutePath());
+            }
+        } else {
+            // Metadata file is specified, check existency
+            if (!m_metadata.exists()) {
+                throw new BuildException("No metadata file found - the file " 
+ m_metadata.getAbsolutePath() + " does not exist");
+            } else {
+                System.out.println("Metadata File : " + 
m_metadata.getAbsolutePath());
+            }
+        }
+
+        System.out.println("Start bundle manipulation");
+        
+        if (m_output == null) {
+            m_output = new File("./_out.jar");
+        }
+        
+        if (m_output.exists()) {
+            boolean r = m_output.delete();
+            if (!r) { throw new BuildException("The file " + 
m_output.getAbsolutePath() + " cannot be deleted"); }
+        }
+        
+        Pojoization pojo = new Pojoization();
+        pojo.pojoization(m_input, m_output, m_metadata);
+        for (int i = 0; i < pojo.getWarnings().size(); i++) {
+            System.out.println((String) pojo.getWarnings().get(i));
+        }
+        if (pojo.getErrors().size() > 0) { throw new BuildException((String) 
pojo.getErrors().get(0)); }
+        
+        String out;
+        if (m_output.getName().equals("_out.jar")) {
+            m_input.delete();
+            m_output.renameTo(m_input);
+            out = m_input.getAbsolutePath();
+        } else {
+            out = m_output.getAbsolutePath();
+        }
+        
+        System.out.println("Bundle manipulation - SUCCESS");
+        System.out.println("Output File : " + out);
+        
+    }
+    
+    
+
+}
+


Reply via email to