use of javax.xml.xpath.XPathExpressionException in project buck by facebook.
the class DefaultAndroidManifestReader method getLauncherActivities.
@Override
public List<String> getLauncherActivities() {
try {
NodeList nodes;
nodes = (NodeList) launchableActivitiesExpression.evaluate(doc, XPathConstants.NODESET);
List<String> activities = Lists.newArrayList();
for (int i = 0; i < nodes.getLength(); i++) {
activities.add(nodes.item(i).getTextContent());
}
return activities;
} catch (XPathExpressionException e) {
throw new RuntimeException(e);
}
}
use of javax.xml.xpath.XPathExpressionException in project buck by facebook.
the class MiniAapt method execute.
@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
ImmutableSet.Builder<RDotTxtEntry> references = ImmutableSet.builder();
try {
collectResources(filesystem, context.getBuckEventBus());
processXmlFilesForIds(filesystem, references);
} catch (IOException | XPathExpressionException | ResourceParseException e) {
context.logError(e, "Error parsing resources to generate resource IDs for %s.", resDirectory);
return StepExecutionResult.ERROR;
}
try {
Set<RDotTxtEntry> missing = verifyReferences(filesystem, references.build());
if (!missing.isEmpty()) {
context.getBuckEventBus().post(ConsoleEvent.severe("The following resources were not found when processing %s: \n%s\n", resDirectory, Joiner.on('\n').join(missing)));
return StepExecutionResult.ERROR;
}
} catch (IOException e) {
context.logError(e, "Error verifying resources for %s.", resDirectory);
return StepExecutionResult.ERROR;
}
if (resourceUnion) {
try {
resourceUnion();
} catch (IOException e) {
context.logError(e, "Error performing resource union for %s.", resDirectory);
return StepExecutionResult.ERROR;
}
}
try (PrintWriter writer = new PrintWriter(filesystem.newFileOutputStream(pathToTextSymbolsFile))) {
Set<RDotTxtEntry> sortedResources = ImmutableSortedSet.copyOf(Ordering.natural(), resourceCollector.getResources());
for (RDotTxtEntry entry : sortedResources) {
writer.printf("%s %s %s %s\n", entry.idType, entry.type, entry.name, entry.idValue);
}
} catch (IOException e) {
context.logError(e, "Error writing file: %s", pathToTextSymbolsFile);
return StepExecutionResult.ERROR;
}
return StepExecutionResult.SUCCESS;
}
use of javax.xml.xpath.XPathExpressionException in project buck by facebook.
the class AndroidManifest method getStringValue.
@NonNull
private static String getStringValue(@NonNull IAbstractFile file, @NonNull String xPath) throws StreamException {
XPath xpath = AndroidXPathFactory.newXPath();
InputStream is = null;
try {
is = file.getContents();
return xpath.evaluate(xPath, new InputSource(is));
} catch (XPathExpressionException e) {
throw new RuntimeException("Malformed XPath expression when reading the attribute from the manifest," + "exp = " + xPath, e);
} finally {
Closeables.closeQuietly(is);
}
}
use of javax.xml.xpath.XPathExpressionException in project gocd by gocd.
the class GeneratePropertyCommandExecutor method execute.
@Override
public boolean execute(BuildCommand command, BuildSession buildSession) {
String propertyName = command.getStringArg("name");
File file = buildSession.resolveRelativeDir(command.getWorkingDirectory(), command.getStringArg("src"));
String xpath = command.getStringArg("xpath");
String indent = " ";
if (!file.exists()) {
buildSession.println(format("%sFailed to create property %s. File %s does not exist.", indent, propertyName, file.getAbsolutePath()));
return true;
}
try {
if (!XpathUtils.nodeExists(file, xpath)) {
buildSession.println(format("%sFailed to create property %s. Nothing matched xpath \"%s\" in the file: %s.", indent, propertyName, xpath, file.getAbsolutePath()));
} else {
String value = XpathUtils.evaluate(file, xpath);
buildSession.getPublisher().setProperty(new Property(propertyName, value));
buildSession.println(format("%sProperty %s = %s created." + "\n", indent, propertyName, value));
}
} catch (Exception e) {
String error = (e instanceof XPathExpressionException) ? (format("Illegal xpath: \"%s\"", xpath)) : ExceptionUtils.messageOf(e);
String message = format("%sFailed to create property %s. %s", indent, propertyName, error);
buildSession.getPublisher().reportErrorMessage(message, e);
}
return true;
}
use of javax.xml.xpath.XPathExpressionException in project gocd by gocd.
the class ArtifactPropertiesGenerator method generate.
public void generate(GoPublisher publisher, File buildWorkingDirectory) {
File file = new File(buildWorkingDirectory, getSrc());
String indent = " ";
if (!file.exists()) {
publisher.consumeLine(format("%sFailed to create property %s. File %s does not exist.", indent, getName(), file.getAbsolutePath()));
} else {
try {
if (!XpathUtils.nodeExists(file, getXpath())) {
publisher.consumeLine(format("%sFailed to create property %s. Nothing matched xpath \"%s\" in the file: %s.", indent, getName(), getXpath(), file.getAbsolutePath()));
} else {
String value = XpathUtils.evaluate(file, getXpath());
publisher.setProperty(new Property(getName(), value));
publisher.consumeLine(format("%sProperty %s = %s created." + "\n", indent, getName(), value));
}
} catch (Exception e) {
String error = (e instanceof XPathExpressionException) ? (format("Illegal xpath: \"%s\"", getXpath())) : ExceptionUtils.messageOf(e);
String message = format("%sFailed to create property %s. %s", indent, getName(), error);
publisher.reportErrorMessage(message, e);
}
}
}
Aggregations