Example usage for org.apache.maven.project MavenProject getCollectedProjects

List of usage examples for org.apache.maven.project MavenProject getCollectedProjects

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getCollectedProjects.

Prototype

public List<MavenProject> getCollectedProjects() 

Source Link

Usage

From source file:org.eluder.coveralls.maven.plugin.util.MavenProjectCollector.java

License:Open Source License

private void collect(final MavenProject project, final List<MavenProject> projects) {
    projects.add(project);/*from www  .  ja  v  a  2  s.c o m*/
    for (MavenProject child : project.getCollectedProjects()) {
        collect(child, projects);
    }
}

From source file:org.ensime.maven.plugins.ensime.EnsimeConfigGenerator.java

License:Apache License

public EnsimeConfigGenerator(final MavenProject project, final RepositorySystem repoSystem,
        final RepositorySystemSession session, final Properties properties, final String ensimeServerVersion,
        final String ensimeScalaVersion, final Log log) {

    this.project = project;
    this.repoSystem = repoSystem;
    this.session = session;
    this.properties = properties;
    this.ENSIME_SERVER_VERSION = ensimeServerVersion;
    this.ENSIME_SCALA_VERSION = ensimeScalaVersion;
    this.log = log;

    List<MavenProject> temp = project.getCollectedProjects();
    temp.add(project);/*from   w w  w  .  ja va 2  s.c  om*/
    modules = temp.stream().filter(p -> !p.getPackaging().equals("pom")).collect(toList());
}

From source file:org.hudsonci.maven.eventspy_30.handler.ProfileLogger.java

License:Open Source License

@SuppressWarnings("unused")
public static void log(final ExecutionEvent event) {
    if (disabled)
        return;//  ww w. j a  va 2 s  .c om

    for (MavenProject project : event.getSession().getProjects()) {
        log.debug("*** Examining profiles for {}.", project.getName());
        logProfileList(project.getActiveProfiles(), "active");
        logProfileList(project.getModel().getProfiles(), "model");

        //logProfiles( event.getSession().getProjectBuildingRequest().getProfiles(), "ProjectBuildingRequest" );
        logProfileList(project.getProjectBuildingRequest().getProfiles(), "ProjectBuildingRequest");

        log.debug("InjectedProfileIds");
        for (Entry<String, List<String>> entry : project.getInjectedProfileIds().entrySet()) {
            log.debug("  from {} are {}", entry.getKey(), entry.getValue());
        }

        Settings settings = event.getSession().getSettings();
        logSettingsProfileList(settings.getProfiles(), "session-settings");

        log.debug("Collected projects: {}", project.getCollectedProjects());
        log.debug("Project references: {}", project.getProjectReferences());
    }
}

From source file:org.jasig.maven.notice.AbstractNoticeMojo.java

License:Apache License

/**
 * Loads the dependency tree for the project via {@link #loadDependencyTree(MavenProject)} and then uses
 * the {@link DependencyNodeVisitor} to load the license data. If {@link #aggregating} is enabled the method
 * recurses on each child module.//  ww w.j ava  2s  . c  om
 */
@SuppressWarnings("unchecked")
protected void parseProject(MavenProject project, DependencyNodeVisitor visitor)
        throws MojoExecutionException, MojoFailureException {
    final Log logger = this.getLog();
    logger.info("Parsing Dependencies for: " + project.getName());

    //Load and parse immediate dependencies
    final DependencyNode tree = this.loadDependencyTree(project);
    tree.accept(visitor);

    //If not including child deps don't recurse on modules
    if (!this.includeChildDependencies) {
        return;
    }

    //No child modules, return
    final List<MavenProject> collectedProjects = project.getCollectedProjects();
    if (collectedProjects == null) {
        return;
    }

    //Find all sub-modules for the project
    for (final MavenProject moduleProject : collectedProjects) {
        if (this.isExcluded(moduleProject, project.getArtifactId())) {
            continue;
        }

        this.parseProject(moduleProject, visitor);
    }
}

From source file:org.jfrog.jade.plugins.idea.IdeaProjectMojo.java

License:Apache License

public void rewriteProject() throws MojoExecutionException {
    MavenProject executedProject = getExecutedProject();
    String ideProjectName = getIdeProjectName();
    File projectFile = new File(executedProject.getBasedir(), ideProjectName + ".ipr");

    try {//  w w w.  j  a v a  2 s . c o m
        Document document = readXmlDocument(projectFile, "project.xml");

        Element module = document.getRootElement();

        // Set the jdk name if set
        if (getJdkName() != null) {
            setJdkName(module, getJdkName());
        } else {
            String javaVersion = System.getProperty("java.version");
            String defaultJdkName;

            if (getIdeaVersion().startsWith("4")) {
                defaultJdkName = "java version &quot;" + javaVersion + "&quot;";
            } else {
                defaultJdkName = javaVersion.substring(0, 3);
            }
            getLog().info("jdkName is not set, using [java version" + javaVersion + "] as default.");
            setJdkName(module, defaultJdkName);
        }

        setWildcardResourcePatterns(module, getWildcardResourcePatterns());

        Element component = findComponent(module, "ProjectModuleManager");
        Element modules = findElement(component, "modules");

        removeOldElements(modules, "module");

        List<MavenProject> collectedProjects = executedProject.getCollectedProjects();
        if (collectedProjects != null && !collectedProjects.isEmpty()) {
            Element m = createElement(modules, "module");
            String projectPath = new File(executedProject.getBasedir(),
                    getNameProvider().getProjectName(executedProject) + ".iml").getAbsolutePath();
            m.addAttribute("filepath",
                    "$PROJECT_DIR$/" + toRelative(executedProject.getBasedir(), projectPath));

            // For groupId group name generation, if no name provider provided
            // Need to find the groupId common denominator between all projects
            int commonUntilIdx = 0;
            if (groupIdBaseGrouping && !getNameProvider().hasGroupDefinitions()) {
                String rootGroupId = null;
                for (MavenProject project : collectedProjects) {
                    String groupId = project.getGroupId();
                    if (rootGroupId == null) {
                        rootGroupId = groupId;
                    } else {
                        int minLength = Math.min(rootGroupId.length(), groupId.length());
                        int idx = 0;
                        for (; idx < minLength; idx++) {
                            if (rootGroupId.charAt(idx) != groupId.charAt(idx))
                                break;
                        }
                        if (idx == 0) {
                            rootGroupId = "";
                            break;
                        }
                        rootGroupId = rootGroupId.substring(0, idx);
                    }
                }
                if (rootGroupId != null) {
                    commonUntilIdx = rootGroupId.length();
                }
            }

            for (MavenProject p : collectedProjects) {
                m = createElement(modules, "module");
                String modulePath = new File(p.getBasedir(), getNameProvider().getProjectName(p) + ".iml")
                        .getAbsolutePath();
                m.addAttribute("filepath",
                        "$PROJECT_DIR$/" + toRelative(executedProject.getBasedir(), modulePath));
                if (groupIdBaseGrouping) {
                    String groupId = p.getGroupId();
                    if (groupId != null) {
                        String groupName = getNameProvider().getGroupName(groupId);
                        if (groupName == null) {
                            // Find the most parent of all
                            groupName = groupId.substring(commonUntilIdx);
                            if (groupName.length() > 0 && groupName.charAt(0) == '.') {
                                groupName = groupName.substring(1);
                            }
                        }
                        if (groupName.length() > 0) {
                            groupName = groupName.replace('.', '/');
                            m.addAttribute("group", groupName);
                        }
                    }
                }
            }

            // Add externalModules
            if (externalModules != null) {
                for (String externalModule : externalModules) {
                    m = createElement(modules, "module");
                    m.addAttribute("filepath", externalModule);
                    m.addAttribute("group", "External");
                }
            }
        } else {
            Element m = createElement(modules, "module");
            String modulePath = new File(executedProject.getBasedir(),
                    getNameProvider().getProjectName(executedProject) + ".iml").getAbsolutePath();
            m.addAttribute("filepath", "$PROJECT_DIR$/" + toRelative(executedProject.getBasedir(), modulePath));
        }

        // add any PathMacros we've come across
        if (getMacros() != null && module.elements("UsedPathMacros").size() > 0) {
            Element usedPathMacros = (Element) module.elements("UsedPathMacros").get(0);
            removeOldElements(usedPathMacros, "macro");
            for (Iterator iterator = getMacros().iterator(); iterator.hasNext();) {
                String macro = (String) iterator.next();
                Element macroElement = createElement(usedPathMacros, "macro");
                macroElement.addAttribute("name", macro);
            }
        }

        writeXmlDocument(projectFile, document);
    } catch (DocumentException e) {
        throw new MojoExecutionException("Error parsing existing IPR file: " + projectFile.getAbsolutePath(),
                e);
    } catch (IOException e) {
        throw new MojoExecutionException("Error parsing existing IPR file: " + projectFile.getAbsolutePath(),
                e);
    }
}

From source file:org.m1theo.apt.repo.utils.Utils.java

License:Open Source License

/**
 * Collects all artifacts of the given type.
 * /*from w  ww  .j  a v a 2  s.  c o m*/
 * @param project The maven project which should be used.
 * @param type The file type which should be collected.
 * @return A collection of all artifacts with the given type.
 */
@SuppressWarnings("unchecked")
public static Collection<Artifact> getAllArtifacts4Type(MavenProject project, String type, Boolean aggregate) {
    final Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
    List<MavenProject> modules = new ArrayList<MavenProject>();
    modules.add(project);
    List<MavenProject> collectedProjects = project.getCollectedProjects();
    if (collectedProjects != null) {
        modules.addAll(collectedProjects);
    }
    for (MavenProject module : modules) {
        addDebArtifact(module.getArtifact(), artifacts, type);
        for (Object artifact : module.getArtifacts()) {
            if (artifact instanceof Artifact) {
                addDebArtifact((Artifact) artifact, artifacts, type);
            }
        }
        for (Object artifact : module.getAttachedArtifacts()) {
            if (artifact instanceof Artifact) {
                addDebArtifact((Artifact) artifact, artifacts, type);
            }
        }
    }
    if (project.hasParent() && aggregate) {
        artifacts.addAll(getAllArtifacts4Type(project.getParent(), type, aggregate));
    }
    return artifacts;
}

From source file:org_scala_tools_maven.ScalaDocMojo.java

License:Apache License

@SuppressWarnings("unchecked")
protected void tryAggregateUpper(MavenProject prj) throws Exception {
    if (prj != null && prj.hasParent() && canAggregate()) {
        MavenProject parent = prj.getParent();
        List<MavenProject> modules = parent.getCollectedProjects();
        if ((modules.size() > 1) && prj.equals(modules.get(modules.size() - 1))) {
            aggregate(parent);//from  w  w  w  .j  av a2  s. c  om
        }
    }
}

From source file:org_scala_tools_maven.ScalaDocMojo.java

License:Apache License

@SuppressWarnings("unchecked")
protected void aggregate(MavenProject parent) throws Exception {
    List<MavenProject> modules = parent.getCollectedProjects();
    File dest = new File(parent.getReporting().getOutputDirectory() + "/" + outputDirectory);
    getLog().info("start aggregation into " + dest);
    StringBuilder mpath = new StringBuilder();
    for (MavenProject module : modules) {
        if ("pom".equals(module.getPackaging().toLowerCase())) {
            continue;
        }//from   ww w  .java 2  s.c o  m
        if (aggregateDirectOnly && module.getParent() != parent) {
            continue;
        }
        File subScaladocPath = new File(module.getReporting().getOutputDirectory() + "/" + outputDirectory)
                .getAbsoluteFile();
        //System.out.println(" -> " + project.getModulePathAdjustment(module)  +" // " + subScaladocPath + " // " + module.getBasedir() );
        if (subScaladocPath.exists()) {
            mpath.append(subScaladocPath).append(File.pathSeparatorChar);
        }
    }
    if (mpath.length() != 0) {
        getLog().info("aggregate vscaladoc from : " + mpath);
        JavaMainCaller jcmd = getScalaCommand();
        jcmd.addOption("-d", dest.getAbsolutePath());
        jcmd.addOption("-aggregate", mpath.toString());
        jcmd.run(displayCmd);
    } else {
        getLog().warn("no vscaladoc to aggregate");
    }
    tryAggregateUpper(parent);
}