1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package org.apache.maven.buildcache.its;
20  
21  import java.io.IOException;
22  import java.nio.file.Files;
23  import java.nio.file.Path;
24  
25  import com.google.common.collect.Lists;
26  import org.apache.commons.io.FileUtils;
27  import org.apache.maven.buildcache.its.junit.IntegrationTest;
28  import org.apache.maven.it.VerificationException;
29  import org.apache.maven.it.Verifier;
30  import org.junit.jupiter.api.AfterEach;
31  import org.junit.jupiter.api.BeforeEach;
32  import org.junit.jupiter.api.Test;
33  
34  import static org.apache.maven.buildcache.xml.CacheConfigImpl.CACHE_LOCATION_PROPERTY_NAME;
35  import static org.junit.jupiter.api.Assertions.assertThrows;
36  
37  
38  
39  
40  
41  @IntegrationTest("src/test/projects/forked-executions-core-extension")
42  public class ForkedExecutionCoreExtensionTest {
43  
44      private static final String PROJECT_NAME = "org.apache.maven.caching.test.simple:forked-executions-core-extension";
45      private Path tempDirectory;
46  
47      @BeforeEach
48      void setUp() throws IOException {
49          tempDirectory = Files.createTempDirectory("build-cache-test-");
50      }
51  
52      @AfterEach
53      void tearDown() throws IOException {
54          FileUtils.deleteDirectory(tempDirectory.toFile());
55      }
56  
57      @Test
58      void testForkedExecution(Verifier verifier) throws VerificationException {
59          verifier.setAutoclean(false);
60  
61          verifier.setLogFileName("../log-1.txt");
62          verifier.setMavenDebug(true);
63          verifier.setCliOptions(
64                  Lists.newArrayList("-D" + CACHE_LOCATION_PROPERTY_NAME + "=" + tempDirectory.toAbsolutePath()));
65          verifier.executeGoal("verify");
66          verifier.verifyTextInLog("Started forked project");
67          
68          verifier.verifyTextInLog(
69                  "[DEBUG] Starting mojo execution: pmd:pmd:emptyLifecyclePhase:maven-pmd-plugin:org.apache.maven.plugins");
70          
71          assertThrows(
72                  VerificationException.class,
73                  () -> verifier.verifyTextInLog(
74                          "Mojo execution pmd:pmd:emptyLifecyclePhase:maven-pmd-plugin:org.apache.maven.plugins is forked,"
75                                  + " returning phase verify from originating mojo "
76                                  + "default:check:verify:maven-pmd-plugin:org.apache.maven.plugins"));
77          verifier.verifyTextInLog("[INFO] BUILD SUCCESS");
78  
79          verifier.setLogFileName("../log-2.txt");
80          verifier.executeGoal("verify");
81          verifier.verifyErrorFreeLog();
82          verifier.verifyTextInLog("Found cached build, restoring " + PROJECT_NAME + " from cache");
83          
84          verifier.verifyTextInLog("[INFO] Skipping plugin execution (cached): pmd:check");
85          
86          assertThrows(
87                  VerificationException.class,
88                  () -> verifier.verifyTextInLog(
89                          "[DEBUG] Starting mojo execution: pmd:pmd:emptyLifecyclePhase:maven-pmd-plugin:org.apache.maven.plugins"));
90          
91          assertThrows(
92                  VerificationException.class,
93                  () -> verifier.verifyTextInLog("[INFO] Skipping plugin execution (cached): pmd:pmd"));
94          verifier.verifyTextInLog("[INFO] BUILD SUCCESS");
95      }
96  }