Search in sources :

Example 71 with XPathExpressionException

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);
    }
}
Also used : XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList)

Example 72 with XPathExpressionException

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;
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) XPathExpressionException(javax.xml.xpath.XPathExpressionException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 73 with XPathExpressionException

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);
    }
}
Also used : XPath(javax.xml.xpath.XPath) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NonNull(com.android.annotations.NonNull)

Example 74 with XPathExpressionException

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;
}
Also used : XPathExpressionException(javax.xml.xpath.XPathExpressionException) File(java.io.File) Property(com.thoughtworks.go.domain.Property) XPathExpressionException(javax.xml.xpath.XPathExpressionException)

Example 75 with XPathExpressionException

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);
        }
    }
}
Also used : XPathExpressionException(javax.xml.xpath.XPathExpressionException) File(java.io.File) Property(com.thoughtworks.go.domain.Property) XPathExpressionException(javax.xml.xpath.XPathExpressionException)

Aggregations

XPathExpressionException (javax.xml.xpath.XPathExpressionException)139 NodeList (org.w3c.dom.NodeList)65 XPath (javax.xml.xpath.XPath)64 Document (org.w3c.dom.Document)46 Node (org.w3c.dom.Node)46 IOException (java.io.IOException)42 XPathExpression (javax.xml.xpath.XPathExpression)38 SAXException (org.xml.sax.SAXException)27 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)25 XPathFactory (javax.xml.xpath.XPathFactory)23 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)18 Test (org.junit.Test)17 InputSource (org.xml.sax.InputSource)17 Element (org.w3c.dom.Element)16 Response (com.jayway.restassured.response.Response)12 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)12 DocumentBuilder (javax.xml.parsers.DocumentBuilder)12 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)12 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)11