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;
}
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);
}
}
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;
}
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);
}
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);
}
}
Aggregations