use of org.apache.maven.artifact.Artifact in project camel by apache.
the class RunMojo method addRelevantPluginDependenciesToClasspath.
/**
* Add any relevant project dependencies to the classpath. Indirectly takes
* includePluginDependencies and ExecutableDependency into consideration.
*
* @param path classpath of {@link java.net.URL} objects
* @throws MojoExecutionException
*/
private void addRelevantPluginDependenciesToClasspath(Set<URL> path) throws MojoExecutionException {
if (hasCommandlineArgs()) {
arguments = parseCommandlineArgs();
}
try {
Iterator<Artifact> iter = this.determineRelevantPluginDependencies().iterator();
while (iter.hasNext()) {
Artifact classPathElement = iter.next();
// java.lang.NoClassDefFoundError: org.osgi.vendor.framework property not set
if (classPathElement.getArtifactId().equals("org.osgi.core")) {
getLog().debug("Skipping org.osgi.core -> " + classPathElement.getGroupId() + "/" + classPathElement.getArtifactId() + "/" + classPathElement.getVersion());
continue;
}
getLog().debug("Adding plugin dependency artifact: " + classPathElement.getArtifactId() + " to classpath");
path.add(classPathElement.getFile().toURI().toURL());
}
} catch (MalformedURLException e) {
throw new MojoExecutionException("Error during setting up classpath", e);
}
}
use of org.apache.maven.artifact.Artifact 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.Artifact 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.Artifact in project camel by apache.
the class RunMojo method addRelevantProjectDependenciesToClasspath.
/**
* Add any relevant project dependencies to the classpath. Takes
* includeProjectDependencies into consideration.
*
* @param path classpath of {@link java.net.URL} objects
* @throws org.apache.maven.plugin.MojoExecutionException
*/
private void addRelevantProjectDependenciesToClasspath(List<URL> path) throws MojoExecutionException {
if (this.includeProjectDependencies) {
try {
getLog().debug("Project Dependencies will be included.");
URL mainClasses = new File(project.getBuild().getOutputDirectory()).toURI().toURL();
getLog().debug("Adding to classpath : " + mainClasses);
path.add(mainClasses);
Set<Artifact> dependencies = CastUtils.cast(project.getArtifacts());
// system scope dependencies are not returned by maven 2.0. See
// MEXEC-17
dependencies.addAll(getAllNonTestScopedDependencies());
Iterator<Artifact> iter = dependencies.iterator();
while (iter.hasNext()) {
Artifact classPathElement = iter.next();
getLog().debug("Adding project dependency artifact: " + classPathElement.getArtifactId() + " to classpath");
File file = classPathElement.getFile();
if (file != null) {
path.add(file.toURI().toURL());
}
}
} catch (MalformedURLException e) {
throw new MojoExecutionException("Error during setting up classpath", e);
}
} else {
getLog().debug("Project Dependencies will be excluded.");
}
}
use of org.apache.maven.artifact.Artifact in project camel by apache.
the class RunMojo method getAllDependencies.
// generic method to retrieve all the transitive dependencies
private Collection<Artifact> getAllDependencies() throws MojoExecutionException {
List<Artifact> artifacts = new ArrayList<Artifact>();
for (Iterator<?> dependencies = project.getDependencies().iterator(); dependencies.hasNext(); ) {
Dependency dependency = (Dependency) dependencies.next();
String groupId = dependency.getGroupId();
String artifactId = dependency.getArtifactId();
VersionRange versionRange;
try {
versionRange = VersionRange.createFromVersionSpec(dependency.getVersion());
} catch (InvalidVersionSpecificationException e) {
throw new MojoExecutionException("unable to parse version", e);
}
String type = dependency.getType();
if (type == null) {
type = "jar";
}
String classifier = dependency.getClassifier();
boolean optional = dependency.isOptional();
String scope = dependency.getScope();
if (scope == null) {
scope = Artifact.SCOPE_COMPILE;
}
Artifact art = this.artifactFactory.createDependencyArtifact(groupId, artifactId, versionRange, type, classifier, scope, null, optional);
if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) {
art.setFile(new File(dependency.getSystemPath()));
}
List<String> exclusions = new ArrayList<String>();
for (Exclusion exclusion : dependency.getExclusions()) {
exclusions.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId());
}
ArtifactFilter newFilter = new ExcludesArtifactFilter(exclusions);
art.setDependencyFilter(newFilter);
artifacts.add(art);
}
return artifacts;
}
Aggregations