List of usage examples for org.apache.maven.project MavenProject getArtifacts
public Set<Artifact> getArtifacts()
From source file:org.basepom.mojo.duplicatefinder.artifact.ArtifactFileResolver.java
License:Apache License
public ArtifactFileResolver(final MavenProject project, final boolean preferLocal) throws DependencyResolutionRequiredException { checkNotNull(project, "project is null"); this.preferLocal = preferLocal; this.localArtifactCache = HashBiMap.create(project.getArtifacts().size()); this.repoArtifactCache = HashBiMap.create(project.getArtifacts().size()); for (final Artifact artifact : project.getArtifacts()) { final File repoPath = artifact.getFile(); final Artifact canonicalizedArtifact = ArtifactFileResolver.canonicalizeArtifact(artifact); checkState(repoPath != null && repoPath.exists(), "Repository Path '%s' does not exist.", repoPath); final File oldFile = repoArtifactCache.put(canonicalizedArtifact, repoPath); checkState(oldFile == null || oldFile.equals(repoPath), "Already encountered a file for %s: %s", canonicalizedArtifact, oldFile); }//from w ww . j ava2s . com for (final MavenProject referencedProject : project.getProjectReferences().values()) { // referenced projects only have GAV coordinates but no scope. final Set<Artifact> repoArtifacts = findRepoArtifacts(referencedProject, repoArtifactCache); checkState(!repoArtifacts.isEmpty(), "Found project reference to %s but no repo reference!", referencedProject.getArtifact()); for (final Artifact artifact : repoArtifacts) { final File outputDir = isTestArtifact(artifact) ? getTestOutputDirectory(referencedProject) : getOutputDirectory(referencedProject); if (outputDir != null && outputDir.exists()) { final File oldFile = localArtifactCache.put(artifact, outputDir); checkState(oldFile == null || oldFile.equals(outputDir), "Already encountered a file for %s: %s", artifact, oldFile); } } } }
From source file:org.codehaus.cargo.maven2.DependencyCalculator.java
License:Apache License
/** * Execute the dependency calculator.//from w ww . ja v a 2 s . c om * @return List of dependency files. * @throws Exception If anything goes wrong. */ public Set<File> execute() throws Exception { ProfileManager profileManager = new DefaultProfileManager(container); fixupProjectArtifact(); // Calculate the new deps Artifact art = mavenProject.getArtifact(); Artifact art2 = artifactFactory.createArtifactWithClassifier(art.getGroupId() + ".cargodeps", art.getArtifactId(), art.getVersion(), "pom", null); resolver.resolve(art2, remoteRepositories, localRepository); MavenProject mavenProject = mavenProjectBuilder.buildWithDependencies(art2.getFile(), localRepository, profileManager); Set<File> filesToAdd = new HashSet<File>(); for (Object artifact : mavenProject.getArtifacts()) { Artifact artdep = (Artifact) artifact; if (artdep.getType().equals("jar")) { resolver.resolve(artdep, remoteRepositories, localRepository); filesToAdd.add(artdep.getFile()); } } return filesToAdd; }
From source file:org.codehaus.cargo.maven2.util.CargoProject.java
License:Apache License
/** * Saves all attributes./*from w w w. j ava2s . c o m*/ * @param project Maven2 project. * @param log Logger. */ public CargoProject(MavenProject project, Log log) { this(project.getPackaging(), project.getGroupId(), project.getArtifactId(), project.getBuild().getDirectory(), project.getBuild().getFinalName(), project.getArtifact(), project.getAttachedArtifacts(), project.getArtifacts(), log); }
From source file:org.codehaus.mojo.chronos.jmeter.DependencyUtil.java
License:LGPL
public List getDependencies(MavenProject project) { List result = new ArrayList(); Iterator it = project.getAttachedArtifacts().iterator(); while (it.hasNext()) { Artifact artifact = (Artifact) it.next(); File attachedArtifactFile = artifact.getFile(); result.add(attachedArtifactFile); }//from www. j a v a2 s . co m File artifactFile = project.getArtifact().getFile(); if (artifactFile == null) { log.warn("Artifact not found. Note that if Your JMeter test contains JUnittestcases, " + "You can only invoke this goal through the default lifecycle."); } else { result.add(artifactFile); } Set dependencyArtifacts = project.getArtifacts(); if (dependencyArtifacts != null) { Iterator deps = dependencyArtifacts.iterator(); while (deps.hasNext()) { Artifact dependency = (Artifact) deps.next(); result.add(dependency.getFile()); } } return result; }
From source file:org.codehaus.mojo.cpp.compiler.artifacts.ArtifactManager.java
License:Apache License
@SuppressWarnings("rawtypes") public ArtifactManager(final Log log, final MavenProject project, final ArtifactFactory factory, final ArtifactResolver resolver, final ArtifactRepository localRepository, final List remoteRepositories) { this.factory = factory; this.resolver = resolver; this.localRepository = localRepository; this.remoteRepositories = remoteRepositories; final List<Artifact> mainArtifacts = new ArtifactFilter(log, "car").filter(project.getArtifacts()); this.resolvedArtifacts.put(MAIN_ARTIFACT_KEY, mainArtifacts); }
From source file:org.codehaus.mojo.javascript.archive.JavascriptArtifactManager.java
License:Apache License
public void unpack(MavenProject project, String scope, File target, boolean useArtifactId) throws ArchiverException { archiver.setOverwrite(false);/* w w w. ja v a 2 s . com*/ Set dependencies = project.getArtifacts(); ArtifactFilter runtime = new ScopeArtifactFilter(scope); for (Iterator iterator = dependencies.iterator(); iterator.hasNext();) { Artifact dependency = (Artifact) iterator.next(); if (!dependency.isOptional() && Types.JAVASCRIPT_TYPE.equals(dependency.getType()) && runtime.include(dependency)) { getLogger().info("Unpack javascript dependency [" + dependency.toString() + "]"); archiver.setSourceFile(dependency.getFile()); File dest = target; if (useArtifactId) { dest = new File(target, dependency.getArtifactId()); } unpack(dependency, dest); } } }
From source file:org.codehaus.mojo.javascript.configurator.JsriaProjectConfigurator.java
License:Open Source License
@Override public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException { monitor = SubMonitor.convert(monitor, "Configure JS RIA project", 3); IProject project = request.getProject(); if (!project.hasNature(JavaScriptCore.NATURE_ID)) { addNature(project, JavaScriptCore.NATURE_ID, monitor); }// w w w. j a va 2s .c o m // also add to the js classpath IJavaScriptProject jsProject = JavaScriptCore.create(project); IIncludePathEntry[] rawIncludepath = jsProject.getRawIncludepath(); List<IIncludePathEntry> entries = new ArrayList<IIncludePathEntry>(); for (int i = 0; i < rawIncludepath.length; i++) { // remove project source entries as well as any entries that have the m2e include path attribtue if (!hasClasspathAttribute(rawIncludepath[i]) && !(rawIncludepath[i].getPath().segmentCount() == 1 && rawIncludepath[i].getEntryKind() == IIncludePathEntry.CPE_SOURCE)) { entries.add(rawIncludepath[i]); } } MavenProject mavenProject = request.getMavenProject(); Set<Artifact> artifacts = mavenProject.getArtifacts(); for (Artifact artifact : artifacts) { if (artifact.getType().equals("js")) { entries.add(createIncludePathEntry(artifact)); } } createSourceFolders("js", project, monitor); IFolder srcMainJs = project.getFolder("src/main/js"); IFolder srcTestJs = project.getFolder("src/test/js"); entries.add(JavaScriptCore.newSourceEntry(srcMainJs.getFullPath(), ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, getClasspathAttribute())); entries.add(JavaScriptCore.newSourceEntry(srcTestJs.getFullPath(), ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, getClasspathAttribute())); jsProject.setRawIncludepath(entries.toArray(new IIncludePathEntry[entries.size()]), monitor); ensureImplicitDependencies(mavenProject); }
From source file:org.codehaus.mojo.license.api.DefaultDependenciesTool.java
License:Open Source License
/** * {@inheritDoc}/* w w w . j a v a2s .c o m*/ */ public SortedMap<String, MavenProject> loadProjectDependencies(MavenProject project, MavenProjectDependenciesConfigurator configuration, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories, SortedMap<String, MavenProject> cache) { boolean haveNoIncludedGroups = StringUtils.isEmpty(configuration.getIncludedGroups()); boolean haveNoIncludedArtifacts = StringUtils.isEmpty(configuration.getIncludedArtifacts()); boolean haveExcludedGroups = StringUtils.isNotEmpty(configuration.getExcludedGroups()); boolean haveExcludedArtifacts = StringUtils.isNotEmpty(configuration.getExcludedArtifacts()); boolean haveExclusions = haveExcludedGroups || haveExcludedArtifacts; Pattern includedGroupPattern = null; Pattern includedArtifactPattern = null; Pattern excludedGroupPattern = null; Pattern excludedArtifactPattern = null; if (!haveNoIncludedGroups) { includedGroupPattern = Pattern.compile(configuration.getIncludedGroups()); } if (!haveNoIncludedArtifacts) { includedArtifactPattern = Pattern.compile(configuration.getIncludedArtifacts()); } if (haveExcludedGroups) { excludedGroupPattern = Pattern.compile(configuration.getExcludedGroups()); } if (haveExcludedArtifacts) { excludedArtifactPattern = Pattern.compile(configuration.getExcludedArtifacts()); } Set<?> depArtifacts; if (configuration.isIncludeTransitiveDependencies()) { // All project dependencies depArtifacts = project.getArtifacts(); } else { // Only direct project dependencies depArtifacts = project.getDependencyArtifacts(); } List<String> includedScopes = configuration.getIncludedScopes(); List<String> excludeScopes = configuration.getExcludedScopes(); boolean verbose = configuration.isVerbose(); SortedMap<String, MavenProject> result = new TreeMap<String, MavenProject>(); for (Object o : depArtifacts) { Artifact artifact = (Artifact) o; if (DefaultThirdPartyTool.LICENSE_DB_TYPE.equals(artifact.getType())) { // the special dependencies for license databases don't count. // Note that this will still see transitive deps of a license db; so using the build helper inside of another project // to make them will be noisy. continue; } String scope = artifact.getScope(); if (CollectionUtils.isNotEmpty(includedScopes) && !includedScopes.contains(scope)) { // not in included scopes continue; } if (excludeScopes.contains(scope)) { // in excluded scopes continue; } Logger log = getLogger(); String id = MojoHelper.getArtifactId(artifact); if (verbose) { log.info("detected artifact " + id); } // Check if the project should be included // If there is no specified artifacts and group to include, include all boolean isToInclude = haveNoIncludedArtifacts && haveNoIncludedGroups || isIncludable(artifact, includedGroupPattern, includedArtifactPattern); // Check if the project should be excluded boolean isToExclude = isToInclude && haveExclusions && isExcludable(artifact, excludedGroupPattern, excludedArtifactPattern); if (!isToInclude || isToExclude) { if (verbose) { log.info("skip artifact " + id); } continue; } MavenProject depMavenProject = null; if (cache != null) { // try to get project from cache depMavenProject = cache.get(id); } if (depMavenProject != null) { if (verbose) { log.info("add dependency [" + id + "] (from cache)"); } } else { // build project try { depMavenProject = mavenProjectBuilder.buildFromRepository(artifact, remoteRepositories, localRepository, true); depMavenProject.getArtifact().setScope(artifact.getScope()); } catch (ProjectBuildingException e) { log.warn("Unable to obtain POM for artifact : " + artifact, e); continue; } if (verbose) { log.info("add dependency [" + id + "]"); } if (cache != null) { // store it also in cache cache.put(id, depMavenProject); } } // keep the project result.put(id, depMavenProject); } return result; }
From source file:org.codehaus.mojo.license.ArtifactHelper.java
License:Open Source License
/** * Get the list of project dependencies after applying transitivity and filtering rules. * /* w w w . j a va 2 s . c o m*/ * @param mojo * @param log * @param cache * @return */ public static SortedMap<String, MavenProject> loadProjectDependencies(MavenProjectDependenciesLoader mojo, Log log, SortedMap<String, MavenProject> cache) { boolean haveNoIncludedGroups = StringUtils.isEmpty(mojo.getIncludedGroups()); boolean haveNoIncludedArtifacts = StringUtils.isEmpty(mojo.getIncludedArtifacts()); boolean haveExcludedGroups = StringUtils.isNotEmpty(mojo.getExcludedGroups()); boolean haveExcludedArtifacts = StringUtils.isNotEmpty(mojo.getExcludedArtifacts()); boolean haveExclusions = haveExcludedGroups || haveExcludedArtifacts; Pattern includedGroupPattern = null; Pattern includedArtifactPattern = null; Pattern excludedGroupPattern = null; Pattern excludedArtifactPattern = null; if (!haveNoIncludedGroups) { includedGroupPattern = Pattern.compile(mojo.getIncludedGroups()); } if (!haveNoIncludedArtifacts) { includedArtifactPattern = Pattern.compile(mojo.getIncludedArtifacts()); } if (haveExcludedGroups) { excludedGroupPattern = Pattern.compile(mojo.getExcludedGroups()); } if (haveExcludedArtifacts) { excludedArtifactPattern = Pattern.compile(mojo.getExcludedArtifacts()); } MavenProject project = mojo.getProject(); Set<?> depArtifacts; if (mojo.isIncludeTransitiveDependencies()) { // All project dependencies depArtifacts = project.getArtifacts(); } else { // Only direct project dependencies depArtifacts = project.getDependencyArtifacts(); } ArtifactRepository localRepository = mojo.getLocalRepository(); List remoteRepositories = mojo.getRemoteRepositories(); MavenProjectBuilder projectBuilder = mojo.getMavenProjectBuilder(); List<String> excludeScopes = mojo.getExcludeScopes(); boolean verbose = mojo.isVerbose(); SortedMap<String, MavenProject> result = new TreeMap<String, MavenProject>(); for (Object o : depArtifacts) { Artifact artifact = (Artifact) o; if (excludeScopes.contains(artifact.getScope())) { // never treate system artifacts (they are mysterious and // no information can be retrive from anywhere)... continue; } String id = getArtifactId(artifact); if (verbose) { log.info("detected artifact " + id); } // Check if the project should be included // If there is no specified artifacts and group to include, include all boolean isToInclude = haveNoIncludedArtifacts && haveNoIncludedGroups || isIncludable(log, artifact, includedGroupPattern, includedArtifactPattern); // Check if the project should be excluded boolean isToExclude = isToInclude && haveExclusions && isExcludable(log, artifact, excludedGroupPattern, excludedArtifactPattern); if (!isToInclude || isToExclude) { if (verbose) { log.info("skip artifact " + id); } continue; } MavenProject depMavenProject = null; if (cache != null) { // try to get project from cache depMavenProject = cache.get(id); } if (depMavenProject != null) { if (verbose) { log.info("add dependency [" + id + "] (from cache)"); } } else { // build project try { depMavenProject = projectBuilder.buildFromRepository(artifact, remoteRepositories, localRepository, true); } catch (ProjectBuildingException e) { log.warn("Unable to obtain POM for artifact : " + artifact); log.warn(e); continue; } if (verbose) { log.info("add dependency [" + id + "]"); } if (cache != null) { // store it also in cache cache.put(id, depMavenProject); } } // keep the project result.put(id, depMavenProject); } return result; }
From source file:org.codehaus.mojo.license.DefaultDependenciesTool.java
License:Educational Community License
/** * {@inheritDoc}/* www. j av a 2 s . c om*/ */ @Override public SortedMap<String, MavenProject> loadProjectDependencies(MavenProject project, MavenProjectDependenciesConfigurator configuration, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories, SortedMap<String, MavenProject> cache) { boolean haveNoIncludedGroups = StringUtils.isEmpty(configuration.getIncludedGroups()); boolean haveNoIncludedArtifacts = StringUtils.isEmpty(configuration.getIncludedArtifacts()); boolean haveExcludedGroups = StringUtils.isNotEmpty(configuration.getExcludedGroups()); boolean haveExcludedArtifacts = StringUtils.isNotEmpty(configuration.getExcludedArtifacts()); boolean haveExclusions = haveExcludedGroups || haveExcludedArtifacts; Pattern includedGroupPattern = null; Pattern includedArtifactPattern = null; Pattern excludedGroupPattern = null; Pattern excludedArtifactPattern = null; if (!haveNoIncludedGroups) { includedGroupPattern = Pattern.compile(configuration.getIncludedGroups()); } if (!haveNoIncludedArtifacts) { includedArtifactPattern = Pattern.compile(configuration.getIncludedArtifacts()); } if (haveExcludedGroups) { excludedGroupPattern = Pattern.compile(configuration.getExcludedGroups()); } if (haveExcludedArtifacts) { excludedArtifactPattern = Pattern.compile(configuration.getExcludedArtifacts()); } Set<?> depArtifacts; if (configuration.isIncludeTransitiveDependencies()) { // All project dependencies depArtifacts = project.getArtifacts(); } else { // Only direct project dependencies depArtifacts = project.getDependencyArtifacts(); } List<String> includedScopes = configuration.getIncludedScopes(); List<String> excludeScopes = configuration.getExcludedScopes(); boolean verbose = configuration.isVerbose(); SortedMap<String, MavenProject> result = new TreeMap<String, MavenProject>(); for (Object o : depArtifacts) { Artifact artifact = (Artifact) o; String scope = artifact.getScope(); if (CollectionUtils.isNotEmpty(includedScopes) && !includedScopes.contains(scope)) { // not in included scopes continue; } if (excludeScopes.contains(scope)) { // in excluded scopes continue; } Logger log = getLogger(); String id = MojoHelper.getArtifactId(artifact); if (verbose) { log.info("detected artifact " + id); } // Check if the project should be included // If there is no specified artifacts and group to include, include all boolean isToInclude = haveNoIncludedArtifacts && haveNoIncludedGroups || isIncludable(artifact, includedGroupPattern, includedArtifactPattern); // Check if the project should be excluded boolean isToExclude = isToInclude && haveExclusions && isExcludable(artifact, excludedGroupPattern, excludedArtifactPattern); if (!isToInclude || isToExclude) { if (verbose) { log.info("skip artifact " + id); } continue; } MavenProject depMavenProject = null; if (cache != null) { // try to get project from cache depMavenProject = cache.get(id); } if (depMavenProject != null) { if (verbose) { log.info("add dependency [" + id + "] (from cache)"); } } else { // build project try { depMavenProject = mavenProjectBuilder.buildFromRepository(artifact, remoteRepositories, localRepository, true); } catch (Exception e) { log.warn("Unable to obtain POM for artifact : " + artifact, e); continue; } if (verbose) { log.info("add dependency [" + id + "]"); } if (cache != null) { // store it also in cache cache.put(id, depMavenProject); } } // keep the project result.put(id, depMavenProject); } return result; }