List of usage examples for org.apache.maven.project MavenProject getArtifacts
public Set<Artifact> getArtifacts()
From source file:org.eclipse.m2e.core.internal.markers.MavenMarkerManager.java
License:Open Source License
private void addMissingArtifactProblemInfos(MavenProject mavenProject, SourceLocation location, List<MavenProblemInfo> knownProblems) { Set<Artifact> artifacts = mavenProject.getArtifacts(); all_artifacts_loop: for (Artifact mavenArtifact : artifacts) { if (!mavenArtifact.isResolved()) { org.sonatype.aether.artifact.Artifact artifact = RepositoryUtils.toArtifact(mavenArtifact); for (MavenProblemInfo problem : knownProblems) { if (problem instanceof ArtifactNotFoundProblemInfo) { ArtifactNotFoundProblemInfo artifactNotFoundProblemInfo = (ArtifactNotFoundProblemInfo) problem; if (equals(artifactNotFoundProblemInfo.getArtifact(), artifact)) { continue all_artifacts_loop; }//from w ww . j a v a 2 s.co m } } knownProblems .add(new ArtifactNotFoundProblemInfo(artifact, mavenConfiguration.isOffline(), location)); } } }
From source file:org.eclipse.m2e.core.internal.project.registry.DefaultMavenDependencyResolver.java
License:Open Source License
@Override public void resolveProjectDependencies(final IMavenProjectFacade facade, Set<Capability> capabilities, Set<RequiredCapability> requirements, final IProgressMonitor monitor) throws CoreException { long start = System.currentTimeMillis(); log.debug("Resolving dependencies for {}", facade.toString()); //$NON-NLS-1$ markerManager.deleteMarkers(facade.getPom(), IMavenConstants.MARKER_DEPENDENCY_ID); ProjectBuildingRequest configuration = getMaven().getExecutionContext().newProjectBuildingRequest(); configuration.setProject(facade.getMavenProject()); // TODO do we need this? configuration.setResolveDependencies(true); MavenExecutionResult mavenResult = getMaven().readMavenProject(facade.getPomFile(), configuration); markerManager.addMarkers(facade.getPom(), IMavenConstants.MARKER_DEPENDENCY_ID, mavenResult); if (!facade.getResolverConfiguration().shouldResolveWorkspaceProjects()) { return;/*from w ww . j a v a 2 s.c o m*/ } MavenProject mavenProject = facade.getMavenProject(); // dependencies // resolved dependencies for (Artifact artifact : mavenProject.getArtifacts()) { requirements.add(MavenRequiredCapability.createMavenArtifact(new ArtifactKey(artifact), artifact.getScope(), artifact.isOptional())); } // extension plugins (affect packaging type calculation) for (Plugin plugin : mavenProject.getBuildPlugins()) { if (plugin.isExtensions()) { ArtifactKey artifactKey = new ArtifactKey(plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), null); requirements.add(MavenRequiredCapability.createMavenArtifact(artifactKey, "plugin", false)); //$NON-NLS-1$ } } // missing dependencies DependencyResolutionResult resolutionResult = mavenResult.getDependencyResolutionResult(); if (resolutionResult != null && resolutionResult.getUnresolvedDependencies() != null) { for (Dependency dependency : resolutionResult.getUnresolvedDependencies()) { org.sonatype.aether.artifact.Artifact artifact = dependency.getArtifact(); ArtifactKey dependencyKey = new ArtifactKey(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), null); requirements.add(MavenRequiredCapability.createMavenArtifact(dependencyKey, dependency.getScope(), dependency.isOptional())); } } log.debug("Resolved dependencies for {} in {} ms", facade.toString(), System.currentTimeMillis() - start); //$NON-NLS-1$ }
From source file:org.eclipse.m2e.jdt.internal.BuildPathManager.java
License:Open Source License
public void scheduleDownload(final IProject project, final boolean downloadSources, final boolean downloadJavadoc) { try {/* ww w .ja va 2s . com*/ if (project != null && project.isAccessible() && project.hasNature(IMavenConstants.NATURE_ID)) { IMavenProjectFacade facade = projectManager.getProject(project); MavenProject mavenProject = facade != null ? facade.getMavenProject() : null; if (mavenProject != null) { for (Artifact artifact : mavenProject.getArtifacts()) { ArtifactKey artifactKey = new ArtifactKey(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact.getClassifier()); scheduleDownload(project, mavenProject, artifactKey, downloadSources, downloadJavadoc); } } else { // project is not in the cache, push all processing to the background job downloadSourcesJob.scheduleDownload(project, null, downloadSources, downloadJavadoc); } } } catch (CoreException e) { log.error("Could not schedule sources/javadoc download", e); //$NON-NLS-1$ } }
From source file:org.eclipse.m2e.jdt.internal.DefaultClasspathManagerDelegate.java
License:Open Source License
void addClasspathEntries(IClasspathDescriptor classpath, IMavenProjectFacade facade, int kind, IProgressMonitor monitor) throws CoreException { ArtifactFilter scopeFilter;/*from w w w.ja v a 2 s.com*/ if (BuildPathManager.CLASSPATH_RUNTIME == kind) { // ECLIPSE-33: runtime+provided scope // ECLIPSE-85: adding system scope scopeFilter = new ArtifactFilter() { public boolean include(Artifact artifact) { return BuildPathManager.SCOPE_FILTER_RUNTIME.include(artifact) || Artifact.SCOPE_PROVIDED.equals(artifact.getScope()) || Artifact.SCOPE_SYSTEM.equals(artifact.getScope()); } }; } else { // ECLIPSE-33: test scope (already includes provided) scopeFilter = BuildPathManager.SCOPE_FILTER_TEST; } MavenProject mavenProject = facade.getMavenProject(monitor); Set<Artifact> artifacts = mavenProject.getArtifacts(); for (Artifact a : artifacts) { if (!scopeFilter.include(a) || !a.getArtifactHandler().isAddedToClasspath()) { continue; } // project IMavenProjectFacade dependency = projectManager.getMavenProject(a.getGroupId(), a.getArtifactId(), a.getBaseVersion()); if (dependency != null && dependency.getProject().equals(facade.getProject())) { continue; } IClasspathEntryDescriptor entry = null; if (dependency != null && dependency.getFullPath(a.getFile()) != null) { entry = classpath.addProjectEntry(dependency.getFullPath()); } else { File artifactFile = a.getFile(); if (artifactFile != null /*&& artifactFile.canRead()*/) { entry = classpath.addLibraryEntry(Path.fromOSString(artifactFile.getAbsolutePath())); } } if (entry != null) { entry.setArtifactKey( new ArtifactKey(a.getGroupId(), a.getArtifactId(), a.getBaseVersion(), a.getClassifier())); entry.setScope(a.getScope()); entry.setOptionalDependency(a.isOptional()); } } }
From source file:org.eclipse.m2e.jdt.internal.DownloadSourcesJob.java
License:Open Source License
private void downloadMaven(IMavenProjectFacade projectFacade, ArtifactKey artifact, boolean downloadSources, boolean downloadJavadoc, IProgressMonitor monitor) throws CoreException { MavenProject mavenProject = projectFacade.getMavenProject(monitor); List<ArtifactRepository> repositories = mavenProject.getRemoteArtifactRepositories(); if (artifact != null) { downloadAttachments(artifact, repositories, downloadSources, downloadJavadoc, monitor); } else {// w w w . ja va 2 s . c o m for (Artifact a : mavenProject.getArtifacts()) { ArtifactKey aKey = new ArtifactKey(a.getGroupId(), a.getArtifactId(), a.getBaseVersion(), a.getClassifier()); downloadAttachments(aKey, repositories, downloadSources, downloadJavadoc, monitor); } } }
From source file:org.eclipse.m2e.wtp.AbstractProjectConfiguratorDelegate.java
License:Open Source License
protected List<IMavenProjectFacade> getWorkspaceDependencies(IProject project, MavenProject mavenProject) { Set<IProject> projects = new HashSet<IProject>(); List<IMavenProjectFacade> dependencies = new ArrayList<IMavenProjectFacade>(); Set<Artifact> artifacts = mavenProject.getArtifacts(); for (Artifact artifact : artifacts) { IMavenProjectFacade dependency = projectManager.getMavenProject(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); if ((Artifact.SCOPE_COMPILE.equals(artifact.getScope()) || Artifact.SCOPE_RUNTIME.equals(artifact.getScope())) //MNGECLIPSE-1578 Runtime dependencies should be deployed && dependency != null && !dependency.getProject().equals(project) && dependency.getFullPath(artifact.getFile()) != null && projects.add(dependency.getProject())) { dependencies.add(dependency); }//from w ww. j a va 2 s . c o m } return dependencies; }
From source file:org.eclipse.m2e.wtp.ConnectorProjectConfiguratorDelegate.java
License:Open Source License
/** * @see org.eclipse.m2e.wtp.IProjectConfiguratorDelegate#setModuleDependencies(org.eclipse.core.resources.IProject, org.apache.maven.project.MavenProject, org.eclipse.core.runtime.IProgressMonitor) *//* w w w . j a va2 s . c om*/ public void setModuleDependencies(IProject project, MavenProject mavenProject, IProgressMonitor monitor) throws CoreException { IVirtualComponent rarComponent = ComponentCore.createComponent(project); Set<IVirtualReference> newRefs = new LinkedHashSet<IVirtualReference>(); Set<Artifact> artifacts = mavenProject.getArtifacts(); //Adding artifact references in .component. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=297777#c1 for (Artifact artifact : artifacts) { ArtifactHelper.fixArtifactHandler(artifact.getArtifactHandler()); //Don't deploy pom, non runtime or optional dependencies if ("pom".equals(artifact.getType()) || !SCOPE_FILTER_RUNTIME.include(artifact) || artifact.isOptional()) { continue; } IMavenProjectFacade workspaceDependency = projectManager.getMavenProject(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); if (workspaceDependency != null && !workspaceDependency.getProject().equals(project) && workspaceDependency.getFullPath(artifact.getFile()) != null) { //artifact dependency is a workspace project IProject depProject = preConfigureDependencyProject(workspaceDependency, monitor); if (ModuleCoreNature.isFlexibleProject(depProject)) { newRefs.add(createReference(rarComponent, depProject, artifact)); } } else { //artifact dependency should be added as a JEE module, referenced with M2_REPO variable newRefs.add(createReference(rarComponent, artifact)); } } IVirtualReference[] newRefsArray = new IVirtualReference[newRefs.size()]; newRefs.toArray(newRefsArray); //Only change the project references if they've changed IVirtualReference[] references = WTPProjectsUtil.extractHardReferences(rarComponent, false); if (WTPProjectsUtil.hasChanged(references, newRefsArray)) { rarComponent.setReferences(newRefsArray); } }
From source file:org.eclipse.m2e.wtp.jaxrs.internal.configurators.JaxRsProjectConfigurator.java
License:Open Source License
@Override public void mavenProjectChanged(MavenProjectChangedEvent event, IProgressMonitor monitor) throws CoreException { IMavenProjectFacade facade = event.getMavenProject(); if (facade != null) { IProject project = facade.getProject(); MavenProject mavenProject = facade.getMavenProject(monitor); if (isWTPProject(project) && WAR_PACKAGING.equals(mavenProject.getPackaging())) { IMavenProjectFacade oldFacade = event.getOldMavenProject(); if (oldFacade != null) { MavenProject oldProject = oldFacade.getMavenProject(monitor); if (oldProject != null && oldProject.getArtifacts().equals(mavenProject.getArtifacts())) { //Nothing changed since last build, no need to lookup for new Facets return; }//from w w w . ja v a2s . co m } configureInternal(mavenProject, project, monitor); } } }
From source file:org.eclipse.m2e.wtp.WebProjectConfiguratorDelegate.java
License:Open Source License
public void setModuleDependencies(IProject project, MavenProject mavenProject, IProgressMonitor monitor) throws CoreException { IVirtualComponent component = ComponentCore.createComponent(project); //if the attempt to create dependencies happens before the project is actually created, abort. //this will be created again when the project exists. if (component == null) { return;//from w w w .j a va2s .c om } //MECLIPSEWTP-41 Fix the missing moduleCoreNature fixMissingModuleCoreNature(project, monitor); DebugUtilities.debug("==============Processing " + project.getName() + " dependencies ==============="); WarPluginConfiguration config = new WarPluginConfiguration(mavenProject, project); IPackagingConfiguration opts = new PackagingConfiguration(config.getPackagingIncludes(), config.getPackagingExcludes()); FileNameMapping fileNameMapping = config.getFileNameMapping(); List<AbstractDependencyConfigurator> depConfigurators = ExtensionReader .readDependencyConfiguratorExtensions(projectManager, MavenPlugin.getMavenRuntimeManager(), mavenMarkerManager); Set<IVirtualReference> references = new LinkedHashSet<IVirtualReference>(); List<IMavenProjectFacade> exportedDependencies = getWorkspaceDependencies(project, mavenProject); Set<String> dups = new HashSet<String>(); Set<String> names = new HashSet<String>(); Map<IVirtualReference, Artifact> referenceMapping = new HashMap<IVirtualReference, Artifact>( exportedDependencies.size()); for (IMavenProjectFacade dependency : exportedDependencies) { String depPackaging = dependency.getPackaging(); if ("pom".equals(depPackaging) //MNGECLIPSE-744 pom dependencies shouldn't be deployed || "war".equals(depPackaging) //Overlays are dealt with the overlay configurator || "zip".equals(depPackaging)) { continue; } try { preConfigureDependencyProject(dependency, monitor); if (!ModuleCoreNature.isFlexibleProject(dependency.getProject())) { //Projects unsupported by WTP (ex. adobe flex projects) should not be added as references continue; } MavenProject depMavenProject = dependency.getMavenProject(monitor); IVirtualComponent depComponent = ComponentCore.createComponent(dependency.getProject()); ArtifactKey artifactKey = ArtifactHelper.toArtifactKey(depMavenProject.getArtifact()); //Get artifact using the proper classifier Artifact artifact = ArtifactHelper.getArtifact(mavenProject.getArtifacts(), artifactKey); if (artifact == null) { //could not map key to artifact artifact = depMavenProject.getArtifact(); } ArtifactHelper.fixArtifactHandler(artifact.getArtifactHandler()); String deployedName = fileNameMapping.mapFileName(artifact); boolean isDeployed = !artifact.isOptional() && opts.isPackaged("WEB-INF/lib/" + deployedName); //an artifact in mavenProject.getArtifacts() doesn't have the "optional" value as depMavenProject.getArtifact(); if (isDeployed) { IVirtualReference reference = ComponentCore.createReference(component, depComponent); IPath path = new Path("/WEB-INF/lib"); reference.setArchiveName(deployedName); reference.setRuntimePath(path); references.add(reference); referenceMapping.put(reference, artifact); if (!names.add(deployedName)) { dups.add(deployedName); } } } catch (RuntimeException ex) { //Should probably be NPEs at this point String dump = DebugUtilities.dumpProjectState("An error occured while configuring a dependency of " + project.getName() + DebugUtilities.SEP, dependency.getProject()); LOG.error(dump); throw ex; } } for (IVirtualReference reference : references) { if (dups.contains(reference.getArchiveName())) { Artifact a = referenceMapping.get(reference); String newName = a.getGroupId() + "-" + reference.getArchiveName(); reference.setArchiveName(newName); } } IVirtualReference[] oldRefs = WTPProjectsUtil.extractHardReferences(component, false); IVirtualReference[] newRefs = references.toArray(new IVirtualReference[references.size()]); if (WTPProjectsUtil.hasChanged(oldRefs, newRefs)) { //Only write in the .component file if necessary IVirtualReference[] overlayRefs = WTPProjectsUtil.extractHardReferences(component, true); IVirtualReference[] allRefs = new IVirtualReference[overlayRefs.length + newRefs.length]; System.arraycopy(newRefs, 0, allRefs, 0, newRefs.length); System.arraycopy(overlayRefs, 0, allRefs, newRefs.length, overlayRefs.length); component.setReferences(allRefs); } //TODO why a 2nd loop??? for (IMavenProjectFacade dependency : exportedDependencies) { MavenProject depMavenProject = dependency.getMavenProject(monitor); Iterator<AbstractDependencyConfigurator> configurators = depConfigurators.iterator(); while (configurators.hasNext()) { try { configurators.next().configureDependency(mavenProject, project, depMavenProject, dependency.getProject(), monitor); } catch (MarkedException ex) { //XXX handle this } } } }
From source file:org.eclipse.m2e.wtp.WebProjectConfiguratorDelegate.java
License:Open Source License
public void configureClasspath(IProject project, MavenProject mavenProject, IClasspathDescriptor classpath, IProgressMonitor monitor) throws CoreException { //Improve skinny war support by generating the manifest classpath //similar to mvn eclipse:eclipse //http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html WarPluginConfiguration config = new WarPluginConfiguration(mavenProject, project); IPackagingConfiguration opts = new PackagingConfiguration(config.getPackagingIncludes(), config.getPackagingExcludes()); /*/*from w w w . j a va 2s .c om*/ * Need to take care of three separate cases * * 1. remove any project dependencies (they are represented as J2EE module dependencies) * 2. add non-dependency attribute for entries originated by artifacts with * runtime, system, test scopes or optional dependencies (not sure about the last one) * 3. make sure all dependency JAR files have unique file names, i.e. artifactId/version collisions */ Set<String> dups = new LinkedHashSet<String>(); Set<String> names = new HashSet<String>(); IVirtualComponent component = ComponentCore.createComponent(project); if (component != null) { for (IVirtualReference vr : component.getReferences()) { if (!vr.getReferencedComponent().isBinary()) { names.add(vr.getArchiveName()); } } } FileNameMapping fileNameMapping = config.getFileNameMapping(); String targetDir = mavenProject.getBuild().getDirectory(); // first pass removes projects, adds non-dependency attribute and collects colliding filenames Iterator<IClasspathEntryDescriptor> iter = classpath.getEntryDescriptors().iterator(); while (iter.hasNext()) { IClasspathEntryDescriptor descriptor = iter.next(); String scope = descriptor.getScope(); Artifact artifact = ArtifactHelper.getArtifact(mavenProject.getArtifacts(), descriptor.getArtifactKey()); ArtifactHelper.fixArtifactHandler(artifact.getArtifactHandler()); String deployedName = fileNameMapping.mapFileName(artifact); boolean isDeployed = (Artifact.SCOPE_COMPILE.equals(scope) || Artifact.SCOPE_RUNTIME.equals(scope)) && !descriptor.isOptionalDependency() && opts.isPackaged("WEB-INF/lib/" + deployedName) && !isWorkspaceProject(artifact); // add non-dependency attribute if this classpathentry is not meant to be deployed // or if it's a workspace project (projects already have a reference created in configure()) if (!isDeployed) { descriptor.setClasspathAttribute(NONDEPENDENCY_ATTRIBUTE.getName(), NONDEPENDENCY_ATTRIBUTE.getValue()); //Bug #382078 : no need to rename non-deployed artifacts. continue; } //If custom fileName is used, check if the underlying file already exists // if it doesn't, copy and rename the artifact under the build dir String fileName = descriptor.getPath().lastSegment(); if (!deployedName.equals(fileName)) { IPath newPath = descriptor.getPath().removeLastSegments(1).append(deployedName); if (!new File(newPath.toOSString()).exists()) { newPath = renameArtifact(targetDir, descriptor.getPath(), deployedName); } if (newPath != null) { descriptor.setPath(newPath); } } if (!names.add(deployedName)) { dups.add(deployedName); } } // second pass disambiguates colliding entry file names iter = classpath.getEntryDescriptors().iterator(); while (iter.hasNext()) { IClasspathEntryDescriptor descriptor = iter.next(); if (descriptor.getClasspathAttributes().containsKey(NONDEPENDENCY_ATTRIBUTE.getName())) { //No need to rename if not deployed continue; } if (dups.contains(descriptor.getPath().lastSegment())) { String newName = descriptor.getGroupId() + "-" + descriptor.getPath().lastSegment(); IPath newPath = renameArtifact(targetDir, descriptor.getPath(), newName); if (newPath != null) { descriptor.setPath(newPath); } } } }