use of org.apache.maven.project.DefaultProjectBuildingRequest in project maven-plugins by apache.
the class DescribeMojo method describePlugin.
/**
* Method for retrieving the plugin description
*
* @param pd contains the plugin description
* @param buffer contains the information to be displayed or printed
* @throws MojoFailureException if any reflection exceptions occur.
* @throws MojoExecutionException if any
*/
private void describePlugin(PluginDescriptor pd, StringBuilder buffer) throws MojoFailureException, MojoExecutionException {
append(buffer, pd.getId(), 0);
buffer.append(LS);
String name = pd.getName();
if (name == null) {
// Can be null because of MPLUGIN-137 (and descriptors generated with maven-plugin-tools-api <= 2.4.3)
ArtifactCoordinate coordinate = toArtifactCoordinate(pd, "jar");
ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
pbr.setRemoteRepositories(remoteRepositories);
pbr.setProject(null);
pbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
try {
Artifact artifact = artifactResolver.resolveArtifact(pbr, coordinate).getArtifact();
name = projectBuilder.build(artifact, pbr).getProject().getName();
} catch (Exception e) {
// oh well, we tried our best.
getLog().warn("Unable to get the name of the plugin " + pd.getId() + ": " + e.getMessage());
name = pd.getId();
}
}
append(buffer, "Name", name, 0);
appendAsParagraph(buffer, "Description", toDescription(pd.getDescription()), 0);
append(buffer, "Group Id", pd.getGroupId(), 0);
append(buffer, "Artifact Id", pd.getArtifactId(), 0);
append(buffer, "Version", pd.getVersion(), 0);
append(buffer, "Goal Prefix", pd.getGoalPrefix(), 0);
buffer.append(LS);
List<MojoDescriptor> mojos = pd.getMojos();
if (mojos == null) {
append(buffer, "This plugin has no goals.", 0);
return;
}
if ((detail || medium) && !minimal) {
append(buffer, "This plugin has " + mojos.size() + " goal" + (mojos.size() > 1 ? "s" : "") + ":", 0);
buffer.append(LS);
mojos = new ArrayList<MojoDescriptor>(mojos);
PluginUtils.sortMojos(mojos);
for (MojoDescriptor md : mojos) {
if (detail) {
describeMojoGuts(md, buffer, true);
} else {
describeMojoGuts(md, buffer, false);
}
buffer.append(LS);
}
}
if (!detail) {
buffer.append("For more information, run 'mvn help:describe [...] -Ddetail'");
buffer.append(LS);
}
}
use of org.apache.maven.project.DefaultProjectBuildingRequest in project maven-plugins by apache.
the class EvaluateMojo method getArtifactFile.
/**
* @param isPom <code>true</code> to lookup the <code>maven-model</code> artifact jar, <code>false</code> to lookup
* the <code>maven-settings</code> artifact jar.
* @return the <code>org.apache.maven:maven-model|maven-settings</code> artifact jar file for this current
* HelpPlugin pom.
* @throws MojoExecutionException if any
* @throws ProjectBuildingException if any
* @throws ArtifactResolverException if any
*/
private File getArtifactFile(boolean isPom) throws MojoExecutionException, ProjectBuildingException, ArtifactResolverException {
List<Dependency> dependencies = getHelpPluginPom().getDependencies();
for (Dependency depependency : dependencies) {
if (!(depependency.getGroupId().equals("org.apache.maven"))) {
continue;
}
if (isPom) {
if (!(depependency.getArtifactId().equals("maven-model"))) {
continue;
}
} else {
if (!(depependency.getArtifactId().equals("maven-settings"))) {
continue;
}
}
ArtifactCoordinate coordinate = getArtifactCoordinate(depependency.getGroupId(), depependency.getArtifactId(), depependency.getVersion(), "jar");
ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
pbr.setRemoteRepositories(remoteRepositories);
return artifactResolver.resolveArtifact(pbr, coordinate).getArtifact().getFile();
}
throw new MojoExecutionException("Unable to find the 'org.apache.maven:" + (isPom ? "maven-model" : "maven-settings") + "' artifact");
}
use of org.apache.maven.project.DefaultProjectBuildingRequest in project maven-plugins by apache.
the class RepoBuilderConfigSourceWrapper method getProjectBuildingRequest.
@Override
public ProjectBuildingRequest getProjectBuildingRequest() {
ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(configSource.getMavenSession().getProjectBuildingRequest());
pbr.setRemoteRepositories(getProject().getRemoteArtifactRepositories());
return pbr;
}
use of org.apache.maven.project.DefaultProjectBuildingRequest 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.DefaultProjectBuildingRequest in project maven-dependency-plugin by apache.
the class AbstractDependencyMojo method newResolveArtifactProjectBuildingRequest.
/**
* @return Returns a new ProjectBuildingRequest populated from the current session and the current project remote
* repositories, used to resolve artifacts.
*/
public ProjectBuildingRequest newResolveArtifactProjectBuildingRequest() {
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(remoteRepositories);
return buildingRequest;
}
Aggregations