Upgrade to spring-javaformat 0.0.11
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 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.
|
||||
@@ -25,8 +25,7 @@ public class DevToolsTestApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(DevToolsTestApplication.class)
|
||||
.listeners(new EmbeddedServerPortFileWriter("target/server.port"))
|
||||
.run(args);
|
||||
.listeners(new EmbeddedServerPortFileWriter("target/server.port")).run(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 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.
|
||||
@@ -73,8 +73,7 @@ public class DevToolsIntegrationTests {
|
||||
@Before
|
||||
public void launchApplication() throws Exception {
|
||||
this.serverPortFile.delete();
|
||||
this.launchedApplication = this.applicationLauncher
|
||||
.launchApplication(this.javaLauncher);
|
||||
this.launchedApplication = this.applicationLauncher.launchApplication(this.javaLauncher);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -86,53 +85,50 @@ 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();
|
||||
assertThat(template.getForObject(urlBase + "/one", String.class))
|
||||
.isEqualTo("one");
|
||||
assertThat(template.getForObject("http://localhost:" + awaitServerPort() + "/two",
|
||||
String.class)).isEqualTo("two");
|
||||
controller("com.example.ControllerOne").withRequestMapping("one").withRequestMapping("two").build();
|
||||
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
|
||||
assertThat(template.getForObject("http://localhost:" + awaitServerPort() + "/two", String.class))
|
||||
.isEqualTo("two");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeARequestMappingFromAnExistingController() throws Exception {
|
||||
TestRestTemplate template = new TestRestTemplate();
|
||||
assertThat(template.getForObject("http://localhost:" + awaitServerPort() + "/one",
|
||||
String.class)).isEqualTo("one");
|
||||
assertThat(template.getForObject("http://localhost:" + awaitServerPort() + "/one", String.class))
|
||||
.isEqualTo("one");
|
||||
controller("com.example.ControllerOne").build();
|
||||
assertThat(template.getForEntity("http://localhost:" + awaitServerPort() + "/one",
|
||||
String.class).getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
assertThat(
|
||||
template.getForEntity("http://localhost:" + awaitServerPort() + "/one", String.class).getStatusCode())
|
||||
.isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
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();
|
||||
assertThat(template.getForObject(urlBase + "/one", String.class))
|
||||
.isEqualTo("one");
|
||||
assertThat(template.getForObject("http://localhost:" + awaitServerPort() + "/two",
|
||||
String.class)).isEqualTo("two");
|
||||
assertThat(template.getForObject(urlBase + "/one", String.class)).isEqualTo("one");
|
||||
assertThat(template.getForObject("http://localhost:" + awaitServerPort() + "/two", String.class))
|
||||
.isEqualTo("two");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteAController() throws Exception {
|
||||
TestRestTemplate template = new TestRestTemplate();
|
||||
assertThat(template.getForObject("http://localhost:" + awaitServerPort() + "/one",
|
||||
String.class)).isEqualTo("one");
|
||||
assertThat(new File(this.launchedApplication.getClassesDirectory(),
|
||||
"com/example/ControllerOne.class").delete()).isTrue();
|
||||
assertThat(template.getForEntity("http://localhost:" + awaitServerPort() + "/one",
|
||||
String.class).getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
assertThat(template.getForObject("http://localhost:" + awaitServerPort() + "/one", String.class))
|
||||
.isEqualTo("one");
|
||||
assertThat(new File(this.launchedApplication.getClassesDirectory(), "com/example/ControllerOne.class").delete())
|
||||
.isTrue();
|
||||
assertThat(
|
||||
template.getForEntity("http://localhost:" + awaitServerPort() + "/one", String.class).getStatusCode())
|
||||
.isEqualTo(HttpStatus.NOT_FOUND);
|
||||
|
||||
}
|
||||
|
||||
@@ -141,10 +137,8 @@ public class DevToolsIntegrationTests {
|
||||
while (this.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",
|
||||
FileCopyUtils.copyToString(new FileReader(
|
||||
this.launchedApplication.getStandardOut()))));
|
||||
"server.port file was not written within 30 seconds. " + "Application output:%n%s",
|
||||
FileCopyUtils.copyToString(new FileReader(this.launchedApplication.getStandardOut()))));
|
||||
}
|
||||
Thread.sleep(100);
|
||||
}
|
||||
@@ -155,8 +149,7 @@ public class DevToolsIntegrationTests {
|
||||
}
|
||||
|
||||
private ControllerBuilder controller(String name) {
|
||||
return new ControllerBuilder(name,
|
||||
this.launchedApplication.getClassesDirectory());
|
||||
return new ControllerBuilder(name, this.launchedApplication.getClassesDirectory());
|
||||
}
|
||||
|
||||
private static final class ControllerBuilder {
|
||||
@@ -178,14 +171,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);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 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.
|
||||
@@ -36,8 +36,7 @@ public class ExplodedRemoteApplicationLauncher extends RemoteApplicationLauncher
|
||||
File appDirectory = new File("target/app");
|
||||
FileSystemUtils.deleteRecursively(appDirectory);
|
||||
appDirectory.mkdirs();
|
||||
FileSystemUtils.copyRecursively(new File("target/test-classes/com"),
|
||||
new File("target/app/com"));
|
||||
FileSystemUtils.copyRecursively(new File("target/test-classes/com"), new File("target/app/com"));
|
||||
List<String> entries = new ArrayList<String>();
|
||||
entries.add("target/app");
|
||||
for (File jar : new File("target/dependencies").listFiles()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -46,10 +46,8 @@ public class JarFileRemoteApplicationLauncher extends RemoteApplicationLauncher
|
||||
appDirectory.mkdirs();
|
||||
Manifest manifest = new Manifest();
|
||||
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
|
||||
JarOutputStream output = new JarOutputStream(
|
||||
new FileOutputStream(new File(appDirectory, "app.jar")), manifest);
|
||||
FileSystemUtils.copyRecursively(new File("target/test-classes/com"),
|
||||
new File("target/app/com"));
|
||||
JarOutputStream output = new JarOutputStream(new FileOutputStream(new File(appDirectory, "app.jar")), manifest);
|
||||
FileSystemUtils.copyRecursively(new File("target/test-classes/com"), new File("target/app/com"));
|
||||
addToJar(output, new File("target/app/"), new File("target/app/"));
|
||||
output.close();
|
||||
List<String> entries = new ArrayList<String>();
|
||||
@@ -57,20 +55,18 @@ public class JarFileRemoteApplicationLauncher extends RemoteApplicationLauncher
|
||||
for (File jar : new File("target/dependencies").listFiles()) {
|
||||
entries.add(jar.getAbsolutePath());
|
||||
}
|
||||
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()) {
|
||||
FileInputStream input = new FileInputStream(file);
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 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,20 +38,18 @@ class JvmLauncher implements TestRule {
|
||||
|
||||
@Override
|
||||
public Statement apply(Statement base, Description description) {
|
||||
this.outputDirectory = new File("target/output/"
|
||||
+ description.getMethodName().replaceAll("[^A-Za-z]+", ""));
|
||||
this.outputDirectory = new File("target/output/" + description.getMethodName().replaceAll("[^A-Za-z]+", ""));
|
||||
this.outputDirectory.mkdirs();
|
||||
return base;
|
||||
}
|
||||
|
||||
LaunchedJvm launch(String name, String classpath, String... args) throws IOException {
|
||||
List<String> command = new ArrayList<String>(Arrays
|
||||
.asList(System.getProperty("java.home") + "/bin/java", "-cp", classpath));
|
||||
List<String> command = new ArrayList<String>(
|
||||
Arrays.asList(System.getProperty("java.home") + "/bin/java", "-cp", classpath));
|
||||
command.addAll(Arrays.asList(args));
|
||||
File standardOut = new File(this.outputDirectory, name + ".out");
|
||||
Process process = new ProcessBuilder(command.toArray(new String[command.size()]))
|
||||
.redirectError(new File(this.outputDirectory, name + ".err"))
|
||||
.redirectOutput(standardOut).start();
|
||||
.redirectError(new File(this.outputDirectory, name + ".err")).redirectOutput(standardOut).start();
|
||||
return new LaunchedJvm(process, standardOut);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 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.
|
||||
@@ -32,20 +32,17 @@ import org.springframework.util.StringUtils;
|
||||
public class LocalApplicationLauncher implements ApplicationLauncher {
|
||||
|
||||
@Override
|
||||
public LaunchedApplication launchApplication(JvmLauncher jvmLauncher)
|
||||
throws Exception {
|
||||
public LaunchedApplication launchApplication(JvmLauncher jvmLauncher) throws Exception {
|
||||
LaunchedJvm jvm = jvmLauncher.launch("local", createApplicationClassPath(),
|
||||
"com.example.DevToolsTestApplication", "--server.port=0");
|
||||
return new LaunchedApplication(new File("target/app"), jvm.getStandardOut(),
|
||||
jvm.getProcess());
|
||||
return new LaunchedApplication(new File("target/app"), jvm.getStandardOut(), jvm.getProcess());
|
||||
}
|
||||
|
||||
protected String createApplicationClassPath() throws Exception {
|
||||
File appDirectory = new File("target/app");
|
||||
FileSystemUtils.deleteRecursively(appDirectory);
|
||||
appDirectory.mkdirs();
|
||||
FileSystemUtils.copyRecursively(new File("target/test-classes/com"),
|
||||
new File("target/app/com"));
|
||||
FileSystemUtils.copyRecursively(new File("target/test-classes/com"), new File("target/app/com"));
|
||||
List<String> entries = new ArrayList<String>();
|
||||
entries.add("target/app");
|
||||
for (File jar : new File("target/dependencies").listFiles()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 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.
|
||||
@@ -35,19 +35,16 @@ import org.springframework.util.StringUtils;
|
||||
abstract class RemoteApplicationLauncher implements ApplicationLauncher {
|
||||
|
||||
@Override
|
||||
public LaunchedApplication launchApplication(JvmLauncher javaLauncher)
|
||||
throws Exception {
|
||||
public LaunchedApplication launchApplication(JvmLauncher javaLauncher) throws Exception {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
LaunchedJvm applicationJvm = javaLauncher.launch("app",
|
||||
createApplicationClassPath(), "com.example.DevToolsTestApplication",
|
||||
"--server.port=" + port, "--spring.devtools.remote.secret=secret");
|
||||
LaunchedJvm remoteSpringApplicationJvm = javaLauncher.launch(
|
||||
"remote-spring-application", createRemoteSpringApplicationClassPath(),
|
||||
RemoteSpringApplication.class.getName(),
|
||||
LaunchedJvm applicationJvm = javaLauncher.launch("app", createApplicationClassPath(),
|
||||
"com.example.DevToolsTestApplication", "--server.port=" + port,
|
||||
"--spring.devtools.remote.secret=secret");
|
||||
LaunchedJvm remoteSpringApplicationJvm = javaLauncher.launch("remote-spring-application",
|
||||
createRemoteSpringApplicationClassPath(), RemoteSpringApplication.class.getName(),
|
||||
"--spring.devtools.remote.secret=secret", "http://localhost:" + port);
|
||||
return new LaunchedApplication(new File("target/remote"),
|
||||
applicationJvm.getStandardOut(), applicationJvm.getProcess(),
|
||||
remoteSpringApplicationJvm.getProcess());
|
||||
return new LaunchedApplication(new File("target/remote"), applicationJvm.getStandardOut(),
|
||||
applicationJvm.getProcess(), remoteSpringApplicationJvm.getProcess());
|
||||
}
|
||||
|
||||
protected abstract String createApplicationClassPath() throws Exception;
|
||||
@@ -56,8 +53,7 @@ abstract class RemoteApplicationLauncher implements ApplicationLauncher {
|
||||
File remoteDirectory = new File("target/remote");
|
||||
FileSystemUtils.deleteRecursively(remoteDirectory);
|
||||
remoteDirectory.mkdirs();
|
||||
FileSystemUtils.copyRecursively(new File("target/test-classes/com"),
|
||||
new File("target/remote/com"));
|
||||
FileSystemUtils.copyRecursively(new File("target/test-classes/com"), new File("target/remote/com"));
|
||||
List<String> entries = new ArrayList<String>();
|
||||
entries.add("target/remote");
|
||||
for (File jar : new File("target/dependencies").listFiles()) {
|
||||
|
||||
Reference in New Issue
Block a user