public static Set getProjectModules()

in src/main/java/org/apache/maven/plugins/assembly/utils/ProjectUtils.java [48:128]


    public static Set<MavenProject> getProjectModules(
            final MavenProject project,
            final List<MavenProject> reactorProjects,
            final boolean includeSubModules,
            final Logger logger)
            throws IOException {
        final Set<MavenProject> singleParentSet = Collections.singleton(project);

        final Set<MavenProject> moduleCandidates = new LinkedHashSet<>(reactorProjects);

        final Set<MavenProject> modules = new LinkedHashSet<>();

        // we temporarily add the master project to the modules set, since this
        // set is pulling double duty as a set of
        // potential module parents in the tree rooted at the master
        // project...this allows us to use the same looping
        // algorithm below to discover both direct modules of the master project
        // AND modules of those direct modules.
        modules.add(project);

        int changed;

        do {
            changed = 0;

            for (final Iterator<MavenProject> candidateIterator = moduleCandidates.iterator();
                    candidateIterator.hasNext(); ) {
                final MavenProject moduleCandidate = candidateIterator.next();

                if (moduleCandidate.getFile() == null) {
                    logger.warn("Cannot compute whether " + moduleCandidate.getId() + " is a module of: "
                            + project.getId() + "; it does not have an associated POM file on the local filesystem.");
                    continue;
                }

                Set<MavenProject> currentPotentialParents;
                if (includeSubModules) {
                    currentPotentialParents = new LinkedHashSet<>(modules);
                } else {
                    currentPotentialParents = singleParentSet;
                }

                for (final MavenProject potentialParent : currentPotentialParents) {
                    if (potentialParent.getFile() == null) {
                        logger.warn("Cannot use: " + moduleCandidate.getId()
                                + " as a potential module-parent while computing the module set for: "
                                + project.getId()
                                + "; it does not have an associated POM file on the local filesystem.");
                        continue;
                    }

                    // if this parent has an entry for the module candidate in
                    // the path adjustments map, it's a direct
                    // module of that parent.
                    if (projectContainsModule(potentialParent, moduleCandidate)) {
                        // add the candidate to the list of modules (and
                        // potential parents)
                        modules.add(moduleCandidate);

                        // remove the candidate from the candidate pool, because
                        // it's been verified.
                        candidateIterator.remove();

                        // increment the change counter, to show that we
                        // verified a new module on this pass.
                        changed++;

                        // We need to move on to the next candidate since this one was just verified
                        break;
                    }
                }
            }
        } while (changed != 0);

        // remove the master project from the modules set, now that we're done
        // using it as a set of potential module
        // parents...
        modules.remove(project);

        return modules;
    }