Search in sources :

Example 1 with XMLIOSource

use of de.pdark.decentxml.XMLIOSource in project fabric8 by jboss-fuse.

the class RouteXml method createExemplarDoc.

protected Document createExemplarDoc() throws IOException {
    String exemplar = "io/fabric8/camel/tooling/exemplar.xml";
    URL url = findResource(exemplar, null);
    if (url != null) {
        return parse(new XMLIOSource(url));
    } else {
        LOG.warn("Could not find file {} on the class path", exemplar);
        Document d = new Document();
        d.addNode(new Element("beans", springNamespace));
        return d;
    }
}
Also used : XMLIOSource(de.pdark.decentxml.XMLIOSource) Element(de.pdark.decentxml.Element) Document(de.pdark.decentxml.Document) URL(java.net.URL)

Example 2 with XMLIOSource

use of de.pdark.decentxml.XMLIOSource in project tycho by eclipse.

the class Util method openXmlFromZip.

public static Document openXmlFromZip(File zipFile, String xmlFile) throws IOException, ZipException {
    XMLParser parser = new XMLParser();
    ZipFile zip = new ZipFile(zipFile);
    try {
        ZipEntry contentXmlEntry = zip.getEntry(xmlFile);
        InputStream entryStream = zip.getInputStream(contentXmlEntry);
        return parser.parse(new XMLIOSource(entryStream));
    } finally {
        zip.close();
    }
}
Also used : ZipFile(java.util.zip.ZipFile) XMLIOSource(de.pdark.decentxml.XMLIOSource) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) XMLParser(de.pdark.decentxml.XMLParser)

Example 3 with XMLIOSource

use of de.pdark.decentxml.XMLIOSource in project tycho by eclipse.

the class RepositoryCategoriesTest method testDeployableFeature.

@Test
public void testDeployableFeature() throws Exception {
    Verifier v01 = getVerifier("TYCHO0439repositoryCategories");
    v01.executeGoal("install");
    v01.verifyErrorFreeLog();
    File site = new File(v01.getBasedir(), "target/site");
    Assert.assertTrue(site.isDirectory());
    File content = new File(site, "content.jar");
    Assert.assertTrue(content.isFile());
    boolean found = false;
    XMLParser parser = new XMLParser();
    Document document = null;
    ZipFile contentJar = new ZipFile(content);
    try {
        ZipEntry contentXmlEntry = contentJar.getEntry("content.xml");
        document = parser.parse(new XMLIOSource(contentJar.getInputStream(contentXmlEntry)));
    } finally {
        contentJar.close();
    }
    Element repository = document.getRootElement();
    all_units: for (Element unit : repository.getChild("units").getChildren("unit")) {
        for (Element property : unit.getChild("properties").getChildren("property")) {
            if ("org.eclipse.equinox.p2.type.category".equals(property.getAttributeValue("name")) && Boolean.parseBoolean(property.getAttributeValue("value"))) {
                found = true;
                break all_units;
            }
        }
    }
    Assert.assertTrue("Custom category", found);
}
Also used : ZipFile(java.util.zip.ZipFile) XMLIOSource(de.pdark.decentxml.XMLIOSource) ZipEntry(java.util.zip.ZipEntry) Element(de.pdark.decentxml.Element) Verifier(org.apache.maven.it.Verifier) XMLParser(de.pdark.decentxml.XMLParser) Document(de.pdark.decentxml.Document) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test) AbstractTychoIntegrationTest(org.eclipse.tycho.test.AbstractTychoIntegrationTest)

Example 4 with XMLIOSource

use of de.pdark.decentxml.XMLIOSource in project tycho by eclipse.

the class MultienvP2infTest method test.

@Test
public void test() throws Exception {
    Verifier verifier = getVerifier("/p2Inf.multiEnv", false);
    verifier.getCliOptions().add("-De342-repo=" + ResourceUtil.P2Repositories.ECLIPSE_342);
    verifier.executeGoals(Arrays.asList("clean", "verify"));
    verifier.verifyErrorFreeLog();
    // assert repository contains cross-platform IUs defined in p2.inf files
    Document doc;
    ZipFile zip = new ZipFile(new File(verifier.getBasedir(), "product/target/repository/content.jar"));
    try {
        InputStream is = zip.getInputStream(zip.getEntry("content.xml"));
        doc = new XMLParser().parse(new XMLIOSource(is));
    } finally {
        zip.close();
    }
    List<String> ids = new ArrayList<>();
    Element units = doc.getChild("repository/units");
    for (Element unit : units.getChildren("unit")) {
        ids.add(unit.getAttributeValue("id"));
    }
    // disabled due to a limitation of BundlesAction
    // Assert.assertTrue(ids.contains("tychotest.bundle.macosx"));
    Assert.assertTrue(ids.contains("tychotest.feature.macosx"));
    Assert.assertTrue(ids.contains("tychotest.product.macosx"));
}
Also used : ZipFile(java.util.zip.ZipFile) XMLIOSource(de.pdark.decentxml.XMLIOSource) InputStream(java.io.InputStream) Element(de.pdark.decentxml.Element) ArrayList(java.util.ArrayList) Verifier(org.apache.maven.it.Verifier) Document(de.pdark.decentxml.Document) XMLParser(de.pdark.decentxml.XMLParser) File(java.io.File) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test) AbstractTychoIntegrationTest(org.eclipse.tycho.test.AbstractTychoIntegrationTest)

Example 5 with XMLIOSource

use of de.pdark.decentxml.XMLIOSource in project tycho by eclipse.

the class IU method read.

public static IU read(File file) throws IOException {
    FileInputStream is = new FileInputStream(file);
    try {
        Document iuDocument = parser.parse(new XMLIOSource(is));
        Element root = iuDocument.getChild(UNIT);
        if (root == null)
            throw new RuntimeException("No iu found.");
        IU result = new IU(iuDocument, root);
        if (result.getId() == null)
            throw new RuntimeException(String.format("The IU defined in %s is missing an id.", file.getAbsolutePath()));
        if (result.getVersion() == null)
            throw new RuntimeException(String.format("The IU defined in %s is missing a version.", file.getAbsolutePath()));
        return result;
    } finally {
        IOUtil.close(is);
    }
}
Also used : XMLIOSource(de.pdark.decentxml.XMLIOSource) Element(de.pdark.decentxml.Element) Document(de.pdark.decentxml.Document) FileInputStream(java.io.FileInputStream)

Aggregations

XMLIOSource (de.pdark.decentxml.XMLIOSource)5 Document (de.pdark.decentxml.Document)4 Element (de.pdark.decentxml.Element)4 XMLParser (de.pdark.decentxml.XMLParser)3 ZipFile (java.util.zip.ZipFile)3 File (java.io.File)2 InputStream (java.io.InputStream)2 ZipEntry (java.util.zip.ZipEntry)2 Verifier (org.apache.maven.it.Verifier)2 AbstractTychoIntegrationTest (org.eclipse.tycho.test.AbstractTychoIntegrationTest)2 Test (org.junit.Test)2 FileInputStream (java.io.FileInputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1