org.apache.ivy.plugins.repository.ResourceDownloader Java Examples
The following examples show how to use
org.apache.ivy.plugins.repository.ResourceDownloader.
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: LocalFileRepositoryCacheManager.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public EnhancedArtifactDownloadReport download(Artifact artifact, ArtifactResourceResolver resourceResolver, ResourceDownloader resourceDownloader, CacheDownloadOptions options) { ResolvedResource resolvedResource = resourceResolver.resolve(artifact); long start = System.currentTimeMillis(); EnhancedArtifactDownloadReport report = new EnhancedArtifactDownloadReport(artifact); if (resolvedResource == null) { report.setDownloadStatus(DownloadStatus.FAILED); report.setDownloadDetails(ArtifactDownloadReport.MISSING_ARTIFACT); report.setDownloadTimeMillis(System.currentTimeMillis() - start); return report; } assert resolvedResource.getResource().isLocal(); File file = new File(resolvedResource.getResource().getName()); assert file.isFile(); ArtifactOrigin origin = new ArtifactOrigin(artifact, true, file.getAbsolutePath()); report.setDownloadStatus(DownloadStatus.NO); report.setArtifactOrigin(origin); report.setSize(file.length()); report.setLocalFile(file); return report; }
Example #2
Source File: LocalFileRepositoryCacheManager.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public ResolvedModuleRevision cacheModuleDescriptor(DependencyResolver resolver, ResolvedResource resolvedResource, DependencyDescriptor dd, Artifact moduleArtifact, ResourceDownloader downloader, CacheMetadataOptions options) throws ParseException { if (!moduleArtifact.isMetadata()) { return null; } assert resolvedResource.getResource().isLocal(); File file = new File(resolvedResource.getResource().getName()); assert file.isFile(); ArtifactOrigin origin = new ArtifactOrigin(moduleArtifact, true, file.getAbsolutePath()); MetadataArtifactDownloadReport report = new MetadataArtifactDownloadReport(moduleArtifact); report.setDownloadStatus(DownloadStatus.NO); report.setArtifactOrigin(origin); report.setSize(file.length()); report.setLocalFile(file); report.setSearched(false); report.setOriginalLocalFile(file); ModuleDescriptor descriptor = parseModuleDescriptor(resolver, moduleArtifact, options, file, resolvedResource.getResource()); return new ResolvedModuleRevision(resolver, resolver, descriptor, report); }
Example #3
Source File: LocalFileRepositoryCacheManager.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
public ResolvedModuleRevision cacheModuleDescriptor(DependencyResolver resolver, ResolvedResource resolvedResource, DependencyDescriptor dd, Artifact moduleArtifact, ResourceDownloader downloader, CacheMetadataOptions options) throws ParseException { if (!moduleArtifact.isMetadata()) { return null; } assert resolvedResource.getResource().isLocal(); File file = new File(resolvedResource.getResource().getName()); assert file.isFile(); ArtifactOrigin origin = new ArtifactOrigin(moduleArtifact, true, file.getAbsolutePath()); MetadataArtifactDownloadReport report = new MetadataArtifactDownloadReport(moduleArtifact); report.setDownloadStatus(DownloadStatus.NO); report.setArtifactOrigin(origin); report.setSize(file.length()); report.setLocalFile(file); report.setSearched(false); report.setOriginalLocalFile(file); ModuleDescriptor descriptor = parseModuleDescriptor(resolver, moduleArtifact, options, file, resolvedResource.getResource()); return new ResolvedModuleRevision(resolver, resolver, descriptor, report); }
Example #4
Source File: LocalFileRepositoryCacheManager.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
public EnhancedArtifactDownloadReport download(Artifact artifact, ArtifactResourceResolver resourceResolver, ResourceDownloader resourceDownloader, CacheDownloadOptions options) { ResolvedResource resolvedResource = resourceResolver.resolve(artifact); long start = System.currentTimeMillis(); EnhancedArtifactDownloadReport report = new EnhancedArtifactDownloadReport(artifact); if (resolvedResource == null) { report.setDownloadStatus(DownloadStatus.FAILED); report.setDownloadDetails(ArtifactDownloadReport.MISSING_ARTIFACT); report.setDownloadTimeMillis(System.currentTimeMillis() - start); return report; } assert resolvedResource.getResource().isLocal(); File file = new File(resolvedResource.getResource().getName()); assert file.isFile(); ArtifactOrigin origin = new ArtifactOrigin(artifact, true, file.getAbsolutePath()); report.setDownloadStatus(DownloadStatus.NO); report.setArtifactOrigin(origin); report.setSize(file.length()); report.setLocalFile(file); return report; }
Example #5
Source File: DownloadingRepositoryCacheManager.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private File downloadAndCacheArtifactFile(final ModuleVersionArtifactMetaData id, Artifact artifact, ResourceDownloader resourceDownloader, Resource resource) throws IOException { final File tmpFile = temporaryFileProvider.createTemporaryFile("gradle_download", "bin"); try { resourceDownloader.download(artifact, resource, tmpFile); return cacheLockingManager.useCache(String.format("Store %s", id), new Factory<File>() { public File create() { return fileStore.move(id, tmpFile).getFile(); } }); } finally { tmpFile.delete(); } }
Example #6
Source File: DownloadingRepositoryCacheManager.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
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: DownloadingRepositoryCacheManager.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
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 #8
Source File: DownloadingRepositoryCacheManager.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
private File downloadAndCacheArtifactFile(final ModuleVersionArtifactMetaData id, Artifact artifact, ResourceDownloader resourceDownloader, Resource resource) throws IOException { final File tmpFile = temporaryFileProvider.createTemporaryFile("gradle_download", "bin"); try { resourceDownloader.download(artifact, resource, tmpFile); return cacheLockingManager.useCache(String.format("Store %s", id), new Factory<File>() { public File create() { return fileStore.move(id, tmpFile).getFile(); } }); } finally { tmpFile.delete(); } }
Example #9
Source File: NoOpRepositoryCacheManager.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public ResolvedModuleRevision cacheModuleDescriptor(DependencyResolver resolver, ResolvedResource orginalMetadataRef, DependencyDescriptor dd, Artifact requestedMetadataArtifact, ResourceDownloader downloader, CacheMetadataOptions options) throws ParseException { return null; }
Example #10
Source File: DefaultRepositoryCacheManager.java From ant-ivy with Apache License 2.0 | 4 votes |
private BackupResourceDownloader(ResourceDownloader delegate) { this.delegate = delegate; }
Example #11
Source File: DefaultRepositoryCacheManager.java From ant-ivy with Apache License 2.0 | 4 votes |
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); } }
Example #12
Source File: DownloadingRepositoryCacheManager.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
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 #13
Source File: NoOpRepositoryCacheManager.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public ResolvedModuleRevision cacheModuleDescriptor(DependencyResolver resolver, ResolvedResource orginalMetadataRef, DependencyDescriptor dd, Artifact requestedMetadataArtifact, ResourceDownloader downloader, CacheMetadataOptions options) throws ParseException { return null; }
Example #14
Source File: NoOpRepositoryCacheManager.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public ArtifactDownloadReport download(Artifact artifact, ArtifactResourceResolver resourceResolver, ResourceDownloader resourceDownloader, CacheDownloadOptions options) { ArtifactDownloadReport report = new ArtifactDownloadReport(null); report.setDownloadStatus(DownloadStatus.NO); return report; }
Example #15
Source File: DownloadingRepositoryCacheManager.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
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 #16
Source File: NoOpRepositoryCacheManager.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public ArtifactDownloadReport download(Artifact artifact, ArtifactResourceResolver resourceResolver, ResourceDownloader resourceDownloader, CacheDownloadOptions options) { ArtifactDownloadReport report = new ArtifactDownloadReport(null); report.setDownloadStatus(DownloadStatus.NO); return report; }
Example #17
Source File: RepositoryCacheManager.java From ant-ivy with Apache License 2.0 | 3 votes |
/** * Caches an original module descriptor. * <p> * After this call, the original module descriptor file (with no modification nor conversion) * should be available as a local file. * </p> * * @param resolver the dependency resolver from which the cache request comes * from * @param originalMetadataRef a resolved resource pointing to the remote original module * descriptor * @param dd the dependency descriptor for which the module descriptor * should be cached * @param requestedMetadataArtifact the module descriptor artifact as requested originally * @param downloader a ResourceDownloader able to download the original module * descriptor resource if required by this cache implementation * @param options options to apply to cache this module descriptor * @return a {@link ResolvedModuleRevision} representing the local cached module descriptor, or * null if it failed * @throws ParseException if an exception occurred while parsing the module descriptor */ ResolvedModuleRevision cacheModuleDescriptor(DependencyResolver resolver, ResolvedResource originalMetadataRef, DependencyDescriptor dd, Artifact requestedMetadataArtifact, ResourceDownloader downloader, CacheMetadataOptions options) throws ParseException;
Example #18
Source File: RepositoryCacheManager.java From ant-ivy with Apache License 2.0 | 2 votes |
/** * Downloads an artifact to this cache. * * @param artifact the artifact to download * @param resourceResolver a resource resolver to use if the artifact needs to be resolved to * a Resource for downloading * @param resourceDownloader a resource downloader to use if actual download of the resource is * needed * @param options a set of options to adjust the download * @return a report indicating how the download was performed */ ArtifactDownloadReport download(Artifact artifact, ArtifactResourceResolver resourceResolver, ResourceDownloader resourceDownloader, CacheDownloadOptions options);