Change package names zero->boot

* actuator -> boot-ops
* cli -> boot-cli
* launcher -> boot-load
* autoconfig -> boot-config
* bootstrap -> boot-strap
* starters -> boot-up

[#54095231] [bs-253] Refactor Zero->Boot
This commit is contained in:
Dave Syer
2013-07-26 11:50:02 +01:00
parent b2873fbc2d
commit 2098e23fca
609 changed files with 1686 additions and 1626 deletions

View File

@@ -0,0 +1,55 @@
/*
* Copyright 2012-2013 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.boot.cli;
import java.io.File;
import org.springframework.boot.cli.command.CleanCommand;
/**
* @author Dave Syer
*/
public class GrapesCleaner {
// FIXME get the version
private static final String VERSION = "0.5.0.BUILD-SNAPSHOT";
public static void cleanIfNecessary() throws Exception {
File installedJar = new File(getMavenRepository(), String.format(
"org/springframework/boot/spring-boot-strap/%s/spring-boot-strap-%s.jar",
VERSION, VERSION));
File grapesJar = new File(
getGrapesCache(),
String.format(
"org.springframework.boot/spring-boot-strap/jars/spring-boot-strap-%s.jar",
VERSION));
if (!VERSION.contains("SNAPSHOT") || installedJar.exists() && grapesJar.exists()
&& installedJar.lastModified() <= grapesJar.lastModified()) {
return;
}
new CleanCommand().run();
}
private static File getMavenRepository() {
return new File(System.getProperty("user.home"), ".m2/repository");
}
private static File getGrapesCache() {
return new File(System.getProperty("user.home"), ".groovy/grapes");
}
}

View File

@@ -0,0 +1,184 @@
/*
* Copyright 2012-2013 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.boot.cli;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.net.URL;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.apache.ivy.util.FileUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.boot.cli.command.RunCommand;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Integration tests to exercise the samples.
*
* @author Dave Syer
*/
public class SampleIntegrationTests {
@BeforeClass
public static void cleanGrapes() throws Exception {
GrapesCleaner.cleanIfNecessary();
// System.setProperty("ivy.message.logger.level", "3");
}
private RunCommand command;
private PrintStream savedOutput;
private ByteArrayOutputStream output;
private PrintStream savedErr;
@Before
public void init() {
this.savedOutput = System.out;
this.savedErr = System.err;
this.output = new ByteArrayOutputStream();
System.setOut(new PrintStream(this.output));
System.setErr(new PrintStream(this.output));
}
@After
public void clear() {
System.setOut(this.savedOutput);
System.setErr(this.savedErr);
System.out.println(getOutput());
}
private String getOutput() {
return this.output.toString();
}
private void start(final String... sample) throws Exception {
Future<RunCommand> future = Executors.newSingleThreadExecutor().submit(
new Callable<RunCommand>() {
@Override
public RunCommand call() throws Exception {
RunCommand command = new RunCommand();
command.run(sample);
return command;
}
});
this.command = future.get(4, TimeUnit.MINUTES);
}
@After
public void stop() {
if (this.command != null) {
this.command.stop();
}
}
@Test
public void appSample() throws Exception {
start("samples/app.groovy");
String output = getOutput();
assertTrue("Wrong output: " + output, output.contains("Hello World"));
}
@Test
public void templateSample() throws Exception {
start("samples/template.groovy");
String output = getOutput();
assertTrue("Wrong output: " + output, output.contains("Hello World!"));
}
@Test
public void jobSample() throws Exception {
start("samples/job.groovy", "foo=bar");
String output = getOutput();
assertTrue("Wrong output: " + output,
output.contains("completed with the following parameters"));
}
@Test
public void reactorSample() throws Exception {
start("samples/reactor.groovy", "Phil");
String output = getOutput();
int count = 0;
while (!output.contains("Hello Phil") && count++ < 5) {
Thread.sleep(200);
output = getOutput();
}
assertTrue("Wrong output: " + output, output.contains("Hello Phil"));
}
@Test
public void jobWebSample() throws Exception {
start("samples/job.groovy", "samples/web.groovy", "foo=bar");
String output = getOutput();
assertTrue("Wrong output: " + output,
output.contains("completed with the following parameters"));
String result = FileUtil.readEntirely(new URL("http://localhost:8080")
.openStream());
assertEquals("World!", result);
}
@Test
public void webSample() throws Exception {
start("samples/web.groovy");
String result = FileUtil.readEntirely(new URL("http://localhost:8080")
.openStream());
assertEquals("World!", result);
}
@Test
public void uiSample() throws Exception {
start("samples/ui.groovy", "--classpath=.:src/test/resources");
String result = FileUtil.readEntirely(new URL("http://localhost:8080")
.openStream());
assertTrue("Wrong output: " + result, result.contains("Hello World"));
result = FileUtil.readEntirely(new URL(
"http://localhost:8080/css/bootstrap.min.css").openStream());
assertTrue("Wrong output: " + result, result.contains("container"));
}
@Test
public void opsSample() throws Exception {
start("samples/ops.groovy");
String result = FileUtil.readEntirely(new URL("http://localhost:8080")
.openStream());
assertEquals("{\"message\":\"Hello World!\"}", result);
}
@Test
public void integrationSample() throws Exception {
start("samples/integration.groovy");
String output = getOutput();
assertTrue("Wrong output: " + output, output.contains("Hello, World"));
}
@Test
public void xmlSample() throws Exception {
start("samples/app.xml", "samples/runner.groovy");
String output = getOutput();
assertTrue("Wrong output: " + output, output.contains("Hello World"));
}
}

View File

@@ -0,0 +1,164 @@
package org.springframework.boot.cli;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.Set;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.boot.cli.Command;
import org.springframework.boot.cli.NoSuchCommandException;
import org.springframework.boot.cli.SpringCli;
import org.springframework.boot.cli.SpringCli.NoArgumentsException;
import org.springframework.boot.cli.SpringCli.NoHelpCommandArgumentsException;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link SpringCli}.
*
* @author Phillip Webb
* @author Dave Syer
*/
public class SpringCliTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private SpringCli cli;
@Mock
private Command regularCommand;
private Set<Call> calls = EnumSet.noneOf(Call.class);
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
this.cli = new SpringCli() {
@Override
protected void showUsage() {
SpringCliTests.this.calls.add(Call.SHOW_USAGE);
super.showUsage();
};
@Override
protected void errorMessage(String message) {
SpringCliTests.this.calls.add(Call.ERROR_MESSAGE);
super.errorMessage(message);
}
@Override
protected void printStackTrace(Exception ex) {
SpringCliTests.this.calls.add(Call.PRINT_STACK_TRACE);
super.printStackTrace(ex);
}
};
given(this.regularCommand.getName()).willReturn("command");
given(this.regularCommand.getDescription()).willReturn("A regular command");
this.cli.setCommands(Arrays.asList(this.regularCommand));
}
@Test
public void runWithoutArguments() throws Exception {
this.thrown.expect(NoArgumentsException.class);
this.cli.run();
}
@Test
public void runCommand() throws Exception {
this.cli.run("command", "--arg1", "arg2");
verify(this.regularCommand).run("--arg1", "arg2");
}
@Test
public void missingCommand() throws Exception {
this.thrown.expect(NoSuchCommandException.class);
this.cli.run("missing");
}
@Test
public void handlesSuccess() throws Exception {
int status = this.cli.runAndHandleErrors("command");
assertThat(status, equalTo(0));
assertThat(this.calls, equalTo((Set<Call>) EnumSet.noneOf(Call.class)));
}
@Test
public void handlesNoArgumentsException() throws Exception {
int status = this.cli.runAndHandleErrors();
assertThat(status, equalTo(1));
assertThat(this.calls, equalTo((Set<Call>) EnumSet.of(Call.SHOW_USAGE)));
}
@Test
public void handlesNoSuchCommand() throws Exception {
int status = this.cli.runAndHandleErrors("missing");
assertThat(status, equalTo(1));
assertThat(this.calls, equalTo((Set<Call>) EnumSet.of(Call.ERROR_MESSAGE)));
}
@Test
public void handlesRegularException() throws Exception {
willThrow(new RuntimeException()).given(this.regularCommand).run();
int status = this.cli.runAndHandleErrors("command");
assertThat(status, equalTo(1));
assertThat(this.calls, equalTo((Set<Call>) EnumSet.of(Call.ERROR_MESSAGE)));
}
@Test
public void handlesExceptionWithDashD() throws Exception {
willThrow(new RuntimeException()).given(this.regularCommand).run();
int status = this.cli.runAndHandleErrors("command", "-d");
assertThat(status, equalTo(1));
assertThat(this.calls, equalTo((Set<Call>) EnumSet.of(Call.ERROR_MESSAGE,
Call.PRINT_STACK_TRACE)));
}
@Test
public void handlesExceptionWithDashDashDebug() throws Exception {
willThrow(new RuntimeException()).given(this.regularCommand).run();
int status = this.cli.runAndHandleErrors("command", "--debug");
assertThat(status, equalTo(1));
assertThat(this.calls, equalTo((Set<Call>) EnumSet.of(Call.ERROR_MESSAGE,
Call.PRINT_STACK_TRACE)));
}
@Test
public void exceptionMessages() throws Exception {
assertThat(new NoSuchCommandException("name").getMessage(),
equalTo(SpringCli.CLI_APP + ": 'name' is not a valid command. See '"
+ SpringCli.CLI_APP + " help'."));
}
@Test
public void help() throws Exception {
this.cli.run("help", "command");
verify(this.regularCommand).getHelp();
}
@Test
public void helpNoCommand() throws Exception {
this.thrown.expect(NoHelpCommandArgumentsException.class);
this.cli.run("help");
}
@Test
public void helpUnknownCommand() throws Exception {
this.thrown.expect(NoSuchCommandException.class);
this.cli.run("help", "missing");
}
private static enum Call {
SHOW_USAGE, ERROR_MESSAGE, PRINT_STACK_TRACE
}
}

View File

@@ -0,0 +1,131 @@
/*
* Copyright 2012-2013 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.boot.cli.command;
import groovy.lang.GroovyObjectSupport;
import groovy.lang.Script;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.boot.cli.GrapesCleaner;
import org.springframework.boot.cli.command.OptionHandler;
import org.springframework.boot.cli.command.ScriptCommand;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
/**
* Tests for {@link ScriptCommand}.
*
* @author Dave Syer
*/
public class ScriptCommandTests {
public static boolean executed = false;
@BeforeClass
public static void cleanGrapes() throws Exception {
GrapesCleaner.cleanIfNecessary();
}
@Test(expected = IllegalStateException.class)
public void testMissing() throws Exception {
ScriptCommand command = new ScriptCommand("missing");
command.run("World");
}
@Test
public void testScript() throws Exception {
ScriptCommand command = new ScriptCommand("script");
command.run("World");
assertEquals("World",
((String[]) ((Script) command.getMain()).getProperty("args"))[0]);
}
@Test
public void testLocateFile() throws Exception {
ScriptCommand command = new ScriptCommand(
"src/test/resources/commands/script.groovy");
command.setPaths(new String[] { "." });
command.run("World");
assertEquals("World",
((String[]) ((Script) command.getMain()).getProperty("args"))[0]);
}
@Test
public void testRunnable() throws Exception {
ScriptCommand command = new ScriptCommand("runnable");
command.run("World");
assertTrue(executed);
}
@Test
public void testClosure() throws Exception {
ScriptCommand command = new ScriptCommand("closure");
command.run("World");
assertTrue(executed);
}
@Test
public void testCommand() throws Exception {
ScriptCommand command = new ScriptCommand("command");
assertEquals("My script command", command.getUsageHelp());
command.run("World");
assertTrue(executed);
}
@Test
public void testDuplicateClassName() throws Exception {
ScriptCommand command1 = new ScriptCommand("handler");
ScriptCommand command2 = new ScriptCommand("command");
assertNotSame(command1.getMain().getClass(), command2.getMain().getClass());
assertEquals(command1.getMain().getClass().getName(), command2.getMain()
.getClass().getName());
}
@Test
public void testOptions() throws Exception {
ScriptCommand command = new ScriptCommand("handler");
String out = ((OptionHandler) command.getMain()).getHelp();
assertTrue("Wrong output: " + out, out.contains("--foo"));
command.run("World", "--foo");
assertTrue(executed);
}
@Test
public void testMixin() throws Exception {
ScriptCommand command = new ScriptCommand("mixin");
GroovyObjectSupport object = (GroovyObjectSupport) command.getMain();
String out = (String) object.getProperty("help");
assertTrue("Wrong output: " + out, out.contains("--foo"));
command.run("World", "--foo");
assertTrue(executed);
}
@Test
public void testMixinWithBlock() throws Exception {
ScriptCommand command = new ScriptCommand("test");
GroovyObjectSupport object = (GroovyObjectSupport) command.getMain();
String out = (String) object.getProperty("help");
System.err.println(out);
assertTrue("Wrong output: " + out, out.contains("--foo"));
command.run("World", "--foo", "--bar=2");
assertTrue(executed);
}
}