Add spring war command
Add a `war` command to the CLI to generate WAR archives. Fixes gh-925 Closes gh-4168
This commit is contained in:
committed by
Phillip Webb
parent
b1aebe6075
commit
9a63e574b6
@@ -44,7 +44,7 @@ public class CommandLineIT {
|
||||
assertThat(cli.await(), equalTo(0));
|
||||
assertThat("Unexpected error: \n" + cli.getErrorOutput(),
|
||||
cli.getErrorOutput().length(), equalTo(0));
|
||||
assertThat(cli.getStandardOutputLines().size(), equalTo(10));
|
||||
assertThat(cli.getStandardOutputLines().size(), equalTo(11));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.boot.cli;
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.cli.command.jar.JarCommand;
|
||||
import org.springframework.boot.cli.command.archive.JarCommand;
|
||||
import org.springframework.boot.cli.infrastructure.CommandLineInvoker;
|
||||
import org.springframework.boot.cli.infrastructure.CommandLineInvoker.Invocation;
|
||||
import org.springframework.boot.loader.tools.JavaExecutable;
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.junit.Test;
|
||||
import org.springframework.boot.cli.command.archive.WarCommand;
|
||||
import org.springframework.boot.cli.infrastructure.CommandLineInvoker;
|
||||
import org.springframework.boot.cli.infrastructure.CommandLineInvoker.Invocation;
|
||||
import org.springframework.boot.loader.tools.JavaExecutable;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Integration test for {@link WarCommand}.
|
||||
*
|
||||
* @author Andrey Stolyarov
|
||||
*/
|
||||
public class WarCommandIT {
|
||||
|
||||
private final CommandLineInvoker cli = new CommandLineInvoker(
|
||||
new File("src/it/resources/war-command"));
|
||||
|
||||
@Test
|
||||
public void warCreation() throws Exception {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
File war = new File("target/test-app.war");
|
||||
Invocation invocation = this.cli.invoke("war", war.getAbsolutePath(),
|
||||
"war.groovy");
|
||||
invocation.await();
|
||||
assertTrue(war.exists());
|
||||
Process process = new JavaExecutable()
|
||||
.processBuilder("-jar", war.getAbsolutePath(), "--server.port=" + port)
|
||||
.start();
|
||||
invocation = new Invocation(process);
|
||||
invocation.await();
|
||||
assertThat(invocation.getErrorOutput(), containsString("onStart error"));
|
||||
assertThat(invocation.getStandardOutput(), containsString("Tomcat started"));
|
||||
assertThat(invocation.getStandardOutput(),
|
||||
containsString("/WEB-INF/lib-provided/tomcat-embed-core"));
|
||||
assertThat(invocation.getStandardOutput(),
|
||||
containsString("/WEB-INF/lib-provided/tomcat-embed-core"));
|
||||
process.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
16
spring-boot-cli/src/it/resources/war-command/war.groovy
Normal file
16
spring-boot-cli/src/it/resources/war-command/war.groovy
Normal file
@@ -0,0 +1,16 @@
|
||||
package org.test
|
||||
|
||||
@RestController
|
||||
class WarExample implements CommandLineRunner {
|
||||
|
||||
@RequestMapping("/")
|
||||
public String hello() {
|
||||
return "Hello"
|
||||
}
|
||||
|
||||
void run(String... args) {
|
||||
println getClass().getResource('/org/apache/tomcat/InstanceManager.class')
|
||||
throw new RuntimeException("onStart error")
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user