use of org.apache.maven.project.artifact.InvalidDependencyVersionException in project felix by apache.
the class BundleAllPlugin method bundleAll.
/**
* Bundle a project and its transitive dependencies up to some depth level
*
* @param project
* @param maxDepth how deep to process the dependency tree
* @throws MojoExecutionException
*/
protected BundleInfo bundleAll(MavenProject project, int maxDepth) throws MojoExecutionException {
if (alreadyBundled(project.getArtifact())) {
getLog().debug("Ignoring project already processed " + project.getArtifact());
return null;
}
if (m_artifactsBeingProcessed.contains(project.getArtifact())) {
getLog().warn("Ignoring artifact due to dependency cycle " + project.getArtifact());
return null;
}
m_artifactsBeingProcessed.add(project.getArtifact());
DependencyNode dependencyTree;
try {
dependencyTree = m_dependencyTreeBuilder.buildDependencyTree(project, localRepository, m_factory, m_artifactMetadataSource, null, m_collector);
} catch (DependencyTreeBuilderException e) {
throw new MojoExecutionException("Unable to build dependency tree", e);
}
BundleInfo bundleInfo = new BundleInfo();
if (!dependencyTree.hasChildren()) {
/* no need to traverse the tree */
return bundleRoot(project, bundleInfo);
}
getLog().debug("Will bundle the following dependency tree" + LS + dependencyTree);
for (Iterator it = dependencyTree.inverseIterator(); it.hasNext(); ) {
DependencyNode node = (DependencyNode) it.next();
if (!it.hasNext()) {
/* this is the root, current project */
break;
}
if (node.getState() != DependencyNode.INCLUDED) {
continue;
}
if (Artifact.SCOPE_SYSTEM.equals(node.getArtifact().getScope())) {
getLog().debug("Ignoring system scoped artifact " + node.getArtifact());
continue;
}
Artifact artifact;
try {
artifact = resolveArtifact(node.getArtifact());
} catch (ArtifactNotFoundException e) {
if (ignoreMissingArtifacts) {
continue;
}
throw new MojoExecutionException("Artifact was not found in the repo" + node.getArtifact(), e);
}
node.getArtifact().setFile(artifact.getFile());
int nodeDepth = node.getDepth();
if (nodeDepth > maxDepth) {
/* node is deeper than we want */
getLog().debug("Ignoring " + node.getArtifact() + ", depth is " + nodeDepth + ", bigger than " + maxDepth);
continue;
}
MavenProject childProject;
try {
childProject = m_mavenProjectBuilder.buildFromRepository(artifact, remoteRepositories, localRepository, true);
if (childProject.getDependencyArtifacts() == null) {
childProject.setDependencyArtifacts(childProject.createArtifacts(m_factory, null, null));
}
} catch (InvalidDependencyVersionException e) {
throw new MojoExecutionException("Invalid dependency version for artifact " + artifact);
} catch (ProjectBuildingException e) {
throw new MojoExecutionException("Unable to build project object for artifact " + artifact, e);
}
childProject.setArtifact(artifact);
getLog().debug("Child project artifact location: " + childProject.getArtifact().getFile());
if ((Artifact.SCOPE_COMPILE.equals(artifact.getScope())) || (Artifact.SCOPE_RUNTIME.equals(artifact.getScope()))) {
BundleInfo subBundleInfo = bundleAll(childProject, maxDepth - 1);
if (subBundleInfo != null) {
bundleInfo.merge(subBundleInfo);
}
} else {
getLog().debug("Not processing due to scope (" + childProject.getArtifact().getScope() + "): " + childProject.getArtifact());
}
}
return bundleRoot(project, bundleInfo);
}
use of org.apache.maven.project.artifact.InvalidDependencyVersionException in project maven-plugins by apache.
the class ProcessRemoteResourcesMojo method aggregateProjectDependencyArtifacts.
@SuppressWarnings("unchecked")
private Set<Artifact> aggregateProjectDependencyArtifacts() throws MojoExecutionException {
Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
List<MavenProject> projects = mavenSession.getSortedProjects();
for (MavenProject p : projects) {
if (p.getDependencyArtifacts() == null) {
try {
Set<Artifact> depArtifacts = p.createArtifacts(artifactFactory, null, null);
if (depArtifacts != null && !depArtifacts.isEmpty()) {
for (Artifact artifact : depArtifacts) {
if (artifact.getVersion() == null && artifact.getVersionRange() != null) {
// Version is required for equality comparison between artifacts,
// but it is not needed for our purposes of filtering out
// transitive dependencies (which requires only groupId/artifactId).
// Therefore set an arbitrary version if missing.
artifact.setResolvedVersion(Artifact.LATEST_VERSION);
}
artifacts.add(artifact);
}
}
} catch (InvalidDependencyVersionException e) {
throw new MojoExecutionException("Failed to create dependency artifacts for: " + p.getId() + ". Reason: " + e.getMessage(), e);
}
}
}
return artifacts;
}
use of org.apache.maven.project.artifact.InvalidDependencyVersionException in project maven-plugins by apache.
the class AbstractJavadocMojo method getClasspath.
/**
* Method that sets the classpath elements that will be specified in the javadoc <code>-classpath</code>
* parameter. Since we have all the sources of the current reactor, it is sufficient to consider the
* dependencies of the reactor modules, excluding the module artifacts which may not yet be available
* when the reactor project is built for the first time.
*
* @return a String that contains the concatenated classpath elements, separated by the System pathSeparator
* string (colon (<code>:</code>) on Solaris or semi-colon (<code>;</code>) on Windows).
* @throws MavenReportException if any.
* @see File#pathSeparator
*/
private String getClasspath() throws MavenReportException {
List<String> classpathElements = new ArrayList<String>();
Map<String, Artifact> compileArtifactMap = new HashMap<String, Artifact>();
if (isTest()) {
classpathElements.addAll(getProjectBuildOutputDirs(project));
}
populateCompileArtifactMap(compileArtifactMap, getProjectArtifacts(project));
if (isAggregator() && project.isExecutionRoot()) {
List<Artifact> reactorArtifacts = new ArrayList<Artifact>();
for (MavenProject p : reactorProjects) {
reactorArtifacts.add(p.getArtifact());
}
try {
for (MavenProject subProject : reactorProjects) {
if (subProject != project) {
classpathElements.addAll(getProjectBuildOutputDirs(subProject));
Set<Artifact> dependencyArtifacts = subProject.createArtifacts(factory, null, null);
// do not attempt to resolve artifacts of the current reactor which may not exist yet
dependencyArtifacts.removeAll(reactorArtifacts);
if (!dependencyArtifacts.isEmpty()) {
ArtifactResolutionResult result = null;
try {
result = resolver.resolveTransitively(dependencyArtifacts, subProject.getArtifact(), subProject.getManagedVersionMap(), localRepository, subProject.getRemoteArtifactRepositories(), artifactMetadataSource);
} catch (ArtifactNotFoundException e) {
throw new MavenReportException(e.getMessage(), e);
} catch (ArtifactResolutionException e) {
throw new MavenReportException(e.getMessage(), e);
}
if (result == null) {
continue;
}
populateCompileArtifactMap(compileArtifactMap, getCompileArtifacts(result.getArtifacts()));
if (getLog().isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
sb.append("Compiled artifacts for ");
sb.append(subProject.getGroupId()).append(":");
sb.append(subProject.getArtifactId()).append(":");
sb.append(subProject.getVersion()).append('\n');
for (Artifact a : compileArtifactMap.values()) {
sb.append(a.getFile()).append('\n');
}
getLog().debug(sb.toString());
}
}
}
}
} catch (InvalidDependencyVersionException e) {
throw new MavenReportException(e.getMessage(), e);
}
}
for (Artifact a : compileArtifactMap.values()) {
classpathElements.add(a.getFile().toString());
}
if (additionalDependencies != null) {
for (Dependency dependency : additionalDependencies) {
Artifact artifact = resolveDependency(dependency);
String path = artifact.getFile().toString();
getLog().debug("add additional artifact with path " + path);
classpathElements.add(path);
}
}
return StringUtils.join(classpathElements.iterator(), File.pathSeparator);
}
use of org.apache.maven.project.artifact.InvalidDependencyVersionException in project wso2-synapse by wso2.
the class AbstractXarMojo method getSynapseRuntimeArtifacts.
/**
* Get the set of artifacts that are provided by Synapse at runtime.
*
* @return
* @throws MojoExecutionException
*/
private Set<Artifact> getSynapseRuntimeArtifacts() throws MojoExecutionException {
Log log = getLog();
log.debug("Looking for synapse-core artifact in XAR project dependencies ...");
Artifact synapseCore = null;
for (Iterator<?> it = project.getDependencyArtifacts().iterator(); it.hasNext(); ) {
Artifact artifact = (Artifact) it.next();
if (artifact.getGroupId().equals("org.apache.synapse") && artifact.getArtifactId().equals("synapse-core")) {
synapseCore = artifact;
break;
}
}
if (synapseCore == null) {
throw new MojoExecutionException("Could not locate dependency on synapse-core");
}
log.debug("Loading project data for " + synapseCore + " ...");
MavenProject synapseCoreProject;
try {
synapseCoreProject = projectBuilder.buildFromRepository(synapseCore, remoteArtifactRepositories, localRepository);
} catch (ProjectBuildingException e) {
throw new MojoExecutionException("Unable to retrieve project information for " + synapseCore, e);
}
Set<Artifact> synapseRuntimeDeps;
try {
synapseRuntimeDeps = synapseCoreProject.createArtifacts(artifactFactory, Artifact.SCOPE_RUNTIME, new TypeArtifactFilter("jar"));
} catch (InvalidDependencyVersionException e) {
throw new MojoExecutionException("Unable to get project dependencies for " + synapseCore, e);
}
log.debug("Direct runtime dependencies for " + synapseCore + " :");
logArtifacts(synapseRuntimeDeps);
log.debug("Resolving transitive dependencies for " + synapseCore + " ...");
try {
synapseRuntimeDeps = artifactCollector.collect(synapseRuntimeDeps, synapseCoreProject.getArtifact(), synapseCoreProject.getManagedVersionMap(), localRepository, remoteArtifactRepositories, artifactMetadataSource, null, Collections.singletonList(new DebugResolutionListener(logger))).getArtifacts();
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException("Unable to resolve transitive dependencies for " + synapseCore);
}
log.debug("All runtime dependencies for " + synapseCore + " :");
logArtifacts(synapseRuntimeDeps);
return synapseRuntimeDeps;
}
Aggregations