use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project ServiceStack.Java by ServiceStack.
the class EclipseMavenHelper method addMavenDependencyIfRequired.
public boolean addMavenDependencyIfRequired(IFile pomFile, String groupId, String packageId, String version) throws Exception {
boolean dependencyAdded = false;
MavenXpp3Reader reader = new MavenXpp3Reader();
Model pomModel;
try {
pomModel = reader.read(new FileReader(new File(pomFile.getLocationURI())));
final List<Dependency> dependencies = pomModel.getDependencies();
boolean requiresPomDependency = true;
for (Dependency dep : dependencies) {
if (Objects.equals(dep.getGroupId(), groupId) && Objects.equals(dep.getArtifactId(), packageId)) {
requiresPomDependency = false;
}
}
String content;
if (requiresPomDependency) {
Dependency dependency = new Dependency();
dependency.setGroupId(groupId);
dependency.setArtifactId(packageId);
dependency.setVersion(version);
pomModel.addDependency(dependency);
StringWriter strWriter = new StringWriter();
new MavenXpp3Writer().write(strWriter, pomModel);
content = strWriter.toString();
InputStream stream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
pomFile.setContents(stream, false, false, null);
dependencyAdded = true;
}
} catch (IOException | XmlPullParserException e) {
e.printStackTrace();
throw new Exception("Unable to process pom.xml to add " + groupId + ":" + packageId + ":" + version);
}
return dependencyAdded;
}
use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project ceylon by eclipse.
the class AetherResolverImpl method getDependencies.
@Override
public DependencyDescriptor getDependencies(File pomXml, String name, String version) throws IOException {
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model;
try (FileReader fileReader = new FileReader(pomXml)) {
model = reader.read(fileReader);
} catch (XmlPullParserException e) {
throw new IOException(e);
}
return new ModelDependencyDescriptor(model);
}
use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project ceylon by eclipse.
the class AetherResolverImpl method getDependencies.
@Override
public DependencyDescriptor getDependencies(InputStream pomXml, String name, String version) throws IOException {
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model;
try {
model = reader.read(pomXml);
} catch (XmlPullParserException e) {
throw new IOException(e);
}
return new ModelDependencyDescriptor(model);
}
use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project mule by mulesoft.
the class MavenUtils method getPomModelFolder.
/**
* Returns the {@link Model} from a given artifact folder
*
* @param artifactFolder folder containing the exploded artifact file.
* @return the {@link Model} from the {@value ArtifactPluginDescriptor#MULE_PLUGIN_POM} file if available
* @throws ArtifactDescriptorCreateException if the folder does not contain a {@value ArtifactPluginDescriptor#MULE_PLUGIN_POM}
* file or the file can' be loaded
*/
public static Model getPomModelFolder(File artifactFolder) {
final File mulePluginPom = lookupPomFromMavenLocation(artifactFolder);
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model;
try (FileReader mulePluginPomFileReader = new FileReader(mulePluginPom)) {
model = reader.read(mulePluginPomFileReader);
} catch (IOException | XmlPullParserException e) {
throw new ArtifactDescriptorCreateException(format("There was an issue reading '%s' for the plugin '%s'", mulePluginPom.getName(), artifactFolder.getAbsolutePath()), e);
}
return model;
}
use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project spoon by INRIA.
the class MavenLauncher method readPOM.
/**
* Extract the information from the pom
* @param path the path to the pom
* @param parent the parent pom
* @return the extracted model
* @throws IOException when the file does not exist
* @throws XmlPullParserException when the file is corrupted
*/
private InheritanceModel readPOM(String path, InheritanceModel parent) throws IOException, XmlPullParserException {
if (!path.endsWith(".xml") && !path.endsWith(".pom")) {
path = Paths.get(path, "pom.xml").toString();
}
File pomFile = new File(path);
if (!pomFile.exists()) {
return null;
}
MavenXpp3Reader pomReader = new MavenXpp3Reader();
try (FileReader reader = new FileReader(pomFile)) {
Model model = pomReader.read(reader);
InheritanceModel inheritanceModel = new InheritanceModel(model, parent, pomFile.getParentFile());
for (String module : model.getModules()) {
inheritanceModel.addModule(readPOM(Paths.get(pomFile.getParent(), module).toString(), inheritanceModel));
}
return inheritanceModel;
}
}
Aggregations