-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
9 changed files
with
435 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 96 additions & 36 deletions
132
japicmp-maven-plugin/src/main/java/japicmp/maven/JApiCmpMojo.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
japicmp-maven-plugin/src/test/java/japicmp/maven/JApiCmpMojoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
japicmp-testbase/japicmp-test-maven-plugin/src/test/java/japicmp/test/ITNoReports.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.