org.apache.ivy.core.cache.DownloadListener Java Examples

The following examples show how to use org.apache.ivy.core.cache.DownloadListener. 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: DownloadingRepositoryCacheManager.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public EnhancedArtifactDownloadReport download(Artifact artifact, ArtifactResourceResolver resourceResolver,
                                               ResourceDownloader resourceDownloader, CacheDownloadOptions options) {
    EnhancedArtifactDownloadReport adr = new EnhancedArtifactDownloadReport(artifact);

    DownloadListener listener = options.getListener();
    if (listener != null) {
        listener.needArtifact(this, artifact);
    }

    long start = System.currentTimeMillis();
    try {
        ResolvedResource artifactRef = resourceResolver.resolve(artifact);
        if (artifactRef != null) {
            final Resource resource = artifactRef.getResource();
            ArtifactOrigin origin = new ArtifactOrigin(artifact, resource.isLocal(), resource.getName());
            if (listener != null) {
                listener.startArtifactDownload(this, artifactRef, artifact, origin);
            }

            ModuleRevisionId moduleRevisionId = artifact.getModuleRevisionId();
            ModuleComponentIdentifier componentIdentifier = DefaultModuleComponentIdentifier.newId(moduleRevisionId.getOrganisation(), moduleRevisionId.getName(), moduleRevisionId.getRevision());
            File artifactFile = downloadAndCacheArtifactFile(new DefaultModuleVersionArtifactMetaData(componentIdentifier, artifact), artifact, resourceDownloader, artifactRef.getResource());

            adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
            adr.setSize(artifactFile.length());
            adr.setDownloadStatus(DownloadStatus.SUCCESSFUL);
            adr.setArtifactOrigin(origin);
            adr.setLocalFile(artifactFile);
        } else {
            adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
            adr.setDownloadStatus(DownloadStatus.FAILED);
            adr.setDownloadDetails(ArtifactDownloadReport.MISSING_ARTIFACT);
        }
    } catch (Throwable throwable) {
        adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
        adr.failed(throwable);
    }
    if (listener != null) {
        listener.endArtifactDownload(this, artifact, adr, adr.getLocalFile());
    }
    return adr;
}
 
Example #2
Source File: DownloadingRepositoryCacheManager.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public EnhancedArtifactDownloadReport download(Artifact artifact, ArtifactResourceResolver resourceResolver,
                                               ResourceDownloader resourceDownloader, CacheDownloadOptions options) {
    EnhancedArtifactDownloadReport adr = new EnhancedArtifactDownloadReport(artifact);

    DownloadListener listener = options.getListener();
    if (listener != null) {
        listener.needArtifact(this, artifact);
    }

    long start = System.currentTimeMillis();
    try {
        ResolvedResource artifactRef = resourceResolver.resolve(artifact);
        if (artifactRef != null) {
            final Resource resource = artifactRef.getResource();
            ArtifactOrigin origin = new ArtifactOrigin(artifact, resource.isLocal(), resource.getName());
            if (listener != null) {
                listener.startArtifactDownload(this, artifactRef, artifact, origin);
            }

            ModuleRevisionId moduleRevisionId = artifact.getModuleRevisionId();
            ModuleComponentIdentifier componentIdentifier = DefaultModuleComponentIdentifier.newId(moduleRevisionId.getOrganisation(), moduleRevisionId.getName(), moduleRevisionId.getRevision());
            File artifactFile = downloadAndCacheArtifactFile(new DefaultModuleVersionArtifactMetaData(componentIdentifier, artifact), artifact, resourceDownloader, artifactRef.getResource());

            adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
            adr.setSize(artifactFile.length());
            adr.setDownloadStatus(DownloadStatus.SUCCESSFUL);
            adr.setArtifactOrigin(origin);
            adr.setLocalFile(artifactFile);
        } else {
            adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
            adr.setDownloadStatus(DownloadStatus.FAILED);
            adr.setDownloadDetails(ArtifactDownloadReport.MISSING_ARTIFACT);
        }
    } catch (Throwable throwable) {
        adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
        adr.failed(throwable);
    }
    if (listener != null) {
        listener.endArtifactDownload(this, artifact, adr, adr.getLocalFile());
    }
    return adr;
}