Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MBUILDCACHE-74] Clean local cache for any artifact (#110)
Not just the ones which have a package phase. Otherwise the cached builds will be kept forever.
- Loading branch information
Showing
6 changed files
with
227 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/test/java/org/apache/maven/buildcache/its/Issue74Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.maven.buildcache.its; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.apache.maven.buildcache.its.junit.IntegrationTest; | ||
import org.apache.maven.buildcache.util.LogFileUtils; | ||
import org.apache.maven.it.VerificationException; | ||
import org.apache.maven.it.Verifier; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Check if cached builds are cleaned up correctly also for projects | ||
* which don't contain a package phase. | ||
*/ | ||
@IntegrationTest("src/test/projects/mbuildcache-74-clean-cache-any-artifact") | ||
public class Issue74Test { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(Issue74Test.class); | ||
|
||
@Test | ||
void simple(Verifier verifier) throws VerificationException, IOException { | ||
verifier.setAutoclean(false); | ||
verifier.setMavenDebug(true); | ||
|
||
// first run - uncached | ||
verifier.setLogFileName("../log-1.txt"); | ||
verifier.setSystemProperty("passed.by.test", "123"); | ||
|
||
verifier.executeGoal("verify"); | ||
|
||
verifier.verifyErrorFreeLog(); | ||
verifier.verifyTextInLog("Local build was not found"); | ||
verifyBuildCacheEntries(verifier, 1); | ||
|
||
// second run - modified | ||
verifier.setLogFileName("../log-2.txt"); | ||
verifier.setSystemProperty("passed.by.test", "456"); | ||
|
||
verifier.executeGoal("verify"); | ||
|
||
verifier.verifyErrorFreeLog(); | ||
verifier.verifyTextInLog("Local build was not found"); | ||
verifyBuildCacheEntries(verifier, 1); | ||
} | ||
|
||
private static void verifyBuildCacheEntries(final Verifier verifier, long expectedBuilds) | ||
throws VerificationException, IOException { | ||
String buildInfoXmlLog = | ||
LogFileUtils.findFirstLineContainingTextsInLogs(verifier, "Saved Build to local file: "); | ||
String buildInfoXmlLocation = buildInfoXmlLog.split(":\\s")[1]; | ||
|
||
Path buildInfoXmlPath = Paths.get(buildInfoXmlLocation); | ||
// buildinfo.xml -> local -> hash -> project | ||
Path projectPathInCache = buildInfoXmlPath.getParent().getParent().getParent(); | ||
|
||
logger.info("Checking '{}' for cached builds ...", projectPathInCache); | ||
|
||
if (!Files.exists(projectPathInCache)) { | ||
throw new VerificationException( | ||
String.format("Project directory in build cache doesn't exist: '%s'", projectPathInCache)); | ||
} | ||
|
||
List<Path> entries = | ||
Files.list(projectPathInCache).filter(p -> Files.isDirectory(p)).collect(Collectors.toList()); | ||
|
||
Assertions.assertEquals( | ||
expectedBuilds, | ||
entries.size(), | ||
"Expected amount of cached builds not satisfied. Found: " | ||
+ entries.stream().map(p -> p.getFileName().toString()).collect(Collectors.joining(","))); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/projects/mbuildcache-74-clean-cache-any-artifact/.mvn/extensions.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2023 the original author or authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<extensions> | ||
<extension> | ||
<groupId>org.apache.maven.extensions</groupId> | ||
<artifactId>maven-build-cache-extension</artifactId> | ||
<version>${projectVersion}</version> | ||
</extension> | ||
</extensions> |
28 changes: 28 additions & 0 deletions
28
src/test/projects/mbuildcache-74-clean-cache-any-artifact/.mvn/maven-build-cache-config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
|
||
<cache xmlns="http://maven.apache.org/CACHE-CONFIG/1.0.0"> | ||
<configuration> | ||
<local> | ||
<maxBuildsCached>1</maxBuildsCached> | ||
</local> | ||
</configuration> | ||
</cache> |
60 changes: 60 additions & 0 deletions
60
src/test/projects/mbuildcache-74-clean-cache-any-artifact/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!-- | ||
Copyright 2023 the original author or authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.apache.maven.caching.test.mbuildcache-74</groupId> | ||
<artifactId>mbuildcache-74</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>pom</packaging> | ||
|
||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-enforcer-plugin</artifactId> | ||
<version>3.4.1</version> | ||
<executions> | ||
<execution> | ||
<id>require-property</id> | ||
<goals> | ||
<goal>enforce</goal> | ||
</goals> | ||
<configuration> | ||
<rules> | ||
<requireProperty> | ||
<property>passed.by.test</property> | ||
<message>Property passed.by.test is required</message> | ||
<regex>\d{3}</regex> | ||
<regexMessage>The passed.by.test property must consist of 3 digits. (actual=${passed.by.test})</regexMessage> | ||
</requireProperty> | ||
</rules> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |