Skip to content

Commit

Permalink
#121 maven plugin has new option to skip XML, HTML and diff report, #122
Browse files Browse the repository at this point in the history
 maven-plugin has new option to ignore missing old version, #123 interface moved to abstract class is no longer reported to be source incompatible
  • Loading branch information
siom79 committed Mar 15, 2016
1 parent 40f643b commit 7a1ca75
Show file tree
Hide file tree
Showing 9 changed files with 435 additions and 58 deletions.
40 changes: 40 additions & 0 deletions japicmp-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@
<artifactId>groovy-jsr223</artifactId>
<version>2.4.6</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -125,6 +131,40 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy</id>
<phase>generate-test-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
<destFileName>guava-19.0.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
<destFileName>guava-18.0.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
132 changes: 96 additions & 36 deletions japicmp-maven-plugin/src/main/java/japicmp/maven/JApiCmpMojo.java

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions japicmp-maven-plugin/src/main/java/japicmp/maven/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public class Parameter {
private List<String> packagingSupporteds;
@org.apache.maven.plugins.annotations.Parameter(required = false)
private String postAnalysisScript;
@org.apache.maven.plugins.annotations.Parameter(required = false)
private String skipHtmlReport;
@org.apache.maven.plugins.annotations.Parameter(required = false)
private String skipXmlReport;
@org.apache.maven.plugins.annotations.Parameter(required = false)
private String skipDiffReport;
@org.apache.maven.plugins.annotations.Parameter(required = false)
private String ignoreMissingOldVersion;

public String getNoAnnotations() {
return noAnnotations;
Expand Down Expand Up @@ -171,4 +179,36 @@ public String getPostAnalysisScript() {
public void setPostAnalysisScript(String postAnalysisScript) {
this.postAnalysisScript = postAnalysisScript;
}

public String getSkipHtmlReport() {
return skipHtmlReport;
}

public void setSkipHtmlReport(String skipHtmlReport) {
this.skipHtmlReport = skipHtmlReport;
}

public String getSkipXmlReport() {
return skipXmlReport;
}

public void setSkipXmlReport(String skipXmlReport) {
this.skipXmlReport = skipXmlReport;
}

public String getSkipDiffReport() {
return skipDiffReport;
}

public void setSkipDiffReport(String skipDiffReport) {
this.skipDiffReport = skipDiffReport;
}

public String getIgnoreMissingOldVersion() {
return ignoreMissingOldVersion;
}

public void setIgnoreMissingOldVersion(String ignoreMissingOldVersion) {
this.ignoreMissingOldVersion = ignoreMissingOldVersion;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package japicmp.maven;

import com.google.common.base.Optional;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.junit.Test;
import org.mockito.Matchers;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class JApiCmpMojoTest {

@Test
public void testSimple() throws MojoFailureException {
JApiCmpMojo mojo = new JApiCmpMojo();
Version oldVersion = createVersion("groupId", "artifactId", "0.1.0");
Version newVersion = createVersion("groupId", "artifactId", "0.1.1");
PluginParameters pluginParameters = new PluginParameters(null, newVersion, oldVersion, null, null, Optional.of(Paths.get(System.getProperty("user.dir"), "target", "simple").toFile()), Optional.<String>absent(), true, null, null, null, null);
ArtifactResolver artifactResolver = mock(ArtifactResolver.class);
ArtifactResolutionResult artifactResolutionResult = mock(ArtifactResolutionResult.class);
Set<Artifact> artifactSet = new HashSet<>();
Artifact resolvedArtifact = mock(Artifact.class);
artifactSet.add(resolvedArtifact);
when(resolvedArtifact.getFile()).thenReturn(Paths.get(System.getProperty("user.dir"), "target", "guava-18.0.jar").toFile());
when(artifactResolutionResult.getArtifacts()).thenReturn(artifactSet);
when(artifactResolver.resolve(Matchers.<ArtifactResolutionRequest>anyObject())).thenReturn(artifactResolutionResult);
ArtifactFactory artifactFactory = mock(ArtifactFactory.class);
when(artifactFactory.createArtifactWithClassifier(eq("groupId"), eq("artifactId"), eq("0.1.1"), anyString(), anyString())).thenReturn(mock(Artifact.class));
MavenParameters mavenParameters = new MavenParameters(new ArrayList<ArtifactRepository>(), artifactFactory, mock(ArtifactRepository.class), artifactResolver, mock(MavenProject.class), mock(MojoExecution.class));
mojo.executeWithParameters(pluginParameters, mavenParameters);
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "simple", "japicmp", "japicmp.diff")), is(true));
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "simple", "japicmp", "japicmp.xml")), is(true));
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "simple", "japicmp", "japicmp.html")), is(true));
}

@Test
public void testNoXmlAndNoHtmlReport() throws MojoFailureException {
JApiCmpMojo mojo = new JApiCmpMojo();
Version oldVersion = createVersion("groupId", "artifactId", "0.1.0");
Version newVersion = createVersion("groupId", "artifactId", "0.1.1");
Parameter parameter = new Parameter();
parameter.setSkipHtmlReport("true");
parameter.setSkipXmlReport("true");
PluginParameters pluginParameters = new PluginParameters(null, newVersion, oldVersion, parameter, null, Optional.of(Paths.get(System.getProperty("user.dir"), "target", "noXmlAndNoHtmlReport").toFile()), Optional.<String>absent(), true, null, null, null, null);
ArtifactResolver artifactResolver = mock(ArtifactResolver.class);
ArtifactResolutionResult artifactResolutionResult = mock(ArtifactResolutionResult.class);
Set<Artifact> artifactSet = new HashSet<>();
Artifact resolvedArtifact = mock(Artifact.class);
artifactSet.add(resolvedArtifact);
when(resolvedArtifact.getFile()).thenReturn(Paths.get(System.getProperty("user.dir"), "target", "guava-18.0.jar").toFile());
when(artifactResolutionResult.getArtifacts()).thenReturn(artifactSet);
when(artifactResolver.resolve(Matchers.<ArtifactResolutionRequest>anyObject())).thenReturn(artifactResolutionResult);
ArtifactFactory artifactFactory = mock(ArtifactFactory.class);
when(artifactFactory.createArtifactWithClassifier(eq("groupId"), eq("artifactId"), eq("0.1.1"), anyString(), anyString())).thenReturn(mock(Artifact.class));
MavenParameters mavenParameters = new MavenParameters(new ArrayList<ArtifactRepository>(), artifactFactory, mock(ArtifactRepository.class), artifactResolver, mock(MavenProject.class), mock(MojoExecution.class));
mojo.executeWithParameters(pluginParameters, mavenParameters);
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "noXmlAndNoHtmlReport", "japicmp", "japicmp.diff")), is(true));
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "noXmlAndNoHtmlReport", "japicmp", "japicmp.xml")), is(false));
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "noXmlAndNoHtmlReport", "japicmp", "japicmp.html")), is(false));
}

private Version createVersion(String groupId, String artifactId, String version) {
Version versionInstance = new Version();
Dependency dependency = new Dependency();
dependency.setGroupId(groupId);
dependency.setArtifactId(artifactId);
dependency.setVersion(version);
versionInstance.setDependency(dependency);
return versionInstance;
}
}
71 changes: 69 additions & 2 deletions japicmp-testbase/japicmp-test-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@
<onlyModified>true</onlyModified>
<accessModifier>public</accessModifier>
<breakBuildOnModifications>false</breakBuildOnModifications>
<breakBuildOnBinaryIncompatibleModifications>false
</breakBuildOnBinaryIncompatibleModifications>
<breakBuildOnBinaryIncompatibleModifications>false</breakBuildOnBinaryIncompatibleModifications>
<includeSynthetic>true</includeSynthetic>
</parameter>
<dependencies>
Expand All @@ -113,6 +112,74 @@
</dependencies>
</configuration>
</execution>
<execution>
<id>no-reports</id>
<phase>pre-integration-test</phase>
<goals>
<goal>cmp</goal>
</goals>
<configuration>
<oldVersion>
<dependency>
<groupId>com.github.siom79.japicmp</groupId>
<artifactId>japicmp-test-v1</artifactId>
<version>${project.version}</version>
</dependency>
</oldVersion>
<newVersion>
<dependency>
<groupId>com.github.siom79.japicmp</groupId>
<artifactId>japicmp-test-v2</artifactId>
<version>${project.version}</version>
</dependency>
</newVersion>
<parameter>
<onlyModified>true</onlyModified>
<skipXmlReport>true</skipXmlReport>
<skipHtmlReport>true</skipHtmlReport>
</parameter>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.4</version>
</dependency>
</dependencies>
</configuration>
</execution>
<execution>
<id>old-version-not-resolvable-file</id>
<phase>pre-integration-test</phase>
<goals>
<goal>cmp</goal>
</goals>
<configuration>
<oldVersion>
<dependency>
<groupId>com.github.siom79.japicmp</groupId>
<artifactId>japicmp-non-existing-artifact</artifactId>
<version>${project.version}</version>
</dependency>
</oldVersion>
<newVersion>
<dependency>
<groupId>com.github.siom79.japicmp</groupId>
<artifactId>japicmp-test-v2</artifactId>
<version>${project.version}</version>
</dependency>
</newVersion>
<parameter>
<ignoreMissingOldVersion>true</ignoreMissingOldVersion>
</parameter>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.4</version>
</dependency>
</dependencies>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package japicmp.test;

import org.junit.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class ITNoReports {

@Test
public void testXmlReportNotGenerated() throws IOException {
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "no-reports.html")), is(false));
}

@Test
public void testHtmlReportNotGenerated() throws IOException {
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "no-reports.xml")), is(false));
}

@Test
public void testDiffReportGenerated() throws IOException {
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "no-reports.diff")), is(true));
}
}
10 changes: 9 additions & 1 deletion japicmp/src/main/java/japicmp/model/JApiClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,26 @@ private void computeInterfaceChanges(List<JApiImplementedInterface> interfacesAr

private Map<String, CtClass> buildInterfaceMap(CtClass ctClass, JarArchiveComparator.ArchiveType archiveType) {
Map<String, CtClass> map = new HashMap<>();
buildInterfaceMap(ctClass, archiveType, map);
return map;
}

private void buildInterfaceMap(CtClass ctClass, JarArchiveComparator.ArchiveType archiveType, Map<String, CtClass> map) {
try {
CtClass[] interfaces = ctClass.getInterfaces();
for (CtClass ctInterface : interfaces) {
map.put(ctInterface.getName(), ctInterface);
buildInterfaceMap(archiveType, map, ctInterface);
}
Optional<CtClass> superClassOptional = getSuperclass(ctClass);
if (superClassOptional.isPresent()) {
buildInterfaceMap(superClassOptional.get(), archiveType, map);
}
} catch (NotFoundException e) {
if (!options.isIgnoreMissingClasses()) {
throw JApiCmpException.forClassLoading(e, "Class not found: " + e.getMessage(), jarArchiveComparator);
}
}
return map;
}

private void buildInterfaceMap(JarArchiveComparator.ArchiveType archiveType, Map<String, CtClass> map, CtClass ctInterface) throws NotFoundException {
Expand Down
36 changes: 36 additions & 0 deletions japicmp/src/test/java/japicmp/compat/CompatibilityChangesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,42 @@ public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
assertThat(jApiMethod.isSourceCompatible(), is(true));
}

@Test
public void testInterfaceMovedToAbstractClass() throws Exception {
JarArchiveComparatorOptions options = new JarArchiveComparatorOptions();
options.setIncludeSynthetic(true);
options.setAccessModifier(AccessModifier.PRIVATE);
List<JApiClass> jApiClasses = ClassesHelper.compareClasses(options, new ClassesHelper.ClassesGenerator() {
@Override
public List<CtClass> createOldClasses(ClassPool classPool) throws Exception {
CtClass ctInterface = CtInterfaceBuilder.create().name("Interface").addToClassPool(classPool);
CtMethodBuilder.create().abstractMethod().returnType(CtClass.voidType).name("method").addToClass(ctInterface);
CtClass ctClass = CtClassBuilder.create().name("Test").implementsInterface(ctInterface).addToClassPool(classPool);
CtMethodBuilder.create().returnType(CtClass.voidType).name("method").body("int a = 42;").addToClass(ctClass);
return Arrays.asList(ctInterface, ctClass);
}

@Override
public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
CtClass ctInterface = CtInterfaceBuilder.create().name("Interface").addToClassPool(classPool);
CtMethodBuilder.create().abstractMethod().returnType(CtClass.voidType).name("method").addToClass(ctInterface);
CtClass ctAbstractClass = CtClassBuilder.create().name("AbstractTest").implementsInterface(ctInterface).addToClassPool(classPool);
CtClass ctClass = CtClassBuilder.create().name("Test").withSuperclass(ctAbstractClass).addToClassPool(classPool);
CtMethodBuilder.create().returnType(CtClass.voidType).name("method").body("int a = 42;").addToClass(ctClass);
return Arrays.asList(ctInterface, ctClass, ctAbstractClass);
}
});
JApiClass jApiClass = getJApiClass(jApiClasses, "Test");
assertThat(jApiClass.getChangeStatus(), is(JApiChangeStatus.MODIFIED));
assertThat(jApiClass.isBinaryCompatible(), is(true));
assertThat(jApiClass.isSourceCompatible(), is(true));
assertThat(jApiClass.getInterfaces().size(), is(1));
JApiMethod jApiMethod = getJApiMethod(jApiClass.getMethods(), "method");
assertThat(jApiMethod.getCompatibilityChanges().size(), is(0));
assertThat(jApiMethod.isBinaryCompatible(), is(true));
assertThat(jApiMethod.isSourceCompatible(), is(true));
}

@Test
public void testClassNowCheckedException() throws Exception {
JarArchiveComparatorOptions options = new JarArchiveComparatorOptions();
Expand Down
Loading

0 comments on commit 7a1ca75

Please sign in to comment.