You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by mc...@apache.org on 2011/06/28 18:06:25 UTC
svn commit: r1140698 - in /felix/trunk/bundleplugin/src:
main/java/org/apache/felix/bundleplugin/
test/java/org/apache/felix/bundleplugin/
Author: mcculls
Date: Tue Jun 28 16:06:24 2011
New Revision: 1140698
URL: http://svn.apache.org/viewvc?rev=1140698&view=rev
Log:
Refactor internals to help reduce code duplication
Modified:
felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java
felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java
felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java?rev=1140698&r1=1140697&r2=1140698&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java Tue Jun 28 16:06:24 2011
@@ -146,14 +146,6 @@ public class BundlePlugin extends Abstra
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 @@ public class BundlePlugin extends Abstra
}
- 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 @@ public class BundlePlugin extends Abstra
dumpInstructions( "BND Instructions:", builder.getProperties(), getLog() );
dumpClasspath( "BND Classpath:", builder.getClasspath(), getLog() );
+ }
- builder.build();
- Jar jar = builder.getJar();
-
- dumpManifest( "BND Manifest:", jar.getManifest(), getLog() );
+ protected Builder buildOSGiBundle( MavenProject currentProject, Map originalInstructions, Properties properties,
+ Jar[] classpath ) throws Exception
+ {
+ Builder builder = getOSGiBuilder( currentProject, originalInstructions, properties, classpath );
- String[] removeHeaders = builder.getProperty( Constants.REMOVEHEADERS, "" ).split( "," );
+ addMavenInstructions( currentProject, builder );
- mergeMavenManifest( currentProject, jar, removeHeaders, getLog() );
- builder.setJar( jar );
+ builder.build();
- dumpManifest( "Final Manifest:", jar.getManifest(), getLog() );
+ mergeMavenManifest( currentProject, builder );
return builder;
}
@@ -531,9 +534,13 @@ public class BundlePlugin extends Abstra
}
- 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 @@ public class BundlePlugin extends Abstra
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 @@ public class BundlePlugin extends Abstra
}
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 @@ public class BundlePlugin extends Abstra
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 @@ public class BundlePlugin extends Abstra
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 @@ public class BundlePlugin extends Abstra
}
- protected void setBasedir( File _basedir )
- {
- baseDir = _basedir;
- }
-
-
protected File getOutputDirectory()
{
return outputDirectory;
Modified: felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java?rev=1140698&r1=1140697&r2=1140698&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java (original)
+++ felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java Tue Jun 28 16:06:24 2011
@@ -25,11 +25,9 @@ import java.util.HashMap;
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 class BlueprintComponentTest exte
public void testBlueprint() throws Exception
{
-
MavenProjectStub project = new MavenProjectStub() {
private final List resources = new ArrayList();
@Override
@@ -52,6 +49,12 @@ public class BlueprintComponentTest exte
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 @@ public class BlueprintComponentTest exte
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"));
Modified: felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java?rev=1140698&r1=1140697&r2=1140698&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java (original)
+++ felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java Tue Jun 28 16:06:24 2011
@@ -52,7 +52,6 @@ public class BundleAllPluginTest extends
{
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" );
Modified: felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java?rev=1140698&r1=1140697&r2=1140698&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java (original)
+++ felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java Tue Jun 28 16:06:24 2011
@@ -51,7 +51,6 @@ public class BundlePluginTest extends Ab
super.setUp();
plugin = new BundlePlugin();
plugin.setMaven2OsgiConverter( new DefaultMaven2OsgiConverter() );
- plugin.setBasedir( new File( "." ) );
plugin.setBuildDirectory( "." );
plugin.setOutputDirectory( new File( "." ) );
}