Minimize and centralize assumptions about build output
Closes gh-15471
This commit is contained in:
@@ -18,7 +18,9 @@ package org.springframework.boot.cli;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.boot.cli.infrastructure.CommandLineInvoker;
|
||||
import org.springframework.boot.cli.infrastructure.CommandLineInvoker.Invocation;
|
||||
@@ -36,7 +38,10 @@ import static org.junit.Assert.assertThat;
|
||||
*/
|
||||
public class CommandLineIT {
|
||||
|
||||
private final CommandLineInvoker cli = new CommandLineInvoker();
|
||||
@Rule
|
||||
public final TemporaryFolder temp = new TemporaryFolder();
|
||||
|
||||
private final CommandLineInvoker cli = new CommandLineInvoker(this.temp);
|
||||
|
||||
@Test
|
||||
public void hintProducesListOfValidCommands()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
@@ -18,7 +18,9 @@ package org.springframework.boot.cli;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.boot.cli.command.archive.JarCommand;
|
||||
import org.springframework.boot.cli.infrastructure.CommandLineInvoker;
|
||||
@@ -43,8 +45,11 @@ public class JarCommandIT {
|
||||
private static final boolean JAVA_9_OR_LATER = isClassPresent(
|
||||
"java.security.cert.URICertStoreParameters");
|
||||
|
||||
@Rule
|
||||
public final TemporaryFolder temp = new TemporaryFolder();
|
||||
|
||||
private final CommandLineInvoker cli = new CommandLineInvoker(
|
||||
new File("src/it/resources/jar-command"));
|
||||
new File("src/it/resources/jar-command"), this.temp);
|
||||
|
||||
@Test
|
||||
public void noArguments() throws Exception {
|
||||
@@ -66,7 +71,7 @@ public class JarCommandIT {
|
||||
|
||||
@Test
|
||||
public void jarCreationWithGrabResolver() throws Exception {
|
||||
File jar = new File("target/test-app.jar");
|
||||
File jar = new File(this.temp.getRoot(), "test-app.jar");
|
||||
Invocation invocation = this.cli.invoke("run", jar.getAbsolutePath(),
|
||||
"bad.groovy");
|
||||
invocation.await();
|
||||
@@ -93,7 +98,7 @@ public class JarCommandIT {
|
||||
|
||||
@Test
|
||||
public void jarCreation() throws Exception {
|
||||
File jar = new File("target/test-app.jar");
|
||||
File jar = new File(this.temp.getRoot(), "test-app.jar");
|
||||
Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(),
|
||||
"jar.groovy");
|
||||
invocation.await();
|
||||
@@ -127,7 +132,7 @@ public class JarCommandIT {
|
||||
|
||||
@Test
|
||||
public void jarCreationWithIncludes() throws Exception {
|
||||
File jar = new File("target/test-app.jar");
|
||||
File jar = new File(this.temp.getRoot(), "test-app.jar");
|
||||
Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(), "--include",
|
||||
"-public/**,-resources/**", "jar.groovy");
|
||||
invocation.await();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
@@ -18,7 +18,9 @@ package org.springframework.boot.cli;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.boot.cli.command.archive.WarCommand;
|
||||
import org.springframework.boot.cli.infrastructure.CommandLineInvoker;
|
||||
@@ -35,12 +37,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class WarCommandIT {
|
||||
|
||||
@Rule
|
||||
public final TemporaryFolder temp = new TemporaryFolder();
|
||||
|
||||
private final CommandLineInvoker cli = new CommandLineInvoker(
|
||||
new File("src/it/resources/war-command"));
|
||||
new File("src/it/resources/war-command"), this.temp);
|
||||
|
||||
@Test
|
||||
public void warCreation() throws Exception {
|
||||
File war = new File("target/test-app.war");
|
||||
File war = new File(this.temp.getRoot(), "test-app.war");
|
||||
Invocation invocation = this.cli.invoke("war", war.getAbsolutePath(),
|
||||
"war.groovy");
|
||||
invocation.await();
|
||||
|
||||
@@ -32,6 +32,9 @@ import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.boot.testsupport.BuildOutput;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
@@ -46,12 +49,15 @@ public final class CommandLineInvoker {
|
||||
|
||||
private final File workingDirectory;
|
||||
|
||||
public CommandLineInvoker() {
|
||||
this(new File("."));
|
||||
private final TemporaryFolder temp;
|
||||
|
||||
public CommandLineInvoker(TemporaryFolder temp) {
|
||||
this(new File("."), temp);
|
||||
}
|
||||
|
||||
public CommandLineInvoker(File workingDirectory) {
|
||||
public CommandLineInvoker(File workingDirectory, TemporaryFolder temp) {
|
||||
this.workingDirectory = workingDirectory;
|
||||
this.temp = temp;
|
||||
}
|
||||
|
||||
public Invocation invoke(String... args) throws IOException {
|
||||
@@ -69,9 +75,9 @@ public final class CommandLineInvoker {
|
||||
}
|
||||
|
||||
private File findLaunchScript() throws IOException {
|
||||
File unpacked = new File("target/unpacked-cli");
|
||||
File unpacked = new File(this.temp.getRoot(), "unpacked-cli");
|
||||
if (!unpacked.isDirectory()) {
|
||||
File zip = new File("target")
|
||||
File zip = new BuildOutput(getClass()).getRootLocation()
|
||||
.listFiles((pathname) -> pathname.getName().endsWith("-bin.zip"))[0];
|
||||
try (ZipInputStream input = new ZipInputStream(new FileInputStream(zip))) {
|
||||
ZipEntry entry;
|
||||
|
||||
Reference in New Issue
Block a user