Java Code Examples for org.apache.ivy.plugins.repository.Resource#exists()
The following examples show how to use
org.apache.ivy.plugins.repository.Resource#exists() .
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: 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 2
Source File: IvyPublisherForMaven.java From jeka with Apache License 2.0 | 5 votes |
private boolean existOnRepo(String dest) { try { final String path = completePath(dest); final Resource resource = resolver.getRepository().getResource(path); return resource.exists(); } catch (final IOException e) { throw new RuntimeException(e); } }
Example 3
Source File: IvyPublisherForMaven.java From jeka with Apache License 2.0 | 5 votes |
private JkMavenMetadata loadMavenMedatata(String path) { try { final Resource resource = resolver.getRepository().getResource(completePath(path)); if (resource.exists()) { final InputStream inputStream = resource.openStream(); final JkMavenMetadata mavenMetadata = JkMavenMetadata.of(inputStream); inputStream.close(); return mavenMetadata; } return null; } catch (final IOException e) { throw new RuntimeException(e); } }
Example 4
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 5
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 6
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 7
Source File: IBiblioResolver.java From ant-ivy with Apache License 2.0 | 4 votes |
private String findTimestampedSnapshotVersion(final ModuleRevisionId mrid) { if (!isM2compatible()) { return null; } if (!shouldUseMavenMetadata(getWholePattern())) { return null; } try { final String metadataLocation = IvyPatternHelper.substitute(root + "[organisation]/[module]/[revision]/maven-metadata.xml", mrid); final Resource metadata = getRepository().getResource(metadataLocation); if (!metadata.exists()) { Message.verbose("\tmaven-metadata not available for: " + mrid); return null; } try (final InputStream metadataStream = metadata.openStream()) { final StringBuilder timestamp = new StringBuilder(); final StringBuilder buildNumber = new StringBuilder(); XMLHelper.parse(metadataStream, null, new ContextualSAXHandler() { @Override public void endElement(String uri, String localName, String qName) throws SAXException { if ("metadata/versioning/snapshot/timestamp".equals(getContext())) { timestamp.append(getText()); } if ("metadata/versioning/snapshot/buildNumber".equals(getContext())) { buildNumber.append(getText()); } super.endElement(uri, localName, qName); } }, null); if (timestamp.length() > 0) { // we have found a timestamp, so this is a snapshot unique version String rev = mrid.getRevision(); rev = rev.substring(0, rev.length() - "SNAPSHOT".length()); rev += timestamp.toString() + "-" + buildNumber.toString(); return rev; } } } catch (IOException | SAXException | ParserConfigurationException e) { Message.debug("impossible to access maven metadata file, ignored", e); } return null; }
Example 8
Source File: RepositoryResolver.java From ant-ivy with Apache License 2.0 | 4 votes |
@Override protected ResolvedResource findResourceUsingPattern(ModuleRevisionId mrid, String pattern, Artifact artifact, ResourceMDParser rmdparser, Date date) { String name = getName(); VersionMatcher versionMatcher = getSettings().getVersionMatcher(); try { if (!versionMatcher.isDynamic(mrid) || isAlwaysCheckExactRevision()) { String resourceName = IvyPatternHelper.substitute(pattern, mrid, artifact); Message.debug("\t trying " + resourceName); logAttempt(resourceName); Resource res = repository.getResource(resourceName); boolean reachable = res.exists(); if (reachable) { String revision; if (pattern.contains(IvyPatternHelper.REVISION_KEY)) { revision = mrid.getRevision(); } else { if ("ivy".equals(artifact.getType()) || "pom".equals(artifact.getType())) { // we can't determine the revision from the pattern, get it // from the module descriptor itself File temp = File.createTempFile("ivy", artifact.getExt()); temp.deleteOnExit(); repository.get(res.getName(), temp); ModuleDescriptorParser parser = ModuleDescriptorParserRegistry .getInstance().getParser(res); ModuleDescriptor md = parser.parseDescriptor(getParserSettings(), temp .toURI().toURL(), res, false); revision = md.getRevision(); if (isNullOrEmpty(revision)) { revision = "working@" + name; } } else { revision = "working@" + name; } } return new ResolvedResource(res, revision); } else if (versionMatcher.isDynamic(mrid)) { return findDynamicResourceUsingPattern(rmdparser, mrid, pattern, artifact, date); } else { Message.debug("\t" + name + ": resource not reachable for " + mrid + ": res=" + res); return null; } } else { return findDynamicResourceUsingPattern(rmdparser, mrid, pattern, artifact, date); } } catch (IOException | ParseException ex) { throw new RuntimeException(name + ": unable to get resource for " + mrid + ": res=" + IvyPatternHelper.substitute(pattern, mrid, artifact) + ": " + ex, ex); } }
Example 9
Source File: YamlParser.java From restcommander with Apache License 2.0 | 4 votes |
public boolean accept(Resource rsrc) { return rsrc.exists() && rsrc.getName().endsWith(".yml"); }