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:org.sonatype.flexmojos.war.CopyMojo.java
License:Apache License
private void performSubArtifactsCopy(Artifact artifact) throws MojoExecutionException { MavenProject artifactProject = getProject(artifact); if (artifactProject != null) { try {//from w ww .j av a 2s . com artifactProject.setArtifacts(artifactProject.createArtifacts(artifactFactory, null, null)); } catch (InvalidDependencyVersionException e) { throw new MojoExecutionException("Error resolving artifacts " + artifact, e); } if (copyRSL) { performRslCopy(artifactProject); } if (copyRuntimeLocales) { performRuntimeLocalesCopy(artifactProject); } } }
From source file:org.sonatype.plugin.nexus.testenvironment.AbstractEnvironmentMojo.java
License:Open Source License
@SuppressWarnings("unchecked") private Collection<Artifact> getNonTransitivePlugins(Set<Artifact> projectArtifacts) throws MojoExecutionException { Collection<Artifact> deps = new LinkedHashSet<Artifact>(); for (Artifact artifact : projectArtifacts) { Artifact pomArtifact = artifactFactory.createArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getClassifier(), "pom"); Set<Artifact> result; try {/* w w w. j a va 2 s . co m*/ MavenProject pomProject = mavenProjectBuilder.buildFromRepository(pomArtifact, remoteRepositories, localRepository); Set<Artifact> artifacts = pomProject.createArtifacts(artifactFactory, null, null); artifacts = filterOutSystemDependencies(artifacts); ArtifactResolutionResult arr = resolver.resolveTransitively(artifacts, pomArtifact, localRepository, remoteRepositories, artifactMetadataSource, null); result = arr.getArtifacts(); } catch (Exception e) { throw new MojoExecutionException("Failed to resolve non-transitive deps " + e.getMessage(), e); } LinkedHashSet<Artifact> plugins = new LinkedHashSet<Artifact>(); plugins.addAll(filtterArtifacts(result, getFilters(null, null, "nexus-plugin", null))); plugins.addAll(filtterArtifacts(result, getFilters(null, null, "zip", "bundle"))); plugins.addAll(getNonTransitivePlugins(plugins)); if (!plugins.isEmpty()) { getLog().debug("Adding non-transitive dependencies for: " + artifact + " -\n" + plugins.toString().replace(',', '\n')); } deps.addAll(plugins); } return deps; }
From source file:org_scala_tools_maven.ScalaMojoSupport.java
License:Apache License
/** * This method resolves the dependency artifacts from the project. * * @param theProject The POM.//w ww . j av a 2 s . c o m * @return resolved set of dependency artifacts. * * @throws ArtifactResolutionException * @throws ArtifactNotFoundException * @throws InvalidDependencyVersionException */ @SuppressWarnings("unchecked") protected Set<Artifact> resolveDependencyArtifacts(MavenProject theProject) throws Exception { AndArtifactFilter filter = new AndArtifactFilter(); filter.add(new ScopeArtifactFilter(Artifact.SCOPE_TEST)); filter.add(new ArtifactFilter() { public boolean include(Artifact artifact) { return !artifact.isOptional(); } }); //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:uk.ac.ox.oucs.plugins.DiscoverMojo.java
License:Apache License
protected void deployAndDependents(Set<Artifact> artifacts) throws MojoExecutionException, MojoFailureException { loadCachedImplentations();// w ww.ja v a2 s . c o m try { toDeploy.addAll(artifacts); do { ArtifactResolutionResult arr = customResolver.resolveTransitively(artifacts, project.getArtifact(), localRepository, remoteRepositories, customMetadataSource, null); Set<Artifact> resolvedArtifacts = arr.getArtifacts(); Set<ResolutionNode> arrRes = arr.getArtifactResolutionNodes(); for (ResolutionNode node : arrRes) { getLog().info(node.getArtifact().getArtifactId()); for (String artifactId : (List<String>) node.getDependencyTrail()) { getLog().info(" +" + artifactId); } } Set<Artifact> artifactsToFind = new HashSet<Artifact>(); for (Artifact artifact : resolvedArtifacts) { if (needsImplementation(artifact)) { getLog().debug("Needed : " + artifact.toString() + " " + artifact.getDependencyTrail()); artifactsToFind.add(artifact); } else { getLog().debug("Ignored : " + artifact.toString() + " " + artifact.getDependencyTrail()); } } artifacts = new HashSet<Artifact>(); for (Artifact artifact : artifactsToFind) { String artifactKey = artifact.getGroupId() + ":" + artifact.getArtifactId(); if (!checkedArtifacts.contains(artifactKey)) { toDeploy.add(artifact); MavenProject project = findImplementation(artifact); if (project != null) { getLog().info("Found implementation: " + artifactKey + " to " + project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion()); Set<Artifact> projectArtifacts = project.createArtifacts(customArtifactFactory, null, null); //artifacts.addAll(projectArtifacts); if (shouldExpand(project)) { toDeploy.addAll(projectArtifacts); } artifacts.add(project.getArtifact()); toDeploy.add(project.getArtifact()); } else { getLog().info("Unresolved implementation: " + artifactKey); } checkedArtifacts.add(artifactKey); } } } while (artifacts.size() > 0); } catch (InvalidDependencyVersionException e1) { throw new MojoExecutionException("Failed to create artifacts", e1); } catch (ArtifactResolutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ArtifactNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { saveCachedImplmentations(); } addToDependencies(); }