Java Code Examples for org.apache.maven.project.MavenProject#getCollectedProjects()

The following examples show how to use org.apache.maven.project.MavenProject#getCollectedProjects() . 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: AggregatingGraphFactory.java    From depgraph-maven-plugin with Apache License 2.0 6 votes vote down vote up
private void buildModuleTree(MavenProject parentProject, GraphBuilder<DependencyNode> graphBuilder) {
  Collection<MavenProject> collectedProjects = parentProject.getCollectedProjects();
  for (MavenProject collectedProject : collectedProjects) {
    MavenProject child = collectedProject;
    MavenProject parent = collectedProject.getParent();

    while (parent != null) {
      DependencyNode parentNode = filterProject(parent);
      DependencyNode childNode = filterProject(child);

      graphBuilder.addEdge(parentNode, childNode);

      // Stop if we reached the original parent project!
      if (parent.equals(parentProject)) {
        break;
      }

      child = parent;
      parent = parent.getParent();
    }
  }
}
 
Example 2
Source File: MvnPluginReport.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the set of {@link Application}s to be considered in the result report.
 * 
 * If the given {@link MavenProject} has the packaging type 'POM', applications
 * corresponding to all its sub-modules will be added to this set.
 * 
 * Depending on the configuration option {@link CoreConfiguration#REP_OVERRIDE_VER},
 * the application version is either taken from the POM or from configuration
 * setting {@link CoreConfiguration#APP_CTX_VERSI}.
 * 
 * @param _prj
 * @param _ids
 */
private void collectApplicationModules(MavenProject _prj, Set<Application> _ids) {

	// The version as specified in the POM of the given project		
	final String pom_version = _prj.getVersion();
	
	// The version specified with configuration option {@link CoreConfiguration#APP_CTX_VERSI}
	final String app_ctx_version = this.goal.getGoalContext().getApplication().getVersion();
	
	// The application module to be added
	final Application app = new Application(_prj.getGroupId(), _prj.getArtifactId(), pom_version);
	
	// Override version found in the respective pom.xml with the version of the application context
	// This becomes necessary if module scan results are NOT uploaded with the version found in the POM,
	// but with one specified in other ways, e.g., per -Dvulas.core.appContext.version
	if(this.vulasConfiguration.getConfiguration().getBoolean(CoreConfiguration.REP_OVERRIDE_VER, false) && !pom_version.equals(app_ctx_version)) {
		app.setVersion(app_ctx_version);
		this.getLog().warn("Report will include application version " + app + " rather than version [" + pom_version + "] specified in its POM");
	}
	
	_ids.add(app);
	if(_prj.getPackaging().equalsIgnoreCase("pom")) {
		for(MavenProject module: _prj.getCollectedProjects()) {
			this.collectApplicationModules(module, _ids);
		}
	}
}
 
Example 3
Source File: FindDeadCodeOnlyMojo.java    From deadcode4j with Apache License 2.0 5 votes vote down vote up
private Collection<MavenProject> getProjectsToAnalyze() {
    if (this.modulesToSkip.isEmpty()) {
        return this.reactorProjects;
    }
    ArrayList<String> unknownModules = newArrayList(this.modulesToSkip);
    int baseDirPathIndex = project.getBasedir().getAbsolutePath().length() + 1;
    ArrayList<MavenProject> mavenProjects = newArrayList(this.reactorProjects);
    for (MavenProject mavenProject : this.reactorProjects) {
        if (project.equals(mavenProject)) {
            continue;
        }
        String projectPath = mavenProject.getBasedir().getAbsolutePath();
        String modulePath = projectPath.substring(baseDirPathIndex);
        if (this.modulesToSkip.contains(modulePath)) {
            unknownModules.remove(modulePath);
            getLog().info("Project [" + getKeyFor(mavenProject) + "] will be skipped.");
            mavenProjects.remove(mavenProject);
            List<MavenProject> collectedProjects = mavenProject.getCollectedProjects();
            if (!collectedProjects.isEmpty()) {
                getLog().info("  Aggregated Projects " + transform(collectedProjects, toKey()) + " will be skipped.");
                mavenProjects.removeAll(collectedProjects);
            }
        }
    }
    for (String unknownModule : unknownModules) {
        getLog().warn("Module [" + unknownModule + "] should be skipped, but does not exist. You should remove the configuration entry.");
    }

    return mavenProjects;
}