Reduce code duplication
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1140774 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 91e8afa..d716c0d 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
@@ -286,10 +286,10 @@
}
- protected boolean reportErrors( String prefix, Builder builder )
+ protected boolean reportErrors( String prefix, Analyzer analyzer )
{
- List errors = builder.getErrors();
- List warnings = builder.getWarnings();
+ List errors = analyzer.getErrors();
+ List warnings = analyzer.getWarnings();
for ( Iterator w = warnings.iterator(); w.hasNext(); )
{
@@ -401,10 +401,7 @@
properties.putAll( transformDirectives( originalInstructions ) );
Builder builder = new Builder();
- if ( currentProject.getBasedir() != null )
- {
- builder.setBase( currentProject.getBasedir() );
- }
+ builder.setBase( getBase( currentProject ) );
builder.setProperties( properties );
if ( classpath != null )
{
@@ -416,11 +413,14 @@
protected void addMavenInstructions( MavenProject currentProject, Builder builder ) throws Exception
{
- // update BND instructions to add included Maven resources
- includeMavenResources( currentProject, builder, getLog() );
+ if ( currentProject.getBasedir() != null )
+ {
+ // update BND instructions to add included Maven resources
+ includeMavenResources( currentProject, builder, getLog() );
- // calculate default export/private settings based on sources
- addLocalPackages( outputDirectory, builder );
+ // calculate default export/private settings based on sources
+ addLocalPackages( outputDirectory, builder );
+ }
// update BND instructions to embed selected Maven dependencies
Collection embeddableArtifacts = getEmbeddableArtifacts( currentProject, builder );
@@ -543,7 +543,7 @@
dumpManifest( "BND Manifest:", jar.getManifest(), getLog() );
- boolean addMavenDescriptor = true;
+ boolean addMavenDescriptor = currentProject.getBasedir() != null;
try
{
@@ -552,7 +552,7 @@
*/
MavenArchiveConfiguration archiveConfig = JarPluginConfiguration.getArchiveConfiguration( currentProject );
String mavenManifestText = new MavenArchiver().getManifest( currentProject, archiveConfig ).toString();
- addMavenDescriptor = archiveConfig.isAddMavenDescriptor();
+ addMavenDescriptor = addMavenDescriptor && archiveConfig.isAddMavenDescriptor();
Manifest mavenManifest = new Manifest();
@@ -959,7 +959,7 @@
{
extension = currentProject.getArtifact().getType();
}
- if ( StringUtils.isEmpty( extension ) || "bundle".equals( extension ) )
+ if ( StringUtils.isEmpty( extension ) || "bundle".equals( extension ) || "pom".equals( extension ) )
{
extension = "jar"; // just in case maven gets confused
}
@@ -1044,7 +1044,7 @@
properties.putAll( getProperties( currentProject.getModel(), "pom." ) );
properties.putAll( getProperties( currentProject.getModel(), "project." ) );
- properties.put( "project.baseDir", currentProject.getBasedir() );
+ properties.put( "project.baseDir", getBase( currentProject ) );
properties.put( "project.build.directory", getBuildDirectory() );
properties.put( "project.build.outputdirectory", getOutputDirectory() );
@@ -1059,6 +1059,12 @@
}
+ protected static File getBase( MavenProject currentProject )
+ {
+ return currentProject.getBasedir() != null ? currentProject.getBasedir() : new File( "" );
+ }
+
+
protected File getOutputDirectory()
{
return outputDirectory;
@@ -1155,15 +1161,15 @@
}
- private static List getMavenResources( MavenProject project )
+ private static List getMavenResources( MavenProject currentProject )
{
- List resources = new ArrayList(project.getResources());
+ List resources = new ArrayList(currentProject.getResources());
- if ( project.getCompileSourceRoots() != null )
+ if ( currentProject.getCompileSourceRoots() != null )
{
// also scan for any "packageinfo" files lurking in the source folders
List packageInfoIncludes = Collections.singletonList( "**/packageinfo" );
- for ( Iterator i = project.getCompileSourceRoots().iterator(); i.hasNext(); )
+ for ( Iterator i = currentProject.getCompileSourceRoots().iterator(); i.hasNext(); )
{
String sourceRoot = (String) i.next();
Resource packageInfoResource = new Resource();
@@ -1177,12 +1183,12 @@
}
- protected static String getMavenResourcePaths( MavenProject project )
+ protected static String getMavenResourcePaths( MavenProject currentProject )
{
- final String basePath = project.getBasedir().getAbsolutePath();
+ final String basePath = currentProject.getBasedir().getAbsolutePath();
Set pathSet = new LinkedHashSet();
- for ( Iterator i = getMavenResources( project ).iterator(); i.hasNext(); )
+ for ( Iterator i = getMavenResources( currentProject ).iterator(); i.hasNext(); )
{
Resource resource = ( Resource ) i.next();
@@ -1272,7 +1278,7 @@
}
- protected Collection getEmbeddableArtifacts( MavenProject project, Analyzer analyzer )
+ protected Collection getEmbeddableArtifacts( MavenProject currentProject, Analyzer analyzer )
throws MojoExecutionException
{
final Collection artifacts;
@@ -1281,12 +1287,12 @@
if ( Boolean.valueOf( embedTransitive ).booleanValue() )
{
// includes transitive dependencies
- artifacts = project.getArtifacts();
+ artifacts = currentProject.getArtifacts();
}
else
{
// only includes direct dependencies
- artifacts = project.getDependencyArtifacts();
+ artifacts = currentProject.getDependencyArtifacts();
}
return getSelectedDependencies( artifacts );
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
index 6280fac..e690d87 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
@@ -103,7 +103,7 @@
public Manifest getManifest( MavenProject project, Jar[] classpath ) throws IOException, MojoFailureException,
MojoExecutionException, Exception
{
- return getManifest( project, new Properties(), new Properties(), classpath );
+ return getManifest( project, new LinkedHashMap(), new Properties(), classpath );
}
@@ -111,22 +111,8 @@
throws IOException, MojoFailureException, MojoExecutionException, Exception
{
Analyzer analyzer = getAnalyzer( project, instructions, properties, classpath );
-
- List errors = analyzer.getErrors();
- List warnings = analyzer.getWarnings();
-
- for ( Iterator w = warnings.iterator(); w.hasNext(); )
- {
- String msg = ( String ) w.next();
- getLog().warn( "Warning in manifest for " + project.getArtifact() + " : " + msg );
- }
- for ( Iterator e = errors.iterator(); e.hasNext(); )
- {
- String msg = ( String ) e.next();
- getLog().error( "Error in manifest for " + project.getArtifact() + " : " + msg );
- }
-
- if ( errors.size() > 0 )
+ boolean hasErrors = reportErrors( "Manifest " + project.getArtifact(), analyzer );
+ if ( hasErrors )
{
String failok = analyzer.getProperty( "-failok" );
if ( null == failok || "false".equalsIgnoreCase( failok ) )
@@ -165,19 +151,7 @@
throw new FileNotFoundException( file.getPath() );
}
- properties.putAll( getDefaultProperties( project ) );
- properties.putAll( transformDirectives( instructions ) );
-
-// PackageVersionAnalyzer analyzer = new PackageVersionAnalyzer();
- Builder analyzer = new Builder();
-
- if ( project.getBasedir() != null )
- analyzer.setBase( project.getBasedir() );
-
- analyzer.setProperties( properties );
-
- if ( classpath != null )
- analyzer.setClasspath( classpath );
+ Builder analyzer = getOSGiBuilder( project, instructions, properties, classpath );
analyzer.setJar( file );
@@ -189,17 +163,12 @@
analyzer.setProperty( Analyzer.EXPORT_PACKAGE, export );
}
- // Apply Embed-Dependency headers, even though the contents won't be changed
- Collection embeddableArtifacts = getEmbeddableArtifacts( project, analyzer );
- new DependencyEmbedder( getLog(), embeddableArtifacts ).processHeaders( analyzer );
-
- dumpInstructions( "BND Instructions:", analyzer.getProperties(), getLog() );
- dumpClasspath( "BND Classpath:", analyzer.getClasspath(), getLog() );
+ addMavenInstructions( project, analyzer );
analyzer.mergeManifest( analyzer.getJar().getManifest() );
analyzer.calcManifest();
- dumpManifest( "BND Manifest:", analyzer.getJar().getManifest(), getLog() );
+ mergeMavenManifest( project, analyzer );
return analyzer;
}
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 58257b3..253725c 100644
--- a/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java
+++ b/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java
@@ -93,6 +93,8 @@
artifact.setVersion( "1.0.0.0" );
MavenProject project = new MavenProjectStub();
+ project.setGroupId( artifact.getGroupId() );
+ project.setArtifactId( artifact.getArtifactId() );
project.setVersion( artifact.getVersion() );
project.setArtifact( artifact );
project.setArtifacts( Collections.EMPTY_SET );