Java Code Examples for org.apache.tools.ant.DirectoryScanner#setIncludes()
The following examples show how to use
org.apache.tools.ant.DirectoryScanner#setIncludes() .
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: 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 2
Source File: ApexCli.java From Bats 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 3
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 4
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 5
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 6
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 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: 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 9
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 10
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 11
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 12
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 13
Source File: Files.java From development with Apache License 2.0 | 5 votes |
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; }
Example 14
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 15
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 16
Source File: CompleterHelper.java From yiistorm with MIT License | 5 votes |
public static String[] searchFolders(String searchPath, String searchString) { DirectoryScanner scanner = new DirectoryScanner(); scanner.setIncludes(new String[]{searchString + "*"}); scanner.setExcludes(new String[]{searchString + "*.php"}); scanner.setBasedir(searchPath); scanner.setCaseSensitive(false); scanner.scan(); return scanner.getIncludedDirectories(); }
Example 17
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 18
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 19
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 20
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(); } }