Merge remote-tracking branch 'origin/master' into pmd/7.0.x
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)."
|
||||
%}
|
||||
</table>
|
||||
|
||||
@ -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)
|
||||
|
@ -209,20 +209,33 @@ nested element. Possible values are:
|
||||
<sourceLanguage name="java" version="1.3"/>
|
||||
<sourceLanguage name="java" version="1.4"/>
|
||||
<sourceLanguage name="java" version="1.5"/>
|
||||
<sourceLanguage name="java" version="5"/> <!-- alias for 1.5 -->
|
||||
<sourceLanguage name="java" version="1.6"/>
|
||||
<sourceLanguage name="java" version="6"/> <!-- alias for 1.6 -->
|
||||
<sourceLanguage name="java" version="1.7"/>
|
||||
<sourceLanguage name="java" version="7"/> <!-- alias for 1.7 -->
|
||||
<sourceLanguage name="java" version="1.8"/>
|
||||
<sourceLanguage name="java" version="8"/> <!-- alias for 1.8 -->
|
||||
<sourceLanguage name="java" version="9"/>
|
||||
<sourceLanguage name="java" version="1.9"/> <!-- alias for 9 -->
|
||||
<sourceLanguage name="java" version="10"/>
|
||||
<sourceLanguage name="java" version="1.10"/> <!-- alias for 10 -->
|
||||
<sourceLanguage name="java" version="11"/>
|
||||
<sourceLanguage name="java" version="12"/> <!-- this is the default -->
|
||||
<sourceLanguage name="java" version="12"/>
|
||||
<sourceLanguage name="java" version="13"/> <!-- this is the default -->
|
||||
<sourceLanguage name="java" version="13-preview"/>
|
||||
<sourceLanguage name="jsp" version=""/>
|
||||
<sourceLanguage name="pom" version=""/>
|
||||
<sourceLanguage name="plsql" version=""/>
|
||||
<sourceLanguage name="xsl" version=""/>
|
||||
<sourceLanguage name="xml" version=""/>
|
||||
<sourceLanguage name="scala" version="2.10"/>
|
||||
<sourceLanguage name="scala" version="2.11"/>
|
||||
<sourceLanguage name="scala" version="2.12"/>
|
||||
<sourceLanguage name="scala" version="2.13"/> <!-- this is the default -->
|
||||
<sourceLanguage name="vf" version=""/>
|
||||
<sourceLanguage name="vm" version=""/>
|
||||
<sourceLanguage name="wsdl" version=""/>
|
||||
<sourceLanguage name="xml" version=""/>
|
||||
<sourceLanguage name="xsl" version=""/>
|
||||
|
||||
### Postprocessing the report file with XSLT
|
||||
|
||||
|
@ -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 %}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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<Language> 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<DataSource> files, final RuleContext ctx, final List<Renderer> 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<Language> getApplicableLanguages(PMDConfiguration configuration, RuleSets ruleSets) {
|
||||
Set<Language> languages = new HashSet<>();
|
||||
LanguageVersionDiscoverer discoverer = configuration.getLanguageVersionDiscoverer();
|
||||
private static Set<Language> getApplicableLanguages(final PMDConfiguration configuration, final RuleSets ruleSets) {
|
||||
final Set<Language> 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());
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<>();
|
||||
|
@ -110,11 +110,11 @@ public abstract class AbstractPMDProcessor {
|
||||
// this is done manually without a try-with-resources
|
||||
public void processFiles(RuleSetFactory ruleSetFactory, List<DataSource> files, RuleContext ctx,
|
||||
List<Renderer> 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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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 <a href="https://gist.github.com/digulla/5884162">digulla/DefaultLocaleRule.java</a>.
|
||||
*
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,11 @@ Just for test
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<!-- variant 1 of a renamed rule. This is definitively within the same ruleset. -->
|
||||
<rule deprecated="true" name="OldNameOfDummyBasicMockRule" ref="DummyBasicMockRule"/>
|
||||
<!-- variant 2 of a renamed and/or moved rule. This could also keep the rule name but
|
||||
move the rule into a different rule or do any combination of both -->
|
||||
<rule deprecated="true" name="OldNameOfDummyBasicMockRule2" ref="rulesets/dummy/basic.xml/DummyBasicMockRule"/>
|
||||
|
||||
<rule name="SampleXPathRule" language="dummy" since="1.1" message="Test Rule 2" class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/dummy/basic.xml#SampleXPathRule">
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
17
pom.xml
17
pom.xml
@ -363,12 +363,12 @@ Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift a
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-core</artifactId>
|
||||
<version>6.18.0</version>
|
||||
<version>6.19.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-java</artifactId>
|
||||
<version>6.18.0</version>
|
||||
<version>6.19.0</version>
|
||||
</dependency>
|
||||
<!-- This contains the dogfood ruleset -->
|
||||
<dependency>
|
||||
@ -391,7 +391,7 @@ Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift a
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.2</version>
|
||||
<version>0.8.5</version>
|
||||
</plugin>
|
||||
<!--This plugin's configuration is used to store Eclipse
|
||||
m2e settings only. It has no influence on the Maven build itself. -->
|
||||
@ -878,6 +878,14 @@ Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift a
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<!-- https://issues.apache.org/jira/browse/MGPG-59 - once m-gpg-p 1.7. is released,
|
||||
this should not be needed anymore -->
|
||||
<gpgArguments>
|
||||
<arg>--pinentry-mode</arg>
|
||||
<arg>loopback</arg>
|
||||
</gpgArguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
@ -942,6 +950,7 @@ Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift a
|
||||
<id>sonar</id>
|
||||
<properties>
|
||||
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
||||
<sonar.organization>pmd</sonar.organization>
|
||||
</properties>
|
||||
<build>
|
||||
<pluginManagement>
|
||||
@ -949,7 +958,7 @@ Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift a
|
||||
<plugin>
|
||||
<groupId>org.sonarsource.scanner.maven</groupId>
|
||||
<artifactId>sonar-maven-plugin</artifactId>
|
||||
<version>3.4.1.1168</version>
|
||||
<version>3.7.0.1746</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
Reference in New Issue
Block a user