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 d8db81de9a..b13246dbf1 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java @@ -3,7 +3,9 @@ */ package net.sourceforge.pmd; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.net.URISyntaxException; @@ -85,7 +87,7 @@ public class PMD { /** * Create a PMD instance using the specified Configuration. - * + * * @param configuration * The runtime Configuration of PMD to use. */ @@ -158,7 +160,7 @@ public class PMD { /** * Create a report, filter out any defective rules, and keep a record of * them. - * + * * @param rs the rules * @param ctx the rule context * @param fileName the filename of the source file, which should appear in the report @@ -179,7 +181,7 @@ public class PMD { /** * Remove and return the misconfigured rules from the rulesets and log them * for good measure. - * + * * @param ruleSets * RuleSets * @return Set @@ -202,7 +204,7 @@ public class PMD { /** * Get the runtime configuration. The configuration can be modified to * affect how PMD behaves. - * + * * @return The configuration. * @see PMDConfiguration */ @@ -220,7 +222,7 @@ public class PMD { /** * This method is the main entry point for command line usage. - * + * * @param configuration the configure to use * @return number of violations found. */ @@ -299,14 +301,14 @@ public class PMD { /** * A callback that would be implemented by IDEs keeping track of PMD's * progress as it evaluates a set of files. - * + * * @author Brian Remedios */ public interface ProgressMonitor { /** * A status update reporting on current progress. Implementers will * return true if it is to continue, false otherwise. - * + * * @param total total number of files to be analyzed * @param totalDone number of files, that have been done analyzing. * @return true if the execution of PMD should continue, false if the execution @@ -318,7 +320,7 @@ public class PMD { /** * An entry point that would typically be used by IDEs intent on providing * ongoing feedback and the ability to terminate it at will. - * + * * @param configuration the PMD configuration to use * @param ruleSetFactory ruleset factory * @param files the files to analyze @@ -337,7 +339,7 @@ public class PMD { /** * Run PMD on a list of files using multiple threads - if more than one is * available - * + * * @param configuration * Configuration * @param ruleSetFactory @@ -417,6 +419,29 @@ public class PMD { throw new RuntimeException("Problem with DBURI: " + uriString, ex); } } + + if (null != configuration.getInputFilePath()) { + String inputFilePath = configuration.getInputFilePath(); + File file = new File(inputFilePath); + try { + if (!file.exists()) { + LOG.log(Level.SEVERE, "Problem with Input File Path", inputFilePath); + throw new RuntimeException("Problem with Input File Path: " + inputFilePath); + } else { + BufferedReader br = new BufferedReader(new FileReader(file)); + String filePaths = br.readLine(); + if (null == filePaths){ + LOG.log(Level.SEVERE, "Problem with Input File Path", inputFilePath); + throw new RuntimeException("Problem with Input File Path: " + inputFilePath); + } + files.addAll(FileUtil.collectFiles(filePaths, fileSelector)); + } + } catch (IOException ex) { + LOG.log(Level.SEVERE, "Problem with Input File", ex); + throw new RuntimeException("Problem with Input File Path: " + inputFilePath, ex); + } + + } return files; } @@ -442,7 +467,7 @@ public class PMD { /** * Entry to invoke PMD as command line tool - * + * * @param args command line arguments */ public static void main(String[] args) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java index 87a4f71f7b..a3f64c7ef8 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java @@ -96,6 +96,7 @@ public class PMDConfiguration extends AbstractConfiguration { private RulePriority minimumPriority = RulePriority.LOW; private String inputPaths; private String inputUri; + private String inputFilePath; private boolean ruleSetFactoryCompatibilityEnabled = true; // Reporting options @@ -112,7 +113,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Get the suppress marker. This is the source level marker used to indicate a * RuleViolation should be suppressed. - * + * * @return The suppress marker. */ public String getSuppressMarker() { @@ -121,7 +122,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Set the suppress marker. - * + * * @param suppressMarker * The suppress marker to use. */ @@ -131,7 +132,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Get the number of threads to use when processing Rules. - * + * * @return The number of threads. */ public int getThreads() { @@ -140,7 +141,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Set the number of threads to use when processing Rules. - * + * * @param threads * The number of threads. */ @@ -150,7 +151,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Get the ClassLoader being used by PMD when processing Rules. - * + * * @return The ClassLoader being used */ public ClassLoader getClassLoader() { @@ -160,7 +161,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Set the ClassLoader being used by PMD when processing Rules. Setting a * value of null will cause the default ClassLoader to be used. - * + * * @param classLoader * The ClassLoader to use */ @@ -181,7 +182,7 @@ public class PMDConfiguration extends AbstractConfiguration { * If the classpath String looks like a URL to a file (i.e. starts with * file://) the file will be read with each line representing * an entry on the classpath. - * + * * @param classpath The prepended classpath. * @throws IOException if the given classpath is invalid (e.g. does not exist) * @see PMDConfiguration#setClassLoader(ClassLoader) @@ -199,7 +200,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Get the LanguageVersionDiscoverer, used to determine the LanguageVersion * of a source file. - * + * * @return The LanguageVersionDiscoverer. */ public LanguageVersionDiscoverer getLanguageVersionDiscoverer() { @@ -208,7 +209,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Set the given LanguageVersion as the current default for it's Language. - * + * * @param languageVersion * the LanguageVersion */ @@ -219,7 +220,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Set the given LanguageVersions as the current default for their * Languages. - * + * * @param languageVersions * The LanguageVersions. */ @@ -235,7 +236,7 @@ public class PMDConfiguration extends AbstractConfiguration { *

* For compatibility with older code that does not always pass in a correct * filename, unrecognized files are assumed to be java files. - * + * * @param fileName * Name of the file, can be absolute, or simple. * @return the LanguageVersion @@ -255,7 +256,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Get the comma separated list of RuleSet URIs. - * + * * @return The RuleSet URIs. */ public String getRuleSets() { @@ -264,7 +265,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Set the comma separated list of RuleSet URIs. - * + * * @param ruleSets the rulesets to set */ public void setRuleSets(String ruleSets) { @@ -273,7 +274,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Get the minimum priority threshold when loading Rules from RuleSets. - * + * * @return The minimum priority threshold. */ public RulePriority getMinimumPriority() { @@ -282,7 +283,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Set the minimum priority threshold when loading Rules from RuleSets. - * + * * @param minimumPriority * The minimum priority. */ @@ -292,7 +293,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Get the comma separated list of input paths to process for source files. - * + * * @return A comma separated list. */ public String getInputPaths() { @@ -301,7 +302,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Set the comma separated list of input paths to process for source files. - * + * * @param inputPaths * The comma separated list. */ @@ -309,9 +310,17 @@ public class PMDConfiguration extends AbstractConfiguration { this.inputPaths = inputPaths; } + public String getInputFilePath() { + return inputFilePath; + } + + public void setInputFilePath(String inputFilePath) { + this.inputFilePath = inputFilePath; + } + /** * Get the input URI to process for source code objects. - * + * * @return URI */ public String getInputUri() { @@ -320,7 +329,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Set the input URI to process for source code objects. - * + * * @param inputUri * a single URI */ @@ -330,7 +339,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Get whether to use File short names in Reports. - * + * * @return true when using short names in reports. */ public boolean isReportShortNames() { @@ -339,7 +348,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Set whether to use File short names in Reports. - * + * * @param reportShortNames * true when using short names in reports. */ @@ -350,7 +359,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Create a Renderer instance based upon the configured reporting options. * No writer is created. - * + * * @return renderer */ public Renderer createRenderer() { @@ -361,7 +370,7 @@ public class PMDConfiguration extends AbstractConfiguration { * Create a Renderer instance based upon the configured reporting options. * If withReportWriter then we'll configure it with a writer for the * reportFile specified. - * + * * @param withReportWriter whether to configure a writer or not * @return A Renderer instance. */ @@ -376,7 +385,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Get the report format. - * + * * @return The report format. */ public String getReportFormat() { @@ -385,10 +394,10 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Set the report format. This should be a name of a Renderer. - * + * * @param reportFormat * The report format. - * + * * @see Renderer */ public void setReportFormat(String reportFormat) { @@ -397,7 +406,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Get the file to which the report should render. - * + * * @return The file to which to render. */ public String getReportFile() { @@ -406,7 +415,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Set the file to which the report should render. - * + * * @param reportFile the file to set */ public void setReportFile(String reportFile) { @@ -415,7 +424,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Get whether the report should show suppressed violations. - * + * * @return true if showing suppressed violations, * false otherwise. */ @@ -425,7 +434,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Set whether the report should show suppressed violations. - * + * * @param showSuppressedViolations * true if showing suppressed violations, * false otherwise. @@ -436,7 +445,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Get the Report properties. These are used to create the Renderer. - * + * * @return The report properties. */ public Properties getReportProperties() { @@ -445,7 +454,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Set the Report properties. These are used to create the Renderer. - * + * * @param reportProperties * The Report properties to set. */ @@ -457,7 +466,7 @@ public class PMDConfiguration extends AbstractConfiguration { * Return the stress test indicator. If this value is true then * PMD will randomize the order of file processing to attempt to shake out * bugs. - * + * * @return true if stress test is enbaled, false * otherwise. */ @@ -467,7 +476,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Set the stress test indicator. - * + * * @param stressTest * The stree test indicator to set. * @see #isStressTest() @@ -479,7 +488,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Return the benchmark indicator. If this value is true then * PMD will log benchmark information. - * + * * @return true if benchmark logging is enbaled, * false otherwise. */ @@ -489,7 +498,7 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Set the benchmark indicator. - * + * * @param benchmark * The benchmark indicator to set. * @see #isBenchmark() @@ -537,4 +546,4 @@ public class PMDConfiguration extends AbstractConfiguration { public void setRuleSetFactoryCompatibilityEnabled(boolean ruleSetFactoryCompatibilityEnabled) { this.ruleSetFactoryCompatibilityEnabled = ruleSetFactoryCompatibilityEnabled; } -} \ No newline at end of file +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java index 104c0295db..7e44b9cd15 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java @@ -29,6 +29,9 @@ public class PMDParameters { @Parameter(names = { "-dir", "-d" }, description = "Root directory for sources.", required = false) private String sourceDir; + @Parameter(names = { "-filelist" }, description = "Path to a file containing a list of files to analyze.", required = false) + private String fileListPath; + @Parameter(names = { "-format", "-f" }, description = "Report format type.") private String format = "text"; // Enhance to support other usage @@ -121,12 +124,13 @@ public class PMDParameters { } public static PMDConfiguration transformParametersIntoConfiguration(PMDParameters params) { - if (null == params.getSourceDir() && null == params.getUri()) { + if (null == params.getSourceDir() && null == params.getUri() && null == params.getFileListPath()) { throw new IllegalArgumentException( - "Please provide either source root directory (-dir or -d) or database URI (-uri or -u) parameter"); + "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()); @@ -231,6 +235,10 @@ public class PMDParameters { return sourceDir; } + public String getFileListPath() { + return fileListPath; + }; + public String getFormat() { return format; }