Merge branch '2.1.x'

Closes gh-17079
This commit is contained in:
Andy Wilkinson
2019-06-07 11:00:44 +01:00
2799 changed files with 28402 additions and 47836 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -24,8 +24,8 @@ import org.springframework.boot.web.context.WebServerPortFileWriter;
public class DevToolsTestApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(DevToolsTestApplication.class)
.listeners(new WebServerPortFileWriter(args[0])).run(args);
new SpringApplicationBuilder(DevToolsTestApplication.class).listeners(new WebServerPortFileWriter(args[0]))
.run(args);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -40,14 +40,13 @@ abstract class AbstractApplicationLauncher implements ApplicationLauncher {
protected final void copyApplicationTo(File location) throws IOException {
FileSystemUtils.deleteRecursively(location);
location.mkdirs();
FileSystemUtils.copyRecursively(
new File(this.directories.getTestClassesDirectory(), "com"),
FileSystemUtils.copyRecursively(new File(this.directories.getTestClassesDirectory(), "com"),
new File(location, "com"));
}
protected final List<String> getDependencyJarPaths() {
return Stream.of(this.directories.getDependenciesDirectory().listFiles())
.map(File::getAbsolutePath).collect(Collectors.toList());
return Stream.of(this.directories.getDependenciesDirectory().listFiles()).map(File::getAbsolutePath)
.collect(Collectors.toList());
}
protected final Directories getDirectories() {

View File

@@ -26,10 +26,9 @@ import java.io.File;
*/
public interface ApplicationLauncher {
LaunchedApplication launchApplication(JvmLauncher javaLauncher, File serverPortFile)
LaunchedApplication launchApplication(JvmLauncher javaLauncher, File serverPortFile) throws Exception;
LaunchedApplication launchApplication(JvmLauncher jvmLauncher, File serverPortFile, String... additionalArgs)
throws Exception;
LaunchedApplication launchApplication(JvmLauncher jvmLauncher, File serverPortFile,
String... additionalArgs) throws Exception;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -58,8 +58,7 @@ public class DevToolsIntegrationTests {
@ClassRule
public static final TemporaryFolder temp = new TemporaryFolder();
private static final BuildOutput buildOutput = new BuildOutput(
DevToolsIntegrationTests.class);
private static final BuildOutput buildOutput = new BuildOutput(DevToolsIntegrationTests.class);
private LaunchedApplication launchedApplication;
@@ -72,15 +71,13 @@ public class DevToolsIntegrationTests {
public DevToolsIntegrationTests(ApplicationLauncher applicationLauncher) {
this.applicationLauncher = applicationLauncher;
this.serverPortFile = new File(
DevToolsIntegrationTests.buildOutput.getRootLocation(), "server.port");
this.serverPortFile = new File(DevToolsIntegrationTests.buildOutput.getRootLocation(), "server.port");
}
@Before
public void launchApplication() throws Exception {
this.serverPortFile.delete();
this.launchedApplication = this.applicationLauncher
.launchApplication(this.javaLauncher, this.serverPortFile);
this.launchedApplication = this.applicationLauncher.launchApplication(this.javaLauncher, this.serverPortFile);
}
@After
@@ -92,25 +89,20 @@ public class DevToolsIntegrationTests {
public void addARequestMappingToAnExistingController() throws Exception {
TestRestTemplate template = new TestRestTemplate();
String urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class))
.isEqualTo("one");
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForEntity(urlBase + "/two", String.class).getStatusCode())
.isEqualTo(HttpStatus.NOT_FOUND);
controller("com.example.ControllerOne").withRequestMapping("one")
.withRequestMapping("two").build();
controller("com.example.ControllerOne").withRequestMapping("one").withRequestMapping("two").build();
urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class))
.isEqualTo("one");
assertThat(template.getForObject(urlBase + "/two", String.class))
.isEqualTo("two");
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForObject(urlBase + "/two", String.class)).isEqualTo("two");
}
@Test
public void removeARequestMappingFromAnExistingController() throws Exception {
TestRestTemplate template = new TestRestTemplate();
String urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class))
.isEqualTo("one");
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
controller("com.example.ControllerOne").build();
urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForEntity(urlBase + "/one", String.class).getStatusCode())
@@ -121,16 +113,13 @@ public class DevToolsIntegrationTests {
public void createAController() throws Exception {
TestRestTemplate template = new TestRestTemplate();
String urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class))
.isEqualTo("one");
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForEntity(urlBase + "/two", String.class).getStatusCode())
.isEqualTo(HttpStatus.NOT_FOUND);
controller("com.example.ControllerTwo").withRequestMapping("two").build();
urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class))
.isEqualTo("one");
assertThat(template.getForObject(urlBase + "/two", String.class))
.isEqualTo("two");
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForObject(urlBase + "/two", String.class)).isEqualTo("two");
}
@@ -138,57 +127,43 @@ public class DevToolsIntegrationTests {
public void createAControllerAndThenAddARequestMapping() throws Exception {
TestRestTemplate template = new TestRestTemplate();
String urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class))
.isEqualTo("one");
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForEntity(urlBase + "/two", String.class).getStatusCode())
.isEqualTo(HttpStatus.NOT_FOUND);
controller("com.example.ControllerTwo").withRequestMapping("two").build();
urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class))
.isEqualTo("one");
assertThat(template.getForObject(urlBase + "/two", String.class))
.isEqualTo("two");
controller("com.example.ControllerTwo").withRequestMapping("two")
.withRequestMapping("three").build();
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForObject(urlBase + "/two", String.class)).isEqualTo("two");
controller("com.example.ControllerTwo").withRequestMapping("two").withRequestMapping("three").build();
urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/three", String.class))
.isEqualTo("three");
assertThat(template.getForObject(urlBase + "/three", String.class)).isEqualTo("three");
}
@Test
public void createAControllerAndThenAddARequestMappingToAnExistingController()
throws Exception {
public void createAControllerAndThenAddARequestMappingToAnExistingController() throws Exception {
TestRestTemplate template = new TestRestTemplate();
String urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class))
.isEqualTo("one");
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForEntity(urlBase + "/two", String.class).getStatusCode())
.isEqualTo(HttpStatus.NOT_FOUND);
controller("com.example.ControllerTwo").withRequestMapping("two").build();
urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class))
.isEqualTo("one");
assertThat(template.getForObject(urlBase + "/two", String.class))
.isEqualTo("two");
controller("com.example.ControllerOne").withRequestMapping("one")
.withRequestMapping("three").build();
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForObject(urlBase + "/two", String.class)).isEqualTo("two");
controller("com.example.ControllerOne").withRequestMapping("one").withRequestMapping("three").build();
urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class))
.isEqualTo("one");
assertThat(template.getForObject(urlBase + "/two", String.class))
.isEqualTo("two");
assertThat(template.getForObject(urlBase + "/three", String.class))
.isEqualTo("three");
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForObject(urlBase + "/two", String.class)).isEqualTo("two");
assertThat(template.getForObject(urlBase + "/three", String.class)).isEqualTo("three");
}
@Test
public void deleteAController() throws Exception {
TestRestTemplate template = new TestRestTemplate();
String urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class))
.isEqualTo("one");
assertThat(new File(this.launchedApplication.getClassesDirectory(),
"com/example/ControllerOne.class").delete()).isTrue();
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(new File(this.launchedApplication.getClassesDirectory(), "com/example/ControllerOne.class").delete())
.isTrue();
urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForEntity(urlBase + "/one", String.class).getStatusCode())
.isEqualTo(HttpStatus.NOT_FOUND);
@@ -199,18 +174,15 @@ public class DevToolsIntegrationTests {
public void createAControllerAndThenDeleteIt() throws Exception {
TestRestTemplate template = new TestRestTemplate();
String urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class))
.isEqualTo("one");
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForEntity(urlBase + "/two", String.class).getStatusCode())
.isEqualTo(HttpStatus.NOT_FOUND);
controller("com.example.ControllerTwo").withRequestMapping("two").build();
urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class))
.isEqualTo("one");
assertThat(template.getForObject(urlBase + "/two", String.class))
.isEqualTo("two");
assertThat(new File(this.launchedApplication.getClassesDirectory(),
"com/example/ControllerTwo.class").delete()).isTrue();
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForObject(urlBase + "/two", String.class)).isEqualTo("two");
assertThat(new File(this.launchedApplication.getClassesDirectory(), "com/example/ControllerTwo.class").delete())
.isTrue();
urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForEntity(urlBase + "/two", String.class).getStatusCode())
.isEqualTo(HttpStatus.NOT_FOUND);
@@ -223,13 +195,10 @@ public class DevToolsIntegrationTests {
while (this.serverPortFile.length() == 0) {
if (System.currentTimeMillis() > end) {
throw new IllegalStateException(String.format(
"server.port file '" + this.serverPortFile
+ "' was not written within " + timeToWait.toMillis()
"server.port file '" + this.serverPortFile + "' was not written within " + timeToWait.toMillis()
+ "ms. " + "Application output:%n%s%s",
FileCopyUtils.copyToString(new FileReader(
this.launchedApplication.getStandardOut())),
FileCopyUtils.copyToString(new FileReader(
this.launchedApplication.getStandardError()))));
FileCopyUtils.copyToString(new FileReader(this.launchedApplication.getStandardOut())),
FileCopyUtils.copyToString(new FileReader(this.launchedApplication.getStandardError()))));
}
Thread.sleep(100);
}
@@ -243,8 +212,7 @@ public class DevToolsIntegrationTests {
}
private ControllerBuilder controller(String name) {
return new ControllerBuilder(name,
this.launchedApplication.getClassesDirectory());
return new ControllerBuilder(name, this.launchedApplication.getClassesDirectory());
}
@Parameters(name = "{0}")
@@ -274,14 +242,12 @@ public class DevToolsIntegrationTests {
}
public void build() throws Exception {
Builder<Object> builder = new ByteBuddy().subclass(Object.class)
.name(this.name).annotateType(AnnotationDescription.Builder
.ofType(RestController.class).build());
Builder<Object> builder = new ByteBuddy().subclass(Object.class).name(this.name)
.annotateType(AnnotationDescription.Builder.ofType(RestController.class).build());
for (String mapping : this.mappings) {
builder = builder.defineMethod(mapping, String.class, Visibility.PUBLIC)
.intercept(FixedValue.value(mapping)).annotateMethod(
AnnotationDescription.Builder.ofType(RequestMapping.class)
.defineArray("value", mapping).build());
.intercept(FixedValue.value(mapping)).annotateMethod(AnnotationDescription.Builder
.ofType(RequestMapping.class).defineArray("value", mapping).build());
}
builder.make().saveIn(this.classesDirectory);
}

View File

@@ -57,8 +57,7 @@ public class DevToolsWithLazyInitializationIntegrationTests {
@ClassRule
public static final TemporaryFolder temp = new TemporaryFolder();
private static final BuildOutput buildOutput = new BuildOutput(
DevToolsIntegrationTests.class);
private static final BuildOutput buildOutput = new BuildOutput(DevToolsIntegrationTests.class);
private LaunchedApplication launchedApplication;
@@ -69,8 +68,7 @@ public class DevToolsWithLazyInitializationIntegrationTests {
@Rule
public JvmLauncher javaLauncher = new JvmLauncher();
public DevToolsWithLazyInitializationIntegrationTests(
ApplicationLauncher applicationLauncher) {
public DevToolsWithLazyInitializationIntegrationTests(ApplicationLauncher applicationLauncher) {
this.applicationLauncher = applicationLauncher;
this.serverPortFile = new File(buildOutput.getRootLocation(), "server.port");
}
@@ -78,8 +76,7 @@ public class DevToolsWithLazyInitializationIntegrationTests {
@Before
public void launchApplication() throws Exception {
this.serverPortFile.delete();
this.launchedApplication = this.applicationLauncher.launchApplication(
this.javaLauncher, this.serverPortFile,
this.launchedApplication = this.applicationLauncher.launchApplication(this.javaLauncher, this.serverPortFile,
"--spring.main.lazy-initialization=true");
}
@@ -92,17 +89,13 @@ public class DevToolsWithLazyInitializationIntegrationTests {
public void addARequestMappingToAnExistingControllerWhenLazyInit() throws Exception {
TestRestTemplate template = new TestRestTemplate();
String urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class))
.isEqualTo("one");
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForEntity(urlBase + "/two", String.class).getStatusCode())
.isEqualTo(HttpStatus.NOT_FOUND);
controller("com.example.ControllerOne").withRequestMapping("one")
.withRequestMapping("two").build();
controller("com.example.ControllerOne").withRequestMapping("one").withRequestMapping("two").build();
urlBase = "http://localhost:" + awaitServerPort();
assertThat(template.getForObject(urlBase + "/one", String.class))
.isEqualTo("one");
assertThat(template.getForObject(urlBase + "/two", String.class))
.isEqualTo("two");
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
assertThat(template.getForObject(urlBase + "/two", String.class)).isEqualTo("two");
}
private int awaitServerPort() throws Exception {
@@ -112,13 +105,10 @@ public class DevToolsWithLazyInitializationIntegrationTests {
while (this.serverPortFile.length() == 0) {
if (System.currentTimeMillis() > end) {
throw new IllegalStateException(String.format(
"server.port file '" + this.serverPortFile
+ "' was not written within " + timeToWait.toMillis()
"server.port file '" + this.serverPortFile + "' was not written within " + timeToWait.toMillis()
+ "ms. " + "Application output:%n%s%s",
FileCopyUtils.copyToString(new FileReader(
this.launchedApplication.getStandardOut())),
FileCopyUtils.copyToString(new FileReader(
this.launchedApplication.getStandardError()))));
FileCopyUtils.copyToString(new FileReader(this.launchedApplication.getStandardOut())),
FileCopyUtils.copyToString(new FileReader(this.launchedApplication.getStandardError()))));
}
Thread.sleep(100);
}
@@ -132,8 +122,7 @@ public class DevToolsWithLazyInitializationIntegrationTests {
}
private ControllerBuilder controller(String name) {
return new ControllerBuilder(name,
this.launchedApplication.getClassesDirectory());
return new ControllerBuilder(name, this.launchedApplication.getClassesDirectory());
}
@Parameterized.Parameters(name = "{0}")
@@ -164,14 +153,12 @@ public class DevToolsWithLazyInitializationIntegrationTests {
}
public void build() throws Exception {
DynamicType.Builder<Object> builder = new ByteBuddy().subclass(Object.class)
.name(this.name).annotateType(AnnotationDescription.Builder
.ofType(RestController.class).build());
DynamicType.Builder<Object> builder = new ByteBuddy().subclass(Object.class).name(this.name)
.annotateType(AnnotationDescription.Builder.ofType(RestController.class).build());
for (String mapping : this.mappings) {
builder = builder.defineMethod(mapping, String.class, Visibility.PUBLIC)
.intercept(FixedValue.value(mapping)).annotateMethod(
AnnotationDescription.Builder.ofType(RequestMapping.class)
.defineArray("value", mapping).build());
.intercept(FixedValue.value(mapping)).annotateMethod(AnnotationDescription.Builder
.ofType(RequestMapping.class).defineArray("value", mapping).build());
}
builder.make().saveIn(this.classesDirectory);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -49,27 +49,24 @@ public class JarFileRemoteApplicationLauncher extends RemoteApplicationLauncher
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
File appJar = new File(appDirectory, "app.jar");
JarOutputStream output = new JarOutputStream(new FileOutputStream(appJar),
manifest);
JarOutputStream output = new JarOutputStream(new FileOutputStream(appJar), manifest);
addToJar(output, appDirectory, appDirectory);
output.close();
List<String> entries = new ArrayList<>();
entries.add(appJar.getAbsolutePath());
entries.addAll(getDependencyJarPaths());
String classpath = StringUtils.collectionToDelimitedString(entries,
File.pathSeparator);
String classpath = StringUtils.collectionToDelimitedString(entries, File.pathSeparator);
return classpath;
}
private void addToJar(JarOutputStream output, File root, File current)
throws IOException {
private void addToJar(JarOutputStream output, File root, File current) throws IOException {
for (File file : current.listFiles()) {
if (file.isDirectory()) {
addToJar(output, root, file);
}
output.putNextEntry(new ZipEntry(
file.getAbsolutePath().substring(root.getAbsolutePath().length() + 1)
.replace("\\", "/") + (file.isDirectory() ? "/" : "")));
file.getAbsolutePath().substring(root.getAbsolutePath().length() + 1).replace("\\", "/")
+ (file.isDirectory() ? "/" : "")));
if (file.isFile()) {
try (FileInputStream input = new FileInputStream(file)) {
StreamUtils.copy(input, output);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -47,20 +47,19 @@ class JvmLauncher implements TestRule {
@Override
public Statement apply(Statement base, Description description) {
this.outputDirectory = new File(this.buildOutput.getRootLocation(),
"output/" + NON_ALPHABET_PATTERN.matcher(description.getMethodName())
.replaceAll(""));
"output/" + NON_ALPHABET_PATTERN.matcher(description.getMethodName()).replaceAll(""));
this.outputDirectory.mkdirs();
return base;
}
LaunchedJvm launch(String name, String classpath, String... args) throws IOException {
List<String> command = new ArrayList<>(Arrays
.asList(System.getProperty("java.home") + "/bin/java", "-cp", classpath));
List<String> command = new ArrayList<>(
Arrays.asList(System.getProperty("java.home") + "/bin/java", "-cp", classpath));
command.addAll(Arrays.asList(args));
File standardOut = new File(this.outputDirectory, name + ".out");
File standardError = new File(this.outputDirectory, name + ".err");
Process process = new ProcessBuilder(StringUtils.toStringArray(command))
.redirectError(standardError).redirectOutput(standardOut).start();
Process process = new ProcessBuilder(StringUtils.toStringArray(command)).redirectError(standardError)
.redirectOutput(standardOut).start();
return new LaunchedJvm(process, standardOut, standardError);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@@ -38,9 +38,8 @@ class LaunchedApplication {
private final BiFunction<Integer, File, Process> remoteProcessRestarter;
LaunchedApplication(File classesDirectory, File standardOut, File standardError,
Process localProcess, Process remoteProcess,
BiFunction<Integer, File, Process> remoteProcessRestarter) {
LaunchedApplication(File classesDirectory, File standardOut, File standardError, Process localProcess,
Process remoteProcess, BiFunction<Integer, File, Process> remoteProcessRestarter) {
this.classesDirectory = classesDirectory;
this.standardOut = standardOut;
this.standardError = standardError;
@@ -52,8 +51,7 @@ class LaunchedApplication {
public void restartRemote(int port) throws InterruptedException {
if (this.remoteProcessRestarter != null) {
stop(this.remoteProcess);
this.remoteProcess = this.remoteProcessRestarter.apply(port,
this.classesDirectory);
this.remoteProcess = this.remoteProcessRestarter.apply(port, this.classesDirectory);
}
}

View File

@@ -36,28 +36,22 @@ public class LocalApplicationLauncher extends AbstractApplicationLauncher {
}
@Override
public LaunchedApplication launchApplication(JvmLauncher jvmLauncher,
File serverPortFile) throws Exception {
public LaunchedApplication launchApplication(JvmLauncher jvmLauncher, File serverPortFile) throws Exception {
LaunchedJvm jvm = jvmLauncher.launch("local", createApplicationClassPath(),
"com.example.DevToolsTestApplication", serverPortFile.getAbsolutePath(),
"--server.port=0");
return new LaunchedApplication(getDirectories().getAppDirectory(),
jvm.getStandardOut(), jvm.getStandardError(), jvm.getProcess(), null,
null);
"com.example.DevToolsTestApplication", serverPortFile.getAbsolutePath(), "--server.port=0");
return new LaunchedApplication(getDirectories().getAppDirectory(), jvm.getStandardOut(), jvm.getStandardError(),
jvm.getProcess(), null, null);
}
@Override
public LaunchedApplication launchApplication(JvmLauncher jvmLauncher,
File serverPortFile, String... additionalArgs) throws Exception {
List<String> args = new ArrayList<>(
Arrays.asList("com.example.DevToolsTestApplication",
serverPortFile.getAbsolutePath(), "--server.port=0"));
public LaunchedApplication launchApplication(JvmLauncher jvmLauncher, File serverPortFile, String... additionalArgs)
throws Exception {
List<String> args = new ArrayList<>(Arrays.asList("com.example.DevToolsTestApplication",
serverPortFile.getAbsolutePath(), "--server.port=0"));
args.addAll(Arrays.asList(additionalArgs));
LaunchedJvm jvm = jvmLauncher.launch("local", createApplicationClassPath(),
args.toArray(new String[] {}));
return new LaunchedApplication(getDirectories().getAppDirectory(),
jvm.getStandardOut(), jvm.getStandardError(), jvm.getProcess(), null,
null);
LaunchedJvm jvm = jvmLauncher.launch("local", createApplicationClassPath(), args.toArray(new String[] {}));
return new LaunchedApplication(getDirectories().getAppDirectory(), jvm.getStandardOut(), jvm.getStandardError(),
jvm.getProcess(), null, null);
}
protected String createApplicationClassPath() throws Exception {

View File

@@ -41,48 +41,38 @@ abstract class RemoteApplicationLauncher extends AbstractApplicationLauncher {
}
@Override
public LaunchedApplication launchApplication(JvmLauncher javaLauncher,
File serverPortFile) throws Exception {
LaunchedJvm applicationJvm = javaLauncher.launch("app",
createApplicationClassPath(), "com.example.DevToolsTestApplication",
serverPortFile.getAbsolutePath(), "--server.port=0",
public LaunchedApplication launchApplication(JvmLauncher javaLauncher, File serverPortFile) throws Exception {
LaunchedJvm applicationJvm = javaLauncher.launch("app", createApplicationClassPath(),
"com.example.DevToolsTestApplication", serverPortFile.getAbsolutePath(), "--server.port=0",
"--spring.devtools.remote.secret=secret");
int port = awaitServerPort(applicationJvm.getStandardOut(), serverPortFile);
BiFunction<Integer, File, Process> remoteRestarter = getRemoteRestarter(
javaLauncher);
return new LaunchedApplication(getDirectories().getRemoteAppDirectory(),
applicationJvm.getStandardOut(), applicationJvm.getStandardError(),
applicationJvm.getProcess(), remoteRestarter.apply(port, null),
BiFunction<Integer, File, Process> remoteRestarter = getRemoteRestarter(javaLauncher);
return new LaunchedApplication(getDirectories().getRemoteAppDirectory(), applicationJvm.getStandardOut(),
applicationJvm.getStandardError(), applicationJvm.getProcess(), remoteRestarter.apply(port, null),
remoteRestarter);
}
@Override
public LaunchedApplication launchApplication(JvmLauncher javaLauncher,
File serverPortFile, String... additionalArgs) throws Exception {
List<String> args = new ArrayList<>(Arrays.asList(
"com.example.DevToolsTestApplication", serverPortFile.getAbsolutePath(),
"--server.port=0", "--spring.devtools.remote.secret=secret"));
public LaunchedApplication launchApplication(JvmLauncher javaLauncher, File serverPortFile,
String... additionalArgs) throws Exception {
List<String> args = new ArrayList<>(Arrays.asList("com.example.DevToolsTestApplication",
serverPortFile.getAbsolutePath(), "--server.port=0", "--spring.devtools.remote.secret=secret"));
args.addAll(Arrays.asList(additionalArgs));
LaunchedJvm applicationJvm = javaLauncher.launch("app",
createApplicationClassPath(), args.toArray(new String[] {}));
LaunchedJvm applicationJvm = javaLauncher.launch("app", createApplicationClassPath(),
args.toArray(new String[] {}));
int port = awaitServerPort(applicationJvm.getStandardOut(), serverPortFile);
BiFunction<Integer, File, Process> remoteRestarter = getRemoteRestarter(
javaLauncher);
return new LaunchedApplication(getDirectories().getRemoteAppDirectory(),
applicationJvm.getStandardOut(), applicationJvm.getStandardError(),
applicationJvm.getProcess(), remoteRestarter.apply(port, null),
BiFunction<Integer, File, Process> remoteRestarter = getRemoteRestarter(javaLauncher);
return new LaunchedApplication(getDirectories().getRemoteAppDirectory(), applicationJvm.getStandardOut(),
applicationJvm.getStandardError(), applicationJvm.getProcess(), remoteRestarter.apply(port, null),
remoteRestarter);
}
private BiFunction<Integer, File, Process> getRemoteRestarter(
JvmLauncher javaLauncher) {
private BiFunction<Integer, File, Process> getRemoteRestarter(JvmLauncher javaLauncher) {
return (port, classesDirectory) -> {
try {
LaunchedJvm remoteSpringApplicationJvm = javaLauncher.launch(
"remote-spring-application",
LaunchedJvm remoteSpringApplicationJvm = javaLauncher.launch("remote-spring-application",
createRemoteSpringApplicationClassPath(classesDirectory),
RemoteSpringApplication.class.getName(),
"--spring.devtools.remote.secret=secret",
RemoteSpringApplication.class.getName(), "--spring.devtools.remote.secret=secret",
"http://localhost:" + port);
awaitRemoteSpringApplication(remoteSpringApplicationJvm.getStandardOut());
return remoteSpringApplicationJvm.getProcess();
@@ -95,8 +85,7 @@ abstract class RemoteApplicationLauncher extends AbstractApplicationLauncher {
protected abstract String createApplicationClassPath() throws Exception;
private String createRemoteSpringApplicationClassPath(File classesDirectory)
throws Exception {
private String createRemoteSpringApplicationClassPath(File classesDirectory) throws Exception {
File remoteAppDirectory = getDirectories().getRemoteAppDirectory();
if (classesDirectory == null) {
copyApplicationTo(remoteAppDirectory);
@@ -112,8 +101,7 @@ abstract class RemoteApplicationLauncher extends AbstractApplicationLauncher {
while (serverPortFile.length() == 0) {
if (System.currentTimeMillis() > end) {
throw new IllegalStateException(String.format(
"server.port file was not written within 30 seconds. "
+ "Application output:%n%s",
"server.port file was not written within 30 seconds. " + "Application output:%n%s",
FileCopyUtils.copyToString(new FileReader(standardOut))));
}
Thread.sleep(100);
@@ -127,16 +115,13 @@ abstract class RemoteApplicationLauncher extends AbstractApplicationLauncher {
long end = System.currentTimeMillis() + 30000;
while (!standardOut.exists()) {
if (System.currentTimeMillis() > end) {
throw new IllegalStateException(
"Standard out file was not written " + "within 30 seconds");
throw new IllegalStateException("Standard out file was not written " + "within 30 seconds");
}
Thread.sleep(100);
}
while (!FileCopyUtils.copyToString(new FileReader(standardOut))
.contains("Started RemoteSpringApplication")) {
while (!FileCopyUtils.copyToString(new FileReader(standardOut)).contains("Started RemoteSpringApplication")) {
if (System.currentTimeMillis() > end) {
throw new IllegalStateException(
"RemoteSpringApplication did not start within 30 seconds");
throw new IllegalStateException("RemoteSpringApplication did not start within 30 seconds");
}
Thread.sleep(100);
}