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 import java.nio.file.Paths;
25 import java.util.List;
26 import java.util.stream.Collectors;
27
28 import org.apache.maven.buildcache.its.junit.IntegrationTest;
29 import org.apache.maven.buildcache.util.LogFileUtils;
30 import org.apache.maven.it.VerificationException;
31 import org.apache.maven.it.Verifier;
32 import org.junit.jupiter.api.Assertions;
33 import org.junit.jupiter.api.Test;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37
38
39
40
41 @IntegrationTest("src/test/projects/mbuildcache-74-clean-cache-any-artifact")
42 public class Issue74Test {
43
44 private static final Logger logger = LoggerFactory.getLogger(Issue74Test.class);
45
46 @Test
47 void simple(Verifier verifier) throws VerificationException, IOException {
48 verifier.setAutoclean(false);
49 verifier.setMavenDebug(true);
50
51
52 verifier.setLogFileName("../log-1.txt");
53 verifier.setSystemProperty("passed.by.test", "123");
54
55 verifier.executeGoal("verify");
56
57 verifier.verifyErrorFreeLog();
58 verifier.verifyTextInLog("Local build was not found");
59 verifyBuildCacheEntries(verifier, 1);
60
61
62 verifier.setLogFileName("../log-2.txt");
63 verifier.setSystemProperty("passed.by.test", "456");
64
65 verifier.executeGoal("verify");
66
67 verifier.verifyErrorFreeLog();
68 verifier.verifyTextInLog("Local build was not found");
69 verifyBuildCacheEntries(verifier, 1);
70 }
71
72 private static void verifyBuildCacheEntries(final Verifier verifier, long expectedBuilds)
73 throws VerificationException, IOException {
74 String buildInfoXmlLog =
75 LogFileUtils.findFirstLineContainingTextsInLogs(verifier, "Saved Build to local file: ");
76 String buildInfoXmlLocation = buildInfoXmlLog.split(":\\s")[1];
77
78 Path buildInfoXmlPath = Paths.get(buildInfoXmlLocation);
79
80 Path projectPathInCache = buildInfoXmlPath.getParent().getParent().getParent();
81
82 logger.info("Checking '{}' for cached builds ...", projectPathInCache);
83
84 if (!Files.exists(projectPathInCache)) {
85 throw new VerificationException(
86 String.format("Project directory in build cache doesn't exist: '%s'", projectPathInCache));
87 }
88
89 List<Path> entries =
90 Files.list(projectPathInCache).filter(p -> Files.isDirectory(p)).collect(Collectors.toList());
91
92 Assertions.assertEquals(
93 expectedBuilds,
94 entries.size(),
95 "Expected amount of cached builds not satisfied. Found: "
96 + entries.stream().map(p -> p.getFileName().toString()).collect(Collectors.joining(",")));
97 }
98 }