use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project liferay-ide by liferay.
the class MavenProjectBuilder method initBundle.
public IStatus initBundle(IProject project, String bundleUrl, IProgressMonitor monitor) throws CoreException {
if (bundleUrl != null) {
File pomFile = FileUtil.getFile(project.getFile("pom.xml"));
MavenXpp3Reader mavenReader = new MavenXpp3Reader();
MavenXpp3Writer mavenWriter = new MavenXpp3Writer();
try (FileReader reader = new FileReader(pomFile)) {
Model model = mavenReader.read(reader);
if (model != null) {
Build build = model.getBuild();
Plugin plugin = build.getPluginsAsMap().get("com.liferay:com.liferay.portal.tools.bundle.support");
if (plugin != null) {
try (FileWriter fileWriter = new FileWriter(pomFile)) {
Xpp3Dom origin = (Xpp3Dom) plugin.getConfiguration();
Xpp3Dom newConfiguration = new Xpp3Dom("configuration");
Xpp3Dom url = new Xpp3Dom("url");
url.setValue(bundleUrl);
newConfiguration.addChild(url);
plugin.setConfiguration(Xpp3Dom.mergeXpp3Dom(newConfiguration, origin));
mavenWriter.write(fileWriter, model);
}
}
}
} catch (Exception e) {
LiferayMavenCore.logError("Could not write file in" + pomFile, e);
}
}
IMavenProjectFacade facade = MavenUtil.getProjectFacade(project, monitor);
if (_execMavenLaunch(project, MavenGoalUtil.getMavenInitBundleGoal(project), facade, monitor)) {
return Status.OK_STATUS;
}
return LiferayMavenCore.createErrorStatus("run init-bundle error");
}
use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project archiva by apache.
the class LegacyToDefaultConverter method copyPom.
@SuppressWarnings("unchecked")
private boolean copyPom(Artifact artifact, ArtifactRepository targetRepository, FileTransaction transaction) throws ArtifactConversionException {
Artifact pom = artifactFactory.createProjectArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
pom.setBaseVersion(artifact.getBaseVersion());
ArtifactRepository repository = artifact.getRepository();
Path file = Paths.get(repository.getBasedir(), repository.pathOf(pom));
boolean result = true;
if (Files.exists(file)) {
Path targetFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(pom));
String contents = null;
boolean checksumsValid = false;
try {
if (testChecksums(artifact, file)) {
checksumsValid = true;
}
// Even if the checksums for the POM are invalid we should still convert the POM
contents = org.apache.archiva.common.utils.FileUtils.readFileToString(file, Charset.defaultCharset());
} catch (IOException e) {
throw new ArtifactConversionException(Messages.getString("unable.to.read.source.pom", e.getMessage()), // $NON-NLS-1$
e);
}
if (// $NON-NLS-1$
checksumsValid && contents.indexOf("modelVersion") >= 0) {
// v4 POM
boolean matching = false;
if (!force && Files.exists(targetFile)) {
String targetContents = org.apache.archiva.common.utils.FileUtils.readFileToString(targetFile, Charset.defaultCharset());
matching = targetContents.equals(contents);
}
if (force || !matching) {
transaction.createFile(contents, targetFile, digesters);
}
} else {
// v3 POM
try (StringReader stringReader = new StringReader(contents)) {
try (StringWriter writer = new StringWriter()) {
org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader v3Reader = new org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader();
org.apache.maven.model.v3_0_0.Model v3Model = v3Reader.read(stringReader);
if (doRelocation(artifact, v3Model, targetRepository, transaction)) {
Artifact relocatedPom = artifactFactory.createProjectArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
targetFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(relocatedPom));
}
Model v4Model = translator.translate(v3Model);
translator.validateV4Basics(v4Model, v3Model.getGroupId(), v3Model.getArtifactId(), v3Model.getVersion(), v3Model.getPackage());
MavenXpp3Writer xpp3Writer = new MavenXpp3Writer();
xpp3Writer.write(writer, v4Model);
transaction.createFile(writer.toString(), targetFile, digesters);
List<String> warnings = translator.getWarnings();
for (String message : warnings) {
addWarning(artifact, message);
}
} catch (XmlPullParserException e) {
addWarning(artifact, // $NON-NLS-1$
Messages.getString("invalid.source.pom", e.getMessage()));
result = false;
} catch (IOException e) {
throw new ArtifactConversionException(Messages.getString("unable.to.write.converted.pom"), // $NON-NLS-1$
e);
} catch (PomTranslationException e) {
addWarning(artifact, // $NON-NLS-1$
Messages.getString("invalid.source.pom", e.getMessage()));
result = false;
}
}
}
} else {
// $NON-NLS-1$
addWarning(artifact, Messages.getString("warning.missing.pom"));
}
return result;
}
use of org.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.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.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;
}
Aggregations