Java Code Examples for org.apache.tools.ant.DirectoryScanner#scan()
The following examples show how to use
org.apache.tools.ant.DirectoryScanner#scan() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AntFile.java From antiplag with Apache License 2.0 | 6 votes |
public static String[] scanFiles(File f,String[] filter){ String[] includeFiles = null; try { DirectoryScanner ds=new DirectoryScanner(); ds.setBasedir(f); ds.setIncludes(filter); //**/*.java ds.scan(); if(ds.getIncludedFilesCount()>0) { includeFiles=ds.getIncludedFiles(); } } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } return includeFiles; }
Example 2
Source File: WildcardScanner.java From gocd with Apache License 2.0 | 6 votes |
public File[] getFiles() { DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(rootPath); scanner.setIncludes(new String[]{pattern}); scanner.scan(); String[] allPaths = scanner.getIncludedFiles(); List<File> allFiles = new ArrayList<>(); String[] directories = scanner.getIncludedDirectories(); for (String directory : directories) { allFiles.add(new File(rootPath, directory)); } for (int i = 0; i < allPaths.length; i++) { File file = new File(rootPath, allPaths[i]); if (!allFiles.contains(file.getParentFile())) { allFiles.add(file); } } return allFiles.toArray(new File[]{}); }
Example 3
Source File: OperatorDiscoveryTest.java From attic-apex-core with Apache License 2.0 | 6 votes |
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[]{}); }
Example 4
Source File: ApexCli.java From attic-apex-core with Apache License 2.0 | 6 votes |
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(); }
Example 5
Source File: Helper.java From bootstraped-multi-test-results-report with MIT License | 5 votes |
public static String[] findFiles(File targetDirectory, String fileIncludePattern, String fileExcludePattern, final String DEFAULT_FILE_INCLUDE_PATTERN) { DirectoryScanner scanner = new DirectoryScanner(); if (fileIncludePattern == null || fileIncludePattern.isEmpty()) { scanner.setIncludes(new String[] {DEFAULT_FILE_INCLUDE_PATTERN}); } else { scanner.setIncludes(new String[] {fileIncludePattern}); } if (fileExcludePattern != null) { scanner.setExcludes(new String[] {fileExcludePattern}); } scanner.setBasedir(targetDirectory); scanner.scan(); return scanner.getIncludedFiles(); }
Example 6
Source File: CompleterHelper.java From yiistorm with MIT License | 5 votes |
public static String[] searchFiles(String searchPath, String searchString) { DirectoryScanner scanner = new DirectoryScanner(); scanner.setIncludes(new String[]{searchString + "*.php"}); scanner.setBasedir(searchPath); scanner.setCaseSensitive(false); scanner.scan(); return scanner.getIncludedFiles(); }
Example 7
Source File: PublishExecutor.java From gocd-s3-artifacts with Apache License 2.0 | 5 votes |
protected String[] parseSourcePath(String source, String workingDir) { DirectoryScanner directoryScanner = new DirectoryScanner(); directoryScanner.setBasedir(workingDir); directoryScanner.setIncludes(new String[]{source}); directoryScanner.scan(); return ArrayUtils.addAll(directoryScanner.getIncludedFiles(), directoryScanner.getIncludedDirectories()); }
Example 8
Source File: AbstractCajaAntTask.java From caja with Apache License 2.0 | 5 votes |
public void addConfiguredFileSet(FileSet fs) { DirectoryScanner scanner = fs.getDirectoryScanner(getProject()); File baseDir = scanner.getBasedir(); scanner.scan(); String[] includedFiles = scanner.getIncludedFiles(); Arrays.sort(includedFiles); for (String localPath : includedFiles) { files.add(new File(baseDir, localPath)); } }
Example 9
Source File: ApexCli.java From attic-apex-core with Apache License 2.0 | 5 votes |
private static String expandFileName(String fileName, boolean expandWildCard) throws IOException { if (fileName.matches("^[a-zA-Z]+:.*")) { // it's a URL return fileName; } // TODO: need to work with other users' home directory if (fileName.startsWith("~" + File.separator)) { fileName = System.getProperty("user.home") + fileName.substring(1); } fileName = new File(fileName).getCanonicalPath(); //LOG.debug("Canonical path: {}", fileName); if (expandWildCard) { DirectoryScanner scanner = new DirectoryScanner(); scanner.setIncludes(new String[]{fileName}); scanner.scan(); String[] files = scanner.getIncludedFiles(); if (files.length == 0) { throw new CliException(fileName + " does not match any file"); } else if (files.length > 1) { throw new CliException(fileName + " matches more than one file"); } return files[0]; } else { return fileName; } }
Example 10
Source File: StramAppLauncher.java From attic-apex-core with Apache License 2.0 | 5 votes |
private void processLibJars(String libjars, Set<URL> clUrls) throws Exception { for (String libjar : libjars.split(",")) { // if hadoop file system, copy from hadoop file system to local URI uri = new URI(libjar); String scheme = uri.getScheme(); if (scheme == null) { // expand wildcards DirectoryScanner scanner = new DirectoryScanner(); scanner.setIncludes(new String[]{libjar}); scanner.scan(); String[] files = scanner.getIncludedFiles(); for (String file : files) { clUrls.add(new URL("file:" + file)); } } else if (scheme.equals("file")) { clUrls.add(new URL(libjar)); } else { if (fs != null) { Path path = new Path(libjar); File dependencyJarsDir = new File(StramClientUtils.getUserDTDirectory(), "dependencyJars"); dependencyJarsDir.mkdirs(); File localJarFile = new File(dependencyJarsDir, path.getName()); fs.copyToLocalFile(path, new Path(localJarFile.getAbsolutePath())); clUrls.add(new URL("file:" + localJarFile.getAbsolutePath())); } else { throw new NotImplementedException("Jar file needs to be from Hadoop File System also in order for the dependency jars to be in Hadoop File System"); } } } }
Example 11
Source File: StramAppLauncher.java From Bats with Apache License 2.0 | 5 votes |
private void processLibJars(String libjars, Set<URL> clUrls) throws Exception { for (String libjar : libjars.split(",")) { // if hadoop file system, copy from hadoop file system to local URI uri = new URI(libjar); String scheme = uri.getScheme(); if (scheme == null) { // expand wildcards DirectoryScanner scanner = new DirectoryScanner(); scanner.setIncludes(new String[]{libjar}); scanner.scan(); String[] files = scanner.getIncludedFiles(); for (String file : files) { clUrls.add(new URL("file:" + file)); } } else if (scheme.equals("file")) { clUrls.add(new URL(libjar)); } else { if (fs != null) { Path path = new Path(libjar); File dependencyJarsDir = new File(StramClientUtils.getUserDTDirectory(), "dependencyJars"); dependencyJarsDir.mkdirs(); File localJarFile = new File(dependencyJarsDir, path.getName()); fs.copyToLocalFile(path, new Path(localJarFile.getAbsolutePath())); clUrls.add(new URL("file:" + localJarFile.getAbsolutePath())); } else { throw new NotImplementedException("Jar file needs to be from Hadoop File System also in order for the dependency jars to be in Hadoop File System"); } } } }
Example 12
Source File: FileSelector.java From maven-replacer-plugin with MIT License | 5 votes |
public List<String> listIncludes(String basedir, List<String> includes, List<String> excludes) { if (includes == null || includes.isEmpty()) { return Collections.emptyList(); } DirectoryScanner directoryScanner = new DirectoryScanner(); directoryScanner.addDefaultExcludes(); directoryScanner.setBasedir(new File(basedir)); directoryScanner.setIncludes(stringListToArray(includes)); directoryScanner.setExcludes(stringListToArray(excludes)); directoryScanner.scan(); return Arrays.asList(directoryScanner.getIncludedFiles()); }
Example 13
Source File: AntDirectoryScanner.java From gocd-yaml-config-plugin with Apache License 2.0 | 5 votes |
@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(); }
Example 14
Source File: CodeGenerator.java From avro-util with BSD 2-Clause "Simplified" License | 5 votes |
private void findAllIncludedFiles(Map<File, File> fileToParent, Set<File> sharedSchemas, Set<File> nonSharedSchemas) { String[] includesArray = includes.toArray(new String[0]); for (File input : inputs) { if (!input.exists()) { LOG.warn("path {} does not exist", input); } if (input.isFile()) { //individual files are always considered included, so no test against includes includeFile(input, input, fileToParent, sharedSchemas, nonSharedSchemas); } else if (input.isDirectory()) { DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(input); scanner.setIncludes(includesArray); scanner.scan(); //results are paths relative (==under) input String[] includedFiles = scanner.getIncludedFiles(); for (String included : includedFiles) { File file = new File(input, included); includeFile(file, input, fileToParent, sharedSchemas, nonSharedSchemas); } } else { LOG.warn("path {} is neither a file nor a directory", input); } } }
Example 15
Source File: PatternSet.java From onedev with MIT License | 5 votes |
public Collection<File> listFiles(File dir) { Collection<File> files = new ArrayList<File>(); DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(dir); scanner.setIncludes(includes.toArray(new String[0])); scanner.setExcludes(excludes.toArray(new String[0])); scanner.scan(); for (String path: scanner.getIncludedFiles()) files.add(new File(dir, path)); return files; }
Example 16
Source File: FileUtil.java From ambari-logsearch with Apache License 2.0 | 5 votes |
public static File[] getInputFilesByPattern(String searchPath) { File searchFile = new File(searchPath); if (searchFile.isFile()) { return new File[]{searchFile}; } else { if (searchPath.contains("*")) { try { String folderBeforeRegex = getLogDirNameBeforeWildCard(searchPath); String fileNameAfterLastFolder = searchPath.substring(folderBeforeRegex.length()); DirectoryScanner scanner = new DirectoryScanner(); scanner.setIncludes(new String[]{fileNameAfterLastFolder}); scanner.setBasedir(folderBeforeRegex); scanner.setCaseSensitive(true); scanner.scan(); String[] fileNames = scanner.getIncludedFiles(); if (fileNames != null && fileNames.length > 0) { File[] files = new File[fileNames.length]; for (int i = 0; i < fileNames.length; i++) { files[i] = new File(folderBeforeRegex + fileNames[i]); } return files; } } catch (Exception e) { fileMonitorLogger.info("Input file was not found by pattern (exception thrown); {}, message: {}", searchPath, e.getMessage()); } } else { fileMonitorLogger.debug("Input file config was not found by pattern; {}", searchPath); } return new File[]{}; } }
Example 17
Source File: CCGBankTaskSources.java From openccg with GNU Lesser General Public License v2.1 | 5 votes |
/** * Gets the files in the specified group as an array of files. The files in * the returned array are in the order returned by <code>group</code>'s * {@link FileSet#getDirectoryScanner(Project) directory scanner}. */ @Override protected File[] getFiles(FileSet group) { Project proj = getProject(); DirectoryScanner scanner = group.getDirectoryScanner(proj); scanner.scan(); String[] fileNames = scanner.getIncludedFiles(); if(fileNames.length == 0) { throw new BuildException("no source files included"); } return makeFiles(group.getDir(proj), fileNames); }
Example 18
Source File: ApexCli.java From Bats with Apache License 2.0 | 5 votes |
private static String expandFileName(String fileName, boolean expandWildCard) throws IOException { if (fileName.matches("^[a-zA-Z]+:.*")) { // it's a URL return fileName; } // TODO: need to work with other users' home directory if (fileName.startsWith("~" + File.separator)) { fileName = System.getProperty("user.home") + fileName.substring(1); } fileName = new File(fileName).getCanonicalPath(); //LOG.debug("Canonical path: {}", fileName); if (expandWildCard) { DirectoryScanner scanner = new DirectoryScanner(); scanner.setIncludes(new String[]{fileName}); scanner.scan(); String[] files = scanner.getIncludedFiles(); if (files.length == 0) { throw new CliException(fileName + " does not match any file"); } else if (files.length > 1) { throw new CliException(fileName + " matches more than one file"); } return files[0]; } else { return fileName; } }
Example 19
Source File: Branding.java From netbeans with Apache License 2.0 | 4 votes |
private void packBrandingJar(File srcDir, File destJarBase, String locale) throws IOException { DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(srcDir); String localeToken = ""; if(locale != null) { String [] includes = {"**/*_" + locale.toString() + ".*"}; scanner.setIncludes(includes); localeToken = "_" + locale.toString(); } else { String [] excludes = {"**/*_??_??.*", "**/*_??.*"}; scanner.setExcludes(excludes); } scanner.addDefaultExcludes(); // #68929 scanner.scan(); String[] files = scanner.getIncludedFiles(); if(files.length > 0) { Jar zip = (Jar) getProject().createTask("jar"); String name = destJarBase.getName(); String nameBase = name.substring(0, name.length() - ".jar".length()); File destFolder = new File(destJarBase.getParentFile(), "locale"); if (!destFolder.isDirectory() && !destFolder.mkdirs()) { throw new IOException("Could not create directory " + destFolder); } File destJar = new File(destFolder, nameBase + "_" + token + localeToken + ".jar"); zip.setDestFile(destJar); zip.setCompress(true); for (int i = 0; i < files.length; i++) { ZipFileSet entry = new ZipFileSet(); entry.setFile(new File(srcDir, files[i])); String basePath = files[i].replace(File.separatorChar, '/'); int slash = basePath.lastIndexOf('/'); int dot = basePath.lastIndexOf('.'); String infix = "_" + token + localeToken; String brandedPath; if (dot == -1 || dot < slash) { brandedPath = basePath + infix; } else { brandedPath = basePath.substring(0, dot - localeToken.length()) + infix + basePath.substring(dot); } entry.setFullpath(brandedPath); zip.addZipfileset(entry); } zip.setLocation(getLocation()); zip.init(); zip.execute(); } }
Example 20
Source File: CopyIcons.java From netbeans with Apache License 2.0 | 4 votes |
private void processProjectDir(File f) { String prjPath = null; //if (f.getAbsolutePath().equals(baseDir.getAbsolutePath())) { // prjPath = ""; //} else { prjPath = f.getAbsolutePath().substring(baseDir.getAbsolutePath().length() + 1); //} log("Processing project dir: " + prjPath); DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(f); ds.setIncludes(getAsArray(iconIncludes)); ds.setExcludes(getAsArray(iconExcludes)); ds.setCaseSensitive(false); ds.scan(); String[] files = ds.getIncludedFiles(); log(" Found " + files.length + " files in " + f); List<ImageInfo> goodIcons = new ArrayList<>(); List<ImageInfo> badIcons = new ArrayList<>(); for (String file : files) { String ext = file.substring(file.lastIndexOf('.') + 1); if (ext.equalsIgnoreCase("gif") || ext.equalsIgnoreCase("png")) { File iconFile = new File(f, file); try { ImageInfo imageInfo = null; imageInfo = readImageInfo(iconFile); if (imageInfo != null) { imageInfo.setPath(file); imageInfo.setExt(ext); int w = imageInfo.getWidth(); int h = imageInfo.getHeight(); if ((w == 8 && h == 8) || (w == 16 && h == 16) || (w == 24 && h == 24) || (w == 32 && h == 32)) { goodIcons.add(imageInfo); } else { badIcons.add(imageInfo); } } } catch (IOException ex) { ex.printStackTrace(); } } } ProjectIconInfo prjIconInfo = new ProjectIconInfo(prjPath, goodIcons, badIcons); prjIconInfoList.add(prjIconInfo); }