Speed up grab command test
The autoconfiguration transformations (and loads of grabs of spring-boot snapshots) were making the grab command tests run really slowly. Snapshots are particularly bad. Fixed by adding a --autoconfigure=false option to the compiler configuration and using it in that test.
This commit is contained in:
@@ -25,6 +25,7 @@ import static java.util.Arrays.asList;
|
||||
* Groovy scripts
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class CompilerOptionHandler extends OptionHandler {
|
||||
|
||||
@@ -32,6 +33,8 @@ public class CompilerOptionHandler extends OptionHandler {
|
||||
|
||||
private OptionSpec<Void> noGuessDependenciesOption;
|
||||
|
||||
private OptionSpec<Boolean> autoconfigureOption;
|
||||
|
||||
private OptionSpec<String> classpathOption;
|
||||
|
||||
@Override
|
||||
@@ -40,6 +43,9 @@ public class CompilerOptionHandler extends OptionHandler {
|
||||
"Do not attempt to guess imports");
|
||||
this.noGuessDependenciesOption = option("no-guess-dependencies",
|
||||
"Do not attempt to guess dependencies");
|
||||
this.autoconfigureOption = option("autoconfigure",
|
||||
"Add autoconfigure compiler transformations").withOptionalArg()
|
||||
.ofType(Boolean.class).defaultsTo(true);
|
||||
this.classpathOption = option(asList("classpath", "cp"),
|
||||
"Additional classpath entries").withRequiredArg();
|
||||
doOptions();
|
||||
@@ -60,4 +66,8 @@ public class CompilerOptionHandler extends OptionHandler {
|
||||
return this.classpathOption;
|
||||
}
|
||||
|
||||
public OptionSpec<Boolean> getAutoconfigureOption() {
|
||||
return this.autoconfigureOption;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,8 +49,6 @@ public class GrabCommand extends OptionParsingCommand {
|
||||
|
||||
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
|
||||
.createDefaultRepositoryConfiguration();
|
||||
repositoryConfiguration.add(0, new RepositoryConfiguration("local", new File(
|
||||
getM2HomeDirectory(), "repository").toURI(), true));
|
||||
|
||||
GroovyCompilerConfiguration configuration = new GroovyCompilerConfigurationAdapter(
|
||||
options, this, repositoryConfiguration);
|
||||
@@ -59,16 +57,33 @@ public class GrabCommand extends OptionParsingCommand {
|
||||
System.setProperty("grape.root", ".");
|
||||
}
|
||||
|
||||
if (!new File(System.getProperty("grape.root")).equals(getM2HomeDirectory())) {
|
||||
GrabCommand.addDefaultCacheAsRespository(repositoryConfiguration);
|
||||
}
|
||||
GroovyCompiler groovyCompiler = new GroovyCompiler(configuration);
|
||||
groovyCompiler.compile(fileOptions.getFilesArray());
|
||||
}
|
||||
|
||||
private File getM2HomeDirectory() {
|
||||
String mavenRoot = System.getProperty("maven.home");
|
||||
if (StringUtils.hasLength(mavenRoot)) {
|
||||
return new File(mavenRoot);
|
||||
}
|
||||
return new File(System.getProperty("user.home"), ".m2");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the default local M2 cache directory as a remote repository. Only do this if
|
||||
* the local cache location has been changed from the default.
|
||||
*
|
||||
* @param repositoryConfiguration
|
||||
*/
|
||||
public static void addDefaultCacheAsRespository(
|
||||
List<RepositoryConfiguration> repositoryConfiguration) {
|
||||
repositoryConfiguration.add(0, new RepositoryConfiguration("local", new File(
|
||||
getM2HomeDirectory(), "repository").toURI(), true));
|
||||
}
|
||||
|
||||
private static File getM2HomeDirectory() {
|
||||
String mavenRoot = System.getProperty("maven.home");
|
||||
if (StringUtils.hasLength(mavenRoot)) {
|
||||
return new File(mavenRoot);
|
||||
}
|
||||
return new File(System.getProperty("user.home"), ".m2");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.boot.cli.command;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@@ -89,8 +88,6 @@ public class RunCommand extends OptionParsingCommand {
|
||||
|
||||
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
|
||||
.createDefaultRepositoryConfiguration();
|
||||
repositoryConfiguration.add(0, new RepositoryConfiguration("local", new File(
|
||||
"repository").toURI(), true));
|
||||
|
||||
SpringApplicationRunnerConfiguration configuration = new SpringApplicationRunnerConfigurationAdapter(
|
||||
options, this, repositoryConfiguration);
|
||||
|
||||
@@ -264,6 +264,11 @@ public class ScriptCommand implements Command {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutoconfigure() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGuessDependencies() {
|
||||
return true;
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
@@ -77,7 +78,7 @@ public class GroovyCompiler {
|
||||
|
||||
private final ExtendedGroovyClassLoader loader;
|
||||
|
||||
private final ServiceLoader<CompilerAutoConfiguration> compilerAutoConfigurations;
|
||||
private final Iterable<CompilerAutoConfiguration> compilerAutoConfigurations;
|
||||
|
||||
private final List<ASTTransformation> transformations;
|
||||
|
||||
@@ -96,8 +97,14 @@ public class GroovyCompiler {
|
||||
|
||||
this.loader.getConfiguration().addCompilationCustomizers(
|
||||
new CompilerAutoConfigureCustomizer());
|
||||
this.compilerAutoConfigurations = ServiceLoader.load(
|
||||
CompilerAutoConfiguration.class, GroovyCompiler.class.getClassLoader());
|
||||
if (configuration.isAutoconfigure()) {
|
||||
this.compilerAutoConfigurations = ServiceLoader.load(
|
||||
CompilerAutoConfiguration.class,
|
||||
GroovyCompiler.class.getClassLoader());
|
||||
}
|
||||
else {
|
||||
this.compilerAutoConfigurations = Collections.emptySet();
|
||||
}
|
||||
|
||||
this.transformations = new ArrayList<ASTTransformation>();
|
||||
this.transformations.add(new GrabResolversAutoConfigurationTransformation());
|
||||
|
||||
@@ -48,6 +48,11 @@ public interface GroovyCompilerConfiguration {
|
||||
*/
|
||||
boolean isGuessDependencies();
|
||||
|
||||
/**
|
||||
* Returns true if autoconfiguration transformations should be applied.
|
||||
*/
|
||||
boolean isAutoconfigure();
|
||||
|
||||
/**
|
||||
* @return a path for local resources
|
||||
*/
|
||||
|
||||
@@ -71,6 +71,11 @@ public class GroovyCompilerConfigurationAdapter implements GroovyCompilerConfigu
|
||||
return !this.options.has(this.optionHandler.getNoGuessDependenciesOption());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutoconfigure() {
|
||||
return this.optionHandler.getAutoconfigureOption().value(this.options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getClasspath() {
|
||||
OptionSpec<String> classpathOption = this.optionHandler.getClasspathOption();
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration;
|
||||
|
||||
/**
|
||||
* @author Andy Wilkinson
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public final class RepositoryConfigurationFactory {
|
||||
|
||||
@@ -51,4 +52,5 @@ public final class RepositoryConfigurationFactory {
|
||||
|
||||
return repositoryConfiguration;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user