diff --git a/.travis.yml b/.travis.yml index cdcc09e7e7..c7968bbd5c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,19 +18,19 @@ matrix: include: - name: "linux - mvn deploy" os: linux - dist: trusty + dist: bionic env: BUILD=deploy - name: "linux - build documentation" os: linux - dist: trusty + dist: bionic env: BUILD=doc - name: "linux - run sonar" os: linux - dist: trusty + dist: bionic env: BUILD=sonar - name: "linux - run coveralls" os: linux - dist: trusty + dist: bionic env: BUILD=coveralls - name: "macosx - mvn verify" os: osx diff --git a/do-release.sh b/do-release.sh index 5790e5d4bb..0a8108ba1f 100755 --- a/do-release.sh +++ b/do-release.sh @@ -124,7 +124,8 @@ git commit -a -m "Prepare pmd release ${RELEASE_VERSION}" ./mvnw -B release:clean release:prepare \ -Dtag=pmd_releases/${RELEASE_VERSION} \ -DreleaseVersion=${RELEASE_VERSION} \ - -DdevelopmentVersion=${DEVELOPMENT_VERSION} + -DdevelopmentVersion=${DEVELOPMENT_VERSION} \ + -Pgenerate-rule-docs echo diff --git a/docs/pages/pmd/userdocs/cli_reference.md b/docs/pages/pmd/userdocs/cli_reference.md index 2be730b98c..91d319095b 100644 --- a/docs/pages/pmd/userdocs/cli_reference.md +++ b/docs/pages/pmd/userdocs/cli_reference.md @@ -88,7 +88,7 @@ The tool comes with a rather extensive help text, simply running with `-help`! %} {% include custom/cli_option_row.html options="-language,-l" option_arg="lang" - description="Specify the language PMD should use." + description="Specify the language PMD should use. Used together with `-version`. See also [Supported Languages](#supported-languages)." %} {% include custom/cli_option_row.html options="-minimumpriority,-min" option_arg="num" @@ -138,7 +138,7 @@ The tool comes with a rather extensive help text, simply running with `-help`! %} {% include custom/cli_option_row.html options="-version,-v" option_arg="version" - description="Specify the version of a language PMD should use." + description="Specify the version of a language PMD should use. Used together with `-language`. See also [Supported Languages](#supported-languages)." %} @@ -166,12 +166,28 @@ This behavior has been introduced to ease PMD integration into scripts or hooks, ## Supported Languages +The language is determined automatically by PMD from the file extensions. Some languages such as "Java" +however support multiple versions. The default version will be used, which is usually the latest supported +version. If you want to use an older version, so that e.g. rules, that suggest usage of language features, +that are not available yet, won't be executed, you need to specify a specific version via the `-language` +and `-version` parameter. + +These parameters are irrelevant for languages that don't support different versions. + +Example: + +``` shell +./run.sh pmd -d src/main/java -f text -R rulesets/java/quickstart.xml -language java -version 8 +``` + * [apex](pmd_rules_apex.html) (Salesforce Apex) * [java](pmd_rules_java.html) + * Supported Versions: 1.3, 1.4, 1.5, 5, 1.6, 6, 1.7, 7, 1.8, 8, 9, 1.9, 10, 1.10, 11, 12, 13 (default), 13-preview * [ecmascript](pmd_rules_ecmascript.html) (JavaScript) * [jsp](pmd_rules_jsp.html) * [plsql](pmd_rules_plsql.html) * [scala](pmd_rules_scala.html) + * Supported Versions: 2.10, 2.11, 2.12, 2.13 (default) * [vf](pmd_rules_vf.html) (Salesforce VisualForce) * [vm](pmd_rules_vm.html) (Apache Velocity) * [xml and xsl](pmd_rules_xml.html) diff --git a/docs/pages/pmd/userdocs/tools/ant.md b/docs/pages/pmd/userdocs/tools/ant.md index 5939a05ffa..7fb2d0bf34 100644 --- a/docs/pages/pmd/userdocs/tools/ant.md +++ b/docs/pages/pmd/userdocs/tools/ant.md @@ -209,20 +209,33 @@ nested element. Possible values are: + + + + + + - + + + - - + + + + + + + ### Postprocessing the report file with XSLT diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 8abb75f161..a331aa14fe 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -21,9 +21,20 @@ This is a {{ site.pmd.release_type }} release. ### Fixed Issues +* apex + * [#2092](https://github.com/pmd/pmd/issues/2092): \[apex] ApexLexer logs visible when Apex is the selected language upon starting the designer +* core + * [#2096](https://github.com/pmd/pmd/issues/2096): \[core] Referencing category errorprone.xml produces deprecation warnings for InvalidSlf4jMessageFormat +* java + * [#1861](https://github.com/pmd/pmd/issues/1861): \[java] Be more lenient with version numbers + ### API Changes ### External Contributions +* [#2088](https://github.com/pmd/pmd/pull/2088): \[java] Add more version shortcuts for older java - [Henning Schmiedehausen](https://github.com/hgschmie) +* [#2089](https://github.com/pmd/pmd/pull/2089): \[core] Minor unrelated improvements to code - [Gonzalo Exequiel Ibars Ingman](https://github.com/gibarsin) +* [#2091](https://github.com/pmd/pmd/pull/2091): \[core] Fix pmd warnings (IdenticalCatchCases) - [Gonzalo Exequiel Ibars Ingman](https://github.com/gibarsin) + {% endtocmaker %} diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexJorjeLogging.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexJorjeLogging.java index ae7a827737..2b7b12c63e 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexJorjeLogging.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexJorjeLogging.java @@ -10,6 +10,9 @@ import java.util.logging.Logger; import apex.jorje.parser.impl.BaseApexLexer; public final class ApexJorjeLogging { + // note: that's a static/strong reference in order to avoid that the logger is garbage collected + private static final Logger APEX_LOGGER = Logger.getLogger(BaseApexLexer.class.getName()); + private ApexJorjeLogging() { // this is a utility class } @@ -19,7 +22,6 @@ public final class ApexJorjeLogging { // Jul 16, 2017 8:49:56 PM apex.jorje.parser.impl.BaseApexLexer dedupe // INFORMATION: Deduped array ApexLexer.DFA23_transition. Found 7927114 shorts which is 15MB not // including array overhead. Removed 7204963 shorts which is 13MB not counting array overhead. Took 18ms. - Logger log = Logger.getLogger(BaseApexLexer.class.getSimpleName()); - log.setLevel(Level.WARNING); + APEX_LOGGER.setLevel(Level.WARNING); } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java index 29211e764a..6894c50daa 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java @@ -37,6 +37,7 @@ import net.sourceforge.pmd.lang.LanguageVersionDiscoverer; import net.sourceforge.pmd.lang.LanguageVersionHandler; import net.sourceforge.pmd.lang.Parser; import net.sourceforge.pmd.lang.ParserOptions; +import net.sourceforge.pmd.processor.AbstractPMDProcessor; import net.sourceforge.pmd.processor.MonoThreadProcessor; import net.sourceforge.pmd.processor.MultiThreadProcessor; import net.sourceforge.pmd.renderers.Renderer; @@ -205,7 +206,7 @@ public class PMD { final RuleSets ruleSets = RulesetsFactoryUtils.getRuleSetsWithBenchmark(configuration.getRuleSets(), ruleSetFactory); if (ruleSets == null) { - return 0; + return PMDCommandLineInterface.NO_ERRORS_STATUS; } final Set languages = getApplicableLanguages(configuration, ruleSets); @@ -250,7 +251,7 @@ public class PMD { } LOG.log(Level.FINE, "Exception during processing", e); LOG.info(PMDCommandLineInterface.buildUsageText()); - return 0; + return PMDCommandLineInterface.NO_ERRORS_STATUS; } finally { /* * Make sure it's our own classloader before attempting to close it.... @@ -297,34 +298,13 @@ public class PMD { */ public static void processFiles(final PMDConfiguration configuration, final RuleSetFactory ruleSetFactory, final List files, final RuleContext ctx, final List renderers) { - - if (!configuration.isIgnoreIncrementalAnalysis() - && configuration.getAnalysisCache() instanceof NoopAnalysisCache - && LOG.isLoggable(Level.WARNING)) { - final String version = PMDVersion.isUnknown() || PMDVersion.isSnapshot() ? "latest" : "pmd-" + PMDVersion.VERSION; - LOG.warning("This analysis could be faster, please consider using Incremental Analysis: " - + "https://pmd.github.io/" + version + "/pmd_userdocs_incremental_analysis.html"); - } - + encourageToUseIncrementalAnalysis(configuration); sortFiles(configuration, files); - // Make sure the cache is listening for analysis results ctx.getReport().addListener(configuration.getAnalysisCache()); final RuleSetFactory silentFactory = new RuleSetFactory(ruleSetFactory, false); - - /* - * Check if multithreaded support is available. ExecutorService can also - * be disabled if threadCount is not positive, e.g. using the - * "-threads 0" command line option. - */ - if (configuration.getThreads() > 0) { - new MultiThreadProcessor(configuration).processFiles(silentFactory, files, ctx, renderers); - } else { - new MonoThreadProcessor(configuration).processFiles(silentFactory, files, ctx, renderers); - } - - // Persist the analysis cache + newFileProcessor(configuration).processFiles(silentFactory, files, ctx, renderers); configuration.getAnalysisCache().persist(); } @@ -346,6 +326,26 @@ public class PMD { } } + private static void encourageToUseIncrementalAnalysis(final PMDConfiguration configuration) { + if (!configuration.isIgnoreIncrementalAnalysis() + && configuration.getAnalysisCache() instanceof NoopAnalysisCache + && LOG.isLoggable(Level.WARNING)) { + final String version = + PMDVersion.isUnknown() || PMDVersion.isSnapshot() ? "latest" : "pmd-" + PMDVersion.VERSION; + LOG.warning("This analysis could be faster, please consider using Incremental Analysis: " + + "https://pmd.github.io/" + version + "/pmd_userdocs_incremental_analysis.html"); + } + } + + /* + * Check if multithreaded support is available. ExecutorService can also + * be disabled if threadCount is not positive, e.g. using the + * "-threads 0" command line option. + */ + private static AbstractPMDProcessor newFileProcessor(final PMDConfiguration configuration) { + return configuration.getThreads() > 0 ? new MultiThreadProcessor(configuration) : new MonoThreadProcessor(configuration); + } + /** * Determines all the files, that should be analyzed by PMD. * @@ -420,20 +420,19 @@ public class PMD { return files; } - private static Set getApplicableLanguages(PMDConfiguration configuration, RuleSets ruleSets) { - Set languages = new HashSet<>(); - LanguageVersionDiscoverer discoverer = configuration.getLanguageVersionDiscoverer(); + private static Set getApplicableLanguages(final PMDConfiguration configuration, final RuleSets ruleSets) { + final Set languages = new HashSet<>(); + final LanguageVersionDiscoverer discoverer = configuration.getLanguageVersionDiscoverer(); - for (Rule rule : ruleSets.getAllRules()) { - Language language = rule.getLanguage(); - if (languages.contains(language)) { - continue; - } - LanguageVersion version = discoverer.getDefaultLanguageVersion(language); - if (RuleSet.applies(rule, version)) { - languages.add(language); - if (LOG.isLoggable(Level.FINE)) { - LOG.fine("Using " + language.getShortName() + " version: " + version.getShortName()); + for (final Rule rule : ruleSets.getAllRules()) { + final Language ruleLanguage = rule.getLanguage(); + if (!languages.contains(ruleLanguage)) { + final LanguageVersion version = discoverer.getDefaultLanguageVersion(ruleLanguage); + if (RuleSet.applies(rule, version)) { + languages.add(ruleLanguage); + if (LOG.isLoggable(Level.FINE)) { + LOG.fine("Using " + ruleLanguage.getShortName() + " version: " + version.getShortName()); + } } } } @@ -466,7 +465,7 @@ public class PMD { TimeTracker.startGlobalTracking(); } - int status; + int status = PMDCommandLineInterface.NO_ERRORS_STATUS; final PMDConfiguration configuration = params.toConfiguration(); final Level logLevel = params.isDebug() ? Level.FINER : Level.INFO; @@ -481,7 +480,7 @@ public class PMD { if (violations > 0 && configuration.isFailOnViolation()) { status = PMDCommandLineInterface.VIOLATIONS_FOUND; } else { - status = 0; + status = PMDCommandLineInterface.NO_ERRORS_STATUS; } } catch (Exception e) { System.out.println(PMDCommandLineInterface.buildUsageText()); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java index 9c62b9a22a..0973dfc216 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java @@ -639,6 +639,10 @@ public class RuleSetFactory { && containsRule(ruleSetReferenceId, otherRuleSetReferenceId.getRuleName())) { otherRuleSetReferenceId = new RuleSetReferenceId(ref, ruleSetReferenceId); isSameRuleSet = true; + } else if (otherRuleSetReferenceId.isExternal() + && otherRuleSetReferenceId.getRuleSetFileName().equals(ruleSetReferenceId.getRuleSetFileName())) { + otherRuleSetReferenceId = new RuleSetReferenceId(otherRuleSetReferenceId.getRuleName(), ruleSetReferenceId); + isSameRuleSet = true; } // do not ignore deprecated rule references Rule referencedRule = ruleSetFactory.createRule(otherRuleSetReferenceId, true); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java index 70f6f23b41..97aa27ca45 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java @@ -90,13 +90,7 @@ public class RuleSetWriter { transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.transform(new DOMSource(document), new StreamResult(outputStream)); - } catch (DOMException e) { - throw new RuntimeException(e); - } catch (FactoryConfigurationError e) { - throw new RuntimeException(e); - } catch (ParserConfigurationException e) { - throw new RuntimeException(e); - } catch (TransformerException e) { + } catch (DOMException | FactoryConfigurationError | ParserConfigurationException | TransformerException e) { throw new RuntimeException(e); } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/SourceCodeProcessor.java b/pmd-core/src/main/java/net/sourceforge/pmd/SourceCodeProcessor.java index 64abfb8860..d7dcfd6881 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/SourceCodeProcessor.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/SourceCodeProcessor.java @@ -85,26 +85,36 @@ public class SourceCodeProcessor { // Coarse check to see if any RuleSet applies to file, will need to do a finer RuleSet specific check later if (ruleSets.applies(ctx.getSourceCodeFile())) { - // Is the cache up to date? - if (configuration.getAnalysisCache().isUpToDate(ctx.getSourceCodeFile())) { - for (final RuleViolation rv : configuration.getAnalysisCache().getCachedViolations(ctx.getSourceCodeFile())) { - ctx.getReport().addRuleViolation(rv); - } - return; + if (isCacheUpToDate(ctx)) { + reportCachedRuleViolations(ctx); + } else { + processSourceCodeWithoutCache(sourceCode, ruleSets, ctx); } + } + } - try { - ruleSets.start(ctx); - processSource(sourceCode, ruleSets, ctx); - } catch (ParseException pe) { - configuration.getAnalysisCache().analysisFailed(ctx.getSourceCodeFile()); - throw new PMDException("Error while parsing " + ctx.getSourceCodeFile(), pe); - } catch (Exception e) { - configuration.getAnalysisCache().analysisFailed(ctx.getSourceCodeFile()); - throw new PMDException("Error while processing " + ctx.getSourceCodeFile(), e); - } finally { - ruleSets.end(ctx); - } + private boolean isCacheUpToDate(final RuleContext ctx) { + return configuration.getAnalysisCache().isUpToDate(ctx.getSourceCodeFile()); + } + + private void reportCachedRuleViolations(final RuleContext ctx) { + for (final RuleViolation rv : configuration.getAnalysisCache().getCachedViolations(ctx.getSourceCodeFile())) { + ctx.getReport().addRuleViolation(rv); + } + } + + private void processSourceCodeWithoutCache(final Reader sourceCode, final RuleSets ruleSets, final RuleContext ctx) throws PMDException { + try { + ruleSets.start(ctx); + processSource(sourceCode, ruleSets, ctx); + } catch (ParseException pe) { + configuration.getAnalysisCache().analysisFailed(ctx.getSourceCodeFile()); + throw new PMDException("Error while parsing " + ctx.getSourceCodeFile(), pe); + } catch (Exception e) { + configuration.getAnalysisCache().analysisFailed(ctx.getSourceCodeFile()); + throw new PMDException("Error while processing " + ctx.getSourceCodeFile(), e); + } finally { + ruleSets.end(ctx); } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDCommandLineInterface.java b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDCommandLineInterface.java index e7244963ef..a39a80c9ba 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDCommandLineInterface.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDCommandLineInterface.java @@ -29,7 +29,7 @@ public final class PMDCommandLineInterface { public static final String NO_EXIT_AFTER_RUN = "net.sourceforge.pmd.cli.noExit"; public static final String STATUS_CODE_PROPERTY = "net.sourceforge.pmd.cli.status"; - private static final int NO_ERRORS_STATUS = 0; + public static final int NO_ERRORS_STATUS = 0; public static final int ERROR_STATUS = 1; public static final int VIOLATIONS_FOUND = 4; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/BaseLanguageModule.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/BaseLanguageModule.java index 0b27364143..1bd21375cf 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/BaseLanguageModule.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/BaseLanguageModule.java @@ -13,6 +13,8 @@ import java.util.Map; import org.checkerframework.checker.nullness.qual.NonNull; +import net.sourceforge.pmd.annotation.Experimental; + /** * Created by christoferdutz on 21.09.14. */ @@ -35,6 +37,23 @@ public abstract class BaseLanguageModule implements Language { this.extensions = Arrays.asList(extensions); } + @Experimental + protected void addVersions(LanguageVersionHandler languageVersionHandler, boolean isDefault, String ... languageVersions) { + if (versions == null) { + versions = new HashMap<>(); + } + + LanguageVersion languageVersion = new LanguageVersion(this, languageVersions[0], languageVersionHandler); + + for (String version : languageVersions) { + versions.put(version, languageVersion); + } + + if (isDefault) { + defaultVersion = languageVersion; + } + } + protected void addVersion(String version, LanguageVersionHandler languageVersionHandler, boolean isDefault) { if (versions == null) { versions = new HashMap<>(); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/processor/AbstractPMDProcessor.java b/pmd-core/src/main/java/net/sourceforge/pmd/processor/AbstractPMDProcessor.java index ba0fd98460..9b1af9682c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/processor/AbstractPMDProcessor.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/processor/AbstractPMDProcessor.java @@ -110,11 +110,11 @@ public abstract class AbstractPMDProcessor { // this is done manually without a try-with-resources public void processFiles(RuleSetFactory ruleSetFactory, List files, RuleContext ctx, List renderers) { - RuleSets rs = createRuleSets(ruleSetFactory, ctx.getReport()); + final RuleSets rs = createRuleSets(ruleSetFactory, ctx.getReport()); configuration.getAnalysisCache().checkValidity(rs, configuration.getClassLoader()); - SourceCodeProcessor processor = new SourceCodeProcessor(configuration); + final SourceCodeProcessor processor = new SourceCodeProcessor(configuration); - for (DataSource dataSource : files) { + for (final DataSource dataSource : files) { // this is the real, canonical and absolute filename (not shortened) String realFileName = dataSource.getNiceFileName(false, null); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java index 7ab3f3d8ba..292d41dae7 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java @@ -25,6 +25,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import net.sourceforge.pmd.junit.JavaUtilLoggingRule; +import net.sourceforge.pmd.junit.LocaleRule; import net.sourceforge.pmd.lang.DummyLanguageModule; import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.rule.MockRule; @@ -37,6 +38,9 @@ public class RuleSetFactoryTest { @org.junit.Rule public ExpectedException ex = ExpectedException.none(); + @org.junit.Rule + public LocaleRule localeRule = LocaleRule.en(); + @Test public void testRuleSetFileName() throws RuleSetNotFoundException { RuleSet rs = loadRuleSet(EMPTY_RULESET); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/junit/LocaleRule.java b/pmd-core/src/test/java/net/sourceforge/pmd/junit/LocaleRule.java new file mode 100644 index 0000000000..63a5d57579 --- /dev/null +++ b/pmd-core/src/test/java/net/sourceforge/pmd/junit/LocaleRule.java @@ -0,0 +1,49 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.junit; + +import java.util.Locale; +import java.util.Objects; + +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; + +/** + * + * Based on digulla/DefaultLocaleRule.java. + * + */ +public class LocaleRule extends TestWatcher { + + private Locale localeForTest; + private Locale originalDefault; + + private LocaleRule(Locale localeForTest) { + this.localeForTest = Objects.requireNonNull(localeForTest); + } + + @Override + protected void starting(Description description) { + originalDefault = Locale.getDefault(); + Locale.setDefault(localeForTest); + } + + @Override + protected void finished(Description description) { + Locale.setDefault(originalDefault); + } + + public void setDefault(Locale newLocale) { + Locale.setDefault(Objects.requireNonNull(newLocale)); + } + + public static LocaleRule en() { + return new LocaleRule(Locale.ENGLISH); + } + + public static LocaleRule de() { + return new LocaleRule(Locale.GERMAN); + } +} diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java index 5493c4f121..efb79b5ee3 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java @@ -38,10 +38,10 @@ public class DummyLanguageModule extends BaseLanguageModule { addVersion("1.2", new Handler(), false); addVersion("1.3", new Handler(), false); addVersion("1.4", new Handler(), false); - addVersion("1.5", new Handler(), false); - addVersion("1.6", new Handler(), false); - addVersion("1.7", new Handler(), true); - addVersion("1.8", new Handler(), false); + addVersions(new Handler(), false, "1.5", "5"); + addVersions(new Handler(), false, "1.6", "6"); + addVersions(new Handler(), true, "1.7", "7"); + addVersions(new Handler(), false, "1.8", "8"); } public static class DummyRuleChainVisitor extends AbstractRuleChainVisitor { diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/LanguageRegistryTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/LanguageRegistryTest.java index 76016e4faf..f7fd11c0ce 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/LanguageRegistryTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/LanguageRegistryTest.java @@ -18,4 +18,29 @@ public class LanguageRegistryTest { Assert.assertSame(DummyLanguageModule.class, defaultLanguage.getClass()); } + @Test + public void getDefaultVersionLanguageTest() { + Language dummy = LanguageRegistry.findLanguageByTerseName("dummy"); + LanguageVersion dummy12 = dummy.getVersion("1.2"); + Assert.assertNotNull(dummy12); + + LanguageVersion dummyDefault = dummy.getDefaultVersion(); + Assert.assertNotNull(dummyDefault); + + Assert.assertNotSame(dummy12, dummyDefault); + } + + @Test + public void getLanguageVersionByAliasTest() { + Language dummy = LanguageRegistry.findLanguageByTerseName("dummy"); + + LanguageVersion dummy17 = dummy.getVersion("1.7"); + Assert.assertNotNull(dummy17); + Assert.assertEquals("1.7", dummy17.getVersion()); + + LanguageVersion dummy7 = dummy.getVersion("7"); + Assert.assertNotNull(dummy7); + Assert.assertEquals("1.7", dummy17.getVersion()); + Assert.assertSame(dummy17, dummy7); + } } diff --git a/pmd-core/src/test/resources/rulesets/dummy/basic.xml b/pmd-core/src/test/resources/rulesets/dummy/basic.xml index f0a9dba6bd..3644f408d1 100644 --- a/pmd-core/src/test/resources/rulesets/dummy/basic.xml +++ b/pmd-core/src/test/resources/rulesets/dummy/basic.xml @@ -18,7 +18,11 @@ Just for test + + + 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 4819106502..778f0381de 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 @@ -40,7 +40,11 @@ public class AllRulesIT extends AbstractBinaryDistributionTest { result.assertNoError("Exception applying rule"); result.assertNoError("Ruleset not found"); result.assertNoError("Use of deprecated attribute"); + result.assertNoError("instead of the deprecated"); // rule deprecations result.assertNoErrorInReport("Error while processing"); result.assertNoErrorInReport("Error while parsing"); + + // See bug #2092: [apex] ApexLexer logs visible when Apex is the selected language upon starting the designer + result.assertNoError("Deduped array ApexLexer"); } } 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 42be030360..a8052f8f32 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 @@ -19,12 +19,12 @@ public class JavaLanguageModule extends BaseLanguageModule { super(NAME, null, TERSE_NAME, JavaRuleChainVisitor.class, "java"); addVersion("1.3", new JavaLanguageHandler(3), false); addVersion("1.4", new JavaLanguageHandler(4), false); - addVersion("1.5", new JavaLanguageHandler(5), false); - addVersion("1.6", new JavaLanguageHandler(6), false); - addVersion("1.7", new JavaLanguageHandler(7), false); - addVersion("1.8", new JavaLanguageHandler(8), false); - addVersion("9", new JavaLanguageHandler(9), false); - addVersion("10", new JavaLanguageHandler(10), false); + addVersions(new JavaLanguageHandler(5), false, "1.5", "5"); + addVersions(new JavaLanguageHandler(6), false, "1.6", "6"); + addVersions(new JavaLanguageHandler(7), false, "1.7", "7"); + addVersions(new JavaLanguageHandler(8), false, "1.8", "8"); + addVersions(new JavaLanguageHandler(9), false, "9", "1.9"); + addVersions(new JavaLanguageHandler(10), false, "10", "1.10"); addVersion("11", new JavaLanguageHandler(11), false); addVersion("12", new JavaLanguageHandler(12), false); addVersion("12-preview", new JavaLanguageHandler(12, true), false); diff --git a/pom.xml b/pom.xml index 956a1d435d..4076d737a4 100644 --- a/pom.xml +++ b/pom.xml @@ -363,12 +363,12 @@ Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift a net.sourceforge.pmd pmd-core - 6.18.0 + 6.19.0 net.sourceforge.pmd pmd-java - 6.18.0 + 6.19.0 @@ -391,7 +391,7 @@ Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift a org.jacoco jacoco-maven-plugin - 0.8.2 + 0.8.5 @@ -878,6 +878,14 @@ Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift a sign + + + + --pinentry-mode + loopback + + @@ -942,6 +950,7 @@ Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift a sonar https://sonarcloud.io + pmd @@ -949,7 +958,7 @@ Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift a org.sonarsource.scanner.maven sonar-maven-plugin - 3.4.1.1168 + 3.7.0.1746