FELIX-556: support use of filters when embedding dependencies, for example: <Embed-Dependency>foo;inline=META-INF/**</Embed-Dependency>
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@675115 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
index 78b8c5f..d35d02b 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
@@ -60,9 +60,9 @@
private final Collection m_dependencyArtifacts;
/**
- * Inlined artifacts.
+ * Inlined paths.
*/
- private final Collection m_inlinedArtifacts;
+ private final Collection m_inlinedPaths;
/**
* Embedded artifacts.
@@ -74,7 +74,7 @@
{
m_dependencyArtifacts = dependencyArtifacts;
- m_inlinedArtifacts = new HashSet();
+ m_inlinedPaths = new HashSet();
m_embeddedArtifacts = new HashSet();
}
@@ -84,7 +84,7 @@
StringBuffer includeResource = new StringBuffer();
StringBuffer bundleClassPath = new StringBuffer();
- m_inlinedArtifacts.clear();
+ m_inlinedPaths.clear();
m_embeddedArtifacts.clear();
String embedDependencyHeader = properties.getProperty( EMBED_DEPENDENCY );
@@ -97,9 +97,9 @@
Map embedInstructions = OSGiHeader.parseHeader( embedDependencyHeader );
processEmbedInstructions( embedInstructions );
- for ( Iterator i = m_inlinedArtifacts.iterator(); i.hasNext(); )
+ for ( Iterator i = m_inlinedPaths.iterator(); i.hasNext(); )
{
- inlineDependency( ( Artifact ) i.next(), includeResource );
+ inlineDependency( ( String ) i.next(), includeResource );
}
for ( Iterator i = m_embeddedArtifacts.iterator(); i.hasNext(); )
{
@@ -177,7 +177,7 @@
DependencyFilter filter;
for ( Iterator clauseIterator = embedInstructions.entrySet().iterator(); clauseIterator.hasNext(); )
{
- boolean inline = false;
+ String inline = "false";
// must use a fresh *modifiable* collection for each unique clause
Collection filteredDependencies = new HashSet( m_dependencyArtifacts );
@@ -281,8 +281,7 @@
}
else if ( "inline".equals( attr.getKey() ) )
{
- inline = Boolean.valueOf( ( String ) attr.getValue() ).booleanValue();
-
+ inline = ( String ) attr.getValue();
continue;
}
else
@@ -294,18 +293,42 @@
filter.filter( filteredDependencies );
}
- if ( inline )
- {
- m_inlinedArtifacts.addAll( filteredDependencies );
- }
- else
+ 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 );
+ }
+ }
}
+ }
- // remove any inlined artifacts from the embedded list
- m_embeddedArtifacts.removeAll( m_inlinedArtifacts );
+
+ private static void addInlinedPaths( Artifact dependency, String inline, Collection inlinedPaths )
+ {
+ File path = dependency.getFile();
+ if ( null != path && path.exists() )
+ {
+ if ( "true".equalsIgnoreCase( inline ) || inline.length() == 0 )
+ {
+ inlinedPaths.add( path.getPath() );
+ }
+ else
+ {
+ String[] filters = inline.split("\\|");
+ for ( int i = 0; i < filters.length; i++ )
+ {
+ if ( filters[i].length() > 0 )
+ {
+ inlinedPaths.add( path + "!/" + filters[i] );
+ }
+ }
+ }
+ }
}
@@ -370,25 +393,21 @@
}
- private void inlineDependency( Artifact dependency, StringBuffer includeResource )
+ private static void inlineDependency( String path, StringBuffer includeResource )
{
- File sourceFile = dependency.getFile();
- if ( null != sourceFile && sourceFile.exists() )
+ if ( includeResource.length() > 0 )
{
- if ( includeResource.length() > 0 )
- {
- includeResource.append( ',' );
- }
-
- includeResource.append( '@' );
- includeResource.append( sourceFile );
+ includeResource.append( ',' );
}
+
+ includeResource.append( '@' );
+ includeResource.append( path );
}
- public Collection getInlinedArtifacts()
+ public Collection getInlinedPaths()
{
- return m_inlinedArtifacts;
+ return m_inlinedPaths;
}