Commit b631c113 authored by Andy Wilkinson's avatar Andy Wilkinson

Update AetherGrapeEngine to honour --local

When running an application, --local can be used to collect the
application's dependencies in a local directory. Prior to
AetherGrapeEngine being introduced, using --local would result in the
dependencies being written to ./grapes. When AetherGrapeEngine was
introduced --local no longer had any effect.

This commit updates AetherGrapeEngine so that it honours --local,
writing its dependencies to ./repository. When --local is not specified
dependencies are written to ~/.m2/repository (the standard location
for the local Maven cache). As part of this change TestCommand has
been refactored so that it lazily initialises its GroovyCompiler. This
ensures that RunCommand has a chance to set the system property that
backs --local before AetherGrapeEngine is initialised and accesses the
property.

Fixes #99
parent e741557a
...@@ -141,8 +141,18 @@ public class AetherGrapeEngine implements GrapeEngine { ...@@ -141,8 +141,18 @@ public class AetherGrapeEngine implements GrapeEngine {
} }
}); });
LocalRepository localRepo = new LocalRepository(new File( String grapeRootProperty = System.getProperty("grape.root");
System.getProperty("user.home"), ".m2/repository")); File root;
if (grapeRootProperty != null && grapeRootProperty.trim().length() > 0) {
root = new File(grapeRootProperty);
}
else {
root = new File(System.getProperty("user.home"), ".m2");
}
LocalRepository localRepo = new LocalRepository(new File(root, "repository"));
repositorySystemSession.setLocalRepositoryManager(this.repositorySystem repositorySystemSession.setLocalRepositoryManager(this.repositorySystem
.newLocalRepositoryManager(repositorySystemSession, localRepo)); .newLocalRepositoryManager(repositorySystemSession, localRepo));
......
...@@ -76,7 +76,7 @@ public class RunCommand extends OptionParsingCommand { ...@@ -76,7 +76,7 @@ public class RunCommand extends OptionParsingCommand {
protected void options() { protected void options() {
this.watchOption = option("watch", "Watch the specified file for changes"); this.watchOption = option("watch", "Watch the specified file for changes");
this.localOption = option("local", this.localOption = option("local",
"Accumulate the dependencies in a local folder (./grapes)"); "Accumulate the dependencies in a local folder (./repository)");
this.editOption = option(asList("edit", "e"), this.editOption = option(asList("edit", "e"),
"Open the file with the default system editor"); "Open the file with the default system editor");
this.noGuessImportsOption = option("no-guess-imports", this.noGuessImportsOption = option("no-guess-imports",
......
...@@ -27,7 +27,6 @@ import java.util.ArrayList; ...@@ -27,7 +27,6 @@ import java.util.ArrayList;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.logging.Level;
import joptsimple.OptionSet; import joptsimple.OptionSet;
...@@ -46,11 +45,8 @@ import org.springframework.boot.cli.util.FileUtils; ...@@ -46,11 +45,8 @@ import org.springframework.boot.cli.util.FileUtils;
*/ */
public class TestCommand extends OptionParsingCommand { public class TestCommand extends OptionParsingCommand {
private TestOptionHandler testOptionHandler;
public TestCommand() { public TestCommand() {
super("test", "Test a groovy script", new TestOptionHandler()); super("test", "Test a groovy script", new TestOptionHandler());
this.testOptionHandler = (TestOptionHandler) this.getHandler();
} }
@Override @Override
...@@ -59,7 +55,7 @@ public class TestCommand extends OptionParsingCommand { ...@@ -59,7 +55,7 @@ public class TestCommand extends OptionParsingCommand {
} }
public TestResults getResults() { public TestResults getResults() {
return this.testOptionHandler.results; return ((TestOptionHandler) this.getHandler()).results;
} }
private static class TestGroovyCompilerConfiguration implements private static class TestGroovyCompilerConfiguration implements
...@@ -79,27 +75,17 @@ public class TestCommand extends OptionParsingCommand { ...@@ -79,27 +75,17 @@ public class TestCommand extends OptionParsingCommand {
public String getClasspath() { public String getClasspath() {
return ""; return "";
} }
public Level getLogLevel() {
return Level.INFO;
}
} }
private static class TestOptionHandler extends OptionHandler { private static class TestOptionHandler extends OptionHandler {
private final GroovyCompiler compiler;
private TestResults results; private TestResults results;
public TestOptionHandler() {
TestGroovyCompilerConfiguration configuration = new TestGroovyCompilerConfiguration();
this.compiler = new GroovyCompiler(configuration);
if (configuration.getLogLevel().intValue() <= Level.FINE.intValue()) {
System.setProperty("groovy.grape.report.downloads", "true");
}
}
@Override @Override
protected void run(OptionSet options) throws Exception { protected void run(OptionSet options) throws Exception {
TestGroovyCompilerConfiguration configuration = new TestGroovyCompilerConfiguration();
GroovyCompiler compiler = new GroovyCompiler(configuration);
FileOptions fileOptions = new FileOptions(options, getClass() FileOptions fileOptions = new FileOptions(options, getClass()
.getClassLoader()); .getClassLoader());
...@@ -114,13 +100,13 @@ public class TestCommand extends OptionParsingCommand { ...@@ -114,13 +100,13 @@ public class TestCommand extends OptionParsingCommand {
// Compile - Pass 1 - compile source code to see what test libraries were // Compile - Pass 1 - compile source code to see what test libraries were
// pulled in // pulled in
Object[] sources = this.compiler.sources(fileOptions.getFilesArray()); Object[] sources = compiler.sources(fileOptions.getFilesArray());
List<File> testerFiles = compileAndCollectTesterFiles(sources); List<File> testerFiles = compileAndCollectTesterFiles(sources);
// Compile - Pass 2 - add appropriate testers // Compile - Pass 2 - add appropriate testers
List<File> files = new ArrayList<File>(fileOptions.getFiles()); List<File> files = new ArrayList<File>(fileOptions.getFiles());
files.addAll(testerFiles); files.addAll(testerFiles);
sources = this.compiler.sources(files.toArray(new File[files.size()])); sources = compiler.sources(files.toArray(new File[files.size()]));
if (sources.length == 0) { if (sources.length == 0) {
throw new RuntimeException("No classes found in '" + files + "'"); throw new RuntimeException("No classes found in '" + files + "'");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment