Skip to content

Commit

Permalink
fix: deprecate methods which will be removed in Gradle v8
Browse files Browse the repository at this point in the history
close #597
  • Loading branch information
KengoTODA committed Oct 28, 2021
1 parent 19c2262 commit 20c594b
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 32 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ to set task-specific properties.
spotbugsMain {
reports {
html {
enabled = true
destination = file("$buildDir/reports/spotbugs/main/spotbugs.html")
required = true
outputLocation = file("$buildDir/reports/spotbugs/main/spotbugs.html")
stylesheet = 'fancy-hist.xsl'
}
}
Expand All @@ -145,8 +145,8 @@ spotbugsMain {
```kotlin
tasks.spotbugsMain {
reports.create("html") {
isEnabled = true
setDestination(file("$buildDir/reports/spotbugs/main/spotbugs.html"))
required.set(true)
outputLocation.set(file("$buildDir/reports/spotbugs.html"))
setStylesheet("fancy-hist.xsl")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CacheabilityFunctionalTest extends Specification {
|}
|spotbugsMain {
| reports {
| text.enabled = true
| text.required = true
| }
|}
|'''.stripMargin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ dependencies {
when:
def result = GradleRunner.create()
.withProjectDir(rootDir)
.withArguments('check', '--info')
.withArguments('check', '--debug', "-Pcom.github.spotbugs.snom.javaexec-in-worker=false")
.withPluginClasspath()
.withGradleVersion(version)
.build()
Expand Down Expand Up @@ -136,12 +136,12 @@ dependencies {
result.output.contains("SpotBugs 4.0.0-beta4") || result.output.contains("spotbugs-4.0.0-beta4.jar")
}

def "can generate spotbugs.html in configured destination"() {
def "can generate spotbugs.html in configured outputLocation"() {
buildFile << """
tasks.spotbugsMain {
reports.create("html") {
isEnabled = true
setDestination(file("\$buildDir/reports/spotbugs.html"))
required.set(true)
outputLocation.set(file("\$buildDir/reports/spotbugs.html"))
setStylesheet("fancy-hist.xsl")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class Foo {
buildFile << """
spotbugsMain {
reports {
text.enabled = true
text.required = true
}
}"""
when:
Expand All @@ -106,7 +106,7 @@ spotbugsMain {
buildFile << """
spotbugsMain {
reports {
text.enabled = true
text.required = true
}
}
buildDir = 'new-build-dir'
Expand All @@ -129,7 +129,7 @@ buildDir = 'new-build-dir'
spotbugsMain {
showStackTraces = false
reports {
text.enabled = true
text.required = true
}
}
buildDir = 'new-build-dir'
Expand Down Expand Up @@ -159,7 +159,7 @@ buildDir = 'new-build-dir'
spotbugsMain {
showStackTraces = false
reports {
html.enabled = true
html.required = true
}
}
buildDir = 'new-build-dir'
Expand All @@ -181,7 +181,7 @@ buildDir = 'new-build-dir'
buildFile << """
spotbugsMain {
reports {
xml.enabled = true
xml.required = true
}
}
buildDir = 'new-build-dir'
Expand All @@ -203,7 +203,7 @@ buildDir = 'new-build-dir'
buildFile << """
spotbugsMain {
reports {
html.enabled = true
html.required = true
}
}"""
when:
Expand Down Expand Up @@ -235,7 +235,7 @@ dependencies { spotbugsStylesheets 'com.github.spotbugs:spotbugs:3.1.10' }
spotbugsMain {
reports {
html {
enabled = true
required = true
stylesheet = resources.text.fromArchiveEntry(configurations.spotbugsStylesheets, 'fancy-hist.xsl')
}
}
Expand Down Expand Up @@ -265,7 +265,7 @@ spotbugsMain {
spotbugsMain {
reports {
html {
enabled = true
required = true
stylesheet = 'fancy-hist.xsl'
}
}
Expand All @@ -289,7 +289,7 @@ spotbugsMain {
buildFile << """
spotbugsMain {
reports {
xml.enabled = true
xml.required = true
}
}"""
when:
Expand Down Expand Up @@ -337,7 +337,7 @@ spotbugsMain {
buildFile << """
spotbugsMain {
reports {
unknown.enabled = true
unknown.required = true
}
}"""
when:
Expand Down Expand Up @@ -434,7 +434,7 @@ configurations.spotbugs {
buildFile << """
spotbugsMain {
reports {
text.enabled = true
text.required = true
}
}
reporting {
Expand All @@ -460,7 +460,7 @@ reporting {
buildFile << """
spotbugsMain {
reports {
sarif.enabled = true
sarif.required = true
}
}"""
when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ spotbugsMain {
buildFile << """
spotbugsMain {
reports {
text.enabled = true
text.required = true
}
}"""
Expand Down Expand Up @@ -423,7 +423,7 @@ sourceSets {
}
spotbugsAnother {
reports {
text.enabled = true
text.required = true
}
}"""
File sourceDir = rootDir.toPath().resolve(Paths.get("src", "another", "java")).toFile()
Expand Down Expand Up @@ -673,7 +673,7 @@ public class SimpleTest {
buildFile << """
spotbugsMain {
reports {
xml.enabled = true
xml.required = true
}
}"""
Expand Down
17 changes: 12 additions & 5 deletions src/main/groovy/com/github/spotbugs/snom/SpotBugsReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.gradle.api.resources.TextResource;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.OutputFile;
import org.gradle.util.ConfigureUtil;

public abstract class SpotBugsReport
Expand All @@ -53,14 +52,14 @@ public SpotBugsReport(ObjectFactory objects, SpotBugsTask task) {
@NonNull
public abstract Optional<String> toCommandLineOption();

/** @deprecated use {@link #getOutputLocation()} instead. */
@Override
@OutputFile
@Deprecated
public File getDestination() {
return destination.get().getAsFile();
}

// @Override // New API from 6.1; see https://github.com/gradle/gradle/issues/11923
@OutputFile
@Override
public RegularFileProperty getOutputLocation() {
return destination;
}
Expand All @@ -71,7 +70,7 @@ public OutputType getOutputType() {
return OutputType.FILE;
}

// @Override // New API from 6.1; see https://github.com/gradle/gradle/issues/11923
@Override
@Input
public Property<Boolean> getRequired() {
return isRequired;
Expand All @@ -98,11 +97,15 @@ public void setEnabled(Provider<Boolean> provider) {
isEnabled.set(provider);
}

/** @deprecated use {@code getOutputLocation().set(file)} instead. */
@Deprecated
@Override
public void setDestination(File file) {
destination.set(file);
}

/** @deprecated use {@code getOutputLocation().set(provider)} instead. */
@Deprecated
@Override
public void setDestination(Provider<File> provider) {
destination.set(this.task.getProject().getLayout().file(provider));
Expand All @@ -127,12 +130,16 @@ public TextResource getStylesheet() {
return null;
}

/** @deprecated use {@code setStylesheetResource(textResource)} instead. */
@Deprecated
@Override
public void setStylesheet(@Nullable TextResource textResource) {
throw new UnsupportedOperationException(
String.format("stylesheet property is not available in the %s type report", getName()));
}

/** @deprecated use {@code setStylesheetPath(path)} instead. */
@Deprecated
public void setStylesheet(@Nullable String path) {
throw new UnsupportedOperationException(
String.format("stylesheet property is not available in the %s type report", getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ abstract class SpotBugsTask extends DefaultTask implements VerificationTask {
@Optional
@Nested
SpotBugsReport getFirstEnabledReport() {
java.util.Optional<SpotBugsReport> report = reports.stream().filter({ report -> report.enabled}).findFirst()
java.util.Optional<SpotBugsReport> report = reports.stream().filter({ report -> report.enabled || report.required}).findFirst()
return report.orElse(null)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.gradle.api.GradleException;
import org.gradle.api.Task;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.RegularFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -72,11 +73,12 @@ protected List<String> buildArguments(SpotBugsTask task) {

SpotBugsReport report = task.getFirstEnabledReport();
if (report != null) {
File dir = report.getDestination().getParentFile();
File outputLocation = report.getOutputLocation().map(RegularFile::getAsFile).get();
File dir = outputLocation.getParentFile();
dir.mkdirs();
report.toCommandLineOption().ifPresent(args::add);
args.add("-outputFile");
args.add(report.getDestination().getAbsolutePath());
args.add(outputLocation.getAbsolutePath());
}

if (task.getEffort().isPresent()) {
Expand Down

0 comments on commit 20c594b

Please sign in to comment.