Skip to content

Commit

Permalink
Merge pull request pmd#4420 from oowekyala:clem.pmd7-remove-pmd-eol
Browse files Browse the repository at this point in the history
[core] Remove PMD.EOL pmd#4420
adangel committed Mar 17, 2023
2 parents 4ab91cb + ee85073 commit 4a14cb7
Showing 47 changed files with 522 additions and 646 deletions.
2 changes: 2 additions & 0 deletions docs/pages/release_notes.md
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@ This is a {{ site.pmd.release_type }} release.
### New and noteworthy

### Fixed Issues
* core
* [#4420](https://github.com/pmd/pmd/pull/4420): \[core] Remove PMD.EOL
* java-bestpractices
* [#1205](https://github.com/pmd/pmd/issues/1205): \[java] Improve ConstantsInInterface message to mention alternatives
* java-documentation
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@

import org.junit.jupiter.api.Test;

import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.Report;
import net.sourceforge.pmd.ViolationSuppressor;
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
@@ -46,94 +45,160 @@ public String getName() {

@Test
void testClassLevelSuppression() {
Report rpt = apex.executeRule(new FooRule(), TEST1);
assertSize(rpt, 0);
rpt = apex.executeRule(new FooRule(), TEST2);
assertSize(rpt, 0);
assertNoWarningsWithFoo("@SuppressWarnings('PMD')\n"
+ "public class Foo {}");
}

private void assertNoWarningsWithFoo(String code) {
assertWarningsWithFoo(0, code);
}

@Test
void testClassLevelSuppression2() {
assertNoWarningsWithFoo("@SuppressWarnings('PMD')\n"
+ "public class Foo {" + "\n"
+ " void bar() {\n"
+ " Integer foo;\n"
+ " }\n"
+ "}");
}

@Test
void testInheritedSuppression() {
Report rpt = apex.executeRule(new FooRule(), TEST3);
assertSize(rpt, 0);
assertNoWarningsWithFoo("public class Baz {\n"
+ " @SuppressWarnings('PMD')" + "\n"
+ " public class Bar {\n"
+ " void bar() {\n"
+ " Integer foo;\n"
+ " }" + "\n"
+ " }\n"
+ "}");
}

@Test
void testMethodLevelSuppression() {
Report rpt = apex.executeRule(new FooRule(), TEST4);
assertSize(rpt, 1);
assertWarningsWithFoo(1, "public class Foo {\n"
+ " @SuppressWarnings('PMD')\n"
+ " void bar() {\n"
+ " Integer foo;\n"
+ " }\n"
+ "}");
}

@Test
void testConstructorLevelSuppression() {
Report rpt = apex.executeRule(new FooRule(), TEST5);
assertSize(rpt, 0);
assertNoWarningsWithFoo("public class Bar {\n"
+ " @SuppressWarnings('PMD')" + "\n"
+ " public Bar() {\n"
+ " Integer foo;\n"
+ " }\n"
+ "}");
}

@Test
void testFieldLevelSuppression() {
Report rpt = apex.executeRule(new FooRule(), TEST6);
assertSize(rpt, 1);
assertWarningsWithFoo(1, "public class Bar {\n"
+ " @SuppressWarnings('PMD')" + "\n"
+ " Integer foo;\n"
+ " void bar() {\n"
+ " Integer foo;\n"
+ " }\n"
+ "}");
}

@Test
void testParameterLevelSuppression() {
Report rpt = apex.executeRule(new FooRule(), TEST7);
assertSize(rpt, 1);
assertWarningsWithFoo(1, "public class Bar {\n"
+ " Integer foo;" + "\n"
+ " void bar(@SuppressWarnings('PMD') Integer foo) {}\n"
+ "}");
}

@Test
void testLocalVariableLevelSuppression() {
Report rpt = apex.executeRule(new FooRule(), TEST8);
assertSize(rpt, 1);
assertWarningsWithFoo(1, "public class Bar {\n"
+ " Integer foo;\n"
+ " void bar() {"
+ "\n" + " @SuppressWarnings('PMD') Integer foo;\n"
+ " }\n"
+ "}");
}

@Test
void testSpecificSuppression() {
Report rpt = apex.executeRule(new FooRule(), TEST9);
assertSize(rpt, 1);
assertWarningsWithFoo(1, "public class Bar {\n"
+ " Integer foo;\n"
+ " void bar() {"
+ "\n" + " @SuppressWarnings('PMD.NoFoo') Integer foo;\n"
+ " }\n"
+ "}");
}

@Test
void testSpecificSuppressionMulitpleValues() {
Report rpt = apex.executeRule(new FooRule(), TEST9_MULTIPLE_VALUES);
assertSize(rpt, 0);
assertNoWarningsWithFoo("@SuppressWarnings('PMD.NoFoo, PMD.NoBar')"
+ "\n" + "public class Bar {\n"
+ " Integer foo;\n"
+ " void bar() {" + "\n"
+ " Integer foo;\n"
+ " }\n"
+ "}");
}

@Test
void testNoSuppressionBlank() {
Report rpt = apex.executeRule(new FooRule(), TEST10);
assertSize(rpt, 2);
assertWarningsWithFoo(2, "public class Bar {\n"
+ " Integer foo;\n"
+ " void bar() {"
+ "\n" + " @SuppressWarnings('') Integer foo;\n"
+ " }\n"
+ "}");
}

private void assertWarningsWithFoo(int size, String code) {
Report rpt = apex.executeRule(new FooRule(), code);
assertSize(rpt, size);
}

@Test
void testNoSuppressionSomethingElseS() {
Report rpt = apex.executeRule(new FooRule(), TEST11);
assertSize(rpt, 2);
assertWarningsWithFoo(2, "public class Bar {\n"
+ " Integer foo;\n"
+ " void bar() {"
+ "\n" + " @SuppressWarnings('SomethingElse') Integer foo;\n"
+ " }\n"
+ "}");
}

@Test
void testSuppressAll() {
Report rpt = apex.executeRule(new FooRule(), TEST12);
assertSize(rpt, 0);
assertNoWarningsWithFoo("public class Bar {\n"
+ " @SuppressWarnings('all') Integer foo;"
+ "\n" + "}");
}

@Test
void testSpecificSuppressionAtTopLevel() {
Report rpt = apex.executeRule(new BarRule(), TEST13);
Report rpt = apex.executeRule(new BarRule(), "@SuppressWarnings('PMD.NoBar')\n"
+ "public class Bar {" + "\n"
+ "}");
assertSize(rpt, 0);
}

@Test
void testCommentSuppression() {
Report rpt = apex.executeRule(new FooRule(), TEST14);
Report rpt = apex.executeRule(new FooRule(), "public class Bar {\n"
+ "Integer foo; // NOPMD\n"
+ "}");
assertSize(rpt, 0);
assertSuppressed(rpt, 1);
}

@Test
void testMessageWithCommentSuppression() {
Report rpt = apex.executeRule(new FooRule(), TEST15);
Report rpt = apex.executeRule(new FooRule(), "public class Bar {\n"
+ "Integer foo; //NOPMD We allow foo here\n"
+ "}");
assertSize(rpt, 0);

List<Report.SuppressedViolation> suppressions = assertSuppressed(rpt, 1);
@@ -143,50 +208,4 @@ void testMessageWithCommentSuppression() {
assertEquals("We allow foo here", suppression.getUserMessage());
}

private static final String TEST1 = "@SuppressWarnings('PMD')" + PMD.EOL + "public class Foo {}";

private static final String TEST2 = "@SuppressWarnings('PMD')" + PMD.EOL + "public class Foo {" + PMD.EOL
+ " void bar() {" + PMD.EOL + " Integer foo;" + PMD.EOL + " }" + PMD.EOL + "}";

private static final String TEST3 = "public class Baz {" + PMD.EOL + " @SuppressWarnings('PMD')" + PMD.EOL
+ " public class Bar {" + PMD.EOL + " void bar() {" + PMD.EOL + " Integer foo;" + PMD.EOL + " }" + PMD.EOL
+ " }" + PMD.EOL + "}";

private static final String TEST4 = "public class Foo {" + PMD.EOL + " @SuppressWarnings('PMD')" + PMD.EOL
+ " void bar() {" + PMD.EOL + " Integer foo;" + PMD.EOL + " }" + PMD.EOL + "}";

private static final String TEST5 = "public class Bar {" + PMD.EOL + " @SuppressWarnings('PMD')" + PMD.EOL
+ " public Bar() {" + PMD.EOL + " Integer foo;" + PMD.EOL + " }" + PMD.EOL + "}";

private static final String TEST6 = "public class Bar {" + PMD.EOL + " @SuppressWarnings('PMD')" + PMD.EOL
+ " Integer foo;" + PMD.EOL + " void bar() {" + PMD.EOL + " Integer foo;" + PMD.EOL + " }" + PMD.EOL + "}";

private static final String TEST7 = "public class Bar {" + PMD.EOL + " Integer foo;" + PMD.EOL
+ " void bar(@SuppressWarnings('PMD') Integer foo) {}" + PMD.EOL + "}";

private static final String TEST8 = "public class Bar {" + PMD.EOL + " Integer foo;" + PMD.EOL + " void bar() {"
+ PMD.EOL + " @SuppressWarnings('PMD') Integer foo;" + PMD.EOL + " }" + PMD.EOL + "}";

private static final String TEST9 = "public class Bar {" + PMD.EOL + " Integer foo;" + PMD.EOL + " void bar() {"
+ PMD.EOL + " @SuppressWarnings('PMD.NoFoo') Integer foo;" + PMD.EOL + " }" + PMD.EOL + "}";

private static final String TEST9_MULTIPLE_VALUES = "@SuppressWarnings('PMD.NoFoo, PMD.NoBar')"
+ PMD.EOL + "public class Bar {" + PMD.EOL + " Integer foo;" + PMD.EOL + " void bar() {" + PMD.EOL
+ " Integer foo;" + PMD.EOL + " }" + PMD.EOL + "}";

private static final String TEST10 = "public class Bar {" + PMD.EOL + " Integer foo;" + PMD.EOL + " void bar() {"
+ PMD.EOL + " @SuppressWarnings('') Integer foo;" + PMD.EOL + " }" + PMD.EOL + "}";

private static final String TEST11 = "public class Bar {" + PMD.EOL + " Integer foo;" + PMD.EOL + " void bar() {"
+ PMD.EOL + " @SuppressWarnings('SomethingElse') Integer foo;" + PMD.EOL + " }" + PMD.EOL + "}";

private static final String TEST12 = "public class Bar {" + PMD.EOL + " @SuppressWarnings('all') Integer foo;"
+ PMD.EOL + "}";

private static final String TEST13 = "@SuppressWarnings('PMD.NoBar')" + PMD.EOL + "public class Bar {" + PMD.EOL
+ "}";

private static final String TEST14 = "public class Bar {" + PMD.EOL + "Integer foo; // NOPMD" + PMD.EOL + "}";

private static final String TEST15 = "public class Bar {" + PMD.EOL + "Integer foo; //NOPMD We allow foo here" + PMD.EOL + "}";
}
62 changes: 0 additions & 62 deletions pmd-core/src/main/java/net/sourceforge/pmd/PMD.java
Original file line number Diff line number Diff line change
@@ -4,25 +4,18 @@

package net.sourceforge.pmd;

import static net.sourceforge.pmd.util.CollectionUtil.listOf;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.stream.Collectors;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;

import net.sourceforge.pmd.Report.GlobalReportBuilderListener;
import net.sourceforge.pmd.benchmark.TextTimingReportRenderer;
import net.sourceforge.pmd.benchmark.TimeTracker;
import net.sourceforge.pmd.benchmark.TimingReport;
@@ -31,10 +24,7 @@
import net.sourceforge.pmd.cli.PmdParametersParseResult;
import net.sourceforge.pmd.internal.LogMessages;
import net.sourceforge.pmd.internal.Slf4jSimpleConfiguration;
import net.sourceforge.pmd.lang.document.TextFile;
import net.sourceforge.pmd.renderers.Renderer;
import net.sourceforge.pmd.reporting.ReportStats;
import net.sourceforge.pmd.util.datasource.DataSource;
import net.sourceforge.pmd.util.log.MessageReporter;
import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter;

@@ -56,61 +46,9 @@ public final class PMD {
// not final, in order to re-initialize logging
private static Logger log = LoggerFactory.getLogger(PMD_PACKAGE);

/**
* The line delimiter used by PMD in outputs. Usually the platform specific
* line separator.
*
* @deprecated Use {@link System#lineSeparator()}
*/
@Deprecated
public static final String EOL = System.lineSeparator();

/**
* The default suppress marker string.
*
* @deprecated Use {@link PMDConfiguration#DEFAULT_SUPPRESS_MARKER}
*/
@Deprecated
public static final String SUPPRESS_MARKER = PMDConfiguration.DEFAULT_SUPPRESS_MARKER;

private PMD() {
}

/**
* Run PMD using the given configuration. This replaces the other overload.
*
* @param configuration Configuration for the run. Note that the files,
* and rulesets, are ignored, as they are supplied
* as parameters
* @param ruleSets Parsed rulesets
* @param files Files to process, will be closed by this method.
* @param renderers Renderers that render the report (may be empty)
*
* @return Report in which violations are accumulated
*
* @throws Exception If there was a problem when opening or closing the renderers
* @deprecated Use {@link PmdAnalysis}
*/
@Deprecated
public static Report processFiles(PMDConfiguration configuration,
List<RuleSet> ruleSets,
Collection<? extends DataSource> files,
List<Renderer> renderers) throws Exception {

try (PmdAnalysis pmd = PmdAnalysis.create(configuration)) {
pmd.addRuleSets(ruleSets);
pmd.addRenderers(renderers);
@SuppressWarnings("PMD.CloseResource")
GlobalReportBuilderListener reportBuilder = new GlobalReportBuilderListener();
List<TextFile> sortedFiles = files.stream()
.map(ds -> TextFile.dataSourceCompat(ds, configuration))
.sorted(Comparator.comparing(TextFile::getPathId))
.collect(Collectors.toList());
pmd.performAnalysisImpl(listOf(reportBuilder), sortedFiles);
return reportBuilder.getResult();
}
}

/**
* Entry to invoke PMD as command line tool. Note that this will
* invoke {@link System#exit(int)}.
Loading
Oops, something went wrong.

0 comments on commit 4a14cb7

Please sign in to comment.