This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to annotated tag japicmp-base-0.1.0
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git

commit c5ec4fed0a43eae1221a0c6ca7072c02fe824c91
Author: siom79 <[email protected]>
AuthorDate: Wed Jun 18 22:11:21 2014 +0200

    started maven plugin
---
 japicmp-maven-plugin/pom.xml                       |  88 ++++++++++++++
 .../src/main/java/japicmp/maven/Dependency.java    |  31 +++++
 .../src/main/java/japicmp/maven/JApiCmpMojo.java   | 129 +++++++++++++++++++++
 .../src/main/java/japicmp/maven/Version.java       |  13 +++
 japicmp-testbase/japicmp-test-maven-plugin/pom.xml |  55 +++++++++
 japicmp-testbase/pom.xml                           |   3 +-
 pom.xml                                            |   7 +-
 7 files changed, 324 insertions(+), 2 deletions(-)

diff --git a/japicmp-maven-plugin/pom.xml b/japicmp-maven-plugin/pom.xml
new file mode 100644
index 0000000..8c9c796
--- /dev/null
+++ b/japicmp-maven-plugin/pom.xml
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <parent>
+        <artifactId>japicmp-base</artifactId>
+        <groupId>japicmp</groupId>
+        <version>0.0.3-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>japicmp-maven-plugin</artifactId>
+    <packaging>maven-plugin</packaging>
+
+    <properties>
+        <maven.version>3.1.0</maven.version>
+        <aether.version>0.9.0.M2</aether.version>
+    </properties>
+
+    <prerequisites>
+        <maven>3.1.0</maven>
+    </prerequisites>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-plugin-api</artifactId>
+            <version>${maven.version}</version>
+            <scope>provided</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.apache.maven</groupId>
+                    <artifactId>maven-model</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.apache.maven</groupId>
+                    <artifactId>maven-artifact</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.eclipse.sisu</groupId>
+                    <artifactId>org.eclipse.sisu.plexus</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-core</artifactId>
+            <version>${maven.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.aether</groupId>
+            <artifactId>aether-api</artifactId>
+            <version>${aether.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.aether</groupId>
+            <artifactId>aether-util</artifactId>
+            <version>${aether.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>japicmp</groupId>
+            <artifactId>japicmp</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-plugin-plugin</artifactId>
+                <version>3.2</version>
+                <configuration>
+                    
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>mojo-descriptor</id>
+                        <phase>process-classes</phase>
+                        <goals>
+                            <goal>descriptor</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
\ No newline at end of file
diff --git a/japicmp-maven-plugin/src/main/java/japicmp/maven/Dependency.java 
b/japicmp-maven-plugin/src/main/java/japicmp/maven/Dependency.java
new file mode 100644
index 0000000..bd676ea
--- /dev/null
+++ b/japicmp-maven-plugin/src/main/java/japicmp/maven/Dependency.java
@@ -0,0 +1,31 @@
+package japicmp.maven;
+
+public class Dependency {
+    private String groupId;
+    private String artifactId;
+    private String version;
+
+    public String getGroupId() {
+        return groupId;
+    }
+
+    public void setGroupId(String groupId) {
+        this.groupId = groupId;
+    }
+
+    public String getArtifactId() {
+        return artifactId;
+    }
+
+    public void setArtifactId(String artifactId) {
+        this.artifactId = artifactId;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+}
diff --git a/japicmp-maven-plugin/src/main/java/japicmp/maven/JApiCmpMojo.java 
b/japicmp-maven-plugin/src/main/java/japicmp/maven/JApiCmpMojo.java
new file mode 100644
index 0000000..11b0582
--- /dev/null
+++ b/japicmp-maven-plugin/src/main/java/japicmp/maven/JApiCmpMojo.java
@@ -0,0 +1,129 @@
+package japicmp.maven;
+
+import com.google.common.io.Files;
+import japicmp.cmp.JarArchiveComparator;
+import japicmp.cmp.JarArchiveComparatorOptions;
+import japicmp.config.Options;
+import japicmp.model.JApiClass;
+import japicmp.output.stdout.StdoutOutputGenerator;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.resolution.ArtifactRequest;
+import org.eclipse.aether.resolution.ArtifactResult;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.List;
+
+/**
+ * @goal cmp
+ */
+public class JApiCmpMojo extends AbstractMojo {
+    /**
+     * @parameter
+     */
+    private Version oldVersion;
+
+    /**
+     * @parameter
+     */
+    private Version newVersion;
+
+    /**
+     * @parameter expression="${project.build.directory}"
+     * @required
+     */
+    private File projectBuildDir;
+
+    /**
+     * @component
+     */
+    private RepositorySystem repoSystem;
+
+    /**
+     * @component default-value="${project.remoteProjectRepositories}"
+     */
+    private List<RemoteRepository> remoteRepos;
+
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        File oldVersionFile = null;
+        File newVersionFile = null;
+        if (oldVersion != null) {
+            Dependency dependency = oldVersion.getDependency();
+            if (dependency != null) {
+                String descriptor = dependency.getGroupId() + ":" + 
dependency.getArtifactId() + ":" + dependency.getVersion();
+                getLog().debug("oldVersion: " + descriptor);
+                oldVersionFile = resolveArtifact(descriptor);
+            }
+        }
+        if (newVersion != null) {
+            Dependency dependency = newVersion.getDependency();
+            if (dependency != null) {
+                String descriptor = dependency.getGroupId() + ":" + 
dependency.getArtifactId() + ":" + dependency.getVersion();
+                getLog().debug("newVersion: " + descriptor);
+                newVersionFile = resolveArtifact(descriptor);
+            }
+        }
+        if(oldVersionFile != null && newVersionFile != null) {
+            JarArchiveComparatorOptions comparatorOptions = new 
JarArchiveComparatorOptions();
+            JarArchiveComparator jarArchiveComparator = new 
JarArchiveComparator(comparatorOptions);
+            List<JApiClass> jApiClasses = 
jarArchiveComparator.compare(oldVersionFile, newVersionFile);
+            StdoutOutputGenerator stdoutOutputGenerator = new 
StdoutOutputGenerator();
+            String output = stdoutOutputGenerator.generate(oldVersionFile, 
newVersionFile, jApiClasses, new Options());
+            getLog().info(output);
+            if(projectBuildDir != null && projectBuildDir.exists()) {
+                try {
+                    File japiBuildDir = new 
File(projectBuildDir.getCanonicalPath() + File.separator + "japicmp");
+                    japiBuildDir.mkdirs();
+                    File diffOutputfile = new 
File(japiBuildDir.getCanonicalPath() + File.separator + "japicmp.diff");
+                    FileWriter fileWriter = null;
+                    try {
+                        fileWriter = new FileWriter(diffOutputfile);
+                        fileWriter.write(output);
+                    } catch(Exception e) {
+                        throw new MojoFailureException(String.format("Failed 
to write diff file: %s", e.getMessage()), e);
+                    } finally {
+                        if(fileWriter != null) {
+                            fileWriter.close();
+                        }
+                    }
+                } catch (IOException e) {
+                    throw new MojoFailureException(String.format("Failed to 
construct output directory: %s", e.getMessage()), e);
+                }
+            }
+        } else {
+            throw new MojoFailureException(String.format("At least one 
required parameter is missing."));
+        }
+    }
+
+    private File resolveArtifact(String descriptor) throws 
MojoFailureException {
+        try {
+            ArtifactRequest request = new ArtifactRequest();
+            request.setArtifact(new DefaultArtifact(descriptor));
+            request.setRepositories(remoteRepos);
+            ArtifactResult result = 
repoSystem.resolveArtifact(newSession(repoSystem), request);
+            File file = result.getArtifact().getFile();
+            getLog().info("Resolved artifact " + result + " to " + file + " 
from " + result.getRepository());
+            return file;
+        } catch (Exception e) {
+            throw new MojoFailureException(String.format("Failed to load 
artifact from repository: %s", e.getMessage()), e);
+        }
+    }
+
+    private static RepositorySystemSession newSession(RepositorySystem system) 
{
+        DefaultRepositorySystemSession session = 
MavenRepositorySystemUtils.newSession();
+        LocalRepository localRepo = new LocalRepository(new 
File(System.getProperty("user.home") + "/.m2/repository"));
+        
session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, 
localRepo));
+        return session;
+    }
+}
diff --git a/japicmp-maven-plugin/src/main/java/japicmp/maven/Version.java 
b/japicmp-maven-plugin/src/main/java/japicmp/maven/Version.java
new file mode 100644
index 0000000..3be2982
--- /dev/null
+++ b/japicmp-maven-plugin/src/main/java/japicmp/maven/Version.java
@@ -0,0 +1,13 @@
+package japicmp.maven;
+
+public class Version {
+    private Dependency dependency;
+
+    public Dependency getDependency() {
+        return dependency;
+    }
+
+    public void setDependency(Dependency dependency) {
+        this.dependency = dependency;
+    }
+}
diff --git a/japicmp-testbase/japicmp-test-maven-plugin/pom.xml 
b/japicmp-testbase/japicmp-test-maven-plugin/pom.xml
new file mode 100644
index 0000000..1cdc6e7
--- /dev/null
+++ b/japicmp-testbase/japicmp-test-maven-plugin/pom.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <parent>
+        <artifactId>japicmp-testbase</artifactId>
+        <groupId>japicmp</groupId>
+        <version>0.0.3-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>japicmp-test-maven-plugin</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>japicmp</groupId>
+            <artifactId>japicmp-maven-plugin</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>japicmp</groupId>
+                <artifactId>japicmp-maven-plugin</artifactId>
+                <version>${project.version}</version>
+                <configuration>
+                    <oldVersion>
+                        <dependency>
+                            <groupId>japicmp</groupId>
+                            <artifactId>japicmp-test-v1</artifactId>
+                            <version>${project.version}</version>
+                        </dependency>
+                    </oldVersion>
+                    <newVersion>
+                        <dependency>
+                            <groupId>japicmp</groupId>
+                            <artifactId>japicmp-test-v2</artifactId>
+                            <version>${project.version}</version>
+                        </dependency>
+                    </newVersion>
+                </configuration>
+                <executions>
+                    <execution>
+                        <phase>verify</phase>
+                        <goals>
+                            <goal>cmp</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
\ No newline at end of file
diff --git a/japicmp-testbase/pom.xml b/japicmp-testbase/pom.xml
index 3ade9b0..e3c9c93 100644
--- a/japicmp-testbase/pom.xml
+++ b/japicmp-testbase/pom.xml
@@ -14,5 +14,6 @@
                <module>japicmp-test-v1</module>
                <module>japicmp-test-v2</module>
                <module>japicmp-test</module>
-       </modules>
+        <module>japicmp-test-maven-plugin</module>
+    </modules>
 </project>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 9406c2b..5c6f160 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
     <modelVersion>4.0.0</modelVersion>
 
     <groupId>japicmp</groupId>
@@ -16,6 +17,7 @@
     <modules>
         <module>japicmp</module>
         <module>japicmp-testbase</module>
+        <module>japicmp-maven-plugin</module>
     </modules>
 
     <dependencies>
@@ -53,6 +55,9 @@
                         <goals>
                             <goal>jar</goal>
                         </goals>
+                        <configuration>
+                            <additionalparam>-Xdoclint:none</additionalparam>
+                        </configuration>
                     </execution>
                 </executions>
             </plugin>

Reply via email to