Fix counting error in SourceOptions

pull/234/head
Dave Syer 11 years ago
parent a5f16d46fe
commit 8ff2a88712

@ -16,10 +16,13 @@
package org.springframework.boot.cli.command; package org.springframework.boot.cli.command;
import groovy.lang.Binding;
import groovy.lang.GroovyClassLoader; import groovy.lang.GroovyClassLoader;
import groovy.lang.Script; import groovy.lang.Script;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.ServiceLoader; import java.util.ServiceLoader;
import joptsimple.OptionSet; import joptsimple.OptionSet;
@ -34,6 +37,7 @@ import org.springframework.boot.cli.compiler.GroovyCompilerConfigurationAdapter;
import org.springframework.boot.cli.compiler.GroovyCompilerScope; import org.springframework.boot.cli.compiler.GroovyCompilerScope;
import org.springframework.boot.cli.compiler.RepositoryConfigurationFactory; import org.springframework.boot.cli.compiler.RepositoryConfigurationFactory;
import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration; import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration;
import org.springframework.core.env.JOptCommandLinePropertySource;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
@ -116,10 +120,17 @@ public class InitCommand extends OptionParsingCommand {
for (Class<?> type : classes) { for (Class<?> type : classes) {
if (Script.class.isAssignableFrom(type)) { if (Script.class.isAssignableFrom(type)) {
Script script = (Script) type.newInstance(); Script script = (Script) type.newInstance();
JOptCommandLinePropertySource properties = new JOptCommandLinePropertySource(
options);
Map<String, Object> map = new HashMap<String, Object>();
for (String key : properties.getPropertyNames()) {
map.put(key, properties.getProperty(key));
}
script.setBinding(new Binding(map));
script.run(); script.run();
} }
enhanced = true;
} }
enhanced = true;
} }
if (enhanced) { if (enhanced) {

@ -61,6 +61,7 @@ public class SourceOptions {
String... defaultPaths) { String... defaultPaths) {
List<?> nonOptionArguments = optionSet.nonOptionArguments(); List<?> nonOptionArguments = optionSet.nonOptionArguments();
List<String> sources = new ArrayList<String>(); List<String> sources = new ArrayList<String>();
int sourceArgCount = 0;
for (Object option : nonOptionArguments) { for (Object option : nonOptionArguments) {
if (option instanceof String) { if (option instanceof String) {
String filename = (String) option; String filename = (String) option;
@ -73,14 +74,18 @@ public class SourceOptions {
sources.add(url); sources.add(url);
} }
} }
if ((filename.endsWith(".groovy") || filename.endsWith(".java")) if ((filename.endsWith(".groovy") || filename.endsWith(".java"))) {
&& urls.isEmpty()) { if (urls.isEmpty()) {
throw new IllegalArgumentException("Can't find " + filename); throw new IllegalArgumentException("Can't find " + filename);
}
else {
sourceArgCount++;
}
} }
} }
} }
this.args = Collections.unmodifiableList(nonOptionArguments.subList( this.args = Collections.unmodifiableList(nonOptionArguments.subList(
sources.size(), nonOptionArguments.size())); sourceArgCount, nonOptionArguments.size()));
if (sources.size() == 0) { if (sources.size() == 0) {
if (defaultPaths.length == 0) { if (defaultPaths.length == 0) {
throw new IllegalArgumentException( throw new IllegalArgumentException(

Loading…
Cancel
Save