From 8ff2a88712fff82d24ccbf44a9d52ea95b99f7bb Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 14 Jan 2014 14:44:12 +0000 Subject: [PATCH] Fix counting error in SourceOptions --- .../boot/cli/command/InitCommand.java | 13 ++++++++++++- .../boot/cli/command/SourceOptions.java | 13 +++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/InitCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/InitCommand.java index 1a14bb3b949..0252a38c2c6 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/InitCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/InitCommand.java @@ -16,10 +16,13 @@ package org.springframework.boot.cli.command; +import groovy.lang.Binding; import groovy.lang.GroovyClassLoader; import groovy.lang.Script; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.ServiceLoader; 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.RepositoryConfigurationFactory; import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration; +import org.springframework.core.env.JOptCommandLinePropertySource; import org.springframework.util.StringUtils; /** @@ -116,10 +120,17 @@ public class InitCommand extends OptionParsingCommand { for (Class type : classes) { if (Script.class.isAssignableFrom(type)) { Script script = (Script) type.newInstance(); + JOptCommandLinePropertySource properties = new JOptCommandLinePropertySource( + options); + Map map = new HashMap(); + for (String key : properties.getPropertyNames()) { + map.put(key, properties.getProperty(key)); + } + script.setBinding(new Binding(map)); script.run(); } + enhanced = true; } - enhanced = true; } if (enhanced) { diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/SourceOptions.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/SourceOptions.java index 5f4b218fc74..ed773c2ff7d 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/SourceOptions.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/SourceOptions.java @@ -61,6 +61,7 @@ public class SourceOptions { String... defaultPaths) { List nonOptionArguments = optionSet.nonOptionArguments(); List sources = new ArrayList(); + int sourceArgCount = 0; for (Object option : nonOptionArguments) { if (option instanceof String) { String filename = (String) option; @@ -73,14 +74,18 @@ public class SourceOptions { sources.add(url); } } - if ((filename.endsWith(".groovy") || filename.endsWith(".java")) - && urls.isEmpty()) { - throw new IllegalArgumentException("Can't find " + filename); + if ((filename.endsWith(".groovy") || filename.endsWith(".java"))) { + if (urls.isEmpty()) { + throw new IllegalArgumentException("Can't find " + filename); + } + else { + sourceArgCount++; + } } } } this.args = Collections.unmodifiableList(nonOptionArguments.subList( - sources.size(), nonOptionArguments.size())); + sourceArgCount, nonOptionArguments.size())); if (sources.size() == 0) { if (defaultPaths.length == 0) { throw new IllegalArgumentException(