Skip to content

Commit d837871

Browse files
committed
If there are no explicit dependencies, behave sensibly
1 parent 965f0a5 commit d837871

File tree

2 files changed

+47
-25
lines changed
  • japicmp-maven-plugin/src/main/java/japicmp/maven
  • japicmp-testbase/japicmp-test-service-impl-base/japicmp-test-service-test

2 files changed

+47
-25
lines changed

japicmp-maven-plugin/src/main/java/japicmp/maven/JApiCmpMojo.java

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ private String createFilename(MavenParameters mavenParameters) {
598598
return sb.toString();
599599
}
600600

601-
private void setUpClassPath(JarArchiveComparatorOptions comparatorOptions, PluginParameters pluginParameters, MavenParameters mavenParameters) throws MojoFailureException {
601+
private void setUpClassPath(JarArchiveComparatorOptions comparatorOptions, PluginParameters pluginParameters, MavenParameters mavenParameters) throws MojoFailureException, MojoExecutionException {
602602
if (pluginParameters != null) {
603603
if (pluginParameters.getDependenciesParam() != null) {
604604
if (pluginParameters.getOldClassPathDependencies() != null || pluginParameters.getNewClassPathDependencies() != null) {
@@ -641,23 +641,59 @@ private void setUpClassPath(JarArchiveComparatorOptions comparatorOptions, Plugi
641641
comparatorOptions.setClassPathMode(JarArchiveComparatorOptions.ClassPathMode.TWO_SEPARATE_CLASSPATHS);
642642
} else {
643643
if (getLog().isDebugEnabled()) {
644-
getLog().debug("None of the elements <oldClassPathDependencies/>, <newClassPathDependencies/> or <dependencies/> found. Using " + JApiCli.ClassPathMode.ONE_COMMON_CLASSPATH);
644+
getLog().debug("None of the elements <oldClassPathDependencies/>, <newClassPathDependencies/> or <dependencies/> found. Using " + JarArchiveComparatorOptions.ClassPathMode.TWO_SEPARATE_CLASSPATHS);
645645
}
646-
comparatorOptions.setClassPathMode(JarArchiveComparatorOptions.ClassPathMode.ONE_COMMON_CLASSPATH);
646+
comparatorOptions.setClassPathMode(JarArchiveComparatorOptions.ClassPathMode.TWO_SEPARATE_CLASSPATHS);
647647
}
648648
}
649649
}
650650
setUpClassPathUsingMavenProject(comparatorOptions, mavenParameters, pluginParameters, ConfigurationVersion.NEW);
651651
}
652652

653-
private void setUpClassPathUsingMavenProject(JarArchiveComparatorOptions comparatorOptions, MavenParameters mavenParameters, PluginParameters pluginParameters, ConfigurationVersion configurationVersion) throws MojoFailureException {
654-
MavenProject mavenProject = mavenParameters.getMavenProject();
655-
notNull(mavenProject, "Maven parameter mavenProject should be provided by maven container.");
653+
private void setUpClassPathUsingMavenProject(JarArchiveComparatorOptions comparatorOptions, MavenParameters mavenParameters, PluginParameters pluginParameters, ConfigurationVersion configurationVersion) throws MojoFailureException, MojoExecutionException {
654+
if (comparatorOptions.getClassPathMode() == JarArchiveComparatorOptions.ClassPathMode.TWO_SEPARATE_CLASSPATHS) {
655+
if (pluginParameters.getOldVersionParam() != null) {
656+
Dependency dependency = pluginParameters.getOldVersionParam().getDependency();
657+
if (dependency != null) {
658+
Set<Artifact> comparisonArtifacts = resolveArtifact(dependency, mavenParameters, false, pluginParameters, ConfigurationVersion.OLD);
659+
if (!comparisonArtifacts.isEmpty()) {
660+
setUpClassPathEntries(comparisonArtifacts.iterator().next(), mavenParameters, pluginParameters, comparatorOptions.getOldClassPath());
661+
}
662+
}
663+
} else if (pluginParameters.getOldVersionsParam() != null) {
664+
// TODO
665+
} else {
666+
// TODO rather than calling getComparisonArtifact again, populateArchivesListsFromParameters should compute the old CP for various modes
667+
Artifact comparisonArtifact = getComparisonArtifact(mavenParameters, pluginParameters, ConfigurationVersion.OLD);
668+
if (comparisonArtifact.getVersion() != null) {
669+
setUpClassPathEntries(comparisonArtifact, mavenParameters, pluginParameters, comparatorOptions.getOldClassPath());
670+
}
671+
}
672+
}
673+
if (pluginParameters.getNewVersionParam() != null) {
674+
Dependency dependency = pluginParameters.getNewVersionParam().getDependency();
675+
if (dependency != null) {
676+
Set<Artifact> comparisonArtifacts = resolveArtifact(dependency, mavenParameters, false, pluginParameters, ConfigurationVersion.NEW);
677+
if (!comparisonArtifacts.isEmpty()) {
678+
setUpClassPathEntries(comparisonArtifacts.iterator().next(), mavenParameters, pluginParameters, comparatorOptions.getNewClassPath());
679+
}
680+
}
681+
} else if (pluginParameters.getNewVersionsParam() != null) {
682+
// TODO
683+
} else {
684+
MavenProject mavenProject = mavenParameters.getMavenProject();
685+
notNull(mavenProject, "Maven parameter mavenProject should be provided by maven container.");
686+
String packaging = mavenProject.getPackaging();
687+
packaging = mapPackaging(packaging, "bundle".equalsIgnoreCase(packaging), "jar");
688+
DefaultArtifact artifact = new DefaultArtifact(mavenProject.getGroupId(), mavenProject.getArtifactId(), packaging, mavenProject.getVersion());
689+
setUpClassPathEntries(artifact, mavenParameters, pluginParameters, comparatorOptions.getClassPathEntries());
690+
}
691+
}
692+
693+
private void setUpClassPathEntries(Artifact comparisonArtifact, MavenParameters mavenParameters, PluginParameters pluginParameters, List<String> classPath) throws MojoFailureException {
694+
getLog().debug("setting up classpath entries for " + comparisonArtifact);
656695
CollectRequest request = new CollectRequest();
657-
String packaging = mavenProject.getPackaging();
658-
packaging = mapPackaging(packaging, "bundle".equalsIgnoreCase(packaging), "jar");
659-
DefaultArtifact defaultArtifact = new DefaultArtifact(mavenProject.getGroupId(), mavenProject.getArtifactId(), packaging, mavenProject.getVersion());
660-
request.setRoot(new org.eclipse.aether.graph.Dependency(defaultArtifact, "compile"));
696+
request.setRoot(new org.eclipse.aether.graph.Dependency(comparisonArtifact, "compile"));
661697
try {
662698
DependencyResult dependencyResult = mavenParameters.getRepoSystem().resolveDependencies(mavenParameters.getRepoSession(), new DependencyRequest(
663699
request, new DependencyFilter() {
@@ -683,7 +719,7 @@ public boolean accept(final DependencyNode node, final List<DependencyNode> pare
683719
}
684720
}
685721
for (String classPathEntry : classPathEntries) {
686-
comparatorOptions.getClassPathEntries().add(classPathEntry);
722+
classPath.add(classPathEntry);
687723
}
688724
} catch (final DependencyResolutionException e) {
689725
throw new MojoFailureException(e.getMessage(), e);

japicmp-testbase/japicmp-test-service-impl-base/japicmp-test-service-test/pom.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,6 @@
9494
<version>${project.version}</version>
9595
</dependency>
9696
</newVersion>
97-
<oldClassPathDependencies>
98-
<dependency>
99-
<groupId>com.github.siom79.japicmp</groupId>
100-
<artifactId>japicmp-test-service-v1</artifactId>
101-
<version>${project.version}</version>
102-
</dependency>
103-
</oldClassPathDependencies>
104-
<newClassPathDependencies>
105-
<dependency>
106-
<groupId>com.github.siom79.japicmp</groupId>
107-
<artifactId>japicmp-test-service-v2</artifactId>
108-
<version>${project.version}</version>
109-
</dependency>
110-
</newClassPathDependencies>
11197
<parameter>
11298
<accessModifier>public</accessModifier>
11399
<onlyModified>true</onlyModified>

0 commit comments

Comments
 (0)