hudson.plugins.analysis.util.FileFinder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of analysis-core Show documentation
Show all versions of analysis-core Show documentation
This plug-in provides utilities for the static code analysis plug-ins.
The newest version!
package hudson.plugins.analysis.util;
import java.io.File;
import java.io.IOException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileSet;
import hudson.FilePath.FileCallable;
import hudson.remoting.VirtualChannel;
/**
* Scans the workspace and finds all Java files.
*
* @author Ulli Hafner
*/
public class FileFinder implements FileCallable {
/** Generated ID. */
private static final long serialVersionUID = 2970029366847565970L;
/** File name pattern for java files. */
private static final String JAVA_PATTERN = "**/*.java";
/** The pattern to scan for. */
private final String pattern;
/**
* Creates a new instance of FileFinder
. This instance will scan
* for Java files, see {@link #JAVA_PATTERN}.
*/
public FileFinder() {
this(JAVA_PATTERN);
}
/**
* Creates a new instance of {@link FileFinder}.
*
* @param pattern the ant file pattern to scan for
*/
public FileFinder(final String pattern) {
this.pattern = pattern;
}
/**
* Returns an array with the filenames of the specified file pattern that
* have been found in the workspace.
*
* @param workspace
* root directory of the workspace
* @param channel
* not used
* @return the filenames of all found files
* @throws IOException
* if the workspace could not be read
*/
public String[] invoke(final File workspace, final VirtualChannel channel) throws IOException {
return find(workspace);
}
/**
* Returns an array with the filenames of the specified file pattern that have been
* found in the workspace.
*
* @param workspace
* root directory of the workspace
* @return the filenames of all found files
*/
public String[] find(final File workspace) {
try {
FileSet fileSet = new FileSet();
Project antProject = new Project();
fileSet.setProject(antProject);
fileSet.setDir(workspace);
fileSet.setIncludes(pattern);
return fileSet.getDirectoryScanner(antProject).getIncludedFiles();
}
catch (BuildException exception) {
return new String[0];
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy