FELIX-684: support filters in excludeDependencies, such as *;scope=runtime
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@744855 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 7c6cdd6..ca4565a 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
@@ -31,14 +31,13 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
-import java.util.zip.ZipException;
import org.apache.maven.archiver.ManifestSection;
import org.apache.maven.archiver.MavenArchiveConfiguration;
@@ -374,8 +373,8 @@
// update BND instructions to add included Maven resources
includeMavenResources( currentProject, builder, getLog() );
- if ( builder.getProperty( Analyzer.EXPORT_PACKAGE ) == null &&
- builder.getProperty( Analyzer.PRIVATE_PACKAGE ) == null )
+ if ( builder.getProperty( Analyzer.EXPORT_PACKAGE ) == null
+ && builder.getProperty( Analyzer.PRIVATE_PACKAGE ) == null )
{
if ( builder.getProperty( Analyzer.EXPORT_CONTENTS ) != null )
{
@@ -725,12 +724,7 @@
}
- /**
- * @return
- * @throws ZipException
- * @throws IOException
- */
- protected Jar[] getClasspath( MavenProject currentProject ) throws ZipException, IOException
+ protected Jar[] getClasspath( MavenProject currentProject ) throws IOException, MojoExecutionException
{
List list = new ArrayList();
@@ -766,7 +760,7 @@
}
- private Collection getSelectedDependencies( Set artifacts )
+ private Collection getSelectedDependencies( Collection artifacts ) throws MojoExecutionException
{
if ( null == excludeDependencies || excludeDependencies.length() == 0 )
{
@@ -777,19 +771,12 @@
return Collections.EMPTY_LIST;
}
- List excludes = Arrays.asList( excludeDependencies.trim().split( "\\s*,\\s*" ) );
+ Collection selectedDependencies = new HashSet( artifacts );
+ DependencyExcluder excluder = new DependencyExcluder( artifacts );
+ excluder.processHeaders( excludeDependencies );
+ selectedDependencies.removeAll( excluder.getExcludedArtifacts() );
- Collection classpath = new ArrayList();
- for ( Iterator i = artifacts.iterator(); i.hasNext(); )
- {
- Artifact artifact = ( Artifact ) i.next();
- if ( !excludes.contains( artifact.getArtifactId() ) )
- {
- classpath.add( artifact );
- }
- }
-
- return classpath;
+ return selectedDependencies;
}
@@ -1021,16 +1008,23 @@
}
- protected static Collection getEmbeddableArtifacts( MavenProject project, Analyzer analyzer )
+ protected Collection getEmbeddableArtifacts( MavenProject project, Analyzer analyzer )
+ throws MojoExecutionException
{
+ final Collection artifacts;
+
String embedTransitive = analyzer.getProperty( DependencyEmbedder.EMBED_TRANSITIVE );
if ( Boolean.valueOf( embedTransitive ).booleanValue() )
{
// includes transitive dependencies
- return project.getArtifacts();
+ artifacts = project.getArtifacts();
+ }
+ else
+ {
+ // only includes direct dependencies
+ artifacts = project.getDependencyArtifacts();
}
- // only includes direct dependencies
- return project.getDependencyArtifacts();
+ return getSelectedDependencies( artifacts );
}
}
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java
new file mode 100644
index 0000000..f8633e5
--- /dev/null
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.bundleplugin;
+
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.apache.maven.plugin.MojoExecutionException;
+
+import aQute.libg.header.OSGiHeader;
+
+
+/**
+ * Exclude selected dependencies from the classpath passed to BND.
+ *
+ * @author mcculls@gmail.com (Stuart McCulloch)
+ */
+public final class DependencyExcluder extends AbstractDependencyFilter
+{
+ /**
+ * Excluded artifacts.
+ */
+ private final Collection m_excludedArtifacts;
+
+
+ public DependencyExcluder( Collection dependencyArtifacts )
+ {
+ super( dependencyArtifacts );
+
+ m_excludedArtifacts = new HashSet();
+ }
+
+
+ public void processHeaders( String excludeDependencies ) throws MojoExecutionException
+ {
+ m_excludedArtifacts.clear();
+
+ if ( null != excludeDependencies && excludeDependencies.length() > 0 )
+ {
+ processInstructions( OSGiHeader.parseHeader( excludeDependencies ) );
+ }
+ }
+
+
+ @Override
+ protected void processDependencies( String inline, Collection filteredDependencies )
+ {
+ m_excludedArtifacts.addAll( filteredDependencies );
+ }
+
+
+ public Collection getExcludedArtifacts()
+ {
+ return m_excludedArtifacts;
+ }
+}