use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.
the class JavadocReportTest method testTaglets.
/**
* Method to test the taglet artifact configuration
*
* @throws Exception if any
*/
public void testTaglets() throws Exception {
// ----------------------------------------------------------------------
// taglet-test: check if a taglet is used
// ----------------------------------------------------------------------
File testPom = new File(unit, "taglet-test/taglet-test-plugin-config.xml");
JavadocReport mojo = lookupMojo(testPom);
MavenSession session = spy(newMavenSession(mojo.project));
ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
when(buildingRequest.getRemoteRepositories()).thenReturn(mojo.project.getRemoteArtifactRepositories());
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepo));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);
LegacySupport legacySupport = lookup(LegacySupport.class);
legacySupport.setSession(session);
setVariableValueToObject(mojo, "session", session);
mojo.execute();
File apidocs = new File(getBasedir(), "target/test/unit/taglet-test/target/site/apidocs");
assertTrue(new File(apidocs, "index.html").exists());
File appFile = new File(apidocs, "taglet/test/App.html");
assertTrue(appFile.exists());
String appString = readFile(appFile);
assertTrue(appString.contains("<b>To Do:</b>"));
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-dependency-plugin by apache.
the class AbstractFromConfigurationMojo method getArtifact.
/**
* Resolves the Artifact from the remote repository if necessary. If no version is specified, it will be retrieved
* from the dependency list or from the DependencyManagement section of the pom.
*
* @param artifactItem containing information about artifact from plugin configuration.
* @return Artifact object representing the specified file.
* @throws MojoExecutionException with a message if the version can't be found in DependencyManagement.
*/
protected Artifact getArtifact(ArtifactItem artifactItem) throws MojoExecutionException {
Artifact artifact;
try {
// mdep-50 - rolledback for now because it's breaking some functionality.
/*
* List listeners = new ArrayList(); Set theSet = new HashSet(); theSet.add( artifact );
* ArtifactResolutionResult artifactResolutionResult = artifactCollector.collect( theSet, project
* .getArtifact(), managedVersions, this.local, project.getRemoteArtifactRepositories(),
* artifactMetadataSource, null, listeners ); Iterator iter =
* artifactResolutionResult.getArtifactResolutionNodes().iterator(); while ( iter.hasNext() ) {
* ResolutionNode node = (ResolutionNode) iter.next(); artifact = node.getArtifact(); }
*/
ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
if (localRepositoryDirectory != null) {
buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, localRepositoryDirectory);
}
// Map dependency to artifact coordinate
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
coordinate.setGroupId(artifactItem.getGroupId());
coordinate.setArtifactId(artifactItem.getArtifactId());
coordinate.setVersion(artifactItem.getVersion());
coordinate.setClassifier(artifactItem.getClassifier());
final String extension;
ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(artifactItem.getType());
if (artifactHandler != null) {
extension = artifactHandler.getExtension();
} else {
extension = artifactItem.getType();
}
coordinate.setExtension(extension);
artifact = artifactResolver.resolveArtifact(buildingRequest, coordinate).getArtifact();
} catch (ArtifactResolverException e) {
throw new MojoExecutionException("Unable to find/resolve artifact.", e);
}
return artifact;
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-dependency-plugin by apache.
the class CopyDependenciesMojo method getResolvedPomArtifact.
/**
* @param artifact {@link Artifact}
* @return {@link Artifact}
*/
protected Artifact getResolvedPomArtifact(Artifact artifact) {
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
coordinate.setGroupId(artifact.getGroupId());
coordinate.setArtifactId(artifact.getArtifactId());
coordinate.setVersion(artifact.getVersion());
coordinate.setExtension("pom");
Artifact pomArtifact = null;
// Resolve the pom artifact using repos
try {
ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
pomArtifact = getArtifactResolver().resolveArtifact(buildingRequest, coordinate).getArtifact();
} catch (ArtifactResolverException e) {
getLog().info(e.getMessage());
}
return pomArtifact;
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-dependency-plugin by apache.
the class TreeMojo method execute.
// Mojo methods -----------------------------------------------------------
/*
* @see org.apache.maven.plugin.Mojo#execute()
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (isSkip()) {
getLog().info("Skipping plugin execution");
return;
}
try {
String dependencyTreeString;
// TODO: note that filter does not get applied due to MSHARED-4
ArtifactFilter artifactFilter = createResolvingArtifactFilter();
if (verbose) {
// To fix we probably need a different DependencyCollector in Aether, which doesn't remove nodes which
// have already been resolved.
getLog().info("Verbose not supported since maven-dependency-plugin 3.0");
}
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setProject(project);
// non-verbose mode use dependency graph component, which gives consistent results with Maven version
// running
rootNode = dependencyGraphBuilder.buildDependencyGraph(buildingRequest, artifactFilter, reactorProjects);
dependencyTreeString = serializeDependencyTree(rootNode);
if (outputFile != null) {
DependencyUtil.write(dependencyTreeString, outputFile, this.appendOutput, getLog());
getLog().info("Wrote dependency tree to: " + outputFile);
} else {
DependencyUtil.log(dependencyTreeString, getLog());
}
} catch (DependencyGraphBuilderException exception) {
throw new MojoExecutionException("Cannot build project dependency graph", exception);
} catch (IOException exception) {
throw new MojoExecutionException("Cannot serialise project dependency graph", exception);
}
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-dependency-plugin by apache.
the class ResolvePluginsMojo method resolvePluginArtifacts.
/**
* This method resolves the plugin artifacts from the project.
*
* @return set of resolved plugin artifacts.
* @throws ArtifactFilterException in case of an error.
* @throws ArtifactResolverException in case of an error.
*/
protected Set<Artifact> resolvePluginArtifacts() throws ArtifactFilterException, ArtifactResolverException {
final Set<Artifact> plugins = getProject().getPluginArtifacts();
final Set<Artifact> reports = getProject().getReportArtifacts();
Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
artifacts.addAll(reports);
artifacts.addAll(plugins);
final FilterArtifacts filter = getPluginArtifactsFilter();
artifacts = filter.filter(artifacts);
Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>(artifacts.size());
// final ArtifactFilter filter = getPluginFilter();
for (final Artifact artifact : new LinkedHashSet<Artifact>(artifacts)) {
// if ( !filter.include( artifact ) )
// {
// final String logStr =
// String.format( " Plugin SKIPPED: %s", DependencyUtil.getFormattedFileName( artifact, false ) );
//
// if ( !silent )
// {
// this.getLog().info( logStr );
// }
//
// artifacts.remove( artifact );
// continue;
// }
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(this.remotePluginRepositories);
// resolve the new artifact
resolvedArtifacts.add(getArtifactResolver().resolveArtifact(buildingRequest, artifact).getArtifact());
}
return artifacts;
}
Aggregations