Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable to skip update checks from pom properties #4212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,18 @@ 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.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
Loading