FELIX-2892 : Get SCR annotations to work with Scala

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1413710 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java b/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java
index 3912f73..0685ab0 100644
--- a/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java
+++ b/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java
@@ -29,6 +29,7 @@
 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 @@
 	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 @@
             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 @@
      * 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 @@
                 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 @@
 
         return files;
 	}
-    
+
 	/**
 	 * Returns all sources which were deleted since the previous build
-	 * 
+	 *
 	 * @return the deleted sources
 	 */
     public Collection<Source> getDeletedSources() {
-    	
+
     	return getSourcesForScanKind(ScanKind.DELETED);
     }
 
diff --git a/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java b/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
index 68c515a..663d9c5 100644
--- a/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
+++ b/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
@@ -178,6 +178,14 @@
             { "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 @@
         // 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 @@
 
     /**
      * 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 @@
      *  <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) {