Skip to content

Commit e5fd7e7

Browse files
committed
[groovy] Use less gstrings when not needed and sort parameter attributes
1 parent 260a4da commit e5fd7e7

11 files changed

+283
-289
lines changed

src/main/groovy/org/codehaus/mojo/spotbugs/BaseViolationCheckMojo.groovy

+44-41
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
4545
*
4646
* @since 1.0.0
4747
*/
48-
@Parameter(defaultValue = "false", property = "spotbugs.xmlOutput", required = true)
48+
@Parameter(defaultValue = 'false', property = 'spotbugs.xmlOutput', required = true)
4949
boolean xmlOutput
5050

5151
/**
@@ -69,7 +69,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
6969
*
7070
* @since 3.1.12.2
7171
*/
72-
@Parameter(defaultValue = "spotbugsXml.xml", property = "spotbugs.outputXmlFilename")
72+
@Parameter(defaultValue = 'spotbugsXml.xml', property = 'spotbugs.outputXmlFilename')
7373
String spotbugsXmlOutputFilename
7474

7575
/** Doxia Site Renderer. */
@@ -97,15 +97,15 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
9797
*
9898
* @since 2.0
9999
*/
100-
@Parameter(defaultValue = "false", property = "spotbugs.includeTests")
100+
@Parameter(defaultValue = 'false', property = 'spotbugs.includeTests')
101101
boolean includeTests
102102

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

107107
/** Maven Session. */
108-
@Parameter (defaultValue = '${session}', required = true, readonly = true)
108+
@Parameter (defaultValue = '${session}', readonly = true, required = true)
109109
MavenSession session
110110

111111
/**
@@ -114,7 +114,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
114114
*
115115
* @since 2.2
116116
*/
117-
@Parameter(defaultValue = '${project.build.sourceEncoding}', property = "encoding")
117+
@Parameter(defaultValue = '${project.build.sourceEncoding}', property = 'encoding')
118118
String sourceEncoding
119119

120120
/**
@@ -123,11 +123,14 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
123123
*
124124
* @since 2.2
125125
*/
126-
@Parameter(defaultValue = '${project.reporting.outputEncoding}', property = "outputEncoding")
126+
@Parameter(defaultValue = '${project.reporting.outputEncoding}', property = 'outputEncoding')
127127
String outputEncoding
128128

129-
/** Threshold of minimum bug severity to report. Valid values are High, Default, Low, Ignore, and Exp (for experimental). */
130-
@Parameter(defaultValue = "Default", property = "spotbugs.threshold")
129+
/**
130+
* Threshold of minimum bug severity to report. Valid values are 'High', 'Default', 'Low', 'Ignore',
131+
* and 'Exp' (for experimental).
132+
*/
133+
@Parameter(defaultValue = 'Default', property = 'spotbugs.threshold')
131134
String threshold
132135

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

153156
/**
@@ -163,7 +166,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
163166
*
164167
* @since 1.0-beta-1
165168
*/
166-
@Parameter(property = "spotbugs.excludeFilterFile")
169+
@Parameter(property = 'spotbugs.excludeFilterFile')
167170
String excludeFilterFile
168171

169172
/**
@@ -180,19 +183,19 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
180183
*
181184
* @since 2.4.1
182185
*/
183-
@Parameter(property = "spotbugs.excludeBugsFile")
186+
@Parameter(property = 'spotbugs.excludeBugsFile')
184187
String excludeBugsFile
185188

186189
/**
187190
* Effort of the bug finders. Valid values are Min, Default and Max.
188191
*
189192
* @since 1.0-beta-1
190193
*/
191-
@Parameter(defaultValue = "Default", property = "spotbugs.effort")
194+
@Parameter(defaultValue = 'Default', property = 'spotbugs.effort')
192195
String effort
193196

194197
/** Turn on Spotbugs debugging. */
195-
@Parameter(defaultValue = "false", property = "spotbugs.debug")
198+
@Parameter(defaultValue = 'false', property = 'spotbugs.debug')
196199
boolean debug
197200

198201
/**
@@ -201,23 +204,23 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
201204
*
202205
* @since 1.1
203206
*/
204-
@Parameter(defaultValue = "false", property = "spotbugs.relaxed")
207+
@Parameter(defaultValue = 'false', property = 'spotbugs.relaxed')
205208
boolean relaxed
206209

207210
/**
208211
* The visitor list to run. This is a comma-delimited list.
209212
*
210213
* @since 1.0-beta-1
211214
*/
212-
@Parameter(property = "spotbugs.visitors")
215+
@Parameter(property = 'spotbugs.visitors')
213216
String visitors
214217

215218
/**
216219
* The visitor list to omit. This is a comma-delimited list.
217220
*
218221
* @since 1.0-beta-1
219222
*/
220-
@Parameter(property = "spotbugs.omitVisitors")
223+
@Parameter(property = 'spotbugs.omitVisitors')
221224
String omitVisitors
222225

223226
/**
@@ -232,15 +235,15 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
232235
*
233236
* @since 1.0-beta-1
234237
*/
235-
@Parameter(property="spotbugs.pluginList")
238+
@Parameter(property = 'spotbugs.pluginList')
236239
String pluginList
237240

238241
/**
239242
* Restrict analysis to the given comma-separated list of classes and packages.
240243
*
241244
* @since 1.1
242245
*/
243-
@Parameter(property = "spotbugs.onlyAnalyze")
246+
@Parameter(property = 'spotbugs.onlyAnalyze')
244247
String onlyAnalyze
245248

246249
/**
@@ -249,7 +252,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
249252
*
250253
* @since 2.3.2
251254
*/
252-
@Parameter(property = "spotbugs.nested", defaultValue = "false")
255+
@Parameter(defaultValue = 'false', property = 'spotbugs.nested')
253256
boolean nested
254257

255258
/**
@@ -258,23 +261,23 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
258261
*
259262
* @since 2.3.2
260263
*/
261-
@Parameter(property = "spotbugs.trace", defaultValue = "false")
264+
@Parameter(defaultValue = 'false', property = 'spotbugs.trace')
262265
boolean trace
263266

264267
/**
265268
* Maximum bug ranking to record.
266269
*
267270
* @since 2.4.1
268271
*/
269-
@Parameter(property = "spotbugs.maxRank")
272+
@Parameter(property = 'spotbugs.maxRank')
270273
int maxRank
271274

272275
/**
273276
* Skip entire check.
274277
*
275278
* @since 1.1
276279
*/
277-
@Parameter(property = "spotbugs.skip", defaultValue = "false")
280+
@Parameter(defaultValue = 'false', property = 'spotbugs.skip')
278281
boolean skip
279282

280283
/**
@@ -298,7 +301,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
298301
*
299302
* @since 2.0
300303
*/
301-
@Parameter(property = "spotbugs.failOnError", defaultValue = "true")
304+
@Parameter(defaultValue = 'true', property = 'spotbugs.failOnError')
302305
boolean failOnError
303306

304307
/**
@@ -307,15 +310,15 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
307310
*
308311
* @since 4.0.1
309312
*/
310-
@Parameter(property = "spotbugs.failThreshold")
313+
@Parameter(property = 'spotbugs.failThreshold')
311314
String failThreshold
312315

313316
/**
314317
* Fork a VM for Spotbugs analysis. This will allow you to set timeouts and heap size.
315318
*
316319
* @since 2.3.2
317320
*/
318-
@Parameter(property = "spotbugs.fork", defaultValue = "true")
321+
@Parameter(defaultValue = 'true', property = 'spotbugs.fork')
319322
boolean fork
320323

321324
/**
@@ -324,7 +327,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
324327
*
325328
* @since 2.2
326329
*/
327-
@Parameter(property = "spotbugs.maxHeap", defaultValue = "512")
330+
@Parameter(defaultValue = '512', property = 'spotbugs.maxHeap')
328331
int maxHeap
329332

330333
/**
@@ -335,45 +338,45 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
335338
*
336339
* @since 2.2
337340
*/
338-
@Parameter(property = "spotbugs.timeout", defaultValue = "600000")
341+
@Parameter(defaultValue = '600000', property = 'spotbugs.timeout')
339342
int timeout
340343

341344
/**
342345
* The arguments to pass to the forked VM (ignored if fork is disabled).
343346
*
344347
* @since 2.4.1
345348
*/
346-
@Parameter(property = "spotbugs.jvmArgs")
349+
@Parameter(property = 'spotbugs.jvmArgs')
347350
String jvmArgs
348351

349352
/**
350353
* specified max number of violations which can be ignored by the spotbugs.
351354
*
352355
* @since 2.4.1
353356
*/
354-
@Parameter(property = "spotbugs.maxAllowedViolations", defaultValue = "0")
357+
@Parameter(defaultValue = '0', property = 'spotbugs.maxAllowedViolations')
355358
int maxAllowedViolations
356359

357360
/** Disable bugs log. */
358-
@Parameter(defaultValue = "false", property = "spotbugs.quiet")
361+
@Parameter(defaultValue = 'false', property = 'spotbugs.quiet')
359362
boolean quiet
360363

361364
@Override
362365
void execute() {
363-
log.debug("Executing spotbugs:check")
366+
log.debug('Executing spotbugs:check')
364367

365368
if (skip) {
366-
log.info("Spotbugs plugin skipped")
369+
log.info('Spotbugs plugin skipped')
367370
return
368371
} else if (!doSourceFilesExist()) {
369-
log.debug("Nothing for SpotBugs to do here.")
372+
log.debug('Nothing for SpotBugs to do here.')
370373
return
371374
}
372375

373-
log.debug("Here goes...............Executing spotbugs:check")
376+
log.debug('Here goes...............Executing spotbugs:check')
374377

375378
if (!spotbugsXmlOutputDirectory.exists() && !spotbugsXmlOutputDirectory.mkdirs()) {
376-
throw new MojoExecutionException("Cannot create xml output directory")
379+
throw new MojoExecutionException('Cannot create xml output directory')
377380
}
378381

379382
File outputFile = new File("${spotbugsXmlOutputDirectory}/${spotbugsXmlOutputFilename}")
@@ -393,7 +396,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
393396
log.info('No errors/warnings found')
394397
return
395398
} else if (maxAllowedViolations > 0 && bugCount <= maxAllowedViolations) {
396-
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)
399+
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}")
397400
printBugs(bugCount, bugs)
398401
return
399402
}
@@ -427,7 +430,7 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
427430
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)
428431

429432
if ((bugCountAboveThreshold || errorCount) && failOnError) {
430-
throw new MojoExecutionException("failed with ${bugCountAboveThreshold} bugs and ${errorCount} errors ")
433+
throw new MojoExecutionException("failed with ${bugCountAboveThreshold} bugs and ${errorCount} errors")
431434
}
432435
}
433436
}
@@ -436,16 +439,16 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
436439
Collection<File> sourceFiles = new ArrayList<>()
437440

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

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

448-
log.debug("SourceFiles: " + Arrays.toString(sourceFiles));
451+
log.debug('SourceFiles: ' + Arrays.toString(sourceFiles));
449452
!sourceFiles.isEmpty()
450453
}
451454

src/main/groovy/org/codehaus/mojo/spotbugs/CheckMojo.groovy

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2005-2023 the original author or authors.
2+
* Copyright 2005-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,8 +27,8 @@ import org.apache.maven.plugins.annotations.ResolutionScope
2727
*
2828
* @since 2.0
2929
*/
30-
@Mojo(name = "check", defaultPhase = LifecyclePhase.VERIFY, requiresDependencyResolution = ResolutionScope.TEST, requiresProject = true, threadSafe = true)
31-
@Execute(goal = "spotbugs")
30+
@Mojo(name = 'check', defaultPhase = LifecyclePhase.VERIFY, requiresDependencyResolution = ResolutionScope.TEST, requiresProject = true, threadSafe = true)
31+
@Execute(goal = 'spotbugs')
3232
class CheckMojo extends BaseViolationCheckMojo {
3333
// Check Mojo to run spotbugs execution
3434
}

src/main/groovy/org/codehaus/mojo/spotbugs/ResourceHelper.groovy

+6-6
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ final class ResourceHelper {
7676
location = location?.replaceAll("[\\?\\:\\&\\=\\%]", "_")
7777
artifact = artifact?.replaceAll("[\\?\\:\\&\\=\\%]", "_")
7878

79-
log.debug("resource is " + resource)
80-
log.debug("location is " + location)
81-
log.debug("artifact is " + artifact)
79+
log.debug('resource is ' + resource)
80+
log.debug('location is ' + location)
81+
log.debug('artifact is ' + artifact)
8282

8383
File resourceFile = getResourceAsFile(resource, artifact)
8484

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

8787
return resourceFile
8888

@@ -99,7 +99,7 @@ final class ResourceHelper {
9999
File outputResourceFile
100100

101101
if (outputPath == null) {
102-
outputResourceFile = Files.createTempFile("plexus-resources", "tmp")
102+
outputResourceFile = Files.createTempFile('plexus-resources', 'tmp')
103103
} else if (outputDirectory != null) {
104104
outputResourceFile = new File(outputDirectory, outputPath)
105105
} else {
@@ -117,7 +117,7 @@ final class ResourceHelper {
117117
os << is
118118

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

123123
return outputResourceFile

0 commit comments

Comments
 (0)