org.apache.ivy.plugins.repository.Resource Java Examples
The following examples show how to use
org.apache.ivy.plugins.repository.Resource.
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: BasicResolver.java From ant-ivy with Apache License 2.0 | 6 votes |
public void download(Artifact artifact, Resource resource, File dest) throws IOException { if (dest.exists()) { dest.delete(); } File part = new File(dest.getAbsolutePath() + ".part"); if (resource.getName().equals(String.valueOf(artifact.getUrl()))) { if (part.getParentFile() != null) { part.getParentFile().mkdirs(); } extartifactrep.get(resource.getName(), part); } else { getAndCheck(resource, part); } if (!part.renameTo(dest)) { throw new IOException("impossible to move part file to definitive one: " + part + " -> " + dest); } }
Example #2
Source File: DefaultRepositoryCacheManager.java From ant-ivy with Apache License 2.0 | 6 votes |
/** * Check that a cached file can be considered up to date and thus not downloaded * * @param archiveFile * the file in the cache * @param resource * the remote resource to check * @param savedOrigin * the saved origin which contains that last checked date * @param origin * the origin in which to store the new last checked date * @param ttl * the time to live to consider the cache up to date * @return <code>true</code> if the cache is considered up to date */ private boolean checkCacheUptodate(File archiveFile, Resource resource, ArtifactOrigin savedOrigin, ArtifactOrigin origin, long ttl) { long time = System.currentTimeMillis(); if (savedOrigin.getLastChecked() != null && (time - savedOrigin.getLastChecked()) < ttl) { // still in the ttl period, no need to check, trust the cache return archiveFile.exists() || !savedOrigin.isExists(); } if (!archiveFile.exists()) { // the the file doesn't exist in the cache, obviously not up to date return false; } origin.setLastChecked(time); // check if the local resource is up to date regarding the remote one return archiveFile.lastModified() >= resource.getLastModified(); }
Example #3
Source File: SFTPRepository.java From ant-ivy with Apache License 2.0 | 6 votes |
/** * This method is similar to getResource, except that the returned resource is fully initialized * (resolved in the sftp repository), and that the given string is a full remote path * * @param path * the full remote path in the repository of the resource * @return a fully initialized resource, able to answer to all its methods without needing any * further connection */ @SuppressWarnings("unchecked") public Resource resolveResource(String path) { try { List<LsEntry> r = getSftpChannel(path).ls(getPath(path)); if (r != null) { SftpATTRS attrs = r.get(0).getAttrs(); return new BasicResource(path, true, attrs.getSize(), attrs.getMTime() * MILLIS_PER_SECOND, false); } } catch (Exception e) { Message.debug("Error while resolving resource " + path, e); // silent fail, return nonexistent resource } return new BasicResource(path, false, 0, 0, false); }
Example #4
Source File: VsftpRepository.java From ant-ivy with Apache License 2.0 | 6 votes |
/** * Parses a ls -l line and transforms it in a resource * * @param file ditto * @param responseLine ditto * @return Resource */ protected Resource lslToResource(String file, String responseLine) { if (responseLine == null || responseLine.startsWith("ls")) { return new BasicResource(file, false, 0, 0, false); } else { String[] parts = responseLine.split("\\s+"); if (parts.length != LS_PARTS_NUMBER) { Message.debug("unrecognized ls format: " + responseLine); return new BasicResource(file, false, 0, 0, false); } else { try { long contentLength = Long.parseLong(parts[LS_SIZE_INDEX]); String date = parts[LS_DATE_INDEX1] + " " + parts[LS_DATE_INDEX2] + " " + parts[LS_DATE_INDEX3] + " " + parts[LS_DATE_INDEX4]; return new BasicResource(file, true, contentLength, FORMAT.parse(date) .getTime(), false); } catch (Exception ex) { Message.warn("impossible to parse server response: " + responseLine, ex); return new BasicResource(file, false, 0, 0, false); } } } }
Example #5
Source File: URLRepository.java From ant-ivy with Apache License 2.0 | 6 votes |
public void get(String source, File destination) throws IOException { fireTransferInitiated(getResource(source), TransferEvent.REQUEST_GET); try { Resource res = getResource(source); long totalLength = res.getContentLength(); if (totalLength > 0) { progress.setTotalLength(totalLength); } FileUtil.copy(new URL(source), destination, progress, getTimeoutConstraint()); } catch (IOException | RuntimeException ex) { fireTransferError(ex); throw ex; } finally { progress.setTotalLength(null); } }
Example #6
Source File: ProgressLoggingTransferListener.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
public void transferProgress(TransferEvent evt) { final Resource resource = evt.getResource(); if (resource.isLocal()) { return; } final int eventType = evt.getEventType(); if (eventType == TransferEvent.TRANSFER_STARTED) { resourceOperation = createResourceOperation(resource.getName(), getRequestType(evt), loggingClass, evt.getTotalLength()); } if (eventType == TransferEvent.TRANSFER_PROGRESS) { resourceOperation.logProcessedBytes(evt.getLength()); } if (eventType == TransferEvent.TRANSFER_COMPLETED) { resourceOperation.completed(); } }
Example #7
Source File: BasicResolver.java From ant-ivy with Apache License 2.0 | 6 votes |
protected ResourceMDParser getRMDParser(final DependencyDescriptor dd, final ResolveData data) { return new ResourceMDParser() { public MDResolvedResource parse(Resource resource, String rev) { try { ResolvedModuleRevision rmr = BasicResolver.this.parse(new ResolvedResource( resource, rev), dd, data); if (rmr != null) { return new MDResolvedResource(resource, rev, rmr); } } catch (ParseException e) { Message.warn("Failed to parse the file '" + resource + "'", e); } return null; } }; }
Example #8
Source File: ChainedRepository.java From ant-ivy with Apache License 2.0 | 6 votes |
public Resource getResource(String source) throws IOException { for (Repository repository : repositories) { logTry(repository); try { Resource r = repository.getResource(source); if (r != null && r.exists()) { logSuccess(repository); return r; } } catch (Exception e) { logFailed(repository, e); } } // resource that basically doesn't exists return new BasicResource(source, false, 0, 0, true); }
Example #9
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 #10
Source File: AbstractRepositoryCacheManager.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
protected ModuleDescriptor parseModuleDescriptor(DependencyResolver resolver, Artifact moduleArtifact, CacheMetadataOptions options, File artifactFile, Resource resource) throws ParseException { ModuleRevisionId moduleRevisionId = moduleArtifact.getId().getModuleRevisionId(); try { IvySettings ivySettings = IvyContextualiser.getIvyContext().getSettings(); ParserSettings parserSettings = new LegacyResolverParserSettings(ivySettings, resolver, moduleRevisionId); ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(resource); return parser.parseDescriptor(parserSettings, new URL(artifactFile.toURI().toASCIIString()), resource, options.isValidate()); } catch (IOException e) { throw UncheckedException.throwAsUncheckedException(e); } }
Example #11
Source File: OSGiManifestParserTest.java From ant-ivy with Apache License 2.0 | 5 votes |
/** * Tests that the * {@link OSGiManifestParser#parseDescriptor(ParserSettings, URL, Resource, boolean)} * works fine for descriptors that are backed by {@link FileResource} * * @throws Exception if something goes wrong */ @Test public void testFileResource() throws Exception { final File manifestFile = new File("test/repositories/osgi/module1/META-INF/MANIFEST.MF"); assertTrue("Manifest file is either missing or not a file at " + manifestFile.getAbsolutePath(), manifestFile.isFile()); final Resource manifestFileResource = new FileResource(null, manifestFile); final ModuleDescriptor md = OSGiManifestParser.getInstance().parseDescriptor(settings, manifestFile.toURI().toURL(), manifestFileResource, true); assertNotNull("Module descriptor created through a OSGi parser was null", md); assertEquals("Unexpected organization name in module descriptor created through a OSGi parser", "bundle", md.getModuleRevisionId().getOrganisation()); assertEquals("Unexpected module name in module descriptor created through a OSGi parser", "module1", md.getModuleRevisionId().getName()); assertEquals("Unexpected version in module descriptor created through a OSGi parser", "1.2.3", md.getModuleRevisionId().getRevision()); }
Example #12
Source File: RepositoryManifestIterable.java From ant-ivy with Apache License 2.0 | 5 votes |
protected URI buildBundleURI(String location) throws IOException { Resource resource = repo.getResource(location); // We have a resource to transform into an URI, let's use some heuristics try { return new URI(resource.getName()); } catch (URISyntaxException e) { return new File(resource.getName()).toURI(); } }
Example #13
Source File: AbstractOSGiResolver.java From ant-ivy with Apache License 2.0 | 5 votes |
@Override public ResolvedResource findArtifactRef(Artifact artifact, Date date) { URL url = artifact.getUrl(); if (url == null) { // not an artifact resolved by this resolver return null; } Message.verbose("\tusing url for " + artifact + ": " + url); logArtifactAttempt(artifact, url.toExternalForm()); final Resource resource = new URLResource(url, this.getTimeoutConstraint()); return new ResolvedResource(resource, artifact.getModuleRevisionId().getRevision()); }
Example #14
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 #15
Source File: DefaultRepositoryCacheManager.java From ant-ivy with Apache License 2.0 | 5 votes |
public void download(Artifact artifact, Resource resource, File dest) throws IOException { // keep a copy of the original file if (dest.exists()) { originalPath = dest.getAbsolutePath(); backup = new File(dest.getAbsolutePath() + ".backup"); FileUtil.copy(dest, backup, null, true); } delegate.download(artifact, resource, dest); }
Example #16
Source File: PomModuleDescriptorBuilder.java From ant-ivy with Apache License 2.0 | 5 votes |
public PomModuleDescriptorBuilder(ModuleDescriptorParser parser, Resource res, ParserSettings ivySettings) { ivyModuleDescriptor = new PomModuleDescriptor(parser, res); ivyModuleDescriptor.setResolvedPublicationDate(new Date(res.getLastModified())); for (Configuration m2conf : MAVEN2_CONFIGURATIONS) { ivyModuleDescriptor.addConfiguration(m2conf); } ivyModuleDescriptor.setMappingOverride(true); ivyModuleDescriptor.addExtraAttributeNamespace("m", IVY_XML_MAVEN_NAMESPACE_URI); parserSettings = ivySettings; }
Example #17
Source File: PomModuleDescriptorParser.java From ant-ivy with Apache License 2.0 | 5 votes |
public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md) throws ParseException, IOException { try { XmlModuleDescriptorWriter.write(md, destFile); } finally { if (is != null) { is.close(); } } }
Example #18
Source File: XmlModuleDescriptorParser.java From ant-ivy with Apache License 2.0 | 5 votes |
/** Used for test purpose */ ModuleDescriptor parseDescriptor(ParserSettings ivySettings, InputStream descriptor, Resource res, boolean validate) throws ParseException { Parser parser = newParser(ivySettings); parser.setValidate(validate); parser.setResource(res); parser.setInput(descriptor); parser.parse(); return parser.getModuleDescriptor(); }
Example #19
Source File: JarResolver.java From ant-ivy with Apache License 2.0 | 5 votes |
@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 #20
Source File: RepositoryResolver.java From ant-ivy with Apache License 2.0 | 5 votes |
@Override protected boolean exist(String path) { try { Resource resource = repository.getResource(path); return resource.exists(); } catch (IOException e) { Message.debug(e); return false; } }
Example #21
Source File: ModuleDescriptorParserRegistry.java From ant-ivy with Apache License 2.0 | 5 votes |
public ModuleDescriptor parseDescriptor(ParserSettings settings, URL descriptorURL, Resource res, boolean validate) throws ParseException, IOException { ModuleDescriptorParser parser = getParser(res); if (parser == null) { Message.warn("no module descriptor parser found for " + res); return null; } return parser.parseDescriptor(settings, descriptorURL, res, validate); }
Example #22
Source File: ModuleDescriptorParserRegistry.java From ant-ivy with Apache License 2.0 | 5 votes |
public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md) throws ParseException, IOException { ModuleDescriptorParser parser = getParser(res); if (parser == null) { Message.warn("no module descriptor parser found for " + res); } else { parser.toIvyFile(is, res, destFile, md); } }
Example #23
Source File: BasicResolver.java From ant-ivy with Apache License 2.0 | 5 votes |
/** * Checks the given resource checksum if a checksum resource exists. * * @param resource * the resource to check * @param dest * the file where the resource has been downloaded * @param algorithm * the checksum algorithm to use * @return true if the checksum has been successfully checked, false if the checksum wasn't * available * @throws IOException * if a checksum exist but do not match the downloaded file checksum */ private boolean check(Resource resource, File dest, String algorithm) throws IOException { if (!ChecksumHelper.isKnownAlgorithm(algorithm)) { throw new IllegalArgumentException("Unknown checksum algorithm: " + algorithm); } Resource csRes = resource.clone(resource.getName() + "." + algorithm); if (csRes.exists()) { Message.debug(algorithm + " file found for " + resource + ": checking..."); File csFile = File.createTempFile("ivytmp", algorithm); try { get(csRes, csFile); try { ChecksumHelper.check(dest, csFile, algorithm); Message.verbose(algorithm + " OK for " + resource); return true; } catch (IOException ex) { dest.delete(); throw ex; } } finally { csFile.delete(); } } else { return false; } }
Example #24
Source File: SFTPResource.java From ant-ivy with Apache License 2.0 | 5 votes |
private void init() { if (!init) { Resource r = repository.resolveResource(path); contentLength = r.getContentLength(); lastModified = r.getLastModified(); exists = r.exists(); init = true; } }
Example #25
Source File: VsftpRepository.java From ant-ivy with Apache License 2.0 | 5 votes |
protected Resource getInitResource(String source) throws IOException { try { return lslToResource(source, sendCommand("ls -l " + source, true, true)); } catch (IOException ex) { cleanup(ex); throw ex; } finally { cleanup(); } }
Example #26
Source File: BasicResolver.java From ant-ivy with Apache License 2.0 | 5 votes |
protected long getAndCheck(Resource resource, File dest) throws IOException { long size = get(resource, dest); for (String checksum : getChecksumAlgorithms()) { if (check(resource, dest, checksum)) { break; } } return size; }
Example #27
Source File: VsftpResource.java From ant-ivy with Apache License 2.0 | 5 votes |
public Resource clone(String cloneName) { try { return repository.getResource(cloneName); } catch (IOException e) { throw new RuntimeException(e); } }
Example #28
Source File: URLRepository.java From ant-ivy with Apache License 2.0 | 5 votes |
public Resource getResource(String source) throws IOException { Resource res = resourcesCache.get(source); if (res == null) { res = new URLResource(new URL(source), this.getTimeoutConstraint()); resourcesCache.put(source, res); } return res; }
Example #29
Source File: BasicResolver.java From ant-ivy with Apache License 2.0 | 5 votes |
protected ResourceMDParser getDefaultRMDParser(final ModuleId mid) { return new ResourceMDParser() { public MDResolvedResource parse(Resource resource, String rev) { DefaultModuleDescriptor md = DefaultModuleDescriptor .newDefaultInstance(new ModuleRevisionId(mid, rev)); MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport( md.getMetadataArtifact()); madr.setDownloadStatus(DownloadStatus.NO); madr.setSearched(true); return new MDResolvedResource(resource, rev, new ResolvedModuleRevision( BasicResolver.this, BasicResolver.this, md, madr, isForce())); } }; }
Example #30
Source File: URLResource.java From ant-ivy with Apache License 2.0 | 5 votes |
public Resource clone(String cloneName) { try { return new URLResource(new URL(cloneName)); } catch (MalformedURLException e) { throw new IllegalArgumentException( "bad clone name provided: not suitable for an URLResource: " + cloneName); } }