Skip to content

Commit 435d35c

Browse files
committed
Suppress Roseau output when there are no breaking changes
1 parent 8bbdabc commit 435d35c

File tree

2 files changed

+66
-34
lines changed

2 files changed

+66
-34
lines changed

gradle/plugins/backward-compatibility/src/main/kotlin/junitbuild.backward-compatibility.gradle.kts

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import junitbuild.compatibility.japicmp.AcceptedViolationsPostProcessRule
66
import junitbuild.compatibility.japicmp.BreakingSuperClassChangeRule
77
import junitbuild.compatibility.japicmp.InternalApiFilter
88
import junitbuild.compatibility.japicmp.SourceIncompatibleRule
9+
import junitbuild.compatibility.roseau.RoseauDiff
910
import junitbuild.extensions.dependencyFromLibs
1011
import junitbuild.extensions.javaModuleName
1112
import me.champeau.gradle.japicmp.JapicmpTask
@@ -61,46 +62,18 @@ val downloadPreviousReleaseJar by tasks.registering(Download::class) {
6162

6263
val roseauCsvFile = layout.buildDirectory.file("reports/roseau/breaking-changes.csv")
6364

64-
val roseau by tasks.registering(JavaExec::class) {
65+
val roseau by tasks.registering(RoseauDiff::class) {
6566
if (gradle.startParameter.isOffline) {
6667
enabled = false
6768
}
6869
onlyIf { extension.enabled.get() }
6970
onlyIf("https://github.com/alien-tools/roseau/issues/90") { !OperatingSystem.current().isWindows }
7071

71-
mainClass = "io.github.alien.roseau.cli.RoseauCLI"
72-
classpath = files(roseauClasspath)
73-
74-
inputs.files(configurations.compileClasspath)
75-
.withNormalizer(CompileClasspathNormalizer::class)
76-
.withPropertyName("apiClasspath")
77-
78-
val v1Jar = downloadPreviousReleaseJar.map { it.outputFiles.single() }
79-
inputs.file(v1Jar)
80-
.withNormalizer(CompileClasspathNormalizer::class)
81-
.withPropertyName("v1")
82-
83-
val v2Jar = tasks.jar.flatMap { it.archiveFile }.map { it.asFile }
84-
inputs.file(v2Jar)
85-
.withNormalizer(CompileClasspathNormalizer::class)
86-
.withPropertyName("v2")
87-
88-
outputs.file(roseauCsvFile)
89-
.withPropertyName("report")
90-
91-
argumentProviders.add(CommandLineArgumentProvider {
92-
listOf(
93-
"--classpath", configurations.compileClasspath.get().asPath,
94-
"--v1", v1Jar.get().absolutePath,
95-
"--v2", v2Jar.get().absolutePath,
96-
"--diff",
97-
"--report", roseauCsvFile.get().asFile.absolutePath,
98-
)
99-
})
100-
101-
doFirst {
102-
roseauCsvFile.get().asFile.parentFile.mkdirs()
103-
}
72+
toolClasspath.from(roseauClasspath)
73+
libraryClasspath.from(configurations.compileClasspath)
74+
v1 = downloadPreviousReleaseJar.map { it.outputFiles.single() }
75+
v2 = tasks.jar.flatMap { it.archiveFile }.map { it.asFile }
76+
csvReport = layout.buildDirectory.file("reports/roseau/breaking-changes.csv")
10477
}
10578

10679
val japicmp by tasks.registering(JapicmpTask::class) {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package junitbuild.compatibility.roseau
2+
3+
import org.gradle.api.DefaultTask
4+
import org.gradle.api.file.ConfigurableFileCollection
5+
import org.gradle.api.file.RegularFileProperty
6+
import org.gradle.api.tasks.Classpath
7+
import org.gradle.api.tasks.CompileClasspath
8+
import org.gradle.api.tasks.OutputFile
9+
import org.gradle.api.tasks.TaskAction
10+
import org.gradle.kotlin.dsl.assign
11+
import org.gradle.process.ExecOperations
12+
import java.io.ByteArrayOutputStream
13+
import javax.inject.Inject
14+
15+
abstract class RoseauDiff : DefaultTask() {
16+
17+
@get:Inject
18+
abstract val execOperations: ExecOperations
19+
20+
@get:Classpath
21+
abstract val toolClasspath: ConfigurableFileCollection
22+
23+
@get:CompileClasspath
24+
abstract val libraryClasspath: ConfigurableFileCollection
25+
26+
@get:CompileClasspath
27+
abstract val v1: RegularFileProperty
28+
29+
@get:CompileClasspath
30+
abstract val v2: RegularFileProperty
31+
32+
@get:OutputFile
33+
abstract val csvReport: RegularFileProperty
34+
35+
@TaskAction
36+
fun run() {
37+
csvReport.get().asFile.parentFile.mkdirs()
38+
val output = ByteArrayOutputStream()
39+
val result = execOperations.javaexec {
40+
mainClass = "io.github.alien.roseau.cli.RoseauCLI"
41+
classpath = toolClasspath
42+
args(
43+
"--classpath", libraryClasspath.asPath,
44+
"--v1", v1.get().asFile.absolutePath,
45+
"--v2", v2.get().asFile.absolutePath,
46+
"--diff",
47+
"--report", csvReport.get().asFile.absolutePath,
48+
"--fail",
49+
)
50+
standardOutput = output
51+
errorOutput = output
52+
isIgnoreExitValue = true
53+
}
54+
if (result.exitValue != 0) {
55+
System.out.write(output.toByteArray())
56+
System.out.flush()
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)