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.io.IOException;
22  import java.nio.file.Files;
23  import java.nio.file.Paths;
24  import java.util.List;
25  
26  import org.apache.commons.lang3.SystemUtils;
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.Test;
31  
32  import static java.util.Arrays.asList;
33  import static org.junit.jupiter.api.Assumptions.assumeFalse;
34  
35  @IntegrationTest("src/test/projects/mbuildcache-367")
36  class Issue367Test {
37  
38      private static final String PROJECT_NAME = "org.apache.maven.caching.test:mbuildcache-367";
39  
40      @Test
41      void fileOutsideInputDirectoryMatchingProjectLevelGlobPatternShouldNotInvalidateCache(Verifier verifier)
42              throws VerificationException, IOException {
43          assumeFalse(SystemUtils.IS_OS_WINDOWS);
44  
45          verifier.setAutoclean(false);
46  
47          verifier.setLogFileName("../log-0.txt");
48          verifier.executeGoals(asList("package"));
49          verifier.verifyErrorFreeLog();
50          verifier.verifyTextInLog("Local build was not found");
51          verifyTextNotInLog(verifier, "Found cached build");
52  
53          verifier.setLogFileName("../log-1.txt");
54          verifier.executeGoals(asList("package"));
55          verifier.verifyErrorFreeLog();
56          verifier.verifyTextInLog("Found cached build");
57          verifyTextNotInLog(verifier, "Local build was not found");
58  
59          Files.copy(
60                  Paths.get(verifier.getBasedir(), "src/main/custom-resources/input/test.properties"),
61                  Paths.get(verifier.getBasedir(), "{*.properties}"));
62  
63          verifier.setLogFileName("../log-2.txt");
64          verifier.executeGoals(asList("package"));
65          verifier.verifyErrorFreeLog();
66          verifier.verifyTextInLog("Found cached build");
67          verifyTextNotInLog(verifier, "Local build was not found");
68      }
69  
70      private static void verifyTextNotInLog(Verifier verifier, String text) throws VerificationException {
71          List<String> lines = verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false);
72          for (String line : lines) {
73              if (Verifier.stripAnsi(line).contains(text)) {
74                  throw new VerificationException("Text found in log: " + text);
75              }
76          }
77      }
78  }