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;
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Assume;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
@@ -42,6 +43,7 @@ import org.springframework.boot.cli.command.archive.JarCommand;
|
||||
import org.springframework.boot.cli.command.grab.GrabCommand;
|
||||
import org.springframework.boot.cli.command.run.RunCommand;
|
||||
import org.springframework.boot.test.rule.OutputCapture;
|
||||
import org.springframework.boot.testsupport.BuildOutput;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -54,6 +56,10 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class CliTester implements TestRule {
|
||||
|
||||
private final TemporaryFolder temp = new TemporaryFolder();
|
||||
|
||||
private final BuildOutput buildOutput = new BuildOutput(getClass());
|
||||
|
||||
private final OutputCapture outputCapture = new OutputCapture();
|
||||
|
||||
private long timeout = TimeUnit.MINUTES.toMillis(6);
|
||||
@@ -62,6 +68,8 @@ public class CliTester implements TestRule {
|
||||
|
||||
private final String prefix;
|
||||
|
||||
private File serverPortFile;
|
||||
|
||||
public CliTester(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
@@ -75,14 +83,15 @@ public class CliTester implements TestRule {
|
||||
boolean classpathUpdated = false;
|
||||
for (String arg : args) {
|
||||
if (arg.startsWith("--classpath=")) {
|
||||
arg = arg + ":" + new File("target/test-classes").getAbsolutePath();
|
||||
arg = arg + ":"
|
||||
+ this.buildOutput.getTestClassesLocation().getAbsolutePath();
|
||||
classpathUpdated = true;
|
||||
}
|
||||
updatedArgs.add(arg);
|
||||
}
|
||||
if (!classpathUpdated) {
|
||||
updatedArgs.add(
|
||||
"--classpath=.:" + new File("target/test-classes").getAbsolutePath());
|
||||
updatedArgs.add("--classpath=.:"
|
||||
+ this.buildOutput.getTestClassesLocation().getAbsolutePath());
|
||||
}
|
||||
Future<RunCommand> future = submitCommand(new RunCommand(),
|
||||
StringUtils.toStringArray(updatedArgs));
|
||||
@@ -111,8 +120,8 @@ public class CliTester implements TestRule {
|
||||
System.setProperty("server.port", "0");
|
||||
System.setProperty("spring.application.class.name",
|
||||
"org.springframework.boot.cli.CliTesterSpringApplication");
|
||||
System.setProperty("portfile",
|
||||
new File("target/server.port").getAbsolutePath());
|
||||
this.serverPortFile = new File(this.temp.newFolder(), "server.port");
|
||||
System.setProperty("portfile", this.serverPortFile.getAbsolutePath());
|
||||
try {
|
||||
command.run(sources);
|
||||
return command;
|
||||
@@ -168,8 +177,9 @@ public class CliTester implements TestRule {
|
||||
|
||||
@Override
|
||||
public Statement apply(Statement base, Description description) {
|
||||
final Statement statement = CliTester.this.outputCapture
|
||||
.apply(new RunLauncherStatement(base), description);
|
||||
final Statement statement = this.temp.apply(
|
||||
this.outputCapture.apply(new RunLauncherStatement(base), description),
|
||||
description);
|
||||
return new Statement() {
|
||||
|
||||
@Override
|
||||
@@ -180,6 +190,7 @@ public class CliTester implements TestRule {
|
||||
.contains("integration"));
|
||||
statement.evaluate();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -190,7 +201,7 @@ public class CliTester implements TestRule {
|
||||
public String getHttpOutput(String uri) {
|
||||
try {
|
||||
int port = Integer.parseInt(
|
||||
FileCopyUtils.copyToString(new FileReader("target/server.port")));
|
||||
FileCopyUtils.copyToString(new FileReader(this.serverPortFile)));
|
||||
InputStream stream = URI.create("http://localhost:" + port + uri).toURL()
|
||||
.openStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
|
||||
|
||||
@@ -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.
|
||||
@@ -22,6 +22,7 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.boot.cli.command.grab.GrabCommand;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
@@ -37,13 +38,15 @@ import static org.junit.Assert.fail;
|
||||
*/
|
||||
public class GrabCommandIntegrationTests {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temp = new TemporaryFolder();
|
||||
|
||||
@Rule
|
||||
public CliTester cli = new CliTester("src/test/resources/grab-samples/");
|
||||
|
||||
@Before
|
||||
@After
|
||||
public void deleteLocalRepository() {
|
||||
FileSystemUtils.deleteRecursively(new File("target/repository"));
|
||||
System.clearProperty("grape.root");
|
||||
System.clearProperty("groovy.grape.report.downloads");
|
||||
}
|
||||
@@ -51,13 +54,13 @@ public class GrabCommandIntegrationTests {
|
||||
@Test
|
||||
public void grab() throws Exception {
|
||||
|
||||
System.setProperty("grape.root", "target");
|
||||
System.setProperty("grape.root", this.temp.getRoot().getAbsolutePath());
|
||||
System.setProperty("groovy.grape.report.downloads", "true");
|
||||
|
||||
// Use --autoconfigure=false to limit the amount of downloaded dependencies
|
||||
String output = this.cli.grab("grab.groovy", "--autoconfigure=false");
|
||||
assertThat(new File("target/repository/joda-time/joda-time").isDirectory())
|
||||
.isTrue();
|
||||
assertThat(new File(this.temp.getRoot(), "repository/joda-time/joda-time"))
|
||||
.isDirectory();
|
||||
// Should be resolved from local repository cache
|
||||
assertThat(output.contains("Downloading: file:")).isTrue();
|
||||
}
|
||||
@@ -76,13 +79,12 @@ public class GrabCommandIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void customMetadata() throws Exception {
|
||||
System.setProperty("grape.root", "target");
|
||||
System.setProperty("grape.root", this.temp.getRoot().getAbsolutePath());
|
||||
File repository = new File(this.temp.getRoot().getAbsolutePath(), "repository");
|
||||
FileSystemUtils.copyRecursively(
|
||||
new File("src/test/resources/grab-samples/repository"),
|
||||
new File("target/repository"));
|
||||
new File("src/test/resources/grab-samples/repository"), repository);
|
||||
this.cli.grab("customDependencyManagement.groovy", "--autoconfigure=false");
|
||||
assertThat(new File("target/repository/javax/ejb/ejb-api/3.0").isDirectory())
|
||||
.isTrue();
|
||||
assertThat(new File(repository, "javax/ejb/ejb-api/3.0")).isDirectory();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -28,8 +28,6 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -50,9 +48,7 @@ public class InstallerTests {
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
System.setProperty("spring.home", "target");
|
||||
FileSystemUtils.deleteRecursively(new File("target/lib"));
|
||||
|
||||
System.setProperty("spring.home", this.tempFolder.getRoot().getAbsolutePath());
|
||||
this.installer = new Installer(this.resolver);
|
||||
}
|
||||
|
||||
@@ -119,7 +115,7 @@ public class InstallerTests {
|
||||
|
||||
private Set<String> getNamesOfFilesInLibExt() {
|
||||
Set<String> names = new HashSet<>();
|
||||
for (File file : new File("target/lib/ext").listFiles()) {
|
||||
for (File file : new File(this.tempFolder.getRoot(), "lib/ext").listFiles()) {
|
||||
names.add(file.getName());
|
||||
}
|
||||
return names;
|
||||
|
||||
Reference in New Issue
Block a user