Skip to content

Commit

Permalink
Merge pull request #34255 from brunobat/build-analytics-part2
Browse files Browse the repository at this point in the history
Build analytics - Fix windows prompt
  • Loading branch information
rsvoboda authored Jun 26, 2023
2 parents fe05bd6 + f3a16b4 commit 5676d07
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 103 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.BufferedWriter;
import java.io.File;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
Expand All @@ -17,8 +18,8 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Scanner;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;

import javax.inject.Inject;

Expand Down Expand Up @@ -69,7 +70,6 @@
import io.quarkus.deployment.dev.DevModeContext;
import io.quarkus.deployment.dev.DevModeMain;
import io.quarkus.deployment.dev.QuarkusDevModeLauncher;
import io.quarkus.gradle.Prompter;
import io.quarkus.gradle.dependency.ApplicationDeploymentClasspathBuilder;
import io.quarkus.gradle.dsl.CompilerOption;
import io.quarkus.gradle.dsl.CompilerOptions;
Expand Down Expand Up @@ -324,14 +324,16 @@ public void startDev() {
AnalyticsService analyticsService = new AnalyticsService(FileLocationsImpl.INSTANCE,
new GradleMessageWriter(getLogger()));
analyticsService.buildAnalyticsUserInput((String prompt) -> {
try {
final AtomicReference<String> userInput = new AtomicReference<>("");
final Prompter prompter = new Prompter();
prompter.addPrompt(prompt, input -> userInput.set(input));
prompter.collectInput();
return userInput.get();
} catch (IOException e) {
getLogger().debug("Failed to collect user input for analytics", e);
System.out.print(prompt);
try (Scanner scanner = new Scanner(new FilterInputStream(System.in) {
@Override
public void close() throws IOException {
//don't close System.in!
}
})) {
return scanner.nextLine();
} catch (Exception e) {
getLogger().warn("Failed to collect user input for analytics", e);
return "";
}
});
Expand Down
22 changes: 12 additions & 10 deletions devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static org.twdata.maven.mojoexecutor.MojoExecutor.version;

import java.io.File;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
Expand All @@ -31,8 +32,8 @@
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.Scanner;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -102,7 +103,6 @@
import io.quarkus.maven.MavenDevModeLauncher.Builder;
import io.quarkus.maven.components.CompilerOptions;
import io.quarkus.maven.components.MavenVersionEnforcer;
import io.quarkus.maven.components.Prompter;
import io.quarkus.maven.components.QuarkusWorkspaceProvider;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.ArtifactKey;
Expand Down Expand Up @@ -411,14 +411,16 @@ public void execute() throws MojoFailureException, MojoExecutionException {
saveTerminalState();

analyticsProvider.buildAnalyticsUserInput((String prompt) -> {
try {
final AtomicReference<String> userInput = new AtomicReference<>("");
final Prompter prompter = new Prompter();
prompter.addPrompt(prompt, input -> userInput.set(input));
prompter.collectInput();
return userInput.get();
} catch (IOException e) {
getLog().debug("Failed to collect user input for analytics", e);
System.out.print(prompt);
try (Scanner scanner = new Scanner(new FilterInputStream(System.in) {
@Override
public void close() throws IOException {
//don't close System.in!
}
})) {
return scanner.nextLine();
} catch (Exception e) {
getLog().warn("Failed to collect user input for analytics", e);
return "";
}
});
Expand Down

0 comments on commit 5676d07

Please sign in to comment.