Skip to content

Commit 9bf19f4

Browse files
committed
[MBUILDCACHE-67] Fix restoration error not starting the normal project build + every restoration was a lazy restore, even if configured otherwise.
1 parent f9920a1 commit 9bf19f4

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ public void execute(
129129
boolean restored = result.isSuccess(); // if partially restored need to save increment
130130
if (restorable) {
131131
restored &= restoreProject(result, mojoExecutions, mojoExecutionRunner, cacheConfig);
132-
} else {
132+
}
133+
if (!restored) {
133134
for (MojoExecution mojoExecution : mojoExecutions) {
134135
if (source == Source.CLI
135136
|| mojoExecution.getLifecyclePhase() == null

src/main/java/org/apache/maven/buildcache/CacheControllerImpl.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,15 @@
4444
import java.util.Set;
4545
import java.util.TreeSet;
4646
import java.util.UUID;
47-
import java.util.concurrent.ConcurrentHashMap;
48-
import java.util.concurrent.ConcurrentMap;
49-
import java.util.concurrent.Future;
50-
import java.util.concurrent.FutureTask;
47+
import java.util.concurrent.*;
5148
import java.util.regex.Pattern;
5249

5350
import org.apache.commons.io.FileUtils;
5451
import org.apache.commons.io.FilenameUtils;
5552
import org.apache.commons.lang3.StringUtils;
5653
import org.apache.commons.lang3.mutable.MutableBoolean;
5754
import org.apache.maven.SessionScoped;
55+
import org.apache.maven.artifact.InvalidArtifactRTException;
5856
import org.apache.maven.artifact.handler.ArtifactHandler;
5957
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
6058
import org.apache.maven.buildcache.artifact.RestoredArtifact;
@@ -401,6 +399,25 @@ private Future<File> createDownloadTask(
401399
});
402400
if (!cacheConfig.isLazyRestore()) {
403401
downloadTask.run();
402+
try {
403+
downloadTask.get();
404+
} catch (InterruptedException e) {
405+
throw new InvalidArtifactRTException(
406+
artifact.getGroupId(),
407+
artifact.getArtifactId(),
408+
artifact.getVersion(),
409+
artifact.getType(),
410+
RestoredArtifact.MSG_INTERRUPTED_WHILE_RETRIEVING_ARTIFACT_FILE,
411+
e);
412+
} catch (ExecutionException e) {
413+
throw new InvalidArtifactRTException(
414+
artifact.getGroupId(),
415+
artifact.getArtifactId(),
416+
artifact.getVersion(),
417+
artifact.getType(),
418+
RestoredArtifact.MSG_ERROR_RETRIEVING_ARTIFACT_FILE,
419+
e.getCause());
420+
}
404421
}
405422
return downloadTask;
406423
}

src/main/java/org/apache/maven/buildcache/artifact/RestoredArtifact.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
public class RestoredArtifact extends DefaultArtifact {
4141

4242
private static final Logger LOGGER = LoggerFactory.getLogger(RestoredArtifact.class);
43+
public static final String MSG_INTERRUPTED_WHILE_RETRIEVING_ARTIFACT_FILE =
44+
"Interrupted while retrieving artifact file";
45+
public static final String MSG_ERROR_RETRIEVING_ARTIFACT_FILE = "Error retrieving artifact file";
4346

4447
private volatile Future<File> fileFuture;
4548

@@ -75,7 +78,7 @@ public File getFile() {
7578
getArtifactId(),
7679
getVersion(),
7780
getType(),
78-
"Error retrieving artifact file",
81+
MSG_ERROR_RETRIEVING_ARTIFACT_FILE,
7982
e);
8083
}
8184
} else {
@@ -94,15 +97,15 @@ public File getFile() {
9497
getArtifactId(),
9598
getVersion(),
9699
getType(),
97-
"Interrupted while retrieving artifact file",
100+
MSG_INTERRUPTED_WHILE_RETRIEVING_ARTIFACT_FILE,
98101
e);
99102
} catch (ExecutionException e) {
100103
throw new InvalidArtifactRTException(
101104
getGroupId(),
102105
getArtifactId(),
103106
getVersion(),
104107
getType(),
105-
"Error retrieving artifact file",
108+
MSG_ERROR_RETRIEVING_ARTIFACT_FILE,
106109
e.getCause());
107110
}
108111
}

0 commit comments

Comments
 (0)