use of org.apache.maven.project.DefaultProjectBuildingRequest 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.DefaultProjectBuildingRequest 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;
}
use of org.apache.maven.project.DefaultProjectBuildingRequest in project evosuite by EvoSuite.
the class EvoSuiteRunner method getCommandToRunEvoSuite.
/**
* We run the EvoSuite that is provided with the plugin
*
* @return
*/
private List<String> getCommandToRunEvoSuite() {
logger.debug("EvoSuite Maven Plugin Artifacts: " + Arrays.toString(artifacts.toArray()));
Artifact evosuite = null;
for (Artifact art : artifacts) {
// first find the main EvoSuite jar among the dependencies
if (art.getArtifactId().equals("evosuite-master")) {
evosuite = art;
break;
}
}
if (evosuite == null) {
logger.error("CRITICAL ERROR: plugin can detect EvoSuite executable");
return null;
}
logger.debug("EvoSuite located at: " + evosuite.getFile());
/*
* now, build a project descriptor for evosuite, which is needed to
* query all of its dependencies
*/
DefaultProjectBuildingRequest req = new DefaultProjectBuildingRequest();
req.setRepositorySession(repoSession);
req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
req.setSystemProperties(System.getProperties());
req.setResolveDependencies(true);
ProjectBuildingResult res;
try {
res = projectBuilder.build(evosuite, req);
} catch (ProjectBuildingException e) {
logger.error("Failed: " + e.getMessage(), e);
return null;
}
// build the classpath to run EvoSuite
String cp = evosuite.getFile().getAbsolutePath();
for (Artifact dep : res.getProject().getArtifacts()) {
cp += File.pathSeparator + dep.getFile().getAbsolutePath();
}
logger.debug("EvoSuite classpath: " + cp);
String entryPoint = EvoSuite.class.getName();
List<String> cmd = new ArrayList<>();
cmd.add(JavaExecCmdUtil.getJavaBinExecutablePath());
cmd.add("-D" + LoggingUtils.USE_DIFFERENT_LOGGING_XML_PARAMETER + "=logback-ctg-entry.xml");
cmd.add("-Dlogback.configurationFile=logback-ctg-entry.xml");
cmd.add("-cp");
cmd.add(cp);
cmd.add(entryPoint);
return cmd;
}
use of org.apache.maven.project.DefaultProjectBuildingRequest in project syndesis by syndesisio.
the class ExtractConnectorDescriptorsMojo method execute.
@Override
@SuppressWarnings({ "PMD.EmptyCatchBlock", "PMD.CyclomaticComplexity" })
public void execute() throws MojoExecutionException, MojoFailureException {
ArrayNode root = new ArrayNode(JsonNodeFactory.instance);
URLClassLoader classLoader = null;
try {
PluginDescriptor desc = (PluginDescriptor) getPluginContext().get("pluginDescriptor");
List<Artifact> artifacts = desc.getArtifacts();
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(remoteRepositories);
for (Artifact artifact : artifacts) {
ArtifactResult result = artifactResolver.resolveArtifact(buildingRequest, artifact);
File jar = result.getArtifact().getFile();
classLoader = createClassLoader(jar);
if (classLoader == null) {
throw new IOException("Can not create classloader for " + jar);
}
ObjectNode entry = new ObjectNode(JsonNodeFactory.instance);
addConnectorMeta(entry, classLoader);
addComponentMeta(entry, classLoader);
if (entry.size() > 0) {
addGav(entry, artifact);
root.add(entry);
}
}
if (root.size() > 0) {
saveCamelMetaData(root);
}
} catch (ArtifactResolverException | IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
} finally {
if (classLoader != null) {
try {
classLoader.close();
} catch (IOException ignored) {
}
}
}
}
use of org.apache.maven.project.DefaultProjectBuildingRequest in project tycho by eclipse.
the class TargetPlatformFilterConfigurationReaderTest method projectBuildRequestForUnitTest.
DefaultProjectBuildingRequest projectBuildRequestForUnitTest() {
DefaultProjectBuildingRequest projectBuildingRequest = new DefaultProjectBuildingRequest();
Properties userProperties = new Properties();
userProperties.put("tycho-version", TychoVersion.getTychoVersion());
projectBuildingRequest.setUserProperties(userProperties);
// this disables the expansion of packaging types (which are undefined at this point in the build)
projectBuildingRequest.setProcessPlugins(false);
return projectBuildingRequest;
}
Aggregations