private boolean restoreProject()

in src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java [170:237]


    private boolean restoreProject(
            CacheResult cacheResult,
            List<MojoExecution> mojoExecutions,
            MojoExecutionRunner mojoExecutionRunner,
            CacheConfig cacheConfig)
            throws LifecycleExecutionException, MojoExecutionException {
        mojoExecutionScope.enter();
        try {
            final Build build = cacheResult.getBuildInfo();
            final MavenProject project = cacheResult.getContext().getProject();
            final MavenSession session = cacheResult.getContext().getSession();
            mojoExecutionScope.seed(MavenProject.class, project);
            mojoExecutionScope.seed(MavenSession.class, session);
            final List<MojoExecution> cachedSegment =
                    lifecyclePhasesHelper.getCachedSegment(project, mojoExecutions, build);

            boolean restored = cacheController.restoreProjectArtifacts(cacheResult);
            if (!restored) {
                LOGGER.info("Cannot restore project artifacts, continuing with non cached build");
                return false;
            }

            for (MojoExecution cacheCandidate : cachedSegment) {
                if (cacheController.isForcedExecution(project, cacheCandidate)) {
                    LOGGER.info(
                            "Mojo execution is forced by project property: {}",
                            cacheCandidate.getMojoDescriptor().getFullGoalName());
                    mojoExecutionScope.seed(MojoExecution.class, cacheCandidate);
                    // need maven 4 as minumum
                    // mojoExecutionScope.seed(
                    //        org.apache.maven.api.plugin.Log.class,
                    //        new DefaultLog(LoggerFactory.getLogger(
                    //                cacheCandidate.getMojoDescriptor().getFullGoalName())));
                    // mojoExecutionScope.seed(Project.class, ((DefaultSession)
                    // session.getSession()).getProject(project));
                    // mojoExecutionScope.seed(
                    //        org.apache.maven.api.MojoExecution.class, new DefaultMojoExecution(cacheCandidate));
                    mojoExecutionRunner.run(cacheCandidate);
                } else {
                    restored = verifyCacheConsistency(
                            cacheCandidate, build, project, session, mojoExecutionRunner, cacheConfig);
                    if (!restored) {
                        break;
                    }
                }
            }

            if (!restored) {
                // cleanup partial state
                project.getArtifact().setFile(null);
                project.getArtifact().setResolved(false);
                mojoListener.remove(project);
                // build as usual
                for (MojoExecution mojoExecution : cachedSegment) {
                    mojoExecutionRunner.run(mojoExecution);
                }
            }

            List<MojoExecution> postCachedSegment =
                    lifecyclePhasesHelper.getPostCachedSegment(project, mojoExecutions, build);
            for (MojoExecution mojoExecution : postCachedSegment) {
                mojoExecutionRunner.run(mojoExecution);
            }
            return restored;
        } finally {
            mojoExecutionScope.exit();
        }
    }