use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project maven-dependency-plugin by apache.
the class AnalyzeDuplicateMojo method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
getLog().info("Skipping plugin execution");
return;
}
MavenXpp3Reader pomReader = new MavenXpp3Reader();
Model model = null;
Reader reader = null;
try {
reader = ReaderFactory.newXmlReader(project.getFile());
model = pomReader.read(reader);
reader.close();
reader = null;
} catch (Exception e) {
throw new MojoExecutionException("IOException: " + e.getMessage(), e);
} finally {
IOUtil.close(reader);
}
Set<String> duplicateDependencies = Collections.emptySet();
if (model.getDependencies() != null) {
duplicateDependencies = findDuplicateDependencies(model.getDependencies());
}
Set<String> duplicateDependenciesManagement = Collections.emptySet();
if (model.getDependencyManagement() != null && model.getDependencyManagement().getDependencies() != null) {
duplicateDependenciesManagement = findDuplicateDependencies(model.getDependencyManagement().getDependencies());
}
if (getLog().isInfoEnabled()) {
StringBuilder sb = new StringBuilder();
if (!duplicateDependencies.isEmpty()) {
sb.append("List of duplicate dependencies defined in <dependencies/> in your pom.xml:\n");
for (Iterator<String> it = duplicateDependencies.iterator(); it.hasNext(); ) {
String dup = it.next();
sb.append("\to ").append(dup);
if (it.hasNext()) {
sb.append("\n");
}
}
}
if (!duplicateDependenciesManagement.isEmpty()) {
if (sb.length() > 0) {
sb.append("\n");
}
sb.append("List of duplicate dependencies defined in <dependencyManagement/> in your pom.xml:\n");
for (Iterator<String> it = duplicateDependenciesManagement.iterator(); it.hasNext(); ) {
String dup = it.next();
sb.append("\to ").append(dup);
if (it.hasNext()) {
sb.append("\n");
}
}
}
if (sb.length() > 0) {
getLog().info(sb.toString());
} else {
getLog().info("No duplicate dependencies found in <dependencies/> or in <dependencyManagement/>");
}
}
}
use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project pom-manipulation-ext by release-engineering.
the class PomIO method readModelsForManipulation.
/**
* Read {@link Model} instances by parsing the POM directly. This is useful to escape some post-processing that happens when the
* {@link MavenProject#getOriginalModel()} instance is set.
*
* @param executionRoot the top level pom file.
* @param peeked a collection of poms resolved from the top level file.
* @return a collection of Projects
* @throws ManipulationException if an error occurs.
*/
private List<Project> readModelsForManipulation(File executionRoot, final List<PomPeek> peeked) throws ManipulationException {
final List<Project> projects = new ArrayList<>();
final HashMap<Project, ProjectVersionRef> projectToParent = new HashMap<>();
for (final PomPeek peek : peeked) {
final File pom = peek.getPom();
// Sucks, but we have to brute-force reading in the raw model.
// The effective-model building, below, has a tantalizing getRawModel()
// method on the result, BUT this seems to return models that have
// the plugin versions set inside profiles...so they're not entirely
// raw.
Model raw = null;
InputStream in = null;
try {
in = new FileInputStream(pom);
raw = new MavenXpp3Reader().read(in);
} catch (final IOException | XmlPullParserException e) {
throw new ManipulationException("Failed to build model for POM: %s.\n--> %s", e, pom, e.getMessage());
} finally {
closeQuietly(in);
}
if (raw == null) {
continue;
}
final Project project = new Project(pom, raw);
projectToParent.put(project, peek.getParentKey());
project.setInheritanceRoot(peek.isInheritanceRoot());
if (executionRoot.equals(pom)) {
logger.debug("Setting execution root to {} with file {}" + (project.isInheritanceRoot() ? " and is the inheritance root. " : ""), project, pom);
project.setExecutionRoot();
try {
if (FileUtils.readFileToString(pom).contains(MODIFIED_BY)) {
project.setIncrementalPME(true);
}
} catch (final IOException e) {
throw new ManipulationException("Failed to read POM: %s", e, pom);
}
}
projects.add(project);
}
// Fill out inheritance info for every project we have created.
for (Project p : projects) {
ProjectVersionRef pvr = projectToParent.get(p);
p.setProjectParent(getParent(projects, pvr));
}
return projects;
}
use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project pom-manipulation-ext by release-engineering.
the class ModelIO method resolveRawModel.
/**
* Read the raw model (equivalent to the pom file on disk) from a given GAV.
*
* @param ref the ProjectVersion to read.
* @return the Maven Model for the GAV
* @throws ManipulationException if an error occurs.
*/
public Model resolveRawModel(final ProjectVersionRef ref) throws ManipulationException {
Transfer transfer;
try {
transfer = galleyWrapper.resolveArtifact(ref.asPomArtifact());
} catch (final TransferException e) {
throw new ManipulationException("Failed to resolve POM: %s.\n--> %s", e, ref, e.getMessage());
}
if (transfer == null) {
throw new ManipulationException("Failed to resolve POM: " + ref.asPomArtifact());
}
InputStream in = null;
try {
in = transfer.openInputStream();
return new MavenXpp3Reader().read(in);
} catch (final IOException | XmlPullParserException e) {
throw new ManipulationException("Failed to build model for POM: %s.\n--> %s", e, ref, e.getMessage());
} finally {
closeQuietly(in);
}
}
use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project fabric8 by jboss-fuse.
the class PomDetails method getModel.
public Model getModel() throws IOException {
try {
Model model = new MavenXpp3Reader().read(new FileInputStream(file));
model.setGroupId(properties.getProperty("groupId", model.getGroupId()));
model.setArtifactId(properties.getProperty("artifactId", model.getArtifactId()));
model.setVersion(properties.getProperty("version", model.getVersion()));
return model;
} catch (XmlPullParserException e) {
throw new IOException("Error parsing maven pom " + file, e);
}
}
use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project liferay-ide by liferay.
the class LiferayMavenLegacyProjectUpdater method _hasDependency.
private boolean _hasDependency(IProject project, String groupId, String artifactId) {
boolean retVal = false;
IFile iFile = project.getFile("pom.xml");
File pomFile = iFile.getLocation().toFile();
MavenXpp3Reader mavenReader = new MavenXpp3Reader();
try (FileReader reader = new FileReader(pomFile.getAbsolutePath())) {
Model model = mavenReader.read(reader);
List<Dependency> dependencies = model.getDependencies();
for (Dependency dependency : dependencies) {
if (groupId.equals(dependency.getGroupId()) && artifactId.equals(dependency.getArtifactId())) {
retVal = true;
break;
}
}
} catch (FileNotFoundException fnfe) {
} catch (IOException ioe) {
} catch (XmlPullParserException xppe) {
}
return retVal;
}
Aggregations