Some corrections for PR #954

This commit is contained in:
Clément Fournier
2018-03-05 16:47:34 +01:00
parent e2c6f1e467
commit ff1c90d753
4 changed files with 63 additions and 58 deletions

View File

@@ -39,6 +39,9 @@ Both are bugfixing releases.
### API Changes
* The static method `PMDParameters.transformParametersIntoConfiguration(PMDParameters)` is now deprecated,
for removal in 7.0.0. The new instance method `PMDParameters.toConfiguration()` replaces it.
### External Contributions
* [#941](https://github.com/pmd/pmd/pull/941): \[java] Use char notation to represent a character to improve performance - [reudismam](https://github.com/reudismam)

View File

@@ -203,6 +203,13 @@ public class PMD {
return 0;
}
// Log warning only once, if not explicitly disabled
if (!configuration.isIgnoreIncrementalAnalysis() && 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_getting_started.html#incremental-analysis");
}
Set<Language> languages = getApplicableLanguages(configuration, ruleSets);
List<DataSource> files = getApplicableFiles(configuration, languages);

View File

@@ -9,7 +9,6 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sourceforge.pmd.cache.AnalysisCache;
@@ -110,7 +109,7 @@ public class PMDConfiguration extends AbstractConfiguration {
private boolean stressTest;
private boolean benchmark;
private AnalysisCache analysisCache;
private AnalysisCache analysisCache = new NoopAnalysisCache();
private boolean ignoreIncrementalAnalysis;
/**
@@ -558,8 +557,7 @@ public class PMDConfiguration extends AbstractConfiguration {
/**
* Sets the rule set factory compatibility feature enabled/disabled.
*
* @param ruleSetFactoryCompatibilityEnabled
* <code>true</code> if the feature should be enabled
* @param ruleSetFactoryCompatibilityEnabled {@code true} if the feature should be enabled
*
* @see RuleSetFactoryCompatibility
*/
@@ -576,7 +574,7 @@ public class PMDConfiguration extends AbstractConfiguration {
// Make sure we are not null
if (analysisCache == null || isIgnoreIncrementalAnalysis() && isAnalysisCacheFunctional()) {
// sets a noop cache
setAnalysisCache(null);
setAnalysisCache(new NoopAnalysisCache());
}
return analysisCache;
@@ -587,22 +585,17 @@ public class PMDConfiguration extends AbstractConfiguration {
* value of {@code null} will cause a Noop AnalysisCache to be used.
* If incremental analysis was explicitly disabled ({@link #isIgnoreIncrementalAnalysis()}),
* then this method is a noop.
*
*
* @param cache The analysis cache to be used.
*/
public void setAnalysisCache(final AnalysisCache cache) {
if (cache == null && isAnalysisCacheFunctional()) {
analysisCache = new NoopAnalysisCache();
// Log warning only once, if not explicitly disabled
if (!isIgnoreIncrementalAnalysis() && 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_getting_started.html#incremental-analysis");
}
} else if (!isIgnoreIncrementalAnalysis()) { // ignore new value if incr. analysis is disabled
} else {
analysisCache = cache;
}
// the doc says it's a noop if incremental analysis was disabled,
// but it's actually the getter that enforces that
}
/**
@@ -612,11 +605,9 @@ public class PMDConfiguration extends AbstractConfiguration {
* @param cacheLocation The location of the analysis cache to be used.
*/
public void setAnalysisCacheLocation(final String cacheLocation) {
if (cacheLocation == null) {
setAnalysisCache(null);
} else {
setAnalysisCache(new FileAnalysisCache(new File(cacheLocation)));
}
setAnalysisCache(cacheLocation == null
? new NoopAnalysisCache()
: new FileAnalysisCache(new File(cacheLocation)));
}
/** Returns true if the current analysis cache isn't noop. */

View File

@@ -152,8 +152,43 @@ public class PMDParameters {
* @throws IllegalArgumentException if the parameters are inconsistent or incomplete
*/
public PMDConfiguration toConfiguration() {
// the static method could probably be deprecated in favour of this one
return transformParametersIntoConfiguration(this);
if (null == this.getSourceDir() && null == this.getUri() && null == this.getFileListPath()) {
throw new IllegalArgumentException(
"Please provide a parameter for source root directory (-dir or -d), database URI (-uri or -u), or file list path (-filelist).");
}
PMDConfiguration configuration = new PMDConfiguration();
configuration.setInputPaths(this.getSourceDir());
configuration.setInputFilePath(this.getFileListPath());
configuration.setInputUri(this.getUri());
configuration.setReportFormat(this.getFormat());
configuration.setBenchmark(this.isBenchmark());
configuration.setDebug(this.isDebug());
configuration.setMinimumPriority(this.getMinimumPriority());
configuration.setReportFile(this.getReportfile());
configuration.setReportProperties(this.getProperties());
configuration.setReportShortNames(this.isShortnames());
configuration.setRuleSets(this.getRulesets());
configuration.setRuleSetFactoryCompatibilityEnabled(!this.noRuleSetCompatibility);
configuration.setShowSuppressedViolations(this.isShowsuppressed());
configuration.setSourceEncoding(this.getEncoding());
configuration.setStressTest(this.isStress());
configuration.setSuppressMarker(this.getSuppressmarker());
configuration.setThreads(this.getThreads());
configuration.setFailOnViolation(this.isFailOnViolation());
configuration.setAnalysisCacheLocation(this.cacheLocation);
configuration.setIgnoreIncrementalAnalysis(this.isIgnoreIncrementalAnalysis());
LanguageVersion languageVersion = LanguageRegistry
.findLanguageVersionByTerseName(this.getLanguage() + ' ' + this.getVersion());
if (languageVersion != null) {
configuration.getLanguageVersionDiscoverer().setDefaultLanguageVersion(languageVersion);
}
try {
configuration.prependClasspath(this.getAuxclasspath());
} catch (IOException e) {
throw new IllegalArgumentException("Invalid auxiliary classpath: " + e.getMessage(), e);
}
return configuration;
}
@@ -162,44 +197,13 @@ public class PMDParameters {
}
/**
* {@link #toConfiguration()}.
* @deprecated To be removed in 7.0.0. Use the instance method {@link #toConfiguration()}.
*/
@Deprecated
public static PMDConfiguration transformParametersIntoConfiguration(PMDParameters params) {
if (null == params.getSourceDir() && null == params.getUri() && null == params.getFileListPath()) {
throw new IllegalArgumentException(
"Please provide a parameter for source root directory (-dir or -d), database URI (-uri or -u), or file list path (-filelist).");
}
PMDConfiguration configuration = new PMDConfiguration();
configuration.setInputPaths(params.getSourceDir());
configuration.setInputFilePath(params.getFileListPath());
configuration.setInputUri(params.getUri());
configuration.setReportFormat(params.getFormat());
configuration.setBenchmark(params.isBenchmark());
configuration.setDebug(params.isDebug());
configuration.setMinimumPriority(params.getMinimumPriority());
configuration.setReportFile(params.getReportfile());
configuration.setReportProperties(params.getProperties());
configuration.setReportShortNames(params.isShortnames());
configuration.setRuleSets(params.getRulesets());
configuration.setRuleSetFactoryCompatibilityEnabled(!params.noRuleSetCompatibility);
configuration.setShowSuppressedViolations(params.isShowsuppressed());
configuration.setSourceEncoding(params.getEncoding());
configuration.setStressTest(params.isStress());
configuration.setSuppressMarker(params.getSuppressmarker());
configuration.setThreads(params.getThreads());
configuration.setFailOnViolation(params.isFailOnViolation());
configuration.setAnalysisCacheLocation(params.cacheLocation);
configuration.setIgnoreIncrementalAnalysis(params.isIgnoreIncrementalAnalysis());
LanguageVersion languageVersion = LanguageRegistry
.findLanguageVersionByTerseName(params.getLanguage() + ' ' + params.getVersion());
if (languageVersion != null) {
configuration.getLanguageVersionDiscoverer().setDefaultLanguageVersion(languageVersion);
}
try {
configuration.prependClasspath(params.getAuxclasspath());
} catch (IOException e) {
throw new IllegalArgumentException("Invalid auxiliary classpath: " + e.getMessage(), e);
}
return configuration;
return params.toConfiguration();
}
public boolean isDebug() {