本文整理匯總了Java中org.apache.tools.ant.DirectoryScanner類的典型用法代碼示例。如果您正苦於以下問題:Java DirectoryScanner類的具體用法?Java DirectoryScanner怎麽用?Java DirectoryScanner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DirectoryScanner類屬於org.apache.tools.ant包,在下文中一共展示了DirectoryScanner類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createExcludeSpec
import org.apache.tools.ant.DirectoryScanner; //導入依賴的package包/類
public Spec<FileTreeElement> createExcludeSpec(PatternSet patternSet) {
List<Spec<FileTreeElement>> allExcludeSpecs = new ArrayList<Spec<FileTreeElement>>(2 + patternSet.getExcludeSpecs().size());
if (!patternSet.getExcludes().isEmpty()) {
allExcludeSpecs.add(createSpec(patternSet.getExcludes(), false, patternSet.isCaseSensitive()));
}
List<String> defaultExcludes = Arrays.asList(DirectoryScanner.getDefaultExcludes());
if (!defaultExcludes.isEmpty()) {
allExcludeSpecs.add(createSpec(defaultExcludes, false, patternSet.isCaseSensitive()));
}
allExcludeSpecs.addAll(patternSet.getExcludeSpecs());
if (allExcludeSpecs.isEmpty()) {
return Specs.satisfyNone();
} else {
return Specs.union(allExcludeSpecs);
}
}
示例2: execute
import org.apache.tools.ant.DirectoryScanner; //導入依賴的package包/類
@Override
public void execute() throws BuildException {
BasicStyleCheckerEngine engine = new BasicStyleCheckerEngine();
try {
for (FileSet fileset: filesets) {
final DirectoryScanner scanner =
fileset.getDirectoryScanner(getProject());
for (String filename: scanner.getIncludedFiles()) {
final File file =
new File(fileset.getDir(getProject()), filename);
System.out.println(file.getCanonicalPath());
engine.check(file);
}
}
} catch (IOException e) {
throw new BuildException(e);
}
}
示例3: processIndirectFiles
import org.apache.tools.ant.DirectoryScanner; //導入依賴的package包/類
private void processIndirectFiles(Writer fileWriter, String dashcnb) throws IOException, BuildException {
if (indirectFiles == null) {
return;
}
DirectoryScanner scan = indirectFiles.getDirectoryScanner(getProject());
Map<String,File> entries = new LinkedHashMap<>();
for (String f : scan.getIncludedFiles()) {
entries.put(f.replace(File.separatorChar, '/'), new File(scan.getBasedir(), f));
}
if (entries.isEmpty()) {
return;
}
File ext = new File(new File(targetFile, dashcnb), "extra-files.jar");
Zip jartask = (Zip) getProject().createTask("jar");
jartask.setDestFile(ext);
for (Map.Entry<String,File> entry : entries.entrySet()) {
ZipFileSet zfs = new ZipFileSet();
zfs.setFile(entry.getValue());
zfs.setFullpath("META-INF/files/" + entry.getKey());
jartask.addZipfileset(zfs);
}
jartask.execute();
fileWriter.write(constructJarHref(ext, dashcnb));
signOrCopy(ext, null);
}
示例4: execute
import org.apache.tools.ant.DirectoryScanner; //導入依賴的package包/類
@Override
public void execute() throws BuildException {
log( "Starting Hibernate EnhancementTask execution", Project.MSG_INFO );
// we use the CtClass stuff here just as a simple vehicle for obtaining low level information about
// the class(es) contained in a file while still maintaining easy access to the underlying byte[]
final Project project = getProject();
for ( FileSet fileSet : filesets ) {
final File fileSetBaseDir = fileSet.getDir( project );
final DirectoryScanner directoryScanner = fileSet.getDirectoryScanner( project );
for ( String relativeIncludedFileName : directoryScanner.getIncludedFiles() ) {
final File javaClassFile = new File( fileSetBaseDir, relativeIncludedFileName );
if ( ! javaClassFile.exists() ) {
continue;
}
processClassFile( javaClassFile);
}
}
}
示例5: scanForFiles
import org.apache.tools.ant.DirectoryScanner; //導入依賴的package包/類
private static void scanForFiles(Collection<File> destination, String pathAndMask) {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setCaseSensitive(false);
String pathPart = FilenameUtils.getFullPath(pathAndMask);
if(StringUtils.isEmpty(pathPart))
{
scanner.setBasedir(Paths.get(".").toAbsolutePath().normalize().toFile());
scanner.setIncludes(new String[]{pathAndMask});
}
else
{
scanner.setBasedir(new File(pathPart));
scanner.setIncludes(new String[]{FilenameUtils.getName(pathAndMask)});
}
scanner.scan();
for (String file : scanner.getIncludedFiles()) {
destination.add(new File(scanner.getBasedir(),file));
}
}
示例6: execute
import org.apache.tools.ant.DirectoryScanner; //導入依賴的package包/類
/**
* Invoke the Hadoop record compiler on each record definition file
*/
@Override
public void execute() throws BuildException {
if (src == null && filesets.size()==0) {
throw new BuildException("There must be a file attribute or a fileset child element");
}
if (src != null) {
doCompile(src);
}
Project myProject = getProject();
for (int i = 0; i < filesets.size(); i++) {
FileSet fs = filesets.get(i);
DirectoryScanner ds = fs.getDirectoryScanner(myProject);
File dir = fs.getDir(myProject);
String[] srcs = ds.getIncludedFiles();
for (int j = 0; j < srcs.length; j++) {
doCompile(new File(dir, srcs[j]));
}
}
}
示例7: collect
import org.apache.tools.ant.DirectoryScanner; //導入依賴的package包/類
/**
* Collects all files from the supplied FileSet.
*
* @param receiver The Collection to receive the files (and implied directories). Not <code>null</code>.
* @param unmanaged The Collection to receive unmanaged directories. Not <code>null</code>.
* @param fileset The FileSet which has to be traversed. Not <code>null</code>.
*/
private void collect( List<File> receiver, List<File> unmanaged, FileSet fileset ) {
DirectoryScanner scanner = fileset.getDirectoryScanner( getProject() );
File dir = fileset.getDir( getProject() );
if( incfiledirs ) {
// we're including directories which are implied by the FileSet
String[] dirs = scanner.getIncludedDirectories();
for( String includeddir : dirs ) {
File directory = new File( dir, includeddir );
collectUnmanaged( unmanaged, dir, directory, false );
receiver.add( directory );
}
}
String[] files = scanner.getIncludedFiles();
for( String includedfile : files ) {
File file = new File( dir, includedfile );
collectUnmanaged( unmanaged, dir, file.getParentFile(), false );
receiver.add( file );
}
}
示例8: getDirectoryScanner
import org.apache.tools.ant.DirectoryScanner; //導入依賴的package包/類
/**
* Returns the directory scanner needed to access the files to process.
* @return a <code>DirectoryScanner</code> instance.
*/
public DirectoryScanner getDirectoryScanner( Project p ) {
if( isReference() ) {
return getRef( p ).getDirectoryScanner( p );
}
File dir = getDir( p );
boolean followSymlinks = false;
if( dir == null ) {
throw new BuildException( "No directory specified for " + getDataTypeName() + "." );
}
if( !dir.exists() ) {
throw new BuildException( dir.getAbsolutePath() + " not found." );
}
if( !dir.isDirectory() ) {
throw new BuildException( dir.getAbsolutePath() + " is not a directory." );
}
DirectoryScanner ds = new SvnDirScanner( SvnFacade.getClientAdapter( this ) );
setupDirectoryScanner( ds, p );
ds.setFollowSymlinks( followSymlinks );
ds.scan();
return ds;
}
示例9: getInputFiles
import org.apache.tools.ant.DirectoryScanner; //導入依賴的package包/類
/**
* Returns the list of input files ({@link java.io.File} objects) to process.
* Note that this does not check that the file is a valid and useful XML file.
*
* @return The input files
*/
private List getInputFiles()
{
ArrayList result = new ArrayList();
for (Iterator it = _fileSets.iterator(); it.hasNext();)
{
FileSet fileSet = (FileSet)it.next();
File fileSetDir = fileSet.getDir(getProject());
DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject());
String[] files = scanner.getIncludedFiles();
for (int idx = 0; (files != null) && (idx < files.length); idx++)
{
File file = new File(fileSetDir, files[idx]);
if (file.isFile() && file.canRead())
{
result.add(file);
}
}
}
return result;
}
示例10: isIncluded
import org.apache.tools.ant.DirectoryScanner; //導入依賴的package包/類
/**
* Checks if passed file is scanned by any of the directory scanners.
*
* @param pathToFile a fully qualified path to tested file.
* @return true if so, false otherwise.
*/
public boolean isIncluded(String pathToFile)
{
Iterator scanners = directoryScanners.iterator();
while (scanners.hasNext())
{
DirectoryScanner scanner = (DirectoryScanner) scanners.next();
scanner.scan();
String[] includedFiles = scanner.getIncludedFiles();
for (int i = 0; i < includedFiles.length; i++)
{
File includedFile = new File(scanner.getBasedir(), includedFiles[i]);
if (pathToFile.equalsIgnoreCase(includedFile.getAbsolutePath()))
{
return true;
}
}
}
return false;
}
示例11: listFiles
import org.apache.tools.ant.DirectoryScanner; //導入依賴的package包/類
@Override
public List<File> listFiles(final String mask) {
try {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setIncludes(new String[]{mask});
scanner.setBasedir(this.basedir.replace("\\", "/"));
scanner.setCaseSensitive(false);
scanner.scan();
String[] files = scanner.getIncludedFiles();
List<File> result = new ArrayList<>();
for (String file : files) {
result.add(
new SimpleFile(file,
FileUtils.readFileToByteArray(new java.io.File(basedir + "/" + file))));
}
return result;
} catch (IOException exception) {
throw new BootException(exception);
}
}
示例12: processFileSet
import org.apache.tools.ant.DirectoryScanner; //導入依賴的package包/類
private void processFileSet(final FileSet fileSet) throws IOException {
final DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject());
final String[] files = scanner.getIncludedFiles();
String base = fileSet.getDir(getProject()).getCanonicalPath() + "\\";
for (String file : files) {
String lastDir = "";
getDirFileList(lastDir);
int idx = -1;
do {
idx = file.indexOf('\\', idx + 1);
if (idx == -1) break;
lastDir = file.substring(0, idx);
getDirFileList(lastDir);
}
while (true);
List<String> fileList = getDirFileList(lastDir);
final String absolute = base + file;
fileList.add(absolute);
myAbsoluteToRelative.put(absolute, file);
}
}
示例13: expandFileNames
import org.apache.tools.ant.DirectoryScanner; //導入依賴的package包/類
private static String[] expandFileNames(String fileName) throws IOException
{
// TODO: need to work with other users
if (fileName.matches("^[a-zA-Z]+:.*")) {
// it's a URL
return new String[]{fileName};
}
if (fileName.startsWith("~" + File.separator)) {
fileName = System.getProperty("user.home") + fileName.substring(1);
}
fileName = new File(fileName).getCanonicalPath();
LOG.debug("Canonical path: {}", fileName);
DirectoryScanner scanner = new DirectoryScanner();
scanner.setIncludes(new String[]{fileName});
scanner.scan();
return scanner.getIncludedFiles();
}
示例14: getClassFileInClasspath
import org.apache.tools.ant.DirectoryScanner; //導入依賴的package包/類
public static String[] getClassFileInClasspath()
{
String classpath = System.getProperty("java.class.path");
String[] paths = classpath.split(":");
List<String> fnames = new LinkedList<>();
for (String cp : paths) {
File f = new File(cp);
if (!f.isDirectory()) {
continue;
}
DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(f);
ds.setIncludes(new String[]{"**\\*.class"});
ds.scan();
for (String name : ds.getIncludedFiles()) {
fnames.add(new File(f, name).getAbsolutePath());
}
}
return fnames.toArray(new String[]{});
}
示例15: execute
import org.apache.tools.ant.DirectoryScanner; //導入依賴的package包/類
/**
* Invoke the Hadoop record compiler on each record definition file
*/
public void execute() throws BuildException {
if (src == null && filesets.size()==0) {
throw new BuildException("There must be a file attribute or a fileset child element");
}
if (src != null) {
doCompile(src);
}
Project myProject = getProject();
for (int i = 0; i < filesets.size(); i++) {
FileSet fs = filesets.get(i);
DirectoryScanner ds = fs.getDirectoryScanner(myProject);
File dir = fs.getDir(myProject);
String[] srcs = ds.getIncludedFiles();
for (int j = 0; j < srcs.length; j++) {
doCompile(new File(dir, srcs[j]));
}
}
}