felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1413710 - in /felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo: MavenProjectScanner.java SCRDescriptorMojo.java
Date Mon, 26 Nov 2012 16:38:26 GMT
Author: cziegeler
Date: Mon Nov 26 16:38:25 2012
New Revision: 1413710

URL: http://svn.apache.org/viewvc?rev=1413710&view=rev
Log:
FELIX-2892 : Get SCR annotations to work with Scala

Modified:
    felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java
    felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java

Modified: felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java?rev=1413710&r1=1413709&r2=1413710&view=diff
==============================================================================
--- felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java
(original)
+++ felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java
Mon Nov 26 16:38:25 2012
@@ -29,6 +29,7 @@ import org.apache.felix.scrplugin.Log;
 import org.apache.felix.scrplugin.Source;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.DirectoryScanner;
 import org.codehaus.plexus.util.Scanner;
 import org.sonatype.plexus.build.incremental.BuildContext;
 
@@ -38,13 +39,14 @@ public class MavenProjectScanner {
 	private enum ScanKind {
 		ADDED_OR_UPDATED, DELETED;
 	}
-	
+
     private final MavenProject project;
 
     private final String includeString;
 
     private final String excludeString;
 
+    private final boolean scanClasses;
     private final Log log;
 
     private final BuildContext buildContext;
@@ -53,10 +55,12 @@ public class MavenProjectScanner {
             final MavenProject project,
             final String includeString,
             final String excludeString,
+            final boolean scanClasses,
             final Log log) {
         this.project = project;
         this.includeString = includeString;
         this.excludeString = excludeString;
+        this.scanClasses = scanClasses;
         this.log = log;
         this.buildContext = buildContext;
     }
@@ -65,7 +69,40 @@ public class MavenProjectScanner {
      * Return all sources.
      */
     public Collection<Source> getSources() {
-    	
+    	if ( scanClasses ) {
+            final ArrayList<Source> files = new ArrayList<Source>();
+
+            final DirectoryScanner scanner = new DirectoryScanner();
+            scanner.setBasedir(this.project.getBuild().getOutputDirectory());
+            if ( this.includeString != null ) {
+                scanner.setIncludes(this.includeString.split(","));
+            } else {
+                scanner.setIncludes(new String[] {"**/*.class"});
+            }
+            if ( this.excludeString != null ) {
+                scanner.setExcludes(this.excludeString.split(","));
+            }
+            scanner.addDefaultExcludes();
+
+            scanner.scan();
+
+            for ( final String fileName : scanner.getIncludedFiles() ) {
+                files.add( new Source() {
+
+                    public File getFile() {
+                        return new File(project.getBuild().getOutputDirectory(), fileName);
+                    }
+
+                    public String getClassName() {
+                        // remove ".class"
+                        String name = fileName.substring(0, fileName.length() - 6);
+                        return name.replace(File.separatorChar, '/').replace('/', '.');
+                    }
+                });
+            }
+
+    	    return files;
+    	}
     	return getSourcesForScanKind(ScanKind.ADDED_OR_UPDATED);
     }
 
@@ -97,23 +134,23 @@ public class MavenProjectScanner {
                 continue;
             }
             log.debug( "Scanning source tree " + tree );
-            
+
             final Scanner scanner;
             switch ( scanKind ) {
-            
+
             	case ADDED_OR_UPDATED:
             		scanner = this.buildContext.newScanner(directory, false);
             		break;
-            		
+
             	case DELETED:
             		scanner = this.buildContext.newDeleteScanner(directory);
             		break;
-            		
+
             	default:
             		throw new AssertionError("Unhandled ScanKind " + scanKind);
-            	
+
             }
-            
+
 
             if ( excludes != null && excludes.length > 0 ) {
                 scanner.setExcludes( excludes );
@@ -141,14 +178,14 @@ public class MavenProjectScanner {
 
         return files;
 	}
-    
+
 	/**
 	 * Returns all sources which were deleted since the previous build
-	 * 
+	 *
 	 * @return the deleted sources
 	 */
     public Collection<Source> getDeletedSources() {
-    	
+
     	return getSourcesForScanKind(ScanKind.DELETED);
     }
 

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=1413710&r1=1413709&r2=1413710&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
Mon Nov 26 16:38:25 2012
@@ -178,6 +178,14 @@ public class SCRDescriptorMojo extends A
             { "jar", "bundle" } );
 
     /**
+     * By default the plugin scans the java source tree, if this is set to true,
+     * the generated classes directory is scanned instead.
+     *
+     * @parameter default-value="false"
+     */
+    private boolean scanClasses;
+
+    /**
      * @component
      */
     private BuildContext buildContext;
@@ -198,7 +206,7 @@ public class SCRDescriptorMojo extends A
         // create project
         final MavenProjectScanner scanner = new MavenProjectScanner(
                 this.buildContext,
-                this.project, this.sourceIncludes, this.sourceExcludes, scrLog);
+                this.project, this.sourceIncludes, this.sourceExcludes, this.scanClasses,
scrLog);
 
         final Project project = new Project();
         // create the class loader
@@ -259,7 +267,7 @@ public class SCRDescriptorMojo extends A
 
     /**
      * Remove existing files for the sources which have recently changed
-     * 
+     *
      * <p>This method ensures that files which were generated in a previous run are
not
      * leftover if the source file has changed by:
      * <ol>
@@ -267,7 +275,7 @@ public class SCRDescriptorMojo extends A
      *  <li>No longer having the <tt>metatype</tt> property set to true</li>
      * </ol>
      * </p>
-     * 
+     *
      * @param sources the changed source files
      */
     private void removePossiblyStaleFiles(final Collection<Source> sources, final Options
options) {



Mime
View raw message