本文整理匯總了Java中org.apache.tools.ant.DirectoryScanner.setBasedir方法的典型用法代碼示例。如果您正苦於以下問題:Java DirectoryScanner.setBasedir方法的具體用法?Java DirectoryScanner.setBasedir怎麽用?Java DirectoryScanner.setBasedir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.tools.ant.DirectoryScanner
的用法示例。
在下文中一共展示了DirectoryScanner.setBasedir方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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));
}
}
示例2: 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);
}
}
示例3: 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[]{});
}
示例4: removeFileContaining
import org.apache.tools.ant.DirectoryScanner; //導入方法依賴的package包/類
private void removeFileContaining(String content) {
DirectoryScanner ds = new DirectoryScanner();
String[] includes = {"**/*.process"};
ds.setIncludes(includes);
ds.setBasedir(testSrcDirectory);
//ds.setCaseSensitive(true);
ContainsSelector contentToRemove = new ContainsSelector();
contentToRemove.setText(content);
FileSelector[] selectors = {contentToRemove};
ds.setSelectors(selectors);
ds.scan();
String[] files = ds.getIncludedFiles();
for (int i = 0; i < files.length; i++) {
String file = testSrcDirectory + File.separator + files[i];
getLog().debug("Deleting file with starter : '" + file + "'");
getLog().info("Deleting file with starter : '" + file + "'");
FileUtils.deleteQuietly(new File(file));
}
}
示例5: downloadProjectSDK
import org.apache.tools.ant.DirectoryScanner; //導入方法依賴的package包/類
/**
* Downloads an SDK for needed language.
*
* @param lang SDK language
* @param response standard response
* @throws SandboxServiceException if couldn't download
*/
@RequestMapping(value = "demoProjects/download/sdk/{lang}", method = RequestMethod.GET)
public void downloadProjectSDK(@PathVariable String lang, HttpServletResponse response) throws SandboxServiceException {
String sdkPath = "/usr/lib/kaa-node/sdk/" + lang + "/";
DirectoryScanner scanner = new DirectoryScanner();
scanner.setIncludes(new String[]{"kaa-*"});
scanner.setBasedir(sdkPath);
scanner.setCaseSensitive(false);
try {
scanner.scan();
String[] files = scanner.getIncludedFiles();
if (files.length == 0) {
LOG.warn("No SDK found for language [{}]", lang);
return;
}
String sdkFullName = sdkPath + files[0];
LOG.info("Downloading SDK [{}]", sdkFullName);
response.setHeader("Content-disposition", "attachment; filename=" + files[0]);
IOUtils.copy(Files.newInputStream(Paths.get(sdkFullName)), response.getOutputStream());
response.flushBuffer();
} catch (IOException e) {
LOG.error("Couldn't download SDK for language [{}]", lang);
throw new SandboxServiceException(e);
}
}
示例6: removeTestClasses
import org.apache.tools.ant.DirectoryScanner; //導入方法依賴的package包/類
/**
* Remove as classes de teste do sistema, para que elas nao entrem na
* analise. Todos os diretorios cujo nome comeca com 'test' (test*) serão
* excluídos.
*/
public void removeTestClasses() {
System.out.println("Deleting test folders");
DirectoryScanner scanner = new DirectoryScanner();
String[] includes = { "**/test*" };
scanner.setIncludes(includes);
scanner.setBasedir(src_path);
scanner.setCaseSensitive(false);
scanner.scan();
String[] included_dirs = scanner.getIncludedDirectories();
for (String test_dir : included_dirs) {
File dirToDelete = new File(src_path, test_dir);
if (dirToDelete.exists())
FileUtils.deleteRecursive(dirToDelete);
}
}
示例7: verifyPathAdheresToDesign
import org.apache.tools.ant.DirectoryScanner; //導入方法依賴的package包/類
private void verifyPathAdheresToDesign(Design d, Path p) throws ClassFormatException, IOException {
String files[] = p.list();
for (int i = 0; i < files.length; i++) {
File file = new File(files[i]);
if (file.isDirectory()) {
FileSet set = new FileSet();
set.setDir(file);
set.setProject(task.getProject());
PatternSet.NameEntry entry1 = set.createInclude();
PatternSet.NameEntry entry2 = set.createInclude();
PatternSet.NameEntry entry3 = set.createInclude();
entry1.setName("**/*.class");
entry2.setName("**/*.jar");
entry3.setName("**/*.war");
DirectoryScanner scanner = set.getDirectoryScanner(task.getProject());
scanner.setBasedir(file);
String[] scannerFiles = scanner.getIncludedFiles();
for (int j = 0; j < scannerFiles.length; j++) {
verifyPartOfPath(scannerFiles[j], new File(file, scannerFiles[j]), d);
}
} else
verifyPartOfPath(files[i], file, d);
}
}
示例8: findJsonFiles
import org.apache.tools.ant.DirectoryScanner; //導入方法依賴的package包/類
private String[] findJsonFiles(File targetDirectory, String fileIncludePattern, String fileExcludePattern) {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(targetDirectory);
if (StringUtils.isEmpty(fileIncludePattern)) {
scanner.setIncludes(new String[]{DEFAULT_FILE_INCLUDE_PATTERN});
} else {
scanner.setIncludes(new String[]{fileIncludePattern});
}
if (StringUtils.isNotEmpty(fileExcludePattern)) {
scanner.setExcludes(new String[]{fileExcludePattern});
}
scanner.setBasedir(targetDirectory);
scanner.scan();
return scanner.getIncludedFiles();
}
示例9: getFiles
import org.apache.tools.ant.DirectoryScanner; //導入方法依賴的package包/類
public Collection<IFile> getFiles() {
final DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(basedir);
ds.setIncludes(new String[] { pattern });
ds.addDefaultExcludes();
ds.scan();
final String[] filenames = ds.getIncludedFiles();
final Collection<IFile> files = new ArrayList<IFile>(
filenames.length);
for (final String name : filenames) {
final String normName = name.replace(File.separatorChar, '/');
files.add(new PhysicalFile(normName, new File(basedir, name)));
}
return files;
}
示例10: listFiles
import org.apache.tools.ant.DirectoryScanner; //導入方法依賴的package包/類
/**
* List all files matching specified patterns under specified base directory.
*
* @param baseDir
* Base directory to scan files in
* @param pathPattern
* Pattern of file path to be used for search
* @return
* Collection of files matching specified path pattern. Directories will not be included even
* if its path matches the pattern
*/
public static Collection<File> listFiles(File baseDir, String pathPattern) {
Collection<File> files = new ArrayList<File>();
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(baseDir);
scanner.setIncludes(new String[]{pathPattern});
scanner.scan();
for (String path: scanner.getIncludedFiles())
files.add(new File(baseDir, path));
return files;
}
示例11: getFilesMatchingPattern
import org.apache.tools.ant.DirectoryScanner; //導入方法依賴的package包/類
@Override
public String[] getFilesMatchingPattern(File directory, String pattern) {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(directory);
scanner.setIncludes(pattern.trim().split(" *, *"));
scanner.scan();
return scanner.getIncludedFiles();
}
示例12: invoke
import org.apache.tools.ant.DirectoryScanner; //導入方法依賴的package包/類
@Override
public Boolean invoke(File f, VirtualChannel channel) {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setIncludes(DEFAULT_FILE_INCLUDES);
scanner.setBasedir(f);
scanner.scan();
return scanner.getIncludedFilesCount() != 0;
}
示例13: listFiles
import org.apache.tools.ant.DirectoryScanner; //導入方法依賴的package包/類
private String[] listFiles(String baseDir, String pattern) {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(baseDir);
scanner.setIncludes(new String[]{pattern});
scanner.scan();
return scanner.getIncludedFiles();
}
示例14: scanPath
import org.apache.tools.ant.DirectoryScanner; //導入方法依賴的package包/類
/**
* Scans the given path and retrieves all files for the given path.
*
* @param path A path to scan.
* @param pathIndex The index of the given path. Used in log messages only.
* @return A list of files, extracted from the given path.
*/
private List<File> scanPath(Path path, int pathIndex) {
final String[] resources = path.list();
log(pathIndex + ") Scanning path " + path, Project.MSG_VERBOSE);
final List<File> allFiles = new ArrayList<File>();
int concreteFilesCount = 0;
for (String resource : resources) {
final File file = new File(resource);
if (file.isFile()) {
concreteFilesCount++;
allFiles.add(file);
}
else {
final DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(file);
scanner.scan();
final List<File> scannedFiles = retrieveAllScannedFiles(scanner, pathIndex);
allFiles.addAll(scannedFiles);
}
}
if (concreteFilesCount > 0) {
log(String.format(Locale.ROOT, "%d) Adding %d files from path %s",
pathIndex, concreteFilesCount, path), Project.MSG_VERBOSE);
}
return allFiles;
}
示例15: getFiles
import org.apache.tools.ant.DirectoryScanner; //導入方法依賴的package包/類
@Override
public List<File> getFiles(String rootPath, String wildCardPattern) {
List<File> allFiles = new ArrayList<>();
File file = new File(rootPath);
if (file.isFile()) {
allFiles.add(file);
return allFiles;
}
if (!wildCardPattern.equals("")) {
rootPath = rootPath.replace(wildCardPattern, "");
}
DirectoryScanner scanner = new DirectoryScanner();
try {
scanner.setBasedir(rootPath);
scanner.setIncludes(new String[]{wildCardPattern});
scanner.scan();
} catch (IllegalStateException e) {
e.printStackTrace();
}
if (wildCardPattern.equals("**")) {
File directory = scanner.getBasedir();
allFiles.add(directory);
return allFiles;
}
String[] files = scanner.getIncludedFiles();
for (String f : files) {
allFiles.add(new File(rootPath, f));
}
return allFiles;
}