Upgrade to spring-javaformat 0.0.11
This commit is contained in:
@@ -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,21 +40,17 @@ public class ConfigurationProcessorIntegrationTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void readMetadata() throws IOException {
|
||||
Resource resource = new ClassPathResource(
|
||||
"META-INF/spring-configuration-metadata.json");
|
||||
Resource resource = new ClassPathResource("META-INF/spring-configuration-metadata.json");
|
||||
assertThat(resource.exists()).isTrue();
|
||||
// Make sure the right file is detected
|
||||
assertThat(resource.getURL().toString())
|
||||
.contains("spring-boot-configuration-processor-tests");
|
||||
repository = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create(resource.getInputStream()).build();
|
||||
assertThat(resource.getURL().toString()).contains("spring-boot-configuration-processor-tests");
|
||||
repository = ConfigurationMetadataRepositoryJsonBuilder.create(resource.getInputStream()).build();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractTypeFromAnnotatedGetter() {
|
||||
ConfigurationMetadataProperty property = repository.getAllProperties()
|
||||
.get("annotated.name");
|
||||
ConfigurationMetadataProperty property = repository.getAllProperties().get("annotated.name");
|
||||
assertThat(property).isNotNull();
|
||||
assertThat(property.getType()).isEqualTo("java.lang.String");
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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.
|
||||
@@ -49,8 +49,8 @@ public class BootRunResourceTests {
|
||||
@Test
|
||||
public void resourcesDirectlyFromSource() {
|
||||
project.newBuild().forTasks("clean", "bootRun")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PaddResources=true")
|
||||
.setStandardOutput(System.out).run();
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PaddResources=true").setStandardOutput(System.out)
|
||||
.run();
|
||||
|
||||
assertThat(this.output.toString()).contains("src/main/resources/test.txt");
|
||||
}
|
||||
@@ -58,8 +58,8 @@ public class BootRunResourceTests {
|
||||
@Test
|
||||
public void resourcesFromBuildOutput() {
|
||||
project.newBuild().forTasks("clean", "bootRun")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PaddResources=false")
|
||||
.setStandardOutput(System.out).run();
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PaddResources=false").setStandardOutput(System.out)
|
||||
.run();
|
||||
assertThat(this.output.toString()).contains("build/resources/main/test.txt");
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -37,8 +37,7 @@ public class ClassifierTests {
|
||||
@Test
|
||||
public void classifierInBootTask() throws Exception {
|
||||
this.project = new ProjectCreator().createProject("classifier");
|
||||
this.project.newBuild().forTasks("build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
|
||||
this.project.newBuild().forTasks("build").withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
|
||||
checkFilesExist("classifier");
|
||||
}
|
||||
|
||||
@@ -46,8 +45,7 @@ public class ClassifierTests {
|
||||
public void classifierInBootExtension() throws Exception {
|
||||
this.project = new ProjectCreator().createProject("classifier-extension");
|
||||
this.project.newBuild().forTasks("build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace", "--info")
|
||||
.run();
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace", "--info").run();
|
||||
}
|
||||
|
||||
private void checkFilesExist(String name) throws Exception {
|
||||
|
||||
@@ -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.
|
||||
@@ -39,8 +39,7 @@ public class DeprecatedPluginTests {
|
||||
@Test
|
||||
public void deprecatedIdWorks() throws Exception {
|
||||
this.project = new ProjectCreator().createProject("deprecated-plugin");
|
||||
this.project.newBuild().forTasks("build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
|
||||
this.project.newBuild().forTasks("build").withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.
|
||||
@@ -51,10 +51,8 @@ public class FlatdirTests {
|
||||
if (!this.libs.exists()) {
|
||||
this.libs.mkdirs();
|
||||
}
|
||||
FileCopyUtils.copy(new File("src/test/resources/foo.jar"),
|
||||
new File(this.libs, "foo-1.0.0.jar"));
|
||||
this.project.newBuild().forTasks("build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
|
||||
FileCopyUtils.copy(new File("src/test/resources/foo.jar"), new File(this.libs, "foo-1.0.0.jar"));
|
||||
this.project.newBuild().forTasks("build").withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -48,8 +48,7 @@ public class FullyExecutableJarTests {
|
||||
|
||||
@Test
|
||||
public void jarIsNotExecutableByDefault() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION).run();
|
||||
project.newBuild().forTasks("clean", "build").withArguments("-PbootVersion=" + BOOT_VERSION).run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(isFullyExecutable(executableJar)).isFalse();
|
||||
@@ -57,8 +56,8 @@ public class FullyExecutableJarTests {
|
||||
|
||||
@Test
|
||||
public void madeExecutableViaExtension() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build").withArguments(
|
||||
"-PbootVersion=" + BOOT_VERSION, "-PextensionExecutable=true").run();
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PextensionExecutable=true").run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(isFullyExecutable(executableJar)).isTrue();
|
||||
@@ -67,8 +66,7 @@ public class FullyExecutableJarTests {
|
||||
@Test
|
||||
public void madeExecutableViaTask() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PtaskExecutable=true")
|
||||
.run();
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PtaskExecutable=true").run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(isFullyExecutable(executableJar)).isTrue();
|
||||
@@ -77,8 +75,7 @@ public class FullyExecutableJarTests {
|
||||
@Test
|
||||
public void taskTakesPrecedenceForMakingJarExecutable() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION,
|
||||
"-PextensionExecutable=false", "-PtaskExecutable=true")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PextensionExecutable=false", "-PtaskExecutable=true")
|
||||
.run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
@@ -88,8 +85,7 @@ public class FullyExecutableJarTests {
|
||||
@Test
|
||||
public void scriptPropertiesFromTask() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PtaskProperties=true")
|
||||
.run();
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PtaskProperties=true").run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(isFullyExecutable(executableJar)).isTrue();
|
||||
@@ -98,8 +94,8 @@ public class FullyExecutableJarTests {
|
||||
|
||||
@Test
|
||||
public void scriptPropertiesFromExtension() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build").withArguments(
|
||||
"-PbootVersion=" + BOOT_VERSION, "-PextensionProperties=true").run();
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PextensionProperties=true").run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(isFullyExecutable(executableJar)).isTrue();
|
||||
@@ -109,8 +105,7 @@ public class FullyExecutableJarTests {
|
||||
@Test
|
||||
public void taskTakesPrecedenceForScriptProperties() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION,
|
||||
"-PextensionProperties=true", "-PtaskProperties=true")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PextensionProperties=true", "-PtaskProperties=true")
|
||||
.run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
@@ -121,8 +116,7 @@ public class FullyExecutableJarTests {
|
||||
@Test
|
||||
public void customScriptFromTask() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PtaskScript=true")
|
||||
.run();
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PtaskScript=true").run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(containsLine("Custom task script", executableJar)).isTrue();
|
||||
@@ -131,8 +125,7 @@ public class FullyExecutableJarTests {
|
||||
@Test
|
||||
public void customScriptFromExtension() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PextensionScript=true")
|
||||
.run();
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PextensionScript=true").run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(containsLine("Custom extension script", executableJar)).isTrue();
|
||||
@@ -141,9 +134,7 @@ public class FullyExecutableJarTests {
|
||||
@Test
|
||||
public void taskTakesPrecedenceForCustomScript() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PextensionScript=true",
|
||||
"-PtaskScript=true")
|
||||
.run();
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PextensionScript=true", "-PtaskScript=true").run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(containsLine("Custom task script", executableJar)).isTrue();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.
|
||||
@@ -33,8 +33,8 @@ public class InstallTests {
|
||||
@Test
|
||||
public void cleanInstall() throws Exception {
|
||||
this.project = new ProjectCreator().createProject("installer");
|
||||
this.project.newBuild().forTasks("install")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
|
||||
this.project.newBuild().forTasks("install").withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace")
|
||||
.run();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -42,8 +42,8 @@ public class InstallTests {
|
||||
this.project = new ProjectCreator().createProject("install-app");
|
||||
// "install" from the application plugin was renamed "installApp" in Gradle
|
||||
// 1.0
|
||||
this.project.newBuild().forTasks("installApp")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
|
||||
this.project.newBuild().forTasks("installApp").withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace")
|
||||
.run();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -44,16 +44,14 @@ public class MainClassTests {
|
||||
|
||||
@Test
|
||||
public void mainFromBootRun() {
|
||||
project.newBuild().forTasks("build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PbootRunMain=true")
|
||||
.run();
|
||||
project.newBuild().forTasks("build").withArguments("-PbootVersion=" + BOOT_VERSION, "-PbootRunMain=true").run();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonJavaExecRunTaskIsIgnored() {
|
||||
try {
|
||||
project.newBuild().forTasks("build").withArguments(
|
||||
"-PbootVersion=" + BOOT_VERSION, "-PnonJavaExecRun=true").run();
|
||||
project.newBuild().forTasks("build").withArguments("-PbootVersion=" + BOOT_VERSION, "-PnonJavaExecRun=true")
|
||||
.run();
|
||||
}
|
||||
catch (BuildException ex) {
|
||||
Throwable rootCause = getRootCause(ex);
|
||||
|
||||
@@ -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.
|
||||
@@ -49,16 +49,12 @@ public class MixedVersionRepackagingTests {
|
||||
@Test
|
||||
public void singleVersionIsIncludedInJar() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true",
|
||||
"-PexcludeDevtools=false")
|
||||
.run();
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true", "-PexcludeDevtools=false").run();
|
||||
File buildLibs = new File("target/mixed-version-repackaging/build/libs");
|
||||
File repackageFile = new File(buildLibs, "mixed-version-repackaging.jar");
|
||||
assertThat(repackageFile.exists()).isTrue();
|
||||
assertThat(new JarFile(repackageFile))
|
||||
.has(entryNamed("BOOT-INF/lib/guava-18.0.jar"));
|
||||
assertThat(new JarFile(repackageFile))
|
||||
.has(not(entryNamed("BOOT-INF/lib/guava-16.0.jar")));
|
||||
assertThat(new JarFile(repackageFile)).has(entryNamed("BOOT-INF/lib/guava-18.0.jar"));
|
||||
assertThat(new JarFile(repackageFile)).has(not(entryNamed("BOOT-INF/lib/guava-16.0.jar")));
|
||||
}
|
||||
|
||||
private Condition<JarFile> entryNamed(String name) {
|
||||
|
||||
@@ -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,41 +35,30 @@ public class MultiProjectRepackagingTests {
|
||||
|
||||
@Test
|
||||
public void repackageWithTransitiveFileDependency() throws Exception {
|
||||
ProjectConnection project = new ProjectCreator()
|
||||
.createProject("multi-project-transitive-file-dependency");
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION).run();
|
||||
File buildLibs = new File(
|
||||
"target/multi-project-transitive-file-dependency/main/build/libs");
|
||||
ProjectConnection project = new ProjectCreator().createProject("multi-project-transitive-file-dependency");
|
||||
project.newBuild().forTasks("clean", "build").withArguments("-PbootVersion=" + BOOT_VERSION).run();
|
||||
File buildLibs = new File("target/multi-project-transitive-file-dependency/main/build/libs");
|
||||
JarFile jarFile = new JarFile(new File(buildLibs, "main.jar"));
|
||||
assertThat(jarFile.getEntry("BOOT-INF/lib/commons-logging-1.1.3.jar"))
|
||||
.isNotNull();
|
||||
assertThat(jarFile.getEntry("BOOT-INF/lib/commons-logging-1.1.3.jar")).isNotNull();
|
||||
assertThat(jarFile.getEntry("BOOT-INF/lib/foo.jar")).isNotNull();
|
||||
jarFile.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repackageWithCommonFileDependency() throws Exception {
|
||||
ProjectConnection project = new ProjectCreator()
|
||||
.createProject("multi-project-common-file-dependency");
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION).run();
|
||||
File buildLibs = new File(
|
||||
"target/multi-project-common-file-dependency/build/libs");
|
||||
JarFile jarFile = new JarFile(
|
||||
new File(buildLibs, "multi-project-common-file-dependency.jar"));
|
||||
ProjectConnection project = new ProjectCreator().createProject("multi-project-common-file-dependency");
|
||||
project.newBuild().forTasks("clean", "build").withArguments("-PbootVersion=" + BOOT_VERSION).run();
|
||||
File buildLibs = new File("target/multi-project-common-file-dependency/build/libs");
|
||||
JarFile jarFile = new JarFile(new File(buildLibs, "multi-project-common-file-dependency.jar"));
|
||||
assertThat(jarFile.getEntry("BOOT-INF/lib/foo.jar")).isNotNull();
|
||||
jarFile.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repackageWithRuntimeProjectDependency() throws Exception {
|
||||
ProjectConnection project = new ProjectCreator()
|
||||
.createProject("multi-project-runtime-project-dependency");
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION).run();
|
||||
File buildLibs = new File(
|
||||
"target/multi-project-runtime-project-dependency/projectA/build/libs");
|
||||
ProjectConnection project = new ProjectCreator().createProject("multi-project-runtime-project-dependency");
|
||||
project.newBuild().forTasks("clean", "build").withArguments("-PbootVersion=" + BOOT_VERSION).run();
|
||||
File buildLibs = new File("target/multi-project-runtime-project-dependency/projectA/build/libs");
|
||||
JarFile jarFile = new JarFile(new File(buildLibs, "projectA.jar"));
|
||||
assertThat(jarFile.getEntry("BOOT-INF/lib/projectB.jar")).isNotNull();
|
||||
jarFile.close();
|
||||
|
||||
@@ -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.
|
||||
@@ -37,8 +37,7 @@ public class NoJarTests {
|
||||
@Test
|
||||
public void nojar() throws Exception {
|
||||
this.project = new ProjectCreator().createProject("nojar");
|
||||
this.project.newBuild().forTasks("build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
|
||||
this.project.newBuild().forTasks("build").withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
|
||||
assertThat(new File("target/nojar/build/libs")).doesNotExist();
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -48,12 +48,10 @@ public class ProjectCreator {
|
||||
File gradleScript = new File(projectDirectory, "build.gradle");
|
||||
|
||||
if (new File("src/test/resources", name).isDirectory()) {
|
||||
FileSystemUtils.copyRecursively(new File("src/test/resources", name),
|
||||
projectDirectory);
|
||||
FileSystemUtils.copyRecursively(new File("src/test/resources", name), projectDirectory);
|
||||
}
|
||||
else {
|
||||
FileCopyUtils.copy(new File("src/test/resources/" + name + ".gradle"),
|
||||
gradleScript);
|
||||
FileCopyUtils.copy(new File("src/test/resources/" + name + ".gradle"), gradleScript);
|
||||
}
|
||||
|
||||
GradleConnector gradleConnector = GradleConnector.newConnector();
|
||||
|
||||
@@ -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.
|
||||
@@ -47,53 +47,43 @@ public class RepackagingTests {
|
||||
|
||||
@Test
|
||||
public void repackagingEnabled() throws IOException {
|
||||
createBuildForTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run();
|
||||
createBuildForTasks("clean", "build").withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
File repackageFile = new File(buildLibs, "repackage.jar");
|
||||
assertThat(repackageFile.exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repackagingDisabled() {
|
||||
createBuildForTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=false")
|
||||
.run();
|
||||
createBuildForTasks("clean", "build").withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=false").run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
assertThat(new File(buildLibs, "repackage.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isFalse();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repackagingDisabledWithCustomRepackagedJar() {
|
||||
createBuildForTasks("clean", "build", "customRepackagedJar")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=false")
|
||||
.run();
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=false").run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
assertThat(new File(buildLibs, "repackage.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isFalse();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists()).isFalse();
|
||||
assertThat(new File(buildLibs, "custom.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "custom.jar.original").exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repackagingDisabledWithCustomRepackagedJarUsingStringJarTaskReference() {
|
||||
project.newBuild()
|
||||
.forTasks("clean", "build", "customRepackagedJarWithStringReference")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=false")
|
||||
.run();
|
||||
project.newBuild().forTasks("clean", "build", "customRepackagedJarWithStringReference")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=false").run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
assertThat(new File(buildLibs, "repackage.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isFalse();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists()).isFalse();
|
||||
assertThat(new File(buildLibs, "custom.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "custom.jar.original").exists()).isTrue();
|
||||
}
|
||||
@@ -105,32 +95,27 @@ public class RepackagingTests {
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
assertThat(new File(buildLibs, "repackage.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists()).isFalse();
|
||||
assertThat(new File(buildLibs, "custom.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "custom.jar.original").exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repackagingEnableWithCustomRepackagedJarUsingStringJarTaskReference() {
|
||||
project.newBuild()
|
||||
.forTasks("clean", "build", "customRepackagedJarWithStringReference")
|
||||
project.newBuild().forTasks("clean", "build", "customRepackagedJarWithStringReference")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
assertThat(new File(buildLibs, "repackage.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists()).isFalse();
|
||||
assertThat(new File(buildLibs, "custom.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "custom.jar.original").exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repackageWithFileDependency() throws Exception {
|
||||
FileCopyUtils.copy(new File("src/test/resources/foo.jar"),
|
||||
new File("target/repackage/foo.jar"));
|
||||
createBuildForTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run();
|
||||
FileCopyUtils.copy(new File("src/test/resources/foo.jar"), new File("target/repackage/foo.jar"));
|
||||
createBuildForTasks("clean", "build").withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
JarFile jarFile = new JarFile(new File(buildLibs, "repackage.jar"));
|
||||
assertThat(jarFile.getEntry("BOOT-INF/lib/foo.jar")).isNotNull();
|
||||
@@ -139,61 +124,51 @@ public class RepackagingTests {
|
||||
|
||||
@Test
|
||||
public void devtoolsIsExcludedByDefault() throws IOException {
|
||||
createBuildForTasks("clean", "bootRepackage")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run();
|
||||
createBuildForTasks("clean", "bootRepackage").withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true")
|
||||
.run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
File repackageFile = new File(buildLibs, "repackage.jar");
|
||||
assertThat(repackageFile.exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists()).isFalse();
|
||||
assertThat(isDevToolsJarIncluded(repackageFile)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void devtoolsCanBeIncludedUsingTheExtension() throws IOException {
|
||||
createBuildForTasks("clean", "bootRepackage")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true",
|
||||
"-PexcludeDevtoolsOnExtension=false")
|
||||
.run();
|
||||
createBuildForTasks("clean", "bootRepackage").withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true",
|
||||
"-PexcludeDevtoolsOnExtension=false").run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
File repackageFile = new File(buildLibs, "repackage.jar");
|
||||
assertThat(repackageFile.exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists()).isFalse();
|
||||
assertThat(isDevToolsJarIncluded(repackageFile)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void devtoolsCanBeIncludedUsingBootRepackage() throws IOException {
|
||||
createBuildForTasks("clean", "bootRepackage")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true",
|
||||
"-PexcludeDevtoolsOnBootRepackage=false")
|
||||
.run();
|
||||
createBuildForTasks("clean", "bootRepackage").withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true",
|
||||
"-PexcludeDevtoolsOnBootRepackage=false").run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
File repackageFile = new File(buildLibs, "repackage.jar");
|
||||
assertThat(repackageFile.exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists()).isFalse();
|
||||
assertThat(isDevToolsJarIncluded(repackageFile)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customRepackagingTaskWithOwnMainClassNameAnNoGlobalMainClassName() {
|
||||
createBuildForTasks("clean", "customRepackagedJarWithOwnMainClass")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true",
|
||||
"-PnoMainClass=true")
|
||||
.run();
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true", "-PnoMainClass=true").run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
assertThat(new File(buildLibs, "custom.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "custom.jar.original").exists()).isTrue();
|
||||
}
|
||||
|
||||
private BuildLauncher createBuildForTasks(String... taskNames) {
|
||||
return project.newBuild().setStandardError(System.err)
|
||||
.setStandardOutput(System.out).forTasks(taskNames);
|
||||
return project.newBuild().setStandardError(System.err).setStandardOutput(System.out).forTasks(taskNames);
|
||||
}
|
||||
|
||||
private boolean isDevToolsJarIncluded(File repackageFile) throws IOException {
|
||||
|
||||
@@ -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.
|
||||
@@ -40,25 +40,20 @@ public class SpringLoadedTests {
|
||||
private static final String SPRING_LOADED_VERSION = Versions.getSpringLoadedVersion();
|
||||
|
||||
@Test
|
||||
public void defaultJvmArgsArePreservedWhenLoadedAgentIsConfigured()
|
||||
throws IOException {
|
||||
ProjectConnection project = new ProjectCreator()
|
||||
.createProject("spring-loaded-jvm-args");
|
||||
project.newBuild().forTasks("bootRun")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION,
|
||||
"-PspringLoadedVersion=" + SPRING_LOADED_VERSION, "--stacktrace")
|
||||
.run();
|
||||
public void defaultJvmArgsArePreservedWhenLoadedAgentIsConfigured() throws IOException {
|
||||
ProjectConnection project = new ProjectCreator().createProject("spring-loaded-jvm-args");
|
||||
project.newBuild().forTasks("bootRun").withArguments("-PbootVersion=" + BOOT_VERSION,
|
||||
"-PspringLoadedVersion=" + SPRING_LOADED_VERSION, "--stacktrace").run();
|
||||
|
||||
List<String> output = getOutput();
|
||||
assertOutputContains("-DSOME_ARG=someValue", output);
|
||||
assertOutputContains("-Xverify:none", output);
|
||||
assertOutputMatches("-javaagent:.*springloaded-" + SPRING_LOADED_VERSION + ".jar",
|
||||
output);
|
||||
assertOutputMatches("-javaagent:.*springloaded-" + SPRING_LOADED_VERSION + ".jar", output);
|
||||
}
|
||||
|
||||
private List<String> getOutput() throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(
|
||||
new File("target/spring-loaded-jvm-args/build/output.txt")));
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new FileReader(new File("target/spring-loaded-jvm-args/build/output.txt")));
|
||||
try {
|
||||
List<String> lines = new ArrayList<String>();
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -33,20 +33,17 @@ public final class Versions {
|
||||
}
|
||||
|
||||
public static String getBootVersion() {
|
||||
return evaluateExpression(
|
||||
"/*[local-name()='project']/*[local-name()='version']" + "/text()");
|
||||
return evaluateExpression("/*[local-name()='project']/*[local-name()='version']" + "/text()");
|
||||
}
|
||||
|
||||
public static String getSpringLoadedVersion() {
|
||||
return evaluateExpression(
|
||||
"/*[local-name()='project']/*[local-name()='properties']"
|
||||
+ "/*[local-name()='spring-loaded.version']/text()");
|
||||
return evaluateExpression("/*[local-name()='project']/*[local-name()='properties']"
|
||||
+ "/*[local-name()='spring-loaded.version']/text()");
|
||||
}
|
||||
|
||||
public static String getSpringVersion() {
|
||||
return evaluateExpression(
|
||||
"/*[local-name()='project']/*[local-name()='properties']"
|
||||
+ "/*[local-name()='spring.version']/text()");
|
||||
"/*[local-name()='project']/*[local-name()='properties']" + "/*[local-name()='spring.version']/text()");
|
||||
}
|
||||
|
||||
private static String evaluateExpression(String expression) {
|
||||
@@ -54,8 +51,7 @@ public final class Versions {
|
||||
XPathFactory xPathFactory = XPathFactory.newInstance();
|
||||
XPath xpath = xPathFactory.newXPath();
|
||||
XPathExpression expr = xpath.compile(expression);
|
||||
String version = expr.evaluate(
|
||||
new InputSource(new FileReader("target/dependencies-pom.xml")));
|
||||
String version = expr.evaluate(new InputSource(new FileReader("target/dependencies-pom.xml")));
|
||||
return version;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
||||
@@ -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.
|
||||
@@ -45,20 +45,16 @@ public class WarPackagingTests {
|
||||
private static final String WEB_INF_LIB_PREFIX = "WEB-INF/lib/";
|
||||
|
||||
private static final Set<String> TOMCAT_EXPECTED_IN_WEB_INF_LIB_PROVIDED = new HashSet<String>(
|
||||
Arrays.asList("spring-boot-starter-tomcat-", "tomcat-annotations",
|
||||
"tomcat-embed-core-", "tomcat-embed-el-", "tomcat-embed-websocket-"));
|
||||
Arrays.asList("spring-boot-starter-tomcat-", "tomcat-annotations", "tomcat-embed-core-", "tomcat-embed-el-",
|
||||
"tomcat-embed-websocket-"));
|
||||
|
||||
private static final Set<String> JETTY_EXPECTED_IN_WEB_INF_LIB_PROVIDED = new HashSet<String>(
|
||||
Arrays.asList("spring-boot-starter-jetty-", "jetty-continuation",
|
||||
"jetty-util-", "javax.servlet-", "jetty-client", "jetty-io-",
|
||||
"jetty-http-", "jetty-server-", "jetty-security-", "jetty-servlet-",
|
||||
"jetty-servlets", "jetty-webapp-", "websocket-api",
|
||||
"javax.annotation-api", "jetty-plus", "javax-websocket-server-impl-",
|
||||
"apache-el", "asm-", "javax.websocket-api-", "asm-tree-",
|
||||
"asm-analysis-", "asm-commons-", "websocket-common-",
|
||||
"jetty-annotations-", "javax-websocket-client-impl-",
|
||||
"websocket-client-", "websocket-server-", "jetty-xml-",
|
||||
"websocket-servlet-"));
|
||||
private static final Set<String> JETTY_EXPECTED_IN_WEB_INF_LIB_PROVIDED = new HashSet<String>(Arrays.asList(
|
||||
"spring-boot-starter-jetty-", "jetty-continuation", "jetty-util-", "javax.servlet-", "jetty-client",
|
||||
"jetty-io-", "jetty-http-", "jetty-server-", "jetty-security-", "jetty-servlet-", "jetty-servlets",
|
||||
"jetty-webapp-", "websocket-api", "javax.annotation-api", "jetty-plus", "javax-websocket-server-impl-",
|
||||
"apache-el", "asm-", "javax.websocket-api-", "asm-tree-", "asm-analysis-", "asm-commons-",
|
||||
"websocket-common-", "jetty-annotations-", "javax-websocket-client-impl-", "websocket-client-",
|
||||
"websocket-server-", "jetty-xml-", "websocket-servlet-"));
|
||||
|
||||
private static final String BOOT_VERSION = Versions.getBootVersion();
|
||||
|
||||
@@ -71,22 +67,18 @@ public class WarPackagingTests {
|
||||
|
||||
@Test
|
||||
public void onlyTomcatIsPackagedInWebInfLibProvided() throws IOException {
|
||||
checkWebInfEntriesForServletContainer("tomcat",
|
||||
TOMCAT_EXPECTED_IN_WEB_INF_LIB_PROVIDED);
|
||||
checkWebInfEntriesForServletContainer("tomcat", TOMCAT_EXPECTED_IN_WEB_INF_LIB_PROVIDED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onlyJettyIsPackagedInWebInfLibProvided() throws IOException {
|
||||
checkWebInfEntriesForServletContainer("jetty",
|
||||
JETTY_EXPECTED_IN_WEB_INF_LIB_PROVIDED);
|
||||
checkWebInfEntriesForServletContainer("jetty", JETTY_EXPECTED_IN_WEB_INF_LIB_PROVIDED);
|
||||
}
|
||||
|
||||
private void checkWebInfEntriesForServletContainer(String servletContainer,
|
||||
Set<String> expectedLibProvidedEntries) throws IOException {
|
||||
private void checkWebInfEntriesForServletContainer(String servletContainer, Set<String> expectedLibProvidedEntries)
|
||||
throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION,
|
||||
"-PservletContainer=" + servletContainer)
|
||||
.run();
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PservletContainer=" + servletContainer).run();
|
||||
|
||||
JarFile war = new JarFile("target/war-packaging/build/libs/war-packaging.war");
|
||||
|
||||
@@ -102,8 +94,7 @@ public class WarPackagingTests {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkWebInfLibProvidedEntries(JarFile war, Set<String> expectedEntries)
|
||||
throws IOException {
|
||||
private void checkWebInfLibProvidedEntries(JarFile war, Set<String> expectedEntries) throws IOException {
|
||||
Set<String> entries = getWebInfLibProvidedEntries(war);
|
||||
assertThat(entries).hasSameSizeAs(expectedEntries);
|
||||
List<String> unexpectedLibProvidedEntries = new ArrayList<String>();
|
||||
@@ -115,8 +106,7 @@ public class WarPackagingTests {
|
||||
assertThat(unexpectedLibProvidedEntries.isEmpty());
|
||||
}
|
||||
|
||||
private void checkWebInfLibEntries(JarFile war, Set<String> entriesOnlyInLibProvided)
|
||||
throws IOException {
|
||||
private void checkWebInfLibEntries(JarFile war, Set<String> entriesOnlyInLibProvided) throws IOException {
|
||||
Set<String> entries = getWebInfLibEntries(war);
|
||||
List<String> unexpectedLibEntries = new ArrayList<String>();
|
||||
for (String entry : entries) {
|
||||
@@ -152,16 +142,14 @@ public class WarPackagingTests {
|
||||
}
|
||||
|
||||
private boolean isWebInfLibProvidedEntry(String name) {
|
||||
return name.startsWith(WEB_INF_LIB_PROVIDED_PREFIX)
|
||||
&& !name.equals(WEB_INF_LIB_PROVIDED_PREFIX);
|
||||
return name.startsWith(WEB_INF_LIB_PROVIDED_PREFIX) && !name.equals(WEB_INF_LIB_PROVIDED_PREFIX);
|
||||
}
|
||||
|
||||
private boolean isWebInfLibEntry(String name) {
|
||||
return name.startsWith(WEB_INF_LIB_PREFIX) && !name.equals(WEB_INF_LIB_PREFIX);
|
||||
}
|
||||
|
||||
private boolean isExpectedInWebInfLibProvided(String name,
|
||||
Set<String> expectedEntries) {
|
||||
private boolean isExpectedInWebInfLibProvided(String name, Set<String> expectedEntries) {
|
||||
for (String expected : expectedEntries) {
|
||||
if (name.startsWith(WEB_INF_LIB_PROVIDED_PREFIX + expected)) {
|
||||
return true;
|
||||
|
||||
@@ -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.
|
||||
@@ -45,8 +45,7 @@ public class StarterDependenciesIntegrationTests {
|
||||
|
||||
private static final String STARTER_NAME_PREFIX = "spring-boot-starter";
|
||||
|
||||
private static final List<String> EXCLUDED_STARTERS = Arrays
|
||||
.asList("spring-boot-starter-parent");
|
||||
private static final List<String> EXCLUDED_STARTERS = Arrays.asList("spring-boot-starter-parent");
|
||||
|
||||
private static ProjectConnection project;
|
||||
|
||||
@@ -62,8 +61,7 @@ public class StarterDependenciesIntegrationTests {
|
||||
for (File file : new File("../../spring-boot-starters").listFiles()) {
|
||||
if (file.isDirectory() && new File(file, "pom.xml").exists()) {
|
||||
String name = file.getName();
|
||||
if (name.startsWith(STARTER_NAME_PREFIX)
|
||||
&& !EXCLUDED_STARTERS.contains(file.getName())) {
|
||||
if (name.startsWith(STARTER_NAME_PREFIX) && !EXCLUDED_STARTERS.contains(file.getName())) {
|
||||
starters.add(new String[] { file.getName() });
|
||||
}
|
||||
}
|
||||
@@ -88,8 +86,8 @@ public class StarterDependenciesIntegrationTests {
|
||||
}
|
||||
|
||||
public StarterDependenciesIntegrationTests(String starter) {
|
||||
this.buildArguments = new String[] { "-Pstarter=" + starter,
|
||||
"-PbootVersion=" + bootVersion, "-PspringVersion=" + springVersion };
|
||||
this.buildArguments = new String[] { "-Pstarter=" + starter, "-PbootVersion=" + bootVersion,
|
||||
"-PspringVersion=" + springVersion };
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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.
|
||||
@@ -39,32 +39,28 @@ import org.springframework.context.annotation.Bean;
|
||||
public class ResourceHandlingApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(ResourceHandlingApplication.class)
|
||||
.properties("server.port:0")
|
||||
.listeners(new EmbeddedServerPortFileWriter("target/server.port"))
|
||||
.run(args);
|
||||
new SpringApplicationBuilder(ResourceHandlingApplication.class).properties("server.port:0")
|
||||
.listeners(new EmbeddedServerPortFileWriter("target/server.port")).run(args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServletRegistrationBean resourceServletRegistration() {
|
||||
ServletRegistrationBean registration = new ServletRegistrationBean(
|
||||
new HttpServlet() {
|
||||
ServletRegistrationBean registration = new ServletRegistrationBean(new HttpServlet() {
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
URL resource = getServletContext()
|
||||
.getResource(req.getQueryString());
|
||||
if (resource == null) {
|
||||
resp.sendError(404);
|
||||
}
|
||||
else {
|
||||
resp.getWriter().println(resource);
|
||||
resp.getWriter().flush();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
URL resource = getServletContext().getResource(req.getQueryString());
|
||||
if (resource == null) {
|
||||
resp.sendError(404);
|
||||
}
|
||||
else {
|
||||
resp.getWriter().println(resource);
|
||||
resp.getWriter().flush();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
registration.addUrlMappings("/servletContext");
|
||||
return registration;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -66,16 +66,14 @@ abstract class AbstractApplicationLauncher extends ExternalResource {
|
||||
|
||||
private Process startApplication() throws Exception {
|
||||
File workingDirectory = getWorkingDirectory();
|
||||
File serverPortFile = (workingDirectory != null)
|
||||
? new File(workingDirectory, "target/server.port")
|
||||
File serverPortFile = (workingDirectory != null) ? new File(workingDirectory, "target/server.port")
|
||||
: new File("target/server.port");
|
||||
serverPortFile.delete();
|
||||
File archive = this.applicationBuilder.buildApplication();
|
||||
List<String> arguments = new ArrayList<String>();
|
||||
arguments.add(System.getProperty("java.home") + "/bin/java");
|
||||
arguments.addAll(getArguments(archive));
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(
|
||||
arguments.toArray(new String[arguments.size()]));
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(arguments.toArray(new String[arguments.size()]));
|
||||
processBuilder.redirectOutput(Redirect.INHERIT);
|
||||
processBuilder.redirectError(Redirect.INHERIT);
|
||||
if (workingDirectory != null) {
|
||||
@@ -90,16 +88,14 @@ abstract class AbstractApplicationLauncher extends ExternalResource {
|
||||
long end = System.currentTimeMillis() + 30000;
|
||||
while (serverPortFile.length() == 0) {
|
||||
if (System.currentTimeMillis() > end) {
|
||||
throw new IllegalStateException(
|
||||
"server.port file was not written within 30 seconds");
|
||||
throw new IllegalStateException("server.port file was not written within 30 seconds");
|
||||
}
|
||||
if (!process.isAlive()) {
|
||||
throw new IllegalStateException("Application failed to launch");
|
||||
}
|
||||
Thread.sleep(100);
|
||||
}
|
||||
return Integer
|
||||
.parseInt(FileCopyUtils.copyToString(new FileReader(serverPortFile)));
|
||||
return Integer.parseInt(FileCopyUtils.copyToString(new FileReader(serverPortFile)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -52,27 +52,25 @@ public abstract class AbstractEmbeddedServletContainerIntegrationTests {
|
||||
public static Object[] parameters(String packaging,
|
||||
List<Class<? extends AbstractApplicationLauncher>> applicationLaunchers) {
|
||||
List<Object> parameters = new ArrayList<Object>();
|
||||
parameters.addAll(createParameters(packaging, "jetty",
|
||||
Arrays.asList("current", "9.3.16.v20170120"), applicationLaunchers));
|
||||
parameters.addAll(createParameters(packaging, "tomcat",
|
||||
Arrays.asList("current", "8.0.41", "7.0.75"), applicationLaunchers));
|
||||
parameters.addAll(createParameters(packaging, "undertow",
|
||||
Collections.singletonList("current"), applicationLaunchers));
|
||||
parameters.addAll(createParameters(packaging, "jetty", Arrays.asList("current", "9.3.16.v20170120"),
|
||||
applicationLaunchers));
|
||||
parameters.addAll(createParameters(packaging, "tomcat", Arrays.asList("current", "8.0.41", "7.0.75"),
|
||||
applicationLaunchers));
|
||||
parameters.addAll(
|
||||
createParameters(packaging, "undertow", Collections.singletonList("current"), applicationLaunchers));
|
||||
return parameters.toArray(new Object[parameters.size()]);
|
||||
}
|
||||
|
||||
private static List<Object> createParameters(String packaging, String container,
|
||||
List<String> versions,
|
||||
private static List<Object> createParameters(String packaging, String container, List<String> versions,
|
||||
List<Class<? extends AbstractApplicationLauncher>> applicationLaunchers) {
|
||||
List<Object> parameters = new ArrayList<Object>();
|
||||
for (String version : versions) {
|
||||
ApplicationBuilder applicationBuilder = new ApplicationBuilder(
|
||||
temporaryFolder, packaging, container, version);
|
||||
ApplicationBuilder applicationBuilder = new ApplicationBuilder(temporaryFolder, packaging, container,
|
||||
version);
|
||||
for (Class<? extends AbstractApplicationLauncher> launcherClass : applicationLaunchers) {
|
||||
try {
|
||||
AbstractApplicationLauncher launcher = launcherClass
|
||||
.getDeclaredConstructor(ApplicationBuilder.class)
|
||||
.newInstance(applicationBuilder);
|
||||
.getDeclaredConstructor(ApplicationBuilder.class).newInstance(applicationBuilder);
|
||||
String name = StringUtils.capitalize(container) + " " + version + ": "
|
||||
+ launcher.getDescription(packaging);
|
||||
parameters.add(new Object[] { name, launcher });
|
||||
@@ -85,8 +83,7 @@ public abstract class AbstractEmbeddedServletContainerIntegrationTests {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
protected AbstractEmbeddedServletContainerIntegrationTests(String name,
|
||||
AbstractApplicationLauncher launcher) {
|
||||
protected AbstractEmbeddedServletContainerIntegrationTests(String name, AbstractApplicationLauncher launcher) {
|
||||
this.launcher = launcher;
|
||||
this.rest.setErrorHandler(new ResponseErrorHandler() {
|
||||
|
||||
@@ -105,14 +102,12 @@ public abstract class AbstractEmbeddedServletContainerIntegrationTests {
|
||||
|
||||
@Override
|
||||
public URI expand(String uriTemplate, Object... uriVariables) {
|
||||
return URI.create(
|
||||
"http://localhost:" + launcher.getHttpPort() + uriTemplate);
|
||||
return URI.create("http://localhost:" + launcher.getHttpPort() + uriTemplate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI expand(String uriTemplate, Map<String, ?> uriVariables) {
|
||||
return URI.create(
|
||||
"http://localhost:" + launcher.getHttpPort() + uriTemplate);
|
||||
return URI.create("http://localhost:" + launcher.getHttpPort() + uriTemplate);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -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.
|
||||
@@ -58,8 +58,7 @@ class ApplicationBuilder {
|
||||
|
||||
private final String containerVersion;
|
||||
|
||||
ApplicationBuilder(TemporaryFolder temp, String packaging, String container,
|
||||
String containerVersion) {
|
||||
ApplicationBuilder(TemporaryFolder temp, String packaging, String container, String containerVersion) {
|
||||
this.temp = temp;
|
||||
this.packaging = packaging;
|
||||
this.container = container;
|
||||
@@ -67,8 +66,7 @@ class ApplicationBuilder {
|
||||
}
|
||||
|
||||
File buildApplication() throws Exception {
|
||||
File containerFolder = new File(this.temp.getRoot(),
|
||||
this.container + "-" + this.containerVersion);
|
||||
File containerFolder = new File(this.temp.getRoot(), this.container + "-" + this.containerVersion);
|
||||
if (containerFolder.exists()) {
|
||||
return new File(containerFolder, "app/target/app-0.0.1." + this.packaging);
|
||||
}
|
||||
@@ -91,33 +89,27 @@ class ApplicationBuilder {
|
||||
if (resourcesJar.exists()) {
|
||||
return resourcesJar;
|
||||
}
|
||||
JarOutputStream resourcesJarStream = new JarOutputStream(
|
||||
new FileOutputStream(resourcesJar));
|
||||
JarOutputStream resourcesJarStream = new JarOutputStream(new FileOutputStream(resourcesJar));
|
||||
resourcesJarStream.putNextEntry(new ZipEntry("META-INF/resources/"));
|
||||
resourcesJarStream.closeEntry();
|
||||
resourcesJarStream.putNextEntry(
|
||||
new ZipEntry("META-INF/resources/nested-meta-inf-resource.txt"));
|
||||
resourcesJarStream.putNextEntry(new ZipEntry("META-INF/resources/nested-meta-inf-resource.txt"));
|
||||
resourcesJarStream.write("nested".getBytes());
|
||||
resourcesJarStream.closeEntry();
|
||||
resourcesJarStream.close();
|
||||
return resourcesJar;
|
||||
}
|
||||
|
||||
private void writePom(File appFolder, File resourcesJar)
|
||||
throws FileNotFoundException, IOException {
|
||||
private void writePom(File appFolder, File resourcesJar) throws FileNotFoundException, IOException {
|
||||
Map<String, Object> context = new HashMap<String, Object>();
|
||||
context.put("packaging", this.packaging);
|
||||
context.put("container", this.container);
|
||||
context.put("bootVersion", Versions.getBootVersion());
|
||||
context.put("resourcesJarPath", resourcesJar.getAbsolutePath());
|
||||
context.put("containerVersion",
|
||||
"current".equals(this.containerVersion) ? ""
|
||||
: String.format("<%s.version>%s</%s.version>", this.container,
|
||||
this.containerVersion, this.container));
|
||||
context.put("containerVersion", "current".equals(this.containerVersion) ? ""
|
||||
: String.format("<%s.version>%s</%s.version>", this.container, this.containerVersion, this.container));
|
||||
context.put("additionalDependencies", getAdditionalDependencies());
|
||||
FileWriter out = new FileWriter(new File(appFolder, "pom.xml"));
|
||||
Mustache.compiler().escapeHTML(false)
|
||||
.compile(new FileReader("src/test/resources/pom-template.xml"))
|
||||
Mustache.compiler().escapeHTML(false).compile(new FileReader("src/test/resources/pom-template.xml"))
|
||||
.execute(context, out);
|
||||
out.close();
|
||||
}
|
||||
@@ -137,14 +129,12 @@ class ApplicationBuilder {
|
||||
private void copyApplicationSource(File appFolder) throws IOException {
|
||||
File examplePackage = new File(appFolder, "src/main/java/com/example");
|
||||
examplePackage.mkdirs();
|
||||
FileCopyUtils.copy(
|
||||
new File("src/test/java/com/example/ResourceHandlingApplication.java"),
|
||||
FileCopyUtils.copy(new File("src/test/java/com/example/ResourceHandlingApplication.java"),
|
||||
new File(examplePackage, "ResourceHandlingApplication.java"));
|
||||
if ("war".equals(this.packaging)) {
|
||||
File srcMainWebapp = new File(appFolder, "src/main/webapp");
|
||||
srcMainWebapp.mkdirs();
|
||||
FileCopyUtils.copy("webapp resource",
|
||||
new FileWriter(new File(srcMainWebapp, "webapp-resource.txt")));
|
||||
FileCopyUtils.copy("webapp resource", new FileWriter(new File(srcMainWebapp, "webapp-resource.txt")));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -61,9 +61,7 @@ class BootRunApplicationLauncher extends AbstractApplicationLauncher {
|
||||
for (File dependency : dependencies.listFiles()) {
|
||||
classpath.add(dependency.getAbsolutePath());
|
||||
}
|
||||
return Arrays.asList("-cp",
|
||||
StringUtils.collectionToDelimitedString(classpath,
|
||||
File.pathSeparator),
|
||||
return Arrays.asList("-cp", StringUtils.collectionToDelimitedString(classpath, File.pathSeparator),
|
||||
"com.example.ResourceHandlingApplication");
|
||||
}
|
||||
catch (IOException ex) {
|
||||
@@ -107,13 +105,11 @@ class BootRunApplicationLauncher extends AbstractApplicationLauncher {
|
||||
}
|
||||
|
||||
private String getClassesPath(File archive) {
|
||||
return (archive.getName().endsWith(".jar") ? "BOOT-INF/classes"
|
||||
: "WEB-INF/classes");
|
||||
return (archive.getName().endsWith(".jar") ? "BOOT-INF/classes" : "WEB-INF/classes");
|
||||
}
|
||||
|
||||
private List<String> getLibPaths(File archive) {
|
||||
return (archive.getName().endsWith(".jar")
|
||||
? Collections.singletonList("BOOT-INF/lib")
|
||||
return (archive.getName().endsWith(".jar") ? Collections.singletonList("BOOT-INF/lib")
|
||||
: Arrays.asList("WEB-INF/lib", "WEB-INF/lib-provided"));
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -40,27 +40,24 @@ public class EmbeddedServletContainerJarDevelopmentIntegrationTests
|
||||
|
||||
@Parameters(name = "{0}")
|
||||
public static Object[] parameters() {
|
||||
return AbstractEmbeddedServletContainerIntegrationTests.parameters("jar", Arrays
|
||||
.asList(BootRunApplicationLauncher.class, IdeApplicationLauncher.class));
|
||||
return AbstractEmbeddedServletContainerIntegrationTests.parameters("jar",
|
||||
Arrays.asList(BootRunApplicationLauncher.class, IdeApplicationLauncher.class));
|
||||
}
|
||||
|
||||
public EmbeddedServletContainerJarDevelopmentIntegrationTests(String name,
|
||||
AbstractApplicationLauncher launcher) {
|
||||
public EmbeddedServletContainerJarDevelopmentIntegrationTests(String name, AbstractApplicationLauncher launcher) {
|
||||
super(name, launcher);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaInfResourceFromDependencyIsAvailableViaHttp() throws Exception {
|
||||
ResponseEntity<String> entity = this.rest
|
||||
.getForEntity("/nested-meta-inf-resource.txt", String.class);
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/nested-meta-inf-resource.txt", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaInfResourceFromDependencyIsAvailableViaServletContext()
|
||||
throws Exception {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity(
|
||||
"/servletContext?/nested-meta-inf-resource.txt", String.class);
|
||||
public void metaInfResourceFromDependencyIsAvailableViaServletContext() throws Exception {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/servletContext?/nested-meta-inf-resource.txt",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -41,48 +41,43 @@ public class EmbeddedServletContainerJarPackagingIntegrationTests
|
||||
@Parameters(name = "{0}")
|
||||
public static Object[] parameters() {
|
||||
return AbstractEmbeddedServletContainerIntegrationTests.parameters("jar",
|
||||
Arrays.asList(PackagedApplicationLauncher.class,
|
||||
ExplodedApplicationLauncher.class));
|
||||
Arrays.asList(PackagedApplicationLauncher.class, ExplodedApplicationLauncher.class));
|
||||
}
|
||||
|
||||
public EmbeddedServletContainerJarPackagingIntegrationTests(String name,
|
||||
AbstractApplicationLauncher launcher) {
|
||||
public EmbeddedServletContainerJarPackagingIntegrationTests(String name, AbstractApplicationLauncher launcher) {
|
||||
super(name, launcher);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedMetaInfResourceIsAvailableViaHttp() throws Exception {
|
||||
ResponseEntity<String> entity = this.rest
|
||||
.getForEntity("/nested-meta-inf-resource.txt", String.class);
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/nested-meta-inf-resource.txt", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedMetaInfResourceIsAvailableViaServletContext() throws Exception {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity(
|
||||
"/servletContext?/nested-meta-inf-resource.txt", String.class);
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/servletContext?/nested-meta-inf-resource.txt",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedJarIsNotAvailableViaHttp() throws Exception {
|
||||
ResponseEntity<String> entity = this.rest
|
||||
.getForEntity("/BOOT-INF/lib/resources-1.0.jar", String.class);
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/BOOT-INF/lib/resources-1.0.jar", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationClassesAreNotAvailableViaHttp() throws Exception {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity(
|
||||
"/BOOT-INF/classes/com/example/ResourceHandlingApplication.class",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = this.rest
|
||||
.getForEntity("/BOOT-INF/classes/com/example/ResourceHandlingApplication.class", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launcherIsNotAvailableViaHttp() throws Exception {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity(
|
||||
"/org/springframework/boot/loader/Launcher.class", String.class);
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/org/springframework/boot/loader/Launcher.class",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -40,34 +40,30 @@ public class EmbeddedServletContainerWarDevelopmentIntegrationTests
|
||||
|
||||
@Parameters(name = "{0}")
|
||||
public static Object[] parameters() {
|
||||
return AbstractEmbeddedServletContainerIntegrationTests.parameters("war", Arrays
|
||||
.asList(BootRunApplicationLauncher.class, IdeApplicationLauncher.class));
|
||||
return AbstractEmbeddedServletContainerIntegrationTests.parameters("war",
|
||||
Arrays.asList(BootRunApplicationLauncher.class, IdeApplicationLauncher.class));
|
||||
}
|
||||
|
||||
public EmbeddedServletContainerWarDevelopmentIntegrationTests(String name,
|
||||
AbstractApplicationLauncher launcher) {
|
||||
public EmbeddedServletContainerWarDevelopmentIntegrationTests(String name, AbstractApplicationLauncher launcher) {
|
||||
super(name, launcher);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaInfResourceFromDependencyIsAvailableViaHttp() throws Exception {
|
||||
ResponseEntity<String> entity = this.rest
|
||||
.getForEntity("/nested-meta-inf-resource.txt", String.class);
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/nested-meta-inf-resource.txt", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaInfResourceFromDependencyIsAvailableViaServletContext()
|
||||
throws Exception {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity(
|
||||
"/servletContext?/nested-meta-inf-resource.txt", String.class);
|
||||
public void metaInfResourceFromDependencyIsAvailableViaServletContext() throws Exception {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/servletContext?/nested-meta-inf-resource.txt",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webappResourcesAreAvailableViaHttp() throws Exception {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/webapp-resource.txt",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/webapp-resource.txt", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -41,48 +41,42 @@ public class EmbeddedServletContainerWarPackagingIntegrationTests
|
||||
@Parameters(name = "{0}")
|
||||
public static Object[] parameters() {
|
||||
return AbstractEmbeddedServletContainerIntegrationTests.parameters("war",
|
||||
Arrays.asList(PackagedApplicationLauncher.class,
|
||||
ExplodedApplicationLauncher.class));
|
||||
Arrays.asList(PackagedApplicationLauncher.class, ExplodedApplicationLauncher.class));
|
||||
}
|
||||
|
||||
public EmbeddedServletContainerWarPackagingIntegrationTests(String name,
|
||||
AbstractApplicationLauncher launcher) {
|
||||
public EmbeddedServletContainerWarPackagingIntegrationTests(String name, AbstractApplicationLauncher launcher) {
|
||||
super(name, launcher);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedMetaInfResourceIsAvailableViaHttp() throws Exception {
|
||||
ResponseEntity<String> entity = this.rest
|
||||
.getForEntity("/nested-meta-inf-resource.txt", String.class);
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/nested-meta-inf-resource.txt", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedMetaInfResourceIsAvailableViaServletContext() throws Exception {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity(
|
||||
"/servletContext?/nested-meta-inf-resource.txt", String.class);
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/servletContext?/nested-meta-inf-resource.txt",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedJarIsNotAvailableViaHttp() throws Exception {
|
||||
ResponseEntity<String> entity = this.rest
|
||||
.getForEntity("/WEB-INF/lib/resources-1.0.jar", String.class);
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/WEB-INF/lib/resources-1.0.jar", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationClassesAreNotAvailableViaHttp() throws Exception {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity(
|
||||
"/WEB-INF/classes/com/example/ResourceHandlingApplication.class",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = this.rest
|
||||
.getForEntity("/WEB-INF/classes/com/example/ResourceHandlingApplication.class", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webappResourcesAreAvailableViaHttp() throws Exception {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/webapp-resource.txt",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/webapp-resource.txt", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -54,8 +54,7 @@ class ExplodedApplicationLauncher extends AbstractApplicationLauncher {
|
||||
|
||||
@Override
|
||||
protected List<String> getArguments(File archive) {
|
||||
String mainClass = (archive.getName().endsWith(".war")
|
||||
? "org.springframework.boot.loader.WarLauncher"
|
||||
String mainClass = (archive.getName().endsWith(".war") ? "org.springframework.boot.loader.WarLauncher"
|
||||
: "org.springframework.boot.loader.JarLauncher");
|
||||
try {
|
||||
explodeArchive(archive);
|
||||
|
||||
@@ -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.
|
||||
@@ -73,9 +73,7 @@ class IdeApplicationLauncher extends AbstractApplicationLauncher {
|
||||
classpath.add(dependency.getAbsolutePath());
|
||||
}
|
||||
classpath.add(resourcesProject.getAbsolutePath());
|
||||
return Arrays.asList("-cp",
|
||||
StringUtils.collectionToDelimitedString(classpath,
|
||||
File.pathSeparator),
|
||||
return Arrays.asList("-cp", StringUtils.collectionToDelimitedString(classpath, File.pathSeparator),
|
||||
"com.example.ResourceHandlingApplication");
|
||||
}
|
||||
catch (IOException ex) {
|
||||
@@ -107,8 +105,7 @@ class IdeApplicationLauncher extends AbstractApplicationLauncher {
|
||||
}
|
||||
|
||||
private File explodedResourcesProject(File dependencies) throws IOException {
|
||||
File resourcesProject = new File(this.exploded,
|
||||
"resources-project/target/classes");
|
||||
File resourcesProject = new File(this.exploded, "resources-project/target/classes");
|
||||
File resourcesJar = new File(dependencies, "resources-1.0.jar");
|
||||
explodeArchive(resourcesJar, resourcesProject);
|
||||
resourcesJar.delete();
|
||||
@@ -128,13 +125,11 @@ class IdeApplicationLauncher extends AbstractApplicationLauncher {
|
||||
}
|
||||
|
||||
private String getClassesPath(File archive) {
|
||||
return (archive.getName().endsWith(".jar") ? "BOOT-INF/classes"
|
||||
: "WEB-INF/classes");
|
||||
return (archive.getName().endsWith(".jar") ? "BOOT-INF/classes" : "WEB-INF/classes");
|
||||
}
|
||||
|
||||
private List<String> getLibPaths(File archive) {
|
||||
return (archive.getName().endsWith(".jar")
|
||||
? Collections.singletonList("BOOT-INF/lib")
|
||||
return (archive.getName().endsWith(".jar") ? Collections.singletonList("BOOT-INF/lib")
|
||||
: Arrays.asList("WEB-INF/lib", "WEB-INF/lib-provided"));
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -36,8 +36,7 @@ final class Versions {
|
||||
|
||||
public static String getBootVersion() {
|
||||
return evaluateExpression(
|
||||
"/*[local-name()='project']/*[local-name()='parent']/*[local-name()='version']"
|
||||
+ "/text()");
|
||||
"/*[local-name()='project']/*[local-name()='parent']/*[local-name()='version']" + "/text()");
|
||||
}
|
||||
|
||||
private static String evaluateExpression(String expression) {
|
||||
|
||||
@@ -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.
|
||||
@@ -102,70 +102,60 @@ public class SysVinitLaunchScriptIT {
|
||||
public void statusWhenStarted() throws Exception {
|
||||
String output = doTest("status-when-started.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(
|
||||
coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusWhenKilled() throws Exception {
|
||||
String output = doTest("status-when-killed.sh");
|
||||
assertThat(output).contains("Status: 1");
|
||||
assertThat(output).has(coloredString(AnsiColor.RED,
|
||||
"Not running (process " + extractPid(output) + " not found)"));
|
||||
assertThat(output)
|
||||
.has(coloredString(AnsiColor.RED, "Not running (process " + extractPid(output) + " not found)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stopWhenStopped() throws Exception {
|
||||
String output = doTest("stop-when-stopped.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output)
|
||||
.has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
||||
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forceStopWhenStopped() throws Exception {
|
||||
String output = doTest("force-stop-when-stopped.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output)
|
||||
.has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
||||
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWhenStarted() throws Exception {
|
||||
String output = doTest("start-when-started.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(coloredString(AnsiColor.YELLOW,
|
||||
"Already running [" + extractPid(output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Already running [" + extractPid(output) + "]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restartWhenStopped() throws Exception {
|
||||
String output = doTest("restart-when-stopped.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output)
|
||||
.has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
||||
assertThat(output).has(
|
||||
coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restartWhenStarted() throws Exception {
|
||||
String output = doTest("restart-when-started.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN,
|
||||
"Started [" + extract("PID1", output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN,
|
||||
"Stopped [" + extract("PID1", output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN,
|
||||
"Started [" + extract("PID2", output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extract("PID1", output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Stopped [" + extract("PID1", output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extract("PID2", output) + "]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWhenStopped() throws Exception {
|
||||
String output = doTest("start-when-stopped.sh");
|
||||
assertThat(output).contains("Status: 0");
|
||||
assertThat(output).has(
|
||||
coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -213,12 +203,9 @@ public class SysVinitLaunchScriptIT {
|
||||
@Test
|
||||
public void launchWithRelativePidFolder() throws Exception {
|
||||
String output = doTest("launch-with-relative-pid-folder.sh");
|
||||
assertThat(output).has(
|
||||
coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
||||
assertThat(output).has(
|
||||
coloredString(AnsiColor.GREEN, "Running [" + extractPid(output) + "]"));
|
||||
assertThat(output).has(
|
||||
coloredString(AnsiColor.GREEN, "Stopped [" + extractPid(output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Running [" + extractPid(output) + "]"));
|
||||
assertThat(output).has(coloredString(AnsiColor.GREEN, "Stopped [" + extractPid(output) + "]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -269,10 +256,8 @@ public class SysVinitLaunchScriptIT {
|
||||
copyFilesToContainer(docker, container, script);
|
||||
docker.startContainerCmd(container).exec();
|
||||
StringBuilder output = new StringBuilder();
|
||||
AttachContainerResultCallback resultCallback = docker
|
||||
.attachContainerCmd(container).withStdOut(true).withStdErr(true)
|
||||
.withFollowStream(true).withLogs(true)
|
||||
.exec(new AttachContainerResultCallback() {
|
||||
AttachContainerResultCallback resultCallback = docker.attachContainerCmd(container).withStdOut(true)
|
||||
.withStdErr(true).withFollowStream(true).withLogs(true).exec(new AttachContainerResultCallback() {
|
||||
|
||||
@Override
|
||||
public void onNext(Frame item) {
|
||||
@@ -298,17 +283,14 @@ public class SysVinitLaunchScriptIT {
|
||||
}
|
||||
|
||||
private DockerClient createClient() {
|
||||
DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
|
||||
.withApiVersion("1.19").build();
|
||||
return DockerClientBuilder.getInstance(config)
|
||||
.withDockerCmdExecFactory(this.commandExecFactory).build();
|
||||
DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder().withApiVersion("1.19")
|
||||
.build();
|
||||
return DockerClientBuilder.getInstance(config).withDockerCmdExecFactory(this.commandExecFactory).build();
|
||||
}
|
||||
|
||||
private String buildImage(DockerClient docker) {
|
||||
String dockerfile = "src/test/resources/conf/" + this.os + "/" + this.version
|
||||
+ "/Dockerfile";
|
||||
String tag = "spring-boot-it/" + this.os.toLowerCase(Locale.ENGLISH) + ":"
|
||||
+ this.version;
|
||||
String dockerfile = "src/test/resources/conf/" + this.os + "/" + this.version + "/Dockerfile";
|
||||
String tag = "spring-boot-it/" + this.os.toLowerCase(Locale.ENGLISH) + ":" + this.version;
|
||||
BuildImageResultCallback resultCallback = new BuildImageResultCallback() {
|
||||
|
||||
private List<BuildResponseItem> items = new ArrayList<BuildResponseItem>();
|
||||
@@ -325,8 +307,7 @@ public class SysVinitLaunchScriptIT {
|
||||
awaitCompletion();
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
throw new DockerClientException(
|
||||
"Interrupted while waiting for image id", ex);
|
||||
throw new DockerClientException("Interrupted while waiting for image id", ex);
|
||||
}
|
||||
return getImageId();
|
||||
}
|
||||
@@ -338,8 +319,8 @@ public class SysVinitLaunchScriptIT {
|
||||
}
|
||||
String imageId = extractImageId();
|
||||
if (imageId == null) {
|
||||
throw new DockerClientException("Could not build image: "
|
||||
+ this.items.get(this.items.size() - 1).getError());
|
||||
throw new DockerClientException(
|
||||
"Could not build image: " + this.items.get(this.items.size() - 1).getError());
|
||||
}
|
||||
return imageId;
|
||||
}
|
||||
@@ -358,38 +339,31 @@ public class SysVinitLaunchScriptIT {
|
||||
}
|
||||
|
||||
};
|
||||
docker.buildImageCmd(new File(dockerfile))
|
||||
.withTags(new HashSet<String>(Arrays.asList(tag))).exec(resultCallback);
|
||||
docker.buildImageCmd(new File(dockerfile)).withTags(new HashSet<String>(Arrays.asList(tag)))
|
||||
.exec(resultCallback);
|
||||
String imageId = resultCallback.awaitImageId();
|
||||
return imageId;
|
||||
}
|
||||
|
||||
private String createContainer(DockerClient docker, String imageId,
|
||||
String testScript) {
|
||||
return docker.createContainerCmd(imageId).withTty(false).withCmd("/bin/bash",
|
||||
"-c", "chmod +x " + testScript + " && ./" + testScript).exec().getId();
|
||||
private String createContainer(DockerClient docker, String imageId, String testScript) {
|
||||
return docker.createContainerCmd(imageId).withTty(false)
|
||||
.withCmd("/bin/bash", "-c", "chmod +x " + testScript + " && ./" + testScript).exec().getId();
|
||||
}
|
||||
|
||||
private void copyFilesToContainer(DockerClient docker, final String container,
|
||||
String script) {
|
||||
private void copyFilesToContainer(DockerClient docker, final String container, String script) {
|
||||
copyToContainer(docker, container, findApplication());
|
||||
copyToContainer(docker, container,
|
||||
new File("src/test/resources/scripts/test-functions.sh"));
|
||||
copyToContainer(docker, container,
|
||||
new File("src/test/resources/scripts/" + script));
|
||||
copyToContainer(docker, container, new File("src/test/resources/scripts/test-functions.sh"));
|
||||
copyToContainer(docker, container, new File("src/test/resources/scripts/" + script));
|
||||
}
|
||||
|
||||
private void copyToContainer(DockerClient docker, final String container,
|
||||
final File file) {
|
||||
this.commandExecFactory.createCopyToContainerCmdExec()
|
||||
.exec(new CopyToContainerCmd(container, file));
|
||||
private void copyToContainer(DockerClient docker, final String container, final File file) {
|
||||
this.commandExecFactory.createCopyToContainerCmdExec().exec(new CopyToContainerCmd(container, file));
|
||||
}
|
||||
|
||||
private File findApplication() {
|
||||
File targetDir = new File("target");
|
||||
for (File file : targetDir.listFiles()) {
|
||||
if (file.getName().startsWith("spring-boot-launch-script-tests")
|
||||
&& file.getName().endsWith(".jar")
|
||||
if (file.getName().startsWith("spring-boot-launch-script-tests") && file.getName().endsWith(".jar")
|
||||
&& !file.getName().endsWith("-sources.jar")) {
|
||||
return file;
|
||||
}
|
||||
@@ -420,29 +394,24 @@ public class SysVinitLaunchScriptIT {
|
||||
if (matcher.matches()) {
|
||||
return matcher.group(1);
|
||||
}
|
||||
throw new IllegalArgumentException(
|
||||
"Failed to extract " + label + " from output: " + output);
|
||||
throw new IllegalArgumentException("Failed to extract " + label + " from output: " + output);
|
||||
}
|
||||
|
||||
private static final class CopyToContainerCmdExec
|
||||
extends AbstrSyncDockerCmdExec<CopyToContainerCmd, Void> {
|
||||
private static final class CopyToContainerCmdExec extends AbstrSyncDockerCmdExec<CopyToContainerCmd, Void> {
|
||||
|
||||
private CopyToContainerCmdExec(WebTarget baseResource,
|
||||
DockerClientConfig dockerClientConfig) {
|
||||
private CopyToContainerCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) {
|
||||
super(baseResource, dockerClientConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void execute(CopyToContainerCmd command) {
|
||||
try {
|
||||
InputStream streamToUpload = new FileInputStream(CompressArchiveUtil
|
||||
.archiveTARFiles(command.getFile().getParentFile(),
|
||||
Arrays.asList(command.getFile()),
|
||||
command.getFile().getName()));
|
||||
WebTarget webResource = getBaseResource().path("/containers/{id}/archive")
|
||||
.resolveTemplate("id", command.getContainer());
|
||||
webResource.queryParam("path", ".")
|
||||
.queryParam("noOverwriteDirNonDir", false).request()
|
||||
InputStream streamToUpload = new FileInputStream(
|
||||
CompressArchiveUtil.archiveTARFiles(command.getFile().getParentFile(),
|
||||
Arrays.asList(command.getFile()), command.getFile().getName()));
|
||||
WebTarget webResource = getBaseResource().path("/containers/{id}/archive").resolveTemplate("id",
|
||||
command.getContainer());
|
||||
webResource.queryParam("path", ".").queryParam("noOverwriteDirNonDir", false).request()
|
||||
.put(Entity.entity(streamToUpload, "application/x-tar")).close();
|
||||
return null;
|
||||
}
|
||||
@@ -479,8 +448,7 @@ public class SysVinitLaunchScriptIT {
|
||||
|
||||
}
|
||||
|
||||
private static final class SpringBootDockerCmdExecFactory
|
||||
extends JerseyDockerCmdExecFactory {
|
||||
private static final class SpringBootDockerCmdExecFactory extends JerseyDockerCmdExecFactory {
|
||||
|
||||
private CopyToContainerCmdExec createCopyToContainerCmdExec() {
|
||||
return new CopyToContainerCmdExec(getBaseResource(), getDockerClientConfig());
|
||||
|
||||
@@ -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 HelloWebSecurityApplicationTests {
|
||||
public void requiresAuthentication() throws Exception {
|
||||
this.request.setMethod("GET");
|
||||
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
||||
assertThat(this.response.getStatus())
|
||||
.isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user