Skip to content

Commit

Permalink
Fix ant tests
Browse files Browse the repository at this point in the history
Report was being rendered mutliple times
  • Loading branch information
oowekyala committed Nov 24, 2020
1 parent 1a2a897 commit 141c51b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pmd-core/src/main/java/net/sourceforge/pmd/PMD.java
Expand Up @@ -333,7 +333,7 @@ public static void processFiles(final PMDConfiguration configuration, final Rule
* and rulesets, are ignored, as they are supplied
* as parameters
* @param rulesets Parsed rulesets
* @param files Files to process
* @param files Files to process, will be closed by this method.
* @param renderers Renderers that render the report
*
* @return Report in which violations are accumulated
Expand Down
Expand Up @@ -12,7 +12,6 @@
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ContextedRuntimeException;
Expand Down Expand Up @@ -132,7 +131,7 @@ private void doTask() {
// TODO Do we really need all this in a loop over each FileSet? Seems
// like a lot of redundancy
Report errorReport = new Report();
final AtomicInteger reportSize = new AtomicInteger();
int problemCount = 0;
final String separator = System.getProperty("file.separator");

for (FileSet fs : filesets) {
Expand Down Expand Up @@ -165,10 +164,7 @@ public void startFileAnalysis(DataSource dataSource) {

@Override
public void renderFileReport(Report r) {
int size = r.size();
if (size > 0) {
reportSize.addAndGet(size);
}
// Nothing to do
}

@Override
Expand All @@ -189,7 +185,8 @@ public String defaultFileExtension() {
renderers.add(renderer);
}
try {
PMD.processFiles(configuration, rulesetList, files, renderers);
Report report = PMD.processFiles(configuration, rulesetList, files, renderers);
problemCount += report.getViolations().size();
} catch (ContextedRuntimeException e) {
if (e.getFirstContextValue("filename") instanceof String) {
handleError((String) e.getFirstContextValue("filename"), errorReport, e);
Expand All @@ -201,7 +198,6 @@ public String defaultFileExtension() {
}
}

int problemCount = reportSize.get();
project.log(problemCount + " problems found", Project.MSG_VERBOSE);

for (Formatter formatter : formatters) {
Expand Down
Expand Up @@ -128,6 +128,10 @@ public void processFiles(RuleSetFactory ruleSetFactory, List<DataSource> files,
public void processFiles(RuleSets rulesets, List<DataSource> files, RuleContext ctx, List<Renderer> renderers) {
try {
reportBrokenRules(ctx.getReport(), rulesets);

// render base report first - general errors
renderReports(renderers, ctx.getReport());

configuration.getAnalysisCache().checkValidity(rulesets, configuration.getClassLoader());
final SourceCodeProcessor processor = new SourceCodeProcessor(configuration);

Expand All @@ -138,9 +142,6 @@ public void processFiles(RuleSets rulesets, List<DataSource> files, RuleContext
runAnalysis(new PmdRunnable(dataSource, realFileName, renderers, ctx, rulesets, processor));
}

// render base report first - general errors
renderReports(renderers, ctx.getReport());

// then add analysis results per file
collectReports(renderers);
} catch (RuntimeException e) {
Expand Down
Expand Up @@ -7,7 +7,6 @@
import static org.junit.Assert.fail;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -71,7 +70,7 @@ public void testInvalidLanguageVersion() {
}

@Test
public void testWithShortFilenames() throws FileNotFoundException, IOException {
public void testWithShortFilenames() throws IOException {
buildRule.executeTarget("testWithShortFilenames");

try (InputStream in = new FileInputStream("target/pmd-ant-test.txt")) {
Expand Down
Expand Up @@ -65,7 +65,7 @@ public void testSingleRuleset() throws RuleSetNotFoundException, IOException {
RuleSetFactory rsf = RulesetsFactoryUtils.createFactory(RulePriority.LOW, false, false, true);
RuleSet ruleset = rsf.createRuleSet("rulesets/ruledoctest/sample.xml");

generator.generate(Arrays.asList(ruleset).iterator(),
generator.generate(Arrays.asList(ruleset),
Arrays.asList(
"rulesets/ruledoctest/sample-deprecated.xml",
"rulesets/ruledoctest/other-ruleset.xml"));
Expand Down

0 comments on commit 141c51b

Please sign in to comment.