diff --git a/src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java b/src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java index 0a2d4d73..d0ee7ff3 100644 --- a/src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java +++ b/src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java @@ -129,7 +129,7 @@ public void execute( for (MojoExecution mojoExecution : cleanPhase) { mojoExecutionRunner.run(mojoExecution); } - if (cacheState == INITIALIZED || skipCache) { + if (cacheState == INITIALIZED) { result = cacheController.findCachedBuild(session, project, mojoExecutions, skipCache); } } else { diff --git a/src/test/java/org/apache/maven/buildcache/its/SkipCacheParamTest.java b/src/test/java/org/apache/maven/buildcache/its/SkipCacheParamTest.java new file mode 100644 index 00000000..9f6b1dae --- /dev/null +++ b/src/test/java/org/apache/maven/buildcache/its/SkipCacheParamTest.java @@ -0,0 +1,103 @@ +/* + * 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.util.List; + +import org.apache.maven.buildcache.its.junit.IntegrationTest; +import org.apache.maven.it.VerificationException; +import org.apache.maven.it.Verifier; +import org.junit.jupiter.api.Test; + +@IntegrationTest("src/test/projects/skip-cache-param") +public class SkipCacheParamTest { + + @Test + void skipCacheAndCacheDisabled(Verifier verifier) throws VerificationException { + // cache.enabled=false , cache.skipCache=false => cache should NOT be created + verifier.setAutoclean(false); + verifier.setLogFileName("../log-0.txt"); + verifier.addCliOption("-Dmaven.build.cache.enabled=false"); + verifier.addCliOption("-Dmaven.build.cache.skipCache=false"); + + verifier.executeGoal("package"); + + verifier.verifyErrorFreeLog(); + verifier.verifyTextInLog("Building jar:"); + verifyTextNotInLog(verifier, "Saved Build to local file:"); + } + + @Test + void cacheEnabledShouldCreateCache(Verifier verifier) throws VerificationException { + // cache.enabled=true , cache.skipCache=false => cache should be created, normal scenario + verifier.setAutoclean(false); + verifier.setLogFileName("../log-1.txt"); + verifier.addCliOption("-Dmaven.build.cache.enabled=true"); + verifier.addCliOption("-Dmaven.build.cache.skipCache=false"); + + verifier.executeGoal("package"); + + verifier.verifyErrorFreeLog(); + verifier.verifyTextInLog("Going to calculate checksum for project"); + } + + @Test + void disabledCacheAndSkipCacheShouldNotCreateCache(Verifier verifier) throws VerificationException { + // cache.enabled=false , cache.skipCache=true => cache should NOT be created + verifier.setAutoclean(false); + + verifier.setLogFileName("../log-2.txt"); + verifier.addCliOption("-Dmaven.build.cache.enabled=false"); + verifier.addCliOption("-Dmaven.build.cache.skipCache=true"); + + verifier.executeGoal("package"); + + verifier.verifyErrorFreeLog(); + verifier.verifyTextInLog("Building jar:"); + verifyTextNotInLog(verifier, "Saved Build to local file:"); + } + + @Test + void enabledCacheAndSkippingCacheShouldNotCreateCache(Verifier verifier) throws VerificationException { + // cache.enabled=true , cache.skipCache= true => cache should not be read, only be created + verifier.setAutoclean(false); + verifier.setLogFileName("../log-3.txt"); + verifier.addCliOption("-Dmaven.build.cache.enabled=true"); + verifier.addCliOption("-Dmaven.build.cache.skipCache=true"); + + verifier.executeGoal("package"); + + verifier.verifyErrorFreeLog(); + verifier.verifyTextInLog("Saved Build to local file:"); + + // repeating one more time should not trigger a lookup + verifier.executeGoal("package"); + + verifyTextNotInLog(verifier, "Found cached build, restoring"); + } + + private static void verifyTextNotInLog(Verifier verifier, String text) throws VerificationException { + List lines = verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false); + for (String line : lines) { + if (Verifier.stripAnsi(line).contains(text)) { + throw new VerificationException("Text found in log: " + text); + } + } + } +} diff --git a/src/test/projects/skip-cache-param/.mvn/extensions.xml b/src/test/projects/skip-cache-param/.mvn/extensions.xml new file mode 100644 index 00000000..15c170e8 --- /dev/null +++ b/src/test/projects/skip-cache-param/.mvn/extensions.xml @@ -0,0 +1,23 @@ + + + + + org.apache.maven.extensions + maven-build-cache-extension + ${projectVersion} + + diff --git a/src/test/projects/skip-cache-param/pom.xml b/src/test/projects/skip-cache-param/pom.xml new file mode 100644 index 00000000..552054a0 --- /dev/null +++ b/src/test/projects/skip-cache-param/pom.xml @@ -0,0 +1,25 @@ + + + + 4.0.0 + com.mayweg + untitled + 1.0-SNAPSHOT + + + diff --git a/src/test/projects/skip-cache-param/src/main/java/Main.java b/src/test/projects/skip-cache-param/src/main/java/Main.java new file mode 100644 index 00000000..eaaa739e --- /dev/null +++ b/src/test/projects/skip-cache-param/src/main/java/Main.java @@ -0,0 +1,6 @@ +public class Main +{ + public static void main(String[] args) { + System.out.println("Hello World!"); + } +}