use of org.apache.ivy.util.ContextualSAXHandler 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.util.ContextualSAXHandler 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;
}
Aggregations