Skip to content

Commit

Permalink
Merge pull request #1319 from michalvavrik/feature/refactor-disabling…
Browse files Browse the repository at this point in the history
…-of-cli-analytics

Only disable analytics for Quarkus CLI dev or build command
  • Loading branch information
mjurc authored Sep 17, 2024
2 parents b652a3f + 24a0285 commit 3ba4289
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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));
Expand All @@ -253,6 +250,10 @@ private Process runCli(Path workingDirectory, File logOutput, String... args) {
}
}

private static boolean commandSendsAnalytics(List<String> commands) {
return commands.stream().anyMatch(cmd -> BUILD.equalsIgnoreCase(cmd) || DEV.equalsIgnoreCase(cmd));
}

private static boolean isUpstream() {
return isUpstream(QuarkusProperties.getVersion());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -38,13 +34,7 @@ public QuarkusTlsGenerateQuarkusCaCommand generateQuarkusCa() {
}

QuarkusCliCommandResult runTlsCommand(List<String> 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() {
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
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;

import io.quarkus.test.bootstrap.ManagedResource;
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 {

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -76,6 +77,9 @@ public static List<String> 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;
Expand Down

0 comments on commit 3ba4289

Please sign in to comment.