List of usage examples for org.apache.maven.project MavenProject getDependencyArtifacts
@Deprecated
public Set<Artifact> getDependencyArtifacts()
From source file:com.exentes.maven.versions.VersionMojoUtils.java
License:Apache License
public static SetMultimap<Artifact, MavenProject> allSnapshotProjectArtifacts(MavenSession session) { SetMultimap<Artifact, MavenProject> allSnapshotProjectArtifacts = HashMultimap.create(); for (MavenProject project : session.getProjects()) { for (Artifact artifact : difference(newHashSet(filterSnapshots(project.getDependencyArtifacts())), newHashSet(transform(session.getProjects(), toProjectArtifactFunction)))) { allSnapshotProjectArtifacts.put(artifact, project); }//w w w .ja va 2s . c o m } return allSnapshotProjectArtifacts; }
From source file:com.greenpepper.maven.runner.resolver.CoordinatesResolver.java
License:Open Source License
private void resolveTemporaryProjectFile() throws Exception { File tmpProjectFile = createTemporaryPomFile(mavenGAV.getGroupId(), mavenGAV.getArtifactId(), mavenGAV.getVersion());/*from w w w. j a va 2s. co m*/ MavenProject tmpProject = embedder.readProjectWithDependencies(tmpProjectFile, new ConsoleDownloadMonitor()); Artifact targetedArtifact = (Artifact) tmpProject.getDependencyArtifacts().iterator().next(); mavenGAV.setVersion(targetedArtifact.getVersion()); }
From source file:com.opengamma.maven.MojoUtils.java
License:Open Source License
/** * Gets a file for the given artifact coordinates. * // w w w . j a v a 2s. c o m * @param resourceArtifact the artifact coordinates in the form groupId:artifactId[:type[:classifier]], not null * @param project the Maven project instance, not null * @return the file corresponding to the given artifact coordinates, not null * @throws MojoExecutionException if no artifact exists with the given coordinates */ @SuppressWarnings("unchecked") public static File getArtifactFile(String resourceArtifact, MavenProject project) throws MojoExecutionException { String[] artifactParts = resourceArtifact.split(":"); if (artifactParts.length < 2 || artifactParts.length > 4) { throw new MojoExecutionException( "resourceArtifact must be of the form groupId:artifactId[:type[:classifier]]"); } String groupId = artifactParts[0]; String artifactId = artifactParts[1]; String type = artifactParts.length > 2 ? artifactParts[2] : null; String classifier = artifactParts.length > 3 ? artifactParts[3] : null; File artifactFile = null; for (Artifact artifact : (Set<Artifact>) project.getDependencyArtifacts()) { if (groupId.equals(artifact.getGroupId()) && artifactId.equals(artifact.getArtifactId()) && (type == null || type.equals(artifact.getType())) && (classifier == null || classifier.equals(artifact.getClassifier()))) { artifactFile = artifact.getFile(); break; } } if (artifactFile == null) { throw new MojoExecutionException("Unable to find artifact with coordinates '" + resourceArtifact + "'"); } return artifactFile; }
From source file:com.sun.enterprise.module.maven.OSGiPackager.java
License:Open Source License
public List<BundleDependency> discoverRequiredBundles(MavenProject pom) throws IOException { List<BundleDependency> dependencies = new ArrayList<BundleDependency>(); for (Artifact a : (Set<Artifact>) pom.getDependencyArtifacts()) { if ("test".equals(a.getScope()) || "provided".equals(a.getScope())) continue; // http://www.nabble.com/V3-gf%3Arun-throws-NPE-tf4816802.html indicates // that some artifacts are not resolved at this point. Not sure when that could happen // so aborting with diagnostics if we find it. We need to better understand what this // means and work accordingly. - KK if (a.getFile() == null) { throw new AssertionError(a.getId() + " is not resolved. a=" + a); }//from www.j ava2 s .c om Attributes attributes = null; String name = null; Manifest manifest = Jar.create(a.getFile()).getManifest(); if (manifest != null) { attributes = manifest.getMainAttributes(); name = attributes.getValue(BUNDLE_SYMBOLICNAME); } if (name != null && attributes.getValue(FRAGMENT_HOST) == null) { // this is a OSGi host module BundleDependency bd = new BundleDependency(); bd.bundleSymbolicName = name; final String version = attributes.getValue(BUNDLE_VERSION); // no need to translate, for it's already an OSGi version bd.versionRange = version; // maps to [version, infinity) // resolution=optional or mandatory bd.resolution = props.getProperty("resolution", RESOLUTION_MANDATORY); bd.visibility = props.getProperty("visibility", VISIBILITY_PRIVATE); dependencies.add(bd); } } return dependencies; }
From source file:com.sun.enterprise.module.maven.Packager.java
License:Open Source License
public Map<String, String> configureManifest(MavenProject pom, MavenArchiveConfiguration archive, File classesDirectory) throws IOException { Map<String, String> entries; if (archive != null) entries = archive.getManifestEntries(); else//from w w w.ja va 2 s. co m entries = new HashMap<String, String>(); entries.put(ManifestConstants.BUNDLE_NAME, pom.getGroupId() + '.' + pom.getArtifactId()); // check META-INF/services/xxx.ImportPolicy to fill in Import-Policy configureImportPolicy(classesDirectory, entries, ImportPolicy.class, ManifestConstants.IMPORT_POLICY); configureImportPolicy(classesDirectory, entries, LifecyclePolicy.class, ManifestConstants.LIFECYLE_POLICY); // check direct dependencies to find out dependency modules. // we don't need to list transitive dependencies here, so use getDependencyArtifacts(). TokenListBuilder dependencyModuleNames = new TokenListBuilder(); Set<String> dependencyModules = new HashSet<String>(); // used to find transitive dependencies through other modules. for (Artifact a : (Set<Artifact>) pom.getDependencyArtifacts()) { if (a.getScope() != null && a.getScope().equals("test")) continue; // http://www.nabble.com/V3-gf%3Arun-throws-NPE-tf4816802.html indicates // that some artifacts are not resolved at this point. Not sure when that could happen // so aborting with diagnostics if we find it. We need to better understand what this // means and work accordingly. - KK if (a.getFile() == null) { throw new AssertionError(a.getId() + " is not resolved. a=" + a); } Jar jar; try { jar = Jar.create(a.getFile()); } catch (IOException ioe) { // not a jar file, so continue. continue; } Manifest manifest = jar.getManifest(); String name = null; if (manifest != null) { Attributes attributes = manifest.getMainAttributes(); name = attributes.getValue(ManifestConstants.BUNDLE_NAME); } if (name != null) { // this is a hk2 module if (!a.isOptional()) dependencyModuleNames.add(name); // even optional modules need to be listed here dependencyModules.add(a.getGroupId() + '.' + a.getArtifactId() + ':' + a.getVersion()); } } // find jar files to be listed in Class-Path. This needs to include transitive // dependencies, except when the path involves a hk2 module. TokenListBuilder classPathNames = new TokenListBuilder(" "); TokenListBuilder classPathIds = new TokenListBuilder(" "); for (Artifact a : (Set<Artifact>) pom.getArtifacts()) { // check the trail. does that include hk2 module in the path? boolean throughModule = false; for (String module : dependencyModules) throughModule |= a.getDependencyTrail().get(1).toString().startsWith(module); if (throughModule) continue; // yep if (a.getScope().equals("system") || a.getScope().equals("provided") || a.getScope().equals("test")) continue; // ignore tools.jar and such dependencies. if (a.isOptional()) continue; // optional dependency classPathNames.add(stripVersion(a)); classPathIds.add(a.getId()); } if (!classPathNames.isEmpty()) { String existingClassPath = entries.get(ManifestConstants.CLASS_PATH); if (existingClassPath != null) entries.put(ManifestConstants.CLASS_PATH, existingClassPath + " " + classPathNames); else entries.put(ManifestConstants.CLASS_PATH, classPathNames.toString()); entries.put(ManifestConstants.CLASS_PATH_ID, classPathIds.toString()); } return entries; }
From source file:com.webguys.maven.plugin.st.Controller.java
License:Open Source License
private Set<Artifact> configureArtifacts(MavenProject project) { Set<Artifact> originalArtifacts = project.getArtifacts(); project.setArtifacts(project.getDependencyArtifacts()); return originalArtifacts; }
From source file:de.bbe_consulting.mavento.helper.MavenUtil.java
License:Apache License
/** * Extracts all compile dependencies./*w w w. j a va 2s.com*/ * * @param targetDirectory * @param project * @param logger * @throws MojoExecutionException * @throws IOException */ public static void extractCompileDependencies(String targetDirectory, MavenProject project, Log logger) throws MojoExecutionException, IOException { final Set<Artifact> projectDependencies = project.getDependencyArtifacts(); FileUtil.createDirectories(targetDirectory, true); final Properties p = project.getProperties(); final String testId = (String) p.get("magento.test.artifact.id"); final String testGroupdId = (String) p.get("magento.test.artifact.group.id"); final String testVersion = (String) p.get("magento.test.artifact.version"); if (testId == null && testGroupdId == null && testVersion == null) { throw new MojoExecutionException("Error: One of the magento.test.artifact.* properties" + " is not defined. Please fix your pom.xml."); } // cycle through project dependencies for (Iterator<Artifact> artifactIterator = projectDependencies.iterator(); artifactIterator.hasNext();) { Artifact artifact = artifactIterator.next(); if ("compile".equals(artifact.getScope())) { if (!artifact.getArtifactId().equals(testId) && !artifact.getGroupId().equals(testGroupdId) && !artifact.getVersion().equals(testVersion)) { logger.info("Extracting " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + ".."); String artifactPath = artifact.getFile().getPath(); FileUtil.unzipFile(artifactPath, targetDirectory); } } } }
From source file:de.tarent.maven.plugins.pkg.Utils.java
License:Open Source License
/** * Gathers the project's artifacts and the artifacts of all its (transitive) * dependencies filtered by the given filter instance. * /*ww w .j a va 2s . c o m*/ * @param filter * @return * @throws ArtifactResolutionException * @throws ArtifactNotFoundException * @throws ProjectBuildingException * @throws InvalidDependencyVersionException */ @SuppressWarnings("unchecked") public static Set<Artifact> findArtifacts(ArtifactFilter filter, ArtifactFactory factory, ArtifactResolver resolver, MavenProject project, Artifact artifact, ArtifactRepository local, List<ArtifactRepository> remoteRepos, ArtifactMetadataSource metadataSource) throws ArtifactResolutionException, ArtifactNotFoundException, ProjectBuildingException, InvalidDependencyVersionException { ArtifactResolutionResult result = resolver.resolveTransitively(project.getDependencyArtifacts(), artifact, local, remoteRepos, metadataSource, filter); return (Set<Artifact>) result.getArtifacts(); }
From source file:de.zalando.mojo.aspectj.AjcHelper.java
License:Open Source License
/** * Constructs AspectJ compiler classpath string * * @param project the Maven Project//w w w . jav a2 s . c o m * @param pluginArtifacts the plugin Artifacts * @param outDirs the outputDirectories * @return a os spesific classpath string */ @SuppressWarnings("unchecked") public static String createClassPath(MavenProject project, List<Artifact> pluginArtifacts, List<String> outDirs) { String cp = new String(); Set<Artifact> classPathElements = Collections.synchronizedSet(new LinkedHashSet<Artifact>()); Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts(); classPathElements .addAll(dependencyArtifacts == null ? Collections.<Artifact>emptySet() : dependencyArtifacts); classPathElements.addAll(project.getArtifacts()); classPathElements.addAll(pluginArtifacts == null ? Collections.<Artifact>emptySet() : pluginArtifacts); for (Artifact classPathElement : classPathElements) { File artifact = classPathElement.getFile(); if (null != artifact) { cp += classPathElement.getFile().getAbsolutePath(); cp += File.pathSeparatorChar; } } Iterator<String> outIter = outDirs.iterator(); while (outIter.hasNext()) { cp += outIter.next(); cp += File.pathSeparatorChar; } if (cp.endsWith("" + File.pathSeparatorChar)) { cp = cp.substring(0, cp.length() - 1); } cp = StringUtils.replace(cp, "//", "/"); return cp; }
From source file:io.fabric8.forge.maven.DownloadArchetypesMojo.java
License:Apache License
private Artifact findFabric8Archetype(MavenProject project) { Iterator it = project.getDependencyArtifacts().iterator(); while (it.hasNext()) { Artifact a = (Artifact) it.next(); if ("io.fabric8.archetypes".equals(a.getGroupId()) && "archetypes-catalog".equals(a.getArtifactId())) { return a; }/* w w w .j av a 2s. c om*/ } return null; }