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

Build analytics - Fix windows prompt #34255

Merged
merged 1 commit into from
Jun 26, 2023
Merged
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

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