Skip to content

Commit

Permalink
Add dotOutput property. Resolves #15
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Dec 12, 2021
1 parent 20e50c7 commit 30f2fff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ The following properties can be specified in the `jdeps` task configuration
| sourceSets | jdeps-sourcesets | jdeps.sourcesets | List<String> | ['main']
| multiRelease | jdeps-multi-release | jdeps.multi.release | Integer |
| multiReleaseJars | | jdeps.multi.release.jars | Map<String, String> | [:]
| dotOutput | jdeps-dot-output | jdeps.dot.output | File |
|===

Task properties may be defined on the command line using their option name, or their property name, such as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import groovy.transform.CompileStatic
import org.gradle.api.DefaultTask
import org.gradle.api.JavaVersion
import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.RegularFile
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.provider.ListProperty
Expand All @@ -40,10 +42,12 @@ import org.kordamp.gradle.property.BooleanState
import org.kordamp.gradle.property.IntegerState
import org.kordamp.gradle.property.ListState
import org.kordamp.gradle.property.MapState
import org.kordamp.gradle.property.RegularFileState
import org.kordamp.gradle.property.SimpleBooleanState
import org.kordamp.gradle.property.SimpleIntegerState
import org.kordamp.gradle.property.SimpleListState
import org.kordamp.gradle.property.SimpleMapState
import org.kordamp.gradle.property.SimpleRegularFileState
import org.kordamp.gradle.util.PluginUtils
import org.zeroturnaround.exec.ProcessExecutor

Expand All @@ -70,6 +74,7 @@ class JDepsReportTask extends DefaultTask {
private final ListState sourceSets
private final IntegerState multiRelease
private final MapState multiReleaseJars
private final RegularFileState dotOutput

private Object reportDir

Expand All @@ -92,6 +97,7 @@ class JDepsReportTask extends DefaultTask {
multiRelease = SimpleIntegerState.of(this, 'jdeps.multi.release', -1)

multiReleaseJars = SimpleMapState.of(this, 'jdeps.multi.release.jars', [:])
dotOutput = SimpleRegularFileState.of(this, 'jdeps.dot.output', (RegularFile) null)
}

@Option(option = 'jdeps-verbose', description = 'Print all class level dependences')
Expand Down Expand Up @@ -130,6 +136,9 @@ class JDepsReportTask extends DefaultTask {
@Option(option = 'jdeps-multi-release', description = 'Set the multi-release level')
void setMultiRelease(String value) { multiRelease.property.set(Integer.valueOf(value)) }

@Option(option = 'jdeps-dot-output', description = 'Destination directory for DOT file output')
void setDotOutput(String value) { dotOutput.property.set(project.file(value)) }

@Internal
Property<Boolean> getVerbose() { verbose.property }

Expand Down Expand Up @@ -212,6 +221,13 @@ class JDepsReportTask extends DefaultTask {
@Optional
Provider<Map<String, String>> getResolvedMultiReleaseJars() { multiReleaseJars.provider }

@Internal
RegularFileProperty getDotOutput() { dotOutput.property }

@Input
@Optional
Provider<RegularFile> getResolvedDotOutput() { dotOutput.provider }

@TaskAction
void evaluate() {
ModuleOptions moduleOptions = extensions.getByType(ModuleOptions)
Expand All @@ -227,6 +243,10 @@ class JDepsReportTask extends DefaultTask {
if (resolvedRecursive.get()) baseCmd << '-R'
if (resolvedJdkinternals.get()) baseCmd << '-jdkinternals'
if (resolvedApionly.get()) baseCmd << '-apionly'
if (getResolvedDotOutput().present) {
baseCmd << '-dotoutput'
baseCmd << getResolvedDotOutput().get().asFile.absolutePath
}

if (JavaVersion.current().java9Compatible) {
if (resolvedMultiRelease.get() > -1) {
Expand Down Expand Up @@ -277,7 +297,7 @@ class JDepsReportTask extends DefaultTask {
}

List<String> warnings = getWarnings(output)
if (warnings && failOnWarning.getOrElse(false)) {
if (warnings && getResolvedFailOnWarning().get()) {
throw new IllegalStateException("jdeps reported errors/warnings: " +
System.lineSeparator() +
warnings.join(System.lineSeparator()))
Expand Down Expand Up @@ -349,7 +369,7 @@ class JDepsReportTask extends DefaultTask {
}

List<String> warnings = getWarnings(output)
if (warnings && failOnWarning.getOrElse(false)) {
if (warnings && getResolvedFailOnWarning().get()) {
throw new IllegalStateException("jdeps reported errors/warnings: " +
System.lineSeparator() +
warnings.join(System.lineSeparator()))
Expand Down

0 comments on commit 30f2fff

Please sign in to comment.