本文整理匯總了Java中org.apache.tools.ant.DirectoryScanner.scan方法的典型用法代碼示例。如果您正苦於以下問題:Java DirectoryScanner.scan方法的具體用法?Java DirectoryScanner.scan怎麽用?Java DirectoryScanner.scan使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.tools.ant.DirectoryScanner
的用法示例。
在下文中一共展示了DirectoryScanner.scan方法的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: 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;
}
示例3: 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;
}
示例4: 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);
}
}
示例5: 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();
}
示例6: 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[]{});
}
示例7: 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));
}
}
示例8: 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);
}
}
示例9: 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);
}
}
示例10: testGetWithSelector
import org.apache.tools.ant.DirectoryScanner; //導入方法依賴的package包/類
@Test
public void testGetWithSelector() {
buildRule.executeTarget("ftp-get-with-selector");
assertContains("selectors are not supported in remote filesets", buildRule.getLog());
FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector");
DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject());
dsDestination.scan();
String[] sortedDestinationDirectories = dsDestination.getIncludedDirectories();
String[] sortedDestinationFiles = dsDestination.getIncludedFiles();
for (int counter = 0; counter < sortedDestinationDirectories.length; counter++) {
sortedDestinationDirectories[counter] =
sortedDestinationDirectories[counter].replace(File.separatorChar, '/');
}
for (int counter = 0; counter < sortedDestinationFiles.length; counter++) {
sortedDestinationFiles[counter] =
sortedDestinationFiles[counter].replace(File.separatorChar, '/');
}
FileSet fsSource = (FileSet) buildRule.getProject().getReference("fileset-source-without-selector");
DirectoryScanner dsSource = fsSource.getDirectoryScanner(buildRule.getProject());
dsSource.scan();
compareFiles(dsSource, sortedDestinationFiles, sortedDestinationDirectories);
}
示例11: 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();
}
示例12: scanFileSets
import org.apache.tools.ant.DirectoryScanner; //導入方法依賴的package包/類
/**
* returns the list of files (full path name) to process.
*
* @return the list of files included via the filesets.
*/
private List<File> scanFileSets() {
final List<File> list = new ArrayList<File>();
for (int i = 0; i < fileSets.size(); i++) {
FileSet fs = fileSets.get(i);
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
ds.scan();
String[] names = ds.getIncludedFiles();
for (String element : names) {
list.add(new File(ds.getBasedir(), element));
}
}
return list;
}
示例13: createPluginsManager
import org.apache.tools.ant.DirectoryScanner; //導入方法依賴的package包/類
/**
* Initialize a plugin manager, using the specified temporary working
* directory.
* @param tempPluginsDir
* @return
* @throws IOException
*/
public static PluginsManager createPluginsManager(Path tempPluginsDir, List<FileSet> filesets) throws IOException {
// FileSet handling
for (FileSet fs : filesets) {
DirectoryScanner ds = fs.getDirectoryScanner();
ds.scan();
File baseDir = ds.getBasedir();
for (String filename : ds.getIncludedFiles()) {
File f = new File(baseDir, filename);
TaskUtil.copyJarToDirectory(tempPluginsDir, f, false);
}
}
PluginsManager plManager = new PluginsManager();
System.out.println("Discovering from " + tempPluginsDir.toFile());
plManager.discover(tempPluginsDir.toFile(), false);
return plManager;
}
示例14: 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;
}
示例15: 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;
}