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 2009/02/16 09:25:03 UTC

svn commit: r744855 - in /felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin: BundlePlugin.java DependencyExcluder.java

Author: mcculls
Date: Mon Feb 16 08:25:03 2009
New Revision: 744855

URL: http://svn.apache.org/viewvc?rev=744855&view=rev
Log:
FELIX-684: support filters in excludeDependencies, such as *;scope=runtime

Added:
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java
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=744855&r1=744854&r2=744855&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 Mon Feb 16 08:25:03 2009
@@ -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 classpath = new ArrayList();
-        for ( Iterator i = artifacts.iterator(); i.hasNext(); )
-        {
-            Artifact artifact = ( Artifact ) i.next();
-            if ( !excludes.contains( artifact.getArtifactId() ) )
-            {
-                classpath.add( artifact );
-            }
-        }
+        Collection selectedDependencies = new HashSet( artifacts );
+        DependencyExcluder excluder = new DependencyExcluder( artifacts );
+        excluder.processHeaders( excludeDependencies );
+        selectedDependencies.removeAll( excluder.getExcludedArtifacts() );
 
-        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 );
     }
 }

Added: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java?rev=744855&view=auto
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java (added)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java Mon Feb 16 08:25:03 2009
@@ -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;
+    }
+}