Author: cziegeler
Date: Wed Dec 30 12:54:58 2015
New Revision: 1722327

URL: http://svn.apache.org/viewvc?rev=1722327&view=rev
Log:
FELIX-5116 : Dump SCR component definitions broken. Apply patch from Stefan 
Seifert

Modified:
    
felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
    
felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java

Modified: 
felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java?rev=1722327&r1=1722326&r2=1722327&view=diff
==============================================================================
--- 
felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
 (original)
+++ 
felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
 Wed Dec 30 12:54:58 2015
@@ -189,6 +189,18 @@ public class BundlePlugin extends Abstra
     @Parameter( defaultValue = "${basedir}/dependency-reduced-pom.xml" )
     protected File dependencyReducedPomLocation;
 
+    /**
+     * Directory where the SCR files will be written
+     */
+    @Parameter(defaultValue="${project.build.outputDirectory}")
+    protected File scrLocation;
+
+    /**
+     * When true, dump the generated SCR files
+     */
+    @Parameter
+    protected boolean exportScr;
+    
     @Component
     private MavenProjectHelper m_projectHelper;
 
@@ -507,7 +519,7 @@ public class BundlePlugin extends Abstra
 
                 try
                 {
-                    ManifestPlugin.writeManifest( builder, outputFile, 
niceManifest );
+                    ManifestPlugin.writeManifest( builder, outputFile, 
niceManifest, exportScr, scrLocation );
                 }
                 catch ( IOException e )
                 {

Modified: 
felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java?rev=1722327&r1=1722326&r2=1722327&view=diff
==============================================================================
--- 
felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
 (original)
+++ 
felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
 Wed Dec 30 12:54:58 2015
@@ -66,19 +66,6 @@ public class ManifestPlugin extends Bund
     @Parameter( property = "rebuildBundle" )
     protected boolean rebuildBundle;
 
-    /**
-     * Directory where the SCR files will be written
-     *
-     * @parameter expression="${scrLocation}" 
default-value="${project.build.outputDirectory}"
-     */
-    protected File scrLocation;
-
-    /**
-     * When true, dump the generated SCR files
-     * @parameter
-     */
-    protected boolean exportScr;
-
     @Override
     protected void execute( MavenProject project, DependencyNode 
dependencyGraph, Map<String, String> instructions, Properties properties, Jar[] 
classpath )
         throws MojoExecutionException
@@ -112,7 +99,7 @@ public class ManifestPlugin extends Bund
 
         try
         {
-            writeManifest( analyzer, outputFile, niceManifest );
+            writeManifest( analyzer, outputFile, niceManifest, exportScr, 
scrLocation );
         }
         catch ( Exception e )
         {
@@ -149,41 +136,45 @@ public class ManifestPlugin extends Bund
 
         if (exportScr)
         {
-            scrLocation.mkdirs();
+            exportScr(analyzer, jar, scrLocation);
+        }
+
+        // cleanup...
+        analyzer.close();
 
-            String bpHeader = analyzer.getProperty(Analyzer.SERVICE_COMPONENT);
-            Parameters map = Processor.parseHeader(bpHeader, null);
-            for (String root : map.keySet())
+        return manifest;
+    }
+    
+    private static void exportScr(Analyzer analyzer, Jar jar, File 
scrLocation) throws Exception {
+        scrLocation.mkdirs();
+
+        String bpHeader = analyzer.getProperty(Analyzer.SERVICE_COMPONENT);
+        Parameters map = Processor.parseHeader(bpHeader, null);
+        for (String root : map.keySet())
+        {
+            Map<String, Resource> dir = jar.getDirectories().get(root);
+            File location = new File(scrLocation, root);
+            if (dir == null || dir.isEmpty())
             {
-                Map<String, Resource> dir = jar.getDirectories().get(root);
-                File location = new File(scrLocation, root);
-                if (dir == null || dir.isEmpty())
+                Resource resource = jar.getResource(root);
+                if (resource != null)
                 {
-                    Resource resource = jar.getResource(root);
-                    if (resource != null)
-                    {
-                        writeSCR(resource, location);
-                    }
+                    writeSCR(resource, location);
                 }
-                else
+            }
+            else
+            {
+                for (Map.Entry<String, Resource> entry : dir.entrySet())
                 {
-                    for (Map.Entry<String, Resource> entry : dir.entrySet())
-                    {
-                        String path = entry.getKey();
-                        Resource resource = entry.getValue();
-                        writeSCR(resource, new File(location, path));
-                    }
+                    String path = entry.getKey();
+                    Resource resource = entry.getValue();
+                    writeSCR(resource, new File(location, path));
                 }
             }
         }
-
-        // cleanup...
-        analyzer.close();
-
-        return manifest;
     }
 
-    protected void writeSCR(Resource resource, File destination) throws 
Exception
+    private static void writeSCR(Resource resource, File destination) throws 
Exception
     {
         destination.getParentFile().mkdirs();
         OutputStream os = new FileOutputStream(destination);
@@ -295,10 +286,12 @@ public class ManifestPlugin extends Bund
     }
 
 
-    public static void writeManifest( Analyzer analyzer, File outputFile, 
boolean niceManifest ) throws Exception
+    public static void writeManifest( Analyzer analyzer, File outputFile, 
boolean niceManifest,
+            boolean exportScr, File scrLocation ) throws Exception
     {
         Properties properties = analyzer.getProperties();
-        Manifest manifest = analyzer.getJar().getManifest();
+        Jar jar = analyzer.getJar();
+        Manifest manifest = jar.getManifest();
         if ( outputFile.exists() && properties.containsKey( "Merge-Headers" ) )
         {
             Manifest analyzerManifest = manifest;
@@ -321,6 +314,11 @@ public class ManifestPlugin extends Bund
             parentFile.mkdirs();
         }
         writeManifest( manifest, outputFile, niceManifest );
+        
+        if (exportScr)
+        {
+            exportScr(analyzer, jar, scrLocation);            
+        }
     }
 
 


Reply via email to