public static void addBomsWithHigherPrecedence(Model pomModel, String bomsWithHigherPrecedence) throws IOException { DependencyManagement dependencyManagement = pomModel.getDependencyManagement(); int i = 0; String[] boms = StringUtils.commaDelimitedListToStringArray(bomsWithHigherPrecedence); for (String bom : boms) { String[] coordinates = StringUtils.delimitedListToStringArray(bom, ":"); if (coordinates.length != 3) { throw new IllegalStateException("Coordinates for additional boms are not defined properly.\n" + "It needs to follow a comma separated pattern of groupId:artifactId:version"); } String groupId = coordinates[0]; String artifactId = coordinates[1]; String version = coordinates[2]; Dependency dependency = new Dependency(); dependency.setGroupId(groupId); dependency.setArtifactId(artifactId); dependency.setVersion(version); dependency.setType("pom"); dependency.setScope("import"); dependencyManagement.getDependencies().add(i++, dependency); } pomModel.setDependencyManagement(dependencyManagement); }
private void visitDependencyManagement( ModelVisitor visitor, DependencyManagement dependencyManagement ) { List<Dependency> dependencies = dependencyManagement.getDependencies(); if ( dependencies != null ) { ListIterator<Dependency> dependencyIterator = dependencies.listIterator(); while ( dependencyIterator.hasNext() ) { Dependency dependency = dependencyIterator.next(); visitor.visitDependencyManagementDependency( dependency ); visitDependencyManagementDependency( visitor, dependency ); dependency = visitor.replaceDependencyManagementDependency( dependency ); if ( dependency == null ) dependencyIterator.remove(); else dependencyIterator.set( dependency ); } } }
private void visitProfileDependencyManagement( ModelVisitor visitor, DependencyManagement dependencyManagement ) { List<Dependency> dependencies = dependencyManagement.getDependencies(); if ( dependencies != null ) { ListIterator<Dependency> dependencyIterator = dependencies.listIterator(); while ( dependencyIterator.hasNext() ) { Dependency dependency = dependencyIterator.next(); visitor.visitProfileDependencyManagementDependency( dependency ); visitProfileDependencyManagementDependency( visitor, dependency ); dependency = visitor.replaceProfileDependencyManagementDependency( dependency ); if ( dependency == null ) dependencyIterator.remove(); else dependencyIterator.set( dependency ); } } }
/** * * @param projectId * @param dependencyManagement * @return * @throws ProjectBuildingException */ private Map createManagedVersionMap(String projectId, DependencyManagement dependencyManagement) throws ProjectBuildingException { Map map; if (dependencyManagement != null && dependencyManagement.getDependencies() != null) { map = new HashMap(); for (Dependency d : dependencyManagement.getDependencies()) { try { VersionRange versionRange = VersionRange.createFromVersionSpec(d.getVersion()); Artifact artifact = factory.createDependencyArtifact(d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), d.getClassifier(), d.getScope()); map.put(d.getManagementKey(), artifact); } catch (InvalidVersionSpecificationException e) { throw new ProjectBuildingException(projectId, "Unable to parse version '" + d.getVersion() + "' for dependency '" + d.getManagementKey() + "': " + e.getMessage(), e); } } } else { map = Collections.EMPTY_MAP; } return map; }
/** * Remove the Maven dependency from a POM file (in management section). * * @param pom * @param dependency * @throws IOException * @throws XmlPullParserException */ public static void removeDependencyManagement(File pom, Dependency dependency, Log logger) throws IOException, XmlPullParserException { Model model = getModelFromPOM(pom, logger); DependencyManagement dMgmt = model.getDependencyManagement(); if (dMgmt == null) { model.setDependencyManagement(new DependencyManagement()); dMgmt = model.getDependencyManagement(); } for (Iterator<Dependency> it = dMgmt.getDependencies().iterator(); it.hasNext();){ if (dependenciesEqual(it.next(), dependency)) { it.remove(); } } writeModelToPOM(model, pom, logger); }
private void checkForSubmoduleDependencyManagement(final MavenProject project, Log log) { if (projectHasManagedDependencies(project) && !ruleIsDefinedInProjectOrNotModuleParent(project, log) && !isExcluded(RuleHelper.getProjectIdentifier(project))) { final DependencyManagement dependencyManagement = project.getOriginalModel().getDependencyManagement(); if (dependencyManagement.getDependencies().size() > 0) { failureDetected = true; logHeader(log, "dependency management in sub modules"); for (Dependency dependency : dependencyManagement.getDependencies()) { log.warn("module '" + project.getArtifact().getDependencyConflictId() + "' has dependency management for: " + dependency.getManagementKey()); } } } }
private static void validate(final Model model) { final List<Dependency> dependencies = model.getDependencies(); for (final Dependency dependency : dependencies) { if (dependency.getVersion() == null) { final DependencyManagement dm = model.getDependencyManagement(); final String version = findVersion(dm, dependency); if (version == null) { throw new IllegalStateException( "Dependency version not set for '" + dependency.getGroupId() + ":" + dependency.getArtifactId() + "' in '" + model.getGroupId() + ":" + model.getArtifactId() + ":" + model.getVersion() + "'"); } dependency.setVersion(Utils4J.replaceVars(version, createVarMap(model))); } } }
@SuppressWarnings("unchecked") protected void injectDependencyDefaults(Dependency[] dependencies) { if (dependencies != null) { final Map<String, Dependency> dependencyMap = new TreeMap<String, Dependency>(); for (final Dependency dependency : dependencies) { if (dependency.getScope() == null) { dependency.setScope(Artifact.SCOPE_RUNTIME); } dependencyMap.put(dependency.getManagementKey(), dependency); } final DependencyManagement dependencyManagement = getProject().getDependencyManagement(); if (dependencyManagement != null) { merge(dependencyMap, dependencyManagement.getDependencies()); } merge(dependencyMap, getProjectDependencies()); } }
/** * This method will scan the dependencies in the dependencyManagement section of the potentially active Profiles in * this project and return a fully resolved list. Note that while updating the {@link Dependency} * reference returned will be reflected in the Model as it is the same object, if you wish to remove or add items * to the Model then you must use {@link #getModel()} * * @param session MavenSessionHandler, used by {@link PropertyResolver} * @return a list of fully resolved {@link ArtifactRef} to the original {@link Dependency} (that were within DependencyManagement) * @throws ManipulationException if an error occurs */ public HashMap<Profile, HashMap<ArtifactRef, Dependency>> getResolvedProfileManagedDependencies( MavenSessionHandler session) throws ManipulationException { if ( resolvedProfileManagedDependencies == null ) { resolvedProfileManagedDependencies = new HashMap<>( ); for ( final Profile profile : ProfileUtils.getProfiles( session, model ) ) { HashMap<ArtifactRef, Dependency> profileDeps = new HashMap<>(); final DependencyManagement dm = profile.getDependencyManagement(); if ( ! ( dm == null || dm.getDependencies() == null ) ) { resolveDeps( session, dm.getDependencies(), false, profileDeps ); resolvedProfileManagedDependencies.put( profile, profileDeps ); } } } return resolvedProfileManagedDependencies; }
public void testCloneWithDependencyManagement() throws Exception { File f = getFileForClasspathResource( "dependencyManagement-pom.xml" ); MavenProject projectToClone = getProjectWithDependencies( f ); DependencyManagement dep = projectToClone.getDependencyManagement(); assertNotNull( "No dependencyManagement", dep ); List<?> list = dep.getDependencies(); assertNotNull( "No dependencies", list ); assertTrue( "Empty dependency list", !list.isEmpty() ); Map<?, ?> map = projectToClone.getManagedVersionMap(); assertNotNull( "No ManagedVersionMap", map ); assertTrue( "ManagedVersionMap is empty", !map.isEmpty() ); MavenProject clonedProject = projectToClone.clone(); assertEquals( "maven-core", clonedProject.getArtifactId() ); Map<?, ?> clonedMap = clonedProject.getManagedVersionMap(); assertNotNull( "ManagedVersionMap not copied", clonedMap ); assertTrue( "ManagedVersionMap is empty", !clonedMap.isEmpty() ); assertTrue( "ManagedVersionMap does not contain test key", clonedMap.containsKey( "maven-test:maven-test-b:jar" ) ); }
@Override public boolean isBom(Model model) { if (bomGavPattern != null) { String gav = model.getId(); if (bomGavPattern.matcher(gav).matches()) { return true; } } if (model.getPackaging() != null && model.getGroupId() != null && model.getArtifactId() != null && model.getPackaging().equals("pom")) { if (model.getGroupId().contains("bom") || model.getArtifactId().contains("bom")) { DependencyManagement depMng = model.getDependencyManagement(); if (depMng != null && depMng.getDependencies() != null && !depMng.getDependencies().isEmpty()) { return true; } } } return false; }
/** Creates a new instance of VersionNode */ public VersionNode(NBVersionInfo versionInfo, boolean fromDepMng) { super(Children.LEAF, fromDepMng ? Lookups.fixed(versionInfo, new DependencyManagement()) : Lookups.fixed(versionInfo)); this.nbvi = versionInfo; this.fromDepMng = fromDepMng; setName(versionInfo.getVersion()); StringBuilder sb = new StringBuilder(); if (fromDepMng) { sb.append(nbvi.getGroupId()); sb.append(DELIMITER); sb.append(nbvi.getArtifactId()); sb.append(DELIMITER); } else { sb.append(nbvi.getVersion()); } sb.append(" [ "); sb.append(nbvi.getType()); String classifier = nbvi.getClassifier(); if (classifier != null) { sb.append(","); sb.append(classifier); } sb.append(" ] "); String repo = nbvi.getRepoId(); if (repo != null) { sb.append(" - "); sb.append(repo); } setDisplayName(sb.toString()); setIconBaseWithExtension(IconResources.ICON_DEPENDENCY_JAR); }
public boolean isManaged() { DependencyManagement dm = project.getLookup().lookup(NbMavenProject.class).getMavenProject().getDependencyManagement(); if (dm != null) { List<Dependency> dmList = dm.getDependencies(); for (Dependency d : dmList) { if (art.getGroupId().equals(d.getGroupId()) && art.getArtifactId().equals(d.getArtifactId())) { return true; } } } return false; }
private static List<Dependency> getDependenciesFromDM(MavenProject project, Project nbprj) { NbMavenProjectImpl p = nbprj.getLookup().lookup(NbMavenProjectImpl.class); MavenProject localProj = project; DependencyManagement curDM; List<Dependency> result = new ArrayList<Dependency>(); //mkleint: without the managementKey checks I got some entries multiple times. // do we actually need to traverse the parent poms, are they completely resolved anyway? //XXX Set<String> knownKeys = new HashSet<String>(); while (localProj != null) { curDM = localProj.getDependencyManagement(); if (curDM != null) { @SuppressWarnings("unchecked") List<Dependency> ds = curDM.getDependencies(); for (Dependency d : ds) { if (knownKeys.contains(d.getManagementKey())) { continue; } result.add(d); knownKeys.add(d.getManagementKey()); } } try { localProj = p.loadParentOf(EmbedderFactory.getProjectEmbedder(), localProj); } catch (ProjectBuildingException x) { break; } } Collections.sort(result, new Comparator<Dependency>() { @Override public int compare(Dependency o1, Dependency o2) { return o1.getManagementKey().compareTo(o2.getManagementKey()); } }); return result; }
private void writeDependencyManagement(DependencyManagement dependencyManagement, String tagName, XmlSerializer serializer) throws java.io.IOException { serializer.startTag(NAMESPACE, tagName); if ((dependencyManagement.getDependencies() != null) && (dependencyManagement.getDependencies().size() > 0)) { serializer.startTag(NAMESPACE, "dependencies"); for (Iterator iter = dependencyManagement.getDependencies().iterator(); iter.hasNext();) { Dependency o = (Dependency) iter.next(); writeDependency(o, "dependency", serializer); } serializer.endTag(NAMESPACE, "dependencies"); } serializer.endTag(NAMESPACE, tagName); }
private int obtainManagedState(MavenDependencyNode dependencyNode) { if (proj == null) { return GraphNode.UNMANAGED; } DependencyManagement dm = proj.getDependencyManagement(); if (dm == null) { return GraphNode.UNMANAGED; } @SuppressWarnings("unchecked") List<Dependency> deps = dm.getDependencies(); if (deps == null) { return GraphNode.UNMANAGED; } Artifact artifact = dependencyNode.getArtifact(); String id = artifact.getArtifactId(); String groupId = artifact.getGroupId(); String version = artifact.getVersion(); for (Dependency dep : deps) { if (id.equals(dep.getArtifactId()) && groupId.equals(dep.getGroupId())) { if (!version.equals(dep.getVersion())) { return GraphNode.OVERRIDES_MANAGED; } else { return GraphNode.MANAGED; } } } return GraphNode.UNMANAGED; }
private Model mockDepManagementModel(String dependencyManagementDep, String normalDep) { Dependency dmDep = getDependency(dependencyManagementDep); Dependency dep = getDependency(normalDep); Model mockModel = mock(Model.class); DependencyManagement dependencyManagement = new DependencyManagement(); dependencyManagement.addDependency(dmDep); when(mockModel.getDependencyManagement()).thenReturn(dependencyManagement); when(mockModel.getDependencies()).thenReturn(ImmutableList.of(dep)); return mockModel; }
/** * Method updateDependencyManagement * * @param value * @param element * @param counter * @param xmlTag */ protected void updateDependencyManagement( DependencyManagement value, String xmlTag, Counter counter, Element element ) { boolean shouldExist = value != null; Element root = updateElement( counter, element, xmlTag, shouldExist ); if ( shouldExist ) { Counter innerCount = new Counter( counter.getDepth() + 1 ); iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" ); } }
/** * Returns true if the pom has the given managed dependency */ public static boolean hasManagedDependency(Model pom, String groupId, String artifactId) { if (pom != null) { DependencyManagement dependencyManagement = pom.getDependencyManagement(); if (dependencyManagement != null) { return hasDependency(dependencyManagement.getDependencies(), groupId, artifactId); } } return false; }
public static void addAdditionalBoms(Model pomModel, List<Bom> additionalBoms) throws IOException { DependencyManagement dependencyManagement = pomModel.getDependencyManagement(); int i = 0; for (Bom bom : additionalBoms) { Dependency dependency = new Dependency(); dependency.setGroupId(bom.getGroupId()); dependency.setArtifactId(bom.getArtifactId()); dependency.setVersion(bom.getVersion()); dependency.setType("pom"); dependency.setScope("import"); dependencyManagement.getDependencies().add(++i, dependency); } pomModel.setDependencyManagement(dependencyManagement); }
private Set<ArtifactCoordinates> getSnapshotsFromManagement(MavenProject project, PomPropertyResolver propertyResolver) { this.log.debug("\t\tChecking managed dependencies"); DependencyManagement dependencyManagement = project.getDependencyManagement(); if (dependencyManagement != null) { Collection<Dependency> snapshots = Collections2.filter(dependencyManagement.getDependencies(), new IsSnapshotDependency(propertyResolver)); HashSet<ArtifactCoordinates> snapshotDependencies = Sets .newHashSet(Collections2.transform(snapshots, DependencyToCoordinates.INSTANCE)); filterMultiModuleDependencies(snapshotDependencies); return snapshotDependencies; } return Collections.emptySet(); }
private Set<ArtifactCoordinates> getSnapshotsFromManagement(Profile profile, PomPropertyResolver propertyResolver) { this.log.debug("\t\tChecking managed dependencies of profile '" + profile.getId() + "'"); DependencyManagement dependencyManagement = profile.getDependencyManagement(); if (dependencyManagement != null) { Collection<Dependency> snapshots = Collections2.filter(dependencyManagement.getDependencies(), new IsSnapshotDependency(propertyResolver)); return Sets.newHashSet(Collections2.transform(snapshots, DependencyToCoordinates.INSTANCE)); } return Collections.emptySet(); }
public MavenArtifactResolvingHelper(ArtifactResolver resolver, RepositorySystem system, RepositorySystemSession session, DependencyManagement dependencyManagement) { this.resolver = resolver; this.system = system; this.session = session; this.dependencyManagement = dependencyManagement; this.remoteRepositories.add(buildRemoteRepository("jboss-public-repository-group", "https://repository.jboss.org/nexus/content/groups/public/", null, ENABLED_POLICY, DISABLED_POLICY)); }
@Override protected List<Dependency> determineDependencies(final Model model) { List<Dependency> dependencies = Collections.emptyList(); final DependencyManagement mgmt = model.getDependencyManagement(); if (mgmt != null) { dependencies = mgmt.getDependencies(); } return dependencies; }
/** * Add the Maven dependency to a POM file (in management section). * * @param pom * @param dependency * @throws IOException * @throws XmlPullParserException */ public static void addDependencyManagement(File pom, Dependency dependency, Log logger) throws IOException, XmlPullParserException { Model model = getModelFromPOM(pom, logger); DependencyManagement dMgmt = model.getDependencyManagement(); if (dMgmt == null) { model.setDependencyManagement(new DependencyManagement()); dMgmt = model.getDependencyManagement(); } dMgmt.addDependency(dependency); writeModelToPOM(model, pom, logger); }
/** * Check whether a dependency exists in a POM (in management section). * * @param pom * @param dependency * @param logger * @return true if the dependency exists in the management section of the * POM * @throws IOException * @throws XmlPullParserException */ public static boolean dependencyExistsManagement(File pom, Dependency dependency, Log logger) throws IOException, XmlPullParserException { Model model = getModelFromPOM(pom, logger); DependencyManagement dMgmt = model.getDependencyManagement(); if (dMgmt == null) { model.setDependencyManagement(new DependencyManagement()); dMgmt = model.getDependencyManagement(); } return dependencyExists(dependency, dMgmt.getDependencies()); }
private static String findVersion(final DependencyManagement dm, final Dependency dep) { final List<Dependency> dependencies = dm.getDependencies(); for (final Dependency dependency : dependencies) { if ((dependency.getGroupId().equals(dep.getGroupId())) && (dependency.getArtifactId().equals(dep.getArtifactId()))) { return dependency.getVersion(); } } return null; }
/** * Returns all dependencies defined in dependency management of the root pom. * * @return */ private Set<Artifact> getProjectDependencyManagement() { Set<Artifact> result = new LinkedHashSet<Artifact>(); DependencyManagement dependencyManagement = getProject().getDependencyManagement(); if (dependencyManagement != null) { for (Dependency dependency : dependencyManagement.getDependencies()) { result.add(toArtifact(dependency)); } } return result; }
protected Map createManagedVersionMap(String projectId, DependencyManagement dependencyManagement) throws ProjectBuildingException { Map map; if (dependencyManagement != null && dependencyManagement.getDependencies() != null) { map = new HashMap(); for (Iterator i = dependencyManagement.getDependencies().iterator(); i .hasNext();) { Dependency d = (Dependency) i.next(); try { VersionRange versionRange = VersionRange .createFromVersionSpec(d.getVersion()); Artifact artifact = factory.createDependencyArtifact(d .getGroupId(), d.getArtifactId(), versionRange, d .getType(), d.getClassifier(), d.getScope()); map.put(d.getManagementKey(), artifact); } catch (InvalidVersionSpecificationException e) { throw new ProjectBuildingException(projectId, "Unable to parse version '" + d.getVersion() + "' for dependency '" + d.getManagementKey() + "': " + e.getMessage(), e); } } } else { map = Collections.EMPTY_MAP; } return map; }
/** * This method will scan the dependencies in the dependencyManagement section of this project and return a * fully resolved list. Note that while updating the {@link Dependency} reference returned will be reflected * in the Model as it is the same object, if you wish to remove or add items to the Model then you must use {@link #getModel()} * * @param session MavenSessionHandler, used by {@link PropertyResolver} * @return a list of fully resolved {@link ArtifactRef} to the original {@link Dependency} (that were within DependencyManagement) * @throws ManipulationException if an error occurs */ public HashMap<ArtifactRef, Dependency> getResolvedManagedDependencies( MavenSessionHandler session ) throws ManipulationException { if ( resolvedManagedDependencies == null ) { resolvedManagedDependencies = new HashMap<>( ); final DependencyManagement dm = getModel().getDependencyManagement(); if ( ! ( dm == null || dm.getDependencies() == null ) ) { resolveDeps( session, dm.getDependencies(), false, resolvedManagedDependencies ); } } return resolvedManagedDependencies; }
private boolean apply( final Project project, final Model model ) throws ManipulationException { boolean result = false; final RelocationState state = session.getState( RelocationState.class ); final WildcardMap<ProjectVersionRef> relocations = state.getDependencyRelocations(); logger.debug( "Applying relocation changes to: " + ga( project ) ); DependencyManagement dependencyManagement = model.getDependencyManagement(); if ( dependencyManagement != null ) { result = updateDependencies( relocations, project.getResolvedManagedDependencies( session ) ); } result |= updateDependencies( relocations, project.getAllResolvedDependencies( session ) ); for ( final Profile profile : ProfileUtils.getProfiles( session, model) ) { dependencyManagement = profile.getDependencyManagement(); if ( dependencyManagement != null ) { result |= updateDependencies( relocations, project.getResolvedProfileManagedDependencies( session ).get( profile ) ); } result |= updateDependencies( relocations, project.getAllResolvedProfileDependencies( session ).get( profile ) ); } return result; }
public Map<String, Artifact> getManagedVersionMap() { if ( managedVersionMap != null ) { return managedVersionMap; } Map<String, Artifact> map = null; if ( repositorySystem != null ) { List<Dependency> deps; DependencyManagement dependencyManagement = getDependencyManagement(); if ( ( dependencyManagement != null ) && ( ( deps = dependencyManagement.getDependencies() ) != null ) && ( deps.size() > 0 ) ) { map = new HashMap<String, Artifact>(); for ( Iterator<Dependency> i = dependencyManagement.getDependencies().iterator(); i.hasNext(); ) { Dependency d = i.next(); Artifact artifact = repositorySystem.createDependencyArtifact( d ); if ( artifact == null ) { map = Collections.emptyMap(); } map.put( d.getManagementKey(), artifact ); } } else { map = Collections.emptyMap(); } } managedVersionMap = map; return managedVersionMap; }
private static int obtainManagedState (Artifact artifact, DependencyGraphScene scene) { MavenProject proj = scene.getMavenProject(); if (proj == null) { return ArtifactGraphNode.UNMANAGED; } DependencyManagement dm = proj.getDependencyManagement(); if (dm == null) { return ArtifactGraphNode.UNMANAGED; } @SuppressWarnings("unchecked") List<Dependency> deps = dm.getDependencies(); if (deps == null) { return ArtifactGraphNode.UNMANAGED; } String id = artifact.getArtifactId(); String groupId = artifact.getGroupId(); String version = artifact.getVersion(); for (Dependency dep : deps) { if (id.equals(dep.getArtifactId()) && groupId.equals(dep.getGroupId())) { if (!version.equals(dep.getVersion())) { return ArtifactGraphNode.OVERRIDES_MANAGED; } else { return ArtifactGraphNode.MANAGED; } } } return ArtifactGraphNode.UNMANAGED; }
public void processModules(ProjectBuildingRequest projectBuildingRequest, MavenProject project) { String modulesText = project.getProperties().getProperty(PROP_CONTRACTORS); if (modulesText == null || modulesText.trim().isEmpty()) { if (Flag.verbose()) { logger.info("No available modules in '{}'", PROP_CONTRACTORS); } else if (logger.isDebugEnabled()) { logger.debug("No available modules in '{}'", PROP_CONTRACTORS); } return; } String[] modulesArray = modulesText.split("[\\s]*[,\\n][\\s]*"); Set<String> modulesSet = Arrays.stream(modulesArray).collect(Collectors.toSet()); modulesSet.add("com.commsen.em.contractors:em.contractors.runtime:" + VAL_EXTENSION_VERSION); for (String moduleText : modulesSet) { String[] coordinates = moduleText.split(":"); if (coordinates.length != 3) { logger.warn("Invalid maven coordinates for module '{}'! It will be ignored!", moduleText); continue; } Dependency dependency = new Dependency(); dependency.setGroupId(coordinates[0]); dependency.setArtifactId(coordinates[1]); dependency.setVersion(coordinates[2]); dependency.setScope("runtime"); dependency.setType("pom"); try { Artifact pomArtifact = dependencies.asArtifact(projectBuildingRequest, dependency); dependency.setType("jar"); MavenXpp3Reader reader = new MavenXpp3Reader(); Model model = reader.read(new FileInputStream(pomArtifact.getFile())); DependencyManagement dm = model.getDependencyManagement(); if (dm == null) { dependencies.addToDependencyManagement(project, dependency); } else { for (Dependency d : dm.getDependencies()) { /* * TODO handle variables properly! For now assume variable is referring to the * contract's artifact itself (that's what EM contractors do). */ if (d.getArtifactId().startsWith("${")) { dependencies.addToDependencyManagement(project, dependency); } else { dependencies.addToDependencyManagement(project, d); } } } } catch (Exception e) { logger.warn("Could not process modules from " + coordinates[0] + ":" + coordinates[1] + ":" + coordinates[2], e); } } }
public void addToDependencyManagement(MavenProject project, Dependency dependency) { if (project.getModel().getDependencyManagement() == null) { project.getModel().setDependencyManagement(new DependencyManagement()); } project.getModel().getDependencyManagement().addDependency(dependency);; }
@Override public void actionPerformed(ActionEvent e) { Project prj = lookup.lookup(Project.class); boolean set = false; if (prj != null) { NbMavenProject mav = prj.getLookup().lookup(NbMavenProject.class); MavenProject m = mav.getMavenProject(); AddDependencyPanel.this.setFields(m.getGroupId(), m.getArtifactId(), m.getVersion(), null, null); set = true; } if (!set) { NBVersionInfo vi = lookup.lookup(NBVersionInfo.class); if (vi != null) { //in dm panel we want to pass empty version boolean isDM = lookup.lookup(DependencyManagement.class) != null; String ver = isDM ? "" : vi.getVersion(); String type = isDM ? "" : vi.getType(); String classifier = isDM ? "" : vi.getClassifier(); AddDependencyPanel.this.setFields(vi.getGroupId(), vi.getArtifactId(), ver, type, classifier); set = true; } } if (set) { if (close) { AddDependencyPanel.this.getOkButton().doClick(); } else { //reset completion. AddDependencyPanel.this.artifactCompleter.setLoading(true); AddDependencyPanel.this.versionCompleter.setLoading(true); final String groupId = txtGroupId.getText().trim(); final String artifactId = txtArtifactId.getText().trim(); RP.post(new Runnable() { @Override public void run() { populateArtifact(groupId); populateVersion(groupId, artifactId); } }); } } else { AddDependencyPanel.this.setFields("", "", "", "", ""); //NOI18N //reset completion. AddDependencyPanel.this.artifactCompleter.setValueList(Collections.<String>emptyList(), false); AddDependencyPanel.this.versionCompleter.setValueList(Collections.<String>emptyList(), false); } }
public void setDependencyManagement(DependencyManagement depMgt) { this.dependencyManagement = depMgt; }