Search in sources :

Example 6 with Document

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

the class Feature method write.

public static void write(Feature feature, File file, String indent) throws IOException {
    OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
    Document document = feature.document;
    try {
        String enc = document.getEncoding() != null ? document.getEncoding() : "UTF-8";
        Writer w = new OutputStreamWriter(os, enc);
        XMLWriter xw = new XMLWriter(w);
        xw.setIndent(indent);
        try {
            document.toXML(xw);
        } finally {
            xw.flush();
        }
    } finally {
        IOUtil.close(os);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Document(de.pdark.decentxml.Document) BufferedOutputStream(java.io.BufferedOutputStream) XMLWriter(de.pdark.decentxml.XMLWriter) Writer(java.io.Writer) XMLWriter(de.pdark.decentxml.XMLWriter) OutputStreamWriter(java.io.OutputStreamWriter)

Example 7 with Document

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

the class IU method write.

public static void write(IU iu, File file, String indent) throws IOException {
    OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
    Document document = iu.document;
    try {
        String enc = document.getEncoding() != null ? document.getEncoding() : "UTF-8";
        Writer w = new OutputStreamWriter(os, enc);
        XMLWriter xw = new XMLWriter(w);
        xw.setIndent(indent);
        try {
            document.toXML(xw);
        } finally {
            xw.flush();
        }
    } finally {
        IOUtil.close(os);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Document(de.pdark.decentxml.Document) BufferedOutputStream(java.io.BufferedOutputStream) XMLWriter(de.pdark.decentxml.XMLWriter) Writer(java.io.Writer) XMLWriter(de.pdark.decentxml.XMLWriter) OutputStreamWriter(java.io.OutputStreamWriter)

Example 8 with Document

use of de.pdark.decentxml.Document 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 9 with Document

use of de.pdark.decentxml.Document 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 10 with Document

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

the class TargetDefinitionFile method write.

public static void write(TargetDefinitionFile target, File file) throws IOException {
    OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
    Document document = target.document;
    try {
        String enc = document.getEncoding() != null ? document.getEncoding() : "UTF-8";
        Writer w = new OutputStreamWriter(os, enc);
        XMLWriter xw = new XMLWriter(w);
        try {
            document.toXML(xw);
        } finally {
            xw.flush();
        }
    } finally {
        IOUtil.close(os);
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Document(de.pdark.decentxml.Document) BufferedOutputStream(java.io.BufferedOutputStream) XMLWriter(de.pdark.decentxml.XMLWriter) XMLWriter(de.pdark.decentxml.XMLWriter) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Aggregations

Document (de.pdark.decentxml.Document)15 Element (de.pdark.decentxml.Element)6 XMLWriter (de.pdark.decentxml.XMLWriter)6 BufferedOutputStream (java.io.BufferedOutputStream)6 FileOutputStream (java.io.FileOutputStream)6 OutputStream (java.io.OutputStream)6 OutputStreamWriter (java.io.OutputStreamWriter)6 Writer (java.io.Writer)6 XMLIOSource (de.pdark.decentxml.XMLIOSource)4 File (java.io.File)4 IOException (java.io.IOException)3 Verifier (org.apache.maven.it.Verifier)3 AbstractTychoIntegrationTest (org.eclipse.tycho.test.AbstractTychoIntegrationTest)3 Test (org.junit.Test)3 XMLParser (de.pdark.decentxml.XMLParser)2 ZipFile (java.util.zip.ZipFile)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Attribute (de.pdark.decentxml.Attribute)1 Node (de.pdark.decentxml.Node)1 XMLParseException (de.pdark.decentxml.XMLParseException)1