List of usage examples for org.apache.maven.project MavenProject getDependencyManagement
public DependencyManagement getDependencyManagement()
From source file:org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog.java
License:Open Source License
/** * @param parent//from w w w.j a v a2s .c o m * @param title * @param mp * @param p * @param inManagedSection true when the result will be added to the dependencyManagement section of the pom. * @return */ public static MavenRepositorySearchDialog createSearchDependencyDialog(Shell parent, String title, MavenProject mp, IProject p, boolean inManagedSection) { Set<ArtifactKey> artifacts = new HashSet<ArtifactKey>(); Set<ArtifactKey> managed = new HashSet<ArtifactKey>(); if (mp != null) { Set<ArtifactKey> keys = inManagedSection ? artifacts : managed; DependencyManagement dm = mp.getDependencyManagement(); if (dm != null && dm.getDependencies() != null) { for (Dependency dep : dm.getDependencies()) { keys.add(new ArtifactKey(dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getClassifier())); } } if (!inManagedSection) { for (Dependency dep : mp.getModel().getDependencies()) { artifacts.add(new ArtifactKey(dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getClassifier())); } } } return new MavenRepositorySearchDialog(parent, title, IIndex.SEARCH_ARTIFACT, artifacts, managed, true, mp, p, true); }
From source file:org.eclipse.m2e.editor.composites.DependencyLabelProvider.java
License:Open Source License
private String[] findManaged(DependenciesComposite.Dependency dep) { if (pomEditor != null) { MavenProject mp = pomEditor.getMavenProject(); String version = null;/*ww w. j a va 2 s. co m*/ String scope = null; if (mp != null) { String id = mp.getGroupId() + ":" + mp.getArtifactId() + ":" + mp.getVersion(); DependencyManagement dm = mp.getDependencyManagement(); if (dm != null) { for (org.apache.maven.model.Dependency d : dm.getDependencies()) { if (d.getGroupId().equals(dep.groupId) && d.getArtifactId().equals(dep.artifactId)) { //based on location, try finding a match in the live Model InputLocation location = d.getLocation("artifactId"); if (location != null) { if (id.equals(location.getSource().getModelId())) { version = d.getVersion(); scope = d.getScope(); break; } } return new String[] { d.getVersion(), d.getScope() }; } } } } List<org.apache.maven.model.Dependency> dm = valueProvider.getValue(); for (org.apache.maven.model.Dependency modelDep : dm) { String modelGroupId = modelDep.getGroupId(); String modelArtifactId = modelDep.getArtifactId(); String modelVersion = modelDep.getVersion(); String modelScope = modelDep.getScope(); if (modelGroupId != null && modelGroupId.equals(dep.groupId) && modelArtifactId != null && modelArtifactId.equals(dep.artifactId)) { if (version != null && (modelVersion == null || modelVersion.contains("${"))) { //prefer the resolved version to the model one if the model version as expressions.. return new String[] { version, modelScope == null ? scope : modelScope }; } return new String[] { modelVersion, modelScope == null ? scope : modelScope }; } } } return null; }
From source file:org.eclipse.m2e.editor.xml.internal.MarkerLocationService.java
License:Open Source License
private static void checkManagedDependencies(IMavenMarkerManager mavenMarkerManager, Element root, IResource pomFile, MavenProject mavenproject, String type, IStructuredDocument document) throws CoreException { List<Element> candidates = new ArrayList<Element>(); Element dependencies = findChild(root, PomEdits.DEPENDENCIES); if (dependencies != null) { for (Element el : findChilds(dependencies, PomEdits.DEPENDENCY)) { Element version = findChild(el, PomEdits.VERSION); if (version != null) { candidates.add(el);//from w w w .j av a2 s . c om } } } //we should also consider <dependencies> section in the profiles, but profile are optional and so is their // dependencyManagement section.. that makes handling our markers more complex. // see MavenProject.getInjectedProfileIds() for a list of currently active profiles in effective pom String currentProjectKey = mavenproject.getGroupId() + ":" + mavenproject.getArtifactId() + ":" //$NON-NLS-1$//$NON-NLS-2$ + mavenproject.getVersion(); List<String> activeprofiles = mavenproject.getInjectedProfileIds().get(currentProjectKey); //remember what profile we found the dependency in. Map<Element, String> candidateProfile = new HashMap<Element, String>(); Element profiles = findChild(root, PomEdits.PROFILES); if (profiles != null) { for (Element profile : findChilds(profiles, PomEdits.PROFILE)) { String idString = getTextValue(findChild(profile, PomEdits.ID)); if (idString != null && activeprofiles.contains(idString)) { dependencies = findChild(profile, PomEdits.DEPENDENCIES); if (dependencies != null) { for (Element el : findChilds(dependencies, PomEdits.DEPENDENCY)) { Element version = findChild(el, PomEdits.VERSION); if (version != null) { candidates.add(el); candidateProfile.put(el, idString); } } } } } } //collect the managed dep ids Map<String, String> managed = new HashMap<String, String>(); DependencyManagement dm = mavenproject.getDependencyManagement(); if (dm != null) { List<Dependency> deps = dm.getDependencies(); if (deps != null) { for (Dependency dep : deps) { if (dep.getVersion() != null) { //#335366 //shall we be using geManagementkey() here? but it contains also the type, not only the gr+art ids.. managed.put(dep.getGroupId() + ":" + dep.getArtifactId(), dep.getVersion()); //$NON-NLS-1$ } } } } //now we have all the candidates, match them against the effective managed set for (Element dep : candidates) { Element version = findChild(dep, PomEdits.VERSION); String grpString = getTextValue(findChild(dep, PomEdits.GROUP_ID)); String artString = getTextValue(findChild(dep, PomEdits.ARTIFACT_ID)); String versionString = getTextValue(version); if (grpString != null && artString != null && versionString != null) { String id = grpString + ":" + artString; //$NON-NLS-1$ if (managed.containsKey(id)) { String managedVersion = managed.get(id); if (version instanceof IndexedRegion) { IndexedRegion off = (IndexedRegion) version; if (lookForIgnoreMarker(document, version, off, IMavenConstants.MARKER_IGNORE_MANAGED)) { continue; } IMarker mark = mavenMarkerManager.addMarker(pomFile, type, NLS.bind(org.eclipse.m2e.core.internal.Messages.MavenMarkerManager_managed_title, managedVersion, artString), document.getLineOfOffset(off.getStartOffset()) + 1, IMarker.SEVERITY_WARNING); mark.setAttribute(IMavenConstants.MARKER_ATTR_EDITOR_HINT, IMavenConstants.EDITOR_HINT_MANAGED_DEPENDENCY_OVERRIDE); mark.setAttribute(IMarker.CHAR_START, off.getStartOffset()); mark.setAttribute(IMarker.CHAR_END, off.getEndOffset()); mark.setAttribute("problemType", "pomhint"); //only imporant in case we enable the generic xml quick fixes //$NON-NLS-1$ //$NON-NLS-2$ //add these attributes to easily and deterministicaly find the declaration in question mark.setAttribute("groupId", grpString); //$NON-NLS-1$ mark.setAttribute("artifactId", artString); //$NON-NLS-1$ String profile = candidateProfile.get(dep); if (profile != null) { mark.setAttribute("profile", profile); //$NON-NLS-1$ } } } } } }
From source file:org.eclipse.m2e.editor.xml.PomTemplateContext.java
License:Open Source License
static String searchDM(MavenProject project, String groupId, String artifactId) { if (project == null) { return null; }/*ww w. java 2 s . c o m*/ String version = null; //see if we can find the dependency is in dependency management of resolved project. String id = groupId + ":" + artifactId + ":"; DependencyManagement dm = project.getDependencyManagement(); if (dm != null) { for (Dependency dep : dm.getDependencies()) { if (dep.getManagementKey().startsWith(id)) { version = dep.getVersion(); break; } } } return version; }
From source file:org.efaps.maven_java5.EfapsAnnotationDescriptorExtractor.java
License:Open Source License
/** * * @param _project/*from ww w . ja va 2 s .c om*/ * @return * @throws InvalidPluginDescriptorException */ protected Map<String, Artifact> getManagedVersionMap(final MavenProject _project) throws InvalidPluginDescriptorException { final Map<String, Artifact> map = new HashMap<String, Artifact>(); final DependencyManagement dependencyManagement = _project.getDependencyManagement(); final String projectId = _project.getId(); if ((dependencyManagement != null) && (dependencyManagement.getDependencies() != null)) { for (final Object obj : dependencyManagement.getDependencies()) { final Dependency d = (Dependency) obj; try { final VersionRange versionRange = VersionRange.createFromVersionSpec(d.getVersion()); final Artifact artifact = this.artifactFactory.createDependencyArtifact(d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), d.getClassifier(), d.getScope(), d.isOptional()); map.put(d.getManagementKey(), artifact); } catch (final InvalidVersionSpecificationException e) { throw new InvalidPluginDescriptorException( "Unable to parse version '" + d.getVersion() + "' for dependency '" + d.getManagementKey() + "' in project " + projectId + " : " + e.getMessage(), e); } } } return map; }
From source file:org.fusesource.ide.camel.model.service.core.util.OnlineArtifactVersionSearcher.java
License:Open Source License
private Dependency retrieveAnyFuseBomUsed(MavenProject mavenProject) { DependencyManagement dependencyManagement = mavenProject.getDependencyManagement(); return retrieveAnyFuseBomUsed(dependencyManagement); }
From source file:org.fusesource.ide.projecttemplates.maven.CamelProjectConfigurator.java
License:Open Source License
private String getCamelVersion(MavenProject mavenProject) throws CoreException { for (Dependency dep : mavenProject.getDependencies()) { if (isCamelDependency(dep)) { return dep.getVersion(); }//from w ww. j ava 2 s. co m } if (mavenProject.getDependencyManagement() != null) { for (Dependency dep : mavenProject.getDependencyManagement().getDependencies()) { if (isCamelDependency(dep)) { return dep.getVersion(); } } } // use deprecated dependency method as a last resort if (mavenProject.getCompileDependencies() != null) { for (Dependency dep : mavenProject.getCompileDependencies()) { if (isCamelDependency(dep)) { return dep.getVersion(); } } } return CamelModelFactory.getLatestCamelVersion(); }
From source file:org.jboss.tools.arquillian.editor.internal.services.ProtocolDependenciesService.java
License:Open Source License
public static List<Dependency> getDependencies(IProject project) { List<Dependency> dependencies = new ArrayList<Dependency>(); Dependency dependency = new Dependency(); dependency.setGroupId(SERVLET_PROTOCOL_GROUP_ID); dependency.setArtifactId(SERVLET_PROTOCOL_ARTIFACT_ID); boolean isManaged = false; try {/*from w w w . j a va 2s .c om*/ IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().create(project, new NullProgressMonitor()); if (facade != null) { MavenProject mavenProject = facade.getMavenProject(new NullProgressMonitor()); if (mavenProject != null) { DependencyManagement depMgmt = mavenProject.getDependencyManagement(); List<Dependency> mgmtDeps = depMgmt.getDependencies(); for (Dependency mgmtDep : mgmtDeps) { if (SERVLET_PROTOCOL_GROUP_ID.equals(mgmtDep.getGroupId()) && SERVLET_PROTOCOL_ARTIFACT_ID.equals(mgmtDep.getArtifactId())) { isManaged = true; break; } } } } } catch (CoreException e) { ArquillianUIActivator.logWarning(e.getLocalizedMessage()); } if (!isManaged) { String coords = dependency.getGroupId() + ":" + dependency.getArtifactId() + ":[0,)"; //$NON-NLS-1$//$NON-NLS-2$ String version = ArquillianUtility.getHighestVersion(coords); dependency.setVersion(version); } dependency.setScope(Artifact.SCOPE_TEST); dependencies.add(dependency); return dependencies; }
From source file:org.kloeckner.maven.plugin.VersionRange.java
License:Apache License
private Map<String, String> getOriginalVersionMap(MavenProject projects) { HashMap<String, String> hashMap = new HashMap<String, String>(); // TODO depmgmt, parent ... if (projects.getParentArtifact() != null) { hashMap.put(/*from w w w .j a va2 s. co m*/ ArtifactUtils.versionlessKey(projects.getParentArtifact().getGroupId(), projects.getParentArtifact().getArtifactId()), projects.getParentArtifact().getArtifactId()); } hashMap.putAll(buildVersionsMap(projects.getDependencies())); if (projects.getDependencyManagement() != null) { hashMap.putAll(buildVersionsMap(projects.getDependencyManagement().getDependencies())); } for (Profile profile : projects.getActiveProfiles()) { hashMap.putAll(buildVersionsMap(profile.getDependencies())); if (profile.getDependencyManagement() != null) { hashMap.putAll(buildVersionsMap(profile.getDependencyManagement().getDependencies())); } } return hashMap; }
From source file:org.phenotips.tool.packager.PackageMojo.java
License:Open Source License
private String getDependencyManagementVersion(MavenProject project, String groupId, String artifactId) throws MojoExecutionException { for (Object dependencyObject : project.getDependencyManagement().getDependencies()) { Dependency dependency = (Dependency) dependencyObject; if (dependency.getGroupId().equals(groupId) && dependency.getArtifactId().equals(artifactId)) { return dependency.getVersion(); }/* ww w.j a v a2s .com*/ } throw new MojoExecutionException( String.format("Failed to find artifact [%s:%s] in dependency management " + "for [%s]", groupId, artifactId, project.toString())); }