yeroc commented on code in PR #493:
URL: 
https://github.com/apache/maven-build-cache-extension/pull/493#discussion_r4408764794


##########
src/main/java/org/apache/maven/buildcache/CacheControllerImpl.java:
##########
@@ -486,6 +486,13 @@ public ArtifactRestorationReport 
restoreProjectArtifacts(CacheResult cacheResult
                 if (!project.hasLifecyclePhase("package")) {
                     project.addLifecyclePhase("package");
                 }
+            } else if (restoredProjectArtifact != null) {
+                // Directory artifact (target/classes from compile-only build).
+                // Point the existing project artifact at the restored 
directory so reactor dependency
+                // resolution can locate this module's compiled output. Don't 
replace the artifact:
+                // RestoredArtifact.getFile() always re-routes through 
restoreToDiskConsumer, which would
+                // break later phases (e.g. jar:jar) that update the file via 
setFile().
+                
project.getArtifact().setFile(restoredProjectArtifact.getFile());

Review Comment:
   We're deliberately leaving Maven's project artifact alone apart from its 
file, so I'd prefer not to change more of its state without a failing case that 
needs it.
   



##########
src/test/java/org/apache/maven/buildcache/its/CompileOnlyReactorRestoreTest.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+package org.apache.maven.buildcache.its;
+
+import java.util.Arrays;
+
+import org.apache.maven.buildcache.its.junit.IntegrationTest;
+import org.apache.maven.it.VerificationException;
+import org.apache.maven.it.Verifier;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Reproducer for <a 
href="https://github.com/apache/maven-build-cache-extension/issues/492";>Issue 
#492</a>:
+ * {@code clean compile} twice in a multi-module reactor fails to resolve the 
upstream module.
+ *
+ * <p>On the second run the cache extension restores the upstream module's 
compiled
+ * output but, because no jar was produced in the original cached build, 
downstream
+ * dependency resolution falls through to remote repositories with
+ * {@code Could not find artifact ...:jar:...-SNAPSHOT}.
+ */
+@IntegrationTest("src/test/projects/issue-393-compile-restore")
+class CompileOnlyReactorRestoreTest {
+
+    @Test
+    void cleanCompileTwiceResolvesUpstreamFromReactorCache(Verifier verifier) 
throws VerificationException {
+        verifier.setAutoclean(false);
+
+        verifier.setLogFileName("../log-compile-1.txt");
+        verifier.executeGoals(Arrays.asList("clean", "compile"));
+        verifier.verifyErrorFreeLog();
+
+        verifier.setLogFileName("../log-compile-2.txt");

Review Comment:
   `IntegrationTestExtension` copies each test project to 
`target/mvn-cache-tests/<TestClass>/<testMethod>/project`, so `../` resolves to 
a directory unique to each test method and can't collide with other tests, even 
when they run in parallel. It's also the convention the rest of the ITs follow 
(nearly every `setLogFileName` call in `src/test/java` uses `../`), so I've 
kept it consistent.
   



##########
src/test/java/org/apache/maven/buildcache/its/CompileOnlyReactorRestoreTest.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+package org.apache.maven.buildcache.its;
+
+import java.util.Arrays;
+
+import org.apache.maven.buildcache.its.junit.IntegrationTest;
+import org.apache.maven.it.VerificationException;
+import org.apache.maven.it.Verifier;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Reproducer for <a 
href="https://github.com/apache/maven-build-cache-extension/issues/492";>Issue 
#492</a>:
+ * {@code clean compile} twice in a multi-module reactor fails to resolve the 
upstream module.
+ *
+ * <p>On the second run the cache extension restores the upstream module's 
compiled
+ * output but, because no jar was produced in the original cached build, 
downstream
+ * dependency resolution falls through to remote repositories with
+ * {@code Could not find artifact ...:jar:...-SNAPSHOT}.
+ */
+@IntegrationTest("src/test/projects/issue-393-compile-restore")
+class CompileOnlyReactorRestoreTest {
+
+    @Test
+    void cleanCompileTwiceResolvesUpstreamFromReactorCache(Verifier verifier) 
throws VerificationException {
+        verifier.setAutoclean(false);
+
+        verifier.setLogFileName("../log-compile-1.txt");
+        verifier.executeGoals(Arrays.asList("clean", "compile"));
+        verifier.verifyErrorFreeLog();
+
+        verifier.setLogFileName("../log-compile-2.txt");

Review Comment:
   See above
   



##########
src/test/java/org/apache/maven/buildcache/its/CompileOnlyReactorRestoreTest.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+package org.apache.maven.buildcache.its;
+
+import java.util.Arrays;
+
+import org.apache.maven.buildcache.its.junit.IntegrationTest;
+import org.apache.maven.it.VerificationException;
+import org.apache.maven.it.Verifier;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Reproducer for <a 
href="https://github.com/apache/maven-build-cache-extension/issues/492";>Issue 
#492</a>:
+ * {@code clean compile} twice in a multi-module reactor fails to resolve the 
upstream module.
+ *
+ * <p>On the second run the cache extension restores the upstream module's 
compiled
+ * output but, because no jar was produced in the original cached build, 
downstream
+ * dependency resolution falls through to remote repositories with
+ * {@code Could not find artifact ...:jar:...-SNAPSHOT}.
+ */
+@IntegrationTest("src/test/projects/issue-393-compile-restore")
+class CompileOnlyReactorRestoreTest {
+
+    @Test
+    void cleanCompileTwiceResolvesUpstreamFromReactorCache(Verifier verifier) 
throws VerificationException {
+        verifier.setAutoclean(false);
+
+        verifier.setLogFileName("../log-compile-1.txt");
+        verifier.executeGoals(Arrays.asList("clean", "compile"));
+        verifier.verifyErrorFreeLog();
+
+        verifier.setLogFileName("../log-compile-2.txt");
+        verifier.executeGoals(Arrays.asList("clean", "compile"));
+        verifier.verifyErrorFreeLog();
+        verifier.verifyTextInLog(
+                "Found cached build, restoring 
org.apache.maven.caching.test.jpms:issue-393-app from cache");

Review Comment:
   This one's intentional. On the second run both `issue-393-app` and 
`issue-393-consumer` are restored from cache, so a bare "Found cached build, 
restoring" would match either module. Including the coordinates is what proves 
the upstream module, the one #492 is about, took the restore path. 
`Issue87Test` and `Issue115Test` assert on the full project name in the same 
way.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to