private void collectProjects()

in src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java [991:1045]


    private void collectProjects(
            File projectsDir, String projectPath, Collection<String> projectPaths, boolean included)
            throws MojoExecutionException {
        projectPath = projectPath.replace('\\', '/');
        File pomFile = new File(projectsDir, projectPath);
        if (pomFile.isDirectory()) {
            pomFile = new File(pomFile, "pom.xml");
            if (!pomFile.exists()) {
                if (included) {
                    projectPaths.add(projectPath);
                }
                return;
            }
            if (!projectPath.endsWith("/")) {
                projectPath += '/';
            }
            projectPath += "pom.xml";
        } else if (!pomFile.isFile()) {
            return;
        }
        if (!projectPaths.add(projectPath)) {
            return;
        }
        getLog().debug("Collecting parent/child projects of " + projectPath);

        Model model = PomUtils.loadPom(pomFile);

        try {
            String projectsRoot = projectsDir.getCanonicalPath();
            String projectDir = pomFile.getParent();

            String parentPath = "../pom.xml";
            if (model.getParent() != null
                    && StringUtils.isNotEmpty(model.getParent().getRelativePath())) {
                parentPath = model.getParent().getRelativePath();
            }
            String parent = relativizePath(new File(projectDir, parentPath), projectsRoot);
            if (parent != null) {
                collectProjects(projectsDir, parent, projectPaths, false);
            }

            Collection<String> modulePaths = new LinkedHashSet<>(model.getModules());

            model.getProfiles().forEach(profile -> modulePaths.addAll(profile.getModules()));

            for (String modulePath : modulePaths) {
                String module = relativizePath(new File(projectDir, modulePath), projectsRoot);
                if (module != null) {
                    collectProjects(projectsDir, module, projectPaths, false);
                }
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Failed to analyze POM: " + pomFile, e);
        }
    }