You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ca...@apache.org on 2007/02/09 21:57:17 UTC

svn commit: r505497 - /maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/ManifestPlugin.java

Author: carlos
Date: Fri Feb  9 12:57:17 2007
New Revision: 505497

URL: http://svn.apache.org/viewvc?view=rev&rev=505497
Log:
Add manifest goal to the plugin

Added:
    maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/ManifestPlugin.java   (with props)

Added: maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/ManifestPlugin.java
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/ManifestPlugin.java?view=auto&rev=505497
==============================================================================
--- maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/ManifestPlugin.java (added)
+++ maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/ManifestPlugin.java Fri Feb  9 12:57:17 2007
@@ -0,0 +1,126 @@
+/*
+ * 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.tools.maven2.bundleplugin;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+import java.util.jar.Manifest;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+
+import aQute.lib.osgi.Analyzer;
+import aQute.lib.osgi.Jar;
+
+/**
+ * Generate an OSGi manifest for this project
+ * 
+ * @goal manifest
+ * @phase process-classes
+ * @requiresDependencyResolution runtime
+ */
+public class ManifestPlugin
+    extends BundlePlugin
+{
+
+    /**
+     * Directory where the manifest will be written
+     * @parameter
+     * @default ""
+     */
+    private String manifestLocation = "";
+
+    protected void execute( MavenProject project, Map instructions, Properties properties, Jar[] classpath )
+        throws MojoExecutionException
+    {
+        Analyzer analyzer = new Analyzer();
+
+        analyzer.setProperties( getDefaultProperties( project ) );
+        if ( properties != null )
+        {
+            analyzer.getProperties().putAll( properties );
+        }
+
+        Manifest manifest;
+        try
+        {
+            analyzer.setJar( outputDirectory );
+
+            if ( analyzer.getProperty( Analyzer.IMPORT_PACKAGE ) == null )
+                analyzer.setProperty( Analyzer.IMPORT_PACKAGE, "*" );
+
+            if ( analyzer.getProperty( Analyzer.EXPORT_PACKAGE ) == null )
+            {
+                String export = analyzer.calculateExportsFromContents();
+                analyzer.setProperty( Analyzer.EXPORT_PACKAGE, export );
+            }
+
+            if ( classpath != null )
+                analyzer.setClasspath( classpath );
+
+            analyzer.mergeManifest();
+
+            analyzer.calcManifest();
+            manifest = analyzer.getJar().getManifest();
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Error trying to generate Manifest", e );
+        }
+
+        File manifestFile = new File( getBuildDirectory(), manifestLocation + "/MANIFEST.MF" );
+        manifestFile.getParentFile().mkdirs();
+
+        FileOutputStream os;
+        try
+        {
+            os = new FileOutputStream( manifestFile );
+        }
+        catch ( FileNotFoundException e )
+        {
+            throw new MojoExecutionException( "Error trying to open file " + manifestFile + " for writing", e );
+        }
+        try
+        {
+            manifest.write( os );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Error writing Manifest to file " + manifestFile, e );
+        }
+        finally
+        {
+            if ( os != null )
+            {
+                try
+                {
+                    os.close();
+                }
+                catch ( IOException e )
+                {
+                    //nothing we can do here
+                }
+            }
+        }
+    }
+}

Propchange: maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/ManifestPlugin.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/ManifestPlugin.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"