felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mccu...@apache.org
Subject svn commit: r629050 - in /felix/trunk/bundleplugin/src/main: java/org/apache/felix/bundleplugin/AntPlugin.java resources/build.xml resources/maven-build.bnd
Date Tue, 19 Feb 2008 09:49:44 GMT
Author: mcculls
Date: Tue Feb 19 01:49:41 2008
New Revision: 629050

URL: http://svn.apache.org/viewvc?rev=629050&view=rev
Log:
FELIX-247: add bundle:ant goal, which creates a custom Ant script to build the bundle (run
ant:ant first)

Added:
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AntPlugin.java  
(with props)
Removed:
    felix/trunk/bundleplugin/src/main/resources/maven-build.bnd
Modified:
    felix/trunk/bundleplugin/src/main/resources/build.xml

Added: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AntPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AntPlugin.java?rev=629050&view=auto
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AntPlugin.java (added)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AntPlugin.java Tue
Feb 19 01:49:41 2008
@@ -0,0 +1,92 @@
+/*
+ * 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.bundleplugin;
+
+
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+
+import aQute.lib.osgi.Builder;
+import aQute.lib.osgi.Jar;
+
+
+/**
+ * Generate Ant script to create the bundle (you should run ant:ant first).
+ *
+ * @goal ant
+ * @requiresDependencyResolution runtime
+ * @description generate Ant script to create the bundle
+ */
+public class AntPlugin extends BundlePlugin
+{
+    static final String BUILD_XML = "/build.xml";
+    static final String BUILD_BND = "/maven-build.bnd";
+
+
+    protected void execute( MavenProject currentProject, Map originalInstructions, Properties
properties,
+        Jar[] classpath ) throws MojoExecutionException
+    {
+        final String artifactId = getProject().getArtifactId();
+        final String baseDir = getProject().getBasedir().getPath();
+
+        try
+        {
+            // assemble bundle as usual, but don't save it - this way we have all the instructions
we need
+            Builder builder = buildOSGiBundle( currentProject, originalInstructions, properties,
classpath );
+            Properties bndProperties = builder.getProperties();
+
+            // cleanup and remove all non-strings from the builder properties
+            for ( Iterator i = bndProperties.values().iterator(); i.hasNext(); )
+            {
+                if ( !( i.next() instanceof String ) )
+                {
+                    i.remove();
+                }
+            }
+
+            // save the BND generated bundle to the same output directory that maven uses
+            bndProperties.setProperty( "-output", "${maven.build.dir}/${maven.build.finalName}.jar"
);
+
+            OutputStream out = new FileOutputStream( baseDir + BUILD_BND );
+            bndProperties.store( out, " Merged BND Instructions" );
+            IOUtil.close( out );
+
+            // modify build template
+            String buildXml = IOUtil.toString( getClass().getResourceAsStream( BUILD_XML
) );
+            buildXml = StringUtils.replace( buildXml, "ARTIFACT_ID", artifactId );
+
+            FileUtils.fileWrite( baseDir + BUILD_XML, buildXml );
+        }
+        catch ( Exception e )
+        {
+            throw new MojoExecutionException( "Problem creating Ant script", e );
+        }
+
+        getLog().info( "Wrote Ant bundle project for " + artifactId + " to " + baseDir );
+    }
+}

Propchange: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AntPlugin.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: felix/trunk/bundleplugin/src/main/resources/build.xml
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/resources/build.xml?rev=629050&r1=629049&r2=629050&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/resources/build.xml (original)
+++ felix/trunk/bundleplugin/src/main/resources/build.xml Tue Feb 19 01:49:41 2008
@@ -20,7 +20,7 @@
     <echo message="Please run: $ant -projecthelp"/>
   </target>
 
-  <property name="bnd.version" value="BND_VERSION"/>
+  <property name="bnd.version" value="0.0.238"/>
 
   <target name="get-bnd"
           depends="test-offline"
@@ -42,7 +42,7 @@
 
   <target name="package" depends="compile,test,get-bnd" description="Package the bundle">
     <pathconvert property="bnd.classpath" refid="build.classpath" pathsep=","/>
-    <bnd files="maven-build.bnd" classpath="${bnd.classpath}"/>
+    <bnd files="maven-build.bnd" classpath="${maven.build.outputDir},${bnd.classpath}"/>
   </target>
 
 </project>



Mime
View raw message