use of org.apache.ivy.plugins.repository.Resource in project ant-ivy by apache.
the class BasicResolver method check.
/**
* 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;
}
}
use of org.apache.ivy.plugins.repository.Resource in project ant-ivy by apache.
the class IBiblioResolver method findTimestampedSnapshotVersion.
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;
}
use of org.apache.ivy.plugins.repository.Resource in project ant-ivy by apache.
the class IBiblioResolver method listRevisionsWithMavenMetadata.
private List<String> listRevisionsWithMavenMetadata(Repository repository, String metadataLocation) {
List<String> revs = null;
InputStream metadataStream = null;
try {
Resource metadata = repository.getResource(metadataLocation);
if (metadata.exists()) {
Message.verbose("\tlisting revisions from maven-metadata: " + metadata);
final List<String> metadataRevs = new ArrayList<>();
metadataStream = metadata.openStream();
XMLHelper.parse(metadataStream, null, new ContextualSAXHandler() {
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if ("metadata/versioning/versions/version".equals(getContext())) {
metadataRevs.add(getText().trim());
}
super.endElement(uri, localName, qName);
}
}, null);
revs = metadataRevs;
} else {
Message.verbose("\tmaven-metadata not available: " + metadata);
}
} catch (IOException e) {
Message.verbose("impossible to access maven metadata file, ignored", e);
} catch (SAXException | ParserConfigurationException e) {
Message.verbose("impossible to parse maven metadata file, ignored", e);
} finally {
if (metadataStream != null) {
try {
metadataStream.close();
} catch (IOException e) {
// ignored
}
}
}
return revs;
}
use of org.apache.ivy.plugins.repository.Resource in project ant-ivy by apache.
the class URLRepository method get.
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);
}
}
use of org.apache.ivy.plugins.repository.Resource in project ant-ivy by apache.
the class SFTPResource method init.
private void init() {
if (!init) {
Resource r = repository.resolveResource(path);
contentLength = r.getContentLength();
lastModified = r.getLastModified();
exists = r.exists();
init = true;
}
}
Aggregations