You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ch...@apache.org on 2011/01/28 16:13:34 UTC
svn commit: r1064721 -
/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
Author: chirino
Date: Fri Jan 28 15:13:33 2011
New Revision: 1064721
URL: http://svn.apache.org/viewvc?rev=1064721&view=rev
Log:
Improving implementation of FELIX-2809, we now look at the transitive path of an artifact to determine if it's optional.
Modified:
felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.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=1064721&r1=1064720&r2=1064721&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 Fri Jan 28 15:13:33 2011
@@ -588,8 +588,7 @@ public class BundlePlugin extends Abstra
protected Set getOptionalPackages( MavenProject currentProject ) throws IOException, MojoExecutionException
{
- HashSet required = new HashSet();
- HashSet optional = new HashSet();
+ ArrayList inscope = new ArrayList();
final Collection artifacts = getSelectedDependencies( currentProject.getArtifacts() );
for ( Iterator it = artifacts.iterator(); it.hasNext(); )
{
@@ -598,25 +597,67 @@ public class BundlePlugin extends Abstra
{
if ( !Artifact.SCOPE_TEST.equals( artifact.getScope() ) )
{
- File file = getFile( artifact );
- if ( file == null )
- {
- continue;
- }
- Jar jar = new Jar( artifact.getArtifactId(), file );
- if( artifact.isOptional() ) {
- optional.addAll(jar.getPackages());
- } else {
- required.addAll(jar.getPackages());
- }
- jar.close();
+ inscope.add(artifact);
}
}
}
+
+ HashSet optionalArtifactIds = new HashSet();
+ for ( Iterator it = inscope.iterator(); it.hasNext(); )
+ {
+ Artifact artifact = ( Artifact ) it.next();
+ if( artifact.isOptional() ) {
+ String id = artifact.toString();
+ if( artifact.getScope()!=null ) {
+ // strip the scope...
+ id = id.replaceFirst(":[^:]*$", "");
+ }
+ optionalArtifactIds.add(id);
+ }
+
+ }
+
+ HashSet required = new HashSet();
+ HashSet optional = new HashSet();
+ for ( Iterator it = inscope.iterator(); it.hasNext(); )
+ {
+ Artifact artifact = ( Artifact ) it.next();
+ File file = getFile( artifact );
+ if ( file == null )
+ {
+ continue;
+ }
+
+ Jar jar = new Jar( artifact.getArtifactId(), file );
+ if( isTransitivelyOptional(optionalArtifactIds, artifact) ) {
+ optional.addAll(jar.getPackages());
+ } else {
+ required.addAll(jar.getPackages());
+ }
+ jar.close();
+ }
+
optional.removeAll(required);
return optional;
}
+ /**
+ * Check to see if any dependency along the dependency trail of
+ * the artifact is optional.
+ *
+ * @param artifact
+ */
+ protected boolean isTransitivelyOptional(HashSet optionalArtifactIds, Artifact artifact) {
+ List trail = artifact.getDependencyTrail();
+ for (Iterator iterator = trail.iterator(); iterator.hasNext();) {
+ String next = (String) iterator.next();
+ if( optionalArtifactIds.contains(next) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private void unpackBundle( File jarFile )
{
File outputDir = getOutputDirectory();