Java Code Examples for org.apache.maven.project.MavenProject#getDependencies()
The following examples show how to use
org.apache.maven.project.MavenProject#getDependencies() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MavenUtilTest.java From jkube with Eclipse Public License 2.0 | 6 votes |
@Test public void testGetDependencies(@Mocked MavenProject mavenProject) { // Given final org.apache.maven.model.Dependency dep1 = new org.apache.maven.model.Dependency(); dep1.setGroupId("org.eclipse.jkube"); dep1.setArtifactId("artifact1"); dep1.setVersion("1.33.7"); dep1.setType("war"); dep1.setScope("compile"); final org.apache.maven.model.Dependency dep2 = dep1.clone(); dep2.setArtifactId("artifact2"); dep2.setType("jar"); new Expectations() { { mavenProject.getDependencies(); result = Arrays.asList(dep1, dep2); } }; // When final List<Dependency> dependencies = MavenUtil.getDependencies(mavenProject); // Then assertThat(dependencies, hasSize(2)); }
Example 2
Source File: ArtifactDependencyIndexCreator.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void populateArtifactInfo(ArtifactContext context) throws IOException { ArtifactInfo ai = context.getArtifactInfo(); if (ai.getClassifier() != null) { return; } try { MavenProject mp = load(ai); if (mp != null) { List<Dependency> dependencies = mp.getDependencies(); LOG.log(Level.FINER, "Successfully loaded project model from repository for {0} with {1} dependencies", new Object[] {ai, dependencies.size()}); dependenciesByArtifact.put(ai, dependencies); } } catch (InvalidArtifactRTException ex) { ex.printStackTrace(); } }
Example 3
Source File: WebModuleImpl.java From netbeans with Apache License 2.0 | 6 votes |
private Profile getProfileFromPOM(final Project project) { final NbMavenProject nbMavenProject = project.getLookup().lookup(NbMavenProject.class); if (nbMavenProject != null) { MavenProject mavenProject = nbMavenProject.getMavenProject(); List<Dependency> dependencies = mavenProject.getDependencies(); for (Map.Entry<Profile, List<DependencyDesc>> entry : javaEEMap.entrySet()) { for (DependencyDesc dependencyDesc : entry.getValue()) { Dependency dependency = checkForDependency(dependencies, dependencyDesc); if (dependency != null) { String version = dependency.getVersion(); if (dependencyDesc.version == null || (version != null && version.startsWith(dependencyDesc.version))) { return entry.getKey(); } } } } } return null; }
Example 4
Source File: EndpointMojo.java From fabric8-forge with Apache License 2.0 | 6 votes |
private static String findCamelVersion(MavenProject project) { Dependency candidate = null; for (Dependency dep : project.getDependencies()) { if ("org.apache.camel".equals(dep.getGroupId())) { if ("camel-core".equals(dep.getArtifactId())) { // favor camel-core candidate = dep; break; } else { candidate = dep; } } } if (candidate != null) { return candidate.getVersion(); } return null; }
Example 5
Source File: MavenProjectConfigurator.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Configure the GWT Nature. * * @param mavenProject * @param monitor */ protected void configureGwtProject(MavenProject mavenProject, IProgressMonitor monitor) { // Get the GWT version from the project pom String gwtVersion = null; List<Dependency> dependencies = mavenProject.getDependencies(); for (Dependency dependency : dependencies) { boolean hasGwtGroupId = GWTMavenRuntime.MAVEN_GWT_GROUP_ID.equals(dependency.getGroupId()); boolean hasGwtUserArtivactId = GWTMavenRuntime.MAVEN_GWT_USER_ARTIFACT_ID.equals(dependency.getArtifactId()); boolean hasGwtUserServletId = GWTMavenRuntime.MAVEN_GWT_SERVLET_ARTIFACT_ID.equals(dependency.getArtifactId()); if (hasGwtGroupId && (hasGwtUserArtivactId || hasGwtUserServletId)) { gwtVersion = dependency.getVersion(); Activator.log("MavenProjectConfigurator, Maven: Setting up Gwt Project. hasGwtGroupId=" + hasGwtGroupId + " hasGwtUser=" + hasGwtUserArtivactId + " hasGwtUserServletId=" + hasGwtUserServletId); break; } } Activator.log("MavenProjectConfigurator, Maven: gwtVersion=" + gwtVersion); resolveGwtDevJar(mavenProject, monitor, gwtVersion); }
Example 6
Source File: Utils.java From nb-springboot with Apache License 2.0 | 5 votes |
/** * Check if any of the project dependencies artifact ids contains the given string. * * @param nbMvn NB maven project * @param search string to look for * @return true if the project has a dependency artifactId containing the search string */ public static boolean dependencyArtifactIdContains(NbMavenProject nbMvn, String search) { MavenProject mPrj = nbMvn.getMavenProject(); for (Object o : mPrj.getDependencies()) { Dependency d = (Dependency) o; if (d.getArtifactId().contains(search)) { return true; } } return false; }
Example 7
Source File: GenerateBomMojo.java From sundrio with Apache License 2.0 | 5 votes |
/** * Returns all dependency artifacts in all modules, excluding all reactor artifacts (including attached). * * @return */ private Set<Artifact> getProjectDependencies() { Set<Artifact> result = new LinkedHashSet<Artifact>(); for (MavenProject p : getSession().getProjectDependencyGraph().getSortedProjects()) { for (Dependency dependency : p.getDependencies()) { result.add(toArtifact(dependency)); } } return result; }
Example 8
Source File: MavenGraphAdapter.java From depgraph-maven-plugin with Apache License 2.0 | 5 votes |
private ArtifactFilter createTransitiveDependencyFilter(MavenProject project) { List<String> dependencyKeys = new ArrayList<>(project.getDependencies().size()); for (Dependency dependency : project.getDependencies()) { dependencyKeys.add(dependency.getManagementKey()); } // Matches direct dependencies or the configured transitive dependencies or the project itself OrArtifactFilter artifactFilter = new OrArtifactFilter(); artifactFilter.add(this.transitiveIncludeExcludeFilter); artifactFilter.add(new StrictPatternIncludesArtifactFilter(dependencyKeys)); artifactFilter.add(new StrictPatternIncludesArtifactFilter(singletonList(project.getArtifact().toString()))); return artifactFilter; }
Example 9
Source File: ArtifactProjectDeleteParticipant.java From developer-studio with Apache License 2.0 | 5 votes |
/** * This method gets executed before the refactoring gets executed on * original file which means this method is executed before the actual * project is deleted from the workspace. If you have any task need to run * before the project is deleted, you need to generate Changes for those * tasks in this method. */ @Override public Change createPreChange(IProgressMonitor arg0) throws CoreException, OperationCanceledException { CompositeChange deleteChange = new CompositeChange("Delete Artifact Project"); IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (IProject project : projects) { if (project.isOpen() && project.hasNature("org.wso2.developerstudio.eclipse.distribution.project.nature")) { try { IFile pomFile = project.getFile(POM_XML); MavenProject mavenProject = ProjectRefactorUtils.getMavenProject(project); Dependency projectDependency = ProjectRefactorUtils.getDependencyForTheProject(originalProject); if (mavenProject != null) { List<?> dependencies = mavenProject.getDependencies(); if (projectDependency != null) { for (Iterator<?> iterator = dependencies.iterator(); iterator.hasNext();) { Dependency dependency = (Dependency) iterator.next(); if (ProjectRefactorUtils.isDependenciesEqual(projectDependency, dependency)) { deleteChange.add(new MavenConfigurationFileDeleteChange(project.getName(), pomFile, originalProject)); } } } } } catch (Exception e) { log.error("Error occured while trying to generate the Refactoring", e); } } } return deleteChange; }
Example 10
Source File: PreCompileMojo.java From jprotobuf with Apache License 2.0 | 5 votes |
/** * Resolve the executable dependencies for the specified project * * @param executablePomArtifact the project's POM * @return a set of Artifacts * @throws MojoExecutionException if a failure happens */ private Set<Artifact> resolveExecutableDependencies( Artifact executablePomArtifact ) throws MojoExecutionException { Set<Artifact> executableDependencies; try { MavenProject executableProject = this.projectBuilder.buildFromRepository( executablePomArtifact, this.remoteRepositories, this.localRepository ); // get all of the dependencies for the executable project List<Dependency> dependencies = executableProject.getDependencies(); // make Artifacts of all the dependencies Set<Artifact> dependencyArtifacts = MavenMetadataSource.createArtifacts( this.artifactFactory, dependencies, null, null, null ); // not forgetting the Artifact of the project itself dependencyArtifacts.add( executableProject.getArtifact() ); // resolve all dependencies transitively to obtain a comprehensive list of assemblies ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencyArtifacts, executablePomArtifact, Collections.emptyMap(), this.localRepository, this.remoteRepositories, metadataSource, null, Collections.emptyList() ); executableDependencies = result.getArtifacts(); } catch ( Exception ex ) { throw new MojoExecutionException( "Encountered problems resolving dependencies of the executable " + "in preparation for its execution.", ex ); } return executableDependencies; }
Example 11
Source File: AbstractGitFlowMojo.java From gitflow-maven-plugin with Apache License 2.0 | 5 votes |
protected void checkSnapshotDependencies() throws MojoFailureException { getLog().info("Checking for SNAPSHOT versions in dependencies."); List<String> snapshots = new ArrayList<String>(); List<String> builtArtifacts = new ArrayList<String>(); List<MavenProject> projects = mavenSession.getProjects(); for (MavenProject project : projects) { final MavenProject reloadedProject = reloadProject(project); builtArtifacts.add(reloadedProject.getGroupId() + ":" + reloadedProject.getArtifactId() + ":" + reloadedProject.getVersion()); List<Dependency> dependencies = reloadedProject.getDependencies(); for (Dependency d : dependencies) { String id = d.getGroupId() + ":" + d.getArtifactId() + ":" + d.getVersion(); if (!builtArtifacts.contains(id) && ArtifactUtils.isSnapshot(d.getVersion())) { snapshots.add(reloadedProject + " -> " + d); } } } if (!snapshots.isEmpty()) { for (String s : snapshots) { getLog().warn(s); } throw new MojoFailureException( "There is some SNAPSHOT dependencies in the project, see warnings above. Change them or ignore with `allowSnapshots` property."); } }
Example 12
Source File: ArtifactProjectRenameRefactorParticipant.java From developer-studio with Apache License 2.0 | 4 votes |
/** * This method gets executed before the refactoring gets executed on * original file which means * this method is executed before the actual project is deleted from the * workspace. * If you have any task need to run before the project is deleted, you need * to generate Changes * for those tasks in this method. */ @Override public Change createPreChange(IProgressMonitor arg0) throws CoreException, OperationCanceledException { IFile pomFile = originalProject.getFile("pom.xml"); CompositeChange artifactChange = new CompositeChange("Maven Configuration Refactor"); MavenConfigurationFileChange endpointArtifactFileChange = new MavenConfigurationFileChange( "HW", pomFile, originalProject.getName(), originalProject, latestName); artifactChange.add(endpointArtifactFileChange); IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (int i = 0; i < projects.length; i++) { if (projects[i].isOpen() && projects[i].hasNature("org.wso2.developerstudio.eclipse.distribution.project.nature")) { try { MavenProject mavenProject = MavenUtils.getMavenProject(projects[i].getFile("pom.xml").getLocation() .toFile()); List<?> dependencies = mavenProject.getDependencies(); for (Iterator<?> iterator = dependencies.iterator(); iterator.hasNext();) { Dependency dependency = (Dependency) iterator.next(); if (originalProject.getName().equalsIgnoreCase(dependency.getArtifactId())) { artifactChange.add(new MavenConfigurationFileChange(projects[i].getName(), projects[i].getFile("pom.xml"), originalProject.getName(), projects[i], latestName)); } } } catch (Exception e) { log.error("Error occured while trying to generate the Refactoring", e); } } } return artifactChange; }