From c66b9a1f7bee04a33b7bfd07a8a57cd93ad4bf82 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Tue, 1 Jul 2003 15:25:20 +0000 Subject: [PATCH] Added ability to pass in comma-delimited list of files to PMD's command line git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2060 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/src/net/sourceforge/pmd/PMD.java | 42 +++++++++++++++++++++------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/pmd/src/net/sourceforge/pmd/PMD.java b/pmd/src/net/sourceforge/pmd/PMD.java index 7ddb56f0c5..b82175fbb9 100644 --- a/pmd/src/net/sourceforge/pmd/PMD.java +++ b/pmd/src/net/sourceforge/pmd/PMD.java @@ -22,6 +22,7 @@ import java.io.Reader; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.StringTokenizer; public class PMD { public static final String EOL = System.getProperty("line.separator", "\n"); @@ -68,18 +69,11 @@ public class PMD { String reportFormat = args[1]; String ruleSets = args[2]; - File inputFile = new File(inputFileName); - if (!inputFile.exists()) { - throw new RuntimeException("File " + inputFileName + " doesn't exist"); - } - List files; - if (!inputFile.isDirectory()) { - files = new ArrayList(); - files.add(inputFile); + if (inputFileName.indexOf(',') != -1) { + files = collectFromCommaDelimitedString(inputFileName); } else { - FileFinder finder = new FileFinder(); - files = finder.findFilesFrom(inputFile.getAbsolutePath(), new JavaLanguage.JavaFileOrDirectoryFilter(), true); + files = collectFilesFromOneName(inputFileName); } PMD pmd = new PMD(); @@ -131,6 +125,34 @@ public class PMD { System.out.println(renderer.render(ctx.getReport())); } + private static List collectFilesFromOneName(String inputFileName) { + return collect(inputFileName); + } + + private static List collectFromCommaDelimitedString(String fileList) { + List files = new ArrayList(); + for (StringTokenizer st = new StringTokenizer(fileList, ","); st.hasMoreTokens();) { + files.addAll(collect(st.nextToken())); + } + return files; + } + + private static List collect(String filename) { + File inputFile = new File(filename); + if (!inputFile.exists()) { + throw new RuntimeException("File " + inputFile.getName() + " doesn't exist"); + } + List files; + if (!inputFile.isDirectory()) { + files = new ArrayList(); + files.add(inputFile); + } else { + FileFinder finder = new FileFinder(); + files = finder.findFilesFrom(inputFile.getAbsolutePath(), new JavaLanguage.JavaFileOrDirectoryFilter(), true); + } + return files; + } + private static void usage() { final String EOL = System.getProperty("line.separator"); System.err.println(EOL +