SHL-66 - Plugins should have access to command line options

This commit is contained in:
mpollack
2012-12-20 05:41:45 +08:00
parent bab23f22d6
commit 730e33d6ff
8 changed files with 203 additions and 55 deletions

View File

@@ -0,0 +1,24 @@
package org.springframework.shell.commands.test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.shell.CommandLine;
import org.springframework.shell.core.CommandMarker;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.stereotype.Component;
@Component
public class OptionsInjectedDummyCommand implements CommandMarker {
@Autowired
private CommandLine commandLine;
@CliCommand("do nothing")
public String simple() {
return "foo";
}
public CommandLine getCommandLine() {
return commandLine;
}
}

View File

@@ -0,0 +1,45 @@
/*
* Copyright 2011-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell.core;
import java.io.IOException;
import java.util.logging.Logger;
import junit.framework.Assert;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.shell.Bootstrap;
import org.springframework.shell.commands.test.OptionsInjectedDummyCommand;
import org.springframework.shell.support.logging.HandlerUtils;
public class CommandLineInjectedTest {
@Test
public void commandLineInjected() throws IOException {
try {
Bootstrap bootstrap = new Bootstrap(null);
AnnotationConfigApplicationContext ctx = bootstrap.getParentApplicationContext();
OptionsInjectedDummyCommand dummyCommand = ctx.getBean(OptionsInjectedDummyCommand.class);
Assert.assertNotNull("commandLine was not injected into a command", dummyCommand.getCommandLine());
} catch (RuntimeException t) {
throw t;
} finally {
HandlerUtils.flushAllHandlers(Logger.getLogger(""));
}
}
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:component-scan base-package="org.springframework.shell.commands.test"/>
</beans>