Skip to content

Commit

Permalink
Infer archive versions via addOldArchives() and addNewArchives()
Browse files Browse the repository at this point in the history
  • Loading branch information
guillermocalvo authored and melix committed Nov 7, 2024
1 parent 63c0418 commit 25c7855
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
34 changes: 32 additions & 2 deletions src/main/java/me/champeau/gradle/japicmp/JapicmpTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,14 @@ public JapicmpTask() {
public void exec() {
ConfigurableFileCollection oldArchives = getOldArchives();
ConfigurableFileCollection newArchives = getNewArchives();
List<JApiCmpWorkerAction.Archive> baseline = !oldArchives.isEmpty() ? toArchives(oldArchives) : inferArchives(getOldClasspath());
List<JApiCmpWorkerAction.Archive> current = !newArchives.isEmpty() ? toArchives(newArchives) : inferArchives(getNewClasspath());
List<JApiCmpWorkerAction.Archive> baseline = getOldArchiveList().getOrElse(Collections.emptyList());
List<JApiCmpWorkerAction.Archive> current = getNewArchiveList().getOrElse(Collections.emptyList());
if (baseline.isEmpty()) {
baseline = !oldArchives.isEmpty() ? toArchives(oldArchives) : inferArchives(getOldClasspath());
}
if (current.isEmpty()) {
current = !newArchives.isEmpty() ? toArchives(newArchives) : inferArchives(getNewClasspath());
}
execForNewGradle(baseline, current);
}

Expand Down Expand Up @@ -297,6 +303,30 @@ public void addExcludeFilter(Class<? extends Filter> excludeFilterClass) {
getExcludeFilters().add(new FilterConfiguration(excludeFilterClass));
}

@Input
@Optional
public abstract ListProperty<JApiCmpWorkerAction.Archive> getOldArchiveList();

public void addOldArchives(Configuration config) {
List<JApiCmpWorkerAction.Archive> oldArchives = new ArrayList<>();
for (ResolvedDependency resolvedDependency : config.getResolvedConfiguration().getFirstLevelModuleDependencies()) {
collectArchives(oldArchives, resolvedDependency);
}
getOldArchiveList().addAll(oldArchives);
}

@Input
@Optional
public abstract ListProperty<JApiCmpWorkerAction.Archive> getNewArchiveList();

public void addNewArchives(Configuration config) {
List<JApiCmpWorkerAction.Archive> newArchives = new ArrayList<>();
for (ResolvedDependency resolvedDependency : config.getResolvedConfiguration().getFirstLevelModuleDependencies()) {
collectArchives(newArchives, resolvedDependency);
}
getNewArchiveList().addAll(newArchives);
}

@Input
@Optional
public abstract ListProperty<String> getCompatibilityChangeExcludes();
Expand Down
33 changes: 28 additions & 5 deletions src/test/groovy/me/champeau/gradle/ReportsFunctionalTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class ReportsFunctionalTest extends BaseFunctionalTest {
result.task(":japicmp").outcome == TaskOutcome.UP_TO_DATE
}

def "can generate an XML report"() {
def "can generate an XML report without versions"() {
when:
def result = run 'japicmpXml'
def result = run 'japicmpXmlWithoutVersions'

then:
result.task(":japicmpXml").outcome == TaskOutcome.SUCCESS
result.task(":japicmpXmlWithoutVersions").outcome == TaskOutcome.SUCCESS
hasXmlReport('oldJar="commons-lang3-3.5.jar"')
hasXmlReport('newJar="commons-lang3-3.6.jar"')
hasXmlReport('oldVersion="unknown version"')
Expand All @@ -52,10 +52,33 @@ class ReportsFunctionalTest extends BaseFunctionalTest {
noRichReport()

when:
result = run 'japicmpXml'
result = run 'japicmpXmlWithoutVersions'

then:
result.task(":japicmpXml").outcome == TaskOutcome.UP_TO_DATE
result.task(":japicmpXmlWithoutVersions").outcome == TaskOutcome.UP_TO_DATE
}

def "can generate an XML report with versions"() {
when:
def result = run 'japicmpXmlWithVersions'

then:
result.task(":japicmpXmlWithVersions").outcome == TaskOutcome.SUCCESS
hasXmlReport('oldJar="commons-lang3-3.5.jar"')
hasXmlReport('newJar="commons-lang3-3.6.jar"')
hasXmlReport('oldVersion="3.5"')
hasXmlReport('newVersion="3.6"')
noTxtReport()
noMarkdownReport()
noSemverReport()
noHtmlReport()
noRichReport()

when:
result = run 'japicmpXmlWithVersions'

then:
result.task(":japicmpXmlWithVersions").outcome == TaskOutcome.UP_TO_DATE
}

def "can generate rich report"() {
Expand Down
8 changes: 7 additions & 1 deletion src/test/test-projects/html-report/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ task japicmpSemver(type: me.champeau.gradle.japicmp.JapicmpTask) {
semverOutputFile = layout.buildDirectory.file('reports/japi.semver').get().asFile
}

task japicmpXml(type: me.champeau.gradle.japicmp.JapicmpTask) {
task japicmpXmlWithoutVersions(type: me.champeau.gradle.japicmp.JapicmpTask) {
oldClasspath.from(configurations.baseline)
newClasspath.from(configurations.current)
xmlOutputFile = layout.buildDirectory.file('reports/japi.xml').get().asFile
}

task japicmpXmlWithVersions(type: me.champeau.gradle.japicmp.JapicmpTask) {
addOldArchives(configurations.baseline)
addNewArchives(configurations.current)
xmlOutputFile = layout.buildDirectory.file('reports/japi.xml').get().asFile
}

0 comments on commit 25c7855

Please sign in to comment.