Search in sources :

Example 46 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.

the class UpdateSiteLoader method readJarOrXml.

private boolean readJarOrXml(URI repoUri, String baseName, XMLInputParser reader) throws IOException, ParseException, SAXException {
    // the input stream from which the xml should be read
    InputStream readIn = null;
    URL contentUrl = repoUri.resolve(baseName + ".jar").toURL();
    URLResource res = new URLResource(contentUrl, this.timeoutConstraint);
    ArtifactDownloadReport report = repositoryCacheManager.downloadRepositoryResource(res, baseName, baseName, "jar", options, urlRepository);
    if (report.getDownloadStatus() == DownloadStatus.FAILED) {
        // no jar file, try the xml one
        contentUrl = repoUri.resolve(baseName + ".xml").toURL();
        res = new URLResource(contentUrl, this.timeoutConstraint);
        report = repositoryCacheManager.downloadRepositoryResource(res, baseName, baseName, "xml", options, urlRepository);
        if (report.getDownloadStatus() == DownloadStatus.FAILED) {
            // no xml either
            return false;
        }
        readIn = new FileInputStream(report.getLocalFile());
    } else {
        InputStream in = new FileInputStream(report.getLocalFile());
        try {
            // compressed, let's get the pointer on the actual xml
            readIn = findEntry(in, baseName + ".xml");
            if (readIn == null) {
                in.close();
                return false;
            }
        } catch (IOException e) {
            in.close();
            throw e;
        }
    }
    try {
        reader.parse(readIn);
    } finally {
        readIn.close();
    }
    return true;
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) IOException(java.io.IOException) URL(java.net.URL) FileInputStream(java.io.FileInputStream)

Example 47 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.

the class UpdateSiteResolver method init.

protected void init() {
    if (url == null) {
        throw new RuntimeException("Missing url");
    }
    CacheResourceOptions options = new CacheResourceOptions();
    if (metadataTtl != null) {
        options.setTtl(metadataTtl);
    }
    if (forceMetadataUpdate != null) {
        options.setForce(forceMetadataUpdate);
    }
    final int log;
    if (logLevel != null) {
        if ("debug".equalsIgnoreCase(logLevel)) {
            log = Message.MSG_DEBUG;
        } else if ("verbose".equalsIgnoreCase(logLevel)) {
            log = Message.MSG_VERBOSE;
        } else if ("info".equalsIgnoreCase(logLevel)) {
            log = Message.MSG_INFO;
        } else if ("warn".equalsIgnoreCase(logLevel)) {
            log = Message.MSG_WARN;
        } else if ("error".equalsIgnoreCase(logLevel)) {
            log = Message.MSG_ERR;
        } else {
            throw new RuntimeException("Unknown log level: " + logLevel);
        }
    } else {
        log = Message.MSG_INFO;
    }
    options.setListener(new DownloadListener() {

        public void startArtifactDownload(RepositoryCacheManager cache, ResolvedResource rres, Artifact artifact, ArtifactOrigin origin) {
            if (log <= Message.MSG_INFO) {
                Message.info("\tdownloading " + rres.getResource().getName());
            }
        }

        public void needArtifact(RepositoryCacheManager cache, Artifact artifact) {
            if (log <= Message.MSG_VERBOSE) {
                Message.verbose("\ttrying to download " + artifact);
            }
        }

        public void endArtifactDownload(RepositoryCacheManager cache, Artifact artifact, ArtifactDownloadReport adr, File archiveFile) {
            if (log <= Message.MSG_VERBOSE) {
                if (adr.isDownloaded()) {
                    Message.verbose("\tdownloaded to " + archiveFile.getAbsolutePath());
                } else {
                    Message.verbose("\tnothing to download");
                }
            }
        }
    });
    final UpdateSiteLoader loader = new UpdateSiteLoader(getRepositoryCacheManager(), getEventManager(), options, this.getTimeoutConstraint());
    loader.setLogLevel(log);
    RepoDescriptor repoDescriptor;
    try {
        repoDescriptor = loader.load(new URI(url));
    } catch (IOException e) {
        throw new RuntimeException("IO issue while trying to read the update site (" + e.getMessage() + ")");
    } catch (ParseException e) {
        throw new RuntimeException("Failed to parse the updatesite (" + e.getMessage() + ")", e);
    } catch (SAXException e) {
        throw new RuntimeException("Ill-formed updatesite (" + e.getMessage() + ")", e);
    } catch (URISyntaxException e) {
        throw new RuntimeException("Ill-formed url (" + e.getMessage() + ")", e);
    }
    if (repoDescriptor == null) {
        setRepoDescriptor(FAILING_REPO_DESCRIPTOR);
        throw new RuntimeException("No update site was found at the location: " + url);
    }
    setRepoDescriptor(repoDescriptor);
}
Also used : RepositoryCacheManager(org.apache.ivy.core.cache.RepositoryCacheManager) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin) URI(java.net.URI) Artifact(org.apache.ivy.core.module.descriptor.Artifact) SAXException(org.xml.sax.SAXException) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) DownloadListener(org.apache.ivy.core.cache.DownloadListener) RepoDescriptor(org.apache.ivy.osgi.repo.RepoDescriptor) CacheResourceOptions(org.apache.ivy.core.cache.CacheResourceOptions) ParseException(java.text.ParseException) File(java.io.File)

Example 48 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.

the class IvyCacheFilesetTest method artifactDownloadReport.

private ArtifactDownloadReport artifactDownloadReport(File localFile) {
    ArtifactDownloadReport report = new ArtifactDownloadReport(null);
    report.setLocalFile(localFile);
    return report;
}
Also used : ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport)

Example 49 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.

the class IvyArtifactReport method generateXml.

private void generateXml(IvyNode[] dependencies, Map<ModuleRevisionId, Set<ArtifactDownloadReport>> moduleRevToArtifactsMap, Map<ArtifactDownloadReport, Set<String>> artifactsToCopy) {
    try {
        try (FileOutputStream fileOutputStream = new FileOutputStream(tofile)) {
            TransformerHandler saxHandler = createTransformerHandler(fileOutputStream);
            saxHandler.startDocument();
            saxHandler.startElement(null, "modules", "modules", new AttributesImpl());
            for (IvyNode dependency : dependencies) {
                if (dependency.getModuleRevision() == null || dependency.isCompletelyEvicted()) {
                    continue;
                }
                startModule(saxHandler, dependency);
                Set<ArtifactDownloadReport> artifactsOfModuleRev = moduleRevToArtifactsMap.get(dependency.getModuleRevision().getId());
                if (artifactsOfModuleRev != null) {
                    for (ArtifactDownloadReport artifact : artifactsOfModuleRev) {
                        RepositoryCacheManager cache = dependency.getModuleRevision().getArtifactResolver().getRepositoryCacheManager();
                        startArtifact(saxHandler, artifact.getArtifact());
                        writeOriginLocationIfPresent(cache, saxHandler, artifact);
                        writeCacheLocationIfPresent(cache, saxHandler, artifact);
                        for (String artifactDestPath : artifactsToCopy.get(artifact)) {
                            writeRetrieveLocation(saxHandler, artifactDestPath);
                        }
                        saxHandler.endElement(null, "artifact", "artifact");
                    }
                }
                saxHandler.endElement(null, "module", "module");
            }
            saxHandler.endElement(null, "modules", "modules");
            saxHandler.endDocument();
        }
    } catch (SAXException | IOException | TransformerConfigurationException e) {
        throw new BuildException("impossible to generate report", e);
    }
}
Also used : TransformerHandler(javax.xml.transform.sax.TransformerHandler) RepositoryCacheManager(org.apache.ivy.core.cache.RepositoryCacheManager) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) AttributesImpl(org.xml.sax.helpers.AttributesImpl) FileOutputStream(java.io.FileOutputStream) BuildException(org.apache.tools.ant.BuildException) IvyNode(org.apache.ivy.core.resolve.IvyNode)

Example 50 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.

the class IvyCacheTask method getAllArtifactReports.

private Collection<ArtifactDownloadReport> getAllArtifactReports() throws ParseException {
    String[] confs = splitToArray(getConf());
    Collection<ArtifactDownloadReport> all = new LinkedHashSet<>();
    ResolveReport report = getResolvedReport();
    if (report != null) {
        Message.debug("using internal report instance to get artifacts list");
        for (String conf : confs) {
            ConfigurationResolveReport configurationReport = report.getConfigurationReport(conf);
            if (configurationReport == null) {
                throw new BuildException("bad confs provided: " + conf + " not found among " + Arrays.asList(report.getConfigurations()));
            }
            for (ModuleRevisionId revId : configurationReport.getModuleRevisionIds()) {
                all.addAll(Arrays.asList(configurationReport.getDownloadReports(revId)));
            }
        }
    } else {
        Message.debug("using stored report to get artifacts list");
        XmlReportParser parser = new XmlReportParser();
        ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
        String resolvedId = getResolveId();
        if (resolvedId == null) {
            resolvedId = ResolveOptions.getDefaultResolveId(getResolvedModuleId());
        }
        for (String conf : confs) {
            File reportFile = cacheMgr.getConfigurationResolveReportInCache(resolvedId, conf);
            parser.parse(reportFile);
            all.addAll(Arrays.asList(parser.getArtifactReports()));
        }
    }
    return all;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) XmlReportParser(org.apache.ivy.plugins.report.XmlReportParser) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Aggregations

ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)64 File (java.io.File)33 Artifact (org.apache.ivy.core.module.descriptor.Artifact)29 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)26 Test (org.junit.Test)25 DownloadReport (org.apache.ivy.core.report.DownloadReport)23 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)18 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)18 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)17 ResolveReport (org.apache.ivy.core.report.ResolveReport)15 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)11 IOException (java.io.IOException)10 DownloadOptions (org.apache.ivy.core.resolve.DownloadOptions)10 URL (java.net.URL)8 JarFile (java.util.jar.JarFile)8 Date (java.util.Date)7 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)7 URLResource (org.apache.ivy.plugins.repository.url.URLResource)7 ArtifactOrigin (org.apache.ivy.core.cache.ArtifactOrigin)6 MalformedURLException (java.net.MalformedURLException)5