FELIX-4009 : maven bundle plugin should be integrated directly with eclipse. Apply patch from Stefan Seifert
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1734773 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/AntPlugin.java b/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/AntPlugin.java
index 0e5c7d6..f2f76c1 100644
--- a/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/AntPlugin.java
+++ b/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/AntPlugin.java
@@ -19,7 +19,7 @@
package org.apache.felix.bundleplugin;
-import java.io.FileOutputStream;
+import java.io.File;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.Map;
@@ -75,7 +75,7 @@
// 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 );
+ OutputStream out = buildContext.newFileOutputStream( new File(baseDir + BUILD_BND) );
bndProperties.store( out, " Merged BND Instructions" );
IOUtil.close( out );
diff --git a/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java b/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
index 462a9d2..b750fae 100644
--- a/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
+++ b/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
@@ -90,6 +90,7 @@
import org.codehaus.plexus.util.PropertyUtils;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.WriterFactory;
+import org.sonatype.plexus.build.incremental.BuildContext;
import aQute.bnd.header.Attrs;
import aQute.bnd.header.OSGiHeader;
@@ -313,6 +314,9 @@
@Parameter( defaultValue = "${session}", readonly = true, required = true )
private MavenSession m_mavenSession;
+ @Component
+ protected BuildContext buildContext;
+
private static final String MAVEN_SYMBOLICNAME = "maven-symbolicname";
private static final String MAVEN_RESOURCES = "{maven-resources}";
private static final String MAVEN_TEST_RESOURCES = "{maven-test-resources}";
@@ -519,7 +523,7 @@
try
{
- ManifestPlugin.writeManifest( builder, outputFile, niceManifest, exportScr, scrLocation );
+ ManifestPlugin.writeManifest( builder, outputFile, niceManifest, exportScr, scrLocation, buildContext );
}
catch ( IOException e )
{
diff --git a/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java b/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
index ff33521..edb81fa 100644
--- a/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
+++ b/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
@@ -22,7 +22,6 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -33,23 +32,25 @@
import java.util.Properties;
import java.util.jar.Manifest;
-import aQute.bnd.header.Parameters;
-import aQute.bnd.osgi.Instructions;
-import aQute.bnd.osgi.Processor;
-import aQute.lib.collections.ExtList;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.dependency.graph.DependencyNode;
+import org.sonatype.plexus.build.incremental.BuildContext;
+import aQute.bnd.header.Parameters;
import aQute.bnd.osgi.Analyzer;
import aQute.bnd.osgi.Builder;
+import aQute.bnd.osgi.Instructions;
import aQute.bnd.osgi.Jar;
+import aQute.bnd.osgi.Processor;
import aQute.bnd.osgi.Resource;
-import org.apache.maven.shared.dependency.graph.DependencyNode;
+import aQute.lib.collections.ExtList;
/**
@@ -66,6 +67,9 @@
@Parameter( property = "rebuildBundle" )
protected boolean rebuildBundle;
+ @Component
+ private BuildContext buildContext;
+
@Override
protected void execute( MavenProject project, DependencyNode dependencyGraph, Map<String, String> instructions, Properties properties, Jar[] classpath )
throws MojoExecutionException
@@ -99,7 +103,7 @@
try
{
- writeManifest( analyzer, outputFile, niceManifest, exportScr, scrLocation );
+ writeManifest( analyzer, outputFile, niceManifest, exportScr, scrLocation, buildContext );
}
catch ( Exception e )
{
@@ -122,12 +126,12 @@
public Manifest getManifest( MavenProject project, DependencyNode dependencyGraph, Jar[] classpath ) throws IOException, MojoFailureException,
MojoExecutionException, Exception
{
- return getManifest( project, dependencyGraph, new LinkedHashMap<String, String>(), new Properties(), classpath );
+ return getManifest( project, dependencyGraph, new LinkedHashMap<String, String>(), new Properties(), classpath, buildContext );
}
- public Manifest getManifest( MavenProject project, DependencyNode dependencyGraph, Map<String, String> instructions, Properties properties, Jar[] classpath )
- throws IOException, MojoFailureException, MojoExecutionException, Exception
+ public Manifest getManifest( MavenProject project, DependencyNode dependencyGraph, Map<String, String> instructions, Properties properties, Jar[] classpath,
+ BuildContext buildContext) throws IOException, MojoFailureException, MojoExecutionException, Exception
{
Analyzer analyzer = getAnalyzer(project, dependencyGraph, instructions, properties, classpath);
@@ -136,7 +140,7 @@
if (exportScr)
{
- exportScr(analyzer, jar, scrLocation);
+ exportScr(analyzer, jar, scrLocation, buildContext);
}
// cleanup...
@@ -145,7 +149,7 @@
return manifest;
}
- private static void exportScr(Analyzer analyzer, Jar jar, File scrLocation) throws Exception {
+ private static void exportScr(Analyzer analyzer, Jar jar, File scrLocation, BuildContext buildContext) throws Exception {
scrLocation.mkdirs();
String bpHeader = analyzer.getProperty(Analyzer.SERVICE_COMPONENT);
@@ -159,7 +163,7 @@
Resource resource = jar.getResource(root);
if (resource != null)
{
- writeSCR(resource, location);
+ writeSCR(resource, location, buildContext);
}
}
else
@@ -168,16 +172,16 @@
{
String path = entry.getKey();
Resource resource = entry.getValue();
- writeSCR(resource, new File(location, path));
+ writeSCR(resource, new File(location, path), buildContext);
}
}
}
}
- private static void writeSCR(Resource resource, File destination) throws Exception
+ private static void writeSCR(Resource resource, File destination, BuildContext buildContext) throws Exception
{
destination.getParentFile().mkdirs();
- OutputStream os = new FileOutputStream(destination);
+ OutputStream os = buildContext.newFileOutputStream(destination);
try
{
resource.write(os);
@@ -275,7 +279,7 @@
if ( !entryFile.exists() || entry.getValue().lastModified() == 0 )
{
entryFile.getParentFile().mkdirs();
- OutputStream os = new FileOutputStream( entryFile );
+ OutputStream os = buildContext.newFileOutputStream( entryFile );
entry.getValue().write( os );
os.close();
}
@@ -287,7 +291,7 @@
public static void writeManifest( Analyzer analyzer, File outputFile, boolean niceManifest,
- boolean exportScr, File scrLocation ) throws Exception
+ boolean exportScr, File scrLocation, BuildContext buildContext ) throws Exception
{
Properties properties = analyzer.getProperties();
Jar jar = analyzer.getJar();
@@ -313,21 +317,21 @@
File parentFile = outputFile.getParentFile();
parentFile.mkdirs();
}
- writeManifest( manifest, outputFile, niceManifest );
+ writeManifest( manifest, outputFile, niceManifest, buildContext );
if (exportScr)
{
- exportScr(analyzer, jar, scrLocation);
+ exportScr(analyzer, jar, scrLocation, buildContext);
}
}
- public static void writeManifest( Manifest manifest, File outputFile, boolean niceManifest ) throws IOException
+ public static void writeManifest( Manifest manifest, File outputFile, boolean niceManifest,
+ BuildContext buildContext ) throws IOException
{
outputFile.getParentFile().mkdirs();
- FileOutputStream os;
- os = new FileOutputStream( outputFile );
+ OutputStream os = buildContext.newFileOutputStream( outputFile );
try
{
ManifestWriter.outputManifest( manifest, os, niceManifest );
diff --git a/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/baseline/AbstractBaselinePlugin.java b/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/baseline/AbstractBaselinePlugin.java
index b4e5e0f..a28efd5 100644
--- a/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/baseline/AbstractBaselinePlugin.java
+++ b/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/baseline/AbstractBaselinePlugin.java
@@ -47,6 +47,7 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.StringUtils;
+import org.sonatype.plexus.build.incremental.BuildContext;
import aQute.bnd.differ.Baseline;
import aQute.bnd.differ.Baseline.Info;
@@ -148,6 +149,9 @@
@Parameter
protected List<String> supportedProjectTypes = Arrays.asList( new String[] { "jar", "bundle" } );
+ @Component
+ protected BuildContext buildContext;
+
public final void execute()
throws MojoExecutionException, MojoFailureException
{
diff --git a/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/baseline/BaselineReport.java b/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/baseline/BaselineReport.java
index 5774d7d..43665a6 100644
--- a/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/baseline/BaselineReport.java
+++ b/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/baseline/BaselineReport.java
@@ -19,7 +19,6 @@
package org.apache.felix.bundleplugin.baseline;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -100,7 +99,7 @@
try
{
- target = new FileOutputStream( targetFile );
+ target = buildContext.newFileOutputStream( targetFile );
IOUtil.copy( source, target );
}
catch ( IOException e )