Author: cziegeler
Date: Tue Mar 3 16:45:36 2015
New Revision: 1663739
URL: http://svn.apache.org/r1663739
Log:
Add hack to copy non maven resources into target/classes
Removed:
felix/sandbox/cziegeler/bnd-maven-plugin/src/main/java/org/apache/felix/bundleplugin/BundleInfo.java
Modified:
felix/sandbox/cziegeler/bnd-maven-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
felix/sandbox/cziegeler/bnd-maven-plugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
Modified:
felix/sandbox/cziegeler/bnd-maven-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/cziegeler/bnd-maven-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java?rev=1663739&r1=1663738&r2=1663739&view=diff
==============================================================================
---
felix/sandbox/cziegeler/bnd-maven-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
(original)
+++
felix/sandbox/cziegeler/bnd-maven-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
Tue Mar 3 16:45:36 2015
@@ -40,7 +40,6 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.jar.Attributes;
@@ -68,7 +67,6 @@ import org.apache.maven.project.MavenPro
import org.apache.maven.project.MavenProjectHelper;
import org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter;
import org.apache.maven.shared.osgi.Maven2OsgiConverter;
-import org.codehaus.plexus.archiver.UnArchiver;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.FileUtils;
@@ -103,35 +101,35 @@ public class BundlePlugin extends Abstra
*
*/
@Parameter(property="manifestLocation",
defaultValue="${project.build.outputDirectory}/META-INF")
- protected File manifestLocation;
+ private File manifestLocation;
/**
* Output a nicely formatted manifest that still respects the 72 character
line limit.
*
*/
@Parameter(property="niceManifest", defaultValue="false")
- protected boolean niceManifest;
+ private boolean niceManifest;
/**
* File where the BND instructions will be dumped
*
*/
@Parameter(property="dumpInstructions")
- protected File dumpInstructions;
+ private File dumpInstructions;
/**
* File where the BND class-path will be dumped
*
*/
@Parameter(property="dumpClasspath")
- protected File dumpClasspath;
+ private File dumpClasspath;
/**
* Comma separated list of artifactIds to exclude from the dependency
classpath passed to BND (use "true" to exclude everything)
*
*/
@Parameter(property="excludeDependencies")
- protected String excludeDependencies;
+ private String excludeDependencies;
/**
* Final name of the bundle (without classifier or extension)
@@ -146,7 +144,7 @@ public class BundlePlugin extends Abstra
*
*/
@Parameter
- protected String classifier;
+ private String classifier;
/**
* Packaging type of the bundle to be installed. For example, "jar".
@@ -154,7 +152,7 @@ public class BundlePlugin extends Abstra
*
*/
@Parameter
- protected String packaging;
+ private String packaging;
@Component
private MavenProjectHelper m_projectHelper;
@@ -170,7 +168,7 @@ public class BundlePlugin extends Abstra
*
*/
@Parameter
- protected List<String> supportedProjectTypes = Arrays.asList( new String[]
+ private List<String> supportedProjectTypes = Arrays.asList( new String[]
{ "jar", "bundle" } );
/**
@@ -232,19 +230,13 @@ public class BundlePlugin extends Abstra
private static final String NL = System.getProperty( "line.separator" );
- protected Maven2OsgiConverter getMaven2OsgiConverter()
+ private Maven2OsgiConverter getMaven2OsgiConverter()
{
return m_maven2OsgiConverter;
}
- protected void setMaven2OsgiConverter( Maven2OsgiConverter
maven2OsgiConverter )
- {
- m_maven2OsgiConverter = maven2OsgiConverter;
- }
-
-
- protected MavenProject getProject()
+ private MavenProject getProject()
{
return project;
}
@@ -271,7 +263,7 @@ public class BundlePlugin extends Abstra
}
- protected void execute( MavenProject currentProject, Map
originalInstructions, Properties properties )
+ private void execute( MavenProject currentProject, Map<String, String>
originalInstructions, Properties properties )
throws MojoExecutionException
{
try
@@ -286,20 +278,20 @@ public class BundlePlugin extends Abstra
/* transform directives from their XML form to the expected BND syntax
(eg. _include becomes -include) */
- protected static Map transformDirectives( Map originalInstructions )
+ private static Map<String, String> transformDirectives( Map<String,
String> originalInstructions )
{
- Map transformedInstructions = new LinkedHashMap();
- for ( Iterator i = originalInstructions.entrySet().iterator();
i.hasNext(); )
+ Map<String, String> transformedInstructions = new
LinkedHashMap<String, String>();
+ for ( Iterator<Map.Entry<String, String>> i =
originalInstructions.entrySet().iterator(); i.hasNext(); )
{
- Map.Entry e = ( Map.Entry ) i.next();
+ Map.Entry<String, String> e = i.next();
- String key = ( String ) e.getKey();
+ String key = e.getKey();
if ( key.startsWith( "_" ) )
{
key = "-" + key.substring( 1 );
}
- String value = ( String ) e.getValue();
+ String value = e.getValue();
if ( null == value )
{
value = "";
@@ -321,22 +313,22 @@ public class BundlePlugin extends Abstra
}
- protected boolean reportErrors( String prefix, Analyzer analyzer )
+ private boolean reportErrors( String prefix, Analyzer analyzer )
{
- List errors = analyzer.getErrors();
- List warnings = analyzer.getWarnings();
+ List<String> errors = analyzer.getErrors();
+ List<String> warnings = analyzer.getWarnings();
- for ( Iterator w = warnings.iterator(); w.hasNext(); )
+ for ( Iterator<String> w = warnings.iterator(); w.hasNext(); )
{
- String msg = ( String ) w.next();
+ String msg = w.next();
getLog().warn( prefix + " : " + msg );
}
boolean hasErrors = false;
String fileNotFound = "Input file does not exist: ";
- for ( Iterator e = errors.iterator(); e.hasNext(); )
+ for ( Iterator<String> e = errors.iterator(); e.hasNext(); )
{
- String msg = ( String ) e.next();
+ String msg = e.next();
if ( msg.startsWith( fileNotFound ) && msg.endsWith( "~" ) )
{
// treat as warning; this error happens when you have
duplicate entries in Include-Resource
@@ -353,7 +345,7 @@ public class BundlePlugin extends Abstra
}
- protected void execute( MavenProject currentProject, Map
originalInstructions, Properties properties,
+ private void execute( MavenProject currentProject, Map<String, String>
originalInstructions, Properties properties,
Jar[] classpath ) throws MojoExecutionException
{
try
@@ -371,7 +363,26 @@ public class BundlePlugin extends Abstra
throw new MojoFailureException( "Error(s) found in bundle
configuration" );
}
}
-/*
+
+ for (Map.Entry<String,aQute.bnd.osgi.Resource> entry :
builder.getJar().getResources().entrySet())
+ {
+ // a little bit hacky
+ final String key = entry.getValue().toString();
+ if ( !key.startsWith(this.buildDirectory) &&
!entry.getKey().startsWith("META-INF/"))
+ {
+ final File f = new File(this.buildDirectory +
File.separator + entry.getKey());
+ final FileOutputStream fos = new FileOutputStream(f);
+ try {
+ entry.getValue().write(fos);
+ }
+ finally
+ {
+ fos.close();
+ }
+ }
+ }
+
+ /*
// attach bundle to maven project
jarFile.getParentFile().mkdirs();
builder.getJar().write( jarFile );
@@ -436,18 +447,18 @@ public class BundlePlugin extends Abstra
}
- protected Builder getOSGiBuilder( MavenProject currentProject, Map
originalInstructions, Properties properties,
+ private Builder getOSGiBuilder( MavenProject currentProject, Map<String,
String> originalInstructions, Properties properties,
Jar[] classpath ) throws Exception
{
properties.putAll( getDefaultProperties( currentProject ) );
properties.putAll( transformDirectives( originalInstructions ) );
// process overrides from project
- final Map addProps = new HashMap();
- final Iterator iter =
currentProject.getProperties().entrySet().iterator();
+ final Map<String, Object> addProps = new HashMap<String, Object>();
+ final Iterator<Map.Entry<Object, Object>> iter =
currentProject.getProperties().entrySet().iterator();
while ( iter.hasNext() )
{
- final Map.Entry entry = (Entry) iter.next();
+ final Map.Entry<Object, Object> entry = iter.next();
final String key = entry.getKey().toString();
if ( key.startsWith(BUNDLE_PLUGIN_EXTENSION) )
{
@@ -464,7 +475,7 @@ public class BundlePlugin extends Abstra
}
}
properties.putAll( addProps );
- final Iterator keyIter = addProps.keySet().iterator();
+ final Iterator<String> keyIter = addProps.keySet().iterator();
while ( keyIter.hasNext() )
{
properties.remove(BUNDLE_PLUGIN_EXTENSION + keyIter.next());
@@ -489,7 +500,7 @@ public class BundlePlugin extends Abstra
{
sb.append(",");
}
- sb.append(sb);
+ sb.append(s);
}
properties.setProperty(Analyzer.PLUGIN, sb.toString());
}
@@ -509,13 +520,13 @@ public class BundlePlugin extends Abstra
}
- protected static Properties sanitize( Properties properties )
+ private static Properties sanitize( Properties properties )
{
// convert any non-String keys/values to Strings
Properties sanitizedEntries = new Properties();
- for ( Iterator itr = properties.entrySet().iterator(); itr.hasNext(); )
+ for ( Iterator<Map.Entry<Object, Object>> itr =
properties.entrySet().iterator(); itr.hasNext(); )
{
- Map.Entry entry = ( Map.Entry ) itr.next();
+ Map.Entry<Object, Object> entry = itr.next();
if ( entry.getKey() instanceof String == false )
{
String key = sanitize( entry.getKey() );
@@ -535,7 +546,7 @@ public class BundlePlugin extends Abstra
}
- protected static String sanitize( Object value )
+ private static String sanitize( Object value )
{
if ( value instanceof String )
{
@@ -570,7 +581,7 @@ public class BundlePlugin extends Abstra
}
- protected void addMavenInstructions( MavenProject currentProject, Builder
builder ) throws Exception
+ private void addMavenInstructions( MavenProject currentProject, Builder
builder ) throws Exception
{
if ( currentProject.getBasedir() != null )
{
@@ -585,7 +596,7 @@ public class BundlePlugin extends Abstra
}
// update BND instructions to embed selected Maven dependencies
- Collection embeddableArtifacts = getEmbeddableArtifacts(
currentProject, builder );
+ Collection<Artifact> embeddableArtifacts = getEmbeddableArtifacts(
currentProject, builder );
new DependencyEmbedder( getLog(), embeddableArtifacts
).processHeaders( builder );
if ( dumpInstructions != null || getLog().isDebugEnabled() )
@@ -614,7 +625,7 @@ public class BundlePlugin extends Abstra
}
- protected Builder buildOSGiBundle( MavenProject currentProject, Map
originalInstructions, Properties properties,
+ private Builder buildOSGiBundle( MavenProject currentProject, Map<String,
String> originalInstructions, Properties properties,
Jar[] classpath ) throws Exception
{
Builder builder = getOSGiBuilder( currentProject,
originalInstructions, properties, classpath );
@@ -629,16 +640,17 @@ public class BundlePlugin extends Abstra
}
- protected static StringBuilder dumpInstructions( Properties properties,
StringBuilder buf )
+ private static StringBuilder dumpInstructions( Properties properties,
StringBuilder buf )
{
try
{
buf.append(
"#-----------------------------------------------------------------------" + NL
);
Properties stringProperties = new Properties();
- for ( Enumeration e = properties.propertyNames();
e.hasMoreElements(); )
+ for ( @SuppressWarnings("unchecked")
+ Enumeration<String> e = (Enumeration<String>)
properties.propertyNames(); e.hasMoreElements(); )
{
// we can only store String properties
- String key = ( String ) e.nextElement();
+ String key = e.nextElement();
String value = properties.getProperty( key );
if ( value != null )
{
@@ -658,15 +670,15 @@ public class BundlePlugin extends Abstra
}
- protected static StringBuilder dumpClasspath( List classpath,
StringBuilder buf )
+ private static StringBuilder dumpClasspath( List<Jar> classpath,
StringBuilder buf )
{
try
{
buf.append(
"#-----------------------------------------------------------------------" + NL
);
buf.append( "-classpath:\\" + NL );
- for ( Iterator i = classpath.iterator(); i.hasNext(); )
+ for ( Iterator<Jar> i = classpath.iterator(); i.hasNext(); )
{
- File path = ( ( Jar ) i.next() ).getSource();
+ File path = i.next().getSource();
if ( path != null )
{
buf.append( ' ' + path.toString() + ( i.hasNext() ? ",\\"
: "" ) + NL );
@@ -682,7 +694,7 @@ public class BundlePlugin extends Abstra
}
- protected static StringBuilder dumpManifest( Manifest manifest,
StringBuilder buf )
+ private static StringBuilder dumpManifest( Manifest manifest,
StringBuilder buf )
{
try
{
@@ -700,7 +712,7 @@ public class BundlePlugin extends Abstra
}
- protected static void includeMavenResources( MavenProject currentProject,
Analyzer analyzer, Log log )
+ private static void includeMavenResources( MavenProject currentProject,
Analyzer analyzer, Log log )
{
// pass maven resource paths onto BND analyzer
final String mavenResourcePaths = getMavenResourcePaths(
currentProject, false );
@@ -734,7 +746,7 @@ public class BundlePlugin extends Abstra
}
- protected void mergeMavenManifest( MavenProject currentProject, Builder
builder ) throws Exception
+ private void mergeMavenManifest( MavenProject currentProject, Builder
builder ) throws Exception
{
Jar jar = builder.getJar();
@@ -780,19 +792,19 @@ public class BundlePlugin extends Abstra
/*
* Add customized manifest sections (for some reason
MavenArchiver doesn't do this for us)
*/
- List sections = archiveConfig.getManifestSections();
- for ( Iterator i = sections.iterator(); i.hasNext(); )
+ List<ManifestSection> sections =
archiveConfig.getManifestSections();
+ for ( Iterator<ManifestSection> i = sections.iterator();
i.hasNext(); )
{
- ManifestSection section = ( ManifestSection ) i.next();
+ ManifestSection section = i.next();
Attributes attributes = new Attributes();
if ( !section.isManifestEntriesEmpty() )
{
- Map entries = section.getManifestEntries();
- for ( Iterator j = entries.entrySet().iterator();
j.hasNext(); )
+ Map<String, String> entries =
section.getManifestEntries();
+ for ( Iterator<Map.Entry<String, String>> j =
entries.entrySet().iterator(); j.hasNext(); )
{
- Map.Entry entry = ( Map.Entry ) j.next();
- attributes.putValue( ( String ) entry.getKey(), (
String ) entry.getValue() );
+ Map.Entry<String, String> entry = j.next();
+ attributes.putValue( entry.getKey(),
entry.getValue() );
}
}
@@ -808,7 +820,7 @@ public class BundlePlugin extends Abstra
// apply -removeheaders to the custom manifest
for ( int i = 0; i < removeHeaders.length; i++ )
{
- for ( Iterator j = mainMavenAttributes.keySet().iterator();
j.hasNext(); )
+ for ( Iterator<Object> j =
mainMavenAttributes.keySet().iterator(); j.hasNext(); )
{
if ( j.next().toString().matches( removeHeaders[i].trim()
) )
{
@@ -829,7 +841,7 @@ public class BundlePlugin extends Abstra
String importPackages =
bundleManifest.getMainAttributes().getValue( "Import-Package" );
if ( importPackages != null )
{
- Set optionalPackages = getOptionalPackages( currentProject );
+ Set<String> optionalPackages = getOptionalPackages(
currentProject );
Map<String, ? extends Map<String, String>> values = new
Analyzer().parseHeader( importPackages );
for ( Map.Entry<String, ? extends Map<String, String>> entry :
values.entrySet() )
@@ -866,13 +878,13 @@ public class BundlePlugin extends Abstra
}
- protected Set getOptionalPackages( MavenProject currentProject ) throws
IOException, MojoExecutionException
+ private Set<String> getOptionalPackages( MavenProject currentProject )
throws IOException, MojoExecutionException
{
- ArrayList inscope = new ArrayList();
- final Collection artifacts = getSelectedDependencies(
currentProject.getArtifacts() );
- for ( Iterator it = artifacts.iterator(); it.hasNext(); )
+ ArrayList<Artifact> inscope = new ArrayList<Artifact>();
+ final Collection<Artifact> artifacts = getSelectedDependencies(
currentProject.getArtifacts() );
+ for ( Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); )
{
- Artifact artifact = ( Artifact ) it.next();
+ Artifact artifact = it.next();
if ( artifact.getArtifactHandler().isAddedToClasspath() )
{
if ( !Artifact.SCOPE_TEST.equals( artifact.getScope() ) )
@@ -882,10 +894,10 @@ public class BundlePlugin extends Abstra
}
}
- HashSet optionalArtifactIds = new HashSet();
- for ( Iterator it = inscope.iterator(); it.hasNext(); )
+ HashSet<String> optionalArtifactIds = new HashSet<String>();
+ for ( Iterator<Artifact> it = inscope.iterator(); it.hasNext(); )
{
- Artifact artifact = ( Artifact ) it.next();
+ Artifact artifact = it.next();
if ( artifact.isOptional() )
{
String id = artifact.toString();
@@ -899,11 +911,11 @@ public class BundlePlugin extends Abstra
}
- HashSet required = new HashSet();
- HashSet optional = new HashSet();
- for ( Iterator it = inscope.iterator(); it.hasNext(); )
+ HashSet<String> required = new HashSet<String>();
+ HashSet<String> optional = new HashSet<String>();
+ for ( Iterator<Artifact> it = inscope.iterator(); it.hasNext(); )
{
- Artifact artifact = ( Artifact ) it.next();
+ Artifact artifact = it.next();
File file = getFile( artifact );
if ( file == null )
{
@@ -933,12 +945,12 @@ public class BundlePlugin extends Abstra
*
* @param artifact
*/
- protected boolean isTransitivelyOptional( HashSet optionalArtifactIds,
Artifact artifact )
+ private boolean isTransitivelyOptional( HashSet<String>
optionalArtifactIds, Artifact artifact )
{
- List trail = artifact.getDependencyTrail();
- for ( Iterator iterator = trail.iterator(); iterator.hasNext(); )
+ List<String> trail = artifact.getDependencyTrail();
+ for ( Iterator<String> iterator = trail.iterator();
iterator.hasNext(); )
{
- String next = ( String ) iterator.next();
+ String next = iterator.next();
if ( optionalArtifactIds.contains( next ) )
{
return true;
@@ -947,63 +959,9 @@ public class BundlePlugin extends Abstra
return false;
}
-
- private void unpackBundle( File jarFile )
+ private static Map<String, String> getProperties( Model projectModel,
String prefix )
{
- File outputDir = getOutputDirectory();
- if ( null == outputDir )
- {
- outputDir = new File( getBuildDirectory(), "classes" );
- }
-
- try
- {
- /*
- * this directory must exist before unpacking, otherwise the plexus
- * unarchiver decides to use the current working directory instead!
- */
- if ( !outputDir.exists() )
- {
- outputDir.mkdirs();
- }
-
- UnArchiver unArchiver = m_archiverManager.getUnArchiver( "jar" );
- unArchiver.setDestDirectory( outputDir );
- unArchiver.setSourceFile( jarFile );
- unArchiver.extract();
- }
- catch ( Exception e )
- {
- getLog().error( "Problem unpacking " + jarFile + " to " +
outputDir, e );
- }
- }
-
-
- protected static String removeTagFromInstruction( String instruction,
String tag )
- {
- StringBuffer buf = new StringBuffer();
-
- String[] clauses = instruction.split( "," );
- for ( int i = 0; i < clauses.length; i++ )
- {
- String clause = clauses[i].trim();
- if ( !tag.equals( clause ) )
- {
- if ( buf.length() > 0 )
- {
- buf.append( ',' );
- }
- buf.append( clause );
- }
- }
-
- return buf.toString();
- }
-
-
- private static Map getProperties( Model projectModel, String prefix )
- {
- Map properties = new LinkedHashMap();
+ Map<String, String> properties = new LinkedHashMap<String, String>();
Method methods[] = Model.class.getDeclaredMethods();
for ( int i = 0; i < methods.length; i++ )
{
@@ -1019,7 +977,7 @@ public class BundlePlugin extends Abstra
if ( v.getClass().isArray() )
properties.put( name, Arrays.asList( ( Object[] )
v ).toString() );
else
- properties.put( name, v );
+ properties.put( name, v.toString() );
}
}
@@ -1033,15 +991,15 @@ public class BundlePlugin extends Abstra
}
- private static StringBuffer printLicenses( List licenses )
+ private static StringBuffer printLicenses( List<License> licenses )
{
if ( licenses == null || licenses.size() == 0 )
return null;
StringBuffer sb = new StringBuffer();
String del = "";
- for ( Iterator i = licenses.iterator(); i.hasNext(); )
+ for ( Iterator<License> i = licenses.iterator(); i.hasNext(); )
{
- License l = ( License ) i.next();
+ License l = i.next();
String url = l.getUrl();
if ( url == null )
continue;
@@ -1075,19 +1033,19 @@ public class BundlePlugin extends Abstra
}
- protected Jar[] getClasspath( MavenProject currentProject ) throws
IOException, MojoExecutionException
+ private Jar[] getClasspath( MavenProject currentProject ) throws
IOException, MojoExecutionException
{
- List list = new ArrayList();
+ List<Jar> list = new ArrayList<Jar>();
if ( getOutputDirectory() != null && getOutputDirectory().exists() )
{
list.add( new Jar( ".", getOutputDirectory() ) );
}
- final Collection artifacts = getSelectedDependencies(
currentProject.getArtifacts() );
- for ( Iterator it = artifacts.iterator(); it.hasNext(); )
+ final Collection<Artifact> artifacts = getSelectedDependencies(
currentProject.getArtifacts() );
+ for ( Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); )
{
- Artifact artifact = ( Artifact ) it.next();
+ Artifact artifact = it.next();
if ( artifact.getArtifactHandler().isAddedToClasspath() )
{
if ( !Artifact.SCOPE_TEST.equals( artifact.getScope() ) )
@@ -1111,7 +1069,7 @@ public class BundlePlugin extends Abstra
}
- private Collection getSelectedDependencies( Collection artifacts ) throws
MojoExecutionException
+ private Collection<Artifact> getSelectedDependencies( Collection<Artifact>
artifacts ) throws MojoExecutionException
{
if ( null == excludeDependencies || excludeDependencies.length() == 0 )
{
@@ -1119,10 +1077,10 @@ public class BundlePlugin extends Abstra
}
else if ( "true".equalsIgnoreCase( excludeDependencies ) )
{
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
- Collection selectedDependencies = new LinkedHashSet( artifacts );
+ Collection<Artifact> selectedDependencies = new
LinkedHashSet<Artifact>( artifacts );
DependencyExcluder excluder = new DependencyExcluder( artifacts );
excluder.processHeaders( excludeDependencies );
selectedDependencies.removeAll( excluder.getExcludedArtifacts() );
@@ -1136,7 +1094,7 @@ public class BundlePlugin extends Abstra
*
* @param artifact
*/
- protected File getFile( Artifact artifact )
+ private File getFile( Artifact artifact )
{
return artifact.getFile();
}
@@ -1155,21 +1113,9 @@ public class BundlePlugin extends Abstra
/**
- * Convert a Maven version into an OSGi compliant version
- *
- * @param version Maven version
- * @return the OSGi version
- */
- protected String convertVersionToOsgi( String version )
- {
- return getMaven2OsgiConverter().getVersion( version );
- }
-
-
- /**
* TODO this should return getMaven2Osgi().getBundleFileName(
project.getArtifact() )
*/
- protected String getBundleName( MavenProject currentProject )
+ private String getBundleName( MavenProject currentProject )
{
String extension;
try
@@ -1192,19 +1138,13 @@ public class BundlePlugin extends Abstra
}
- protected String getBuildDirectory()
+ private String getBuildDirectory()
{
return buildDirectory;
}
- protected void setBuildDirectory( String _buildirectory )
- {
- buildDirectory = _buildirectory;
- }
-
-
- protected Properties getDefaultProperties( MavenProject currentProject )
+ private Properties getDefaultProperties( MavenProject currentProject )
{
Properties properties = new Properties();
@@ -1256,9 +1196,9 @@ public class BundlePlugin extends Abstra
properties.putAll( currentProject.getProperties() );
properties.putAll( currentProject.getModel().getProperties() );
- for ( Iterator i = currentProject.getFilters().iterator();
i.hasNext(); )
+ for ( Iterator<String> i = currentProject.getFilters().iterator();
i.hasNext(); )
{
- File filterFile = new File( ( String ) i.next() );
+ File filterFile = new File( i.next() );
if ( filterFile.isFile() )
{
properties.putAll( PropertyUtils.loadProperties( filterFile )
);
@@ -1271,7 +1211,7 @@ public class BundlePlugin extends Abstra
{
// don't pass upper-case session settings to bnd as they end
up in the manifest
Properties sessionProperties =
m_mavenSession.getExecutionProperties();
- for ( Enumeration e = sessionProperties.propertyNames();
e.hasMoreElements(); )
+ for ( Enumeration<?> e = sessionProperties.propertyNames();
e.hasMoreElements(); )
{
String key = ( String ) e.nextElement();
if ( key.length() > 0 && !Character.isUpperCase(
key.charAt( 0 ) ) )
@@ -1300,24 +1240,18 @@ public class BundlePlugin extends Abstra
}
- protected static File getBase( MavenProject currentProject )
+ private static File getBase( MavenProject currentProject )
{
return currentProject.getBasedir() != null ?
currentProject.getBasedir() : new File( "" );
}
- protected File getOutputDirectory()
+ private File getOutputDirectory()
{
return outputDirectory;
}
- protected void setOutputDirectory( File _outputDirectory )
- {
- outputDirectory = _outputDirectory;
- }
-
-
private static void addLocalPackages( File outputDirectory, Analyzer
analyzer ) throws IOException
{
Packages packages = new Packages();
@@ -1415,17 +1349,17 @@ public class BundlePlugin extends Abstra
}
- private static List getMavenResources( MavenProject currentProject,
boolean test )
+ private static List<Resource> getMavenResources( MavenProject
currentProject, boolean test )
{
- List resources = new ArrayList( test ?
currentProject.getTestResources() : currentProject.getResources() );
+ List<Resource> resources = new ArrayList<Resource>( test ?
currentProject.getTestResources() : currentProject.getResources() );
if ( currentProject.getCompileSourceRoots() != null )
{
// also scan for any "packageinfo" files lurking in the source
folders
- List packageInfoIncludes = Collections.singletonList(
"**/packageinfo" );
- for ( Iterator i =
currentProject.getCompileSourceRoots().iterator(); i.hasNext(); )
+ List<String> packageInfoIncludes = Collections.singletonList(
"**/packageinfo" );
+ for ( Iterator<String> i =
currentProject.getCompileSourceRoots().iterator(); i.hasNext(); )
{
- String sourceRoot = ( String ) i.next();
+ String sourceRoot = i.next();
Resource packageInfoResource = new Resource();
packageInfoResource.setDirectory( sourceRoot );
packageInfoResource.setIncludes( packageInfoIncludes );
@@ -1437,14 +1371,14 @@ public class BundlePlugin extends Abstra
}
- protected static String getMavenResourcePaths( MavenProject
currentProject, boolean test )
+ private static String getMavenResourcePaths( MavenProject currentProject,
boolean test )
{
final String basePath = currentProject.getBasedir().getAbsolutePath();
- Set pathSet = new LinkedHashSet();
- for ( Iterator i = getMavenResources( currentProject, test
).iterator(); i.hasNext(); )
+ Set<String> pathSet = new LinkedHashSet<String>();
+ for ( Iterator<Resource> i = getMavenResources( currentProject, test
).iterator(); i.hasNext(); )
{
- Resource resource = ( Resource ) i.next();
+ Resource resource = i.next();
final String sourcePath = resource.getDirectory();
final String targetPath = resource.getTargetPath();
@@ -1472,11 +1406,11 @@ public class BundlePlugin extends Abstra
scanner.addDefaultExcludes();
scanner.scan();
- List includedFiles = Arrays.asList( scanner.getIncludedFiles()
);
+ List<String> includedFiles = Arrays.asList(
scanner.getIncludedFiles() );
- for ( Iterator j = includedFiles.iterator(); j.hasNext(); )
+ for ( Iterator<String> j = includedFiles.iterator();
j.hasNext(); )
{
- String name = ( String ) j.next();
+ String name = j.next();
String path = sourcePath + '/' + name;
// make relative to project
@@ -1518,8 +1452,8 @@ public class BundlePlugin extends Abstra
}
}
- StringBuffer resourcePaths = new StringBuffer();
- for ( Iterator i = pathSet.iterator(); i.hasNext(); )
+ StringBuilder resourcePaths = new StringBuilder();
+ for ( Iterator<String> i = pathSet.iterator(); i.hasNext(); )
{
resourcePaths.append( i.next() );
if ( i.hasNext() )
@@ -1532,10 +1466,10 @@ public class BundlePlugin extends Abstra
}
- protected Collection getEmbeddableArtifacts( MavenProject currentProject,
Analyzer analyzer )
+ private Collection<Artifact> getEmbeddableArtifacts( MavenProject
currentProject, Analyzer analyzer )
throws MojoExecutionException
{
- final Collection artifacts;
+ final Collection<Artifact> artifacts;
String embedTransitive = analyzer.getProperty(
DependencyEmbedder.EMBED_TRANSITIVE );
if ( Boolean.valueOf( embedTransitive ).booleanValue() )
@@ -1553,27 +1487,27 @@ public class BundlePlugin extends Abstra
}
- protected static void addMavenSourcePath( MavenProject currentProject,
Analyzer analyzer, Log log )
+ private static void addMavenSourcePath( MavenProject currentProject,
Analyzer analyzer, Log log )
{
// pass maven source paths onto BND analyzer
StringBuilder mavenSourcePaths = new StringBuilder();
StringBuilder mavenTestSourcePaths = new StringBuilder();
- Map<StringBuilder, List<?>> map = new HashMap<StringBuilder,
List<?>>(2);
+ Map<StringBuilder, List<String>> map = new HashMap<StringBuilder,
List<String>>(2);
map.put(mavenSourcePaths, currentProject.getCompileSourceRoots() );
map.put(mavenTestSourcePaths,
currentProject.getTestCompileSourceRoots() );
- for ( Map.Entry<StringBuilder, List<?>> entry : map.entrySet() )
+ for ( Map.Entry<StringBuilder, List<String>> entry : map.entrySet() )
{
- List<?> compileSourceRoots = entry.getValue();
+ List<String> compileSourceRoots = entry.getValue();
if ( compileSourceRoots != null )
{
StringBuilder sourcePaths = entry.getKey();
- for ( Iterator i = compileSourceRoots.iterator(); i.hasNext();
)
+ for ( Iterator<String> i = compileSourceRoots.iterator();
i.hasNext(); )
{
if ( sourcePaths.length() > 0 )
{
sourcePaths.append( ',' );
}
- sourcePaths.append( ( String ) i.next() );
+ sourcePaths.append( i.next() );
}
}
}
Modified:
felix/sandbox/cziegeler/bnd-maven-plugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/cziegeler/bnd-maven-plugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java?rev=1663739&r1=1663738&r2=1663739&view=diff
==============================================================================
---
felix/sandbox/cziegeler/bnd-maven-plugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
(original)
+++
felix/sandbox/cziegeler/bnd-maven-plugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
Tue Mar 3 16:45:36 2015
@@ -34,7 +34,7 @@ import aQute.bnd.osgi.Analyzer;
/**
* Add BND directives to embed selected dependencies inside a bundle
- *
+ *
* @author <a href="mailto:[email protected]">Felix Project Team</a>
*/
public final class DependencyEmbedder extends AbstractDependencyFilter
@@ -278,7 +278,7 @@ public final class DependencyEmbedder ex
// every occurance of MAVEN_DEPENDENCIES and a following comma
with an empty string
if ( mavenDependencies.length() == 0 )
{
- String cleanInstruction =
BundlePlugin.removeTagFromInstruction( instruction, MAVEN_DEPENDENCIES );
+ String cleanInstruction = removeTagFromInstruction(
instruction, MAVEN_DEPENDENCIES );
analyzer.setProperty( directiveName, cleanInstruction );
}
else
@@ -309,4 +309,25 @@ public final class DependencyEmbedder ex
}
// otherwise leave instruction unchanged
}
+
+ private static String removeTagFromInstruction( String instruction, String
tag )
+ {
+ StringBuffer buf = new StringBuffer();
+
+ String[] clauses = instruction.split( "," );
+ for ( int i = 0; i < clauses.length; i++ )
+ {
+ String clause = clauses[i].trim();
+ if ( !tag.equals( clause ) )
+ {
+ if ( buf.length() > 0 )
+ {
+ buf.append( ',' );
+ }
+ buf.append( clause );
+ }
+ }
+
+ return buf.toString();
+ }
}