From 6c95689ed3a1d7a5d5ef0917d2139557ac2c0baf Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 9 Feb 2023 12:07:11 +0100 Subject: [PATCH 01/12] [core] Require explicit language versions (#4120) --- .../java/net/sourceforge/pmd/lang/LanguageModuleBase.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageModuleBase.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageModuleBase.java index 8133d732fb..8d4c648666 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageModuleBase.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageModuleBase.java @@ -290,7 +290,7 @@ public abstract class LanguageModuleBase implements Language { * @param aliases Additional names that are mapped to this version. Must contain no spaces. * * @throws NullPointerException If any parameter is null - * @throws IllegalArgumentException If the name or aliases contain spaces + * @throws IllegalArgumentException If the name or aliases are empty or contain spaces */ public LanguageMetadata addVersion(String name, String... aliases) { @@ -305,7 +305,7 @@ public abstract class LanguageModuleBase implements Language { * @param aliases Additional names that are mapped to this version. Must contain no spaces. * * @throws NullPointerException If any parameter is null - * @throws IllegalArgumentException If the name or aliases contain spaces + * @throws IllegalArgumentException If the name or aliases are empty or contain spaces */ public LanguageMetadata addDefaultVersion(String name, String... aliases) { versionMetadata.add(new LangVersionMetadata(name, Arrays.asList(aliases), true)); @@ -351,7 +351,7 @@ public abstract class LanguageModuleBase implements Language { } private static void checkVersionName(String name) { - if (SPACE_PAT.matcher(name).find()) { // TODO #4120 also check that the name is non-empty + if (StringUtils.isBlank(name) || SPACE_PAT.matcher(name).find()) { throw new IllegalArgumentException("Invalid version name: " + StringUtil.inSingleQuotes(name)); } } From d7d2ad541e835130678acf960927879c80140551 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 9 Feb 2023 12:15:43 +0100 Subject: [PATCH 02/12] Add explicit language versions (#4120) --- .../pmd/lang/apex/ApexLanguageModule.java | 19 ++++++++++--- .../pmd/lang/apex/LanguageVersionTest.java | 4 +-- .../pmd/lang/PlainTextLanguage.java | 4 ++- .../pmd/it/BinaryDistributionIT.java | 27 ++++++++++++++----- .../pmd/lang/html/HtmlLanguageModule.java | 4 ++- .../pmd/lang/html/LanguageVersionTest.java | 2 +- .../ecmascript/EcmascriptLanguageModule.java | 7 ++++- .../lang/ecmascript/ast/EcmascriptParser.java | 16 ++++++++--- .../lang/ecmascript/LanguageVersionTest.java | 2 +- .../pmd/lang/jsp/JspLanguageModule.java | 4 ++- .../pmd/lang/jsp/LanguageVersionTest.java | 2 +- .../pmd/lang/kotlin/KotlinLanguageModule.java | 4 +-- .../pmd/lang/kotlin/LanguageVersionTest.java | 4 +-- .../lang/modelica/ModelicaLanguageModule.java | 5 +++- .../lang/modelica/LanguageVersionTest.java | 2 +- .../pmd/lang/plsql/PLSQLLanguageModule.java | 8 +++++- .../pmd/lang/plsql/LanguageVersionTest.java | 2 +- .../pmd/lang/swift/SwiftLanguageModule.java | 13 ++++++++- .../pmd/lang/swift/LanguageVersionTest.java | 2 +- .../pmd/lang/vf/VfLanguageModule.java | 15 ++++++++--- .../pmd/lang/vf/LanguageVersionTest.java | 6 +++-- .../pmd/lang/vm/VmLanguageModule.java | 8 +++++- .../pmd/lang/vm/LanguageVersionTest.java | 2 +- .../pmd/lang/pom/PomLanguageModule.java | 5 +++- .../pmd/lang/wsdl/WsdlLanguageModule.java | 6 ++++- .../pmd/lang/xml/XmlLanguageModule.java | 6 ++++- .../pmd/lang/xsl/XslLanguageModule.java | 7 ++++- .../pmd/lang/xml/LanguageVersionTest.java | 8 +++--- .../sourceforge/pmd/ant/xml/pmdtasktest.xml | 2 +- 29 files changed, 146 insertions(+), 50 deletions(-) diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java index 7b57934bd7..a5fca0cce0 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java @@ -4,22 +4,33 @@ package net.sourceforge.pmd.lang.apex; +import static net.sourceforge.pmd.util.CollectionUtil.listOf; + +import java.util.List; + import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageModuleBase; import net.sourceforge.pmd.lang.LanguageProcessor; import net.sourceforge.pmd.lang.LanguagePropertyBundle; import net.sourceforge.pmd.lang.LanguageRegistry; -import apex.jorje.services.Version; - public class ApexLanguageModule extends LanguageModuleBase { public static final String NAME = "Apex"; public static final String TERSE_NAME = "apex"; + public static final List VERSIONS = listOf("52", "53", "54", "55", "56", "57"); + public ApexLanguageModule() { - super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("cls", "trigger") - .addDefaultVersion(String.valueOf((int) Version.CURRENT.getExternal()))); + super(createMetadata()); + } + + private static LanguageMetadata createMetadata() { + LanguageMetadata languageMetadata = LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("cls", "trigger"); + int lastVersion = VERSIONS.size() - 1; + VERSIONS.subList(0, lastVersion).forEach(languageMetadata::addVersion); + languageMetadata.addDefaultVersion(VERSIONS.get(lastVersion)); + return languageMetadata; } @Override diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/LanguageVersionTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/LanguageVersionTest.java index fe132bcb61..0379b1a16a 100644 --- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/LanguageVersionTest.java +++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/LanguageVersionTest.java @@ -12,7 +12,7 @@ import net.sourceforge.pmd.AbstractLanguageVersionTest; class LanguageVersionTest extends AbstractLanguageVersionTest { static Collection data() { - return Arrays.asList(new TestDescriptor(ApexLanguageModule.NAME, ApexLanguageModule.TERSE_NAME, "35", - getLanguage("Apex").getVersion("35"))); + return Arrays.asList(new TestDescriptor(ApexLanguageModule.NAME, ApexLanguageModule.TERSE_NAME, "57", + ApexLanguageModule.getInstance().getDefaultVersion())); } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/PlainTextLanguage.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/PlainTextLanguage.java index 29afc7d45d..3c14dd61de 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/PlainTextLanguage.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/PlainTextLanguage.java @@ -31,7 +31,9 @@ public final class PlainTextLanguage extends SimpleLanguageModuleBase { static final String TERSE_NAME = "text"; private PlainTextLanguage() { - super(LanguageMetadata.withId(TERSE_NAME).name("Plain text").extensions("plain-text-file-goo-extension"), + super(LanguageMetadata.withId(TERSE_NAME).name("Plain text") + .extensions("plain-text-file-goo-extension") + .addDefaultVersion("default"), new TextLvh()); } diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java index cf6304f58a..46d3e81ac2 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java @@ -30,16 +30,29 @@ class BinaryDistributionIT extends AbstractBinaryDistributionTest { + " kotlin, lua, matlab, modelica, objectivec, perl," + System.lineSeparator() + " php, plsql, python, ruby, scala, swift, tsql," + System.lineSeparator() + " vf, xml"; - SUPPORTED_LANGUAGES_PMD = "Valid values: apex-54, ecmascript-ES6, html-," + System.lineSeparator() - + " java-1.10, java-1.3, java-1.4, java-1.5, java-1." + System.lineSeparator() - + " 6, java-1.7, java-1.8, java-1.9, java-10," + System.lineSeparator() + SUPPORTED_LANGUAGES_PMD = "Valid values: apex-52, apex-53, apex-54, apex-55," + System.lineSeparator() + + " apex-56, apex-57, ecmascript-3, ecmascript-5," + System.lineSeparator() + + " ecmascript-6, ecmascript-7, ecmascript-8," + System.lineSeparator() + + " ecmascript-9, ecmascript-ES2015," + System.lineSeparator() + + " ecmascript-ES2016, ecmascript-ES2017," + System.lineSeparator() + + " ecmascript-ES2018, ecmascript-ES6, html-4," + System.lineSeparator() + + " html-5, java-1.10, java-1.3, java-1.4, java-1.5," + System.lineSeparator() + + " java-1.6, java-1.7, java-1.8, java-1.9, java-10," + System.lineSeparator() + " java-11, java-12, java-13, java-14, java-15," + System.lineSeparator() + " java-16, java-17, java-18, java-18-preview," + System.lineSeparator() + " java-19, java-19-preview, java-5, java-6, java-7," + System.lineSeparator() - + " java-8, java-9, jsp-, kotlin-1.6, kotlin-1." + System.lineSeparator() - + " 6-rfc+0.1, modelica-, plsql-, pom-, scala-2.10," + System.lineSeparator() - + " scala-2.11, scala-2.12, scala-2.13, swift-, vf-," + System.lineSeparator() - + " vm-, wsdl-, xml-, xsl-"; + + " java-8, java-9, jsp-2, jsp-3, kotlin-1.6," + System.lineSeparator() + + " kotlin-1.7, modelica-3.4, modelica-3.5," + System.lineSeparator() + + " plsql-11g, plsql-12.1, plsql-12.2," + System.lineSeparator() + + " plsql-12c_Release_1, plsql-12c_Release_2," + System.lineSeparator() + + " plsql-18c, plsql-19c, plsql-21c, pom-4.0.0," + System.lineSeparator() + + " scala-2.10, scala-2.11, scala-2.12, scala-2.13," + System.lineSeparator() + + " swift-4.2, swift-5.0, swift-5.1, swift-5.2," + System.lineSeparator() + + " swift-5.3, swift-5.4, swift-5.5, swift-5.6," + System.lineSeparator() + + " swift-5.7, vf-52, vf-53, vf-54, vf-55, vf-56," + System.lineSeparator() + + " vf-57, vm-2.0, vm-2.1, vm-2.2, vm-2.3, wsdl-1.1," + System.lineSeparator() + + " wsdl-2.0, xml-1.0, xml-1.1, xsl-1.0, xsl-2.0," + System.lineSeparator() + + " xsl-3.0"; } private final String srcDir = new File(".", "src/test/resources/sample-source/java/").getAbsolutePath(); diff --git a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java index f242c180be..e93401e190 100644 --- a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java +++ b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java @@ -15,7 +15,9 @@ public final class HtmlLanguageModule extends SimpleLanguageModuleBase { public HtmlLanguageModule() { super(LanguageMetadata.withId(TERSE_NAME).name(NAME) - .extensions("html", "htm", "xhtml", "xht", "shtml"), + .extensions("html", "htm", "xhtml", "xht", "shtml") + .addVersion("4") + .addDefaultVersion("5"), new HtmlHandler()); } diff --git a/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/LanguageVersionTest.java b/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/LanguageVersionTest.java index c1baee0c98..3534875ac5 100644 --- a/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/LanguageVersionTest.java +++ b/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/LanguageVersionTest.java @@ -12,7 +12,7 @@ import net.sourceforge.pmd.AbstractLanguageVersionTest; class LanguageVersionTest extends AbstractLanguageVersionTest { static Collection data() { - return Arrays.asList(new TestDescriptor(HtmlLanguageModule.NAME, HtmlLanguageModule.TERSE_NAME, "", + return Arrays.asList(new TestDescriptor(HtmlLanguageModule.NAME, HtmlLanguageModule.TERSE_NAME, "5", getLanguage(HtmlLanguageModule.NAME).getDefaultVersion())); } } diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java index e73a983d37..ea4ed73860 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java @@ -19,7 +19,12 @@ public class EcmascriptLanguageModule extends SimpleLanguageModuleBase { public EcmascriptLanguageModule() { super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("js") - .addDefaultVersion("ES6"), + .addVersion("3") + .addVersion("5") + .addVersion("6", "ES6", "ES2015") + .addVersion("7", "ES2016") + .addVersion("8", "ES2017") + .addDefaultVersion("9", "ES2018"), properties -> () -> new EcmascriptParser(properties)); } diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParser.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParser.java index bb80c84d5b..6f6c00b5f8 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParser.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParser.java @@ -18,6 +18,7 @@ import org.mozilla.javascript.ast.ErrorCollector; import org.mozilla.javascript.ast.ParseProblem; import net.sourceforge.pmd.lang.LanguagePropertyBundle; +import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.ast.AstInfo; import net.sourceforge.pmd.lang.ast.FileAnalysisException; import net.sourceforge.pmd.lang.ast.ParseException; @@ -30,11 +31,11 @@ public final class EcmascriptParser implements net.sourceforge.pmd.lang.ast.Pars this.properties = properties; } - private AstRoot parseEcmascript(final String sourceCode, final List parseProblems) throws ParseException { + private AstRoot parseEcmascript(final String sourceCode, final LanguageVersion version, final List parseProblems) throws ParseException { final CompilerEnvirons compilerEnvirons = new CompilerEnvirons(); compilerEnvirons.setRecordingComments(true); compilerEnvirons.setRecordingLocalJsDocComments(true); - compilerEnvirons.setLanguageVersion(Context.VERSION_ES6); + compilerEnvirons.setLanguageVersion(determineRhinoLanguageVersion(version)); // Scope's don't appear to get set right without this compilerEnvirons.setIdeMode(true); compilerEnvirons.setWarnTrailingComma(true); @@ -52,10 +53,19 @@ public final class EcmascriptParser implements net.sourceforge.pmd.lang.ast.Pars return astRoot; } + private static int determineRhinoLanguageVersion(LanguageVersion version) { + switch (version.getVersion()) { + case "3": return Context.VERSION_1_5; + case "5": return Context.VERSION_1_8; + default: return Context.VERSION_ES6; + } + } + @Override public RootNode parse(ParserTask task) throws FileAnalysisException { + final LanguageVersion version = task.getLanguageVersion(); final List parseProblems = new ArrayList<>(); - final AstRoot astRoot = parseEcmascript(task.getSourceText(), parseProblems); + final AstRoot astRoot = parseEcmascript(task.getSourceText(), version, parseProblems); final EcmascriptTreeBuilder treeBuilder = new EcmascriptTreeBuilder(parseProblems); ASTAstRoot tree = (ASTAstRoot) treeBuilder.build(astRoot); diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/LanguageVersionTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/LanguageVersionTest.java index 5df250aff5..73a35e13db 100644 --- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/LanguageVersionTest.java +++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/LanguageVersionTest.java @@ -13,7 +13,7 @@ class LanguageVersionTest extends AbstractLanguageVersionTest { static Collection data() { return Arrays.asList( - new TestDescriptor(EcmascriptLanguageModule.NAME, EcmascriptLanguageModule.TERSE_NAME, "ES6", + new TestDescriptor(EcmascriptLanguageModule.NAME, EcmascriptLanguageModule.TERSE_NAME, "9", getLanguage(EcmascriptLanguageModule.NAME).getDefaultVersion())); } } diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspLanguageModule.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspLanguageModule.java index 573a42b94c..d36076551d 100644 --- a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspLanguageModule.java +++ b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspLanguageModule.java @@ -16,7 +16,9 @@ public class JspLanguageModule extends SimpleLanguageModuleBase { public JspLanguageModule() { super(LanguageMetadata.withId(TERSE_NAME).name(NAME).shortName("JSP") - .extensions("jsp", "jspx", "jspf", "tag"), + .extensions("jsp", "jspx", "jspf", "tag") + .addVersion("2") + .addDefaultVersion("3"), new JspHandler()); } diff --git a/pmd-jsp/src/test/java/net/sourceforge/pmd/lang/jsp/LanguageVersionTest.java b/pmd-jsp/src/test/java/net/sourceforge/pmd/lang/jsp/LanguageVersionTest.java index 4707c22101..ed81a65e96 100644 --- a/pmd-jsp/src/test/java/net/sourceforge/pmd/lang/jsp/LanguageVersionTest.java +++ b/pmd-jsp/src/test/java/net/sourceforge/pmd/lang/jsp/LanguageVersionTest.java @@ -12,7 +12,7 @@ import net.sourceforge.pmd.AbstractLanguageVersionTest; class LanguageVersionTest extends AbstractLanguageVersionTest { static Collection data() { - return Arrays.asList(new TestDescriptor(JspLanguageModule.NAME, JspLanguageModule.TERSE_NAME, "", + return Arrays.asList(new TestDescriptor(JspLanguageModule.NAME, JspLanguageModule.TERSE_NAME, "3", getLanguage(JspLanguageModule.NAME).getDefaultVersion())); } } diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java index 31e0d209d4..d82342bc4e 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java @@ -25,8 +25,8 @@ public class KotlinLanguageModule extends SimpleLanguageModuleBase { */ public KotlinLanguageModule() { super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("kt", "ktm") - .addDefaultVersion("1.6-rfc+0.1", "1.6"), + .addVersion("1.6") + .addDefaultVersion("1.7"), new KotlinHandler()); - } } diff --git a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/LanguageVersionTest.java b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/LanguageVersionTest.java index 9417c8b537..5a6956aa8e 100644 --- a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/LanguageVersionTest.java +++ b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/LanguageVersionTest.java @@ -13,9 +13,7 @@ class LanguageVersionTest extends AbstractLanguageVersionTest { static Collection data() { return Arrays.asList( - new TestDescriptor(KotlinLanguageModule.NAME, KotlinLanguageModule.TERSE_NAME, "1.6-rfc+0.1", - getLanguage(KotlinLanguageModule.NAME).getDefaultVersion()), - new TestDescriptor(KotlinLanguageModule.NAME, KotlinLanguageModule.TERSE_NAME, "1.6", + new TestDescriptor(KotlinLanguageModule.NAME, KotlinLanguageModule.TERSE_NAME, "1.7", getLanguage(KotlinLanguageModule.NAME).getDefaultVersion())); } } diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ModelicaLanguageModule.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ModelicaLanguageModule.java index 2746c21363..290533ba0d 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ModelicaLanguageModule.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ModelicaLanguageModule.java @@ -11,7 +11,10 @@ public class ModelicaLanguageModule extends SimpleLanguageModuleBase { public static final String TERSE_NAME = "modelica"; public ModelicaLanguageModule() { - super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("mo"), + super(LanguageMetadata.withId(TERSE_NAME).name(NAME) + .extensions("mo") + .addVersion("3.4") + .addDefaultVersion("3.5"), new ModelicaHandler()); } diff --git a/pmd-modelica/src/test/java/net/sourceforge/pmd/lang/modelica/LanguageVersionTest.java b/pmd-modelica/src/test/java/net/sourceforge/pmd/lang/modelica/LanguageVersionTest.java index 367e843585..f06c1c8a1a 100644 --- a/pmd-modelica/src/test/java/net/sourceforge/pmd/lang/modelica/LanguageVersionTest.java +++ b/pmd-modelica/src/test/java/net/sourceforge/pmd/lang/modelica/LanguageVersionTest.java @@ -12,7 +12,7 @@ import net.sourceforge.pmd.AbstractLanguageVersionTest; class LanguageVersionTest extends AbstractLanguageVersionTest { static Collection data() { - return Arrays.asList(new TestDescriptor(ModelicaLanguageModule.NAME, ModelicaLanguageModule.TERSE_NAME, "", + return Arrays.asList(new TestDescriptor(ModelicaLanguageModule.NAME, ModelicaLanguageModule.TERSE_NAME, "3.5", getLanguage(ModelicaLanguageModule.NAME).getDefaultVersion())); } } diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLLanguageModule.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLLanguageModule.java index 0b74d631c2..6422362df0 100644 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLLanguageModule.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLLanguageModule.java @@ -27,7 +27,13 @@ public class PLSQLLanguageModule extends SimpleLanguageModuleBase { "pck", "pks", "pkh", "pkb", // Packages "typ", "tyb", // Object Types "tps", "tpb" // Object Types - ), + ) + .addVersion("11g") + .addVersion("12c_Release_1", "12.1") + .addVersion("12c_Release_2", "12.2") + .addVersion("18c") + .addVersion("19c") + .addDefaultVersion("21c"), new PLSQLHandler() ); } diff --git a/pmd-plsql/src/test/java/net/sourceforge/pmd/lang/plsql/LanguageVersionTest.java b/pmd-plsql/src/test/java/net/sourceforge/pmd/lang/plsql/LanguageVersionTest.java index f28d58964e..886b4c5fe5 100644 --- a/pmd-plsql/src/test/java/net/sourceforge/pmd/lang/plsql/LanguageVersionTest.java +++ b/pmd-plsql/src/test/java/net/sourceforge/pmd/lang/plsql/LanguageVersionTest.java @@ -12,7 +12,7 @@ import net.sourceforge.pmd.AbstractLanguageVersionTest; class LanguageVersionTest extends AbstractLanguageVersionTest { static Collection data() { - return Arrays.asList(new TestDescriptor(PLSQLLanguageModule.NAME, PLSQLLanguageModule.TERSE_NAME, "", + return Arrays.asList(new TestDescriptor(PLSQLLanguageModule.NAME, PLSQLLanguageModule.TERSE_NAME, "21c", getLanguage(PLSQLLanguageModule.NAME).getDefaultVersion())); } } diff --git a/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftLanguageModule.java b/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftLanguageModule.java index 1b05e94b4b..5e94c303f0 100644 --- a/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftLanguageModule.java +++ b/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftLanguageModule.java @@ -20,6 +20,17 @@ public class SwiftLanguageModule extends SimpleLanguageModuleBase { * Create a new instance of Swift Language Module. */ public SwiftLanguageModule() { - super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("swift"), new SwiftHandler()); + super(LanguageMetadata.withId(TERSE_NAME).name(NAME) + .extensions("swift") + .addVersion("4.2") + .addVersion("5.0") + .addVersion("5.1") + .addVersion("5.2") + .addVersion("5.3") + .addVersion("5.4") + .addVersion("5.5") + .addVersion("5.6") + .addDefaultVersion("5.7"), + new SwiftHandler()); } } diff --git a/pmd-swift/src/test/java/net/sourceforge/pmd/lang/swift/LanguageVersionTest.java b/pmd-swift/src/test/java/net/sourceforge/pmd/lang/swift/LanguageVersionTest.java index e56e9f3ca9..9f5302ba72 100644 --- a/pmd-swift/src/test/java/net/sourceforge/pmd/lang/swift/LanguageVersionTest.java +++ b/pmd-swift/src/test/java/net/sourceforge/pmd/lang/swift/LanguageVersionTest.java @@ -12,7 +12,7 @@ import net.sourceforge.pmd.AbstractLanguageVersionTest; class LanguageVersionTest extends AbstractLanguageVersionTest { static Collection data() { - return Arrays.asList(new TestDescriptor(SwiftLanguageModule.NAME, SwiftLanguageModule.TERSE_NAME, "", + return Arrays.asList(new TestDescriptor(SwiftLanguageModule.NAME, SwiftLanguageModule.TERSE_NAME, "5.7", getLanguage(SwiftLanguageModule.NAME).getDefaultVersion())); } } diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfLanguageModule.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfLanguageModule.java index b75d9ffba6..3223c311d2 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfLanguageModule.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfLanguageModule.java @@ -20,12 +20,21 @@ public class VfLanguageModule extends SimpleLanguageModuleBase { public static final String TERSE_NAME = "vf"; public VfLanguageModule() { - super(LanguageMetadata.withId(TERSE_NAME).name(NAME) - .extensions("page", "component") - .dependsOnLanguage(ApexLanguageModule.TERSE_NAME), + super(createMetdata(), p -> new VfHandler((VfLanguageProperties) p)); } + private static LanguageMetadata createMetdata() { + LanguageMetadata languageMetadata = LanguageMetadata.withId(TERSE_NAME).name(NAME) + .extensions("page", "component") + .dependsOnLanguage(ApexLanguageModule.TERSE_NAME); + // use the same versions as in Apex + int lastVersion = ApexLanguageModule.VERSIONS.size() - 1; + ApexLanguageModule.VERSIONS.subList(0, lastVersion).forEach(languageMetadata::addVersion); + languageMetadata.addDefaultVersion(ApexLanguageModule.VERSIONS.get(lastVersion)); + return languageMetadata; + } + @Override public LanguagePropertyBundle newPropertyBundle() { return new VfLanguageProperties(); diff --git a/pmd-visualforce/src/test/java/net/sourceforge/pmd/lang/vf/LanguageVersionTest.java b/pmd-visualforce/src/test/java/net/sourceforge/pmd/lang/vf/LanguageVersionTest.java index 141d62ed8c..38c68b028a 100644 --- a/pmd-visualforce/src/test/java/net/sourceforge/pmd/lang/vf/LanguageVersionTest.java +++ b/pmd-visualforce/src/test/java/net/sourceforge/pmd/lang/vf/LanguageVersionTest.java @@ -8,11 +8,13 @@ import java.util.Arrays; import java.util.Collection; import net.sourceforge.pmd.AbstractLanguageVersionTest; +import net.sourceforge.pmd.lang.apex.ApexLanguageModule; class LanguageVersionTest extends AbstractLanguageVersionTest { static Collection data() { - return Arrays.asList(new TestDescriptor(VfLanguageModule.NAME, VfLanguageModule.TERSE_NAME, "", - getLanguage(VfLanguageModule.NAME).getDefaultVersion())); + return Arrays.asList(new TestDescriptor(VfLanguageModule.NAME, VfLanguageModule.TERSE_NAME, + ApexLanguageModule.getInstance().getDefaultVersion().getVersion(), + getLanguage(VfLanguageModule.NAME).getDefaultVersion())); } } diff --git a/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/VmLanguageModule.java b/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/VmLanguageModule.java index 553fb8a4e8..0cc028c236 100644 --- a/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/VmLanguageModule.java +++ b/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/VmLanguageModule.java @@ -15,7 +15,13 @@ public class VmLanguageModule extends SimpleLanguageModuleBase { public static final String TERSE_NAME = "vm"; public VmLanguageModule() { - super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("vm"), new VmHandler()); + super(LanguageMetadata.withId(TERSE_NAME).name(NAME) + .extensions("vm") + .addVersion("2.0") + .addVersion("2.1") + .addVersion("2.2") + .addDefaultVersion("2.3"), + new VmHandler()); } } diff --git a/pmd-vm/src/test/java/net/sourceforge/pmd/lang/vm/LanguageVersionTest.java b/pmd-vm/src/test/java/net/sourceforge/pmd/lang/vm/LanguageVersionTest.java index 2e5645fc11..32f4877901 100644 --- a/pmd-vm/src/test/java/net/sourceforge/pmd/lang/vm/LanguageVersionTest.java +++ b/pmd-vm/src/test/java/net/sourceforge/pmd/lang/vm/LanguageVersionTest.java @@ -12,7 +12,7 @@ import net.sourceforge.pmd.AbstractLanguageVersionTest; class LanguageVersionTest extends AbstractLanguageVersionTest { static Collection data() { - return Arrays.asList(new TestDescriptor(VmLanguageModule.NAME, VmLanguageModule.TERSE_NAME, "", + return Arrays.asList(new TestDescriptor(VmLanguageModule.NAME, VmLanguageModule.TERSE_NAME, "2.3", getLanguage(VmLanguageModule.NAME).getDefaultVersion())); } } diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/pom/PomLanguageModule.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/pom/PomLanguageModule.java index 7de4d4da0b..9f91051657 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/pom/PomLanguageModule.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/pom/PomLanguageModule.java @@ -12,7 +12,10 @@ public class PomLanguageModule extends SimpleLanguageModuleBase { public static final String TERSE_NAME = "pom"; public PomLanguageModule() { - super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("pom"), new XmlHandler()); + super(LanguageMetadata.withId(TERSE_NAME).name(NAME) + .extensions("pom") + .addDefaultVersion("4.0.0"), + new XmlHandler()); } } diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/wsdl/WsdlLanguageModule.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/wsdl/WsdlLanguageModule.java index ed9512d1cb..f48d4c9ddd 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/wsdl/WsdlLanguageModule.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/wsdl/WsdlLanguageModule.java @@ -15,7 +15,11 @@ public class WsdlLanguageModule extends SimpleLanguageModuleBase { public static final String TERSE_NAME = "wsdl"; public WsdlLanguageModule() { - super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("wsdl"), new XmlHandler()); + super(LanguageMetadata.withId(TERSE_NAME).name(NAME) + .extensions("wsdl") + .addVersion("1.1") + .addDefaultVersion("2.0"), + new XmlHandler()); } } diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlLanguageModule.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlLanguageModule.java index 5df4a35b06..21bf0e22bc 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlLanguageModule.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlLanguageModule.java @@ -15,6 +15,10 @@ public class XmlLanguageModule extends SimpleLanguageModuleBase { public static final String TERSE_NAME = "xml"; public XmlLanguageModule() { - super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("xml"), new XmlHandler()); + super(LanguageMetadata.withId(TERSE_NAME).name(NAME) + .extensions("xml") + .addVersion("1.0") + .addDefaultVersion("1.1"), + new XmlHandler()); } } diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xsl/XslLanguageModule.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xsl/XslLanguageModule.java index c51c48096a..ce0b833b44 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xsl/XslLanguageModule.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xsl/XslLanguageModule.java @@ -16,7 +16,12 @@ public class XslLanguageModule extends SimpleLanguageModuleBase { public static final String TERSE_NAME = "xsl"; public XslLanguageModule() { - super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("xsl", "xslt"), new XmlHandler()); + super(LanguageMetadata.withId(TERSE_NAME).name(NAME) + .extensions("xsl", "xslt") + .addVersion("1.0") + .addVersion("2.0") + .addDefaultVersion("3.0"), + new XmlHandler()); } } diff --git a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/LanguageVersionTest.java b/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/LanguageVersionTest.java index 4e4816f7fb..0654616943 100644 --- a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/LanguageVersionTest.java +++ b/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/LanguageVersionTest.java @@ -16,13 +16,13 @@ class LanguageVersionTest extends AbstractLanguageVersionTest { static Collection data() { return Arrays.asList( - new TestDescriptor(XmlLanguageModule.NAME, XmlLanguageModule.TERSE_NAME, "", + new TestDescriptor(XmlLanguageModule.NAME, XmlLanguageModule.TERSE_NAME, "1.1", getLanguage(XmlLanguageModule.NAME).getDefaultVersion()), - new TestDescriptor(XslLanguageModule.NAME, XslLanguageModule.TERSE_NAME, "", + new TestDescriptor(XslLanguageModule.NAME, XslLanguageModule.TERSE_NAME, "3.0", getLanguage(XslLanguageModule.NAME).getDefaultVersion()), - new TestDescriptor(WsdlLanguageModule.NAME, WsdlLanguageModule.TERSE_NAME, "", + new TestDescriptor(WsdlLanguageModule.NAME, WsdlLanguageModule.TERSE_NAME, "2.0", getLanguage(WsdlLanguageModule.NAME).getDefaultVersion()), - new TestDescriptor(PomLanguageModule.NAME, PomLanguageModule.TERSE_NAME, "", + new TestDescriptor(PomLanguageModule.NAME, PomLanguageModule.TERSE_NAME, "4.0.0", getLanguage(PomLanguageModule.NAME).getDefaultVersion())); } } diff --git a/pmd-xml/src/test/resources/net/sourceforge/pmd/ant/xml/pmdtasktest.xml b/pmd-xml/src/test/resources/net/sourceforge/pmd/ant/xml/pmdtasktest.xml index 52ba35fc8c..db7406fb77 100644 --- a/pmd-xml/src/test/resources/net/sourceforge/pmd/ant/xml/pmdtasktest.xml +++ b/pmd-xml/src/test/resources/net/sourceforge/pmd/ant/xml/pmdtasktest.xml @@ -7,7 +7,7 @@ - + From e2bb0c8480e74cc765166969841c1c941368e60a Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 9 Feb 2023 17:17:37 +0100 Subject: [PATCH 03/12] Reuse names and extensions for CPD language --- docs/_data/sidebars/pmd_sidebar.yml | 36 ++++++++--------- .../net/sourceforge/pmd/cpd/ApexLanguage.java | 4 +- .../pmd/lang/apex/ApexLanguageModule.java | 7 +++- .../sourceforge/pmd/cpd/AbstractLanguage.java | 17 +++++++- .../test/resources/expected/pmd_sidebar.yml | 18 ++++----- .../net/sourceforge/pmd/docs/sidebar.yml | 24 ++++++------ .../pmd/lang/html/HtmlCpdLanguage.java | 2 +- .../pmd/lang/html/HtmlLanguageModule.java | 10 ++++- .../net/sourceforge/pmd/cpd/JavaLanguage.java | 4 +- .../pmd/lang/java/JavaLanguageModule.java | 9 ++++- .../pmd/cpd/EcmascriptLanguage.java | 5 ++- .../ecmascript/EcmascriptLanguageModule.java | 11 +++++- .../net/sourceforge/pmd/cpd/JSPLanguage.java | 4 +- .../pmd/lang/jsp/JspLanguageModule.java | 9 ++++- .../sourceforge/pmd/cpd/KotlinLanguage.java | 4 +- .../pmd/lang/kotlin/KotlinLanguageModule.java | 10 ++++- .../sourceforge/pmd/cpd/ModelicaLanguage.java | 2 +- .../lang/modelica/ModelicaLanguageModule.java | 9 ++++- .../sourceforge/pmd/cpd/PLSQLLanguage.java | 13 ++----- .../pmd/lang/plsql/PLSQLLanguageModule.java | 39 +++++++++++-------- .../sourceforge/pmd/cpd/ScalaLanguage.java | 4 +- .../pmd/lang/scala/ScalaLanguageModule.java | 9 ++++- .../sourceforge/pmd/cpd/SwiftLanguage.java | 4 +- .../pmd/lang/swift/SwiftLanguageModule.java | 10 ++++- .../net/sourceforge/pmd/cpd/VfLanguage.java | 4 +- .../pmd/lang/vf/VfLanguageModule.java | 10 ++++- .../pmd/lang/xml/XmlLanguageModule.java | 9 ++++- .../sourceforge/pmd/xml/cpd/XmlLanguage.java | 3 +- 28 files changed, 198 insertions(+), 92 deletions(-) diff --git a/docs/_data/sidebars/pmd_sidebar.yml b/docs/_data/sidebars/pmd_sidebar.yml index 376df38be3..f0a57382be 100644 --- a/docs/_data/sidebars/pmd_sidebar.yml +++ b/docs/_data/sidebars/pmd_sidebar.yml @@ -160,24 +160,6 @@ entries: - title: Security output: web, pdf url: /pmd_rules_apex_security.html - - title: null - output: web, pdf - subfolders: - - title: Ecmascript Rules - output: web, pdf - subfolderitems: - - title: Index - output: web, pdf - url: /pmd_rules_ecmascript.html - - title: Best Practices - output: web, pdf - url: /pmd_rules_ecmascript_bestpractices.html - - title: Code Style - output: web, pdf - url: /pmd_rules_ecmascript_codestyle.html - - title: Error Prone - output: web, pdf - url: /pmd_rules_ecmascript_errorprone.html - title: null output: web, pdf subfolders: @@ -247,6 +229,24 @@ entries: - title: Security output: web, pdf url: /pmd_rules_jsp_security.html + - title: null + output: web, pdf + subfolders: + - title: JavaScript Rules + output: web, pdf + subfolderitems: + - title: Index + output: web, pdf + url: /pmd_rules_ecmascript.html + - title: Best Practices + output: web, pdf + url: /pmd_rules_ecmascript_bestpractices.html + - title: Code Style + output: web, pdf + url: /pmd_rules_ecmascript_codestyle.html + - title: Error Prone + output: web, pdf + url: /pmd_rules_ecmascript_errorprone.html - title: null output: web, pdf subfolders: diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/cpd/ApexLanguage.java b/pmd-apex/src/main/java/net/sourceforge/pmd/cpd/ApexLanguage.java index 0bb7bd7014..5ca6959052 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/cpd/ApexLanguage.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/cpd/ApexLanguage.java @@ -6,6 +6,8 @@ package net.sourceforge.pmd.cpd; import java.util.Properties; +import net.sourceforge.pmd.lang.apex.ApexLanguageModule; + public class ApexLanguage extends AbstractLanguage { public ApexLanguage() { @@ -13,7 +15,7 @@ public class ApexLanguage extends AbstractLanguage { } public ApexLanguage(Properties properties) { - super("Apex", "apex", new ApexTokenizer(), ".cls"); + super(ApexLanguageModule.NAME, ApexLanguageModule.TERSE_NAME, new ApexTokenizer(), ApexLanguageModule.EXTENSIONS); setProperties(properties); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java index a5fca0cce0..33c9f5b0d6 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java @@ -8,6 +8,7 @@ import static net.sourceforge.pmd.util.CollectionUtil.listOf; import java.util.List; +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageModuleBase; import net.sourceforge.pmd.lang.LanguageProcessor; @@ -19,14 +20,18 @@ public class ApexLanguageModule extends LanguageModuleBase { public static final String NAME = "Apex"; public static final String TERSE_NAME = "apex"; + @InternalApi public static final List VERSIONS = listOf("52", "53", "54", "55", "56", "57"); + @InternalApi + public static final List EXTENSIONS = listOf("cls", "trigger"); public ApexLanguageModule() { super(createMetadata()); } private static LanguageMetadata createMetadata() { - LanguageMetadata languageMetadata = LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("cls", "trigger"); + LanguageMetadata languageMetadata = LanguageMetadata.withId(TERSE_NAME).name(NAME); + languageMetadata.extensions(EXTENSIONS.get(0), EXTENSIONS.subList(0, EXTENSIONS.size()).toArray(new String[0])); int lastVersion = VERSIONS.size() - 1; VERSIONS.subList(0, lastVersion).forEach(languageMetadata::addVersion); languageMetadata.addDefaultVersion(VERSIONS.get(lastVersion)); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AbstractLanguage.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AbstractLanguage.java index 7e08eccf8a..4045ddbf16 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AbstractLanguage.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AbstractLanguage.java @@ -11,6 +11,7 @@ import java.util.Arrays; import java.util.List; import java.util.Properties; import java.util.function.Predicate; +import java.util.stream.Collectors; import net.sourceforge.pmd.internal.util.PredicateUtil; @@ -22,11 +23,23 @@ public abstract class AbstractLanguage implements Language { private final List extensions; public AbstractLanguage(String name, String terseName, Tokenizer tokenizer, String... extensions) { + this(name, terseName, tokenizer, Arrays.asList(extensions)); + } + + protected AbstractLanguage(String name, String terseName, Tokenizer tokenizer, List extensions) { this.name = name; this.terseName = terseName; this.tokenizer = tokenizer; - this.fileFilter = PredicateUtil.toNormalizedFileFilter(PredicateUtil.getFileExtensionFilter(extensions).or(it -> Files.isDirectory(Paths.get(it)))); - this.extensions = Arrays.asList(extensions); + List extensionsWithDot = extensions.stream().map(e -> { + if (e.length() > 0 && e.charAt(0) != '.') { + return "." + e; + } + return e; + }).collect(Collectors.toList()); + this.fileFilter = PredicateUtil.toNormalizedFileFilter( + PredicateUtil.getFileExtensionFilter(extensionsWithDot.toArray(new String[0])) + .or(it -> Files.isDirectory(Paths.get(it)))); + this.extensions = extensionsWithDot; } @Override diff --git a/pmd-doc/src/test/resources/expected/pmd_sidebar.yml b/pmd-doc/src/test/resources/expected/pmd_sidebar.yml index b7ce41869c..685cfc5851 100644 --- a/pmd-doc/src/test/resources/expected/pmd_sidebar.yml +++ b/pmd-doc/src/test/resources/expected/pmd_sidebar.yml @@ -15,15 +15,6 @@ entries: - title: Index output: web, pdf url: /pmd_rules_apex.html - - title: null - output: web, pdf - subfolders: - - title: Ecmascript Rules - output: web, pdf - subfolderitems: - - title: Index - output: web, pdf - url: /pmd_rules_ecmascript.html - title: null output: web, pdf subfolders: @@ -54,6 +45,15 @@ entries: - title: Index output: web, pdf url: /pmd_rules_jsp.html + - title: null + output: web, pdf + subfolders: + - title: JavaScript Rules + output: web, pdf + subfolderitems: + - title: Index + output: web, pdf + url: /pmd_rules_ecmascript.html - title: null output: web, pdf subfolders: diff --git a/pmd-doc/src/test/resources/net/sourceforge/pmd/docs/sidebar.yml b/pmd-doc/src/test/resources/net/sourceforge/pmd/docs/sidebar.yml index 69435aad61..0b8bcc1128 100644 --- a/pmd-doc/src/test/resources/net/sourceforge/pmd/docs/sidebar.yml +++ b/pmd-doc/src/test/resources/net/sourceforge/pmd/docs/sidebar.yml @@ -1,15 +1,3 @@ -- title: null - output: web, pdf - subfolders: - - title: Ecmascript Rules - output: web, pdf - subfolderitems: - - title: Index - output: web, pdf - url: /pmd_rules_ecmascript.html - - title: test - output: web, pdf - url: /pmd_rules_ecmascript_bestpractices.html - title: null output: web, pdf subfolders: @@ -25,6 +13,18 @@ - title: test2 output: web, pdf url: /pmd_rules_java_codestyle.html +- title: null + output: web, pdf + subfolders: + - title: JavaScript Rules + output: web, pdf + subfolderitems: + - title: Index + output: web, pdf + url: /pmd_rules_ecmascript.html + - title: test + output: web, pdf + url: /pmd_rules_ecmascript_bestpractices.html - title: null output: web, pdf subfolders: diff --git a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlCpdLanguage.java b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlCpdLanguage.java index 3c6c0fdbde..740acfff6b 100644 --- a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlCpdLanguage.java +++ b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlCpdLanguage.java @@ -11,6 +11,6 @@ import net.sourceforge.pmd.lang.html.ast.HtmlTokenizer; public final class HtmlCpdLanguage extends AbstractLanguage { public HtmlCpdLanguage() { - super("HTML", "html", new HtmlTokenizer(), ".html"); + super(HtmlLanguageModule.NAME, HtmlLanguageModule.TERSE_NAME, new HtmlTokenizer(), HtmlLanguageModule.EXTENSIONS); } } diff --git a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java index e93401e190..0743f248b9 100644 --- a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java +++ b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java @@ -2,9 +2,13 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ - package net.sourceforge.pmd.lang.html; +import static net.sourceforge.pmd.util.CollectionUtil.listOf; + +import java.util.List; + +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase; @@ -12,10 +16,12 @@ public final class HtmlLanguageModule extends SimpleLanguageModuleBase { public static final String NAME = "HTML"; public static final String TERSE_NAME = "html"; + @InternalApi + public static final List EXTENSIONS = listOf("html", "htm", "xhtml", "xht", "shtml"); public HtmlLanguageModule() { super(LanguageMetadata.withId(TERSE_NAME).name(NAME) - .extensions("html", "htm", "xhtml", "xht", "shtml") + .extensions(EXTENSIONS.get(0), EXTENSIONS.subList(0, EXTENSIONS.size()).toArray(new String[0])) .addVersion("4") .addDefaultVersion("5"), new HtmlHandler()); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/cpd/JavaLanguage.java b/pmd-java/src/main/java/net/sourceforge/pmd/cpd/JavaLanguage.java index 0ff3638c99..2a68ea48a5 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/cpd/JavaLanguage.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/cpd/JavaLanguage.java @@ -6,13 +6,15 @@ package net.sourceforge.pmd.cpd; import java.util.Properties; +import net.sourceforge.pmd.lang.java.JavaLanguageModule; + public class JavaLanguage extends AbstractLanguage { public JavaLanguage() { this(System.getProperties()); } public JavaLanguage(Properties properties) { - super("Java", "java", new JavaTokenizer(), ".java"); + super(JavaLanguageModule.NAME, JavaLanguageModule.TERSE_NAME, new JavaTokenizer(), JavaLanguageModule.EXTENSIONS); setProperties(properties); } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/JavaLanguageModule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/JavaLanguageModule.java index 4bd8bbde05..bc3658ea79 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/JavaLanguageModule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/JavaLanguageModule.java @@ -4,6 +4,11 @@ package net.sourceforge.pmd.lang.java; +import static net.sourceforge.pmd.util.CollectionUtil.listOf; + +import java.util.List; + +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageModuleBase; import net.sourceforge.pmd.lang.LanguageProcessor; @@ -19,9 +24,11 @@ public class JavaLanguageModule extends LanguageModuleBase { public static final String NAME = "Java"; public static final String TERSE_NAME = "java"; + @InternalApi + public static final List EXTENSIONS = listOf("java"); public JavaLanguageModule() { - super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("java") + super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions(EXTENSIONS.get(0)) .addVersion("1.3") .addVersion("1.4") .addVersion("1.5", "5") diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/cpd/EcmascriptLanguage.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/cpd/EcmascriptLanguage.java index 2ad5fd6f41..e7edb068fd 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/cpd/EcmascriptLanguage.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/cpd/EcmascriptLanguage.java @@ -4,12 +4,15 @@ package net.sourceforge.pmd.cpd; +import net.sourceforge.pmd.lang.ecmascript.EcmascriptLanguageModule; + /** * * @author Zev Blut zb@ubit.com */ public class EcmascriptLanguage extends AbstractLanguage { public EcmascriptLanguage() { - super("JavaScript", "ecmascript", new EcmascriptTokenizer(), ".js"); + super(EcmascriptLanguageModule.NAME, EcmascriptLanguageModule.TERSE_NAME, new EcmascriptTokenizer(), + EcmascriptLanguageModule.EXTENSIONS); } } diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java index ea4ed73860..e8c56f48c3 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java @@ -4,6 +4,11 @@ package net.sourceforge.pmd.lang.ecmascript; +import static net.sourceforge.pmd.util.CollectionUtil.listOf; + +import java.util.List; + +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptParser; @@ -14,11 +19,13 @@ import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase; */ public class EcmascriptLanguageModule extends SimpleLanguageModuleBase { - public static final String NAME = "Ecmascript"; + public static final String NAME = "JavaScript"; public static final String TERSE_NAME = "ecmascript"; + @InternalApi + public static final List EXTENSIONS = listOf("js"); public EcmascriptLanguageModule() { - super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("js") + super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions(EXTENSIONS.get(0)) .addVersion("3") .addVersion("5") .addVersion("6", "ES6", "ES2015") diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/cpd/JSPLanguage.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/cpd/JSPLanguage.java index c4c480cecc..26b2ef171d 100644 --- a/pmd-jsp/src/main/java/net/sourceforge/pmd/cpd/JSPLanguage.java +++ b/pmd-jsp/src/main/java/net/sourceforge/pmd/cpd/JSPLanguage.java @@ -4,8 +4,10 @@ package net.sourceforge.pmd.cpd; +import net.sourceforge.pmd.lang.jsp.JspLanguageModule; + public class JSPLanguage extends AbstractLanguage { public JSPLanguage() { - super("JSP", "jsp", new JSPTokenizer(), ".jsp", ".jspx", ".jspf", ".tag"); + super(JspLanguageModule.NAME, JspLanguageModule.TERSE_NAME, new JSPTokenizer(), JspLanguageModule.EXTENSIONS); } } diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspLanguageModule.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspLanguageModule.java index d36076551d..33fb67c449 100644 --- a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspLanguageModule.java +++ b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspLanguageModule.java @@ -4,6 +4,11 @@ package net.sourceforge.pmd.lang.jsp; +import static net.sourceforge.pmd.util.CollectionUtil.listOf; + +import java.util.List; + +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase; /** @@ -13,10 +18,12 @@ public class JspLanguageModule extends SimpleLanguageModuleBase { public static final String NAME = "Java Server Pages"; public static final String TERSE_NAME = "jsp"; + @InternalApi + public static final List EXTENSIONS = listOf("jsp", "jspx", "jspf", "tag"); public JspLanguageModule() { super(LanguageMetadata.withId(TERSE_NAME).name(NAME).shortName("JSP") - .extensions("jsp", "jspx", "jspf", "tag") + .extensions(EXTENSIONS.get(0), EXTENSIONS.toArray(new String[0])) .addVersion("2") .addDefaultVersion("3"), new JspHandler()); diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/cpd/KotlinLanguage.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/cpd/KotlinLanguage.java index 4a14aa766f..1ec0e63349 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/cpd/KotlinLanguage.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/cpd/KotlinLanguage.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.cpd; +import net.sourceforge.pmd.lang.kotlin.KotlinLanguageModule; + /** * Language implementation for Kotlin */ @@ -13,6 +15,6 @@ public class KotlinLanguage extends AbstractLanguage { * Creates a new Kotlin Language instance. */ public KotlinLanguage() { - super("Kotlin", "kotlin", new KotlinTokenizer(), ".kt"); + super(KotlinLanguageModule.NAME, KotlinLanguageModule.TERSE_NAME, new KotlinTokenizer(), KotlinLanguageModule.EXTENSIONS); } } diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java index d82342bc4e..1bdaa924c7 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java @@ -4,7 +4,12 @@ package net.sourceforge.pmd.lang.kotlin; +import static net.sourceforge.pmd.util.CollectionUtil.listOf; + +import java.util.List; + import net.sourceforge.pmd.annotation.Experimental; +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase; /** @@ -20,11 +25,14 @@ public class KotlinLanguageModule extends SimpleLanguageModuleBase { /** The terse name. */ public static final String TERSE_NAME = "kotlin"; + @InternalApi + public static final List EXTENSIONS = listOf("kt", "ktm"); + /** * Create a new instance of Kotlin Language Module. */ public KotlinLanguageModule() { - super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("kt", "ktm") + super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions(EXTENSIONS.get(0), EXTENSIONS.toArray(new String[0])) .addVersion("1.6") .addDefaultVersion("1.7"), new KotlinHandler()); diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/cpd/ModelicaLanguage.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/cpd/ModelicaLanguage.java index 53852955e5..c7c5a58b2c 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/cpd/ModelicaLanguage.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/cpd/ModelicaLanguage.java @@ -8,6 +8,6 @@ import net.sourceforge.pmd.lang.modelica.ModelicaLanguageModule; public class ModelicaLanguage extends AbstractLanguage { public ModelicaLanguage() { - super(ModelicaLanguageModule.NAME, ModelicaLanguageModule.TERSE_NAME, new ModelicaTokenizer(), ".mo"); + super(ModelicaLanguageModule.NAME, ModelicaLanguageModule.TERSE_NAME, new ModelicaTokenizer(), ModelicaLanguageModule.EXTENSIONS); } } diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ModelicaLanguageModule.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ModelicaLanguageModule.java index 290533ba0d..e0c6863a8b 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ModelicaLanguageModule.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ModelicaLanguageModule.java @@ -4,15 +4,22 @@ package net.sourceforge.pmd.lang.modelica; +import static net.sourceforge.pmd.util.CollectionUtil.listOf; + +import java.util.List; + +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase; public class ModelicaLanguageModule extends SimpleLanguageModuleBase { public static final String NAME = "Modelica"; public static final String TERSE_NAME = "modelica"; + @InternalApi + public static final List EXTENSIONS = listOf("mo"); public ModelicaLanguageModule() { super(LanguageMetadata.withId(TERSE_NAME).name(NAME) - .extensions("mo") + .extensions(EXTENSIONS.get(0)) .addVersion("3.4") .addDefaultVersion("3.5"), new ModelicaHandler()); diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/cpd/PLSQLLanguage.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/cpd/PLSQLLanguage.java index 5331ec9f72..3a744e12ae 100755 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/cpd/PLSQLLanguage.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/cpd/PLSQLLanguage.java @@ -6,22 +6,15 @@ package net.sourceforge.pmd.cpd; import java.util.Properties; +import net.sourceforge.pmd.lang.plsql.PLSQLLanguageModule; + /** * * @author Stuart Turton sturton@users.sourceforge.net */ public class PLSQLLanguage extends AbstractLanguage { public PLSQLLanguage() { - super("PL/SQL", "plsql", new PLSQLTokenizer(), - ".sql", - ".trg", // Triggers - ".prc", ".fnc", // Standalone Procedures and Functions - ".pld", // Oracle*Forms - ".pls", ".plh", ".plb", // Packages - ".pck", ".pks", ".pkh", ".pkb", // Packages - ".typ", ".tyb", // Object Types - ".tps", ".tpb" // Object Types - ); + super(PLSQLLanguageModule.NAME, PLSQLLanguageModule.TERSE_NAME, new PLSQLTokenizer(), PLSQLLanguageModule.EXTENSIONS); } @Override diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLLanguageModule.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLLanguageModule.java index 6422362df0..01f262ac4b 100644 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLLanguageModule.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLLanguageModule.java @@ -4,6 +4,11 @@ package net.sourceforge.pmd.lang.plsql; +import static net.sourceforge.pmd.util.CollectionUtil.listOf; + +import java.util.List; + +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase; /** @@ -13,27 +18,29 @@ public class PLSQLLanguageModule extends SimpleLanguageModuleBase { public static final String NAME = "PLSQL"; public static final String TERSE_NAME = "plsql"; + @InternalApi + public static final List EXTENSIONS = listOf( + "sql", + "trg", // Triggers + "prc", "fnc", // Standalone Procedures and Functions + "pld", // Oracle*Forms + "pls", "plh", "plb", // Packages + "pck", "pks", "pkh", "pkb", // Packages + "typ", "tyb", // Object Types + "tps", "tpb" // Object Types + ); public PLSQLLanguageModule() { super( LanguageMetadata.withId(TERSE_NAME) .name(NAME) - .extensions( - "sql", - "trg", // Triggers - "prc", "fnc", // Standalone Procedures and Functions - "pld", // Oracle*Forms - "pls", "plh", "plb", // Packages - "pck", "pks", "pkh", "pkb", // Packages - "typ", "tyb", // Object Types - "tps", "tpb" // Object Types - ) - .addVersion("11g") - .addVersion("12c_Release_1", "12.1") - .addVersion("12c_Release_2", "12.2") - .addVersion("18c") - .addVersion("19c") - .addDefaultVersion("21c"), + .extensions(EXTENSIONS.get(0), EXTENSIONS.toArray(new String[0])) + .addVersion("11g") + .addVersion("12c_Release_1", "12.1") + .addVersion("12c_Release_2", "12.2") + .addVersion("18c") + .addVersion("19c") + .addDefaultVersion("21c"), new PLSQLHandler() ); } diff --git a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/cpd/ScalaLanguage.java b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/cpd/ScalaLanguage.java index fd1f1b6da9..fe1e4c6f03 100644 --- a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/cpd/ScalaLanguage.java +++ b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/cpd/ScalaLanguage.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.cpd; +import net.sourceforge.pmd.lang.scala.ScalaLanguageModule; + /** * Language implementation for Scala. */ @@ -13,6 +15,6 @@ public class ScalaLanguage extends AbstractLanguage { * Creates a new Scala Language instance. */ public ScalaLanguage() { - super("Scala", "scala", new ScalaTokenizer(), ".scala"); + super(ScalaLanguageModule.NAME, ScalaLanguageModule.TERSE_NAME, new ScalaTokenizer(), ScalaLanguageModule.EXTENSIONS); } } diff --git a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ScalaLanguageModule.java b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ScalaLanguageModule.java index 1825eec5c6..6bfa00c615 100644 --- a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ScalaLanguageModule.java +++ b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ScalaLanguageModule.java @@ -4,6 +4,10 @@ package net.sourceforge.pmd.lang.scala; +import static net.sourceforge.pmd.util.CollectionUtil.listOf; + +import java.util.List; + import org.checkerframework.checker.nullness.qual.NonNull; import net.sourceforge.pmd.annotation.InternalApi; @@ -24,11 +28,14 @@ public class ScalaLanguageModule extends SimpleLanguageModuleBase { /** The terse name. */ public static final String TERSE_NAME = "scala"; + @InternalApi + public static final List EXTENSIONS = listOf("scala"); + /** * Create a new instance of Scala Language Module. */ public ScalaLanguageModule() { - super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("scala") + super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions(EXTENSIONS.get(0)) .addVersion("2.10") .addVersion("2.11") .addVersion("2.12") diff --git a/pmd-swift/src/main/java/net/sourceforge/pmd/cpd/SwiftLanguage.java b/pmd-swift/src/main/java/net/sourceforge/pmd/cpd/SwiftLanguage.java index 841e0861fd..297f27cf24 100644 --- a/pmd-swift/src/main/java/net/sourceforge/pmd/cpd/SwiftLanguage.java +++ b/pmd-swift/src/main/java/net/sourceforge/pmd/cpd/SwiftLanguage.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.cpd; +import net.sourceforge.pmd.lang.swift.SwiftLanguageModule; + /** * Language implementation for Swift */ @@ -13,6 +15,6 @@ public class SwiftLanguage extends AbstractLanguage { * Creates a new Swift Language instance. */ public SwiftLanguage() { - super("Swift", "swift", new SwiftTokenizer(), ".swift"); + super(SwiftLanguageModule.NAME, SwiftLanguageModule.TERSE_NAME, new SwiftTokenizer(), SwiftLanguageModule.EXTENSIONS); } } diff --git a/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftLanguageModule.java b/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftLanguageModule.java index 5e94c303f0..ac2daf61a5 100644 --- a/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftLanguageModule.java +++ b/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftLanguageModule.java @@ -4,6 +4,11 @@ package net.sourceforge.pmd.lang.swift; +import static net.sourceforge.pmd.util.CollectionUtil.listOf; + +import java.util.List; + +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase; /** @@ -16,12 +21,15 @@ public class SwiftLanguageModule extends SimpleLanguageModuleBase { /** The terse name. */ public static final String TERSE_NAME = "swift"; + @InternalApi + public static final List EXTENSIONS = listOf("swift"); + /** * Create a new instance of Swift Language Module. */ public SwiftLanguageModule() { super(LanguageMetadata.withId(TERSE_NAME).name(NAME) - .extensions("swift") + .extensions(EXTENSIONS.get(0)) .addVersion("4.2") .addVersion("5.0") .addVersion("5.1") diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/cpd/VfLanguage.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/cpd/VfLanguage.java index 301bfc15c3..5551e91a5d 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/cpd/VfLanguage.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/cpd/VfLanguage.java @@ -4,12 +4,14 @@ package net.sourceforge.pmd.cpd; +import net.sourceforge.pmd.lang.vf.VfLanguageModule; + /** * @author sergey.gorbaty * */ public class VfLanguage extends AbstractLanguage { public VfLanguage() { - super("VisualForce", "vf", new VfTokenizer(), ".page", ".component"); + super(VfLanguageModule.NAME, VfLanguageModule.TERSE_NAME, new VfTokenizer(), VfLanguageModule.EXTENSIONS); } } diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfLanguageModule.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfLanguageModule.java index 3223c311d2..74f8596ea5 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfLanguageModule.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfLanguageModule.java @@ -4,13 +4,17 @@ package net.sourceforge.pmd.lang.vf; +import static net.sourceforge.pmd.util.CollectionUtil.listOf; + +import java.util.List; + +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguagePropertyBundle; import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.apex.ApexLanguageModule; import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase; - /** * @author sergey.gorbaty */ @@ -18,6 +22,8 @@ public class VfLanguageModule extends SimpleLanguageModuleBase { public static final String NAME = "Salesforce VisualForce"; public static final String TERSE_NAME = "vf"; + @InternalApi + public static final List EXTENSIONS = listOf("page", "component"); public VfLanguageModule() { super(createMetdata(), @@ -26,7 +32,7 @@ public class VfLanguageModule extends SimpleLanguageModuleBase { private static LanguageMetadata createMetdata() { LanguageMetadata languageMetadata = LanguageMetadata.withId(TERSE_NAME).name(NAME) - .extensions("page", "component") + .extensions(EXTENSIONS.get(0), EXTENSIONS.toArray(new String[0])) .dependsOnLanguage(ApexLanguageModule.TERSE_NAME); // use the same versions as in Apex int lastVersion = ApexLanguageModule.VERSIONS.size() - 1; diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlLanguageModule.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlLanguageModule.java index 21bf0e22bc..838fac01d0 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlLanguageModule.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlLanguageModule.java @@ -4,6 +4,11 @@ package net.sourceforge.pmd.lang.xml; +import static net.sourceforge.pmd.util.CollectionUtil.listOf; + +import java.util.List; + +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase; /** @@ -13,10 +18,12 @@ public class XmlLanguageModule extends SimpleLanguageModuleBase { public static final String NAME = "XML"; public static final String TERSE_NAME = "xml"; + @InternalApi + public static final List EXTENSIONS = listOf("xml"); public XmlLanguageModule() { super(LanguageMetadata.withId(TERSE_NAME).name(NAME) - .extensions("xml") + .extensions(EXTENSIONS.get(0)) .addVersion("1.0") .addDefaultVersion("1.1"), new XmlHandler()); diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/xml/cpd/XmlLanguage.java b/pmd-xml/src/main/java/net/sourceforge/pmd/xml/cpd/XmlLanguage.java index 38b38c8eb3..c5c849a248 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/xml/cpd/XmlLanguage.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/xml/cpd/XmlLanguage.java @@ -5,10 +5,11 @@ package net.sourceforge.pmd.xml.cpd; import net.sourceforge.pmd.cpd.AbstractLanguage; +import net.sourceforge.pmd.lang.xml.XmlLanguageModule; public class XmlLanguage extends AbstractLanguage { public XmlLanguage() { - super("Xml", "xml", new XmlTokenizer(), ".xml"); + super(XmlLanguageModule.NAME, XmlLanguageModule.TERSE_NAME, new XmlTokenizer(), XmlLanguageModule.EXTENSIONS); } } From ee3f08a498bfc1cbb5da0d26f03f9643f564a110 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 9 Feb 2023 18:18:56 +0100 Subject: [PATCH 04/12] [doc] Update release notes regarding ecmascript version --- docs/pages/7_0_0_release_notes.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/pages/7_0_0_release_notes.md b/docs/pages/7_0_0_release_notes.md index 86c89181b6..b82e539b7d 100644 --- a/docs/pages/7_0_0_release_notes.md +++ b/docs/pages/7_0_0_release_notes.md @@ -153,9 +153,9 @@ See {% jdoc core::lang.ast.NodeStream %} for more details. #### JavaScript support The JS specific parser options have been removed. The parser now always retains comments and uses version ES6. -The language module registers only one version (as before), now correctly with version "ES6" instead of "3". -Since there is only one version available for JavaScript there is actually no need to selected a specific version. -The default version is always ES6. +The language module registers a couple of different versions. The latest version, which supports ES6 and also some +new constructs (see [Rhino](https://github.com/mozilla/rhino)]), is the default. This should be fine for most +use cases. #### New Rules From 8aaef01ed8f2972e82353350ece96aa634c7b201 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 9 Feb 2023 17:58:58 +0100 Subject: [PATCH 05/12] [doc] Update release notes (#4120) [skip ci] --- docs/pages/7_0_0_release_notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/pages/7_0_0_release_notes.md b/docs/pages/7_0_0_release_notes.md index b82e539b7d..2d877db318 100644 --- a/docs/pages/7_0_0_release_notes.md +++ b/docs/pages/7_0_0_release_notes.md @@ -254,6 +254,7 @@ The following previously deprecated rules have been finally removed: * [#3782](https://github.com/pmd/pmd/issues/3782): \[core] Language lifecycle * [#3902](https://github.com/pmd/pmd/issues/3902): \[core] Violation decorators * [#4035](https://github.com/pmd/pmd/issues/4035): \[core] ConcurrentModificationException in DefaultRuleViolationFactory + * [#4120](https://github.com/pmd/pmd/issues/4120): \[core] Explicitly name all language versions * cli * [#3828](https://github.com/pmd/pmd/issues/3828): \[core] Progress reporting * [#4079](https://github.com/pmd/pmd/issues/4079): \[cli] Split off CLI implementation into a pmd-cli submodule From a283615299beb0abb9ac9204eff55b34b687393a Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 10 Feb 2023 12:39:21 +0100 Subject: [PATCH 06/12] Refactor LanguageMetdata::extensions usages --- .../pmd/lang/LanguageModuleBase.java | 22 ++++++++++++++++++- .../pmd/lang/html/HtmlLanguageModule.java | 2 +- .../ecmascript/EcmascriptLanguageModule.java | 2 +- .../pmd/lang/jsp/JspLanguageModule.java | 2 +- .../pmd/lang/kotlin/KotlinLanguageModule.java | 3 ++- .../lang/modelica/ModelicaLanguageModule.java | 2 +- .../pmd/lang/plsql/PLSQLLanguageModule.java | 2 +- .../pmd/lang/scala/ScalaLanguageModule.java | 3 ++- .../pmd/lang/swift/SwiftLanguageModule.java | 2 +- .../pmd/lang/vf/VfLanguageModule.java | 7 +++--- .../pmd/lang/xml/XmlLanguageModule.java | 2 +- 11 files changed, 36 insertions(+), 13 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageModuleBase.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageModuleBase.java index 8d4c648666..5f1b67c55b 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageModuleBase.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageModuleBase.java @@ -8,6 +8,7 @@ import static net.sourceforge.pmd.util.CollectionUtil.setOf; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -269,7 +270,7 @@ public abstract class LanguageModuleBase implements Language { /** * Record the {@linkplain Language#getExtensions() extensions} - * assigned to the language. Parameters should not start with a period + * assigned to the language. Extensions should not start with a period * {@code .}. * * @param e1 First extensions @@ -283,6 +284,25 @@ public abstract class LanguageModuleBase implements Language { return this; } + /** + * Record the {@linkplain Language#getExtensions() extensions} + * assigned to the language. Extensions should not start with a period + * {@code .}. At least one extension must be provided. + * + * @param extensions the extensions + * + * @throws NullPointerException If any extension is null + * @throws IllegalArgumentException If no extensions are provided + */ + public LanguageMetadata extensions(Collection extensions) { + this.extensions = new ArrayList<>(new HashSet<>(extensions)); + AssertionUtil.requireContainsNoNullValue("extensions", this.extensions); + if (this.extensions.isEmpty()) { + throw new IllegalArgumentException("At least one extension is required."); + } + return this; + } + /** * Add a new version by its name. * diff --git a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java index 0743f248b9..900ab8c381 100644 --- a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java +++ b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java @@ -21,7 +21,7 @@ public final class HtmlLanguageModule extends SimpleLanguageModuleBase { public HtmlLanguageModule() { super(LanguageMetadata.withId(TERSE_NAME).name(NAME) - .extensions(EXTENSIONS.get(0), EXTENSIONS.subList(0, EXTENSIONS.size()).toArray(new String[0])) + .extensions(EXTENSIONS) .addVersion("4") .addDefaultVersion("5"), new HtmlHandler()); diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java index e8c56f48c3..9d68ea6b0d 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java @@ -25,7 +25,7 @@ public class EcmascriptLanguageModule extends SimpleLanguageModuleBase { public static final List EXTENSIONS = listOf("js"); public EcmascriptLanguageModule() { - super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions(EXTENSIONS.get(0)) + super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions(EXTENSIONS) .addVersion("3") .addVersion("5") .addVersion("6", "ES6", "ES2015") diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspLanguageModule.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspLanguageModule.java index 33fb67c449..09741a8d67 100644 --- a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspLanguageModule.java +++ b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspLanguageModule.java @@ -23,7 +23,7 @@ public class JspLanguageModule extends SimpleLanguageModuleBase { public JspLanguageModule() { super(LanguageMetadata.withId(TERSE_NAME).name(NAME).shortName("JSP") - .extensions(EXTENSIONS.get(0), EXTENSIONS.toArray(new String[0])) + .extensions(EXTENSIONS) .addVersion("2") .addDefaultVersion("3"), new JspHandler()); diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java index 1bdaa924c7..6faf72c06b 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java @@ -32,7 +32,8 @@ public class KotlinLanguageModule extends SimpleLanguageModuleBase { * Create a new instance of Kotlin Language Module. */ public KotlinLanguageModule() { - super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions(EXTENSIONS.get(0), EXTENSIONS.toArray(new String[0])) + super(LanguageMetadata.withId(TERSE_NAME).name(NAME) + .extensions(EXTENSIONS) .addVersion("1.6") .addDefaultVersion("1.7"), new KotlinHandler()); diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ModelicaLanguageModule.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ModelicaLanguageModule.java index e0c6863a8b..d43ef71c24 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ModelicaLanguageModule.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ModelicaLanguageModule.java @@ -19,7 +19,7 @@ public class ModelicaLanguageModule extends SimpleLanguageModuleBase { public ModelicaLanguageModule() { super(LanguageMetadata.withId(TERSE_NAME).name(NAME) - .extensions(EXTENSIONS.get(0)) + .extensions(EXTENSIONS) .addVersion("3.4") .addDefaultVersion("3.5"), new ModelicaHandler()); diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLLanguageModule.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLLanguageModule.java index 01f262ac4b..81d1d3b929 100644 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLLanguageModule.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLLanguageModule.java @@ -34,7 +34,7 @@ public class PLSQLLanguageModule extends SimpleLanguageModuleBase { super( LanguageMetadata.withId(TERSE_NAME) .name(NAME) - .extensions(EXTENSIONS.get(0), EXTENSIONS.toArray(new String[0])) + .extensions(EXTENSIONS) .addVersion("11g") .addVersion("12c_Release_1", "12.1") .addVersion("12c_Release_2", "12.2") diff --git a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ScalaLanguageModule.java b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ScalaLanguageModule.java index 6bfa00c615..1507c4716d 100644 --- a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ScalaLanguageModule.java +++ b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ScalaLanguageModule.java @@ -35,7 +35,8 @@ public class ScalaLanguageModule extends SimpleLanguageModuleBase { * Create a new instance of Scala Language Module. */ public ScalaLanguageModule() { - super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions(EXTENSIONS.get(0)) + super(LanguageMetadata.withId(TERSE_NAME).name(NAME) + .extensions(EXTENSIONS) .addVersion("2.10") .addVersion("2.11") .addVersion("2.12") diff --git a/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftLanguageModule.java b/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftLanguageModule.java index ac2daf61a5..a2c3192477 100644 --- a/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftLanguageModule.java +++ b/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftLanguageModule.java @@ -29,7 +29,7 @@ public class SwiftLanguageModule extends SimpleLanguageModuleBase { */ public SwiftLanguageModule() { super(LanguageMetadata.withId(TERSE_NAME).name(NAME) - .extensions(EXTENSIONS.get(0)) + .extensions(EXTENSIONS) .addVersion("4.2") .addVersion("5.0") .addVersion("5.1") diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfLanguageModule.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfLanguageModule.java index 74f8596ea5..6ea4ea183f 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfLanguageModule.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfLanguageModule.java @@ -31,9 +31,10 @@ public class VfLanguageModule extends SimpleLanguageModuleBase { } private static LanguageMetadata createMetdata() { - LanguageMetadata languageMetadata = LanguageMetadata.withId(TERSE_NAME).name(NAME) - .extensions(EXTENSIONS.get(0), EXTENSIONS.toArray(new String[0])) - .dependsOnLanguage(ApexLanguageModule.TERSE_NAME); + LanguageMetadata languageMetadata = + LanguageMetadata.withId(TERSE_NAME).name(NAME) + .extensions(EXTENSIONS) + .dependsOnLanguage(ApexLanguageModule.TERSE_NAME); // use the same versions as in Apex int lastVersion = ApexLanguageModule.VERSIONS.size() - 1; ApexLanguageModule.VERSIONS.subList(0, lastVersion).forEach(languageMetadata::addVersion); diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlLanguageModule.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlLanguageModule.java index 838fac01d0..b0ab3d3b00 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlLanguageModule.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlLanguageModule.java @@ -23,7 +23,7 @@ public class XmlLanguageModule extends SimpleLanguageModuleBase { public XmlLanguageModule() { super(LanguageMetadata.withId(TERSE_NAME).name(NAME) - .extensions(EXTENSIONS.get(0)) + .extensions(EXTENSIONS) .addVersion("1.0") .addDefaultVersion("1.1"), new XmlHandler()); From 56dbdd1c95d345556ac36affcd5624394d3434e8 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 17 Feb 2023 09:41:52 +0100 Subject: [PATCH 07/12] [core] Don't allow languages without versions --- .../pmd/lang/LanguageModuleBase.java | 8 ++------ .../pmd/lang/LanguageModuleBaseTest.java | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageModuleBase.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageModuleBase.java index 5f1b67c55b..0d1d45553f 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageModuleBase.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageModuleBase.java @@ -22,7 +22,6 @@ import org.apache.commons.lang3.StringUtils; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import net.sourceforge.pmd.lang.LanguageModuleBase.LanguageMetadata.LangVersionMetadata; import net.sourceforge.pmd.util.AssertionUtil; import net.sourceforge.pmd.util.StringUtil; @@ -45,7 +44,7 @@ public abstract class LanguageModuleBase implements Language { * Construct a module instance using the given metadata. The metadata must * be properly constructed. * - * @throws IllegalStateException If the metadata is invalid (eg missing extensions or name) + * @throws IllegalStateException If the metadata is invalid (eg missing extensions or name or no versions) */ protected LanguageModuleBase(LanguageMetadata metadata) { this.meta = metadata; @@ -56,10 +55,7 @@ public abstract class LanguageModuleBase implements Language { LanguageVersion defaultVersion = null; if (metadata.versionMetadata.isEmpty()) { - // Many languages have just one version, which is implicitly - // created here. - // TODO #4120 remove this branch, before 7.0.0 - metadata.versionMetadata.add(new LangVersionMetadata("", Collections.emptyList(), true)); + throw new IllegalStateException("No versions for '" + getId() + "'"); } int i = 0; diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/LanguageModuleBaseTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/LanguageModuleBaseTest.java index 64fae5a9c8..91e56eff8d 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/LanguageModuleBaseTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/LanguageModuleBaseTest.java @@ -28,6 +28,16 @@ class LanguageModuleBaseTest { assertInvalidId("C"); assertInvalidId("ab-c"); assertThrows(NullPointerException.class, () -> LanguageMetadata.withId(null)); + + Exception e = assertThrows(IllegalArgumentException.class, () -> LanguageMetadata.withId("dummy").addVersion(""), + "Empty versions should not be allowed."); + assertEquals("Invalid version name: ''", e.getMessage()); + assertThrows(IllegalArgumentException.class, () -> LanguageMetadata.withId("dummy").addVersion(" "), + "Empty versions should not be allowed."); + assertThrows(IllegalArgumentException.class, () -> LanguageMetadata.withId("dummy").addVersion(null), + "Empty versions should not be allowed."); + assertThrows(IllegalArgumentException.class, () -> LanguageMetadata.withId("dummy").addVersion("1.0", ""), + "Empty versions should not be allowed."); } @Test @@ -36,6 +46,13 @@ class LanguageModuleBaseTest { assertThat(lang.getDefaultVersion(), equalTo(lang.getVersion("abc"))); } + @Test + void testMissingVersions() { + Exception e = assertThrows(IllegalStateException.class, () -> makeLanguage(LanguageMetadata.withId("dumdum").name("Name").extensions("o")), + "Languages without versions should not be allowed."); + assertEquals("No versions for 'dumdum'", e.getMessage()); + } + @Test void testNoExtensions() { Exception ex = assertThrows(IllegalStateException.class, () -> makeLanguage(LanguageMetadata.withId("dumdum").name("Name").addVersion("abc"))); From eebe9088a737a3d0a8772f1dd554c87b7b8c3edd Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 17 Feb 2023 09:42:45 +0100 Subject: [PATCH 08/12] [doc] Update language versions doc --- docs/pages/pmd/userdocs/cli_reference.md | 10 ++++-- docs/pages/pmd/userdocs/tools/ant.md | 44 +++--------------------- 2 files changed, 12 insertions(+), 42 deletions(-) diff --git a/docs/pages/pmd/userdocs/cli_reference.md b/docs/pages/pmd/userdocs/cli_reference.md index ba0353d144..285089ef6e 100644 --- a/docs/pages/pmd/userdocs/cli_reference.md +++ b/docs/pages/pmd/userdocs/cli_reference.md @@ -224,7 +224,14 @@ non-preview version. If you want to use an older version, so that e.g. rules tha that are not available yet won't be executed, you need to specify a specific version via the `--use-version` parameter. -These parameters are irrelevant for languages that don't support different versions. +The selected language version can also influence which rules are applied. Some rules might be relevant for +just a specific version of the language. Such rules are marked with either `minimumLanguageVersion` or +`maximumLanguageVersion` or both. Most rules apply for all language versions. + +These parameters are most of the time irrelevant, if the rules apply for all versions. + +The available versions depend on the language. You can get a list of the currently supported language versions +via the CLI option `--help`. Example: @@ -245,7 +252,6 @@ Example: * [plsql](pmd_rules_plsql.html) * [pom](pmd_rules_pom.html) (Maven POM) * [scala](pmd_rules_scala.html) - * Supported Versions: 2.10, 2.11, 2.12, 2.13 (default) * [swift](pmd_rules_swift.html) * [vf](pmd_rules_vf.html) (Salesforce VisualForce) * [vm](pmd_rules_vm.html) (Apache Velocity) diff --git a/docs/pages/pmd/userdocs/tools/ant.md b/docs/pages/pmd/userdocs/tools/ant.md index c0637db94e..ae3abbcbab 100644 --- a/docs/pages/pmd/userdocs/tools/ant.md +++ b/docs/pages/pmd/userdocs/tools/ant.md @@ -211,48 +211,12 @@ sense with Java 1.7 and later. If your project uses Java 1.5, then you should co accordingly and this rule won't be executed. The specific version of a language to be used is selected via the `sourceLanguage` -nested element. Possible values are: +nested element. Example: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +The available versions depend on the language. You can get a list of the currently supported language versions +via the CLI option `--help`. ### Postprocessing the report file with XSLT From be6a46ccff63d17a7eea4876fb82fdf49028da9d Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 17 Feb 2023 11:22:52 +0100 Subject: [PATCH 09/12] [vf] Refactor dependency to apex language module --- .../pmd/lang/apex/ApexLanguageModule.java | 19 +++++++------------ .../pmd/lang/vf/VfLanguageModule.java | 13 ++++++++++--- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java index 33c9f5b0d6..8bb3084136 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java @@ -20,22 +20,17 @@ public class ApexLanguageModule extends LanguageModuleBase { public static final String NAME = "Apex"; public static final String TERSE_NAME = "apex"; - @InternalApi - public static final List VERSIONS = listOf("52", "53", "54", "55", "56", "57"); @InternalApi public static final List EXTENSIONS = listOf("cls", "trigger"); public ApexLanguageModule() { - super(createMetadata()); - } - - private static LanguageMetadata createMetadata() { - LanguageMetadata languageMetadata = LanguageMetadata.withId(TERSE_NAME).name(NAME); - languageMetadata.extensions(EXTENSIONS.get(0), EXTENSIONS.subList(0, EXTENSIONS.size()).toArray(new String[0])); - int lastVersion = VERSIONS.size() - 1; - VERSIONS.subList(0, lastVersion).forEach(languageMetadata::addVersion); - languageMetadata.addDefaultVersion(VERSIONS.get(lastVersion)); - return languageMetadata; + super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions(EXTENSIONS) + .addVersion("52") + .addVersion("53") + .addVersion("54") + .addVersion("55") + .addVersion("56") + .addDefaultVersion("57")); } @Override diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfLanguageModule.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfLanguageModule.java index 6ea4ea183f..e43738df99 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfLanguageModule.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfLanguageModule.java @@ -12,6 +12,7 @@ import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguagePropertyBundle; import net.sourceforge.pmd.lang.LanguageRegistry; +import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.apex.ApexLanguageModule; import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase; @@ -36,9 +37,15 @@ public class VfLanguageModule extends SimpleLanguageModuleBase { .extensions(EXTENSIONS) .dependsOnLanguage(ApexLanguageModule.TERSE_NAME); // use the same versions as in Apex - int lastVersion = ApexLanguageModule.VERSIONS.size() - 1; - ApexLanguageModule.VERSIONS.subList(0, lastVersion).forEach(languageMetadata::addVersion); - languageMetadata.addDefaultVersion(ApexLanguageModule.VERSIONS.get(lastVersion)); + // need to create a temporary apex module, since the global language registry is not initialized yet + ApexLanguageModule temporaryApexModule = new ApexLanguageModule(); + LanguageVersion defaultApexVersion = temporaryApexModule.getDefaultVersion(); + for (LanguageVersion languageVersion : temporaryApexModule.getVersions()) { + if (!defaultApexVersion.equals(languageVersion)) { + languageMetadata.addVersion(languageVersion.getVersion()); + } + } + languageMetadata.addDefaultVersion(defaultApexVersion.getVersion()); return languageMetadata; } From 50577f2b4042998ac8f4d50781abf3310fb9ac80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 26 Feb 2023 15:33:36 +0100 Subject: [PATCH 10/12] Rewrite binaryDistributionIt to be easier to maintain --- .../java/net/sourceforge/pmd/PMDVersion.java | 2 +- .../net/sourceforge/pmd/it/AllRulesIT.java | 5 +- .../java/net/sourceforge/pmd/it/AntIT.java | 9 +- .../pmd/it/BinaryDistributionIT.java | 135 +++++++++++------- .../sourceforge/pmd/it/ExecutionResult.java | 118 ++++----------- 5 files changed, 122 insertions(+), 147 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMDVersion.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMDVersion.java index 96565eca93..d7391eb7e5 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMDVersion.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMDVersion.java @@ -23,7 +23,7 @@ public final class PMDVersion { */ public static final String VERSION; - private static final String UNKNOWN_VERSION = "unknown"; + private static final String UNKNOWN_VERSION = "7.0.0-SNAPSHOT"; /** * Determines the version from maven's generated pom.properties file. diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/AllRulesIT.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/AllRulesIT.java index 74faa00fbc..9a32b681a1 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/AllRulesIT.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/AllRulesIT.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.it; +import static org.hamcrest.Matchers.containsString; + import java.io.File; import java.util.Arrays; @@ -30,7 +32,8 @@ class AllRulesIT extends AbstractBinaryDistributionTest { } private static void assertDefaultExecutionResult(ExecutionResult result) { - result.assertExecutionResult(4, ""); + result.assertExitCode(4) + .assertStdOut(containsString("")); result.assertNoError("Exception applying rule"); result.assertNoError("Ruleset not found"); diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/AntIT.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/AntIT.java index f28e430273..bc4ca8be7d 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/AntIT.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/AntIT.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.it; +import static org.hamcrest.Matchers.containsString; + import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -38,8 +40,11 @@ class AntIT extends AbstractBinaryDistributionTest { File antTestProjectFolder = prepareAntTestProjectFolder(); ExecutionResult result = runAnt(antBasepath, pmdHome, antTestProjectFolder); - result.assertExecutionResult(0, "BUILD SUCCESSFUL"); - result.assertExecutionResult(0, "NoPackage"); // the no package rule + result.assertExitCode(0) + .assertStdOut(containsString("BUILD SUCCESSFUL")); + // the no package rule + result.assertExitCode(0) + .assertStdOut(containsString("NoPackage")); } diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java index 61140975cf..4ecee48c31 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java @@ -4,6 +4,9 @@ package net.sourceforge.pmd.it; +import static net.sourceforge.pmd.util.CollectionUtil.listOf; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.matchesRegex; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -11,7 +14,10 @@ import java.io.File; import java.io.IOException; import java.util.Enumeration; import java.util.HashSet; +import java.util.List; import java.util.Set; +import java.util.regex.Pattern; +import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -21,43 +27,50 @@ import net.sourceforge.pmd.PMDVersion; class BinaryDistributionIT extends AbstractBinaryDistributionTest { - private static final String SUPPORTED_LANGUAGES_CPD; - private static final String SUPPORTED_LANGUAGES_PMD; + private static final List SUPPORTED_LANGUAGES_CPD = listOf( + "apex", "cpp", "cs", "dart", "ecmascript", + "fortran", "gherkin", "go", "groovy", "html", "java", "jsp", + "kotlin", "lua", "matlab", "modelica", "objectivec", "perl", + "php", "plsql", "python", "ruby", "scala", "swift", "tsql", + "vf", "xml" + ); + + private static final List SUPPORTED_LANGUAGES_PMD = listOf( + "apex-52", "apex-53", "apex-54", "apex-55", + "apex-56", "apex-57", "ecmascript-3", "ecmascript-5", + "ecmascript-6", "ecmascript-7", "ecmascript-8", + "ecmascript-9", "ecmascript-ES2015", + "ecmascript-ES2016", "ecmascript-ES2017", + "ecmascript-ES2018", "ecmascript-ES6", "html-4", + "html-5", "java-1.10", "java-1.3", "java-1.4", "java-1.5", + "java-1.6", "java-1.7", "java-1.8", "java-1.9", "java-10", + "java-11", "java-12", "java-13", "java-14", "java-15", + "java-16", "java-17", "java-18", "java-19", + "java-19-preview", "java-20", "java-20-preview", + "java-5", "java-6", "java-7", + "java-8", "java-9", "jsp-2", "jsp-3", "kotlin-1.6", + "kotlin-1.7", "modelica-3.4", "modelica-3.5", + "plsql-11g", "plsql-12.1", "plsql-12.2", + "plsql-12c_Release_1", "plsql-12c_Release_2", + "plsql-18c", "plsql-19c", "plsql-21c", "pom-4.0.0", + "scala-2.10", "scala-2.11", "scala-2.12", "scala-2.13", + "swift-4.2", "swift-5.0", "swift-5.1", "swift-5.2", + "swift-5.3", "swift-5.4", "swift-5.5", "swift-5.6", + "swift-5.7", "vf-52", "vf-53", "vf-54", "vf-55", "vf-56", + "vf-57", "vm-2.0", "vm-2.1", "vm-2.2", "vm-2.3", "wsdl-1.1", + "wsdl-2.0", "xml-1.0", "xml-1.1", "xsl-1.0", "xsl-2.0", + "xsl-3.0" + ); - static { - SUPPORTED_LANGUAGES_CPD = "Valid values: apex, cpp, cs, dart, ecmascript," + System.lineSeparator() - + " fortran, gherkin, go, groovy, html, java, jsp," + System.lineSeparator() - + " kotlin, lua, matlab, modelica, objectivec, perl," + System.lineSeparator() - + " php, plsql, python, ruby, scala, swift, tsql," + System.lineSeparator() - + " vf, xml"; - SUPPORTED_LANGUAGES_PMD = "Valid values: apex-52, apex-53, apex-54, apex-55," + System.lineSeparator() - + " apex-56, apex-57, ecmascript-3, ecmascript-5," + System.lineSeparator() - + " ecmascript-6, ecmascript-7, ecmascript-8," + System.lineSeparator() - + " ecmascript-9, ecmascript-ES2015," + System.lineSeparator() - + " ecmascript-ES2016, ecmascript-ES2017," + System.lineSeparator() - + " ecmascript-ES2018, ecmascript-ES6, html-4," + System.lineSeparator() - + " html-5, java-1.10, java-1.3, java-1.4, java-1.5," + System.lineSeparator() - + " java-1.6, java-1.7, java-1.8, java-1.9, java-10," + System.lineSeparator() - + " java-11, java-12, java-13, java-14, java-15," + System.lineSeparator() - + " java-16, java-17, java-18, java-19," + System.lineSeparator() - + " java-19-preview, java-20, java-20-preview," + System.lineSeparator() - + " java-5, java-6, java-7," - + " java-8, java-9, jsp-2, jsp-3, kotlin-1.6," + System.lineSeparator() - + " kotlin-1.7, modelica-3.4, modelica-3.5," + System.lineSeparator() - + " plsql-11g, plsql-12.1, plsql-12.2," + System.lineSeparator() - + " plsql-12c_Release_1, plsql-12c_Release_2," + System.lineSeparator() - + " plsql-18c, plsql-19c, plsql-21c, pom-4.0.0," + System.lineSeparator() - + " scala-2.10, scala-2.11, scala-2.12, scala-2.13," + System.lineSeparator() - + " swift-4.2, swift-5.0, swift-5.1, swift-5.2," + System.lineSeparator() - + " swift-5.3, swift-5.4, swift-5.5, swift-5.6," + System.lineSeparator() - + " swift-5.7, vf-52, vf-53, vf-54, vf-55, vf-56," + System.lineSeparator() - + " vf-57, vm-2.0, vm-2.1, vm-2.2, vm-2.3, wsdl-1.1," + System.lineSeparator() - + " wsdl-2.0, xml-1.0, xml-1.1, xsl-1.0, xsl-2.0," + System.lineSeparator() - + " xsl-3.0"; - } private final String srcDir = new File(".", "src/test/resources/sample-source/java/").getAbsolutePath(); + private static Pattern toListPattern(List items) { + String pattern = items.stream().map(Pattern::quote) + .collect(Collectors.joining(",\\s+", ".*Valid values: ", ".*")); + return Pattern.compile(pattern, Pattern.DOTALL); + } + @Test void testFileExistence() { assertTrue(getBinaryDistribution().exists()); @@ -99,46 +112,49 @@ class BinaryDistributionIT extends AbstractBinaryDistributionTest { @Test void testPmdJavaQuickstart() throws Exception { ExecutionResult result = PMDExecutor.runPMDRules(createTemporaryReportFile(), tempDir, srcDir, "rulesets/java/quickstart.xml"); - result.assertExecutionResult(4, ""); + result.assertExitCode(4) + .assertStdOut(containsString("")); } @Test void testPmdXmlFormat() throws Exception { ExecutionResult result = PMDExecutor.runPMDRules(createTemporaryReportFile(), tempDir, srcDir, "src/test/resources/rulesets/sample-ruleset.xml", "xml"); - result.assertExecutionResult(4, "", "JumbledIncrementer.java\">"); - result.assertExecutionResult(4, "", "")); + result.assertExitCode(4).assertReport(containsString(""); - result.assertExecutionResult(4, "Class1.java\"/>"); - result.assertExecutionResult(4, "Class2.java\"/>"); + result.assertExitCode(4) + .assertStdOut(containsString("")); + result.assertExitCode(4) + .assertStdOut(containsString("Class1.java\"/>")); + result.assertExitCode(4) + .assertStdOut(containsString("Class2.java\"/>")); result = CpdExecutor.runCpd(tempDir, "--minimum-tokens", "1000", "--format", "text", "--dir", srcDir); - result.assertExecutionResult(0); + result.assertExitCode(0); } } diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/ExecutionResult.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/ExecutionResult.java index ee00990309..d182e83d8c 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/ExecutionResult.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/ExecutionResult.java @@ -4,13 +4,12 @@ package net.sourceforge.pmd.it; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; -import net.sourceforge.pmd.PMD; +import org.hamcrest.Matcher; /** * Collects the result of a command execution in order to verify it. @@ -32,96 +31,40 @@ public class ExecutionResult { @Override public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("ExecutionResult:") - .append(PMD.EOL) - .append(" exit code: ").append(exitCode).append(PMD.EOL) - .append(" output:").append(PMD.EOL).append(output).append(PMD.EOL) - .append(" errorOutput:").append(PMD.EOL).append(errorOutput).append(PMD.EOL) - .append(" report:").append(PMD.EOL).append(report).append(PMD.EOL); - return sb.toString(); + return "ExecutionResult:\n" + + " exit code: " + exitCode + "\n" + + " output:\n" + output + "\n" + + " errorOutput:\n" + errorOutput + "\n" + + " report:\n" + report + "\n"; } - /** - * Asserts that the command exited with the expected exit code. Any output is ignored. - * - * @param expectedExitCode the exit code, e.g. 0 if no rule violations are expected, or 4 if violations are found - */ - public void assertExecutionResult(int expectedExitCode) { - assertExecutionResult(expectedExitCode, null); - } - - /** - * Asserts that the command exited with the expected exit code and that the given expected - * output is contained in the actual command output. - * - * @param expectedExitCode the exit code, e.g. 0 if no rule violations are expected, or 4 if violations are found - * @param expectedOutput the output to search for - */ - public void assertExecutionResult(int expectedExitCode, String expectedOutput) { - assertExecutionResult(expectedExitCode, expectedOutput, null); - } - - /** - * Asserts that the command exited with the expected exit code and that the given expected - * output is contained in the actual command output and the given expected report is in the - * generated report. - * - * @param expectedExitCode the exit code, e.g. 0 if no rule violations are expected, or 4 if violations are found - * @param expectedOutput the output to search for - * @param expectedReport the string to search for tin the report - */ - public void assertExecutionResult(int expectedExitCode, String expectedOutput, String expectedReport) { - assertExecResultImpl(expectedExitCode, output, expectedOutput, expectedReport); - } - - /** - * Asserts that the command exited with the expected exit code and that the given expected - * output is contained in the actual command ERROR output, and the given expected report is in the - * generated report. - * - * @param expectedExitCode the exit code, e.g. 0 if no rule violations are expected, or 4 if violations are found - * @param expectedErrorOutput the output to search for in stderr - * @param expectedReport the string to search for tin the report - */ - public void assertExecutionResultErrOutput(int expectedExitCode, String expectedErrorOutput, String expectedReport) { - assertExecResultImpl(expectedExitCode, errorOutput, expectedErrorOutput, expectedReport); - } - - /** - * Asserts that the command exited with the expected exit code and that the given expected - * output is contained in the actual command ERROR output. - * - * @param expectedExitCode the exit code, e.g. 0 if no rule violations are expected, or 4 if violations are found - * @param expectedErrorOutput the output to search for in stderr - */ - public void assertExecutionResultErrOutput(int expectedExitCode, String expectedErrorOutput) { - assertExecResultImpl(expectedExitCode, errorOutput, expectedErrorOutput, null); - } - - private void assertExecResultImpl(int expectedExitCode, String output, String expectedOutput, String expectedReport) { + public ExecutionResult assertExitCode(int expectedExitCode) { assertEquals(expectedExitCode, exitCode, "Command exited with wrong code.\nComplete result:\n\n" + this); - assertNotNull(output, "No output found"); - if (expectedOutput != null && !expectedOutput.isEmpty()) { - if (!output.contains(expectedOutput)) { - fail("Expected output '" + expectedOutput + "' not present.\nComplete result:\n\n" + this); - } - } else if (expectedOutput != null && expectedOutput.isEmpty()) { - assertTrue(output.isEmpty(), "The output should have been empty.\nComplete result:\n\n" + this); - } - if (expectedReport != null && !expectedReport.isEmpty()) { - assertTrue(report.contains(expectedReport), - "Expected report '" + expectedReport + "'.\nComplete result:\n\n" + this); - } + return this; + } + + public ExecutionResult assertReport(Matcher reportMatcher) { + assertThat("Report", report, reportMatcher); + return this; + } + + public ExecutionResult assertStdErr(Matcher matcher) { + assertThat("Standard error", errorOutput, matcher); + return this; + } + + public ExecutionResult assertStdOut(Matcher matcher) { + assertThat("Standard output", output, matcher); + return this; } /** * Asserts that the given error message is not in the error output. + * * @param errorMessage the error message to search for */ public void assertNoError(String errorMessage) { - assertFalse(errorOutput.contains(errorMessage), - "Found error message: " + errorMessage + ".\nComplete result:\n\n" + this); + assertStdErr(not(containsString(errorMessage))); } /** @@ -129,12 +72,11 @@ public class ExecutionResult { * @param errorMessage the error message to search for */ public void assertNoErrorInReport(String errorMessage) { - assertFalse(report.contains(errorMessage), - "Found error message in report: " + errorMessage + ".\nComplete result:\n\n" + this); + assertReport(not(containsString(errorMessage))); } public void assertErrorOutputContains(String message) { - assertTrue(errorOutput.contains(message), "erroroutput didn't contain " + message); + assertStdErr(containsString(message)); } static class Builder { From 71dbeb2acd998e89c482ab7c2f26c2318789dfc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 26 Feb 2023 15:35:28 +0100 Subject: [PATCH 11/12] Revert version change --- pmd-core/src/main/java/net/sourceforge/pmd/PMDVersion.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMDVersion.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMDVersion.java index d7391eb7e5..96565eca93 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMDVersion.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMDVersion.java @@ -23,7 +23,7 @@ public final class PMDVersion { */ public static final String VERSION; - private static final String UNKNOWN_VERSION = "7.0.0-SNAPSHOT"; + private static final String UNKNOWN_VERSION = "unknown"; /** * Determines the version from maven's generated pom.properties file. From bf2c69921e16fc5bd5ca5fe794e93aea6cd6f264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 26 Feb 2023 16:23:12 +0100 Subject: [PATCH 12/12] Fix merge --- .../java/net/sourceforge/pmd/it/AnalysisCacheIT.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/AnalysisCacheIT.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/AnalysisCacheIT.java index ef010cb850..b9a4478ec3 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/AnalysisCacheIT.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/AnalysisCacheIT.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd.it; +import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; @@ -25,7 +26,7 @@ class AnalysisCacheIT extends AbstractBinaryDistributionTest { // Ensure we have violations and a non-empty cache file assertTrue(cacheFile.toFile().length() > 0, "cache file is empty after run"); - result.assertExecutionResult(4, "", srcDir + File.separator + "JumbledIncrementer.java:8:\tJumbledIncrementer:\t"); + result.assertExitCode(4).assertReport(containsString(srcDir + File.separator + "JumbledIncrementer.java:8:\tJumbledIncrementer:\t")); // rerun from cache ExecutionResult resultFromCache = PMDExecutor.runPMD(createTemporaryReportFile(), tempDir, "-d", srcDir, "-R", "src/test/resources/rulesets/sample-ruleset.xml", @@ -45,7 +46,8 @@ class AnalysisCacheIT extends AbstractBinaryDistributionTest { // Ensure we have violations and a non-empty cache file assertTrue(cacheFile.toFile().length() > 0, "cache file is empty after run"); - result.assertExecutionResult(4, "", srcDir + File.separator + "JumbledIncrementer.java:8:\tJumbledIncrementer:\t"); + result.assertExitCode(4) + .assertReport(containsString(srcDir + File.separator + "JumbledIncrementer.java:8:\tJumbledIncrementer:\t")); // rerun from cache with relativized paths ExecutionResult resultFromCache = PMDExecutor.runPMD(createTemporaryReportFile(), tempDir, "-d", Paths.get(".").toAbsolutePath().relativize(Paths.get(srcDir)).toString(), "-R", "src/test/resources/rulesets/sample-ruleset.xml", @@ -54,7 +56,8 @@ class AnalysisCacheIT extends AbstractBinaryDistributionTest { resultFromCache.assertErrorOutputContains("Incremental Analysis cache HIT"); // An error with the relative path should exist, but no with the absolute one - resultFromCache.assertExecutionResult(4, "", "src/test/resources/sample-source/java/JumbledIncrementer.java:8:\tJumbledIncrementer:\t".replace('/', File.separatorChar)); + result.assertExitCode(4) + .assertReport(containsString("src/test/resources/sample-source/java/JumbledIncrementer.java:8:\tJumbledIncrementer:\t".replace('/', File.separatorChar))); resultFromCache.assertNoErrorInReport(srcDir + File.separator + "JumbledIncrementer.java:8:\tJumbledIncrementer:\t"); } }