Search in sources :

Example 76 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project maven-archetype by apache.

the class ArchetypeDescriptorBuilder method addResourceToDescriptor.

/**
 * Adds the resource element <code>resource</code> to the list of resources in the
 * <code>descriptor</code> and sets its <code>TemplateDescriptor</code> to
 * <i>filtered</i> if the attribute <code>filtered</code> was not
 * specified or its value is <code>&quot;true&quot;</code>, or <code>false</code>
 * if its value is <code>&quot;false&quot;</code>, and the encoding specified
 * in the <code>encoding</code> attribute or the Java virtual machine's default if
 * it is not defined. If the <code>resource</code> is a property file (ends in
 * <code>.properties</code>) its encoding will be set to <code>iso-8859-1</code>
 * even if some other encoding is specified in the attribute.
 *
 * @param resource   a <code>&lt;resource&gt;</code> element from the <code>&lt;resources&gt;</code>
 * @param descriptor the <code>ArchetypeDescriptor</code> to add the resource template to.
 * @throws XmlPullParserException if the encoding specified is not valid or supported or if the
 *                                value of the attribute <code>filtered</code> is no valid.
 */
private static void addResourceToDescriptor(Xpp3Dom resource, ArchetypeDescriptor descriptor) throws XmlPullParserException {
    descriptor.addResource(resource.getValue());
    if (resource.getAttribute("filtered") != null) {
        TemplateDescriptor resourceDesc = descriptor.getResourceDescriptor(resource.getValue());
        try {
            resourceDesc.setFiltered(getValueFilteredAttribute(resource.getAttribute("filtered")));
        } catch (IllegalArgumentException iae) {
            throw new XmlPullParserException(iae.getMessage());
        }
    }
    if (resource.getAttribute("encoding") != null) {
        TemplateDescriptor resourceDesc = descriptor.getResourceDescriptor(resource.getValue());
        try {
            resourceDesc.setEncoding(resource.getAttribute("encoding"));
        } catch (IllegalCharsetNameException icne) {
            throw new XmlPullParserException(resource.getAttribute("encoding") + " is not a valid encoding.");
        } catch (UnsupportedCharsetException uce) {
            throw new XmlPullParserException(resource.getAttribute("encoding") + " is not a supported encoding.");
        }
    }
    if (resource.getValue().endsWith(".properties")) {
        TemplateDescriptor resourceDesc = descriptor.getResourceDescriptor(resource.getValue());
        resourceDesc.setEncoding("iso-8859-1");
    }
}
Also used : IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException)

Example 77 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project maven-archetype by apache.

the class ArchetypeDescriptorBuilder method addTestSourceToDescriptor.

/**
 * Adds the test-source element <code>source</code> to the list of sources in the
 * <code>descriptor</code> and sets its <code>TemplateDescriptor</code> to
 * <i>filtered</i> and with the encoding specified in the <code>encoding</code>
 * attribute or the Java virtual machine's default if it is not defined.
 *
 * @param testSource a <code>&lt;source&gt;</code> element from the <code>&lt;testSources&gt;</code>
 * @param descriptor the <code>ArchetypeDescriptor</code> to add the test-source template to.
 * @throws XmlPullParserException if the encoding specified is not valid or supported.
 */
private static void addTestSourceToDescriptor(Xpp3Dom testSource, ArchetypeDescriptor descriptor) throws XmlPullParserException {
    descriptor.addTestSource(testSource.getValue());
    TemplateDescriptor testSourceDesc = descriptor.getTestSourceDescriptor(testSource.getValue());
    testSourceDesc.setFiltered(true);
    if (testSource.getAttribute("encoding") != null) {
        try {
            testSourceDesc.setEncoding(testSource.getAttribute("encoding"));
        } catch (IllegalCharsetNameException icne) {
            throw new XmlPullParserException(testSource.getAttribute("encoding") + " is not a valid encoding.");
        } catch (UnsupportedCharsetException uce) {
            throw new XmlPullParserException(testSource.getAttribute("encoding") + " is not a supported encoding.");
        }
    }
}
Also used : IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException)

Example 78 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException 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 79 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException 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

XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)79 IOException (java.io.IOException)73 File (java.io.File)37 Model (org.apache.maven.model.Model)32 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)30 FileNotFoundException (java.io.FileNotFoundException)20 Reader (java.io.Reader)20 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)19 FileReader (java.io.FileReader)15 FileInputStream (java.io.FileInputStream)12 ArrayList (java.util.ArrayList)12 InputStream (java.io.InputStream)11 StringReader (java.io.StringReader)10 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)10 Path (java.nio.file.Path)7 Artifact (org.eclipse.aether.artifact.Artifact)7 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)7 PluginException (org.bimserver.shared.exceptions.PluginException)6 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)6 HashMap (java.util.HashMap)5