Author: dkulp
Date: Fri May 16 20:21:14 2014
New Revision: 1595335

URL: http://svn.apache.org/r1595335
Log:
Update version plugin to work with all the Maven versions > 3
Also flip to using the plugin annotations

Modified:
    aries/trunk/blueprint/blueprint-core/pom.xml
    aries/trunk/versioning/versioning-plugin/pom.xml
    
aries/trunk/versioning/versioning-plugin/src/main/java/org/apache/aries/versioning/mojo/CLVersionCheckerMojo.java
    
aries/trunk/versioning/versioning-plugin/src/main/java/org/apache/aries/versioning/mojo/VersionCheckerMojo.java

Modified: aries/trunk/blueprint/blueprint-core/pom.xml
URL: 
http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/pom.xml?rev=1595335&r1=1595334&r2=1595335&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/pom.xml (original)
+++ aries/trunk/blueprint/blueprint-core/pom.xml Fri May 16 20:21:14 2014
@@ -229,7 +229,7 @@
             <plugin>
                 <groupId>org.apache.aries.versioning</groupId>
                 <artifactId>org.apache.aries.versioning.plugin</artifactId>
-                <version>0.1.0</version>
+                <version>0.2.0-SNAPSHOT</version>
                 <executions>
                     <execution>
                         <id>default-verify</id>

Modified: aries/trunk/versioning/versioning-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/aries/trunk/versioning/versioning-plugin/pom.xml?rev=1595335&r1=1595334&r2=1595335&view=diff
==============================================================================
--- aries/trunk/versioning/versioning-plugin/pom.xml (original)
+++ aries/trunk/versioning/versioning-plugin/pom.xml Fri May 16 20:21:14 2014
@@ -51,29 +51,19 @@
             <version>3.0.3</version>
         </dependency>
         <dependency>
-           <groupId>org.eclipse.aether</groupId>
-           <artifactId>aether-api</artifactId>
-           <version>0.9.1.v20140329</version>
-         </dependency>
-         <dependency>
-           <groupId>org.eclipse.aether</groupId>
-           <artifactId>aether-util</artifactId>
-           <version>0.9.1.v20140329</version>
-         </dependency>
-        <dependency>
             <groupId>org.apache.maven</groupId>
             <artifactId>maven-artifact</artifactId>
-            <version>3.1.0</version>
+            <version>3.0.3</version>
         </dependency>
         <dependency>
             <groupId>org.apache.maven</groupId>
             <artifactId>maven-core</artifactId>
-            <version>3.1.0</version>
+            <version>3.0.3</version>
         </dependency>
         <dependency>
             <groupId>org.apache.maven</groupId>
             <artifactId>maven-compat</artifactId>
-            <version>3.1.0</version>
+            <version>3.0.3</version>
         </dependency>
         <dependency>
             <groupId>junit</groupId>
@@ -81,15 +71,43 @@
             <version>3.8.1</version>
             <scope>test</scope>
         </dependency>
+        
+        <dependency>
+            <groupId>org.apache.maven.plugin-tools</groupId>
+            <artifactId>maven-plugin-annotations</artifactId>
+            <version>3.2</version>
+            <scope>provided</scope>
+        </dependency>
+        <!-- maven shared -->
+        <dependency>
+            <groupId>org.apache.maven.shared</groupId>
+            <artifactId>maven-artifact-resolver</artifactId>
+            <version>1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven.shared</groupId>
+            <artifactId>maven-common-artifact-filters</artifactId>
+            <version>1.4</version>
+        </dependency>
     </dependencies>
     <build>
         <plugins>
             <plugin>
                 <artifactId>maven-plugin-plugin</artifactId>
-                <version>2.3</version>
+                <version>3.2</version>
                 <configuration>
                     <goalPrefix>asv</goalPrefix>
+                    <useJava5>true</useJava5>
+                    
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
                 </configuration>
+                <executions>
+                    <execution>
+                        <id>generate-descriptor</id>
+                        <goals>
+                            <goal>descriptor</goal>
+                        </goals>
+                    </execution>
+                </executions>
             </plugin>
         </plugins>
     </build>

Modified: 
aries/trunk/versioning/versioning-plugin/src/main/java/org/apache/aries/versioning/mojo/CLVersionCheckerMojo.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/versioning/versioning-plugin/src/main/java/org/apache/aries/versioning/mojo/CLVersionCheckerMojo.java?rev=1595335&r1=1595334&r2=1595335&view=diff
==============================================================================
--- 
aries/trunk/versioning/versioning-plugin/src/main/java/org/apache/aries/versioning/mojo/CLVersionCheckerMojo.java
 (original)
+++ 
aries/trunk/versioning/versioning-plugin/src/main/java/org/apache/aries/versioning/mojo/CLVersionCheckerMojo.java
 Fri May 16 20:21:14 2014
@@ -20,15 +20,13 @@
 
 package org.apache.aries.versioning.mojo;
 
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+
 /**
  * Check semantic version changes between an explicitly named old artifact and 
the project output artifact.
  * Optionally write packageinfo files for wrong package versions.
- *
- * @goal check
- *
- * @requiresDirectInvocation true
- *
- * @execute phase=package
  */
+@Mojo(name = "check", defaultPhase = LifecyclePhase.PACKAGE, 
requiresDirectInvocation = true)
 public class CLVersionCheckerMojo extends VersionCheckerMojo {
 }

Modified: 
aries/trunk/versioning/versioning-plugin/src/main/java/org/apache/aries/versioning/mojo/VersionCheckerMojo.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/versioning/versioning-plugin/src/main/java/org/apache/aries/versioning/mojo/VersionCheckerMojo.java?rev=1595335&r1=1595334&r2=1595335&view=diff
==============================================================================
--- 
aries/trunk/versioning/versioning-plugin/src/main/java/org/apache/aries/versioning/mojo/VersionCheckerMojo.java
 (original)
+++ 
aries/trunk/versioning/versioning-plugin/src/main/java/org/apache/aries/versioning/mojo/VersionCheckerMojo.java
 Fri May 16 20:21:14 2014
@@ -22,196 +22,160 @@ import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.aries.util.manifest.BundleManifest;
 import org.apache.aries.versioning.check.BundleCompatibility;
 import org.apache.aries.versioning.check.BundleInfo;
 import org.apache.aries.versioning.check.VersionChange;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
-import org.eclipse.aether.RepositorySystem;
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.artifact.DefaultArtifact;
-import org.eclipse.aether.repository.RemoteRepository;
-import org.eclipse.aether.resolution.ArtifactRequest;
-import org.eclipse.aether.resolution.ArtifactResult;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.repository.RepositorySystem;
 
 /**
- * Check semantic version changes between an explicitly named old artifact and 
the project output artifact.
- * Optionally write packageinfo files for wrong package versions.
- *
- * @goal version-check
- * 
- * @phase verify
+ * Check semantic version changes between an explicitly named old artifact and
+ * the project output artifact. Optionally write packageinfo files for wrong
+ * package versions.
  */
-public class VersionCheckerMojo
-extends AbstractMojo
-{
-
-  /**
-   * name of old artifact in 
<groupId>:<artifactId>[:<extension>[:<classifier>]]:<version> notation
-   * @parameter expression="${oldArtifact}"
-   */
-  private String oldArtifact;
-
-  //    * @parameter expression="${project.artifact.file}"
-  /**
-   * Location of the file.
-   * @parameter 
expression="${project.build.directory}/${project.build.finalName}.jar"
-   * @required
-   */
-  private File newFile;
-
-  /**
-   * whether to write packageinfo files into source tree
-   * @parameter expression="${writePackageInfos}" default-value="false"
-   */
-  private boolean writePackageinfos = false;
-
-  /**
-   * source tree location
-   * @parameter expression="${project.basedir}/src/main/java"
-   */
-  private File source;
-
-  /**
-   * The entry point to Aether, i.e. the component doing all the work.
-   *
-   * @component
-   * @required
-   * @readonly
-   */
-  private RepositorySystem repoSystem;
-
-  /**
-   * The current repository/network configuration of Maven.
-   *
-   * @parameter default-value="${repositorySystemSession}"
-   * @required
-   * @readonly
-   */
-  private RepositorySystemSession repoSession;
-
-  /**
-   * The project's remote repositories to use for the resolution of project 
dependencies.
-   *
-   * @parameter default-value="${project.remoteProjectRepositories}"
-   * @readonly
-   */
-  private List<RemoteRepository> projectRepos;
-
-  /**
-   * The project's remote repositories to use for the resolution of plugins 
and their dependencies.
-   *
-   * @parameter default-value="${project.remotePluginRepositories}"
-   * @required
-   * @readonly
-   */
-  private List<RemoteRepository> pluginRepos;
-
-
-
-  public void execute()
-  throws MojoExecutionException
-  {
-    if (oldArtifact != null) {
-      try {
-        BundleInfo oldBundle = getBundleInfo(resolve(oldArtifact));
-        BundleInfo newBundle = getBundleInfo(newFile);
-        String bundleSymbolicName = 
newBundle.getBundleManifest().getSymbolicName();
-        URLClassLoader oldClassLoader = new URLClassLoader(new URL[] 
{oldBundle.getBundle().toURI().toURL()});
-        URLClassLoader newClassLoader = new URLClassLoader(new URL[] 
{newBundle.getBundle().toURI().toURL()});
-        BundleCompatibility bundleCompatibility = new 
BundleCompatibility(bundleSymbolicName, newBundle, oldBundle, oldClassLoader, 
newClassLoader);
-        bundleCompatibility.invoke();
-        String bundleElement = bundleCompatibility.getBundleElement();
-        String pkgElement = bundleCompatibility.getPkgElements().toString();
-        boolean failed = false;
-        if ((bundleElement != null) && (bundleElement.trim().length() >0)){
-          getLog().error(bundleElement + "\r\n");
-          failed = true;
-        }
-        if ((pkgElement != null) && (pkgElement.trim().length() >0 )) {
-          getLog().error(pkgElement);
-          failed = true;
-        }
+@Mojo(name = "version-check", defaultPhase = LifecyclePhase.VERIFY)
+public class VersionCheckerMojo extends AbstractMojo {
 
-        if (writePackageinfos) {
-          writePackageInfos(bundleCompatibility);
+    /**
+     * name of old artifact in
+     * groupId:artifactId[:extension[:classifier]]:version notation
+     */
+    @Parameter(defaultValue="${oldArtifact")
+    private String oldArtifact;
+
+    /**
+     * Location of the file.
+     */
+    @Parameter(required = true, defaultValue = 
"${project.build.directory}/${project.build.finalName}.jar")
+    private File newFile;
+
+    /**
+     * whether to write packageinfo files into source tree
+     */
+    @Parameter(property="writePackageInfos", defaultValue="false")
+    private boolean writePackageinfos = false;
+
+    /**
+     * source tree location
+     */
+    @Parameter(defaultValue="${project.basedir}/src/main/java")
+    private File source;
+
+    @Component
+    private RepositorySystem repository;
+    
+    @Component
+    protected MavenProject project;
+    
+    @Component
+    private MavenSession session;
+    
+    public void execute() throws MojoExecutionException {
+        if (oldArtifact != null) {
+            try {
+                BundleInfo oldBundle = getBundleInfo(resolve(oldArtifact));
+                BundleInfo newBundle = getBundleInfo(newFile);
+                String bundleSymbolicName = 
newBundle.getBundleManifest().getSymbolicName();
+                URLClassLoader oldClassLoader = new URLClassLoader(new URL[] 
{oldBundle.getBundle().toURI()
+                    .toURL()});
+                URLClassLoader newClassLoader = new URLClassLoader(new URL[] 
{newBundle.getBundle().toURI()
+                    .toURL()});
+                BundleCompatibility bundleCompatibility = new 
BundleCompatibility(bundleSymbolicName,
+                                                                               
   newBundle, oldBundle,
+                                                                               
   oldClassLoader,
+                                                                               
   newClassLoader);
+                bundleCompatibility.invoke();
+                String bundleElement = bundleCompatibility.getBundleElement();
+                String pkgElement = 
bundleCompatibility.getPkgElements().toString();
+                
+                boolean failed = false;
+                if ((bundleElement != null) && (bundleElement.trim().length() 
> 0)) {
+                    getLog().error(bundleElement + "\r\n");
+                    failed = true;
+                }
+                if ((pkgElement != null) && (pkgElement.trim().length() > 0)) {
+                    getLog().error(pkgElement);
+                    failed = true;
+                }
+
+                if (writePackageinfos) {
+                    writePackageInfos(bundleCompatibility);
+                }
+                if (failed) {
+                    throw new RuntimeException("Semantic Versioning 
incorrect");
+                } else {
+                    getLog().info("All package or bundle versions are 
semanticly versioned correctly.");
+                }
+            } catch (MalformedURLException e) {
+                throw new MojoExecutionException("Problem analyzing sources");
+            } catch (IOException e) {
+                throw new MojoExecutionException("Problem analyzing sources");
+            }
         }
-        if (failed){
-          throw new RuntimeException ("Semantic Versioning incorrect");
-        } else {
-          getLog().info("All package or bundle versions are semanticly 
versioned correctly.");
-        }
-      } catch (MalformedURLException e) {
-        throw new MojoExecutionException("Problem analyzing sources");
-      } catch (IOException e) {
-        throw new MojoExecutionException("Problem analyzing sources");
-      }
     }
-  }
 
-  private void writePackageInfos(BundleCompatibility bundleCompatibility) {
-    Map<String, VersionChange> packages = 
bundleCompatibility.getPackageChanges();
-    for (Map.Entry<String, VersionChange> packageChange: packages.entrySet()) {
-      VersionChange versionChange = packageChange.getValue();
-      if (!versionChange.isCorrect()) {
-        String packageName = packageChange.getKey();
-        String[] bits = packageName.split("\\.");
-        File packageInfo = source;
-        for (String bit: bits) {
-          packageInfo = new File(packageInfo, bit);
-        }
-        packageInfo.mkdirs();
-        packageInfo = new File(packageInfo, "packageinfo");
-        try {
-          FileWriter w = new FileWriter(packageInfo);
-          try {
-            w.append("# generated by Apache Aries semantic versioning tool\n");
-            w.append("version " + 
versionChange.getRecommendedNewVersion().toString() + "\n");
-            w.flush();
-          } finally {
-            w.close();
-          }
-        } catch (IOException e) {
-          getLog().error("Could not write packageinfo for package " + 
packageName, e);
+    private void writePackageInfos(BundleCompatibility bundleCompatibility) {
+        Map<String, VersionChange> packages = 
bundleCompatibility.getPackageChanges();
+        for (Map.Entry<String, VersionChange> packageChange : 
packages.entrySet()) {
+            VersionChange versionChange = packageChange.getValue();
+            if (!versionChange.isCorrect()) {
+                String packageName = packageChange.getKey();
+                String[] bits = packageName.split("\\.");
+                File packageInfo = source;
+                for (String bit : bits) {
+                    packageInfo = new File(packageInfo, bit);
+                }
+                packageInfo.mkdirs();
+                packageInfo = new File(packageInfo, "packageinfo");
+                try {
+                    FileWriter w = new FileWriter(packageInfo);
+                    try {
+                        w.append("# generated by Apache Aries semantic 
versioning tool\n");
+                        w.append("version " + 
versionChange.getRecommendedNewVersion().toString() + "\n");
+                        w.flush();
+                    } finally {
+                        w.close();
+                    }
+                } catch (IOException e) {
+                    getLog().error("Could not write packageinfo for package " 
+ packageName, e);
+                }
+            }
         }
-      }
     }
-  }
 
-  private File resolve(String oldArtifact) {
-    Artifact artifact = new DefaultArtifact(oldArtifact);
-    return resolve(artifact);
-  }
-
-  private File resolve(Artifact artifact) {
-    ArtifactRequest request = new ArtifactRequest();
-    request.setArtifact(artifact);
-    request.setRepositories(projectRepos);
-
-    getLog().debug("Resolving artifact " + artifact +
-        " from " + projectRepos);
-
-    ArtifactResult result;
-    try {
-      result = repoSystem.resolveArtifact(repoSession, request);
-    } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) {
-      getLog().warn("could not resolve " + artifact, e);
-      return null;
+    private File resolve(String artifactDescriptor) {
+        String[] s = artifactDescriptor.split(":");
+
+        String type = (s.length >= 4 ? s[3] : "jar");
+        Artifact artifact = repository.createArtifact(s[0], s[1], s[2], type);
+
+        ArtifactResolutionRequest request = new ArtifactResolutionRequest();
+        request.setArtifact(artifact);
+        
+        request.setResolveRoot(true).setResolveTransitively(false);
+        request.setServers( session.getRequest().getServers() );
+        request.setMirrors( session.getRequest().getMirrors() );
+        request.setProxies( session.getRequest().getProxies() );
+        request.setLocalRepository(session.getLocalRepository());
+        
request.setRemoteRepositories(session.getRequest().getRemoteRepositories());
+        repository.resolve(request);
+        return artifact.getFile();
     }
 
-    getLog().debug("Resolved artifact " + artifact + " to " +
-        result.getArtifact().getFile() + " from "
-        + result.getRepository());
-    return result.getArtifact().getFile();
-  }
-
-  private BundleInfo getBundleInfo(File f) {
-    BundleManifest bundleManifest = BundleManifest.fromBundle(f);
-    return new BundleInfo(bundleManifest, f);
-  }
+    private BundleInfo getBundleInfo(File f) {
+        BundleManifest bundleManifest = BundleManifest.fromBundle(f);
+        return new BundleInfo(bundleManifest, f);
+    }
 }


Reply via email to