Skip to content

Commit

Permalink
Merge pull request #923 from hazendaz/charset
Browse files Browse the repository at this point in the history
Gstring to string where appropriate / Update deprecated maven code for getting report plugins
  • Loading branch information
hazendaz authored Nov 11, 2024
2 parents 260a4da + 559b0ca commit 62ddea0
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
*
* @since 1.0.0
*/
@Parameter(defaultValue = "false", property = "spotbugs.xmlOutput", required = true)
@Parameter(defaultValue = 'false', property = 'spotbugs.xmlOutput', required = true)
boolean xmlOutput

/**
Expand All @@ -69,7 +69,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
*
* @since 3.1.12.2
*/
@Parameter(defaultValue = "spotbugsXml.xml", property = "spotbugs.outputXmlFilename")
@Parameter(defaultValue = 'spotbugsXml.xml', property = 'spotbugs.outputXmlFilename')
String spotbugsXmlOutputFilename

/** Doxia Site Renderer. */
Expand Down Expand Up @@ -97,15 +97,15 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
*
* @since 2.0
*/
@Parameter(defaultValue = "false", property = "spotbugs.includeTests")
@Parameter(defaultValue = 'false', property = 'spotbugs.includeTests')
boolean includeTests

/** List of artifacts this plugin depends on. Used for resolving the Spotbugs core plugin. */
@Parameter(property = "plugin.artifacts", required = true, readonly = true)
@Parameter(property = 'plugin.artifacts', readonly = true, required = true)
List pluginArtifacts

/** Maven Session. */
@Parameter (defaultValue = '${session}', required = true, readonly = true)
@Parameter (defaultValue = '${session}', readonly = true, required = true)
MavenSession session

/**
Expand All @@ -114,7 +114,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
*
* @since 2.2
*/
@Parameter(defaultValue = '${project.build.sourceEncoding}', property = "encoding")
@Parameter(defaultValue = '${project.build.sourceEncoding}', property = 'encoding')
String sourceEncoding

/**
Expand All @@ -123,11 +123,14 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
*
* @since 2.2
*/
@Parameter(defaultValue = '${project.reporting.outputEncoding}', property = "outputEncoding")
@Parameter(defaultValue = '${project.reporting.outputEncoding}', property = 'outputEncoding')
String outputEncoding

/** Threshold of minimum bug severity to report. Valid values are High, Default, Low, Ignore, and Exp (for experimental). */
@Parameter(defaultValue = "Default", property = "spotbugs.threshold")
/**
* Threshold of minimum bug severity to report. Valid values are 'High', 'Default', 'Low', 'Ignore',
* and 'Exp' (for experimental).
*/
@Parameter(defaultValue = 'Default', property = 'spotbugs.threshold')
String threshold

/** Artifact resolver, needed to download the coreplugin jar. */
Expand All @@ -147,7 +150,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
*
* @since 1.0-beta-1
*/
@Parameter(property = "spotbugs.includeFilterFile")
@Parameter(property = 'spotbugs.includeFilterFile')
String includeFilterFile

/**
Expand All @@ -163,7 +166,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
*
* @since 1.0-beta-1
*/
@Parameter(property = "spotbugs.excludeFilterFile")
@Parameter(property = 'spotbugs.excludeFilterFile')
String excludeFilterFile

/**
Expand All @@ -180,19 +183,19 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
*
* @since 2.4.1
*/
@Parameter(property = "spotbugs.excludeBugsFile")
@Parameter(property = 'spotbugs.excludeBugsFile')
String excludeBugsFile

/**
* Effort of the bug finders. Valid values are Min, Default and Max.
*
* @since 1.0-beta-1
*/
@Parameter(defaultValue = "Default", property = "spotbugs.effort")
@Parameter(defaultValue = 'Default', property = 'spotbugs.effort')
String effort

/** Turn on Spotbugs debugging. */
@Parameter(defaultValue = "false", property = "spotbugs.debug")
@Parameter(defaultValue = 'false', property = 'spotbugs.debug')
boolean debug

/**
Expand All @@ -201,23 +204,23 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
*
* @since 1.1
*/
@Parameter(defaultValue = "false", property = "spotbugs.relaxed")
@Parameter(defaultValue = 'false', property = 'spotbugs.relaxed')
boolean relaxed

/**
* The visitor list to run. This is a comma-delimited list.
*
* @since 1.0-beta-1
*/
@Parameter(property = "spotbugs.visitors")
@Parameter(property = 'spotbugs.visitors')
String visitors

/**
* The visitor list to omit. This is a comma-delimited list.
*
* @since 1.0-beta-1
*/
@Parameter(property = "spotbugs.omitVisitors")
@Parameter(property = 'spotbugs.omitVisitors')
String omitVisitors

/**
Expand All @@ -232,15 +235,15 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
*
* @since 1.0-beta-1
*/
@Parameter(property="spotbugs.pluginList")
@Parameter(property = 'spotbugs.pluginList')
String pluginList

/**
* Restrict analysis to the given comma-separated list of classes and packages.
*
* @since 1.1
*/
@Parameter(property = "spotbugs.onlyAnalyze")
@Parameter(property = 'spotbugs.onlyAnalyze')
String onlyAnalyze

/**
Expand All @@ -249,7 +252,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
*
* @since 2.3.2
*/
@Parameter(property = "spotbugs.nested", defaultValue = "false")
@Parameter(defaultValue = 'false', property = 'spotbugs.nested')
boolean nested

/**
Expand All @@ -258,23 +261,23 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
*
* @since 2.3.2
*/
@Parameter(property = "spotbugs.trace", defaultValue = "false")
@Parameter(defaultValue = 'false', property = 'spotbugs.trace')
boolean trace

/**
* Maximum bug ranking to record.
*
* @since 2.4.1
*/
@Parameter(property = "spotbugs.maxRank")
@Parameter(property = 'spotbugs.maxRank')
int maxRank

/**
* Skip entire check.
*
* @since 1.1
*/
@Parameter(property = "spotbugs.skip", defaultValue = "false")
@Parameter(defaultValue = 'false', property = 'spotbugs.skip')
boolean skip

/**
Expand All @@ -298,7 +301,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
*
* @since 2.0
*/
@Parameter(property = "spotbugs.failOnError", defaultValue = "true")
@Parameter(defaultValue = 'true', property = 'spotbugs.failOnError')
boolean failOnError

/**
Expand All @@ -307,15 +310,15 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
*
* @since 4.0.1
*/
@Parameter(property = "spotbugs.failThreshold")
@Parameter(property = 'spotbugs.failThreshold')
String failThreshold

/**
* Fork a VM for Spotbugs analysis. This will allow you to set timeouts and heap size.
*
* @since 2.3.2
*/
@Parameter(property = "spotbugs.fork", defaultValue = "true")
@Parameter(defaultValue = 'true', property = 'spotbugs.fork')
boolean fork

/**
Expand All @@ -324,7 +327,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
*
* @since 2.2
*/
@Parameter(property = "spotbugs.maxHeap", defaultValue = "512")
@Parameter(defaultValue = '512', property = 'spotbugs.maxHeap')
int maxHeap

/**
Expand All @@ -335,45 +338,45 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
*
* @since 2.2
*/
@Parameter(property = "spotbugs.timeout", defaultValue = "600000")
@Parameter(defaultValue = '600000', property = 'spotbugs.timeout')
int timeout

/**
* The arguments to pass to the forked VM (ignored if fork is disabled).
*
* @since 2.4.1
*/
@Parameter(property = "spotbugs.jvmArgs")
@Parameter(property = 'spotbugs.jvmArgs')
String jvmArgs

/**
* specified max number of violations which can be ignored by the spotbugs.
*
* @since 2.4.1
*/
@Parameter(property = "spotbugs.maxAllowedViolations", defaultValue = "0")
@Parameter(defaultValue = '0', property = 'spotbugs.maxAllowedViolations')
int maxAllowedViolations

/** Disable bugs log. */
@Parameter(defaultValue = "false", property = "spotbugs.quiet")
@Parameter(defaultValue = 'false', property = 'spotbugs.quiet')
boolean quiet

@Override
void execute() {
log.debug("Executing spotbugs:check")
log.debug('Executing spotbugs:check')

if (skip) {
log.info("Spotbugs plugin skipped")
log.info('Spotbugs plugin skipped')
return
} else if (!doSourceFilesExist()) {
log.debug("Nothing for SpotBugs to do here.")
log.debug('Nothing for SpotBugs to do here.')
return
}

log.debug("Here goes...............Executing spotbugs:check")
log.debug('Here goes...............Executing spotbugs:check')

if (!spotbugsXmlOutputDirectory.exists() && !spotbugsXmlOutputDirectory.mkdirs()) {
throw new MojoExecutionException("Cannot create xml output directory")
throw new MojoExecutionException('Cannot create xml output directory')
}

File outputFile = new File("${spotbugsXmlOutputDirectory}/${spotbugsXmlOutputFilename}")
Expand All @@ -393,7 +396,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
log.info('No errors/warnings found')
return
} else if (maxAllowedViolations > 0 && bugCount <= maxAllowedViolations) {
log.info("total ${bugCount} violations are found which is set to be acceptable using configured property maxAllowedViolations :" + maxAllowedViolations + "." + SpotBugsInfo.EOL + "Below are list of bugs ignored :" + SpotBugsInfo.EOL)
log.info("total ${bugCount} violations are found which is set to be acceptable using configured property maxAllowedViolations :${maxAllowedViolations}.${SpotBugsInfo.EOL}Below are list of bugs ignored :${SpotBugsInfo.EOL}")
printBugs(bugCount, bugs)
return
}
Expand Down Expand Up @@ -427,7 +430,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
log.info(SpotBugsInfo.EOL + SpotBugsInfo.EOL + SpotBugsInfo.EOL + 'To see bug detail using the Spotbugs GUI, use the following command "mvn spotbugs:gui"' + SpotBugsInfo.EOL + SpotBugsInfo.EOL + SpotBugsInfo.EOL)

if ((bugCountAboveThreshold || errorCount) && failOnError) {
throw new MojoExecutionException("failed with ${bugCountAboveThreshold} bugs and ${errorCount} errors ")
throw new MojoExecutionException("failed with ${bugCountAboveThreshold} bugs and ${errorCount} errors")
}
}
}
Expand All @@ -436,16 +439,16 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
Collection<File> sourceFiles = new ArrayList<>()

if (this.classFilesDirectory.isDirectory()) {
log.debug("looking for class files with extensions: " + SpotBugsInfo.EXTENSIONS)
log.debug('looking for class files with extensions: ' + SpotBugsInfo.EXTENSIONS)
sourceFiles.addAll(FileUtils.listFiles(classFilesDirectory, SpotBugsInfo.EXTENSIONS, true))
}

if (this.includeTests && this.testClassFilesDirectory.isDirectory()) {
log.debug("looking for test class files: " + SpotBugsInfo.EXTENSIONS)
log.debug('looking for test class files: ' + SpotBugsInfo.EXTENSIONS)
sourceFiles.addAll(FileUtils.listFiles(testClassFilesDirectory, SpotBugsInfo.EXTENSIONS, true))
}

log.debug("SourceFiles: " + Arrays.toString(sourceFiles));
log.debug('SourceFiles: ' + Arrays.toString(sourceFiles));
!sourceFiles.isEmpty()
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/groovy/org/codehaus/mojo/spotbugs/CheckMojo.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2005-2023 the original author or authors.
* Copyright 2005-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,8 +27,8 @@ import org.apache.maven.plugins.annotations.ResolutionScope
*
* @since 2.0
*/
@Mojo(name = "check", defaultPhase = LifecyclePhase.VERIFY, requiresDependencyResolution = ResolutionScope.TEST, requiresProject = true, threadSafe = true)
@Execute(goal = "spotbugs")
@Mojo(name = 'check', defaultPhase = LifecyclePhase.VERIFY, requiresDependencyResolution = ResolutionScope.TEST, requiresProject = true, threadSafe = true)
@Execute(goal = 'spotbugs')
class CheckMojo extends BaseViolationCheckMojo {
// Check Mojo to run spotbugs execution
}
12 changes: 6 additions & 6 deletions src/main/groovy/org/codehaus/mojo/spotbugs/ResourceHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ final class ResourceHelper {
location = location?.replaceAll("[\\?\\:\\&\\=\\%]", "_")
artifact = artifact?.replaceAll("[\\?\\:\\&\\=\\%]", "_")

log.debug("resource is " + resource)
log.debug("location is " + location)
log.debug("artifact is " + artifact)
log.debug('resource is ' + resource)
log.debug('location is ' + location)
log.debug('artifact is ' + artifact)

File resourceFile = getResourceAsFile(resource, artifact)

log.debug("location of resourceFile file is " + resourceFile.absolutePath)
log.debug('location of resourceFile file is ' + resourceFile.absolutePath)

return resourceFile

Expand All @@ -99,7 +99,7 @@ final class ResourceHelper {
File outputResourceFile

if (outputPath == null) {
outputResourceFile = Files.createTempFile("plexus-resources", "tmp")
outputResourceFile = Files.createTempFile('plexus-resources', 'tmp')
} else if (outputDirectory != null) {
outputResourceFile = new File(outputDirectory, outputPath)
} else {
Expand All @@ -117,7 +117,7 @@ final class ResourceHelper {
os << is

} catch (IOException e) {
throw new FileResourceCreationException("Cannot create file-based resource.", e)
throw new FileResourceCreationException('Cannot create file-based resource.', e)
}

return outputResourceFile
Expand Down
Loading

0 comments on commit 62ddea0

Please sign in to comment.