From 24a02852f8754f508070543bc0929d734b6ce57c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Vav=C5=99=C3=ADk?= Date: Mon, 16 Sep 2024 12:02:53 +0200 Subject: [PATCH] Only disable analytics for CLI dev or build cmd --- .../test/bootstrap/QuarkusCliClient.java | 15 ++++++------ .../test/bootstrap/tls/QuarkusTlsCommand.java | 24 +------------------ ...rkusApplicationManagedResourceBuilder.java | 8 ------- ...rkusApplicationManagedResourceBuilder.java | 4 ++++ .../quarkus/model/QuarkusProperties.java | 6 +++++ .../io/quarkus/test/utils/MavenUtils.java | 4 ++++ 6 files changed, 23 insertions(+), 38 deletions(-) diff --git a/quarkus-test-cli/src/main/java/io/quarkus/test/bootstrap/QuarkusCliClient.java b/quarkus-test-cli/src/main/java/io/quarkus/test/bootstrap/QuarkusCliClient.java index 465a43922..96213d249 100644 --- a/quarkus-test-cli/src/main/java/io/quarkus/test/bootstrap/QuarkusCliClient.java +++ b/quarkus-test-cli/src/main/java/io/quarkus/test/bootstrap/QuarkusCliClient.java @@ -1,7 +1,6 @@ package io.quarkus.test.bootstrap; -import static io.quarkus.test.services.quarkus.model.QuarkusProperties.QUARKUS_ANALYTICS_DISABLED_LOCAL_PROP_KEY; -import static java.lang.String.format; +import static io.quarkus.test.services.quarkus.model.QuarkusProperties.createDisableBuildAnalyticsProperty; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; @@ -33,6 +32,7 @@ public class QuarkusCliClient { private static final String QUARKUS_VERSION_PROPERTY_NAME = "quarkus.version"; private static final String QUARKUS_UPSTREAM_VERSION = "999-SNAPSHOT"; private static final String BUILD = "build"; + private static final String DEV = "dev"; private static final PropertyLookup COMMAND = new PropertyLookup("ts.quarkus.cli.cmd", "quarkus"); private static final Path TARGET = Paths.get("target"); @@ -234,11 +234,8 @@ private Process runCli(Path workingDirectory, File logOutput, String... args) { cmd.addAll(Arrays.asList(COMMAND.get().split(" "))); cmd.addAll(Arrays.asList(args)); - if (QuarkusProperties.disableBuildAnalytics()) { - // TODO: if logic behind setting disabled analytics in our FW get revision - // alter io.quarkus.test.bootstrap.tls.QuarkusTlsCommand.runTlsCommand - // QE tracker: https://issues.redhat.com/browse/QQE-935 - cmd.add(format("-D%s=%s", QUARKUS_ANALYTICS_DISABLED_LOCAL_PROP_KEY, Boolean.TRUE)); + if (commandSendsAnalytics(cmd) && QuarkusProperties.disableBuildAnalytics()) { + cmd.add(createDisableBuildAnalyticsProperty()); } Log.info(String.join(" ", cmd)); @@ -253,6 +250,10 @@ private Process runCli(Path workingDirectory, File logOutput, String... args) { } } + private static boolean commandSendsAnalytics(List commands) { + return commands.stream().anyMatch(cmd -> BUILD.equalsIgnoreCase(cmd) || DEV.equalsIgnoreCase(cmd)); + } + private static boolean isUpstream() { return isUpstream(QuarkusProperties.getVersion()); } diff --git a/quarkus-test-cli/src/main/java/io/quarkus/test/bootstrap/tls/QuarkusTlsCommand.java b/quarkus-test-cli/src/main/java/io/quarkus/test/bootstrap/tls/QuarkusTlsCommand.java index c5acde3be..86e61b31f 100644 --- a/quarkus-test-cli/src/main/java/io/quarkus/test/bootstrap/tls/QuarkusTlsCommand.java +++ b/quarkus-test-cli/src/main/java/io/quarkus/test/bootstrap/tls/QuarkusTlsCommand.java @@ -1,8 +1,5 @@ package io.quarkus.test.bootstrap.tls; -import static io.quarkus.test.services.quarkus.model.QuarkusProperties.QUARKUS_ANALYTICS_DISABLED_LOCAL_PROP_KEY; - -import java.io.Closeable; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -11,7 +8,6 @@ import io.quarkus.test.bootstrap.AbstractCliCommand; import io.quarkus.test.bootstrap.QuarkusCliClient; import io.quarkus.test.bootstrap.QuarkusCliCommandResult; -import io.quarkus.test.services.quarkus.model.QuarkusProperties; import io.quarkus.test.utils.FileUtils; public final class QuarkusTlsCommand extends AbstractCliCommand { @@ -38,13 +34,7 @@ public QuarkusTlsGenerateQuarkusCaCommand generateQuarkusCa() { } QuarkusCliCommandResult runTlsCommand(List subCmdArgs) { - // TLS config command doesn't support -Dquarkus.analytics.disabled option - // this forces QuarkusCliClient to don't set it - try (var ignored = dontDisableAnalyticsWithProp()) { - return runCommand("tls", subCmdArgs); - } catch (IOException e) { - throw new RuntimeException(e); - } + return runCommand("tls", subCmdArgs); } private static QuarkusCliClient.CreateApplicationRequest getCreateAppReq() { @@ -53,18 +43,6 @@ private static QuarkusCliClient.CreateApplicationRequest getCreateAppReq() { .withExtensions("tls-registry", "quarkus-rest"); } - private static Closeable dontDisableAnalyticsWithProp() { - // TODO: QE tracker for this workaround: https://issues.redhat.com/browse/QQE-935 - if (QuarkusProperties.disableBuildAnalytics()) { - System.setProperty(QUARKUS_ANALYTICS_DISABLED_LOCAL_PROP_KEY, Boolean.FALSE.toString()); - return () -> System.setProperty(QUARKUS_ANALYTICS_DISABLED_LOCAL_PROP_KEY, Boolean.TRUE.toString()); - } else { - // NOOP - return () -> { - }; - } - } - private static File createTempDir() { try { return Files.createTempDirectory("quarkus-tls-command-tests").toFile(); diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/DevModeQuarkusApplicationManagedResourceBuilder.java b/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/DevModeQuarkusApplicationManagedResourceBuilder.java index af12a0dae..0ddcf6f89 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/DevModeQuarkusApplicationManagedResourceBuilder.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/DevModeQuarkusApplicationManagedResourceBuilder.java @@ -1,7 +1,5 @@ package io.quarkus.test.services.quarkus; -import static io.quarkus.test.services.quarkus.model.QuarkusProperties.QUARKUS_ANALYTICS_DISABLED_LOCAL_PROP_KEY; - import java.lang.annotation.Annotation; import java.nio.file.Path; @@ -9,7 +7,6 @@ import io.quarkus.test.bootstrap.ServiceContext; import io.quarkus.test.security.certificate.CertificateBuilder; import io.quarkus.test.services.DevModeQuarkusApplication; -import io.quarkus.test.services.quarkus.model.QuarkusProperties; public class DevModeQuarkusApplicationManagedResourceBuilder extends QuarkusApplicationManagedResourceBuilder { @@ -33,11 +30,6 @@ public ManagedResource build(ServiceContext context) { setContext(context); configureLogging(); configureCertificates(); - if (QuarkusProperties.disableBuildAnalytics()) { - getContext() - .getOwner() - .withProperty(QUARKUS_ANALYTICS_DISABLED_LOCAL_PROP_KEY, Boolean.TRUE.toString()); - } build(); return new DevModeLocalhostQuarkusApplicationManagedResource(this); } diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/RemoteDevModeQuarkusApplicationManagedResourceBuilder.java b/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/RemoteDevModeQuarkusApplicationManagedResourceBuilder.java index 37862a385..d80e4f3af 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/RemoteDevModeQuarkusApplicationManagedResourceBuilder.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/RemoteDevModeQuarkusApplicationManagedResourceBuilder.java @@ -1,5 +1,6 @@ package io.quarkus.test.services.quarkus; +import static io.quarkus.test.services.quarkus.model.QuarkusProperties.createDisableBuildAnalyticsProperty; import static io.quarkus.test.utils.FileUtils.findTargetFile; import static io.quarkus.test.utils.MavenUtils.ENSURE_QUARKUS_BUILD; import static io.quarkus.test.utils.MavenUtils.SKIP_CHECKSTYLE; @@ -123,6 +124,9 @@ protected ProcessBuilder prepareRemoteDevProcess() { command.add(withProperty(QUARKUS_LIVE_RELOAD_URL, managedResource.getURI(Protocol.HTTP).toString())); command.add("quarkus:remote-dev"); + if (QuarkusProperties.disableBuildAnalytics()) { + command.add(createDisableBuildAnalyticsProperty()); + } Log.info("Running command: %s", String.join(" ", command)); diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/model/QuarkusProperties.java b/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/model/QuarkusProperties.java index be49b8f6f..2b17e251a 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/model/QuarkusProperties.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/model/QuarkusProperties.java @@ -1,5 +1,7 @@ package io.quarkus.test.services.quarkus.model; +import static java.lang.String.format; + import java.util.Arrays; import java.util.List; @@ -50,6 +52,10 @@ public static boolean disableBuildAnalytics() { return QUARKUS_ANALYTICS_DISABLED_LOCAL_PROP.getAsBoolean(); } + public static String createDisableBuildAnalyticsProperty() { + return format("-D%s=%s", QUARKUS_ANALYTICS_DISABLED_LOCAL_PROP_KEY, Boolean.TRUE); + } + public static boolean isNativeEnabled() { return Boolean.parseBoolean(NATIVE_ENABLED.get()); } diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/utils/MavenUtils.java b/quarkus-test-core/src/main/java/io/quarkus/test/utils/MavenUtils.java index 0e951a8c0..ca89beae3 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/utils/MavenUtils.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/utils/MavenUtils.java @@ -19,6 +19,7 @@ import io.quarkus.test.bootstrap.ServiceContext; import io.quarkus.test.configuration.PropertyLookup; +import io.quarkus.test.services.quarkus.model.QuarkusProperties; public final class MavenUtils { @@ -76,6 +77,9 @@ public static List devModeMavenCommand(ServiceContext serviceContext, Li command.addAll(Arrays.asList(BATCH_MODE, SKIP_PROGRESS)); command.addAll(systemProperties); command.add(withProperty("debug", "false")); + if (QuarkusProperties.disableBuildAnalytics()) { + command.add(QuarkusProperties.createDisableBuildAnalyticsProperty()); + } command.add("quarkus:dev"); return command;