From commits-return-90031-archive-asf-public=cust-asf.ponee.io@maven.apache.org Sat Jun 20 09:33:20 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id EF46A180669 for ; Sat, 20 Jun 2020 11:33:19 +0200 (CEST) Received: (qmail 68116 invoked by uid 500); 20 Jun 2020 09:33:16 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 67518 invoked by uid 99); 20 Jun 2020 09:33:14 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 20 Jun 2020 09:33:14 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 6AD2B890C0; Sat, 20 Jun 2020 09:33:14 +0000 (UTC) Date: Sat, 20 Jun 2020 09:33:23 +0000 To: "commits@maven.apache.org" Subject: [maven] 10/31: Refactored to call the resumption manager from the DefaultMaven instead of the CLI. As DefaultMaven has the right info to determine the execution root. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: rfscholte@apache.org In-Reply-To: <159264559346.14062.15479645306461176972@gitbox.apache.org> References: <159264559346.14062.15479645306461176972@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: maven X-Git-Refname: refs/heads/MNG-5760 X-Git-Reftype: branch X-Git-Rev: df606590141756018ebca1e4000207e986d705ce X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20200620093314.6AD2B890C0@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. rfscholte pushed a commit to branch MNG-5760 in repository https://gitbox.apache.org/repos/asf/maven.git commit df606590141756018ebca1e4000207e986d705ce Author: Martin Kanters AuthorDate: Sat May 23 08:27:50 2020 +0200 Refactored to call the resumption manager from the DefaultMaven instead of the CLI. As DefaultMaven has the right info to determine the execution root. --- .../main/java/org/apache/maven/DefaultMaven.java | 30 +++++++++++++++++++++- .../maven/execution/BuildResumptionManager.java | 8 +++--- .../lifecycle/LifecycleExecutionException.java | 12 +++++++++ .../main/java/org/apache/maven/cli/MavenCli.java | 9 ++++--- 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index fc26290..026f729 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -30,12 +30,14 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; import org.apache.maven.artifact.ArtifactUtils; +import org.apache.maven.execution.BuildResumptionManager; import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.execution.ExecutionEvent; import org.apache.maven.execution.MavenExecutionRequest; @@ -44,6 +46,7 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.ProjectDependencyGraph; import org.apache.maven.graph.GraphBuilder; import org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory; +import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.internal.ExecutionEventCatapult; import org.apache.maven.lifecycle.internal.LifecycleStarter; import org.apache.maven.model.Prerequisites; @@ -99,6 +102,9 @@ public class DefaultMaven @Named( GraphBuilder.HINT ) private GraphBuilder graphBuilder; + @Inject + private BuildResumptionManager buildResumptionManager; + @Override public MavenExecutionResult execute( MavenExecutionRequest request ) { @@ -312,7 +318,9 @@ public class DefaultMaven if ( session.getResult().hasExceptions() ) { - return addExceptionToResult( result, session.getResult().getExceptions().get( 0 ) ); + addExceptionToResult( result, session.getResult().getExceptions().get( 0 ) ); + saveResumptionDataWhenApplicable( result, session ); + return result; } } finally @@ -349,6 +357,26 @@ public class DefaultMaven } } + private void saveResumptionDataWhenApplicable( MavenExecutionResult result, MavenSession session ) + { + List lifecycleExecutionExceptions = result.getExceptions().stream() + .filter( LifecycleExecutionException.class::isInstance ) + .map( LifecycleExecutionException.class::cast ) + .collect( Collectors.toList() ); + + if ( !lifecycleExecutionExceptions.isEmpty() ) + { + session.getAllProjects().stream() + .filter( MavenProject::isExecutionRoot ) + .findFirst() + .ifPresent( rootProject -> + { + boolean persisted = buildResumptionManager.persistResumptionData( result, rootProject ); + lifecycleExecutionExceptions.forEach( e -> e.setBuildResumptionDataSaved( persisted ) ); + } ); + } + } + public RepositorySystemSession newRepositorySession( MavenExecutionRequest request ) { return repositorySessionFactory.newRepositorySession( request ); diff --git a/maven-core/src/main/java/org/apache/maven/execution/BuildResumptionManager.java b/maven-core/src/main/java/org/apache/maven/execution/BuildResumptionManager.java index 0fb22e4..2e7e775 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/BuildResumptionManager.java +++ b/maven-core/src/main/java/org/apache/maven/execution/BuildResumptionManager.java @@ -61,7 +61,7 @@ public class BuildResumptionManager @Inject private Logger logger; - public boolean persistResumptionData( MavenExecutionResult result ) + public boolean persistResumptionData( MavenExecutionResult result, MavenProject rootProject ) { Properties properties = determineResumptionProperties( result ); @@ -71,7 +71,7 @@ public class BuildResumptionManager return false; } - return writeResumptionFile( result, properties ); + return writeResumptionFile( rootProject, properties ); } public void applyResumptionData( MavenExecutionRequest request, MavenProject rootProject ) @@ -206,9 +206,9 @@ public class BuildResumptionManager .noneMatch( projectsGAs::contains ); } - private boolean writeResumptionFile( MavenExecutionResult result, Properties properties ) + private boolean writeResumptionFile( MavenProject rootProject, Properties properties ) { - Path resumeProperties = Paths.get( result.getProject().getBuild().getDirectory(), RESUME_PROPERTIES_FILENAME ); + Path resumeProperties = Paths.get( rootProject.getBuild().getDirectory(), RESUME_PROPERTIES_FILENAME ); try { Files.createDirectories( resumeProperties.getParent() ); diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java index 0831a4f..af9821a 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java @@ -33,6 +33,8 @@ public class LifecycleExecutionException { private MavenProject project; + private boolean buildResumptionDataSaved = false; + public LifecycleExecutionException( String message ) { super( message ); @@ -76,6 +78,16 @@ public class LifecycleExecutionException return project; } + public boolean isBuildResumptionDataSaved() + { + return buildResumptionDataSaved; + } + + public void setBuildResumptionDataSaved( boolean isBuildResumptionDataSaved ) + { + this.buildResumptionDataSaved = isBuildResumptionDataSaved; + } + private static String createMessage( MojoExecution execution, MavenProject project, Throwable cause ) { MessageBuilder buffer = buffer( 256 ); diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index 113af25..657dfe0 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -992,6 +992,7 @@ public class MavenCli Map references = new LinkedHashMap<>(); MavenProject project = null; + boolean isResumptionDataSaved = false; for ( Throwable exception : result.getExceptions() ) { @@ -1001,7 +1002,9 @@ public class MavenCli if ( project == null && exception instanceof LifecycleExecutionException ) { - project = ( (LifecycleExecutionException) exception ).getProject(); + LifecycleExecutionException lifecycleExecutionException = (LifecycleExecutionException) exception; + project = lifecycleExecutionException.getProject(); + isResumptionDataSaved = lifecycleExecutionException.isBuildResumptionDataSaved(); } } @@ -1030,10 +1033,8 @@ public class MavenCli } } - boolean resumeFileCreated = buildResumptionManager.persistResumptionData( result ); - List sortedProjects = result.getTopologicallySortedProjects(); - if ( resumeFileCreated ) + if ( isResumptionDataSaved ) { logBuildResumeHint( "mvn -r " ); }