Make sure the PmdAnalysis is closed
This commit is contained in:
parent
a5f479189e
commit
e56791fdb0
4 changed files with 54 additions and 46 deletions
|
@ -22,6 +22,7 @@ import net.sourceforge.pmd.lang.LanguageVersion;
|
|||
import net.sourceforge.pmd.lang.rule.RulePriority;
|
||||
import net.sourceforge.pmd.reporting.Report;
|
||||
import rife.bld.BaseProject;
|
||||
import rife.bld.extension.pmd.PmdAnalysisResults;
|
||||
import rife.bld.operations.AbstractOperation;
|
||||
import rife.bld.operations.exceptions.ExitStatusException;
|
||||
|
||||
|
@ -804,10 +805,9 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
|||
* @return the number of violations
|
||||
* @throws ExitStatusException if an error occurs
|
||||
*/
|
||||
@SuppressWarnings("PMD.CloseResource")
|
||||
public PmdAnalysisResults performPmdAnalysis(String commandName, PMDConfiguration config)
|
||||
throws ExitStatusException {
|
||||
var pmd = PmdAnalysis.create(config);
|
||||
try (var pmd = PmdAnalysis.create(config)) {
|
||||
var report = pmd.performAnalysisAndCollectReport();
|
||||
|
||||
if (LOGGER.isLoggable(Level.INFO) && !silent()) {
|
||||
|
@ -822,15 +822,12 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
|||
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int rulesChecked = 0;
|
||||
var rulesChecked = 0;
|
||||
var rules = pmd.getRulesets();
|
||||
if (!rules.isEmpty()) {
|
||||
for (var rule : rules) {
|
||||
rulesChecked += rule.getRules().size();
|
||||
}
|
||||
if (LOGGER.isLoggable(Level.INFO) && !silent()) {
|
||||
LOGGER.info(String.format("[%s] %d rules were checked.", commandName, rulesChecked));
|
||||
}
|
||||
}
|
||||
|
||||
var result = new PmdAnalysisResults(
|
||||
|
@ -842,24 +839,33 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
|||
rulesChecked
|
||||
);
|
||||
|
||||
if (result.processingErrors() > 0 && LOGGER.isLoggable(Level.WARNING) && !silent()) {
|
||||
if (!silent()) {
|
||||
if (LOGGER.isLoggable(Level.INFO)) {
|
||||
LOGGER.info(String.format("[%s] %d rules were checked.", commandName, result.rulesChecked()));
|
||||
}
|
||||
|
||||
if (LOGGER.isLoggable(Level.WARNING)) {
|
||||
if (result.processingErrors() > 0) {
|
||||
for (var err : report.getProcessingErrors()) {
|
||||
LOGGER.warning(String.format("[%s] %s", commandName, err.getMsg()));
|
||||
}
|
||||
}
|
||||
|
||||
if (result.configurationErrors() > 0 && LOGGER.isLoggable(Level.WARNING) && !silent()) {
|
||||
if (result.configurationErrors() > 0) {
|
||||
for (var err : report.getConfigurationErrors()) {
|
||||
LOGGER.warning(String.format("[%s] %s", commandName, err.issue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (LOGGER.isLoggable(Level.FINEST) && !silent()) {
|
||||
if (LOGGER.isLoggable(Level.FINEST)) {
|
||||
LOGGER.finest(result.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend the specified classpath like string to the current ClassLoader of the configuration. If no ClassLoader
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package rife.bld.extension;
|
||||
package rife.bld.extension.pmd;
|
||||
|
||||
/**
|
||||
* Represents the results of a PMD analysis, containing various counts
|
|
@ -622,6 +622,8 @@ class PmdOperationTests {
|
|||
|
||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)).violations())
|
||||
.as(ANALYSIS_FAILURE).isGreaterThan(0);
|
||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)).configurationErrors())
|
||||
.as(ANALYSIS_FAILURE).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package rife.bld.extension;
|
||||
package rife.bld.extension.pmd;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
Loading…
Add table
Add a link
Reference in a new issue