diff --git a/japicmp-maven-plugin/src/main/java/japicmp/maven/JApiCmpMojo.java b/japicmp-maven-plugin/src/main/java/japicmp/maven/JApiCmpMojo.java index 7cd5ad1de..39f21e3b0 100644 --- a/japicmp-maven-plugin/src/main/java/japicmp/maven/JApiCmpMojo.java +++ b/japicmp-maven-plugin/src/main/java/japicmp/maven/JApiCmpMojo.java @@ -411,6 +411,7 @@ private void populateArchivesListsFromParameters(PluginParameters pluginParamete throw new MojoFailureException(message); } } + getLog().debug("oldArchives=" + oldArchives + " newArchives=" + newArchives); } void breakBuildIfNecessary(List jApiClasses, Parameter parameterParam, Options options, JarArchiveComparator jarArchiveComparator) throws MojoFailureException, MojoExecutionException { @@ -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 found. Using " + JApiCli.ClassPathMode.ONE_COMMON_CLASSPATH); } for (Dependency dependency : pluginParameters.getDependenciesParam()) { @@ -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 , or found. Using " + JApiCli.ClassPathMode.ONE_COMMON_CLASSPATH); + getLog().debug("None of the elements , or 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 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 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 dependencyArtifacts = mavenParameters.getMavenProject().getArtifacts(); + setUpClassPathEntries(dependencyArtifacts, newClassPath, mavenParameters, pluginParameters, configurationVersion); + } + + private void setUpClassPathEntries(Set dependencyArtifacts, List classPath, MavenParameters mavenParameters, PluginParameters pluginParameters, ConfigurationVersion configurationVersion) throws MojoFailureException { Set classPathEntries = new HashSet<>(); for (Artifact artifact : dependencyArtifacts) { String scope = artifact.getScope(); @@ -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()) { diff --git a/japicmp/src/main/java/japicmp/cmp/JApiCmpArchive.java b/japicmp/src/main/java/japicmp/cmp/JApiCmpArchive.java index 5821058b1..ff13da264 100644 --- a/japicmp/src/main/java/japicmp/cmp/JApiCmpArchive.java +++ b/japicmp/src/main/java/japicmp/cmp/JApiCmpArchive.java @@ -20,4 +20,10 @@ public File getFile() { public Version getVersion() { return version; } + + @Override + public String toString() { + return file + "@" + version.getStringVersion(); + } + }