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>"true"</code>, or <code>false</code>
* if its value is <code>"false"</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><resource></code> element from the <code><resources></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");
}
}
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><source></code> element from the <code><testSources></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.");
}
}
}
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);
}
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);
}
}
Aggregations