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.File;
22 import java.util.regex.Matcher;
23 import java.util.regex.Pattern;
24
25 import org.apache.maven.buildcache.its.junit.IntegrationTest;
26 import org.apache.maven.buildcache.util.LogFileUtils;
27 import org.apache.maven.it.VerificationException;
28 import org.apache.maven.it.Verifier;
29 import org.junit.jupiter.api.Assertions;
30 import org.junit.jupiter.api.Test;
31
32 @IntegrationTest("src/test/projects/include-exclude")
33 public class IncludeExcludeTest {
34
35 private static final Pattern NB_SRC_PATTERN = Pattern.compile("^(.*Found )([0-9]*)( input files.*)");
36
37 private static final String PROJECT_NAME = "org.apache.maven.caching.test.include-exclude:include-exclude";
38
39
40
41
42
43
44 @Test
45 void includeExclude(Verifier verifier) throws VerificationException {
46 verifier.setAutoclean(false);
47 verifier.setMavenDebug(true);
48
49
50 verifier.setLogFileName("../log-1.txt");
51 verifier.executeGoal("verify");
52 verifyLogs(verifier);
53
54
55 verifier.setLogFileName("../log-2.txt");
56 verifier.executeGoal("verify");
57 verifyLogs(verifier);
58 verifier.verifyTextInLog("Found cached build, restoring " + PROJECT_NAME + " from cache");
59 }
60
61 private void verifyLogs(Verifier verifier) throws VerificationException {
62 final String nbFilesToFind = "9";
63
64 verifier.verifyErrorFreeLog();
65
66
67 String foundXFiles = LogFileUtils.findFirstLineContainingTextsInLogs(verifier, "Found ", " input files.");
68
69 Matcher m = NB_SRC_PATTERN.matcher(foundXFiles);
70 Assertions.assertTrue(
71 m.find(), "Found XX input files string not found in log. This test might need an update?");
72
73 Assertions.assertEquals(nbFilesToFind, m.group(2), "Expected " + nbFilesToFind + " as source.");
74
75
76 String srcInputLine = LogFileUtils.findFirstLineContainingTextsInLogs(verifier, "Src input: [");
77
78 srcInputLine = srcInputLine.substring(0, srcInputLine.length() - 1);
79 String[] srcInputs = srcInputLine.split(",");
80
81 findLineContaining(srcInputs, "this_one_should_be_scanned.txt");
82 findLineContaining(srcInputs, "included_file_one.txt");
83 findLineContaining(srcInputs, "included_file_two.txt");
84 findLineContaining(srcInputs, "extraFile.txt");
85 findLineContaining(srcInputs, "from_second_folder.txt");
86 findLineContaining(srcInputs, "will_be_scanned.txt");
87 findLineContaining(srcInputs, "Test.java");
88 findLineContaining(srcInputs, "second_circle.txt");
89 findLineContaining(srcInputs, "third_circle.txt");
90
91
92 String blacklistedLine = LogFileUtils.findFirstLineContainingTextsInLogs(
93 verifier, "Skipping subtree (blacklisted)", "buildcache" + File.separator + "not");
94 Assertions.assertNotNull(
95 blacklistedLine,
96 "Expecting a debug line saying that \"src/main/java/org/apache/maven/buildcache/not\" is excluded from tree walking.");
97 }
98
99 private void findLineContaining(String[] lines, String text) throws VerificationException {
100 for (String line : lines) {
101 if (line.contains(text)) {
102 return;
103 }
104 }
105 throw new VerificationException("There is no line containing : " + text);
106 }
107 }