Skip to content

Commit 24ca0e2

Browse files
committed
Fixes #367 - Do not consider project level glob as additional input value
1 parent d1f9cd9 commit 24ca0e2

File tree

6 files changed

+167
-1
lines changed

6 files changed

+167
-1
lines changed

src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ private SortedSet<Path> getInputFiles() {
370370

371371
Properties properties = project.getProperties();
372372
for (String name : properties.stringPropertyNames()) {
373-
if (name.startsWith(CACHE_INPUT_NAME)) {
373+
if (name.startsWith(CACHE_INPUT_NAME) && !CACHE_INPUT_GLOB_NAME.equals(name)) {
374374
String path = properties.getProperty(name);
375375
startWalk(Paths.get(path), projectGlob, recursive, collectedFiles, visitedDirs);
376376
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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.maven.buildcache.its.junit.IntegrationTest;
27+
import org.apache.maven.it.VerificationException;
28+
import org.apache.maven.it.Verifier;
29+
import org.junit.jupiter.api.Test;
30+
31+
import static java.util.Arrays.asList;
32+
33+
@IntegrationTest("src/test/projects/mbuildcache-367")
34+
class Issue367Test {
35+
36+
private static final String PROJECT_NAME = "org.apache.maven.caching.test:mbuildcache-367";
37+
38+
@Test
39+
void fileOutsideInputDirectoryMatchingProjectLevelGlobPatternShouldNotInvalidateCache(Verifier verifier)
40+
throws VerificationException, IOException {
41+
42+
verifier.setAutoclean(false);
43+
44+
verifier.setLogFileName("../log-0.txt");
45+
verifier.executeGoals(asList("package"));
46+
verifier.verifyErrorFreeLog();
47+
verifier.verifyTextInLog("Local build was not found");
48+
verifyTextNotInLog(verifier, "Found cached build");
49+
50+
verifier.setLogFileName("../log-1.txt");
51+
verifier.executeGoals(asList("package"));
52+
verifier.verifyErrorFreeLog();
53+
verifier.verifyTextInLog("Found cached build");
54+
verifyTextNotInLog(verifier, "Local build was not found");
55+
56+
Files.copy(
57+
Paths.get(verifier.getBasedir(), "src/main/custom-resources/input/test.properties"),
58+
Paths.get(verifier.getBasedir(), "{*.properties}"));
59+
60+
verifier.setLogFileName("../log-2.txt");
61+
verifier.executeGoals(asList("package"));
62+
verifier.verifyErrorFreeLog();
63+
verifier.verifyTextInLog("Found cached build");
64+
verifyTextNotInLog(verifier, "Local build was not found");
65+
}
66+
67+
private static void verifyTextNotInLog(Verifier verifier, String text) throws VerificationException {
68+
List<String> lines = verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false);
69+
for (String line : lines) {
70+
if (Verifier.stripAnsi(line).contains(text)) {
71+
throw new VerificationException("Text found in log: " + text);
72+
}
73+
}
74+
}
75+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright 2021 the original author or authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
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, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<extensions>
20+
<extension>
21+
<groupId>org.apache.maven.extensions</groupId>
22+
<artifactId>maven-build-cache-extension</artifactId>
23+
<version>${projectVersion}</version>
24+
</extension>
25+
</extensions>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<cache xmlns="http://maven.apache.org/BUILD-CACHE-CONFIG/1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/BUILD-CACHE-CONFIG/1.2.0 https://maven.apache.org/xsd/build-cache-config-1.2.0.xsd">
24+
<input>
25+
<global>
26+
<glob>{*.properties}</glob>
27+
<includes>
28+
<include>src/main/custom-resources/input/</include>
29+
</includes>
30+
</global>
31+
</input>
32+
</cache>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!--
2+
3+
Copyright 2021 the original author or authors.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
-->
18+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20+
21+
<modelVersion>4.0.0</modelVersion>
22+
<groupId>org.apache.maven.caching.test</groupId>
23+
<artifactId>mbuildcache-367</artifactId>
24+
<version>0.0.1-SNAPSHOT</version>
25+
<packaging>jar</packaging>
26+
27+
<properties>
28+
<maven.compiler.source>1.8</maven.compiler.source>
29+
<maven.compiler.target>1.8</maven.compiler.target>
30+
31+
<maven.build.cache.input.glob>{*.properties}</maven.build.cache.input.glob>
32+
</properties>
33+
</project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A

0 commit comments

Comments
 (0)