private void cloneProjects()

in src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java [1113:1204]


    private void cloneProjects(Collection<String> projectPaths) throws MojoExecutionException {
        if (!cloneProjectsTo.mkdirs() && cloneClean) {
            try {
                FileUtils.cleanDirectory(cloneProjectsTo);
            } catch (IOException e) {
                throw new MojoExecutionException(
                        "Could not clean the cloneProjectsTo directory. Reason: " + e.getMessage(), e);
            }
        }

        // determine project directories to clone
        Collection<String> dirs = new LinkedHashSet<>();
        for (String projectPath : projectPaths) {
            if (!new File(projectsDirectory, projectPath).isDirectory()) {
                projectPath = getParentPath(projectPath);
            }
            dirs.add(projectPath);
        }

        boolean filter;

        // clone project directories
        try {
            filter = !cloneProjectsTo.getCanonicalFile().equals(projectsDirectory.getCanonicalFile());

            List<String> clonedSubpaths = new ArrayList<>();

            for (String subpath : dirs) {
                // skip this project if its parent directory is also scheduled for cloning
                if (!".".equals(subpath) && dirs.contains(getParentPath(subpath))) {
                    continue;
                }

                // avoid copying subdirs that are already cloned.
                if (!alreadyCloned(subpath, clonedSubpaths)) {
                    // avoid creating new files that point to dir/.
                    if (".".equals(subpath)) {
                        String cloneSubdir = relativizePath(cloneProjectsTo, projectsDirectory.getCanonicalPath());

                        // avoid infinite recursion if the cloneTo path is a subdirectory.
                        if (cloneSubdir != null) {
                            File temp = Files.createTempDirectory("pre-invocation-clone.")
                                    .toFile();

                            copyDirectoryStructure(projectsDirectory, temp);

                            FileUtils.deleteDirectory(new File(temp, cloneSubdir));

                            copyDirectoryStructure(temp, cloneProjectsTo);
                        } else {
                            copyDirectoryStructure(projectsDirectory, cloneProjectsTo);
                        }
                    } else {
                        File srcDir = new File(projectsDirectory, subpath);
                        File dstDir = new File(cloneProjectsTo, subpath);
                        copyDirectoryStructure(srcDir, dstDir);
                    }

                    clonedSubpaths.add(subpath);
                }
            }
        } catch (IOException e) {
            throw new MojoExecutionException(
                    "Failed to clone projects from: " + projectsDirectory + " to: " + cloneProjectsTo + ". Reason: "
                            + e.getMessage(),
                    e);
        }

        // filter cloned POMs
        if (filter) {
            for (String projectPath : projectPaths) {
                File pomFile = new File(cloneProjectsTo, projectPath);
                if (pomFile.isFile()) {
                    buildInterpolatedFile(pomFile, pomFile);
                }

                // MINVOKER-186
                // The following is a temporary solution to support Maven 3.3.1 (.mvn/extensions.xml) filtering
                // Will be replaced by MINVOKER-117 with general filtering mechanism
                File baseDir = pomFile.getParentFile();
                File mvnDir = new File(baseDir, ".mvn");
                if (mvnDir.isDirectory()) {
                    File extensionsFile = new File(mvnDir, "extensions.xml");
                    if (extensionsFile.isFile()) {
                        buildInterpolatedFile(extensionsFile, extensionsFile);
                    }
                }
                // END MINVOKER-186
            }
            filteredPomPrefix = null;
        }
    }