Skip to content

Commit

Permalink
drop gradle 5 and 6 support,
Browse files Browse the repository at this point in the history
upgrade to spotbugs gradle plugin 5.2.5 (#94),
remove spotbugsShowStackTraces (not used by plugin anymore),
remove custom spotbugs xsl file usage for html report generation (use native html report instead)
  • Loading branch information
xvik committed Jan 25, 2024
1 parent bcf5257 commit 6a2d79a
Show file tree
Hide file tree
Showing 26 changed files with 70 additions and 242 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* (BREAKING) Drop gradle 5 and 6 support
* Update spotbugs plugin to 5.2.5 (#94)
- Remove spotbugsShowStackTraces option because it's not used by spotbugs anymore
- Custom xsl file not used for html report - native html report generation used instead

### 4.9.0 (2023-02-18)
* Gradle 8 support (#77)
* Update checkstyle 10.3.1 -> 10.6.0
Expand Down
10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ plugins {
id 'ru.vyarus.mkdocs' version '3.0.0'
}

sourceCompatibility = 1.8
java {
sourceCompatibility = 1.8
}

wrapper {
gradleVersion = '8.5'
Expand All @@ -23,15 +25,15 @@ wrapper {
ext {
animalsnifferVersion = '1.7.1'
cpdVersion = '3.3'
spotbugsPluginVersion = '4.8.0'
spotbugsPluginVersion = '5.2.5'
docVersion = '4.9.0'
}

repositories { mavenLocal(); mavenCentral(); gradlePluginPortal() }
dependencies {
implementation "com.github.spotbugs.snom:spotbugs-gradle-plugin:$spotbugsPluginVersion"

testImplementation('org.spockframework:spock-core:2.0-groovy-2.5') {
testImplementation('org.spockframework:spock-core:2.3-groovy-3.0') {
exclude group: 'org.codehaus.groovy'
}
testImplementation "ru.vyarus:gradle-animalsniffer-plugin:$animalsnifferVersion"
Expand Down Expand Up @@ -85,7 +87,7 @@ nexusPublishing {
}

// skip signing for jitpack (snapshots)
tasks.withType(Sign) {onlyIf { !System.getenv('JITPACK') }}
tasks.withType(Sign).configureEach { onlyIf { !System.getenv('JITPACK') } }

// Required signing properties for release: signing.keyId, signing.password and signing.secretKeyRingFile
// (https://docs.gradle.org/current/userguide/signing_plugin.html#sec:signatory_credentials)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class ConfigLoader {
private final String pmd = 'pmd/pmd.xml'
private final String cpdXsl = 'cpd/cpdhtml.xslt'
private final String spotbugsExclude = 'spotbugs/exclude.xml'
private final String spotbugsXsl = 'spotbugs/html-report-style.xsl'
private final String codenarc = 'codenarc/codenarc.xml'

Project project
Expand Down Expand Up @@ -56,10 +55,6 @@ class ConfigLoader {
resolve(spotbugsExclude, copyDefaultFile)
}

File resolveSpotbugsXsl(boolean copyDefaultFile = true) {
resolve(spotbugsXsl, copyDefaultFile)
}

File resolveCodenarcConfig(boolean copyDefaultFile = true) {
resolve(codenarc, copyDefaultFile)
}
Expand All @@ -71,7 +66,7 @@ class ConfigLoader {
*/
void initUserConfigs(boolean override) {
init()
[checkstyle, checkstyleSuppressions, pmd, cpdXsl, codenarc, spotbugsExclude, spotbugsXsl].each {
[checkstyle, checkstyleSuppressions, pmd, cpdXsl, codenarc, spotbugsExclude].each {
copyConfig(configDir, it, override)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@ class QualityExtension {
*/
boolean cpdUnifySources = true

/**
* Shortcut for {@code spotbugs.showStackTraces}. Original spotbugs property is enabled by default, causing
* not pretty exception logs in non strict mode (when not fails on errors). This option was introduced to change
* the default to false and not show that nasty stacktrace, but still provide an easy way to revert default back.
*/
boolean spotbugsShowStackTraces = false

/**
* The analysis effort level. The value specified should be one of min, default, or max.
* Higher levels increase precision and find more bugs at the expense of running time and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ import org.gradle.api.execution.TaskExecutionGraph
import org.gradle.api.plugins.GroovyPlugin
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.quality.*
import org.gradle.api.reporting.Report
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceTask
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.TaskState
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.process.CommandLineArgumentProvider
import org.gradle.util.GradleVersion
import ru.vyarus.gradle.plugin.quality.report.*
import ru.vyarus.gradle.plugin.quality.spotbugs.CustomSpotBugsPlugin
import ru.vyarus.gradle.plugin.quality.task.InitQualityConfigTask
Expand Down Expand Up @@ -158,22 +156,15 @@ class QualityPlugin implements Plugin<Project> {

tasks.withType(Checkstyle).configureEach {
doFirst {
if (GradleVersion.current() < GradleVersion.version('6.0')) {
// required for gradle < 6 because it will not set config_loc if target dir does not exists
// https://github.com/gradle/gradle/issues/11058
String propName = 'config_loc'
configProperties[propName] = configProperties[propName]
?: configLoader.resolveCheckstyleConfigDir().absolutePath
}
if (extension.checkstyleBackport) {
project.logger.warn("WARNING: checkstyle-backport-jre8 (${extension.checkstyleVersion})" +
' used instead of regular checkstyle: https://checkstyle.org/#Backport')
}
configLoader.resolveCheckstyleConfig()
applyExcludes(it, extension)
}
enableReport(reports.xml)
enableReport(reports.html, extension.htmlReports)
reports.xml.required.set(true)
reports.html.required.set(extension.htmlReports)
}
}
configurePluginTasks(project, extension, Checkstyle, 'checkstyle', new CheckstyleReporter(configLoader))
Expand Down Expand Up @@ -209,8 +200,8 @@ class QualityPlugin implements Plugin<Project> {
configLoader.resolvePmdConfig()
applyExcludes(it, extension)
}
enableReport(reports.xml)
enableReport(reports.html, extension.htmlReports)
reports.xml.required.set(true)
reports.html.required.set(extension.htmlReports)
}
}
configurePluginTasks(project, extension, Pmd, 'pmd', new PmdReporter())
Expand All @@ -231,8 +222,6 @@ class QualityPlugin implements Plugin<Project> {
spotbugs {
toolVersion = extension.spotbugsVersion
ignoreFailures = !extension.strict
// when enabled show an additional stacktrace in non strict mode (plugin default changed)
showStackTraces = extension.spotbugsShowStackTraces
effort = extension.spotbugsEffort
reportLevel = extension.spotbugsLevel

Expand Down Expand Up @@ -261,7 +250,10 @@ class QualityPlugin implements Plugin<Project> {
)))
reports {
xml {
enableReport(it)
required.set(true)
}
html {
required.set(extension.htmlReports)
}
}
}
Expand Down Expand Up @@ -296,8 +288,8 @@ class QualityPlugin implements Plugin<Project> {
configLoader.resolveCodenarcConfig()
applyExcludes(it, extension)
}
enableReport(reports.xml)
enableReport(reports.html, extension.htmlReports)
reports.xml.required.set(true)
reports.html.required.set(extension.htmlReports)
}
}
configurePluginTasks(project, extension, CodeNarc, 'codenarc', new CodeNarcReporter())
Expand Down Expand Up @@ -370,7 +362,7 @@ class QualityPlugin implements Plugin<Project> {
Class<Task> cpdTasksType = plugin.class.classLoader.loadClass('de.aaschmid.gradle.plugins.cpd.Cpd')
// reports applied for all registered cpd tasks
prj.tasks.withType(cpdTasksType).configureEach { task ->
enableReport(reports.xml)
reports.xml.required.set(true)
doFirst {
configLoader.resolveCpdXsl()
}
Expand All @@ -390,14 +382,6 @@ class QualityPlugin implements Plugin<Project> {
}
}

private void enableReport(Report report, boolean enable = true) {
if (GradleVersion.current() < GradleVersion.version('7.0')) {
report.enabled = enable
} else {
report.required.set(enable)
}
}

private void applyReporter(Project project, String type, Reporter reporter,
boolean consoleReport, boolean htmlReport) {
boolean generatesHtmlReport = htmlReport && HtmlReportGenerator.isAssignableFrom(reporter.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.gradle.api.Project
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.reporting.Report
import org.gradle.api.tasks.SourceSet
import org.gradle.util.GradleVersion

/**
* Reporting utils.
Expand Down Expand Up @@ -112,9 +111,6 @@ class ReportUtils {
if (report == null) {
return null
}
if (GradleVersion.current() < GradleVersion.version('7.0')) {
return report.destination
}
// Provider for gradle 7 and Property for gradle 8
// static compilation must be disabled for method!
Object output = report.outputLocation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import ru.vyarus.gradle.plugin.quality.util.FileUtils

/**
* Prints spotbugs errors (from xml report) into console and generates html report using custom xsl.
* Gradle spotbugs plugin support html report generation too, but it can't generate both xml and html at the same
* time (so we have to generate html separately, because xml report is required for console reporting).
*
* @author Vyacheslav Rusakov
* @since 28.01.2018
*/
@CompileStatic
class SpotbugsReporter implements Reporter<SpotBugsTask>, HtmlReportGenerator<SpotBugsTask> {
private static final String XML = 'XML'
class SpotbugsReporter implements Reporter<SpotBugsTask> {
private static final String XML = 'xml'

ConfigLoader configLoader

Expand Down Expand Up @@ -70,26 +68,6 @@ class SpotbugsReporter implements Reporter<SpotBugsTask>, HtmlReportGenerator<Sp
}
}

@Override
@CompileStatic(TypeCheckingMode.SKIP)
void generateHtmlReport(SpotBugsTask task, String type) {
File reportFile = ReportUtils.getReportFile(task.reports.findByName(XML))
if (reportFile == null || !reportFile.exists()) {
return
}
Project project = task.project
// html report
String htmlReportPath = "${project.extensions.spotbugs.reportsDir.get()}/${type}.html"
File htmlReportFile = project.file(htmlReportPath)
// avoid redundant re-generation
if (!htmlReportFile.exists() || reportFile.lastModified() > htmlReportFile.lastModified()) {
project.ant.xslt(in: reportFile,
style: configLoader.resolveSpotbugsXsl(),
out: htmlReportPath,
)
}
}

@CompileStatic(TypeCheckingMode.SKIP)
private Map<String, String> buildDescription(Node result) {
Map<String, String> desc = [:]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import groovy.xml.XmlUtil
import org.gradle.api.Project
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.util.GradleVersion
import org.slf4j.Logger
import ru.vyarus.gradle.plugin.quality.QualityExtension

Expand Down Expand Up @@ -84,9 +83,7 @@ class SpotbugsUtils {
}
// apt is a special dir, not mentioned in sources!
JavaCompile javaCompile = task.project.tasks.findByName(set.compileJavaTaskName) as JavaCompile
File aptGenerated = GradleVersion.current() < GradleVersion.version('7.0')
? javaCompile.options.annotationProcessorGeneratedSourcesDirectory
: javaCompile.options.generatedSourceOutputDirectory.get().asFile
File aptGenerated = javaCompile.options.generatedSourceOutputDirectory.get().asFile

Set<File> ignored = FileUtils.resolveIgnoredFiles(task.sourceDirs.asFileTree, extension.exclude)
// exclude all apt-generated files
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.vyarus.gradle.plugin.quality

import groovy.ant.AntBuilder
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome
import spock.lang.TempDir
Expand All @@ -20,7 +21,7 @@ class BuildCacheSupportKitTest extends AbstractKitTest {
file("settings.gradle") << """
rootProject.name='my-project'
buildCache {
local(DirectoryBuildCache) {
local {
directory = new File('${cacheDir.canonicalPath.replace('\\', '\\\\')}')
}
}
Expand Down Expand Up @@ -91,7 +92,7 @@ class BuildCacheSupportKitTest extends AbstractKitTest {
// build cache will survive within test only!!
file("settings.gradle") << """
buildCache {
local(DirectoryBuildCache) {
local {
directory = new File('${cacheDir.canonicalPath.replace('\\', '\\\\')}')
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ class ConsoleReportsDisableKitTest extends AbstractKitTest {
fileFromClasspath('src/main/groovy/sample/GSample.groovy', '/ru/vyarus/gradle/plugin/quality/groovy/sample/GSample.groovy')

when: "run check task with both sources"
debug()
BuildResult result = run('check')

then: "all plugins detect violations"
result.task(":check").outcome == TaskOutcome.SUCCESS
result.output.contains('CodeNarc rule violations were found')
result.output.contains('Checkstyle rule violations were found')
result.output.contains('SpotBugs violations were found')
result.output.contains('SpotBugs ended with exit code 1')
result.output.contains('PMD rule violations were found')

then: "no console reporting performed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,13 @@ class ExcludeKitTest extends AbstractKitTest {
build("""
plugins {
id 'groovy'
id 'ru.vyarus.animalsniffer' version '1.5.0'
id 'ru.vyarus.animalsniffer' version '1.7.1'
id 'ru.vyarus.quality'
}
sourceCompatibility = 1.8
java {
sourceCompatibility = 1.8
}
quality {
strict false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,13 @@ class ExcludeSourcesKitTest extends AbstractKitTest {
build("""
plugins {
id 'java'
id 'ru.vyarus.animalsniffer' version '1.5.0'
id 'ru.vyarus.animalsniffer' version '1.7.1'
id 'ru.vyarus.quality'
}
sourceCompatibility = 1.8
java {
sourceCompatibility = 1.8
}
sourceSets.main {
java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GeneratedSourceExcludeKitTest extends AbstractKitTest {
plugins {
id 'java'
id 'ru.vyarus.quality'
id 'org.hidetake.swagger.generator' version '2.18.1'
id 'org.hidetake.swagger.generator' version '2.19.2'
}
repositories { mavenCentral() }
Expand Down
Loading

0 comments on commit 6a2d79a

Please sign in to comment.