felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1394025 - in /felix/trunk/scrplugin: generator/src/main/java/org/apache/felix/scrplugin/ generator/src/main/java/org/apache/felix/scrplugin/xml/ maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/
Date Thu, 04 Oct 2012 12:51:50 GMT
Author: cziegeler
Date: Thu Oct  4 12:51:49 2012
New Revision: 1394025

URL: http://svn.apache.org/viewvc?rev=1394025&view=rev
Log:
FELIX-3643 :  Use BuildContext for scanning changed files 

Modified:
    felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
    felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
    felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
    felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java

Modified: felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java?rev=1394025&r1=1394024&r2=1394025&view=diff
==============================================================================
--- felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
(original)
+++ felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
Thu Oct  4 12:51:49 2012
@@ -205,4 +205,21 @@ public class Options {
     public void setGenerateSeparateDescriptors(boolean generateSeparateDescriptors) {
         this.generateSeparateDescriptors = generateSeparateDescriptors;
     }
+
+    private static final String PARENT_NAME = "OSGI-INF";
+
+    /**
+     * Convenience method to get the meta type directory.
+     */
+    public File getMetaTypeDirectory() {
+        final File parentDir = new File(this.getOutputDirectory(), PARENT_NAME);
+        return new File(parentDir, "metatype");
+    }
+
+    /**
+     * Convenience method to get the component descriptor directory.
+     */
+    public File getComponentDescriptorDirectory() {
+        return new File(this.getOutputDirectory(), PARENT_NAME);
+    }
 }

Modified: felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java?rev=1394025&r1=1394024&r2=1394025&view=diff
==============================================================================
--- felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
(original)
+++ felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
Thu Oct  4 12:51:49 2012
@@ -161,8 +161,8 @@ public class ComponentDescriptorIO {
     private static final String PROPERTIES = "properties";
 
     public static List<ClassDescription> read(final InputStream file,
-                    final ClassLoader classLoader,
-                    final IssueLog iLog, final String location) throws SCRDescriptorException
{
+            final ClassLoader classLoader,
+            final IssueLog iLog, final String location) throws SCRDescriptorException {
         try {
             final XmlHandler xmlHandler = new XmlHandler(classLoader, iLog, location);
             IOUtils.parse(file, xmlHandler);
@@ -181,11 +181,11 @@ public class ComponentDescriptorIO {
      * @throws SAXException
      */
     protected static void generateXML(final DescriptionContainer module,
-                    final List<ComponentContainer> components,
-                    final File descriptorFile,
-                    final Log logger) throws SAXException {
+            final List<ComponentContainer> components,
+            final File descriptorFile,
+            final Log logger) throws SAXException {
         logger.info("Writing " + components.size() + " Service Component Descriptors to "
-                        + descriptorFile);
+                + descriptorFile);
         final ContentHandler contentHandler = IOUtils.getSerializer(descriptorFile);
         // detect namespace to use
         final String namespace = module.getOptions().getSpecVersion().getNamespaceUrl();
@@ -216,10 +216,10 @@ public class ComponentDescriptorIO {
      * @throws SAXException
      */
     protected static void generateXML(final String namespace,
-                    final DescriptionContainer module,
-                    final ComponentContainer container,
-                    final ContentHandler contentHandler)
-    throws SAXException {
+            final DescriptionContainer module,
+            final ComponentContainer container,
+            final ContentHandler contentHandler)
+                    throws SAXException {
         final ComponentDescription component = container.getComponentDescription();
 
         final AttributesImpl ai = new AttributesImpl();
@@ -276,9 +276,9 @@ public class ComponentDescriptorIO {
         IOUtils.addAttribute(ai, IMPLEMENTATION_ATTR_CLASS, component.getClassDescription().getDescribedClass().getName());
         IOUtils.indent(contentHandler, 2);
         contentHandler.startElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.IMPLEMENTATION,
-                        ComponentDescriptorIO.IMPLEMENTATION_QNAME, ai);
+                ComponentDescriptorIO.IMPLEMENTATION_QNAME, ai);
         contentHandler.endElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.IMPLEMENTATION,
-                        ComponentDescriptorIO.IMPLEMENTATION_QNAME);
+                ComponentDescriptorIO.IMPLEMENTATION_QNAME);
         IOUtils.newline(contentHandler);
     }
 
@@ -290,9 +290,9 @@ public class ComponentDescriptorIO {
      * @throws SAXException
      */
     protected static void generateServiceXML(
-                    final ServiceDescription service,
-                    final ContentHandler contentHandler)
-    throws SAXException {
+            final ServiceDescription service,
+            final ContentHandler contentHandler)
+                    throws SAXException {
         final AttributesImpl ai = new AttributesImpl();
         IOUtils.addAttribute(ai, SERVICE_ATTR_FACTORY, String.valueOf(service.isServiceFactory()));
         IOUtils.indent(contentHandler, 2);
@@ -316,12 +316,12 @@ public class ComponentDescriptorIO {
      * @throws SAXException
      */
     private static void generateServiceXML(final String interfaceName, final ContentHandler
contentHandler)
-    throws SAXException {
+            throws SAXException {
         final AttributesImpl ai = new AttributesImpl();
         IOUtils.addAttribute(ai, INTERFACE_ATTR_NAME, interfaceName);
         IOUtils.indent(contentHandler, 3);
         contentHandler.startElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.INTERFACE,
ComponentDescriptorIO.INTERFACE_QNAME,
-                        ai);
+                ai);
         contentHandler.endElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.INTERFACE, ComponentDescriptorIO.INTERFACE_QNAME);
         IOUtils.newline(contentHandler);
     }
@@ -365,10 +365,10 @@ public class ComponentDescriptorIO {
      * @throws SAXException
      */
     protected static void generateReferenceXML(final ComponentDescription component,
-                    final DescriptionContainer module,
-                    final ReferenceDescription reference,
-                    final ContentHandler contentHandler)
-    throws SAXException {
+            final DescriptionContainer module,
+            final ReferenceDescription reference,
+            final ContentHandler contentHandler)
+                    throws SAXException {
         final AttributesImpl ai = new AttributesImpl();
         IOUtils.addAttribute(ai, ATTR_NAME, reference.getName());
         IOUtils.addAttribute(ai, INTERFACE_ATTR_NAME, reference.getInterfaceName());
@@ -392,7 +392,7 @@ public class ComponentDescriptorIO {
 
         IOUtils.indent(contentHandler, 2);
         contentHandler.startElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.REFERENCE,
ComponentDescriptorIO.REFERENCE_QNAME,
-                        ai);
+                ai);
         contentHandler.endElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.REFERENCE, ComponentDescriptorIO.REFERENCE_QNAME);
         IOUtils.newline(contentHandler);
     }
@@ -448,8 +448,9 @@ public class ComponentDescriptorIO {
         /**
          * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String,
java.lang.String, org.xml.sax.Attributes)
          */
+        @Override
         public void startElement(String uri, final String localName, final String name, final
Attributes attributes)
-        throws SAXException {
+                throws SAXException {
             // according to the spec, the elements should have the namespace,
             // except when the root element is the "component" element
             // So we check this for the first element, we receive.
@@ -654,6 +655,7 @@ public class ComponentDescriptorIO {
         /**
          * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
java.lang.String)
          */
+        @Override
         public void endElement(String uri, String localName, String name) throws SAXException
{
             if (this.overrideNamespace != null && "".equals(uri)) {
                 uri = this.overrideNamespace;
@@ -690,6 +692,7 @@ public class ComponentDescriptorIO {
         /**
          * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
          */
+        @Override
         public void characters(char[] ch, int start, int length) throws SAXException {
             if (this.pendingProperty != null) {
                 final String text = new String(ch, start, length);
@@ -708,7 +711,7 @@ public class ComponentDescriptorIO {
      * Generate descriptor file(s)
      */
     public static List<String> generateDescriptorFiles(final DescriptionContainer module,
final Options options, final Log logger)
-    throws SCRDescriptorException, SCRDescriptorFailureException {
+            throws SCRDescriptorException, SCRDescriptorFailureException {
         final List<ComponentContainer> components = new ArrayList<ComponentContainer>();
         for(final ComponentContainer container : module.getComponents()) {
             if (!container.getComponentDescription().isCreateDs()) {
@@ -720,7 +723,7 @@ public class ComponentDescriptorIO {
         }
 
         // check descriptor file
-        final File descriptorDir = new File(options.getOutputDirectory(), PARENT_NAME);
+        final File descriptorDir = options.getComponentDescriptorDirectory();
         final File descriptorFile = StringUtils.isEmpty(options.getSCRName()) ? null : new
File(descriptorDir, options.getSCRName());
 
         // terminate if there is nothing else to write

Modified: felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java?rev=1394025&r1=1394024&r2=1394025&view=diff
==============================================================================
--- felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
(original)
+++ felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
Thu Oct  4 12:51:49 2012
@@ -72,9 +72,9 @@ public class MetaTypeIO {
     private static final String OPTION_ELEMENT_QNAME = OPTION_ELEMENT;
 
     public static List<String> generateDescriptors(final DescriptionContainer module,
-                    final Options options,
-                    final Log logger)
-    throws SCRDescriptorException {
+            final Options options,
+            final Log logger)
+                    throws SCRDescriptorException {
         int metatypeCount = 0;
         for(final ComponentContainer component : module.getComponents()) {
             if ( component.getMetatypeContainer() != null ) {
@@ -83,8 +83,8 @@ public class MetaTypeIO {
         }
         // write meta type info if there is a file name
         if (!StringUtils.isEmpty(options.getMetaTypeName())) {
-            final File parentDir = new File(options.getOutputDirectory(), "OSGI-INF");
-            final File mtDir = new File(parentDir, "metatype");
+            final File mtDir = options.getMetaTypeDirectory();
+            final File parentDir = mtDir.getParentFile();
 
             final File mtFile = new File(mtDir, options.getMetaTypeName());
 
@@ -128,7 +128,7 @@ public class MetaTypeIO {
      * @throws SAXException
      */
     private static void write(final DescriptionContainer metaData, final List<ComponentContainer>
components, final File file)
-    throws SCRDescriptorException {
+            throws SCRDescriptorException {
         try {
             final ContentHandler contentHandler = IOUtils.getSerializer(file);
 
@@ -159,7 +159,7 @@ public class MetaTypeIO {
     }
 
     private static void generateOCDXML(final MetatypeContainer ocd, final ContentHandler
contentHandler)
-    throws SAXException {
+            throws SAXException {
         final AttributesImpl ai = new AttributesImpl();
         IOUtils.addAttribute(ai, "id", ocd.getId());
         IOUtils.addAttribute(ai, "name", ocd.getName());
@@ -182,7 +182,7 @@ public class MetaTypeIO {
     }
 
     private static void generateAttributeXML(final MetatypeAttributeDefinition ad, final
ContentHandler contentHandler)
-    throws SAXException {
+            throws SAXException {
         final AttributesImpl ai = new AttributesImpl();
         IOUtils.addAttribute(ai, "id", ad.getId());
         IOUtils.addAttribute(ai, "type", ad.getType());
@@ -224,7 +224,7 @@ public class MetaTypeIO {
     }
 
     private static void generateDesignateXML(final MetatypeContainer designate, final ContentHandler
contentHandler)
-    throws SAXException {
+            throws SAXException {
         final AttributesImpl ai = new AttributesImpl();
         IOUtils.addAttribute(ai, "pid", designate.getId());
         IOUtils.addAttribute(ai, "factoryPid", designate.getFactoryPid());
@@ -240,7 +240,7 @@ public class MetaTypeIO {
     }
 
     private static void generateObjectXML(final MetatypeContainer obj, final ContentHandler
contentHandler)
-    throws SAXException {
+            throws SAXException {
         final AttributesImpl ai = new AttributesImpl();
         IOUtils.addAttribute(ai, "ocdref", obj.getId());
         IOUtils.indent(contentHandler, 2);

Modified: felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java?rev=1394025&r1=1394024&r2=1394025&view=diff
==============================================================================
--- felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
(original)
+++ felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
Thu Oct  4 12:51:49 2012
@@ -175,7 +175,7 @@ public class SCRDescriptorMojo extends A
      * @parameter
      */
     private List<String> supportedProjectTypes = Arrays.asList( new String[]
-        { "jar", "bundle" } );
+            { "jar", "bundle" } );
 
     /**
      * @component
@@ -188,7 +188,7 @@ public class SCRDescriptorMojo extends A
         // ignore unsupported project types, useful when bundleplugin is configured in parent
pom
         if ( !supportedProjectTypes.contains( projectType ) ) {
             getLog().debug(
-                "Ignoring project type " + projectType + " - supportedProjectTypes = " +
supportedProjectTypes );
+                    "Ignoring project type " + projectType + " - supportedProjectTypes =
" + supportedProjectTypes );
             return;
         }
 
@@ -197,13 +197,13 @@ public class SCRDescriptorMojo extends A
 
         // create project
         final MavenProjectScanner scanner = new MavenProjectScanner(
-                        this.buildContext,
+                this.buildContext,
                 this.project, this.sourceIncludes, this.sourceExcludes, scrLog);
-        
+
         final Project project = new Project();
         // create the class loader
         project.setClassLoader(new URLClassLoader(getClassPath(), this
-                                .getClass().getClassLoader()));
+                .getClass().getClassLoader()));
         project.setDependencies(scanner.getDependencies());
         project.setSources(scanner.getSources());
         project.setClassesDirectory(this.project.getBuild().getOutputDirectory());
@@ -234,16 +234,14 @@ public class SCRDescriptorMojo extends A
 
             final Result result = generator.execute();
             this.setServiceComponentHeader(result.getScrFiles());
+
             this.updateProjectResources();
-            
-            // TODO - should we skip performing these operations just one descriptor file
is generated?
-            this.cleanUpDeletedSources(scanner.getDeletedSources());
+            // don't try to delete per-class descriptors if only one descriptor is generated
+            if ( options.isGenerateSeparateDescriptors() )
+                this.cleanUpDeletedSources(scanner.getDeletedSources(), options);
             this.refreshMessages(result.getProcessedSourceFiles());
-            
-            // TODO - refreshing the target files does not seem to be the right thing ; however,
new files
-            // are not refresh in Eclipse right now
-            //this.updateBuildContext(result);
-            
+            this.updateBuildContext(result);
+
         } catch (final SCRDescriptorException sde) {
             throw new MojoExecutionException(sde.getSourceLocation() + " : " + sde.getMessage(),
sde);
         } catch (final SCRDescriptorFailureException sdfe) {
@@ -252,48 +250,50 @@ public class SCRDescriptorMojo extends A
         }
     }
 
-	/**
-	 * @param scrFiles
-	 */
-	private void refreshMessages(List<String> scrFiles) {
-		
-		for ( String scrFile : scrFiles )
-			buildContext.removeMessages(new File(scrFile));
-		
-	}
-	
-	private void cleanUpDeletedSources(Collection<Source> deletedSources) {
-		
-		// TODO remove duplication of file name selection - MetaTypeIO, ComponentDescriptorIO
-		
-        final File parentDir = new File(this.outputDirectory, "OSGI-INF");
-        final File mtDir = new File(parentDir, "metatype");
-		
-		for ( Source deletedSource : deletedSources ) {
-			
-			File metaTypeFile = new File(mtDir, deletedSource.getClassName() + ".xml");
-			boolean deleted = metaTypeFile.delete();
-			if ( deleted )
-				buildContext.refresh(metaTypeFile);
-			
-			File componentDescriptorFile = new File(parentDir, deletedSource.getClassName()+".xml");
-			deleted = componentDescriptorFile.delete();
-			if ( deleted )
-				buildContext.refresh(componentDescriptorFile);
-		}
-	}
+    /**
+     * @param scrFiles
+     */
+    private void refreshMessages(List<String> scrFiles) {
+
+        for ( String scrFile : scrFiles )
+            buildContext.removeMessages(new File(scrFile));
+    }
+
+    private void cleanUpDeletedSources(final Collection<Source> deletedSources, final
Options options) {
+
+        final File componentDir = options.getComponentDescriptorDirectory();
+        final File mtDir = options.getMetaTypeDirectory();
+
+        for ( Source deletedSource : deletedSources ) {
+
+            File metaTypeFile = new File(mtDir, deletedSource.getClassName() + ".xml");
+            getLog().debug("Deleting " + metaTypeFile + " ");
+            boolean deleted = metaTypeFile.delete();
+            if ( deleted )
+                buildContext.refresh(metaTypeFile);
+
+            File componentDescriptorFile = new File(componentDir, deletedSource.getClassName()
+ ".xml");
+            getLog().debug("Deleting " + componentDescriptorFile);
+            deleted = componentDescriptorFile.delete();
+            if ( deleted )
+                buildContext.refresh(componentDescriptorFile);
+        }
+    }
 
-	
+    private void updateBuildContext(final Result result) {
 
-	private void updateBuildContext(final Result result) {
         if ( result.getMetatypeFiles() != null ) {
             for(final String name : result.getMetatypeFiles() ) {
-                this.buildContext.refresh(new File(this.outputDirectory, name.replace('/',
File.separatorChar)));
+                File metaTypeFile = new File(this.outputDirectory, name.replace('/', File.separatorChar));
+                getLog().debug("Refreshing " + metaTypeFile);
+                this.buildContext.refresh(metaTypeFile);
             }
         }
         if ( result.getScrFiles() != null ) {
             for(final String name : result.getScrFiles() ) {
-                this.buildContext.refresh(new File(this.outputDirectory, name.replace('/',
File.separatorChar)));
+                File scrFile = new File(this.outputDirectory, name.replace('/', File.separatorChar));
+                getLog().debug("Refreshing " + scrFile);
+                this.buildContext.refresh(scrFile);
             }
         }
     }
@@ -305,7 +305,7 @@ public class SCRDescriptorMojo extends A
 
         try {
             path.add(new File(this.project.getBuild().getOutputDirectory())
-                    .toURI().toURL());
+            .toURI().toURL());
         } catch (final IOException ioe) {
             throw new MojoFailureException(
                     "Unable to add target directory to classloader.");
@@ -401,7 +401,7 @@ public class SCRDescriptorMojo extends A
         boolean found = false;
         @SuppressWarnings("unchecked")
         final Iterator<Resource> rsrcIterator = this.project.getResources()
-                .iterator();
+        .iterator();
         while (!found && rsrcIterator.hasNext()) {
             final Resource rsrc = rsrcIterator.next();
             found = rsrc.getDirectory().equals(ourRsrcPath);



Mime
View raw message