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 08:35:52 UTC
svn commit: r744834 -
/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
Author: mcculls
Date: Mon Feb 16 07:35:51 2009
New Revision: 744834
URL: http://svn.apache.org/viewvc?rev=744834&view=rev
Log:
FELIX-684: separate out dependency filtering code so we can re-use it when excluding
Modified:
felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java?rev=744834&r1=744833&r2=744834&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java Mon Feb 16 07:35:51 2009
@@ -30,7 +30,6 @@
import org.codehaus.plexus.util.StringUtils;
import aQute.lib.osgi.Analyzer;
-import aQute.lib.osgi.Instruction;
import aQute.libg.header.OSGiHeader;
@@ -39,7 +38,7 @@
*
* @author stuart.mcculloch@jayway.net (Stuart McCulloch)
*/
-public final class DependencyEmbedder
+public final class DependencyEmbedder extends AbstractDependencyFilter
{
public static final String EMBED_DEPENDENCY = "Embed-Dependency";
public static final String EMBED_DIRECTORY = "Embed-Directory";
@@ -54,11 +53,6 @@
private String m_embedStripVersion;
/**
- * Dependency artifacts.
- */
- private final Collection m_dependencyArtifacts;
-
- /**
* Inlined paths.
*/
private final Collection m_inlinedPaths;
@@ -71,7 +65,7 @@
public DependencyEmbedder( Collection dependencyArtifacts )
{
- m_dependencyArtifacts = dependencyArtifacts;
+ super( dependencyArtifacts );
m_inlinedPaths = new HashSet();
m_embeddedArtifacts = new HashSet();
@@ -94,7 +88,7 @@
m_embedStripVersion = analyzer.getProperty( EMBED_STRIP_VERSION );
Map embedInstructions = OSGiHeader.parseHeader( embedDependencyHeader );
- processEmbedInstructions( embedInstructions );
+ processInstructions( embedInstructions );
for ( Iterator i = m_inlinedPaths.iterator(); i.hasNext(); )
{
@@ -119,189 +113,19 @@
appendDependencies( analyzer, Analyzer.BUNDLE_CLASSPATH, bundleClassPath.toString() );
}
- protected static abstract class DependencyFilter
- {
- private final Instruction m_instruction;
- private final String m_defaultValue;
-
-
- public DependencyFilter( String expression )
- {
- this( expression, "" );
- }
-
-
- public DependencyFilter( String expression, String defaultValue )
- {
- m_instruction = Instruction.getPattern( expression );
- m_defaultValue = defaultValue;
- }
-
-
- public void filter( Collection dependencies )
- {
- for ( Iterator i = dependencies.iterator(); i.hasNext(); )
- {
- if ( false == matches( ( Artifact ) i.next() ) )
- {
- i.remove();
- }
- }
- }
-
-
- abstract boolean matches( Artifact dependency );
-
- boolean matches( String text )
+ @Override
+ protected void processDependencies( String inline, Collection filteredDependencies )
+ {
+ if ( null == inline || "false".equalsIgnoreCase( inline ) )
{
- boolean result;
-
- if ( null == text )
- {
- result = m_instruction.matches( m_defaultValue );
- }
- else
- {
- result = m_instruction.matches( text );
- }
-
- return m_instruction.isNegated() ? !result : result;
+ m_embeddedArtifacts.addAll( filteredDependencies );
}
- }
-
-
- private void processEmbedInstructions( Map embedInstructions ) throws MojoExecutionException
- {
- DependencyFilter filter;
- for ( Iterator clauseIterator = embedInstructions.entrySet().iterator(); clauseIterator.hasNext(); )
+ else
{
- String inline = "false";
-
- // must use a fresh *modifiable* collection for each unique clause
- Collection filteredDependencies = new HashSet( m_dependencyArtifacts );
-
- // CLAUSE: REGEXP --> { ATTRIBUTE MAP }
- Map.Entry clause = ( Map.Entry ) clauseIterator.next();
-
- filter = new DependencyFilter( ( String ) clause.getKey() )
+ for ( Iterator i = filteredDependencies.iterator(); i.hasNext(); )
{
- boolean matches( Artifact dependency )
- {
- return super.matches( dependency.getArtifactId() );
- }
- };
-
- // FILTER ON MAIN CLAUSE
- filter.filter( filteredDependencies );
-
- for ( Iterator attrIterator = ( ( Map ) clause.getValue() ).entrySet().iterator(); attrIterator.hasNext(); )
- {
- // ATTRIBUTE: KEY --> REGEXP
- Map.Entry attr = ( Map.Entry ) attrIterator.next();
-
- if ( "groupId".equals( attr.getKey() ) )
- {
- filter = new DependencyFilter( ( String ) attr.getValue() )
- {
- boolean matches( Artifact dependency )
- {
- return super.matches( dependency.getGroupId() );
- }
- };
- }
- else if ( "artifactId".equals( attr.getKey() ) )
- {
- filter = new DependencyFilter( ( String ) attr.getValue() )
- {
- boolean matches( Artifact dependency )
- {
- return super.matches( dependency.getArtifactId() );
- }
- };
- }
- else if ( "version".equals( attr.getKey() ) )
- {
- filter = new DependencyFilter( ( String ) attr.getValue() )
- {
- boolean matches( Artifact dependency )
- {
- try
- {
- // use the symbolic version if available (ie. 1.0.0-SNAPSHOT)
- return super.matches( dependency.getSelectedVersion().toString() );
- }
- catch ( Exception e )
- {
- return super.matches( dependency.getVersion() );
- }
- }
- };
- }
- else if ( "scope".equals( attr.getKey() ) )
- {
- filter = new DependencyFilter( ( String ) attr.getValue(), "compile" )
- {
- boolean matches( Artifact dependency )
- {
- return super.matches( dependency.getScope() );
- }
- };
- }
- else if ( "type".equals( attr.getKey() ) )
- {
- filter = new DependencyFilter( ( String ) attr.getValue(), "jar" )
- {
- boolean matches( Artifact dependency )
- {
- return super.matches( dependency.getType() );
- }
- };
- }
- else if ( "classifier".equals( attr.getKey() ) )
- {
- filter = new DependencyFilter( ( String ) attr.getValue() )
- {
- boolean matches( Artifact dependency )
- {
- return super.matches( dependency.getClassifier() );
- }
- };
- }
- else if ( "optional".equals( attr.getKey() ) )
- {
- filter = new DependencyFilter( ( String ) attr.getValue(), "false" )
- {
- boolean matches( Artifact dependency )
- {
- return super.matches( "" + dependency.isOptional() );
- }
- };
- }
- else if ( "inline".equals( attr.getKey() ) )
- {
- inline = ( String ) attr.getValue();
- continue;
- }
- else
- {
- throw new MojoExecutionException( "Unexpected attribute " + attr.getKey() );
- }
-
- // FILTER ON EACH ATTRIBUTE
- filter.filter( filteredDependencies );
- }
-
- if ( null == inline || "false".equalsIgnoreCase( inline ) )
- {
- m_embeddedArtifacts.addAll( filteredDependencies );
- }
- else
- {
- for ( Iterator i = filteredDependencies.iterator(); i.hasNext(); )
- {
- addInlinedPaths( ( Artifact ) i.next(), inline, m_inlinedPaths );
- }
+ addInlinedPaths( ( Artifact ) i.next(), inline, m_inlinedPaths );
}
}
}