Refactor internals to help reduce code duplication
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1140698 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
index 95a2673..666c59a 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
@@ -146,14 +146,6 @@
private File outputDirectory;
/**
- * The directory for the pom
- *
- * @parameter expression="${basedir}"
- * @required
- */
- private File baseDir;
-
- /**
* The directory for the generated JAR.
*
* @parameter expression="${project.build.directory}"
@@ -400,17 +392,28 @@
}
- protected Builder buildOSGiBundle( MavenProject currentProject, Map originalInstructions, Properties properties,
+ protected Builder getOSGiBuilder( MavenProject currentProject, Map originalInstructions, Properties properties,
Jar[] classpath ) throws Exception
{
properties.putAll( getDefaultProperties( currentProject ) );
properties.putAll( transformDirectives( originalInstructions ) );
Builder builder = new Builder();
- builder.setBase( currentProject.getBasedir() );
+ if ( currentProject.getBasedir() != null )
+ {
+ builder.setBase( currentProject.getBasedir() );
+ }
builder.setProperties( properties );
- builder.setClasspath( classpath );
+ if ( classpath != null )
+ {
+ builder.setClasspath( classpath );
+ }
+ return builder;
+ }
+
+ protected void addMavenInstructions( MavenProject currentProject, Builder builder ) throws Exception
+ {
// update BND instructions to add included Maven resources
includeMavenResources( currentProject, builder, getLog() );
@@ -423,18 +426,18 @@
dumpInstructions( "BND Instructions:", builder.getProperties(), getLog() );
dumpClasspath( "BND Classpath:", builder.getClasspath(), getLog() );
+ }
+
+ protected Builder buildOSGiBundle( MavenProject currentProject, Map originalInstructions, Properties properties,
+ Jar[] classpath ) throws Exception
+ {
+ Builder builder = getOSGiBuilder( currentProject, originalInstructions, properties, classpath );
+
+ addMavenInstructions( currentProject, builder );
builder.build();
- Jar jar = builder.getJar();
- dumpManifest( "BND Manifest:", jar.getManifest(), getLog() );
-
- String[] removeHeaders = builder.getProperty( Constants.REMOVEHEADERS, "" ).split( "," );
-
- mergeMavenManifest( currentProject, jar, removeHeaders, getLog() );
- builder.setJar( jar );
-
- dumpManifest( "Final Manifest:", jar.getManifest(), getLog() );
+ mergeMavenManifest( currentProject, builder );
return builder;
}
@@ -531,9 +534,13 @@
}
- protected void mergeMavenManifest( MavenProject currentProject, Jar jar, String[] removeHeaders, Log log )
- throws IOException
+ protected void mergeMavenManifest( MavenProject currentProject, Builder builder )
+ throws Exception
{
+ Jar jar = builder.getJar();
+
+ dumpManifest( "BND Manifest:", jar.getManifest(), getLog() );
+
boolean addMavenDescriptor = true;
try
@@ -587,6 +594,8 @@
Attributes mainMavenAttributes = mavenManifest.getMainAttributes();
mainMavenAttributes.putValue( "Created-By", "Apache Maven Bundle Plugin" );
+ String[] removeHeaders = builder.getProperty( Constants.REMOVEHEADERS, "" ).split( "," );
+
// apply -removeheaders to the custom manifest
for ( int i = 0; i < removeHeaders.length; i++ )
{
@@ -628,13 +637,17 @@
}
catch ( Exception e )
{
- log.warn( "Unable to merge Maven manifest: " + e.getLocalizedMessage() );
+ getLog().warn( "Unable to merge Maven manifest: " + e.getLocalizedMessage() );
}
if ( addMavenDescriptor )
{
doMavenMetadata( currentProject, jar );
}
+
+ dumpManifest( "Final Manifest:", builder.getJar().getManifest(), getLog() );
+
+ builder.setJar( jar );
}
@@ -824,7 +837,7 @@
private void doMavenMetadata( MavenProject currentProject, Jar jar ) throws IOException
{
String path = "META-INF/maven/" + currentProject.getGroupId() + "/" + currentProject.getArtifactId();
- File pomFile = new File( baseDir, "pom.xml" );
+ File pomFile = new File( currentProject.getBasedir(), "pom.xml" );
jar.putResource( path + "/pom.xml", new FileResource( pomFile ) );
Properties p = new Properties();
@@ -1029,7 +1042,7 @@
properties.putAll( getProperties( currentProject.getModel(), "pom." ) );
properties.putAll( getProperties( currentProject.getModel(), "project." ) );
- properties.put( "project.baseDir", baseDir );
+ properties.put( "project.baseDir", currentProject.getBasedir() );
properties.put( "project.build.directory", getBuildDirectory() );
properties.put( "project.build.outputdirectory", getOutputDirectory() );
@@ -1044,12 +1057,6 @@
}
- protected void setBasedir( File _basedir )
- {
- baseDir = _basedir;
- }
-
-
protected File getOutputDirectory()
{
return outputDirectory;
diff --git a/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java b/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java
index 729576c..17d2d44 100644
--- a/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java
+++ b/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java
@@ -25,11 +25,9 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.Set;
import java.util.jar.Manifest;
import aQute.lib.osgi.Builder;
-import aQute.lib.spring.XMLType;
import junit.framework.TestCase;
import org.apache.felix.bundleplugin.ManifestPlugin;
import org.apache.maven.model.Resource;
@@ -40,7 +38,6 @@
public void testBlueprint() throws Exception
{
-
MavenProjectStub project = new MavenProjectStub() {
private final List resources = new ArrayList();
@Override
@@ -52,6 +49,12 @@
public List getResources() {
return resources;
}
+
+ @Override
+ public File getBasedir()
+ {
+ return new File("target/tmp/basedir");
+ }
};
project.setGroupId( "group" );
project.setArtifactId( "artifact" );
@@ -63,7 +66,6 @@
project.addCompileSourceRoot(new File("src/test/resources").getAbsoluteFile().getCanonicalPath());
ManifestPlugin plugin = new ManifestPlugin();
- plugin.setBasedir(new File("target/tmp/basedir"));
plugin.setBuildDirectory("target/tmp/basedir/target");
plugin.setOutputDirectory(new File("target/tmp/basedir/target/classes"));
diff --git a/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java b/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java
index ed724d2..58257b3 100644
--- a/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java
+++ b/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java
@@ -52,7 +52,6 @@
{
plugin = new BundleAllPlugin();
File baseDirectory = new File( getBasedir() );
- plugin.setBasedir( baseDirectory );
File buildDirectory = new File( baseDirectory, "target" );
plugin.setBuildDirectory( buildDirectory.getPath() );
File outputDirectory = new File( buildDirectory, "test-classes" );
diff --git a/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java b/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
index fc3df49..bcafd68 100644
--- a/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
+++ b/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
@@ -51,7 +51,6 @@
super.setUp();
plugin = new BundlePlugin();
plugin.setMaven2OsgiConverter( new DefaultMaven2OsgiConverter() );
- plugin.setBasedir( new File( "." ) );
plugin.setBuildDirectory( "." );
plugin.setOutputDirectory( new File( "." ) );
}