Java Code Examples for org.apache.tools.ant.DirectoryScanner#setExcludes()

The following examples show how to use org.apache.tools.ant.DirectoryScanner#setExcludes() . 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: PatternSet.java    From onedev with MIT License 5 votes vote down vote up
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 2
Source File: Helper.java    From bootstraped-multi-test-results-report with MIT License 5 votes vote down vote up
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 3
Source File: FileSelector.java    From maven-replacer-plugin with MIT License 5 votes vote down vote up
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 4
Source File: CompleterHelper.java    From yiistorm with MIT License 5 votes vote down vote up
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 5
Source File: CopyIcons.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 6
Source File: Branding.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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();
    }
}