felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1602812 - in /felix/trunk/bundleplugin/src: main/java/org/apache/felix/bundleplugin/BundlePlugin.java main/java/org/apache/felix/bundleplugin/ManifestPlugin.java test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
Date Mon, 16 Jun 2014 07:07:12 GMT
Author: gnodet
Date: Mon Jun 16 07:07:12 2014
New Revision: 1602812

URL: http://svn.apache.org/r1602812
Log:
[FELIX-3381] Support for {maven-test-resources} and {maven-test-sources} placeholders

Modified:
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
    felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.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=1602812&r1=1602811&r2=1602812&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 Jun 16 07:07:12 2014
@@ -33,6 +33,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -231,8 +232,10 @@ public class BundlePlugin extends Abstra
 
     private static final String MAVEN_SYMBOLICNAME = "maven-symbolicname";
     private static final String MAVEN_RESOURCES = "{maven-resources}";
+    private static final String MAVEN_TEST_RESOURCES = "{maven-test-resources}";
     private static final String LOCAL_PACKAGES = "{local-packages}";
     private static final String MAVEN_SOURCES = "{maven-sources}";
+    private static final String MAVEN_TEST_SOURCES = "{maven-test-sources}";
 
     private static final String[] EMPTY_STRING_ARRAY =
         {};
@@ -695,37 +698,28 @@ public class BundlePlugin extends Abstra
     protected static void includeMavenResources( MavenProject currentProject, Analyzer analyzer,
Log log )
     {
         // pass maven resource paths onto BND analyzer
-        final String mavenResourcePaths = getMavenResourcePaths( currentProject );
-        final String includeResource = ( String ) analyzer.getProperty( Analyzer.INCLUDE_RESOURCE
);
+        final String mavenResourcePaths = getMavenResourcePaths( currentProject, false );
+        final String mavenTestResourcePaths = getMavenResourcePaths( currentProject, true
);
+        final String includeResource = analyzer.getProperty( Analyzer.INCLUDE_RESOURCE );
         if ( includeResource != null )
         {
-            if ( includeResource.indexOf( MAVEN_RESOURCES ) >= 0 )
+            if ( includeResource.contains( MAVEN_RESOURCES ) || includeResource.contains(
MAVEN_TEST_RESOURCES ) )
             {
-                // if there is no maven resource path, we do a special treatment and replace
-                // every occurance of MAVEN_RESOURCES and a following comma with an empty
string
-                if ( mavenResourcePaths.length() == 0 )
+                String combinedResource = StringUtils.replace( includeResource, MAVEN_RESOURCES,
mavenResourcePaths );
+                combinedResource = StringUtils.replace( combinedResource, MAVEN_TEST_RESOURCES,
mavenTestResourcePaths );
+                if ( combinedResource.length() > 0 )
                 {
-                    String cleanedResource = removeTagFromInstruction( includeResource, MAVEN_RESOURCES
);
-                    if ( cleanedResource.length() > 0 )
-                    {
-                        analyzer.setProperty( Analyzer.INCLUDE_RESOURCE, cleanedResource
);
-                    }
-                    else
-                    {
-                        analyzer.unsetProperty( Analyzer.INCLUDE_RESOURCE );
-                    }
+                    analyzer.setProperty( Analyzer.INCLUDE_RESOURCE, combinedResource );
                 }
                 else
                 {
-                    String combinedResource = StringUtils
-                        .replace( includeResource, MAVEN_RESOURCES, mavenResourcePaths );
-                    analyzer.setProperty( Analyzer.INCLUDE_RESOURCE, combinedResource );
+                    analyzer.unsetProperty( Analyzer.INCLUDE_RESOURCE );
                 }
             }
             else if ( mavenResourcePaths.length() > 0 )
             {
                 log.warn( Analyzer.INCLUDE_RESOURCE + ": overriding " + mavenResourcePaths
+ " with " + includeResource
-                    + " (add " + MAVEN_RESOURCES + " if you want to include the maven resources)"
);
+                        + " (add " + MAVEN_RESOURCES + " if you want to include the maven
resources)" );
             }
         }
         else if ( mavenResourcePaths.length() > 0 )
@@ -1421,9 +1415,9 @@ public class BundlePlugin extends Abstra
     }
 
 
-    private static List getMavenResources( MavenProject currentProject )
+    private static List getMavenResources( MavenProject currentProject, boolean test )
     {
-        List resources = new ArrayList( currentProject.getResources() );
+        List resources = new ArrayList( test ? currentProject.getTestResources() : currentProject.getResources()
);
 
         if ( currentProject.getCompileSourceRoots() != null )
         {
@@ -1443,12 +1437,12 @@ public class BundlePlugin extends Abstra
     }
 
 
-    protected static String getMavenResourcePaths( MavenProject currentProject )
+    protected static String getMavenResourcePaths( MavenProject currentProject, boolean test
)
     {
         final String basePath = currentProject.getBasedir().getAbsolutePath();
 
         Set pathSet = new LinkedHashSet();
-        for ( Iterator i = getMavenResources( currentProject ).iterator(); i.hasNext(); )
+        for ( Iterator i = getMavenResources( currentProject, test ).iterator(); i.hasNext();
)
         {
             Resource resource = ( Resource ) i.next();
 
@@ -1563,41 +1557,40 @@ public class BundlePlugin extends Abstra
     {
         // pass maven source paths onto BND analyzer
         StringBuilder mavenSourcePaths = new StringBuilder();
-        if ( currentProject.getCompileSourceRoots() != null )
+        StringBuilder mavenTestSourcePaths = new StringBuilder();
+        Map<StringBuilder, List<?>> map = new HashMap<StringBuilder, List<?>>(2);
+        map.put(mavenSourcePaths, currentProject.getCompileSourceRoots() );
+        map.put(mavenTestSourcePaths, currentProject.getTestCompileSourceRoots() );
+        for ( Map.Entry<StringBuilder, List<?>> entry : map.entrySet() )
         {
-            for ( Iterator i = currentProject.getCompileSourceRoots().iterator(); i.hasNext();
)
+            List<?> compileSourceRoots = entry.getValue();
+            if ( compileSourceRoots != null )
             {
-                if ( mavenSourcePaths.length() > 0 )
+                StringBuilder sourcePaths = entry.getKey();
+                for ( Iterator i = compileSourceRoots.iterator(); i.hasNext(); )
                 {
-                    mavenSourcePaths.append( ',' );
+                    if ( sourcePaths.length() > 0 )
+                    {
+                        sourcePaths.append( ',' );
+                    }
+                    sourcePaths.append( ( String ) i.next() );
                 }
-                mavenSourcePaths.append( ( String ) i.next() );
             }
         }
-        final String sourcePath = ( String ) analyzer.getProperty( Analyzer.SOURCEPATH );
+        final String sourcePath = analyzer.getProperty( Analyzer.SOURCEPATH );
         if ( sourcePath != null )
         {
-            if ( sourcePath.indexOf( MAVEN_SOURCES ) >= 0 )
+            if ( sourcePath.contains(MAVEN_SOURCES) || sourcePath.contains(MAVEN_TEST_RESOURCES)
)
             {
-                // if there is no maven source path, we do a special treatment and replace
-                // every occurance of MAVEN_SOURCES and a following comma with an empty string
-                if ( mavenSourcePaths.length() == 0 )
+                String combinedSource = StringUtils.replace( sourcePath, MAVEN_SOURCES, mavenSourcePaths.toString()
);
+                combinedSource = StringUtils.replace( combinedSource, MAVEN_TEST_SOURCES,
mavenTestSourcePaths.toString() );
+                if ( combinedSource.length() > 0 )
                 {
-                    String cleanedSource = removeTagFromInstruction( sourcePath, MAVEN_SOURCES
);
-                    if ( cleanedSource.length() > 0 )
-                    {
-                        analyzer.setProperty( Analyzer.SOURCEPATH, cleanedSource );
-                    }
-                    else
-                    {
-                        analyzer.unsetProperty( Analyzer.SOURCEPATH );
-                    }
+                    analyzer.setProperty( Analyzer.SOURCEPATH, combinedSource );
                 }
                 else
                 {
-                    String combinedSource = StringUtils
-                        .replace( sourcePath, MAVEN_SOURCES, mavenSourcePaths.toString()
);
-                    analyzer.setProperty( Analyzer.SOURCEPATH, combinedSource );
+                    analyzer.unsetProperty( Analyzer.SOURCEPATH );
                 }
             }
             else if ( mavenSourcePaths.length() > 0 )
@@ -1605,6 +1598,11 @@ public class BundlePlugin extends Abstra
                 log.warn( Analyzer.SOURCEPATH + ": overriding " + mavenSourcePaths + " with
" + sourcePath + " (add "
                     + MAVEN_SOURCES + " if you want to include the maven sources)" );
             }
+            else if ( mavenTestSourcePaths.length() > 0 )
+            {
+                log.warn( Analyzer.SOURCEPATH + ": overriding " + mavenTestSourcePaths +
" with " + sourcePath + " (add "
+                        + MAVEN_TEST_SOURCES + " if you want to include the maven sources)"
);
+            }
         }
         else if ( mavenSourcePaths.length() > 0 )
         {

Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java?rev=1602812&r1=1602811&r2=1602812&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
(original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
Mon Jun 16 07:07:12 2014
@@ -164,10 +164,10 @@ public class ManifestPlugin extends Bund
             return buildOSGiBundle( project, instructions, properties, classpath );
         }
 
-        File file = project.getArtifact().getFile();
+        File file = getOutputDirectory();
         if ( file == null )
         {
-            file = getOutputDirectory();
+            file = project.getArtifact().getFile();
         }
 
         if ( !file.exists() )

Modified: felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java?rev=1602812&r1=1602811&r2=1602812&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
(original)
+++ felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
Mon Jun 16 07:07:12 2014
@@ -209,7 +209,7 @@ public class BundlePluginTest extends Ab
         MavenProject project = getMavenProjectStub();
         project.addCompileSourceRoot( getBasedir() + "/src/test/java" );
 
-        String resourcePaths = plugin.getMavenResourcePaths( project );
+        String resourcePaths = plugin.getMavenResourcePaths( project, false );
 
         assertEquals( "org/apache/felix/bundleplugin/packageinfo="
             + "src/test/java/org/apache/felix/bundleplugin/packageinfo", resourcePaths );



Mime
View raw message