You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2020/06/20 08:40:30 UTC

[maven] 23/30: When something fails while persisting resumption data, throw an exception instead of returning false.

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 cb2e26ea9d1681e5cec879071c1707bbbe337342
Author: Martin Kanters <Ma...@infosupport.com>
AuthorDate: Fri Jun 5 21:21:14 2020 +0200

    When something fails while persisting resumption data, throw an exception instead of returning false.
---
 .../main/java/org/apache/maven/DefaultMaven.java   | 12 ++++++--
 .../org/apache/maven/execution/BuildResumer.java   |  4 ++-
 .../BuildResumptionPersistenceException.java       | 34 ++++++++++++++++++++++
 .../maven/execution/DefaultBuildResumer.java       |  6 ++--
 4 files changed, 51 insertions(+), 5 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 a78bf75..1543591 100644
--- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
+++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
@@ -37,6 +37,7 @@ import javax.inject.Singleton;
 
 import org.apache.maven.artifact.ArtifactUtils;
 import org.apache.maven.execution.BuildResumer;
+import org.apache.maven.execution.BuildResumptionPersistenceException;
 import org.apache.maven.execution.DefaultMavenExecutionResult;
 import org.apache.maven.execution.ExecutionEvent;
 import org.apache.maven.execution.MavenExecutionRequest;
@@ -375,9 +376,16 @@ public class DefaultMaven
                     .findFirst()
                     .ifPresent( rootProject ->
                     {
-                        if ( buildResumer.persistResumptionData( result, rootProject ) )
+                        try
                         {
-                            result.setCanResume();
+                            if ( buildResumer.persistResumptionData( result, rootProject ) )
+                            {
+                                result.setCanResume();
+                            }
+                        }
+                        catch ( BuildResumptionPersistenceException e )
+                        {
+                            logger.warn( "Could not persist build resumption data", e );
                         }
                     } );
         }
diff --git a/maven-core/src/main/java/org/apache/maven/execution/BuildResumer.java b/maven-core/src/main/java/org/apache/maven/execution/BuildResumer.java
index be85371..fd6840e 100644
--- a/maven-core/src/main/java/org/apache/maven/execution/BuildResumer.java
+++ b/maven-core/src/main/java/org/apache/maven/execution/BuildResumer.java
@@ -37,9 +37,11 @@ public interface BuildResumer
      *
      * @param result The result of the current Maven invocation.
      * @param rootProject The root project that is being built.
+     * @throws BuildResumptionPersistenceException When an error occurs while persisting data.
      * @return Whether any data was persisted.
      */
-    boolean persistResumptionData( final MavenExecutionResult result, final MavenProject rootProject );
+    boolean persistResumptionData( final MavenExecutionResult result, final MavenProject rootProject )
+            throws BuildResumptionPersistenceException;
 
     /**
      * Uses previously stored resumption data to enrich an existing execution request.
diff --git a/maven-core/src/main/java/org/apache/maven/execution/BuildResumptionPersistenceException.java b/maven-core/src/main/java/org/apache/maven/execution/BuildResumptionPersistenceException.java
new file mode 100644
index 0000000..fb9281b
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/execution/BuildResumptionPersistenceException.java
@@ -0,0 +1,34 @@
+package org.apache.maven.execution;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.project.MavenProject;
+
+/**
+ * This exception will be thrown when something fails while persisting build resumption data.
+ * @see BuildResumer#persistResumptionData(MavenExecutionResult, MavenProject)
+ */
+public class BuildResumptionPersistenceException extends Exception
+{
+    public BuildResumptionPersistenceException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+}
diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultBuildResumer.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultBuildResumer.java
index 0e0e165..21d99de 100644
--- a/maven-core/src/main/java/org/apache/maven/execution/DefaultBuildResumer.java
+++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultBuildResumer.java
@@ -59,6 +59,7 @@ public class DefaultBuildResumer implements BuildResumer
 
     @Override
     public boolean persistResumptionData( MavenExecutionResult result, MavenProject rootProject )
+            throws BuildResumptionPersistenceException
     {
         Properties properties = determineResumptionProperties( result );
 
@@ -204,6 +205,7 @@ public class DefaultBuildResumer implements BuildResumer
     }
 
     private boolean writeResumptionFile( MavenProject rootProject, Properties properties )
+            throws BuildResumptionPersistenceException
     {
         Path resumeProperties = Paths.get( rootProject.getBuild().getDirectory(), RESUME_PROPERTIES_FILENAME );
         try
@@ -216,8 +218,8 @@ public class DefaultBuildResumer implements BuildResumer
         }
         catch ( IOException e )
         {
-            LOGGER.warn( "Could not create {} file. ", RESUME_PROPERTIES_FILENAME, e );
-            return false;
+            String message = "Could not create " + RESUME_PROPERTIES_FILENAME + " file.";
+            throw new BuildResumptionPersistenceException( message, e);
         }
 
         return true;