diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleProjectProperties.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleProjectProperties.java index 6a1978fe192..cef93aa1f8b 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleProjectProperties.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleProjectProperties.java @@ -454,6 +454,12 @@ public boolean isOffline() { return project.getGradle().getStartParameter().isOffline(); } + @Override + public boolean isDisableUpdateCheck() { + return Boolean.parseBoolean( + String.valueOf(project.findProperty(PropertyNames.DISABLE_UPDATE_CHECKS))); + } + @Override public JibContainerBuilder runPluginExtensions( List extensionConfigs, diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/TaskCommon.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/TaskCommon.java index ca7fc761ebc..230dbe34698 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/TaskCommon.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/TaskCommon.java @@ -50,6 +50,7 @@ class TaskCommon { static Future> newUpdateChecker( ProjectProperties projectProperties, GlobalConfig globalConfig, Logger logger) { if (projectProperties.isOffline() + || projectProperties.isDisableUpdateCheck() || !logger.isLifecycleEnabled() || globalConfig.isDisableUpdateCheck()) { return Futures.immediateFuture(Optional.empty()); diff --git a/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/MavenProjectProperties.java b/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/MavenProjectProperties.java index 7b457951c6a..b1126bb357b 100644 --- a/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/MavenProjectProperties.java +++ b/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/MavenProjectProperties.java @@ -482,6 +482,12 @@ public boolean isOffline() { return session.isOffline(); } + @Override + public boolean isDisableUpdateCheck() { + return Boolean.parseBoolean( + project.getProperties().getProperty(PropertyNames.DISABLE_UPDATE_CHECKS)); + } + @VisibleForTesting Path getWarArtifact() { Build build = project.getBuild(); diff --git a/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/MojoCommon.java b/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/MojoCommon.java index 6857f89a407..d1ec8c72b80 100644 --- a/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/MojoCommon.java +++ b/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/MojoCommon.java @@ -53,6 +53,7 @@ public class MojoCommon { static Future> newUpdateChecker( ProjectProperties projectProperties, GlobalConfig globalConfig, Log logger) { if (projectProperties.isOffline() + || projectProperties.isDisableUpdateCheck() || !logger.isInfoEnabled() || globalConfig.isDisableUpdateCheck()) { return Futures.immediateFuture(Optional.empty()); diff --git a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/MavenProjectPropertiesTest.java b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/MavenProjectPropertiesTest.java index 5bbceaf3b9c..e85a82289f6 100644 --- a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/MavenProjectPropertiesTest.java +++ b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/MavenProjectPropertiesTest.java @@ -16,9 +16,12 @@ package com.google.cloud.tools.jib.maven; +import static com.google.cloud.tools.jib.plugins.common.PropertyNames.DISABLE_UPDATE_CHECKS; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth8.assertThat; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -1089,6 +1092,26 @@ public void testGetDependencies() throws URISyntaxException { testRepository.artifactPathOnDisk("com.test", "dependencyX", "1.0.0-SNAPSHOT")); } + @Test + public void testIsDisableCheck() { + final MavenProject project = new MavenProject(); + final MavenProjectProperties properties = + new MavenProjectProperties( + mockJibPluginDescriptor, + project, + mockMavenSession, + mockLog, + mockTempDirectoryProvider, + Collections.emptyList(), + mockExtensionLoader); + + project.getProperties().setProperty(DISABLE_UPDATE_CHECKS, "true"); + assertTrue(properties.isDisableUpdateCheck()); + + project.getProperties().setProperty(DISABLE_UPDATE_CHECKS, "false"); + assertFalse(mavenProjectProperties.isDisableUpdateCheck()); + } + private BuildContext setUpBuildContext() throws InvalidImageReferenceException, IOException, CacheDirectoryCreationException { return setUpBuildContext(ContainerizingMode.EXPLODED); diff --git a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/MojoCommonTest.java b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/MojoCommonTest.java index 88e3901f39b..d085298da0e 100644 --- a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/MojoCommonTest.java +++ b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/MojoCommonTest.java @@ -16,6 +16,8 @@ package com.google.cloud.tools.jib.maven; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -24,7 +26,10 @@ import com.google.cloud.tools.jib.plugins.common.ProjectProperties; import com.google.common.util.concurrent.Futures; import java.util.Optional; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import org.apache.maven.monitor.logging.DefaultLog; +import org.codehaus.plexus.logging.console.ConsoleLogger; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -60,4 +65,19 @@ public void testFinishUpdateChecker_correctMessageLogged() { + ProjectInfo.GITHUB_URL + "/blob/master/docs/privacy.md for info on disabling this update check.")); } + + @Test + public void testUpdateChecker_disabledFromProjectProperties() + throws ExecutionException, InterruptedException { + when(mockProjectProperties.getToolName()).thenThrow(new AssertionError("shouldn't occur")); + when(mockProjectProperties.isDisableUpdateCheck()).thenReturn(true); + + final Future> future = + MojoCommon.newUpdateChecker( + mockProjectProperties, + null /* not tested since project property disable it before */, + new DefaultLog(new ConsoleLogger())); + assertEquals("com.google.common.util.concurrent.ImmediateFuture", future.getClass().getName()); + assertFalse(future.get().isPresent()); + } } diff --git a/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/ProjectProperties.java b/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/ProjectProperties.java index e8a0516226b..bef4f641200 100644 --- a/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/ProjectProperties.java +++ b/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/ProjectProperties.java @@ -90,6 +90,8 @@ JibContainerBuilder createJibContainerBuilder( boolean isOffline(); + boolean isDisableUpdateCheck(); + JibContainerBuilder runPluginExtensions( List extensionConfigs, JibContainerBuilder jibContainerBuilder)