Search in sources :

Example 1 with XmlStreamReader

use of org.codehaus.plexus.util.xml.XmlStreamReader in project tycho by eclipse.

the class EclipseInstallationLayout method getSites.

public Set<File> getSites() {
    Set<File> result = new LinkedHashSet<>();
    if (location == null) {
        return result;
    }
    if (new File(location, PLUGINS).isDirectory()) {
        result.add(location);
    }
    File platform = new File(location, "configuration/org.eclipse.update/platform.xml");
    if (platform.canRead()) {
        try {
            FileInputStream is = new FileInputStream(platform);
            try {
                XmlStreamReader reader = new XmlStreamReader(is);
                Xpp3Dom dom = Xpp3DomBuilder.build(reader);
                Xpp3Dom[] sites = dom.getChildren("site");
                for (Xpp3Dom site : sites) {
                    String enabled = site.getAttribute("enabled");
                    if (enabled == null || Boolean.parseBoolean(enabled)) {
                        File dir = parsePlatformURL(location, site.getAttribute("url"));
                        if (dir != null) {
                            result.add(dir);
                        }
                    }
                }
            } finally {
                is.close();
            }
        } catch (Exception e) {
            getLogger().warn("Exception parsing " + toString(platform), e);
        }
    }
    addLinks(result, location, new File(location, "links"));
    // deal with dropins folder
    result.add(dropinsLocation);
    File[] dropinsFiles = dropinsLocation.listFiles();
    if (dropinsFiles != null) {
        for (File dropinsFile : dropinsFiles) {
            File plugins = new File(dropinsFile, PLUGINS);
            if (plugins.isDirectory()) {
                result.add(plugins.getParentFile());
                continue;
            }
            plugins = new File(dropinsFile, "eclipse/plugins");
            if (plugins.isDirectory()) {
                result.add(plugins.getParentFile());
            }
        }
    }
    addLinks(result, location, dropinsLocation);
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) XmlStreamReader(org.codehaus.plexus.util.xml.XmlStreamReader) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 2 with XmlStreamReader

use of org.codehaus.plexus.util.xml.XmlStreamReader in project maven-plugins by apache.

the class Project001Stub method readModelFromFile.

static Model readModelFromFile(File file) throws IOException, XmlPullParserException {
    MavenXpp3Reader pomReader = new MavenXpp3Reader();
    XmlStreamReader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(file);
        final Model model = pomReader.read(reader);
        reader.close();
        reader = null;
        return model;
    } finally {
        IOUtil.close(reader);
    }
}
Also used : Model(org.apache.maven.model.Model) XmlStreamReader(org.codehaus.plexus.util.xml.XmlStreamReader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader)

Example 3 with XmlStreamReader

use of org.codehaus.plexus.util.xml.XmlStreamReader in project maven-plugins by apache.

the class BundlePackMojo method readPom.

/**
 * Read the POM file.
 *
 * @param pom The file to read
 * @return A Maven Model
 * @throws MojoExecutionException if something goes wrong when reading the file
 */
private Model readPom(File pom) throws MojoExecutionException {
    Model model;
    XmlStreamReader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(pom);
        model = new MavenXpp3Reader().read(reader);
        reader.close();
        reader = null;
    } catch (XmlPullParserException e) {
        throw new MojoExecutionException("Unable to parse POM at " + pom.getAbsolutePath() + ": " + e.getMessage(), e);
    } catch (FileNotFoundException e) {
        throw new MojoExecutionException("Unable to read POM at " + pom.getAbsolutePath() + ": " + e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to read POM at " + pom.getAbsolutePath() + ": " + e.getMessage(), e);
    } finally {
        IOUtil.close(reader);
    }
    return model;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) FileNotFoundException(java.io.FileNotFoundException) XmlStreamReader(org.codehaus.plexus.util.xml.XmlStreamReader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 4 with XmlStreamReader

use of org.codehaus.plexus.util.xml.XmlStreamReader in project tycho by eclipse.

the class GeneratePomsMojo method generateFeaturePom.

private void generateFeaturePom(Model parent, File basedir) throws MojoExecutionException {
    Model model = readPomTemplate("feature-pom.xml");
    setParentOrAddTychoExtension(basedir, model, parent);
    try {
        FileInputStream is = new FileInputStream(new File(basedir, "feature.xml"));
        try {
            XmlStreamReader reader = new XmlStreamReader(is);
            Xpp3Dom dom = Xpp3DomBuilder.build(reader);
            String groupId = this.groupId;
            if (groupId == null) {
                groupId = dom.getAttribute("id");
            }
            model.setGroupId(groupId);
            model.setArtifactId(dom.getAttribute("id"));
            model.setVersion(toMavenVersion(dom.getAttribute("version")));
        } finally {
            is.close();
        }
    } catch (XmlPullParserException e) {
        throw new MojoExecutionException("Can't create pom.xml file", e);
    } catch (IOException e) {
        throw new MojoExecutionException("Can't create pom.xml file", e);
    }
    writePom(basedir, model);
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) XmlStreamReader(org.codehaus.plexus.util.xml.XmlStreamReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 5 with XmlStreamReader

use of org.codehaus.plexus.util.xml.XmlStreamReader in project tycho by eclipse.

the class GeneratePomsMojo method readPomTemplate.

private Model readPomTemplate(String name) throws MojoExecutionException {
    try {
        XmlStreamReader reader;
        File file = new File(templatesDir, name);
        if (file.canRead()) {
            // check custom templates dir first
            reader = ReaderFactory.newXmlReader(file);
        } else {
            // fall back to internal templates
            ClassLoader cl = GeneratePomsMojo.class.getClassLoader();
            InputStream is = cl.getResourceAsStream("templates/" + name);
            reader = is != null ? ReaderFactory.newXmlReader(is) : null;
        }
        if (reader != null) {
            try {
                return modelReader.read(reader);
            } finally {
                reader.close();
            }
        } else {
            throw new MojoExecutionException("pom.xml template cannot be found " + name);
        }
    } catch (XmlPullParserException e) {
        throw new MojoExecutionException("Can't read pom.xml template " + name, e);
    } catch (IOException e) {
        throw new MojoExecutionException("Can't read pom.xml template " + name, e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XmlStreamReader(org.codehaus.plexus.util.xml.XmlStreamReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) File(java.io.File)

Aggregations

XmlStreamReader (org.codehaus.plexus.util.xml.XmlStreamReader)5 IOException (java.io.IOException)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 Model (org.apache.maven.model.Model)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)3 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)2 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 LinkedHashSet (java.util.LinkedHashSet)1