FELIX-4246 : SCR and Metatype descriptor files get deleted on subsequent (incremental) eclipse build

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1526858 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/generator/changelog.txt b/scrplugin/generator/changelog.txt
index f3c0e76..5384f79 100644
--- a/scrplugin/generator/changelog.txt
+++ b/scrplugin/generator/changelog.txt
@@ -3,6 +3,7 @@
 ** Bug
     * [FELIX-4192] - SCR Generator fails with a NPE in case a class level Reference doesn't define a referenceInterface
     * [FELIX-4010] - SCR Plugin aborts when scanning a Java 8 class file
+    * [FELIX-4246] - SCR and Metatype descriptor files get deleted on subsequent (incremental) eclipse build
 
  
 Changes from 1.8.0 to 1.7.0
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
index db0def5..610ca29 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
@@ -43,6 +43,9 @@
     /** The output directory for the generated files. */
     private File outputDirectory;
 
+    /** Is this an incremental build? */
+    private boolean incremental = false;
+
     /**
      * @see #setGenerateAccessors(boolean)
      * @return Whether accessor methods should be generated.
@@ -157,4 +160,18 @@
     public File getComponentDescriptorDirectory() {
         return new File(this.getOutputDirectory(), PARENT_NAME);
     }
+
+    /**
+     * Is this an incremental build
+     */
+    public boolean isIncremental() {
+        return incremental;
+    }
+
+    /**
+     * Set whether this is an incremental build
+     */
+    public void setIncremental(final boolean incremental) {
+        this.incremental = incremental;
+    }
 }
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
index cff9823..e9dd4ac 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
@@ -18,11 +18,9 @@
  */
 package org.apache.felix.scrplugin.xml;
 
-import java.awt.Component;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.security.Provider.Service;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.StringTokenizer;
@@ -210,7 +208,7 @@
     }
 
     /**
-     * Write the xml for a {@link Component}.
+     * Write the xml for a Component
      *
      * @param component
      * @param contentHandler
@@ -266,7 +264,7 @@
     }
 
     /**
-     * Write the xml for a {@link Implementation}.
+     * Write the xml for an Implementation.
      *
      * @param implementation
      * @param contentHandler
@@ -284,7 +282,7 @@
     }
 
     /**
-     * Write the xml for a {@link Service}.
+     * Write the xml for a service.
      *
      * @param service
      * @param contentHandler
@@ -310,7 +308,7 @@
     }
 
     /**
-     * Write the xml for a {@link Interface}.
+     * Write the xml for a interface
      *
      * @param interf
      * @param contentHandler
@@ -328,7 +326,7 @@
     }
 
     /**
-     * Write the xml for a {@link Property}.
+     * Write the xml for a property.
      *
      * @param property
      * @param contentHandler
@@ -369,7 +367,7 @@
     }
 
     /**
-     * Write the xml for a {@link Reference}.
+     * Write the xml for a Reference.
      *
      * @param reference
      * @param contentHandler
@@ -752,7 +750,7 @@
         if (components.isEmpty()) {
             logger.debug("No Service Component Descriptors found in project.");
             // remove files if it exists
-            if ( descriptorDir.exists() ) {
+            if ( descriptorDir.exists() && !options.isIncremental()) {
                 for(final File f : descriptorDir.listFiles()) {
                     if ( f.isFile() ) {
                         logger.debug("Removing obsolete service descriptor " + f);
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
index d726a9e..14e75a9 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
@@ -174,7 +174,7 @@
 
             return fileNames;
         }
-        if (mtDir.exists()) {
+        if (mtDir.exists() && !options.isIncremental()) {
             for(final File f : mtDir.listFiles()) {
                 if ( f.isFile() ) {
                     logger.debug("Removing obsolete metatype file " + f);
diff --git a/scrplugin/maven-scr-plugin/changelog.txt b/scrplugin/maven-scr-plugin/changelog.txt
index a8b0e1a..38028be 100644
--- a/scrplugin/maven-scr-plugin/changelog.txt
+++ b/scrplugin/maven-scr-plugin/changelog.txt
@@ -5,6 +5,7 @@
 ** Bug
     * [FELIX-4192] - SCR Generator fails with a NPE in case a class level Reference doesn't define a referenceInterface
     * [FELIX-4010] - SCR Plugin aborts when scanning a Java 8 class file
+    * [FELIX-4246] - SCR and Metatype descriptor files get deleted on subsequent (incremental) eclipse build
 
 
 Changes from 1.14.0 to 1.13.0
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 214527c..ce77ff5 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
@@ -201,6 +201,7 @@
         options.setStrictMode(strictMode);
         options.setProperties(properties);
         options.setSpecVersion(SpecVersion.fromName(specVersion));
+        options.setIncremental(this.buildContext.isIncremental());
 
         if ( specVersion != null && options.getSpecVersion() == null ) {
             throw new MojoExecutionException("Unknown spec version specified: " + specVersion);