Java Code Examples for org.apache.tools.ant.types.selectors.SelectorUtils

The following examples show how to use org.apache.tools.ant.types.selectors.SelectorUtils. These examples are extracted from open source projects. 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 Project: netbeans   Source File: VerifyLibsAndLicenses.java    License: Apache License 2.0 6 votes vote down vote up
private void findStrayThirdPartyBinaries(File dir, String prefix, Set<String> violations, List<String> ignoredPatterns) throws IOException {
    for (String n : findHgControlledFiles(dir)) {
        File f = new File(dir, n);
        if (f.isDirectory()) {
            findStrayThirdPartyBinaries(f, prefix + n + "/", violations, ignoredPatterns);
        } else if (n.matches(".*\\.(jar|zip)")) {
            String path = prefix + n;
            boolean ignored = false;
            for (String pattern : ignoredPatterns) {
                if (SelectorUtils.matchPath(pattern, path)) {
                    ignored = true;
                    break;
                }
            }
            if (!ignored && dir.getName().equals("external") &&
                    new File(new File(dir.getParentFile(), "nbproject"), "project.xml").isFile()) {
                ignored = true;
            }
            if (!ignored) {
                violations.add(path);
            } else {
                //System.err.println("accepted: " + path);
            }
        }
    }
}
 
Example 2
Source Project: netbeans   Source File: DeleteUnreferencedClusterFiles.java    License: Apache License 2.0 6 votes vote down vote up
private void scanForExtraFiles(File d, String prefix, Set<String> files, String cluster, StringBuilder extraFiles) {
    if (prefix.equals("update_tracking/")) {
        return;
    }
    for (String n : d.list()) {
        File f = new File(d, n);
        if (f.getName().equals(".lastModified")) {
            continue;
        }
        if (f.isDirectory()) {
            scanForExtraFiles(f, prefix + n + "/", files, cluster, extraFiles);
        } else {
            String path = prefix + n;
            if ( patterns != null )
                for( String p: patterns.getExcludePatterns(getProject()) ) 
                    if (SelectorUtils.matchPath(p, path)) return;
                
            if (!files.contains(path)) {
                extraFiles.append("\n" + cluster + ": untracked file " + path);
                f.delete();
            }
        }
    }
}
 
Example 3
Source Project: yGuard   Source File: PatternMatchedFilter.java    License: MIT License 5 votes vote down vote up
protected boolean match( TypePatternSet.Type type, String str, PatternMatchedSection section ) {

    PatternSet patternSet = section.getPatternSet( type );

    if ( patternSet != null ) {

      String[] excludePatterns = patternSet.getExcludePatterns( project );
      if ( null != excludePatterns ) {
        for ( String excludePattern : excludePatterns ) {
          if ( SelectorUtils.match( excludePattern, str ) ) {
            return false;
          }
        }
      }

      String[] includePatterns = patternSet.getIncludePatterns( project );
      if ( null != includePatterns ) {
        for ( String includePattern : includePatterns ) {
          if ( SelectorUtils.match( includePattern, str ) ) {
            return true;
          }
        }
      } else {
        return true; // no include given: include all
      }
    } else {
      return true; // no patternset for type given: include all
    }
    return false; // str wasnt contained in includes / excludes
  }
 
Example 4
Source Project: avro-util   Source File: CodeGenerator.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean isSharedSchema(String pathRelativeToRoot) {
    for (String importPattern : importablePatterns) {
        if (SelectorUtils.matchPath(importPattern, pathRelativeToRoot)) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source Project: netbeans   Source File: CustomJavac.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isIgnored(
        final String[] patterns,
        final String resource) {
    for (String pattern : patterns) {
        if (SelectorUtils.match(pattern, resource)) {
            return true;
        }
    }
    return false;
}
 
Example 6
Source Project: netbeans   Source File: CreateLicenseSummary.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean matchModule(Project project, PatternSet pattern, String module) {
    for (String p : pattern.getExcludePatterns(project)) {
        if (SelectorUtils.matchPath(p, module)) {
            return true;
        }
    }
    return false;
}
 
Example 7
Source Project: netbeans   Source File: Branding.java    License: Apache License 2.0 5 votes vote down vote up
private boolean excluded(File f, String prefix) { // #68929
    String pathAbs = f.getAbsolutePath();
    if (!pathAbs.startsWith(prefix)) {
        throw new BuildException("Examined file " + f + " should have a path starting with " + prefix, getLocation());
    }
    // Cannot just call matchPath on the pathAbs because a relative pattern will *never* match an absolute path!
    String path = pathAbs.substring(prefix.length());
    for (String exclude : DirectoryScanner.getDefaultExcludes()) {
        if (SelectorUtils.matchPath(exclude.replace('/', File.separatorChar), path)) {
            return true;
        }
    }
    return false;
}
 
Example 8
Source Project: gocd   Source File: ArtifactPlan.java    License: Apache License 2.0 5 votes vote down vote up
protected String destinationURL(File rootPath, File file, String src, String dest) {
    String trimmedPattern = SelectorUtils.rtrimWildcardTokens(FilenameUtils.separatorsToUnix(src).replace('/', File.separatorChar));
    if (StringUtils.equals(FilenameUtils.separatorsToUnix(trimmedPattern), FilenameUtils.separatorsToUnix(src))) {
        return dest;
    }
    String trimmedPath = removeStart(subtractPath(rootPath, file), FilenameUtils.separatorsToUnix(trimmedPattern));
    if (!StringUtils.startsWith(trimmedPath, "/") && StringUtils.isNotEmpty(trimmedPath)) {
        trimmedPath = "/" + trimmedPath;
    }
    return dest + trimmedPath;
}
 
Example 9
Source Project: pipeline-utility-steps-plugin   Source File: UnZipStepExecution.java    License: MIT License 4 votes vote down vote up
boolean matches(String path, String glob) {
    String safeGlob = glob.replace('/', File.separatorChar);
    String safePath = path.replace('/', File.separatorChar);
    return SelectorUtils.matchPath(safeGlob, safePath);
}