use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class VersionCalculator method getMetadataVersions.
/**
* Accumulate all available versions for a given GAV from all available repositories.
* @param groupId the groupId to search for
* @param artifactId the artifactId to search for
* @return Collection of versions for the specified group:artifact
* @throws ManipulationException if an error occurs.
*/
private Set<String> getMetadataVersions(final String groupId, final String artifactId) throws ManipulationException {
logger.debug("Reading available versions from repository metadata for: " + groupId + ":" + artifactId);
try {
final MavenMetadataView metadataView = readerWrapper.readMetadataView(new SimpleProjectRef(groupId, artifactId));
final List<String> versions = metadataView.resolveXPathToAggregatedStringList("/metadata/versioning/versions/version", true, -1);
return new HashSet<>(versions);
} catch (final GalleyMavenException e) {
throw new ManipulationException("Failed to resolve metadata for: %s:%s.", e, groupId, artifactId);
}
}
use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class XMLManipulator method internalApplyChanges.
void internalApplyChanges(Project project, XMLState.XMLOperation operation) throws ManipulationException {
File target = new File(project.getPom().getParentFile(), operation.getFile());
logger.info("Attempting to start XML update to file {} with xpath {} and replacement {}", target, operation.getXPath(), operation.getUpdate());
Document doc = xmlIO.parseXML(target);
try {
NodeList nodeList = (NodeList) xPath.evaluate(operation.getXPath(), doc, XPathConstants.NODESET);
if (nodeList.getLength() == 0) {
if (project.isIncrementalPME()) {
logger.warn("Did not locate XML using XPath " + operation.getXPath());
return;
} else {
logger.error("XPath {} did not find any expressions within {} ", operation.getXPath(), operation.getFile());
throw new ManipulationException("Did not locate XML using XPath " + operation.getXPath());
}
}
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (isEmpty(operation.getUpdate())) {
// Delete
node.getParentNode().removeChild(node);
} else {
// Update
node.setTextContent(operation.getUpdate());
}
}
xmlIO.writeXML(target, doc);
} catch (XPathExpressionException e) {
logger.error("Caught XML exception processing file {}, document context {} ", target, doc, e);
throw new ManipulationException("Caught XML exception processing file", e);
}
}
Aggregations