Skip to content

Commit

Permalink
Make the mojo define old & new classpaths automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Jul 28, 2020
1 parent 067bb62 commit bdf3ce2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
35 changes: 29 additions & 6 deletions japicmp-maven-plugin/src/main/java/japicmp/maven/JApiCmpMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ private void populateArchivesListsFromParameters(PluginParameters pluginParamete
throw new MojoFailureException(message);
}
}
getLog().debug("oldArchives=" + oldArchives + " newArchives=" + newArchives);
}

void breakBuildIfNecessary(List<JApiClass> jApiClasses, Parameter parameterParam, Options options, JarArchiveComparator jarArchiveComparator) throws MojoFailureException, MojoExecutionException {
Expand Down Expand Up @@ -657,6 +658,7 @@ private void setUpClassPath(JarArchiveComparatorOptions comparatorOptions, Plugi
"separate classpath for the new and old version.");
} else {
if (getLog().isDebugEnabled()) {
// TODO should perhaps still use TWO_SEPARATE_CLASSPATHS and add dependencies to both?
getLog().debug("Element <dependencies/> found. Using " + JApiCli.ClassPathMode.ONE_COMMON_CLASSPATH);
}
for (Dependency dependency : pluginParameters.getDependenciesParam()) {
Expand Down Expand Up @@ -691,18 +693,41 @@ private void setUpClassPath(JarArchiveComparatorOptions comparatorOptions, Plugi
comparatorOptions.setClassPathMode(JarArchiveComparatorOptions.ClassPathMode.TWO_SEPARATE_CLASSPATHS);
} else {
if (getLog().isDebugEnabled()) {
getLog().debug("None of the elements <oldClassPathDependencies/>, <newClassPathDependencies/> or <dependencies/> found. Using " + JApiCli.ClassPathMode.ONE_COMMON_CLASSPATH);
getLog().debug("None of the elements <oldClassPathDependencies/>, <newClassPathDependencies/> or <dependencies/> found. Using " + JApiCli.ClassPathMode.TWO_SEPARATE_CLASSPATHS);
}
comparatorOptions.setClassPathMode(JarArchiveComparatorOptions.ClassPathMode.ONE_COMMON_CLASSPATH);
comparatorOptions.setClassPathMode(JarArchiveComparatorOptions.ClassPathMode.TWO_SEPARATE_CLASSPATHS);
}
}
}
setUpClassPathUsingMavenProject(comparatorOptions, mavenParameters, pluginParameters, ConfigurationVersion.NEW);
getLog().debug("mode=" + comparatorOptions.getClassPathMode() + " classPathEntries=" + comparatorOptions.getClassPathEntries() + " oldClassPath=" + comparatorOptions.getOldClassPath() + " newClassPath=" + comparatorOptions.getNewClassPath());
}

private void setUpClassPathUsingMavenProject(JarArchiveComparatorOptions comparatorOptions, MavenParameters mavenParameters, PluginParameters pluginParameters, ConfigurationVersion configurationVersion) throws MojoFailureException {
List<String> newClassPath;
if (comparatorOptions.getClassPathMode() == JarArchiveComparatorOptions.ClassPathMode.TWO_SEPARATE_CLASSPATHS) {
if (pluginParameters.getOldVersionParam() == null && pluginParameters.getOldVersionsParam() == null) {
try {
// TODO rather than calling getComparisonArtifact again, populateArchivesListsFromParameters should compute the old CP for various modes
Artifact comparisonArtifact = getComparisonArtifact(mavenParameters, pluginParameters);
if (comparisonArtifact.getVersion() != null) {
Set<Artifact> artifacts = resolveArtifact(comparisonArtifact, mavenParameters, true, pluginParameters, ConfigurationVersion.OLD);
setUpClassPathEntries(artifacts, comparatorOptions.getOldClassPath(), mavenParameters, pluginParameters, configurationVersion);
}
} catch (MojoExecutionException e) {
throw new MojoFailureException("Computing and resolving comparison artifact failed: " + e.getMessage(), e);
}
}
newClassPath = comparatorOptions.getNewClassPath();
} else {
newClassPath = comparatorOptions.getClassPathEntries();
}
notNull(mavenParameters.getMavenProject(), "Maven parameter mavenProject should be provided by maven container.");
Set<Artifact> dependencyArtifacts = mavenParameters.getMavenProject().getArtifacts();
setUpClassPathEntries(dependencyArtifacts, newClassPath, mavenParameters, pluginParameters, configurationVersion);
}

private void setUpClassPathEntries(Set<Artifact> dependencyArtifacts, List<String> classPath, MavenParameters mavenParameters, PluginParameters pluginParameters, ConfigurationVersion configurationVersion) throws MojoFailureException {
Set<String> classPathEntries = new HashSet<>();
for (Artifact artifact : dependencyArtifacts) {
String scope = artifact.getScope();
Expand All @@ -724,10 +749,8 @@ private void setUpClassPathUsingMavenProject(JarArchiveComparatorOptions compara
}
}
}
for (String classPathEntry : classPathEntries) {
comparatorOptions.getClassPathEntries().add(classPathEntry);
}
}
classPath.addAll(classPathEntries);
}

private void handleMissingArtifactFile(PluginParameters pluginParameters, Artifact artifact) {
if (artifact.isOptional()) {
Expand Down
6 changes: 6 additions & 0 deletions japicmp/src/main/java/japicmp/cmp/JApiCmpArchive.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ public File getFile() {
public Version getVersion() {
return version;
}

@Override
public String toString() {
return file + "@" + version.getStringVersion();
}

}

0 comments on commit bdf3ce2

Please sign in to comment.