use of org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter in project randomizedtesting by randomizedtesting.
the class JUnit4Mojo method setupTestClasspath.
/**
* Setup the classpath used for tests.
*/
private void setupTestClasspath(Element junit4) {
junit4.addComment("Runtime classpath.");
Element cp = junit4.addElement("classpath");
// Test classes.
cp.addComment("Test classes directory.");
cp.addElement("pathelement").addAttribute("location", testClassesDirectory.getAbsolutePath());
// Classes directory.
cp.addComment("Test classes directory.");
cp.addElement("pathelement").addAttribute("location", classesDirectory.getAbsolutePath());
// Project dependencies.
cp.addComment("Project dependencies.");
Set<Artifact> classpathArtifacts = (Set<Artifact>) project.getArtifacts();
if (!Strings.isNullOrEmpty(classpathDependencyScopeExclude)) {
classpathArtifacts = filterArtifacts(cp, classpathArtifacts, new ScopeArtifactFilter(classpathDependencyScopeExclude));
}
if (classpathDependencyExcludes != null && !classpathDependencyExcludes.isEmpty()) {
classpathArtifacts = filterArtifacts(cp, classpathArtifacts, new PatternIncludesArtifactFilter(classpathDependencyExcludes));
}
for (Artifact artifact : classpathArtifacts) {
if (artifact.getArtifactHandler().isAddedToClasspath()) {
File file = artifact.getFile();
if (file != null) {
cp.addComment("Dependency artifact: " + artifact.getId());
cp.addElement("pathelement").addAttribute("location", file.getAbsolutePath());
}
}
}
// Additional dependencies.
cp.addComment("Additional classpath elements.");
if (additionalClasspathElements != null && !additionalClasspathElements.isEmpty()) {
for (String classpathElement : additionalClasspathElements) {
if (!Strings.isNullOrEmpty(classpathElement)) {
cp.addElement("pathelement").addAttribute("location", classpathElement);
}
}
}
}
use of org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter in project camel by apache.
the class RunMojo method determineRelevantPluginDependencies.
/**
* Determine all plugin dependencies relevant to the executable. Takes
* includePlugins, and the executableDependency into consideration.
*
* @return a set of Artifact objects. (Empty set is returned if there are no
* relevant plugin dependencies.)
* @throws MojoExecutionException
*/
private Set<Artifact> determineRelevantPluginDependencies() throws MojoExecutionException {
Set<Artifact> relevantDependencies;
if (this.includePluginDependencies) {
if (this.executableDependency == null) {
getLog().debug("All Plugin Dependencies will be included.");
relevantDependencies = new HashSet<Artifact>(this.pluginDependencies);
} else {
getLog().debug("Selected plugin Dependencies will be included.");
Artifact executableArtifact = this.findExecutableArtifact();
Artifact executablePomArtifact = this.getExecutablePomArtifact(executableArtifact);
relevantDependencies = this.resolveExecutableDependencies(executablePomArtifact, false);
}
} else {
getLog().debug("Only Direct Plugin Dependencies will be included.");
PluginDescriptor descriptor = (PluginDescriptor) getPluginContext().get("pluginDescriptor");
try {
relevantDependencies = artifactResolver.resolveTransitively(MavenMetadataSource.createArtifacts(this.artifactFactory, descriptor.getPlugin().getDependencies(), null, null, null), this.project.getArtifact(), Collections.emptyMap(), this.localRepository, this.remoteRepositories, metadataSource, new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME), Collections.emptyList()).getArtifacts();
} catch (Exception ex) {
throw new MojoExecutionException("Encountered problems resolving dependencies of the plugin " + "in preparation for its execution.", ex);
}
}
return relevantDependencies;
}
use of org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter in project camel by apache.
the class RunMojo method resolveExecutableDependencies.
private Set<Artifact> resolveExecutableDependencies(Artifact executablePomArtifact, boolean ignoreFailures) throws MojoExecutionException {
Set<Artifact> executableDependencies = null;
try {
MavenProject executableProject = this.projectBuilder.buildFromRepository(executablePomArtifact, this.remoteRepositories, this.localRepository);
// get all of the dependencies for the executable project
List<Artifact> dependencies = CastUtils.cast(executableProject.getDependencies());
// make Artifacts of all the dependencies
Set<Artifact> dependencyArtifacts = CastUtils.cast(MavenMetadataSource.createArtifacts(this.artifactFactory, dependencies, null, null, null));
// not forgetting the Artifact of the project itself
dependencyArtifacts.add(executableProject.getArtifact());
// resolve runtime dependencies transitively to obtain a comprehensive list of assemblies
ArtifactResolutionResult result = artifactResolver.resolveTransitively(dependencyArtifacts, executablePomArtifact, Collections.emptyMap(), this.localRepository, this.remoteRepositories, metadataSource, new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME), Collections.emptyList());
executableDependencies = CastUtils.cast(result.getArtifacts());
} catch (Exception ex) {
if (ignoreFailures) {
getLog().debug("Ignoring maven resolving dependencies failure " + ex.getMessage());
} else {
throw new MojoExecutionException("Encountered problems resolving dependencies of the executable " + "in preparation for its execution.", ex);
}
}
return executableDependencies;
}
use of org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter in project camel by apache.
the class SpringBootStarterMojo method filterIncludedArtifacts.
private Set<String> filterIncludedArtifacts(Set<String> artifacts) throws DependencyTreeBuilderException {
Set<String> included = new TreeSet<>();
ArtifactFilter artifactFilter = new ScopeArtifactFilter(null);
DependencyNode node = treeBuilder.buildDependencyTree(project, localRepository, artifactFactory, artifactMetadataSource, artifactFilter, artifactCollector);
CollectingDependencyNodeVisitor visitor = new CollectingDependencyNodeVisitor();
node.accept(visitor);
List<DependencyNode> nodes = visitor.getNodes();
for (DependencyNode dependencyNode : nodes) {
Artifact artifact = dependencyNode.getArtifact();
getLog().debug("Found dependency node: " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + " - scope=" + artifact.getScope());
if (!Artifact.SCOPE_TEST.equals(artifact.getScope()) && !Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) {
String canonicalName = artifact.getGroupId() + ":" + artifact.getArtifactId();
if (artifacts.contains(canonicalName)) {
getLog().debug(canonicalName + " marked for exclusion");
included.add(canonicalName);
}
}
}
return included;
}
use of org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter in project maven-plugins by apache.
the class TreeMojo method createResolvingArtifactFilter.
// private methods --------------------------------------------------------
/**
* Gets the artifact filter to use when resolving the dependency tree.
*
* @return the artifact filter
*/
private ArtifactFilter createResolvingArtifactFilter() {
ArtifactFilter filter;
// filter scope
if (scope != null) {
getLog().debug("+ Resolving dependency tree for scope '" + scope + "'");
filter = new ScopeArtifactFilter(scope);
} else {
filter = null;
}
return filter;
}
Aggregations