Search in sources :

Example 6 with XPath

use of org.jdom.xpath.XPath in project intellij-community by JetBrains.

the class GuiTestBase method cleanUpProjectForImport.

protected void cleanUpProjectForImport(@NotNull File projectPath) {
    File dotIdeaFolderPath = new File(projectPath, Project.DIRECTORY_STORE_FOLDER);
    if (dotIdeaFolderPath.isDirectory()) {
        File modulesXmlFilePath = new File(dotIdeaFolderPath, "modules.xml");
        if (modulesXmlFilePath.isFile()) {
            SAXBuilder saxBuilder = new SAXBuilder();
            try {
                Document document = saxBuilder.build(modulesXmlFilePath);
                XPath xpath = XPath.newInstance("//*[@fileurl]");
                //noinspection unchecked
                List<Element> modules = xpath.selectNodes(document);
                int urlPrefixSize = "file://$PROJECT_DIR$/".length();
                for (Element module : modules) {
                    String fileUrl = module.getAttributeValue("fileurl");
                    if (!StringUtil.isEmpty(fileUrl)) {
                        String relativePath = toSystemDependentName(fileUrl.substring(urlPrefixSize));
                        File imlFilePath = new File(projectPath, relativePath);
                        if (imlFilePath.isFile()) {
                            delete(imlFilePath);
                        }
                        // It is likely that each module has a "build" folder. Delete it as well.
                        File buildFilePath = new File(imlFilePath.getParentFile(), "build");
                        if (buildFilePath.isDirectory()) {
                            delete(buildFilePath);
                        }
                    }
                }
            } catch (Throwable ignored) {
            // if something goes wrong, just ignore. Most likely it won't affect project import in any way.
            }
        }
        delete(dotIdeaFolderPath);
    }
}
Also used : XPath(org.jdom.xpath.XPath) SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) Document(org.jdom.Document) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) File(java.io.File)

Example 7 with XPath

use of org.jdom.xpath.XPath in project android by JetBrains.

the class GuiTestRule method cleanUpProjectForImport.

public void cleanUpProjectForImport(@NotNull File projectPath) {
    File dotIdeaFolderPath = new File(projectPath, Project.DIRECTORY_STORE_FOLDER);
    if (dotIdeaFolderPath.isDirectory()) {
        File modulesXmlFilePath = new File(dotIdeaFolderPath, "modules.xml");
        if (modulesXmlFilePath.isFile()) {
            SAXBuilder saxBuilder = new SAXBuilder();
            try {
                Document document = saxBuilder.build(modulesXmlFilePath);
                XPath xpath = XPath.newInstance("//*[@fileurl]");
                //noinspection unchecked
                List<Element> modules = xpath.selectNodes(document);
                int urlPrefixSize = "file://$PROJECT_DIR$/".length();
                for (Element module : modules) {
                    String fileUrl = module.getAttributeValue("fileurl");
                    if (!StringUtil.isEmpty(fileUrl)) {
                        String relativePath = FileUtil.toSystemDependentName(fileUrl.substring(urlPrefixSize));
                        File imlFilePath = new File(projectPath, relativePath);
                        if (imlFilePath.isFile()) {
                            FileUtilRt.delete(imlFilePath);
                        }
                        // It is likely that each module has a "build" folder. Delete it as well.
                        File buildFilePath = new File(imlFilePath.getParentFile(), "build");
                        if (buildFilePath.isDirectory()) {
                            FileUtilRt.delete(buildFilePath);
                        }
                    }
                }
            } catch (Throwable ignored) {
            // if something goes wrong, just ignore. Most likely it won't affect project import in any way.
            }
        }
        FileUtilRt.delete(dotIdeaFolderPath);
    }
}
Also used : XPath(org.jdom.xpath.XPath) SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) Document(org.jdom.Document) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 8 with XPath

use of org.jdom.xpath.XPath in project intellij-community by JetBrains.

the class XPathResponseHandler method selectString.

@Nullable
@Override
protected String selectString(@NotNull Selector selector, @NotNull Object context) throws Exception {
    if (StringUtil.isEmpty(selector.getPath())) {
        return null;
    }
    XPath xPath = lazyCompile(selector.getPath());
    String s = xPath.valueOf(context);
    if (s == null) {
        throw new Exception(String.format("XPath expression '%s' doesn't match", xPath.getXPath()));
    }
    return s;
}
Also used : XPath(org.jdom.xpath.XPath) JDOMException(org.jdom.JDOMException) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with XPath

use of org.jdom.xpath.XPath in project maven-plugins by apache.

the class ComponentsXmlArchiverFileFilterTest method testAddToArchive_ShouldWriteComponentWithoutHintToFile.

public void testAddToArchive_ShouldWriteComponentWithoutHintToFile() throws IOException, ArchiverException, JDOMException {
    final Xpp3Dom dom = createComponentDom(new ComponentDef("role", null, "impl"));
    filter.components = new LinkedHashMap<String, Xpp3Dom>();
    filter.components.put("role", dom);
    final FileCatchingArchiver fca = new FileCatchingArchiver();
    filter.finalizeArchiveCreation(fca);
    assertEquals(ComponentsXmlArchiverFileFilter.COMPONENTS_XML_PATH, fca.getDestFileName());
    final SAXBuilder builder = new SAXBuilder(false);
    final Document doc = builder.build(fca.getFile());
    final XPath role = XPath.newInstance("//component[position()=1]/role/text()");
    final XPath hint = XPath.newInstance("//component[position()=1]/role-hint/text()");
    final XPath implementation = XPath.newInstance("//component[position()=1]/implementation/text()");
    assertEquals("role", ((Text) role.selectSingleNode(doc)).getText());
    assertNull(hint.selectSingleNode(doc));
    assertEquals("impl", ((Text) implementation.selectSingleNode(doc)).getText());
}
Also used : XPath(org.jdom.xpath.XPath) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) SAXBuilder(org.jdom.input.SAXBuilder) Document(org.jdom.Document)

Example 10 with XPath

use of org.jdom.xpath.XPath in project maven-plugins by apache.

the class ComponentsXmlArchiverFileFilterTest method testAddToArchive_ShouldWriteTwoComponentToFile.

public void testAddToArchive_ShouldWriteTwoComponentToFile() throws IOException, ArchiverException, JDOMException {
    filter.components = new LinkedHashMap<String, Xpp3Dom>();
    final Xpp3Dom dom = createComponentDom(new ComponentDef("role", "hint", "impl"));
    filter.components.put("rolehint", dom);
    final Xpp3Dom dom2 = createComponentDom(new ComponentDef("role", "hint2", "impl"));
    filter.components.put("rolehint2", dom2);
    final FileCatchingArchiver fca = new FileCatchingArchiver();
    filter.finalizeArchiveCreation(fca);
    assertEquals(ComponentsXmlArchiverFileFilter.COMPONENTS_XML_PATH, fca.getDestFileName());
    final SAXBuilder builder = new SAXBuilder(false);
    final Document doc = builder.build(fca.getFile());
    final XPath role = XPath.newInstance("//component[position()=1]/role/text()");
    final XPath hint = XPath.newInstance("//component[position()=1]/role-hint/text()");
    final XPath implementation = XPath.newInstance("//component[position()=1]/implementation/text()");
    assertEquals("role", ((Text) role.selectSingleNode(doc)).getText());
    assertEquals("hint", ((Text) hint.selectSingleNode(doc)).getText());
    assertEquals("impl", ((Text) implementation.selectSingleNode(doc)).getText());
    final XPath role2 = XPath.newInstance("//component[position()=2]/role/text()");
    final XPath hint2 = XPath.newInstance("//component[position()=2]/role-hint/text()");
    final XPath implementation2 = XPath.newInstance("//component[position()=2]/implementation/text()");
    assertEquals("role", ((Text) role2.selectSingleNode(doc)).getText());
    assertEquals("hint2", ((Text) hint2.selectSingleNode(doc)).getText());
    assertEquals("impl", ((Text) implementation2.selectSingleNode(doc)).getText());
}
Also used : XPath(org.jdom.xpath.XPath) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) SAXBuilder(org.jdom.input.SAXBuilder) Document(org.jdom.Document)

Aggregations

XPath (org.jdom.xpath.XPath)12 Document (org.jdom.Document)10 SAXBuilder (org.jdom.input.SAXBuilder)9 Element (org.jdom.Element)6 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)4 JDOMException (org.jdom.JDOMException)4 File (java.io.File)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 IOException (java.io.IOException)2 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)2 Logger (com.intellij.openapi.diagnostic.Logger)1 Comparing (com.intellij.openapi.util.Comparing)1 PasswordUtil (com.intellij.openapi.util.PasswordUtil)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 VfsUtil.findFileByIoFile (com.intellij.openapi.vfs.VfsUtil.findFileByIoFile)1 LightElement (com.intellij.psi.impl.light.LightElement)1 com.intellij.tasks (com.intellij.tasks)1 BaseRepository (com.intellij.tasks.impl.BaseRepository)1