Skip to content

Commit

Permalink
Enable to skip update checks from pom properties
Browse files Browse the repository at this point in the history
  • Loading branch information
rmannibucau committed Mar 18, 2024
1 parent 8df72a1 commit a493114
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends ExtensionConfiguration> extensionConfigs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class TaskCommon {
static Future<Optional<String>> newUpdateChecker(
ProjectProperties projectProperties, GlobalConfig globalConfig, Logger logger) {
if (projectProperties.isOffline()
|| projectProperties.isDisableUpdateCheck()
|| !logger.isLifecycleEnabled()
|| globalConfig.isDisableUpdateCheck()) {
return Futures.immediateFuture(Optional.empty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class MojoCommon {
static Future<Optional<String>> newUpdateChecker(
ProjectProperties projectProperties, GlobalConfig globalConfig, Log logger) {
if (projectProperties.isOffline()
|| projectProperties.isDisableUpdateCheck()
|| !logger.isInfoEnabled()
|| globalConfig.isDisableUpdateCheck()) {
return Futures.immediateFuture(Optional.empty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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<Optional<String>> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ JibContainerBuilder createJibContainerBuilder(

boolean isOffline();

boolean isDisableUpdateCheck();

JibContainerBuilder runPluginExtensions(
List<? extends ExtensionConfiguration> extensionConfigs,
JibContainerBuilder jibContainerBuilder)
Expand Down

0 comments on commit a493114

Please sign in to comment.