Java Code Examples for org.apache.ivy.core.report.ArtifactDownloadReport#getDownloadStatus()

The following examples show how to use org.apache.ivy.core.report.ArtifactDownloadReport#getDownloadStatus() . 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: UpdateSiteLoader.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private UpdateSite loadSite(URI repoUri) throws IOException, SAXException {
    URI siteUri = normalizeSiteUri(repoUri, null);
    URL u = siteUri.resolve("site.xml").toURL();

    final URLResource res = new URLResource(u, this.timeoutConstraint);
    ArtifactDownloadReport report = repositoryCacheManager.downloadRepositoryResource(res,
        "site", "updatesite", "xml", options, urlRepository);
    if (report.getDownloadStatus() == DownloadStatus.FAILED) {
        return null;
    }
    try (InputStream in = new FileInputStream(report.getLocalFile())) {
        UpdateSite site = EclipseUpdateSiteParser.parse(in);
        site.setUri(normalizeSiteUri(site.getUri(), siteUri));
        return site;
    }
}
 
Example 2
Source File: UpdateSiteLoader.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private UpdateSiteDescriptor loadFromDigest(UpdateSite site) throws IOException,
        SAXException {
    URI digestBaseUri = site.getDigestUri();
    if (digestBaseUri == null) {
        digestBaseUri = site.getUri();
    } else if (!digestBaseUri.isAbsolute()) {
        digestBaseUri = site.getUri().resolve(digestBaseUri);
    }
    URL digest = digestBaseUri.resolve("digest.zip").toURL();
    Message.verbose("\tReading " + digest);

    final URLResource res = new URLResource(digest, this.timeoutConstraint);
    ArtifactDownloadReport report = repositoryCacheManager.downloadRepositoryResource(res,
        "digest", "digest", "zip", options, urlRepository);
    if (report.getDownloadStatus() == DownloadStatus.FAILED) {
        return null;
    }
    try (InputStream in = new FileInputStream(report.getLocalFile())) {
        ZipInputStream zipped = findEntry(in, "digest.xml");
        if (zipped == null) {
            return null;
        }
        return UpdateSiteDigestParser.parse(zipped, site);
    }
}
 
Example 3
Source File: UpdateSiteLoader.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private UpdateSiteDescriptor loadFromSite(UpdateSite site) throws IOException, SAXException {
    UpdateSiteDescriptor repoDescriptor = new UpdateSiteDescriptor(site.getUri(),
            ExecutionEnvironmentProfileProvider.getInstance());

    for (EclipseFeature feature : site.getFeatures()) {
        URL url = site.getUri().resolve(feature.getUrl()).toURL();

        final URLResource res = new URLResource(url, this.timeoutConstraint);
        ArtifactDownloadReport report = repositoryCacheManager.downloadRepositoryResource(res,
            feature.getId(), "feature", "jar", options, urlRepository);
        if (report.getDownloadStatus() == DownloadStatus.FAILED) {
            return null;
        }
        try (InputStream in = new FileInputStream(report.getLocalFile())) {
            ZipInputStream zipped = findEntry(in, "feature.xml");
            if (zipped == null) {
                return null;
            }
            EclipseFeature f = FeatureParser.parse(zipped);
            f.setURL(feature.getUrl());
            repoDescriptor.addFeature(f);
        }
    }

    return repoDescriptor;
}
 
Example 4
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    RepositoryCacheManager cacheManager = getRepositoryCacheManager();

    clearArtifactAttempts();
    DownloadReport dr = new DownloadReport();
    for (Artifact artifact : artifacts) {
        ArtifactDownloadReport adr = cacheManager.download(artifact, artifactResourceResolver,
            downloader, getCacheDownloadOptions(options));
        if (DownloadStatus.FAILED == adr.getDownloadStatus()) {
            if (!ArtifactDownloadReport.MISSING_ARTIFACT.equals(adr.getDownloadDetails())) {
                Message.warn("\t" + adr);
            }
        } else if (DownloadStatus.NO == adr.getDownloadStatus()) {
            Message.verbose("\t" + adr);
        } else if (LogOptions.LOG_QUIET.equals(options.getLog())) {
            Message.verbose("\t" + adr);
        } else {
            Message.info("\t" + adr);
        }
        dr.addArtifactReport(adr);
        checkInterrupted();
    }
    return dr;
}
 
Example 5
Source File: DownloadingRepositoryCacheManager.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ResolvedModuleRevision cacheModuleDescriptor(DependencyResolver resolver, final ResolvedResource resolvedResource, DependencyDescriptor dd, Artifact moduleArtifact, ResourceDownloader downloader, CacheMetadataOptions options) throws ParseException {
    if (!moduleArtifact.isMetadata()) {
        return null;
    }

    ArtifactResourceResolver artifactResourceResolver = new ArtifactResourceResolver() {
        public ResolvedResource resolve(Artifact artifact) {
            return resolvedResource;
        }
    };
    ArtifactDownloadReport report = download(moduleArtifact, artifactResourceResolver, downloader, new CacheDownloadOptions().setListener(options.getListener()).setForce(true));

    if (report.getDownloadStatus() == DownloadStatus.FAILED) {
        LOGGER.warn("problem while downloading module descriptor: {}: {} ({} ms)", resolvedResource.getResource(), report.getDownloadDetails(), report.getDownloadTimeMillis());
        return null;
    }

    ModuleDescriptor md = parseModuleDescriptor(resolver, moduleArtifact, options, report.getLocalFile(), resolvedResource.getResource());
    LOGGER.debug("\t{}: parsed downloaded md file for {}; parsed={}" + getName(), moduleArtifact.getModuleRevisionId(), md.getModuleRevisionId());

    MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(md.getMetadataArtifact());
    madr.setSearched(true);
    madr.setDownloadStatus(report.getDownloadStatus());
    madr.setDownloadDetails(report.getDownloadDetails());
    madr.setArtifactOrigin(report.getArtifactOrigin());
    madr.setDownloadTimeMillis(report.getDownloadTimeMillis());
    madr.setOriginalLocalFile(report.getLocalFile());
    madr.setSize(report.getSize());

    return new ResolvedModuleRevision(resolver, resolver, md, madr);
}
 
Example 6
Source File: DownloadingRepositoryCacheManager.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ResolvedModuleRevision cacheModuleDescriptor(DependencyResolver resolver, final ResolvedResource resolvedResource, DependencyDescriptor dd, Artifact moduleArtifact, ResourceDownloader downloader, CacheMetadataOptions options) throws ParseException {
    if (!moduleArtifact.isMetadata()) {
        return null;
    }

    ArtifactResourceResolver artifactResourceResolver = new ArtifactResourceResolver() {
        public ResolvedResource resolve(Artifact artifact) {
            return resolvedResource;
        }
    };
    ArtifactDownloadReport report = download(moduleArtifact, artifactResourceResolver, downloader, new CacheDownloadOptions().setListener(options.getListener()).setForce(true));

    if (report.getDownloadStatus() == DownloadStatus.FAILED) {
        LOGGER.warn("problem while downloading module descriptor: {}: {} ({} ms)", resolvedResource.getResource(), report.getDownloadDetails(), report.getDownloadTimeMillis());
        return null;
    }

    ModuleDescriptor md = parseModuleDescriptor(resolver, moduleArtifact, options, report.getLocalFile(), resolvedResource.getResource());
    LOGGER.debug("\t{}: parsed downloaded md file for {}; parsed={}" + getName(), moduleArtifact.getModuleRevisionId(), md.getModuleRevisionId());

    MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(md.getMetadataArtifact());
    madr.setSearched(true);
    madr.setDownloadStatus(report.getDownloadStatus());
    madr.setDownloadDetails(report.getDownloadDetails());
    madr.setArtifactOrigin(report.getArtifactOrigin());
    madr.setDownloadTimeMillis(report.getDownloadTimeMillis());
    madr.setOriginalLocalFile(report.getLocalFile());
    madr.setSize(report.getSize());

    return new ResolvedModuleRevision(resolver, resolver, md, madr);
}
 
Example 7
Source File: XmlReportParser.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public void endElement(String uri, String localName, String qname) throws SAXException {
    if ("dependencies".equals(qname)) {
        // add the artifacts in the correct order
        for (List<ArtifactDownloadReport> artifactReports : revisionsMap.values()) {
            SaxXmlReportParser.this.artifactReports.addAll(artifactReports);
            for (ArtifactDownloadReport artifactReport : artifactReports) {
                if (artifactReport.getDownloadStatus() != DownloadStatus.FAILED) {
                    artifacts.add(artifactReport.getArtifact());
                }
            }

        }
    }
}
 
Example 8
Source File: AbstractResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Default implementation actually download the artifact Subclasses should overwrite this to
 * avoid the download
 *
 * @param artifact ArtifactOrigin
 * @return ArtifactOrigin
 */
public ArtifactOrigin locate(Artifact artifact) {
    DownloadReport dr = download(new Artifact[] {artifact}, new DownloadOptions());
    if (dr == null) {
        /*
         * according to IVY-831, it seems that this actually happen sometime, while the
         * contract of DependencyResolver says that it should never return null
         */
        throw new IllegalStateException("null download report returned by " + getName() + " ("
                + getClass().getName() + ")" + " when trying to download " + artifact);
    }
    ArtifactDownloadReport adr = dr.getArtifactReport(artifact);
    return adr.getDownloadStatus() == DownloadStatus.FAILED ? null : adr.getArtifactOrigin();
}
 
Example 9
Source File: JarResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Override
public void setSettings(ResolverSettings settings) {
    super.setSettings(settings);
    if (url == null) {
        return;
    }
    // let's resolve the url
    ArtifactDownloadReport report;
    EventManager eventManager = getEventManager();
    try {
        if (eventManager != null) {
            getRepository().addTransferListener(eventManager);
        }
        Resource jarResource = new URLResource(url, this.getTimeoutConstraint());
        CacheResourceOptions options = new CacheResourceOptions();
        report = getRepositoryCacheManager().downloadRepositoryResource(jarResource,
            "jarrepository", "jar", "jar", options, new URLRepository());
    } finally {
        if (eventManager != null) {
            getRepository().removeTransferListener(eventManager);
        }
    }
    if (report.getDownloadStatus() == DownloadStatus.FAILED) {
        throw new RuntimeException("The jar file " + url.toExternalForm()
                + " could not be downloaded (" + report.getDownloadDetails() + ")");
    }
    setJarFile(report.getLocalFile());
}
 
Example 10
Source File: IvyDependencyResolverAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private boolean downloadFailed(ArtifactDownloadReport artifactReport) {
    // Ivy reports FAILED with MISSING_ARTIFACT message when the artifact doesn't exist.
    return artifactReport.getDownloadStatus() == DownloadStatus.FAILED
            && !artifactReport.getDownloadDetails().equals(ArtifactDownloadReport.MISSING_ARTIFACT);
}
 
Example 11
Source File: IvyDependencyResolverAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private boolean downloadFailed(ArtifactDownloadReport artifactReport) {
    // Ivy reports FAILED with MISSING_ARTIFACT message when the artifact doesn't exist.
    return artifactReport.getDownloadStatus() == DownloadStatus.FAILED
            && !artifactReport.getDownloadDetails().equals(ArtifactDownloadReport.MISSING_ARTIFACT);
}
 
Example 12
Source File: ResolveEngine.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public void downloadArtifacts(ResolveReport report, Filter<Artifact> artifactFilter,
        DownloadOptions options) {
    long start = System.currentTimeMillis();

    eventManager.fireIvyEvent(new PrepareDownloadEvent(report.getArtifacts().toArray(
        new Artifact[report.getArtifacts().size()])));

    long totalSize = 0;
    for (IvyNode dependency : report.getDependencies()) {
        checkInterrupted();
        // download artifacts required in all asked configurations
        if (!dependency.isCompletelyEvicted() && !dependency.hasProblem()
                && dependency.getModuleRevision() != null) {
            DependencyResolver resolver = dependency.getModuleRevision()
                    .getArtifactResolver();
            Artifact[] selectedArtifacts = dependency.getSelectedArtifacts(artifactFilter);
            DownloadReport dReport = resolver.download(selectedArtifacts, options);
            for (ArtifactDownloadReport adr : dReport.getArtifactsReports()) {
                if (adr.getDownloadStatus() == DownloadStatus.FAILED) {
                    if (adr.getArtifact().getExtraAttribute("ivy:merged") != null) {
                        Message.warn("\tmerged artifact not found: " + adr.getArtifact()
                                + ". It was required in "
                                + adr.getArtifact().getExtraAttribute("ivy:merged"));
                    } else {
                        Message.warn("\t" + adr);
                        resolver.reportFailure(adr.getArtifact());
                    }
                } else if (adr.getDownloadStatus() == DownloadStatus.SUCCESSFUL) {
                    totalSize += adr.getSize();
                }
            }
            // update concerned reports
            for (String dconf : dependency.getRootModuleConfigurations()) {
                // the report itself is responsible to take into account only
                // artifacts required in its corresponding configuration
                // (as described by the Dependency object)
                if (dependency.isEvicted(dconf)
                        || dependency.isBlacklisted(dconf)) {
                    report.getConfigurationReport(dconf).addDependency(dependency);
                } else {
                    report.getConfigurationReport(dconf).addDependency(dependency,
                            dReport);
                }
            }
        }
    }
    report.setDownloadTime(System.currentTimeMillis() - start);
    report.setDownloadSize(totalSize);
}
 
Example 13
Source File: DefaultRepositoryCacheManager.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public ArtifactDownloadReport download(Artifact artifact,
        ArtifactResourceResolver resourceResolver, ResourceDownloader resourceDownloader,
        CacheDownloadOptions options) {
    final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifact);
    boolean useOrigin = isUseOrigin();

    // TODO: see if we could lock on the artifact to download only, instead of the module
    // metadata artifact. We'd need to store artifact origin and is local in artifact specific
    // file to do so, or lock the metadata artifact only to update artifact origin, which would
    // mean acquiring nested locks, which can be a dangerous thing
    ModuleRevisionId mrid = artifact.getModuleRevisionId();
    if (!lockMetadataArtifact(mrid)) {
        adr.setDownloadStatus(DownloadStatus.FAILED);
        adr.setDownloadDetails("impossible to get lock for " + mrid);
        return adr;
    }
    try {
        DownloadListener listener = options.getListener();
        if (listener != null) {
            listener.needArtifact(this, artifact);
        }
        ArtifactOrigin origin = getSavedArtifactOrigin(artifact);
        // if we can use origin file, we just ask ivy for the file in cache, and it will
        // return the original one if possible. If we are not in useOrigin mode, we use the
        // getArchivePath method which always return a path in the actual cache
        File archiveFile = getArchiveFileInCache(artifact, origin, useOrigin);

        if (archiveFile.exists() && !options.isForce()) {
            adr.setDownloadStatus(DownloadStatus.NO);
            adr.setSize(archiveFile.length());
            adr.setArtifactOrigin(origin);
            adr.setLocalFile(archiveFile);
        } else {
            long start = System.currentTimeMillis();
            try {
                ResolvedResource artifactRef = resourceResolver.resolve(artifact);
                if (artifactRef != null) {
                    Resource artifactRes = artifactRef.getResource();
                    origin = new ArtifactOrigin(artifact, artifactRes.isLocal(),
                            artifactRes.getName());
                    if (useOrigin && artifactRes.isLocal()) {
                        if (artifactRes instanceof LocalizableResource) {
                            origin.setLocation(((LocalizableResource) artifactRes).getFile()
                                    .getAbsolutePath());
                        }
                        saveArtifactOrigin(artifact, origin);
                        archiveFile = getArchiveFileInCache(artifact, origin);
                        adr.setDownloadStatus(DownloadStatus.NO);
                        adr.setSize(archiveFile.length());
                        adr.setArtifactOrigin(origin);
                        adr.setLocalFile(archiveFile);
                    } else {
                        // refresh archive file now that we better now its origin
                        archiveFile = getArchiveFileInCache(artifact, origin, useOrigin);
                        if (ResourceHelper.equals(artifactRes, archiveFile)) {
                            throw new IllegalStateException("invalid settings for '"
                                    + resourceResolver
                                    + "': pointing repository to ivy cache is forbidden !");
                        }
                        if (listener != null) {
                            listener.startArtifactDownload(this, artifactRef, artifact, origin);
                        }

                        resourceDownloader.download(artifact, artifactRes, archiveFile);
                        adr.setSize(archiveFile.length());
                        saveArtifactOrigin(artifact, origin);
                        adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
                        adr.setDownloadStatus(DownloadStatus.SUCCESSFUL);
                        adr.setArtifactOrigin(origin);
                        adr.setLocalFile(archiveFile);
                    }
                } else {
                    adr.setDownloadStatus(DownloadStatus.FAILED);
                    adr.setDownloadDetails(ArtifactDownloadReport.MISSING_ARTIFACT);
                    adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
                }
            } catch (Exception ex) {
                Message.debug(ex);
                adr.setDownloadStatus(DownloadStatus.FAILED);
                adr.setDownloadDetails(ex.getMessage());
                adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
            }
        }
        if (adr.getDownloadStatus() != DownloadStatus.FAILED) {
            unpackArtifact(artifact, adr, options);
        }
        if (listener != null) {
            listener.endArtifactDownload(this, artifact, adr, archiveFile);
        }
        return adr;
    } finally {
        unlockMetadataArtifact(mrid);
    }
}