Search in sources :

Example 6 with Resource

use of org.apache.tools.ant.types.Resource in project lucene-solr by apache.

the class LibVersionsCheckTask method execute.

/**
   * 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.");
    }
}
Also used : FileResource(org.apache.tools.ant.types.resources.FileResource) Resource(org.apache.tools.ant.types.Resource) FileResource(org.apache.tools.ant.types.resources.FileResource) ParseException(java.text.ParseException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Iterator(java.util.Iterator) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with Resource

use of org.apache.tools.ant.types.Resource in project lucene-solr by apache.

the class LicenseCheckTask method processJars.

/**
   * 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);
}
Also used : Iterator(java.util.Iterator) FileResource(org.apache.tools.ant.types.resources.FileResource) Resource(org.apache.tools.ant.types.Resource) FileResource(org.apache.tools.ant.types.resources.FileResource) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 8 with Resource

use of org.apache.tools.ant.types.Resource in project jslint4java by happygiraffe.

the class JSLintTask method execute.

/**
 * Scan the specified directories for JavaScript files and lint them.
 */
@Override
public void execute() throws BuildException {
    if (resources.size() == 0) {
        // issue 53: this isn't a fail, just a notice.
        log(NO_FILES_TO_LINT);
    }
    JSLint lint = makeLint();
    applyOptions(lint);
    for (ResultFormatter rf : formatters) {
        rf.begin();
    }
    int failedCount = 0;
    int totalErrorCount = 0;
    for (Resource resource : resources.listResources()) {
        try {
            int errorCount = lintStream(lint, resource);
            if (errorCount > 0) {
                totalErrorCount += errorCount;
                failedCount++;
            }
        } catch (IOException e) {
            throw new BuildException(e);
        }
    }
    for (ResultFormatter rf : formatters) {
        rf.end();
    }
    if (failedCount != 0) {
        String msg = failureMessage(failedCount, totalErrorCount);
        if (haltOnFailure) {
            throw new BuildException(msg);
        } else {
            log(msg);
            if (failureProperty != null) {
                getProject().setProperty(failureProperty, msg);
            }
        }
    }
}
Also used : JSLint(com.googlecode.jslint4java.JSLint) Resource(org.apache.tools.ant.types.Resource) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) JSLint(com.googlecode.jslint4java.JSLint)

Example 9 with Resource

use of org.apache.tools.ant.types.Resource in project xtext-xtend by eclipse.

the class XtendCompilerAntTask method validateArgs.

private void validateArgs() {
    if (getDestdir() == null) {
        throw new BuildException("Destination directory 'destdir' is required.");
    }
    Path srcDirs = getSrcdir();
    if (srcDirs == null) {
        throw new BuildException("Sources directory 'srcdir' is required.");
    }
    Iterator<?> pathIter = srcDirs.iterator();
    while (pathIter.hasNext()) {
        Object next = pathIter.next();
        if (!(next instanceof Resource && ((Resource) next).isDirectory())) {
            throw new BuildException("Source directory must be a directory. Check 'srcdir' entry: " + next);
        }
    }
}
Also used : Path(org.apache.tools.ant.types.Path) Resource(org.apache.tools.ant.types.Resource) BuildException(org.apache.tools.ant.BuildException)

Aggregations

BuildException (org.apache.tools.ant.BuildException)9 Resource (org.apache.tools.ant.types.Resource)9 IOException (java.io.IOException)5 Iterator (java.util.Iterator)5 FileResource (org.apache.tools.ant.types.resources.FileResource)5 File (java.io.File)3 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 URLResource (org.apache.tools.ant.types.resources.URLResource)2 SAXException (org.xml.sax.SAXException)2 ClassGlobFilter (com.carrotsearch.randomizedtesting.ClassGlobFilter)1 JSLint (com.googlecode.jslint4java.JSLint)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1