Changed signature of Checker.process(String[]) to process(File[])
This is a step towards making TreeWalker a FileSetCheck, next some methods need to be moved around.
This commit is contained in:
parent
cb2862b73a
commit
822384a711
|
|
@ -334,7 +334,7 @@ public class CheckStyleTask
|
|||
}
|
||||
|
||||
// Process the files
|
||||
final String[] files = scanFileSets();
|
||||
final File[] files = scanFileSets();
|
||||
final int numErrs = c.process(files);
|
||||
|
||||
// Handle the return status
|
||||
|
|
@ -424,14 +424,14 @@ public class CheckStyleTask
|
|||
* returns the list of files (full path name) to process.
|
||||
* @return the list of files included via the filesets.
|
||||
*/
|
||||
protected String[] scanFileSets()
|
||||
protected File[] scanFileSets()
|
||||
{
|
||||
final ArrayList list = new ArrayList();
|
||||
if (mFileName != null) {
|
||||
// oops we've got an additional one to process, don't
|
||||
// forget it. No sweat, it's fully resolved via the setter.
|
||||
log("Adding standalone file for audit", Project.MSG_VERBOSE);
|
||||
list.add(mFileName);
|
||||
list.add(new File(mFileName));
|
||||
}
|
||||
for (int i = 0; i < mFileSets.size(); i++) {
|
||||
final FileSet fs = (FileSet) mFileSets.get(i);
|
||||
|
|
@ -446,11 +446,11 @@ public class CheckStyleTask
|
|||
for (int j = 0; j < names.length; j++) {
|
||||
final String pathname =
|
||||
ds.getBasedir() + File.separator + names[j];
|
||||
list.add(pathname);
|
||||
list.add(new File(pathname));
|
||||
}
|
||||
}
|
||||
|
||||
return (String[]) list.toArray(new String[0]);
|
||||
return (File[]) list.toArray(new File[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ public class Checker
|
|||
* @return the total number of errors found
|
||||
* @see #destroy()
|
||||
*/
|
||||
public int process(String[] aFiles)
|
||||
public int process(File[] aFiles)
|
||||
{
|
||||
int total = 0;
|
||||
fireAuditStarted();
|
||||
|
|
@ -179,34 +179,34 @@ public class Checker
|
|||
/**
|
||||
* Processes a specified file and prints out all errors found.
|
||||
* @return the number of errors found
|
||||
* @param aFileName the name of the file to process
|
||||
* @param aFile the file to process
|
||||
**/
|
||||
private int process(String aFileName)
|
||||
private int process(File aFile)
|
||||
{
|
||||
// check if already checked and passed the file
|
||||
final File f = new File(aFileName);
|
||||
final long timestamp = f.lastModified();
|
||||
if (mCache.alreadyChecked(aFileName, timestamp)) {
|
||||
final String fileName = aFile.getPath();
|
||||
final long timestamp = aFile.lastModified();
|
||||
if (mCache.alreadyChecked(fileName, timestamp)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Create a stripped down version
|
||||
final String stripped;
|
||||
final String basedir = mConfig.getBasedir();
|
||||
if ((basedir == null) || !aFileName.startsWith(basedir)) {
|
||||
stripped = aFileName;
|
||||
if ((basedir == null) || !fileName.startsWith(basedir)) {
|
||||
stripped = fileName;
|
||||
}
|
||||
else {
|
||||
// making the assumption that there is text after basedir
|
||||
final int skipSep = basedir.endsWith(File.separator) ? 0 : 1;
|
||||
stripped = aFileName.substring(basedir.length() + skipSep);
|
||||
stripped = fileName.substring(basedir.length() + skipSep);
|
||||
}
|
||||
|
||||
mMessages.reset();
|
||||
try {
|
||||
fireFileStarted(stripped);
|
||||
final String[] lines = Utils.getLines(aFileName);
|
||||
final FileContents contents = new FileContents(aFileName, lines);
|
||||
final String[] lines = Utils.getLines(fileName);
|
||||
final FileContents contents = new FileContents(fileName, lines);
|
||||
final DetailAST rootAST = parse(contents);
|
||||
mWalker.walk(rootAST, contents, mConfig.getClassLoader());
|
||||
}
|
||||
|
|
@ -232,7 +232,7 @@ public class Checker
|
|||
}
|
||||
|
||||
if (mMessages.size() == 0) {
|
||||
mCache.checkedOk(aFileName, timestamp);
|
||||
mCache.checkedOk(fileName, timestamp);
|
||||
}
|
||||
else {
|
||||
fireErrors(stripped, mMessages.getMessages());
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ import java.io.FileNotFoundException;
|
|||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
|
|
@ -146,7 +146,7 @@ public final class Main
|
|||
}
|
||||
|
||||
// Get all the Java files
|
||||
final List files = new ArrayList();
|
||||
final List files = new LinkedList();
|
||||
if (line.hasOption("r")) {
|
||||
final String[] values = line.getOptionValues("r");
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
|
|
@ -156,7 +156,7 @@ public final class Main
|
|||
|
||||
final String[] remainingArgs = line.getArgs();
|
||||
for (int i = 0; i < remainingArgs.length; i++) {
|
||||
files.add(remainingArgs[i]);
|
||||
files.add(new File(remainingArgs[i]));
|
||||
}
|
||||
|
||||
if (files.isEmpty()) {
|
||||
|
|
@ -191,8 +191,9 @@ public final class Main
|
|||
System.exit(1);
|
||||
}
|
||||
|
||||
final int numErrs =
|
||||
c.process((String[]) files.toArray(new String[files.size()]));
|
||||
final File[] processedFiles = new File[files.size()];
|
||||
files.toArray(processedFiles);
|
||||
final int numErrs = c.process(processedFiles);
|
||||
c.destroy();
|
||||
System.exit(numErrs);
|
||||
}
|
||||
|
|
@ -227,7 +228,7 @@ public final class Main
|
|||
}
|
||||
}
|
||||
else if (aNode.isFile() && aNode.getPath().endsWith(".java")) {
|
||||
aFiles.add(aNode.getPath());
|
||||
aFiles.add(aNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public abstract class BaseCheckTestCase
|
|||
throws Exception
|
||||
{
|
||||
mStream.flush();
|
||||
final int errs = aC.process(new String[] {aFilename});
|
||||
final int errs = aC.process(new File[] {new File(aFilename)});
|
||||
|
||||
// process each of the lines
|
||||
final ByteArrayInputStream bais =
|
||||
|
|
|
|||
Loading…
Reference in New Issue