use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project fabric8-maven-plugin by fabric8io.
the class BaseBoosterIT method updateSourceCode.
protected void updateSourceCode(Repository repository, String relativePomPath) throws XmlPullParserException, IOException {
MavenXpp3Reader reader = new MavenXpp3Reader();
String baseDir = repository.getWorkTree().getAbsolutePath();
Model model = reader.read(new FileInputStream(new File(baseDir, relativePomPath)));
Dependency dependency = new Dependency();
dependency.setGroupId("org.apache.commons");
dependency.setArtifactId("commons-lang3");
dependency.setVersion("3.5");
model.getDependencies().add(dependency);
MavenXpp3Writer writer = new MavenXpp3Writer();
writer.write(new FileOutputStream(new File(baseDir, relativePomPath)), model);
model.getArtifactId();
}
use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project dkpro-tc by dkpro.
the class ModelVersionIO method getCurrentTcVersionFromJar.
default String getCurrentTcVersionFromJar() throws Exception {
Class<?> contextClass = getClass();
InputStream stream = contextClass.getResourceAsStream("/META-INF/maven/org.dkpro.tc/dkpro-tc-core/pom.xml");
if (stream == null) {
return null;
}
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model;
try {
model = reader.read(stream);
} finally {
IOUtils.closeQuietly(stream);
}
String version = model.getParent().getVersion();
return version;
}
use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project dkpro-tc by dkpro.
the class ModelVersionIO method getCurrentTcVersionFromWorkspace.
default String getCurrentTcVersionFromWorkspace() throws Exception {
Class<?> contextClass = getClass();
// Try to determine the location of the POM file belonging to the
// context object
URL url = contextClass.getResource(contextClass.getSimpleName() + ".class");
String classPart = contextClass.getName().replace(".", "/") + ".class";
String base = url.toString();
base = base.substring(0, base.length() - classPart.length());
base = base.substring(0, base.length() - "target/classes/".length());
File pomFile = new File(new File(URI.create(base)), "pom.xml");
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model;
FileInputStream fis = null;
try {
fis = new FileInputStream(pomFile);
model = reader.read(fis);
} finally {
IOUtils.closeQuietly(fis);
}
String version = model.getParent().getVersion();
return version;
}
use of org.eclipse.ceylon.aether.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.eclipse.ceylon.aether.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);
}
Aggregations