Search in sources :

Example 11 with FileResource

use of org.apache.tools.ant.types.resources.FileResource 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 12 with FileResource

use of org.apache.tools.ant.types.resources.FileResource 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)

Aggregations

FileResource (org.apache.tools.ant.types.resources.FileResource)12 BuildException (org.apache.tools.ant.BuildException)11 IOException (java.io.IOException)9 File (java.io.File)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 Liquibase (liquibase.Liquibase)5 Iterator (java.util.Iterator)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 Contexts (liquibase.Contexts)4 LiquibaseException (liquibase.exception.LiquibaseException)4 Resource (org.apache.tools.ant.types.Resource)4 Writer (java.io.Writer)3 PrintStream (java.io.PrintStream)2 DiffOutputControl (liquibase.diff.output.DiffOutputControl)2 DiffToChangeLog (liquibase.diff.output.changelog.DiffToChangeLog)2 DatabaseException (liquibase.exception.DatabaseException)2 ChangeLogOutputFile (liquibase.integration.ant.type.ChangeLogOutputFile)2 ChangeLogSerializer (liquibase.serializer.ChangeLogSerializer)2 JsonChangeLogSerializer (liquibase.serializer.core.json.JsonChangeLogSerializer)2 StringChangeLogSerializer (liquibase.serializer.core.string.StringChangeLogSerializer)2