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.Path;
23 import java.nio.file.Paths;
24 import java.util.Arrays;
25 import java.util.List;
26
27 import org.apache.maven.buildcache.its.junit.IntegrationTest;
28 import org.apache.maven.buildcache.util.LogFileUtils;
29 import org.apache.maven.buildcache.xml.XmlService;
30 import org.apache.maven.buildcache.xml.build.ProjectsInputInfo;
31 import org.apache.maven.it.VerificationException;
32 import org.apache.maven.it.Verifier;
33 import org.junit.jupiter.api.Test;
34
35 import static org.junit.jupiter.api.Assertions.assertEquals;
36
37 @IntegrationTest("src/test/projects/mbuildcache-87")
38 class Issue87Test {
39
40 private static final String MODULE1_PROJECT_ARTIFACT = "org.apache.maven.caching.test.mbuildcache-87:module1:jar";
41 private static final String MODULE2_PROJECT_NAME = "org.apache.maven.caching.test.mbuildcache-87:module2";
42 private static final String FOUND_CACHED_RESTORING_MODULE2_MESSAGE =
43 "Found cached build, restoring " + MODULE2_PROJECT_NAME + " from cache";
44
45 @Test
46 void simple(Verifier verifier) throws VerificationException, IOException {
47 verifier.setLogFileName("../log-0.txt");
48 verifier.executeGoals(Arrays.asList("-f", "external", "install"));
49 verifier.verifyErrorFreeLog();
50
51 verifier.setAutoclean(false);
52
53 verifier.setLogFileName("../log-1.txt");
54 verifier.executeGoals(Arrays.asList("-f", "top", "verify"));
55 verifier.verifyErrorFreeLog();
56
57 verifier.setLogFileName("../log-2.txt");
58 verifier.executeGoals(Arrays.asList("-f", "top", "verify"));
59 verifier.verifyErrorFreeLog();
60 verifier.verifyTextInLog(FOUND_CACHED_RESTORING_MODULE2_MESSAGE);
61
62
63 verifier.writeFile("top/module1/src/main/resources/org/apache/maven/buildcache/test.properties", "foo=bar");
64 verifier.setLogFileName("../log-3.txt");
65 verifier.executeGoals(Arrays.asList("-f", "top", "verify"));
66 verifier.verifyErrorFreeLog();
67 verifyTextNotInLog(verifier, FOUND_CACHED_RESTORING_MODULE2_MESSAGE);
68
69
70 String buildInfoXmlLog =
71 LogFileUtils.findLinesContainingTextsInLogs(verifier, "Saved Build to local file: ").stream()
72 .filter(line -> line.contains("module2"))
73 .findFirst()
74 .orElseThrow(
75 () -> new VerificationException("Could not find module2 build info file location"));
76 Path buildInfoXmlLocation = Paths.get(buildInfoXmlLog.split(":\\s")[1]);
77
78 ProjectsInputInfo projectsInputInfo =
79 new XmlService().loadBuild(buildInfoXmlLocation.toFile()).getProjectsInputInfo();
80
81 assertEquals(
82 1,
83 projectsInputInfo.getItems().stream()
84 .filter(item -> "dependency".equals(item.getType()))
85 .filter(item -> MODULE1_PROJECT_ARTIFACT.equals(item.getValue()))
86 .count(),
87 "Expected artifact acting as plugin dependency and project dependency to be considered twice during checksum computation");
88 assertEquals(
89 1,
90 projectsInputInfo.getItems().stream()
91 .filter(item -> "pluginDependency".equals(item.getType()))
92 .filter(item -> ("org.apache.maven.plugins:maven-dependency-plugin:maven-plugin|0|"
93 + MODULE1_PROJECT_ARTIFACT)
94 .equals(item.getValue()))
95 .count(),
96 "Expected artifact acting as plugin dependency and project dependency to be considered twice during checksum computation");
97
98 assertEquals(
99 1,
100 projectsInputInfo.getItems().stream()
101 .filter(item -> "pluginDependency".equals(item.getType()))
102 .filter(item ->
103 "org.apache.maven.plugins:maven-dependency-plugin:maven-plugin|0|org.apache.maven.caching.test.mbuildcache-87:external:jar"
104 .equals(item.getValue()))
105 .count(),
106 "Expected external snapshot plugin dependency to be included in the checksum computation");
107
108 assertEquals(
109 0,
110 projectsInputInfo.getItems().stream()
111 .filter(item -> "pluginDependency".equals(item.getType()))
112 .filter(item -> item.getValue()
113 .startsWith("org.apache.maven.plugins:maven-compiler-plugin:maven-plugin|"))
114 .count(),
115 "Expected plugins having excludeDependencies=true to have their dependencies excluded");
116 }
117
118 private void verifyTextNotInLog(Verifier verifier, String text) throws VerificationException {
119
120 List<String> lines = verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false);
121
122 boolean result = true;
123 for (String line : lines) {
124 if (Verifier.stripAnsi(line).contains(text)) {
125 result = false;
126 break;
127 }
128 }
129 if (!result) {
130 throw new VerificationException("Text found in log: " + text);
131 }
132 }
133 }