List of usage examples for org.apache.maven.project MavenProject createArtifacts
@Deprecated public Set<Artifact> createArtifacts(ArtifactFactory artifactFactory, String inheritedScope, ArtifactFilter filter) throws InvalidDependencyVersionException
From source file:com.github.wix_maven.PatchMojo.java
License:Apache License
protected Set<Artifact> resolveDependencyArtifacts(MavenProject theProject) throws ArtifactResolutionException, ArtifactNotFoundException, InvalidDependencyVersionException { Set<Artifact> artifacts = theProject.createArtifacts(this.factory, null, new ScopeArtifactFilter(Artifact.SCOPE_COMPILE)); // doubt: scope if not null is ignoring the Provided scope elements - all examples show using some scope getLog().info("Checking " + artifacts.size() + " dependents of " + theProject.getId()); for (Artifact artifact : artifacts) { getLog().debug("Checking dependent " + artifact.getId()); // resolve the new artifact this.resolver.resolve(artifact, this.remoteArtifactRepositories, this.localRepository); }/*from w w w.ja v a2s. c o m*/ return artifacts; }
From source file:com.google.code.play2.plugin.AbstractPlay2Mojo.java
License:Apache License
/** * This method resolves the dependency artifacts from the project. * /* ww w .j a va2 s. c o m*/ * @param theProject The POM. * @return resolved set of dependency artifacts. * @throws ArtifactResolutionException * @throws ArtifactNotFoundException * @throws InvalidDependencyVersionException */ private Set<Artifact> resolveDependencyArtifacts(MavenProject theProject) throws ArtifactNotFoundException, ArtifactResolutionException, InvalidDependencyVersionException { AndArtifactFilter filter = new AndArtifactFilter(); filter.add(new ScopeArtifactFilter(Artifact.SCOPE_TEST)); filter.add(new NonOptionalArtifactFilter()); // TODO follow the dependenciesManagement and override rules Set<Artifact> artifacts = theProject.createArtifacts(factory, Artifact.SCOPE_RUNTIME, filter); for (Artifact artifact : artifacts) { resolver.resolve(artifact, remoteRepos, localRepo); } return artifacts; }
From source file:com.googlecode.Artifact.java
License:Apache License
/** * Will fetch a list of all the transitive dependencies for an artifact and * return a set of those artifacts.// w ww. j a v a 2 s. c o m * * @param artifact * The artifact for which transitive dependencies need to be * downloaded. * @return The set of dependencies that was dependant. * @throws MojoFailureException * If anything goes wrong when getting transitive dependency. * Note : Suppress warning used for the uncheck cast of artifact * set. */ @SuppressWarnings("unchecked") private Set<org.apache.maven.artifact.Artifact> getTransitiveDependency( org.apache.maven.artifact.Artifact artifact) throws MojoFailureException { try { org.apache.maven.artifact.Artifact pomArtifact = artifactFactory.createArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getClassifier(), "pom"); MavenProject pomProject = mavenProjectBuilder.buildFromRepository(pomArtifact, this.remoteRepositories, this.localRepository); Set<org.apache.maven.artifact.Artifact> dependents = pomProject.createArtifacts(this.artifactFactory, null, null); ArtifactResolutionResult result = resolver.resolveTransitively(dependents, pomArtifact, this.localRepository, this.remoteRepositories, this.metadatSource, null); if (result != null) { getLog().debug("Found transitive dependency : " + result); return result.getArtifacts(); } } catch (ArtifactResolutionException e) { getLog().debug("Could not resolved the dependency", e); throw new MojoFailureException("Could not resolved the dependency : " + e.getMessage()); } catch (ArtifactNotFoundException e) { getLog().debug("Could not find the dependency", e); throw new MojoFailureException("Could not find the dependency : " + e.getMessage()); } catch (ProjectBuildingException e) { getLog().debug("Error Creating the pom project for artifact : " + artifact, e); throw new MojoFailureException("Error getting transitive dependencies : " + e.getMessage()); } catch (InvalidDependencyVersionException e) { getLog().debug("Error Creating the pom project for artifact : " + artifact, e); throw new MojoFailureException("Error getting transitive dependencies : " + e.getMessage()); } return null; }
From source file:com.luke.maven.plugins.Dependencies.java
License:Apache License
private void resolveDependencies(MavenProject p) throws ProjectBuildingException { count++;// ww w.j a v a 2 s . c om Set<Artifact> artifacts = p.createArtifacts(factory, Artifact.LATEST_VERSION, null); for (Artifact a : artifacts) { System.out.println( tabGen(count) + "+- " + a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion()); MavenProject pomProject = mavenProjectBuilder.buildFromRepository(a, remoteRepos, local); resolveDependencies(pomProject); } count--; }
From source file:com.technophobia.substeps.runner.ForkedRunner.java
License:Open Source License
@SuppressWarnings("unchecked") private List<String> resolveStepImplementationArtifacts() throws MojoExecutionException { final List<String> stepImplementationArtifactJars = Lists.newArrayList(); if (this.stepImplementationArtifacts != null) { for (final String stepImplementationArtifactString : this.stepImplementationArtifacts) { final String[] artifactDetails = stepImplementationArtifactString.split(":"); if (artifactDetails.length != 3) { throw new MojoExecutionException( "Invalid artifact format found in substepImplementationArtifact, must be in format groupId:artifactId:version but was '" + stepImplementationArtifactString + "'"); }/* ww w. j a v a 2 s. c o m*/ try { final Artifact stepImplementationJarArtifact = this.artifactFactory.createArtifact( artifactDetails[0], artifactDetails[1], artifactDetails[2], "test", "jar"); this.artifactResolver.resolve(stepImplementationJarArtifact, this.remoteRepositories, this.localRepository); addArtifactPath(stepImplementationArtifactJars, stepImplementationJarArtifact); final Artifact stepImplementationPomArtifact = this.artifactFactory.createArtifact( artifactDetails[0], artifactDetails[1], artifactDetails[2], "test", "pom"); this.artifactResolver.resolve(stepImplementationPomArtifact, this.remoteRepositories, this.localRepository); final MavenProject stepImplementationProject = this.mavenProjectBuilder.buildFromRepository( stepImplementationPomArtifact, this.remoteRepositories, this.localRepository); final Set<Artifact> stepImplementationArtifacts = stepImplementationProject .createArtifacts(this.artifactFactory, null, null); final Set<Artifact> transitiveDependencies = this.artifactResolver .resolveTransitively(stepImplementationArtifacts, stepImplementationPomArtifact, stepImplementationProject.getManagedVersionMap(), this.localRepository, this.remoteRepositories, this.artifactMetadataSource) .getArtifacts(); for (final Artifact transitiveDependency : transitiveDependencies) { addArtifactPath(stepImplementationArtifactJars, transitiveDependency); } } catch (final ArtifactResolutionException e) { throw new MojoExecutionException("Unable to resolve artifact for substep implementation '" + stepImplementationArtifactString + "'", e); } catch (final ProjectBuildingException e) { throw new MojoExecutionException("Unable to resolve artifact for substep implementation '" + stepImplementationArtifactString + "'", e); } catch (final InvalidDependencyVersionException e) { throw new MojoExecutionException("Unable to resolve artifact for substep implementation '" + stepImplementationArtifactString + "'", e); } catch (final ArtifactNotFoundException e) { throw new MojoExecutionException("Unable to resolve artifact for substep implementation '" + stepImplementationArtifactString + "'", e); } } } return stepImplementationArtifactJars; }
From source file:com.xpn.xwiki.tool.xar.AbstractXarMojo.java
License:Open Source License
/** * @param pomProject the project/*from www . j a v a 2 s.c om*/ * @return set of dependencies * @throws ArtifactResolutionException error * @throws ArtifactNotFoundException error * @throws InvalidDependencyVersionException error */ protected Set<Artifact> resolveDependencyArtifacts(MavenProject pomProject) throws ArtifactResolutionException, ArtifactNotFoundException, InvalidDependencyVersionException { AndArtifactFilter filters = new AndArtifactFilter(); filters.add(new TypeArtifactFilter("xar")); filters.add(new ScopeArtifactFilter(DefaultArtifact.SCOPE_RUNTIME)); Set<Artifact> artifacts = pomProject.createArtifacts(this.factory, Artifact.SCOPE_TEST, filters); for (Artifact artifact : artifacts) { // resolve the new artifact this.resolver.resolve(artifact, this.remoteRepos, this.local); } return artifacts; }
From source file:eu.monnetproject.framework.bndannotation.BNDAnnotationProcessor.java
License:Apache License
private void resolveClassLoader() throws Exception { final Artifact pomArtifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), null, "pom"); final MavenProject pomProject = mavenProjectBuilder.buildFromRepository(pomArtifact, remoteRepositories, localRepository);// w w w . j ava 2s . c om final Set<?> resolvedArtifacts = pomProject.createArtifacts(this.artifactFactory, null, null); final ArtifactFilter filter = new ScopeArtifactFilter("compile"); final ArtifactResolutionResult arr = resolver.resolveTransitively(resolvedArtifacts, pomArtifact, pomProject.getManagedVersionMap(), localRepository, remoteRepositories, artifactMetadataSource, filter); @SuppressWarnings("unchecked") Set<Artifact> artifacts = arr.getArtifacts(); Set<URL> urls = new HashSet<URL>(); for (Artifact artifact : artifacts) { urls.add(artifact.getFile().toURI().toURL()); } URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class<URLClassLoader> sysclass = URLClassLoader.class; try { Method method = sysclass.getDeclaredMethod("addURL", new Class<?>[] { URL.class }); method.setAccessible(true); for (URL url : urls) { method.invoke(sysloader, new Object[] { url }); } } catch (Throwable t) { t.printStackTrace(); throw new IOException("Error, could not add URL to system classloader"); } }
From source file:info.jtrac.maven.AntPropsMojo.java
License:Apache License
/** * resolve dependencies for the given artifact details using Maven, on the fly *///from w ww .j a v a 2 s . com private Collection resolveDependencies(String groupId, String artifactId, String version) throws Exception { Artifact pomArtifact = getArtifact(groupId, artifactId, version); MavenProject pomProject = mavenProjectBuilder.buildFromRepository(pomArtifact, remoteArtifactRepositories, localRepository); Collection artifacts = pomProject.createArtifacts(artifactFactory, Artifact.SCOPE_TEST, new ScopeArtifactFilter(Artifact.SCOPE_TEST)); Iterator i = artifacts.iterator(); while (i.hasNext()) { Artifact a = (Artifact) i.next(); resolveArtifact(a); } artifacts.add(pomArtifact); return artifacts; }
From source file:npanday.resolver.NPandayDependencyResolution.java
License:Apache License
private void createArtifactsForMaven2BackCompat(MavenProject project) throws InvalidDependencyVersionException { if (getLogger().isDebugEnabled()) { getLogger().debug("NPANDAY-148-008: creating dependency collection for maven 2 projects"); }/*from w w w .ja va 2 s. c o m*/ project.setDependencyArtifacts(project.createArtifacts(artifactFactory, null, null)); }
From source file:org.apache.felix.bundleplugin.BundleAllPlugin.java
License:Apache License
/** * Bundle a project and its transitive dependencies up to some depth level * // w w w. j av a2 s .c om * @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 (ProjectBuildingException e) { throw new MojoExecutionException("Unable to build project object for artifact " + artifact, e); } catch (InvalidDependencyVersionException e) { throw new MojoExecutionException("Invalid dependency version for artifact " + artifact); } 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); }