Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix archive versions #80

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions src/main/java/me/champeau/gradle/japicmp/JapicmpTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,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 @@ -204,7 +210,7 @@ private static List<JApiCmpWorkerAction.Archive> toArchives(FileCollection fc) {
Set<File> files = fc.getFiles();
List<JApiCmpWorkerAction.Archive> archives = new ArrayList<>(files.size());
for (File file : files) {
archives.add(new JApiCmpWorkerAction.Archive(file, "1.0"));
archives.add(new JApiCmpWorkerAction.Archive(file, "unknown version"));
}
return archives;
}
Expand Down Expand Up @@ -287,6 +293,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
8 changes: 8 additions & 0 deletions src/test/groovy/me/champeau/gradle/BaseFunctionalTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ abstract class BaseFunctionalTest extends Specification {
hasReport('japi', 'html', lookup)
}

void hasXmlReport(String lookup = '') {
hasReport('japi', 'xml', lookup)
}

void hasRichReport(String lookup = '') {
hasReport('rich', 'html', lookup)
}
Expand All @@ -88,6 +92,10 @@ abstract class BaseFunctionalTest extends Specification {
assert !getReport('japi', 'html').exists()
}

void noXmlReport() {
assert !getReport('japi', 'xml').exists()
}

void noRichReport() {
assert !getReport('rich', 'html').exists()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class BomFunctionalTest extends BaseFunctionalTest {
hasTextReport('CLASS FILE FORMAT VERSION: 50.0 <- 50.0')
noSemverReport()
noHtmlReport()
noXmlReport()
noMarkdownReport()
noRichReport()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ClasspathIsUsedFunctionalTest extends BaseFunctionalTest {
noSemverReport()
noMarkdownReport()
noHtmlReport()
noXmlReport()
noRichReport()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Compare2JarsFunctionalTest extends BaseFunctionalTest {
noSemverReport()
noMarkdownReport()
noHtmlReport()
noXmlReport()
noRichReport()

when:
Expand All @@ -36,6 +37,7 @@ class Compare2JarsFunctionalTest extends BaseFunctionalTest {
noSemverReport()
noMarkdownReport()
noHtmlReport()
noXmlReport()
noRichReport()

when:
Expand Down
51 changes: 51 additions & 0 deletions src/test/groovy/me/champeau/gradle/ReportsFunctionalTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ReportsFunctionalTest extends BaseFunctionalTest {
noTxtReport()
noMarkdownReport()
noSemverReport()
noXmlReport()
noRichReport()

when:
Expand All @@ -34,6 +35,52 @@ class ReportsFunctionalTest extends BaseFunctionalTest {
result.task(":japicmp").outcome == TaskOutcome.UP_TO_DATE
}

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

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

when:
result = run 'japicmpXmlWithoutVersions'

then:
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"() {
when:
def result = run 'japicmpRich'
Expand All @@ -46,6 +93,7 @@ class ReportsFunctionalTest extends BaseFunctionalTest {
noMarkdownReport()
noSemverReport()
noHtmlReport()
noXmlReport()

when:
result = run 'japicmpRich'
Expand All @@ -64,6 +112,7 @@ class ReportsFunctionalTest extends BaseFunctionalTest {
noTxtReport()
noMarkdownReport()
noHtmlReport()
noXmlReport()
noRichReport()

when:
Expand All @@ -84,6 +133,7 @@ class ReportsFunctionalTest extends BaseFunctionalTest {
noTxtReport()
noSemverReport()
noHtmlReport()
noXmlReport()
noRichReport()

when:
Expand All @@ -104,6 +154,7 @@ class ReportsFunctionalTest extends BaseFunctionalTest {
noTxtReport()
noSemverReport()
noHtmlReport()
noXmlReport()
noRichReport()

when:
Expand Down
12 changes: 12 additions & 0 deletions src/test/test-projects/html-report/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,15 @@ task japicmpSemver(type: me.champeau.gradle.japicmp.JapicmpTask) {
newClasspath.from(configurations.current)
semverOutputFile = layout.buildDirectory.file('reports/japi.semver').get().asFile
}

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
}