From bddc1908483f4b26a9c9bcf2e20c2c95822d774b Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 19 Apr 2017 22:13:28 -0700 Subject: [PATCH] Suppress "resolving dependencies" when --quiet Update Spring CLI so that the "resolving dependencies" message is suppressed when `run --quiet` is used. Fixes gh-8946 --- .../OptionSetGroovyCompilerConfiguration.java | 5 +++++ .../boot/cli/command/run/RunCommand.java | 7 ++++++- .../boot/cli/compiler/GroovyCompiler.java | 3 ++- .../cli/compiler/GroovyCompilerConfiguration.java | 6 ++++++ .../boot/cli/compiler/grape/AetherGrapeEngine.java | 12 +++++++----- .../cli/compiler/grape/AetherGrapeEngineFactory.java | 10 ++-------- .../install/GroovyGrabDependencyResolverTests.java | 5 +++++ .../cli/compiler/grape/AetherGrapeEngineTests.java | 2 +- 8 files changed, 34 insertions(+), 16 deletions(-) diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/options/OptionSetGroovyCompilerConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/options/OptionSetGroovyCompilerConfiguration.java index b3e0ee7919..d4a6b2ec19 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/options/OptionSetGroovyCompilerConfiguration.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/options/OptionSetGroovyCompilerConfiguration.java @@ -92,4 +92,9 @@ public class OptionSetGroovyCompilerConfiguration implements GroovyCompilerConfi return this.repositoryConfiguration; } + @Override + public boolean isQuiet() { + return false; + } + } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/run/RunCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/run/RunCommand.java index 97b32f30cc..ed480ed6f6 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/run/RunCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/run/RunCommand.java @@ -140,7 +140,7 @@ public class RunCommand extends OptionParsingCommand { @Override public Level getLogLevel() { - if (getOptions().has(RunOptionHandler.this.quietOption)) { + if (isQuiet()) { return Level.OFF; } if (getOptions().has(RunOptionHandler.this.verboseOption)) { @@ -149,6 +149,11 @@ public class RunCommand extends OptionParsingCommand { return Level.INFO; } + @Override + public boolean isQuiet() { + return getOptions().has(RunOptionHandler.this.quietOption); + } + } } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java index 7b4db23c27..0f7ba330bc 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java @@ -95,7 +95,8 @@ public class GroovyCompiler { new SpringBootDependenciesDependencyManagement()); AetherGrapeEngine grapeEngine = AetherGrapeEngineFactory.create(this.loader, - configuration.getRepositoryConfiguration(), resolutionContext); + configuration.getRepositoryConfiguration(), resolutionContext, + configuration.isQuiet()); GrapeEngineInstaller.install(grapeEngine); diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompilerConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompilerConfiguration.java index 7741f3242c..7fd8462dc8 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompilerConfiguration.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompilerConfiguration.java @@ -71,4 +71,10 @@ public interface GroovyCompilerConfiguration { */ List getRepositoryConfiguration(); + /** + * Returns if running in quiet mode. + * @return {@code true} if running in quiet mode + */ + boolean isQuiet(); + } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java index c62d40f98d..2342b44f03 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java @@ -77,7 +77,7 @@ public class AetherGrapeEngine implements GrapeEngine { RepositorySystem repositorySystem, DefaultRepositorySystemSession repositorySystemSession, List remoteRepositories, - DependencyResolutionContext resolutionContext) { + DependencyResolutionContext resolutionContext, boolean quiet) { this.classLoader = classLoader; this.repositorySystem = repositorySystem; this.session = repositorySystemSession; @@ -89,12 +89,14 @@ public class AetherGrapeEngine implements GrapeEngine { for (RemoteRepository repository : remotes) { addRepository(repository); } - this.progressReporter = getProgressReporter(this.session); + this.progressReporter = getProgressReporter(this.session, quiet); } - private ProgressReporter getProgressReporter(DefaultRepositorySystemSession session) { - String progressReporter = System.getProperty( - "org.springframework.boot.cli.compiler.grape.ProgressReporter"); + private ProgressReporter getProgressReporter(DefaultRepositorySystemSession session, + boolean quiet) { + String progressReporter = (quiet ? "none" + : System.getProperty( + "org.springframework.boot.cli.compiler.grape.ProgressReporter")); if ("detail".equals(progressReporter) || Boolean.getBoolean("groovy.grape.report.downloads")) { return new DetailedProgressReporter(session, System.out); diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineFactory.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineFactory.java index 13017518c1..4054e780e0 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineFactory.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineFactory.java @@ -44,27 +44,21 @@ public abstract class AetherGrapeEngineFactory { public static AetherGrapeEngine create(GroovyClassLoader classLoader, List repositoryConfigurations, - DependencyResolutionContext dependencyResolutionContext) { - + DependencyResolutionContext dependencyResolutionContext, boolean quiet) { RepositorySystem repositorySystem = createServiceLocator() .getService(RepositorySystem.class); - DefaultRepositorySystemSession repositorySystemSession = MavenRepositorySystemUtils .newSession(); - ServiceLoader autoConfigurations = ServiceLoader .load(RepositorySystemSessionAutoConfiguration.class); - for (RepositorySystemSessionAutoConfiguration autoConfiguration : autoConfigurations) { autoConfiguration.apply(repositorySystemSession, repositorySystem); } - new DefaultRepositorySystemSessionAutoConfiguration() .apply(repositorySystemSession, repositorySystem); - return new AetherGrapeEngine(classLoader, repositorySystem, repositorySystemSession, createRepositories(repositoryConfigurations), - dependencyResolutionContext); + dependencyResolutionContext, quiet); } private static ServiceLocator createServiceLocator() { diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java index 5803df1bfc..6920683a2a 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java @@ -81,6 +81,11 @@ public class GroovyGrabDependencyResolverTests { return new String[] { "." }; } + @Override + public boolean isQuiet() { + return false; + } + }; this.resolver = new GroovyGrabDependencyResolver(configuration); } diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java index 304e2b4273..036ed9b7eb 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java @@ -59,7 +59,7 @@ public class AetherGrapeEngineTests { dependencyResolutionContext.addDependencyManagement( new SpringBootDependenciesDependencyManagement()); return AetherGrapeEngineFactory.create(this.groovyClassLoader, - repositoryConfigurations, dependencyResolutionContext); + repositoryConfigurations, dependencyResolutionContext, false); } @Test