You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2008/03/04 13:13:35 UTC

svn commit: r633441 - /felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java

Author: cziegeler
Date: Tue Mar  4 04:13:32 2008
New Revision: 633441

URL: http://svn.apache.org/viewvc?rev=633441&view=rev
Log:
RESOLVED - issue FELIX-506: scr-plugin-generated resources not always bundled 
https://issues.apache.org/jira/browse/FELIX-506

Modified:
    felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java

Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java?rev=633441&r1=633440&r2=633441&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java (original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java Tue Mar  4 04:13:32 2008
@@ -125,9 +125,9 @@
             throw new MojoFailureException("SCR Descriptor parsing had failures (see log)");
         }
 
-        // write meta type info if there is a file
+        boolean addResources = false;
+        // write meta type info if there is a file name
         if (!StringUtils.isEmpty(this.metaTypeName)) {
-
             File mtFile = new File(this.outputDirectory, "OSGI-INF" + File.separator + "metatype" + File.separator + this.metaTypeName);
             if ( metaData.getDescriptors().size() > 0 ) {
                 this.getLog().info("Generating "
@@ -135,6 +135,7 @@
                     + " MetaType Descriptors to " + mtFile);
                 mtFile.getParentFile().mkdirs();
                 MetaTypeIO.write(metaData, mtFile);
+                addResources = true;
             } else {
                 if ( mtFile.exists() ) {
                     mtFile.delete();
@@ -142,7 +143,7 @@
             }
 
         } else {
-            this.getLog().info("Have no meta type file name, not writing metatype info");
+            this.getLog().info("Meta type file name is not set: meta type info is not written.");
         }
 
         // if we have abstract descriptors, write them
@@ -151,6 +152,7 @@
             this.getLog().info("Writing abstract service descriptor " + adFile + " with " + abstractComponents.getComponents().size() + " entries.");
             adFile.getParentFile().mkdirs();
             ComponentDescriptorIO.write(abstractComponents, adFile);
+            addResources = true;
         } else {
             this.getLog().debug("No abstract SCR Descriptors found in project.");
             // remove file
@@ -160,46 +162,53 @@
             }
         }
 
+        // check descriptor file
+        final File descriptorFile = StringUtils.isEmpty(this.finalName) ? null : new File(new File(this.outputDirectory, "OSGI-INF"), this.finalName);
+
         // terminate if there is nothing else to write
         if (components.getComponents().isEmpty()) {
             this.getLog().debug("No SCR Descriptors found in project.");
-            return;
-        }
+            // remove file if it exists
+            if ( descriptorFile != null && descriptorFile.exists() ) {
+                this.getLog().debug("Removing obsolete service descriptor " + descriptorFile);
+                descriptorFile.delete();
+            }
+        } else {
 
-        // check file name
-        if (StringUtils.isEmpty(this.finalName)) {
-            this.getLog().error("Descriptor file name must not be empty.");
-            return;
-        }
+            if (descriptorFile == null) {
+                throw new MojoFailureException("Descriptor file name must not be empty.");
+            }
 
-        // finally the descriptors have to be written ....
-        File descriptorFile = new File(new File(this.outputDirectory, "OSGI-INF"), this.finalName);
-        descriptorFile.getParentFile().mkdirs(); // ensure parent dir
-
-        this.getLog().info("Generating " + components.getComponents().size()
-                + " Service Component Descriptors to " + descriptorFile);
-
-        ComponentDescriptorIO.write(components, descriptorFile);
-
-
-        // now add the descriptor file to the maven resources
-        final String ourRsrcPath = this.outputDirectory.getAbsolutePath();
-        boolean found = false;
-        final Iterator rsrcIterator = this.project.getResources().iterator();
-        while ( !found && rsrcIterator.hasNext() ) {
-            final Resource rsrc = (Resource)rsrcIterator.next();
-            found = rsrc.getDirectory().equals(ourRsrcPath);
-        }
-        if ( !found ) {
-            final Resource resource = new Resource();
-            resource.setDirectory(this.outputDirectory.getAbsolutePath());
-            this.project.addResource(resource);
-        }
+            // finally the descriptors have to be written ....
+            descriptorFile.getParentFile().mkdirs(); // ensure parent dir
+
+            this.getLog().info("Generating " + components.getComponents().size()
+                    + " Service Component Descriptors to " + descriptorFile);
+
+            ComponentDescriptorIO.write(components, descriptorFile);
+            addResources = true;
 
-        // and set include accordingly
-        String svcComp = project.getProperties().getProperty("Service-Component");
-        svcComp= (svcComp == null) ? "OSGI-INF/" + finalName : svcComp + ", " + "OSGI-INF/" + finalName;
-        project.getProperties().setProperty("Service-Component", svcComp);
+            // and set include accordingly
+            String svcComp = project.getProperties().getProperty("Service-Component");
+            svcComp= (svcComp == null) ? "OSGI-INF/" + finalName : svcComp + ", " + "OSGI-INF/" + finalName;
+            project.getProperties().setProperty("Service-Component", svcComp);
+        }
+
+        // now add the descriptor directory to the maven resources
+        if (addResources) {
+            final String ourRsrcPath = this.outputDirectory.getAbsolutePath();
+            boolean found = false;
+            final Iterator rsrcIterator = this.project.getResources().iterator();
+            while ( !found && rsrcIterator.hasNext() ) {
+                final Resource rsrc = (Resource)rsrcIterator.next();
+                found = rsrc.getDirectory().equals(ourRsrcPath);
+            }
+            if ( !found ) {
+                final Resource resource = new Resource();
+                resource.setDirectory(this.outputDirectory.getAbsolutePath());
+                this.project.addResource(resource);
+            }
+        }
     }
 
     /**