List of usage examples for org.apache.maven.execution ProjectDependencyGraph getDownstreamProjects
List<MavenProject> getDownstreamProjects(MavenProject project, boolean transitive);
From source file:com.soebes.maven.extensions.incremental.IncrementalModuleBuilderImpl.java
License:Apache License
IncrementalModuleBuilderImpl(List<MavenProject> selectedProjects, LifecycleModuleBuilder lifecycleModuleBuilder, MavenSession session, ReactorContext reactorContext, List<TaskSegment> taskSegments) { this.lifecycleModuleBuilder = Objects.requireNonNull(lifecycleModuleBuilder, "lifecycleModuleBuilder is not allowed to be null."); this.mavenSession = Objects.requireNonNull(session, "session is not allowed to be null."); this.taskSegments = Objects.requireNonNull(taskSegments, "taskSegements is not allowed to be null"); this.reactorContext = Objects.requireNonNull(reactorContext, "reactorContext is not allowed to be null."); ProjectDependencyGraph projectDependencyGraph = session.getProjectDependencyGraph(); List<MavenProject> intermediateResult = new LinkedList<>(); for (MavenProject selectedProject : selectedProjects) { intermediateResult.add(selectedProject); // Up or downstream ? (-amd) intermediateResult.addAll(projectDependencyGraph.getDownstreamProjects(selectedProject, true)); // TODO: Need to think about this? -am ? // intermediateResult.addAll(projectDependencyGraph.getUpstreamProjects(selectedProject, // true)); }/*www .ja va 2 s . c om*/ List<MavenProject> result = new LinkedList<>(); for (MavenProject project : intermediateResult) { if (!result.contains(project)) { result.add(project); } } this.projects = result; }
From source file:org.glassfish.jersey.tools.plugins.GenerateJerseyModuleListMojo.java
License:Open Source License
@Override public void execute() throws MojoExecutionException { try {/*from w w w . ja va 2 s . co m*/ configuration = prepareParameters(); } catch (IOException e) { throw new MojoExecutionException("Plugin initialization failed. Problem reading input files.", e); } ProjectDependencyGraph graph = mavenSession.getProjectDependencyGraph(); List<MavenProject> projects = graph.getDownstreamProjects(mavenProject, true); // categorize modules based on predefined categories Map<String, List<MavenProject>> categorizedProjects = categorizeModules(projects); // list of already "used" categories (maintained in order to identified unmatched modules later) List<String> allGroups = new ArrayList<String>(); // The entire module list table content - will replace the placeholder in the template StringBuilder content = new StringBuilder(); // iterate over known categories for (PredefinedCategories category : PredefinedCategories.values()) { allGroups.add(category.getGroupId()); // ignore tests, but still keep them among the used categories (so that they do not appear in the unmatched list) if (category.getGroupId().contains("tests")) { continue; } List<MavenProject> projectsInCategory = categorizedProjects.get(category.getGroupId()); content.append(processCategory(category, projectsInCategory)); } // get the list of unmatched modules List<MavenProject> unmatched = new LinkedList<MavenProject>(); for (String groupId : categorizedProjects.keySet()) { if (!allGroups.contains(groupId)) { unmatched.addAll(categorizedProjects.get(groupId)); } } if (unmatched.size() > 0) { log.warn("There are unmatched modules (" + unmatched.size() + ")."); if (!outputUnmatched) { log.warn("You can configure the plugin to output unmatched modules by adding " + "<outputUnmatched>true</outputUnmatched> in the configuration."); } } if (outputUnmatched) { content.append(processUnmatched(unmatched)); } PrintWriter writer = null; try { writer = new PrintWriter(outputFileName); writer.println(configuration.getSectionTemplate().replace(CONTENT_PLACEHOLDER, content.toString())); } catch (FileNotFoundException e) { throw new MojoExecutionException("File not found exception"); } finally { if (writer != null) { writer.close(); } } log.info("Output written to: " + outputFileName); }