View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.buildcache.its;
20  
21  import java.util.List;
22  
23  import org.apache.maven.buildcache.its.junit.IntegrationTest;
24  import org.apache.maven.it.VerificationException;
25  import org.apache.maven.it.Verifier;
26  import org.junit.jupiter.api.Test;
27  
28  @IntegrationTest("src/test/projects/skip-cache-param")
29  public class SkipCacheParamTest {
30  
31      @Test
32      void skipCacheAndCacheDisabled(Verifier verifier) throws VerificationException {
33          // cache.enabled=false , cache.skipCache=false => cache should NOT be created
34          verifier.setAutoclean(false);
35          verifier.setLogFileName("../log-0.txt");
36          verifier.addCliOption("-Dmaven.build.cache.enabled=false");
37          verifier.addCliOption("-Dmaven.build.cache.skipCache=false");
38  
39          verifier.executeGoal("package");
40  
41          verifier.verifyErrorFreeLog();
42          verifier.verifyTextInLog("Building jar:");
43          verifyTextNotInLog(verifier, "Saved Build to local file:");
44      }
45  
46      @Test
47      void cacheEnabledShouldCreateCache(Verifier verifier) throws VerificationException {
48          // cache.enabled=true , cache.skipCache=false => cache should be created, normal scenario
49          verifier.setAutoclean(false);
50          verifier.setLogFileName("../log-1.txt");
51          verifier.addCliOption("-Dmaven.build.cache.enabled=true");
52          verifier.addCliOption("-Dmaven.build.cache.skipCache=false");
53  
54          verifier.executeGoal("package");
55  
56          verifier.verifyErrorFreeLog();
57          verifier.verifyTextInLog("Going to calculate checksum for project");
58      }
59  
60      @Test
61      void disabledCacheAndSkipCacheShouldNotCreateCache(Verifier verifier) throws VerificationException {
62          // cache.enabled=false , cache.skipCache=true => cache should NOT be created
63          verifier.setAutoclean(false);
64  
65          verifier.setLogFileName("../log-2.txt");
66          verifier.addCliOption("-Dmaven.build.cache.enabled=false");
67          verifier.addCliOption("-Dmaven.build.cache.skipCache=true");
68  
69          verifier.executeGoal("package");
70  
71          verifier.verifyErrorFreeLog();
72          verifier.verifyTextInLog("Building jar:");
73          verifyTextNotInLog(verifier, "Saved Build to local file:");
74      }
75  
76      @Test
77      void enabledCacheAndSkippingCacheShouldNotCreateCache(Verifier verifier) throws VerificationException {
78          // cache.enabled=true , cache.skipCache= true => cache should not be read, only be created
79          verifier.setAutoclean(false);
80          verifier.setLogFileName("../log-3.txt");
81          verifier.addCliOption("-Dmaven.build.cache.enabled=true");
82          verifier.addCliOption("-Dmaven.build.cache.skipCache=true");
83  
84          verifier.executeGoal("package");
85  
86          verifier.verifyErrorFreeLog();
87          verifier.verifyTextInLog("Saved Build to local file:");
88  
89          // repeating one more time should not trigger a lookup
90          verifier.executeGoal("package");
91  
92          verifyTextNotInLog(verifier, "Found cached build, restoring");
93      }
94  
95      private static void verifyTextNotInLog(Verifier verifier, String text) throws VerificationException {
96          List<String> lines = verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false);
97          for (String line : lines) {
98              if (Verifier.stripAnsi(line).contains(text)) {
99                  throw new VerificationException("Text found in log: " + text);
100             }
101         }
102     }
103 }