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:
parent
fce48c00c7
commit
89332e230e
|
@ -25,6 +25,7 @@ import static java.util.Arrays.asList;
|
||||||
* Groovy scripts
|
* Groovy scripts
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class CompilerOptionHandler extends OptionHandler {
|
public class CompilerOptionHandler extends OptionHandler {
|
||||||
|
|
||||||
|
@ -32,6 +33,8 @@ public class CompilerOptionHandler extends OptionHandler {
|
||||||
|
|
||||||
private OptionSpec<Void> noGuessDependenciesOption;
|
private OptionSpec<Void> noGuessDependenciesOption;
|
||||||
|
|
||||||
|
private OptionSpec<Boolean> autoconfigureOption;
|
||||||
|
|
||||||
private OptionSpec<String> classpathOption;
|
private OptionSpec<String> classpathOption;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,6 +43,9 @@ public class CompilerOptionHandler extends OptionHandler {
|
||||||
"Do not attempt to guess imports");
|
"Do not attempt to guess imports");
|
||||||
this.noGuessDependenciesOption = option("no-guess-dependencies",
|
this.noGuessDependenciesOption = option("no-guess-dependencies",
|
||||||
"Do not attempt to 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"),
|
this.classpathOption = option(asList("classpath", "cp"),
|
||||||
"Additional classpath entries").withRequiredArg();
|
"Additional classpath entries").withRequiredArg();
|
||||||
doOptions();
|
doOptions();
|
||||||
|
@ -60,4 +66,8 @@ public class CompilerOptionHandler extends OptionHandler {
|
||||||
return this.classpathOption;
|
return this.classpathOption;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OptionSpec<Boolean> getAutoconfigureOption() {
|
||||||
|
return this.autoconfigureOption;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,6 @@ public class GrabCommand extends OptionParsingCommand {
|
||||||
|
|
||||||
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
|
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
|
||||||
.createDefaultRepositoryConfiguration();
|
.createDefaultRepositoryConfiguration();
|
||||||
repositoryConfiguration.add(0, new RepositoryConfiguration("local", new File(
|
|
||||||
getM2HomeDirectory(), "repository").toURI(), true));
|
|
||||||
|
|
||||||
GroovyCompilerConfiguration configuration = new GroovyCompilerConfigurationAdapter(
|
GroovyCompilerConfiguration configuration = new GroovyCompilerConfigurationAdapter(
|
||||||
options, this, repositoryConfiguration);
|
options, this, repositoryConfiguration);
|
||||||
|
@ -59,16 +57,33 @@ public class GrabCommand extends OptionParsingCommand {
|
||||||
System.setProperty("grape.root", ".");
|
System.setProperty("grape.root", ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!new File(System.getProperty("grape.root")).equals(getM2HomeDirectory())) {
|
||||||
|
GrabCommand.addDefaultCacheAsRespository(repositoryConfiguration);
|
||||||
|
}
|
||||||
GroovyCompiler groovyCompiler = new GroovyCompiler(configuration);
|
GroovyCompiler groovyCompiler = new GroovyCompiler(configuration);
|
||||||
groovyCompiler.compile(fileOptions.getFilesArray());
|
groovyCompiler.compile(fileOptions.getFilesArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getM2HomeDirectory() {
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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");
|
String mavenRoot = System.getProperty("maven.home");
|
||||||
if (StringUtils.hasLength(mavenRoot)) {
|
if (StringUtils.hasLength(mavenRoot)) {
|
||||||
return new File(mavenRoot);
|
return new File(mavenRoot);
|
||||||
}
|
}
|
||||||
return new File(System.getProperty("user.home"), ".m2");
|
return new File(System.getProperty("user.home"), ".m2");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.boot.cli.command;
|
package org.springframework.boot.cli.command;
|
||||||
|
|
||||||
import java.awt.Desktop;
|
import java.awt.Desktop;
|
||||||
import java.io.File;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
@ -89,8 +88,6 @@ public class RunCommand extends OptionParsingCommand {
|
||||||
|
|
||||||
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
|
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
|
||||||
.createDefaultRepositoryConfiguration();
|
.createDefaultRepositoryConfiguration();
|
||||||
repositoryConfiguration.add(0, new RepositoryConfiguration("local", new File(
|
|
||||||
"repository").toURI(), true));
|
|
||||||
|
|
||||||
SpringApplicationRunnerConfiguration configuration = new SpringApplicationRunnerConfigurationAdapter(
|
SpringApplicationRunnerConfiguration configuration = new SpringApplicationRunnerConfigurationAdapter(
|
||||||
options, this, repositoryConfiguration);
|
options, this, repositoryConfiguration);
|
||||||
|
|
|
@ -264,6 +264,11 @@ public class ScriptCommand implements Command {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAutoconfigure() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isGuessDependencies() {
|
public boolean isGuessDependencies() {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
|
@ -77,7 +78,7 @@ public class GroovyCompiler {
|
||||||
|
|
||||||
private final ExtendedGroovyClassLoader loader;
|
private final ExtendedGroovyClassLoader loader;
|
||||||
|
|
||||||
private final ServiceLoader<CompilerAutoConfiguration> compilerAutoConfigurations;
|
private final Iterable<CompilerAutoConfiguration> compilerAutoConfigurations;
|
||||||
|
|
||||||
private final List<ASTTransformation> transformations;
|
private final List<ASTTransformation> transformations;
|
||||||
|
|
||||||
|
@ -96,8 +97,14 @@ public class GroovyCompiler {
|
||||||
|
|
||||||
this.loader.getConfiguration().addCompilationCustomizers(
|
this.loader.getConfiguration().addCompilationCustomizers(
|
||||||
new CompilerAutoConfigureCustomizer());
|
new CompilerAutoConfigureCustomizer());
|
||||||
|
if (configuration.isAutoconfigure()) {
|
||||||
this.compilerAutoConfigurations = ServiceLoader.load(
|
this.compilerAutoConfigurations = ServiceLoader.load(
|
||||||
CompilerAutoConfiguration.class, GroovyCompiler.class.getClassLoader());
|
CompilerAutoConfiguration.class,
|
||||||
|
GroovyCompiler.class.getClassLoader());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.compilerAutoConfigurations = Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
this.transformations = new ArrayList<ASTTransformation>();
|
this.transformations = new ArrayList<ASTTransformation>();
|
||||||
this.transformations.add(new GrabResolversAutoConfigurationTransformation());
|
this.transformations.add(new GrabResolversAutoConfigurationTransformation());
|
||||||
|
|
|
@ -48,6 +48,11 @@ public interface GroovyCompilerConfiguration {
|
||||||
*/
|
*/
|
||||||
boolean isGuessDependencies();
|
boolean isGuessDependencies();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if autoconfiguration transformations should be applied.
|
||||||
|
*/
|
||||||
|
boolean isAutoconfigure();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a path for local resources
|
* @return a path for local resources
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -71,6 +71,11 @@ public class GroovyCompilerConfigurationAdapter implements GroovyCompilerConfigu
|
||||||
return !this.options.has(this.optionHandler.getNoGuessDependenciesOption());
|
return !this.options.has(this.optionHandler.getNoGuessDependenciesOption());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAutoconfigure() {
|
||||||
|
return this.optionHandler.getAutoconfigureOption().value(this.options);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getClasspath() {
|
public String[] getClasspath() {
|
||||||
OptionSpec<String> classpathOption = this.optionHandler.getClasspathOption();
|
OptionSpec<String> classpathOption = this.optionHandler.getClasspathOption();
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public final class RepositoryConfigurationFactory {
|
public final class RepositoryConfigurationFactory {
|
||||||
|
|
||||||
|
@ -51,4 +52,5 @@ public final class RepositoryConfigurationFactory {
|
||||||
|
|
||||||
return repositoryConfiguration;
|
return repositoryConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,8 +98,13 @@ public class CliTester implements TestRule {
|
||||||
final String[] sources = new String[args.length];
|
final String[] sources = new String[args.length];
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
String arg = args[i];
|
String arg = args[i];
|
||||||
|
if (arg.startsWith("--")) {
|
||||||
|
sources[i] = arg;
|
||||||
|
}
|
||||||
|
else {
|
||||||
sources[i] = this.prefix + arg;
|
sources[i] = this.prefix + arg;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return sources;
|
return sources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
* Integration tests for {@link GrabCommand}
|
* Integration tests for {@link GrabCommand}
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class GrabCommandIntegrationTests {
|
public class GrabCommandIntegrationTests {
|
||||||
|
|
||||||
|
@ -41,22 +42,21 @@ public class GrabCommandIntegrationTests {
|
||||||
@After
|
@After
|
||||||
public void deleteLocalRepository() {
|
public void deleteLocalRepository() {
|
||||||
FileSystemUtils.deleteRecursively(new File("target/repository"));
|
FileSystemUtils.deleteRecursively(new File("target/repository"));
|
||||||
|
System.clearProperty("grape.root");
|
||||||
|
System.clearProperty("groovy.grape.report.downloads");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void grab() throws Exception {
|
public void grab() throws Exception {
|
||||||
|
|
||||||
System.setProperty("grape.root", "target");
|
System.setProperty("grape.root", "target");
|
||||||
System.setProperty("groovy.grape.report.downloads", "true");
|
System.setProperty("groovy.grape.report.downloads", "true");
|
||||||
|
|
||||||
try {
|
// Use --autoconfigure=false to limit the amount of downloaded dependencies
|
||||||
String output = this.cli.grab("grab.groovy");
|
String output = this.cli.grab("grab.groovy", "--autoconfigure=false");
|
||||||
assertTrue(output.contains("Downloading: file:"));
|
assertTrue(output.contains("Downloading: file:"));
|
||||||
assertTrue(new File("target/repository/org/springframework/spring-jdbc")
|
assertTrue(new File("target/repository/net/sf/jopt-simple/jopt-simple")
|
||||||
.isDirectory());
|
.isDirectory());
|
||||||
}
|
|
||||||
finally {
|
|
||||||
System.clearProperty("grape.root");
|
|
||||||
System.clearProperty("groovy.grape.report.downloads");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
@Grab('spring-jdbc')
|
@Grab('jopt-simple')
|
||||||
class GrabTest {
|
class GrabTest {
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue