GRANITE-4175 : scr.ant task does not provide scanClasses option. Apply patch from Daniel Kuffer

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1505656 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/scrtask/changelog.txt b/scrplugin/scrtask/changelog.txt
index 482012b..3b9a1e9 100644
--- a/scrplugin/scrtask/changelog.txt
+++ b/scrplugin/scrtask/changelog.txt
@@ -1,6 +1,7 @@
 Changes from 1.8.0 to 1.7.0
 ---------------------------
 ** Improvement
+    * [FELIX-4175] - scr.ant task does not provide scanClasses option
     * [FELIX-4101] - Create metatype.properties file when description and label are inlined
     * [FELIX-4126] - Discontinue creation of single XML descriptor files 
 
diff --git a/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java b/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java
index 74e0cb7..85dd3f7 100644
--- a/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java
+++ b/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java
@@ -59,6 +59,12 @@
     protected boolean strictMode = false;
 
     /**
+     * Set to true to scan classes instead of sources.
+     * By default scan sources to be backwards compatible
+     */
+    private boolean scanClasses = false;
+
+    /**
      * The version of the DS spec this plugin generates a descriptor for. By
      * default the version is detected by the used tags.
      *
@@ -131,11 +137,20 @@
         final List<Source> result = new ArrayList<Source>();
         @SuppressWarnings("unchecked")
         final Iterator<Resource> resources = sourceFiles.iterator();
+
+        final String ext;
+        if(scanClasses) {
+            ext = ".class";
+        } else {
+            ext = ".java";
+        }
+
         while ( resources.hasNext() ) {
             final Resource r = resources.next();
             if ( r instanceof FileResource ) {
                 final File file = ( ( FileResource ) r ).getFile();
-                if ( file.getName().endsWith(".java") ) {
+
+                if ( file.getName().endsWith(ext) ) {
                     result.add(new Source() {
 
                         public File getFile() {
@@ -144,7 +159,7 @@
 
                         public String getClassName() {
                             String name = file.getAbsolutePath().substring(prefixLength).replace(File.separatorChar, '/').replace('/', '.');
-                            return name.substring(0, name.length() - 5);
+                            return name.substring(0, name.length() - ext.length());
                         }
                     });
                 }
@@ -216,4 +231,12 @@
     public void setSpecVersion( String specVersion ) {
         this.specVersion = specVersion;
     }
+
+    public boolean isScanClasses() {
+        return scanClasses;
+    }
+
+    public void setScanClasses(boolean scanClasses) {
+        this.scanClasses = scanClasses;
+    }
 }