Search in sources :

Example 66 with XPathExpression

use of javax.xml.xpath.XPathExpression in project buck by facebook.

the class SchemeGeneratorTest method enablingParallelizeBuild.

@Test
public void enablingParallelizeBuild() throws Exception {
    ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder = ImmutableMap.builder();
    PBXTarget rootTarget = new PBXNativeTarget("rootRule");
    rootTarget.setGlobalID("rootGID");
    rootTarget.setProductReference(new PBXFileReference("root.a", "root.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
    rootTarget.setProductType(ProductType.STATIC_LIBRARY);
    Path pbxprojectPath = Paths.get("foo/Foo.xcodeproj/project.pbxproj");
    targetToProjectPathMapBuilder.put(rootTarget, pbxprojectPath);
    SchemeGenerator schemeGenerator = new SchemeGenerator(projectFilesystem, Optional.of(rootTarget), ImmutableSet.of(rootTarget), ImmutableSet.of(), ImmutableSet.of(), "TestScheme", Paths.get("_gen/Foo.xcworkspace/scshareddata/xcshemes"), true, /* primaryTargetIsBuildWithBuck */
    true, /* parallelizeBuild */
    Optional.empty(), /* runnablePath */
    Optional.empty(), /* remoteRunnablePath */
    SchemeActionType.DEFAULT_CONFIG_NAMES, targetToProjectPathMapBuilder.build(), XCScheme.LaunchAction.LaunchStyle.AUTO);
    Path schemePath = schemeGenerator.writeScheme();
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document scheme = dBuilder.parse(projectFilesystem.newFileInputStream(schemePath));
    XPathFactory xpathFactory = XPathFactory.newInstance();
    XPath buildActionXpath = xpathFactory.newXPath();
    XPathExpression buildActionExpr = buildActionXpath.compile("//BuildAction");
    NodeList buildActionNodes = (NodeList) buildActionExpr.evaluate(scheme, XPathConstants.NODESET);
    assertThat(buildActionNodes.getLength(), is(1));
    Node buildActionNode = buildActionNodes.item(0);
    assertThat(buildActionNode.getAttributes().getNamedItem("buildImplicitDependencies").getNodeValue(), equalTo("YES"));
    assertThat(buildActionNode.getAttributes().getNamedItem("parallelizeBuildables").getNodeValue(), equalTo("YES"));
}
Also used : PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) XPath(javax.xml.xpath.XPath) Path(java.nio.file.Path) XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) PBXNativeTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) ImmutableMap(com.google.common.collect.ImmutableMap) XPathFactory(javax.xml.xpath.XPathFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) Test(org.junit.Test)

Example 67 with XPathExpression

use of javax.xml.xpath.XPathExpression in project buck by facebook.

the class SchemeGeneratorTest method allActionsShouldBePresentInSchemeWithDefaultBuildConfigurations.

@Test
public void allActionsShouldBePresentInSchemeWithDefaultBuildConfigurations() throws Exception {
    ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder = ImmutableMap.builder();
    PBXTarget rootTarget = new PBXNativeTarget("rootRule");
    rootTarget.setGlobalID("rootGID");
    rootTarget.setProductReference(new PBXFileReference("root.a", "root.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
    rootTarget.setProductType(ProductType.STATIC_LIBRARY);
    Path pbxprojectPath = Paths.get("foo/Foo.xcodeproj/project.pbxproj");
    targetToProjectPathMapBuilder.put(rootTarget, pbxprojectPath);
    SchemeGenerator schemeGenerator = new SchemeGenerator(projectFilesystem, Optional.of(rootTarget), ImmutableSet.of(rootTarget), ImmutableSet.of(), ImmutableSet.of(), "TestScheme", Paths.get("_gen/Foo.xcworkspace/scshareddata/xcshemes"), false, /* primaryTargetIsBuildWithBuck */
    false, /* parallelizeBuild */
    Optional.empty(), /* runnablePath */
    Optional.empty(), /* remoteRunnablePath */
    SchemeActionType.DEFAULT_CONFIG_NAMES, targetToProjectPathMapBuilder.build(), XCScheme.LaunchAction.LaunchStyle.AUTO);
    Path schemePath = schemeGenerator.writeScheme();
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document scheme = dBuilder.parse(projectFilesystem.newFileInputStream(schemePath));
    XPathFactory xpathFactory = XPathFactory.newInstance();
    XPath schemeChildrenXPath = xpathFactory.newXPath();
    XPathExpression schemeChildrenExpr = schemeChildrenXPath.compile("/Scheme/node()");
    NodeList actions = (NodeList) schemeChildrenExpr.evaluate(scheme, XPathConstants.NODESET);
    assertThat(actions.getLength(), equalTo(6));
    Node buildAction = actions.item(0);
    assertThat(buildAction.getNodeName(), equalTo("BuildAction"));
    assertThat(buildAction.getAttributes().getNamedItem("buildConfiguration"), nullValue());
    Node testAction = actions.item(1);
    assertThat(testAction.getNodeName(), equalTo("TestAction"));
    assertThat(testAction.getAttributes().getNamedItem("buildConfiguration").getNodeValue(), equalTo("Debug"));
    Node launchAction = actions.item(2);
    assertThat(launchAction.getNodeName(), equalTo("LaunchAction"));
    assertThat(launchAction.getAttributes().getNamedItem("buildConfiguration").getNodeValue(), equalTo("Debug"));
    Node profileAction = actions.item(3);
    assertThat(profileAction.getNodeName(), equalTo("ProfileAction"));
    assertThat(profileAction.getAttributes().getNamedItem("buildConfiguration").getNodeValue(), equalTo("Release"));
    Node analyzeAction = actions.item(4);
    assertThat(analyzeAction.getNodeName(), equalTo("AnalyzeAction"));
    assertThat(analyzeAction.getAttributes().getNamedItem("buildConfiguration").getNodeValue(), equalTo("Debug"));
    Node archiveAction = actions.item(5);
    assertThat(archiveAction.getNodeName(), equalTo("ArchiveAction"));
    assertThat(archiveAction.getAttributes().getNamedItem("buildConfiguration").getNodeValue(), equalTo("Release"));
}
Also used : PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) XPath(javax.xml.xpath.XPath) Path(java.nio.file.Path) XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) PBXNativeTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) ImmutableMap(com.google.common.collect.ImmutableMap) XPathFactory(javax.xml.xpath.XPathFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) Test(org.junit.Test)

Example 68 with XPathExpression

use of javax.xml.xpath.XPathExpression in project android-selector-intellij-plugin by importre.

the class AndroidSelectorDialog method getColorNodes.

private NodeList getColorNodes(InputStream stream) throws Exception {
    XPath xPath = XPathFactory.newInstance().newXPath();
    String expression = "//item[@type=\"color\"]|//color";
    XPathExpression compile = xPath.compile(expression);
    DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = f.newDocumentBuilder();
    Document doc = builder.parse(stream);
    return (NodeList) compile.evaluate(doc, XPathConstants.NODESET);
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document)

Example 69 with XPathExpression

use of javax.xml.xpath.XPathExpression in project openhab1-addons by openhab.

the class XMLUtil method XPathValueFromString.

/**
     * Returns the xml value.
     * 
     * @param sIn
     * @param sxpath
     * @return
     * @throws ParserConfigurationException
     * @throws IOException
     * @throws SAXException
     * @throws XPathExpressionException
     */
public static String XPathValueFromString(String sIn, String sxpath) throws ParserConfigurationException, IOException, SAXException, XPathExpressionException {
    // DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    Document doc = loadXMLFromString(sIn);
    XPath xPath = XPathFactory.newInstance().newXPath();
    // XPath Query for showing all nodes value
    XPathExpression expr = xPath.compile(sxpath);
    Object result = expr.evaluate(doc, XPathConstants.NODESET);
    NodeList nodes = (NodeList) result;
    String sReturn = "";
    for (int i = 0; i < nodes.getLength(); i++) {
        sReturn = nodes.item(i).getNodeValue();
    }
    return sReturn;
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document)

Example 70 with XPathExpression

use of javax.xml.xpath.XPathExpression in project antlr4 by antlr.

the class BaseCSharpTest method createProject.

public boolean createProject() {
    try {
        String pack = BaseCSharpTest.class.getPackage().getName().replace(".", "/") + "/";
        // save auxiliary files
        saveResourceAsFile(pack + "AssemblyInfo.cs", new File(tmpdir, "AssemblyInfo.cs"));
        saveResourceAsFile(pack + "App.config", new File(tmpdir, "App.config"));
        // update project
        String projectName = isWindows() ? "Antlr4.Test.vs2013.csproj" : "Antlr4.Test.mono.csproj";
        final ClassLoader loader = Thread.currentThread().getContextClassLoader();
        InputStream input = loader.getResourceAsStream(pack + projectName);
        Document prjXml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(input);
        // update runtime project reference
        // find project file as a resource not relative pathname (now that we've merged repos)
        String runtimeName = isWindows() ? "Antlr4.Runtime.vs2013.csproj" : "Antlr4.Runtime.mono.csproj";
        final URL runtimeProj = loader.getResource("CSharp/runtime/CSharp/Antlr4.Runtime/" + runtimeName);
        if (runtimeProj == null) {
            throw new RuntimeException("C# runtime project file not found!");
        }
        String runtimeProjPath = runtimeProj.getPath();
        if (isWindows()) {
            runtimeProjPath = runtimeProjPath.replaceFirst("/", "");
        }
        XPathExpression exp = XPathFactory.newInstance().newXPath().compile("/Project/ItemGroup/ProjectReference[@Include='" + runtimeName + "']");
        Element node = (Element) exp.evaluate(prjXml, XPathConstants.NODE);
        node.setAttribute("Include", runtimeProjPath.replace("/", "\\"));
        // update project file list
        exp = XPathFactory.newInstance().newXPath().compile("/Project/ItemGroup[Compile/@Include='AssemblyInfo.cs']");
        Element group = (Element) exp.evaluate(prjXml, XPathConstants.NODE);
        if (group == null)
            return false;
        // remove existing children
        while (group.hasChildNodes()) group.removeChild(group.getFirstChild());
        // add AssemblyInfo.cs, not a generated source
        sourceFiles.add("AssemblyInfo.cs");
        // add files to compile
        for (String file : sourceFiles) {
            Element elem = group.getOwnerDocument().createElement("Compile");
            elem.setAttribute("Include", file);
            group.appendChild(elem);
        }
        // save project
        File prjFile = getTestProjectFile();
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.transform(new DOMSource(prjXml), new StreamResult(prjFile));
        return true;
    } catch (Exception e) {
        e.printStackTrace(System.err);
        return false;
    }
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) BaseRuntimeTest.antlrOnString(org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString) Document(org.w3c.dom.Document) URL(java.net.URL) IOException(java.io.IOException) File(java.io.File) BaseRuntimeTest.writeFile(org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile)

Aggregations

XPathExpression (javax.xml.xpath.XPathExpression)98 XPath (javax.xml.xpath.XPath)69 NodeList (org.w3c.dom.NodeList)56 Document (org.w3c.dom.Document)48 XPathExpressionException (javax.xml.xpath.XPathExpressionException)40 XPathFactory (javax.xml.xpath.XPathFactory)40 Node (org.w3c.dom.Node)38 DocumentBuilder (javax.xml.parsers.DocumentBuilder)24 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)19 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 Element (org.w3c.dom.Element)12 PBXNativeTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget)11 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 IOException (java.io.IOException)11 Path (java.nio.file.Path)11 PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)10 InputSource (org.xml.sax.InputSource)9