Java Code Examples for org.apache.tools.ant.types.Resource#isExists()

The following examples show how to use org.apache.tools.ant.types.Resource#isExists() . 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: Test.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
protected Resource[][] grabNonFileSetResources(ResourceCollection[] rcs) {
    Resource[][] result = new Resource[rcs.length][];
    for (int i = 0; i < rcs.length; i++) {
        ArrayList<Resource> dirs = new ArrayList<Resource>();
        ArrayList<Resource> files = new ArrayList<Resource>();
        for (Resource r : rcs[i]) {
            if (r.isExists()) {
                if (r.isDirectory()) {
                    dirs.add(r);
                } else {
                    files.add(r);
                }
            }
        }
        // make sure directories are in alpha-order - this also
        // ensures parents come before their children
        Collections.sort(dirs, new Comparator<Resource>() {
            public int compare(Resource r1, Resource r2) {
                return r1.getName().compareTo(r2.getName());
            }
        });
        ArrayList<Resource> rs = new ArrayList<Resource>(dirs);
        rs.addAll(files);
        result[i] = rs.toArray(new Resource[rs.size()]);
    }
    return result;
}
 
Example 2
Source File: Test.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
protected Resource[][] grabNonFileSetResources(ResourceCollection[] rcs) {
    Resource[][] result = new Resource[rcs.length][];
    for (int i = 0; i < rcs.length; i++) {
        ArrayList<Resource> dirs = new ArrayList<Resource>();
        ArrayList<Resource> files = new ArrayList<Resource>();
        for (Resource r : rcs[i]) {
            if (r.isExists()) {
                if (r.isDirectory()) {
                    dirs.add(r);
                } else {
                    files.add(r);
                }
            }
        }
        // make sure directories are in alpha-order - this also
        // ensures parents come before their children
        Collections.sort(dirs, new Comparator<Resource>() {
            public int compare(Resource r1, Resource r2) {
                return r1.getName().compareTo(r2.getName());
            }
        });
        ArrayList<Resource> rs = new ArrayList<Resource>(dirs);
        rs.addAll(files);
        result[i] = rs.toArray(new Resource[rs.size()]);
    }
    return result;
}
 
Example 3
Source File: Test.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
protected Resource[][] grabNonFileSetResources(ResourceCollection[] rcs) {
    Resource[][] result = new Resource[rcs.length][];
    for (int i = 0; i < rcs.length; i++) {
        ArrayList<Resource> dirs = new ArrayList<Resource>();
        ArrayList<Resource> files = new ArrayList<Resource>();
        for (Resource r : rcs[i]) {
            if (r.isExists()) {
                if (r.isDirectory()) {
                    dirs.add(r);
                } else {
                    files.add(r);
                }
            }
        }
        // make sure directories are in alpha-order - this also
        // ensures parents come before their children
        Collections.sort(dirs, new Comparator<Resource>() {
            public int compare(Resource r1, Resource r2) {
                return r1.getName().compareTo(r2.getName());
            }
        });
        ArrayList<Resource> rs = new ArrayList<Resource>(dirs);
        rs.addAll(files);
        result[i] = rs.toArray(new Resource[rs.size()]);
    }
    return result;
}
 
Example 4
Source File: PluginTask.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean initRequested() throws IOException {
    requestedPlugins = new HashSet<CordovaPlugin>();
    Resource resource = getProject().getResource("nbproject/plugins.properties");
    if (resource == null || !resource.isExists()) {
        return false;
    }
    Properties props = new Properties();
    props.load(resource.getInputStream());
    for (String name : props.stringPropertyNames()) {
        requestedPlugins.add(new CordovaPlugin(name, props.getProperty(name)));
    }
    return true;
}
 
Example 5
Source File: LicenseCheckTask.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Process all JARs.
 */
private void processJars() {
  log("Starting scan.", verboseLevel);
  long start = System.currentTimeMillis();

  @SuppressWarnings("unchecked")
  Iterator<Resource> iter = (Iterator<Resource>) jarResources.iterator();
  int checked = 0;
  int errors = 0;
  while (iter.hasNext()) {
    final Resource r = iter.next();
    if (!r.isExists()) { 
      throw new BuildException("JAR resource does not exist: " + r.getName());
    }
    if (!(r instanceof FileResource)) {
      throw new BuildException("Only filesystem resource are supported: " + r.getName()
          + ", was: " + r.getClass().getName());
    }

    File jarFile = ((FileResource) r).getFile();
    if (! checkJarFile(jarFile) ) {
      errors++;
    }
    checked++;
  }

  log(String.format(Locale.ROOT, 
      "Scanned %d JAR file(s) for licenses (in %.2fs.), %d error(s).",
      checked, (System.currentTimeMillis() - start) / 1000.0, errors),
      errors > 0 ? Project.MSG_ERR : Project.MSG_INFO);
}
 
Example 6
Source File: IconResource.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public IconResource(Resource r, BufferedImage badgeIcon) {
    super(r.getName(), r.isExists(), r.getLastModified(), r.isDirectory(), r.getSize());
    this.r = r;
    this.badgeIcon = badgeIcon;
}
 
Example 7
Source File: LibVersionsCheckTask.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * Execute the task.
 */
@Override
public void execute() throws BuildException {
  log("Starting scan.", verboseLevel);
  long start = System.currentTimeMillis();

  setupIvy();

  int numErrors = 0;
  if ( ! verifySortedCoordinatesPropertiesFile(centralizedVersionsFile)) {
    ++numErrors;
  }
  if ( ! verifySortedCoordinatesPropertiesFile(ignoreConflictsFile)) {
    ++numErrors;
  }
  collectDirectDependencies();
  if ( ! collectVersionConflictsToIgnore()) {
    ++numErrors;
  }

  int numChecked = 0;

  @SuppressWarnings("unchecked")
  Iterator<Resource> iter = (Iterator<Resource>)ivyXmlResources.iterator();
  while (iter.hasNext()) {
    final Resource resource = iter.next();
    if ( ! resource.isExists()) {
      throw new BuildException("Resource does not exist: " + resource.getName());
    }
    if ( ! (resource instanceof FileResource)) {
      throw new BuildException("Only filesystem resources are supported: " 
          + resource.getName() + ", was: " + resource.getClass().getName());
    }

    File ivyXmlFile = ((FileResource)resource).getFile();
    try {
      if ( ! checkIvyXmlFile(ivyXmlFile)) {
        ++numErrors;
      }
      if ( ! resolveTransitively(ivyXmlFile)) {
        ++numErrors;
      }
      if ( ! findLatestConflictVersions()) {
        ++numErrors;
      }
    } catch (Exception e) {
      throw new BuildException("Exception reading file " + ivyXmlFile.getPath() + " - " + e.toString(), e);
    }
    ++numChecked;
  }

  log("Checking for orphans in " + centralizedVersionsFile.getName(), verboseLevel);
  for (Map.Entry<String,Dependency> entry : directDependencies.entrySet()) {
    String coordinateKey = entry.getKey();
    if ( ! entry.getValue().directlyReferenced) {
      log("ORPHAN coordinate key '" + coordinateKey + "' in " + centralizedVersionsFile.getName()
          + " is not found in any " + IVY_XML_FILENAME + " file.",
          Project.MSG_ERR);
      ++numErrors;
    }
  }

  int numConflicts = emitConflicts();

  int messageLevel = numErrors > 0 ? Project.MSG_ERR : Project.MSG_INFO;
  log("Checked that " + centralizedVersionsFile.getName() + " and " + ignoreConflictsFile.getName()
      + " have lexically sorted '/org/name' keys and no duplicates or orphans.",
      messageLevel);
  log("Scanned " + numChecked + " " + IVY_XML_FILENAME + " files for rev=\"${/org/name}\" format.",
      messageLevel);
  log("Found " + numConflicts + " indirect dependency version conflicts.");
  log(String.format(Locale.ROOT, "Completed in %.2fs., %d error(s).",
                    (System.currentTimeMillis() - start) / 1000.0, numErrors),
      messageLevel);

  if (numConflicts > 0 || numErrors > 0) {
    throw new BuildException("Lib versions check failed. Check the logs.");
  }
}