use of org.apache.maven.project.ProjectBuildingException in project che by eclipse.
the class EffectivePomWriter method getEffectivePom.
public static String getEffectivePom(MavenServerImpl server, final File pom, List<String> activeProfiles, List<String> inactiveProfiles) {
StringWriter stringWriter = new StringWriter();
try {
MavenExecutionRequest request = server.newMavenRequest(pom, activeProfiles, inactiveProfiles, Collections.emptyList());
server.runMavenRequest(request, () -> {
try {
ProjectBuilder builder = server.getMavenComponent(ProjectBuilder.class);
ProjectBuildingResult projectBuildingResult = builder.build(new File(pom.getPath()), request.getProjectBuildingRequest());
MavenProject project = projectBuildingResult.getProject();
XMLWriter writer = new PrettyPrintXMLWriter(stringWriter, " ");
writeHeader(writer);
writeEffectivePom(project, writer);
} catch (ProjectBuildingException | MojoExecutionException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
});
} catch (Exception e) {
return null;
}
return stringWriter.toString();
}
use of org.apache.maven.project.ProjectBuildingException in project karaf by apache.
the class GenerateDescriptorMojo method resolveProject.
private MavenProject resolveProject(final Object artifact) throws MojoExecutionException {
MavenProject resolvedProject = project;
if (includeTransitiveVersionRanges) {
resolvedProject = resolvedProjects.get(artifact);
if (resolvedProject == null) {
final ProjectBuildingRequest request = new DefaultProjectBuildingRequest();
// Fixes KARAF-4626; if the system properties are not transferred to the request,
// test-feature-use-version-range-transfer-properties will fail
request.setSystemProperties(System.getProperties());
request.setResolveDependencies(true);
request.setRemoteRepositories(project.getPluginArtifactRepositories());
request.setLocalRepository(localRepo);
request.setProfiles(new ArrayList<>(mavenSession.getRequest().getProfiles()));
request.setActiveProfileIds(new ArrayList<>(mavenSession.getRequest().getActiveProfiles()));
dependencyHelper.setRepositorySession(request);
final Artifact pomArtifact = repoSystem.createArtifact(dependencyHelper.getGroupId(artifact), dependencyHelper.getArtifactId(artifact), dependencyHelper.getBaseVersion(artifact), "pom");
try {
resolvedProject = mavenProjectBuilder.build(pomArtifact, request).getProject();
resolvedProjects.put(pomArtifact, resolvedProject);
} catch (final ProjectBuildingException e) {
throw new MojoExecutionException(format("Maven-project could not be built for artifact %s", pomArtifact), e);
}
}
}
return resolvedProject;
}
use of org.apache.maven.project.ProjectBuildingException in project maven-plugins by apache.
the class ProcessRemoteResourcesMojo method getProjects.
@SuppressWarnings("unchecked")
protected List<MavenProject> getProjects() throws MojoExecutionException {
List<MavenProject> projects = new ArrayList<MavenProject>();
// add filters in well known order, least specific to most specific
FilterArtifacts filter = new FilterArtifacts();
Set<Artifact> artifacts = resolveProjectArtifacts();
if (this.excludeTransitive) {
Set<Artifact> depArtifacts;
if (runOnlyAtExecutionRoot) {
depArtifacts = aggregateProjectDependencyArtifacts();
} else {
depArtifacts = project.getDependencyArtifacts();
}
filter.addFilter(new ProjectTransitivityFilter(depArtifacts, true));
}
filter.addFilter(new ScopeFilter(this.includeScope, this.excludeScope));
filter.addFilter(new GroupIdFilter(this.includeGroupIds, this.excludeGroupIds));
filter.addFilter(new ArtifactIdFilter(this.includeArtifactIds, this.excludeArtifactIds));
// perform filtering
try {
artifacts = filter.filter(artifacts);
} catch (ArtifactFilterException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
for (Artifact artifact : artifacts) {
try {
List<ArtifactRepository> remoteRepo = remoteArtifactRepositories;
if (artifact.isSnapshot()) {
VersionRange rng = VersionRange.createFromVersion(artifact.getBaseVersion());
artifact = artifactFactory.createDependencyArtifact(artifact.getGroupId(), artifact.getArtifactId(), rng, artifact.getType(), artifact.getClassifier(), artifact.getScope(), null, artifact.isOptional());
}
getLog().debug("Building project for " + artifact);
MavenProject p;
try {
p = mavenProjectBuilder.buildFromRepository(artifact, remoteRepo, localRepository);
} catch (InvalidProjectModelException e) {
getLog().warn("Invalid project model for artifact [" + artifact.getArtifactId() + ":" + artifact.getGroupId() + ":" + artifact.getVersion() + "]. " + "It will be ignored by the remote resources Mojo.");
continue;
}
String supplementKey = generateSupplementMapKey(p.getModel().getGroupId(), p.getModel().getArtifactId());
if (supplementModels.containsKey(supplementKey)) {
Model mergedModel = mergeModels(p.getModel(), supplementModels.get(supplementKey));
MavenProject mergedProject = new MavenProject(mergedModel);
projects.add(mergedProject);
mergedProject.setArtifact(artifact);
mergedProject.setVersion(artifact.getVersion());
getLog().debug("Adding project with groupId [" + mergedProject.getGroupId() + "] (supplemented)");
} else {
projects.add(p);
getLog().debug("Adding project with groupId [" + p.getGroupId() + "]");
}
} catch (ProjectBuildingException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
Collections.sort(projects, new ProjectComparator());
return projects;
}
use of org.apache.maven.project.ProjectBuildingException in project maven-plugins by apache.
the class DeployFileMojo method createMavenProject.
/**
* Creates a Maven project in-memory from the user-supplied groupId, artifactId and version. When a classifier is
* supplied, the packaging must be POM because the project with only have attachments. This project serves as basis
* to attach the artifacts to deploy to.
*
* @return The created Maven project, never <code>null</code>.
* @throws MojoExecutionException When the model of the project could not be built.
* @throws MojoFailureException When building the project failed.
*/
private MavenProject createMavenProject() throws MojoExecutionException, MojoFailureException {
if (groupId == null || artifactId == null || version == null || packaging == null) {
throw new MojoExecutionException("The artifact information is incomplete: 'groupId', 'artifactId', " + "'version' and 'packaging' are required.");
}
ModelSource modelSource = new StringModelSource("<project>" + "<modelVersion>4.0.0</modelVersion>" + "<groupId>" + groupId + "</groupId>" + "<artifactId>" + artifactId + "</artifactId>" + "<version>" + version + "</version>" + "<packaging>" + (classifier == null ? packaging : "pom") + "</packaging>" + "</project>");
DefaultProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(getSession().getProjectBuildingRequest());
buildingRequest.setProcessPlugins(false);
try {
return projectBuilder.build(modelSource, buildingRequest).getProject();
} catch (ProjectBuildingException e) {
if (e.getCause() instanceof ModelBuildingException) {
throw new MojoExecutionException("The artifact information is not valid:" + Os.LINE_SEP + e.getCause().getMessage());
}
throw new MojoFailureException("Unable to create the project.", e);
}
}
use of org.apache.maven.project.ProjectBuildingException in project maven-plugins by apache.
the class DoapMojo method getMavenProject.
// ----------------------------------------------------------------------
// Private methods
// ----------------------------------------------------------------------
/**
* @param artifact not null
* @return the maven project for the given doap artifact
* @since 1.1
*/
private MavenProject getMavenProject(DoapArtifact artifact) {
if (artifact == null) {
return null;
}
if (StringUtils.isEmpty(artifact.getGroupId()) || StringUtils.isEmpty(artifact.getArtifactId()) || StringUtils.isEmpty(artifact.getVersion())) {
getLog().warn("Missing groupId or artifactId or version in <artifact/> parameter, ignored it.");
return null;
}
getLog().info("Using artifact " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion());
try {
Artifact art = factory.createProjectArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), Artifact.SCOPE_COMPILE);
if (art.getFile() == null) {
MavenProject proj = mavenProjectBuilder.buildFromRepository(art, remoteRepositories, localRepository);
art = proj.getArtifact();
resolver.resolve(art, remoteRepositories, localRepository);
return proj;
}
} catch (ArtifactResolutionException e) {
getLog().error("ArtifactResolutionException: " + e.getMessage() + "\nIgnored <artifact/> parameter.");
} catch (ArtifactNotFoundException e) {
getLog().error("ArtifactNotFoundException: " + e.getMessage() + "\nIgnored <artifact/> parameter.");
} catch (ProjectBuildingException e) {
getLog().error("ProjectBuildingException: " + e.getMessage() + "\nIgnored <artifact/> parameter.");
}
return null;
}
Aggregations