FELIX-2680 Require minimum version of the SCR Annotation library
artifact (if declared). For now set this version to 1.3.1-SNAPSHOT. This
is to be updated once the release candidate for the SCR Annotation
library 1.4.0 has been built.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1029903 13f79535-47bb-0310-9956-ffa450edef68
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 6638226..e9560e1 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
@@ -26,6 +26,9 @@
 
 import org.apache.felix.scrplugin.*;
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
 import org.apache.maven.model.Resource;
 import org.apache.maven.plugin.*;
 import org.apache.maven.project.MavenProject;
@@ -43,6 +46,30 @@
 public class SCRDescriptorMojo extends AbstractMojo {
 
     /**
+     * The groupID of the SCR Annotation library
+     *
+     * @see #SCR_ANN_MIN_VERSION
+     * @see #checkAnnotationArtifact(Artifact)
+     */
+    private static final String SCR_ANN_GROUPID = "org.apache.felix";
+
+    /**
+     * The artifactID of the SCR Annotation library.
+     *
+     * @see #SCR_ANN_MIN_VERSION
+     * @see #checkAnnotationArtifact(Artifact)
+     */
+    private static final String SCR_ANN_ARTIFACTID = "org.apache.felix.scr.annotations";
+
+    /**
+     * The minimum SCR Annotation library version supported by this plugin. See
+     * FELIX-2680 for full details.
+     *
+     * @see #checkAnnotationArtifact(Artifact)
+     */
+    private static final ArtifactVersion SCR_ANN_MIN_VERSION = new DefaultArtifactVersion("1.3.1-SNAPSHOT");
+
+    /**
      * @parameter expression="${project.build.directory}/scr-plugin-generated"
      * @required
      * @readonly
@@ -186,6 +213,7 @@
 
         for (Iterator<Artifact> ai=artifacts.iterator(); ai.hasNext(); ) {
             Artifact a = ai.next();
+            assertMinScrAnnotationArtifactVersion(a);
             try {
                 path.add(a.getFile().toURI().toURL());
             } catch (IOException ioe) {
@@ -196,6 +224,46 @@
         return path.toArray( new URL[path.size()] );
     }
 
+    /**
+     * Asserts that the artifact is at least version
+     * {@link #SCR_ANN_MIN_VERSION} if it is
+     * org.apache.felix:org.apache.felix.scr.annotations. If the version is
+     * lower then the build fails because as of Maven SCR Plugin 1.6.0 the old
+     * SCR Annotation libraries do not produce descriptors any more. If the
+     * artifact is not this method silently returns.
+     *
+     * @param a The artifact to check and assert
+     * @see #SCR_ANN_ARTIFACTID
+     * @see #SCR_ANN_GROUPID
+     * @see #SCR_ANN_MIN_VERSION
+     * @throws MojoFailureException If the artifact refers to the SCR Annotation
+     *             library with a version less than {@link #SCR_ANN_MIN_VERSION}
+     */
+    private void assertMinScrAnnotationArtifactVersion(Artifact a) throws MojoFailureException
+    {
+        if (SCR_ANN_ARTIFACTID.equals(a.getArtifactId()) && SCR_ANN_GROUPID.equals(a.getGroupId()))
+        {
+            // compare version number
+            try
+            {
+                ArtifactVersion aVersion = a.getSelectedVersion();
+                if (SCR_ANN_MIN_VERSION.compareTo(aVersion) > 0)
+                {
+                    getLog().error("Project depends on " + a);
+                    getLog().error("Minimum required version is " + SCR_ANN_MIN_VERSION);
+                    throw new MojoFailureException(
+                        "Please use org.apache.felix:org.apache.felix.scr.annotations version " + SCR_ANN_MIN_VERSION
+                            + " or newer.");
+                }
+            }
+            catch (OverConstrainedVersionException oe)
+            {
+                getLog().error(oe.toString());
+                getLog().debug(oe);
+                throw new MojoFailureException(oe.getMessage());
+            }
+        }
+    }
 
     private void setServiceComponentHeader()
     {