Skip to content

Commit

Permalink
Merge branch '2.6.x' into 2.7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb committed Aug 17, 2022
2 parents 3fcfcc4 + 13bd61b commit 60e1cc5
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 144 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2021 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.
Expand Down Expand Up @@ -128,6 +128,9 @@ private JarFile(RandomAccessDataFile rootFile, String pathFromRoot, RandomAccess
private JarFile(RandomAccessDataFile rootFile, String pathFromRoot, RandomAccessData data, JarEntryFilter filter,
JarFileType type, Supplier<Manifest> manifestSupplier) throws IOException {
super(rootFile.getFile());
if (System.getSecurityManager() == null) {
super.close();
}
this.rootFile = rootFile;
this.pathFromRoot = pathFromRoot;
CentralDirectoryParser parser = new CentralDirectoryParser();
Expand All @@ -139,7 +142,8 @@ private JarFile(RandomAccessDataFile rootFile, String pathFromRoot, RandomAccess
}
catch (RuntimeException ex) {
try {
close();
this.rootFile.close();
super.close();
}
catch (IOException ioex) {
}
Expand Down Expand Up @@ -184,13 +188,8 @@ public void visitEnd() {
JarFileWrapper getWrapper() throws IOException {
JarFileWrapper wrapper = this.wrapper;
if (wrapper == null) {
synchronized (this) {
if (this.wrapper != null) {
return this.wrapper;
}
wrapper = new JarFileWrapper(this);
this.wrapper = wrapper;
}
wrapper = new JarFileWrapper(this);
this.wrapper = wrapper;
}
return wrapper;
}
Expand Down Expand Up @@ -356,13 +355,11 @@ public void close() throws IOException {
if (this.closed) {
return;
}
synchronized (this) {
super.close();
if (this.type == JarFileType.DIRECT) {
this.rootFile.close();
}
this.closed = true;
super.close();
if (this.type == JarFileType.DIRECT) {
this.rootFile.close();
}
this.closed = true;
}

private void ensureOpen() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2021 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.
Expand Down Expand Up @@ -40,6 +40,9 @@ class JarFileWrapper extends AbstractJarFile {
JarFileWrapper(JarFile parent) throws IOException {
super(parent.getRootJarFile().getFile());
this.parent = parent;
if (System.getSecurityManager() == null) {
super.close();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2021 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.
Expand All @@ -18,7 +18,6 @@

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -166,7 +165,7 @@ public InputStream getInputStream() throws IOException {
if (inputStream == null) {
throwFileNotFound(this.jarEntryName, this.jarFile);
}
return new ConnectionInputStream(inputStream);
return inputStream;
}

private void throwFileNotFound(Object entry, AbstractJarFile jarFile) throws FileNotFoundException {
Expand Down Expand Up @@ -291,19 +290,6 @@ private static JarURLConnection notFound(JarFile jarFile, JarEntryName jarEntryN
return new JarURLConnection(null, jarFile, jarEntryName);
}

private class ConnectionInputStream extends FilterInputStream {

ConnectionInputStream(InputStream in) {
super(in);
}

@Override
public void close() throws IOException {
JarURLConnection.this.jarFile.close();
}

}

/**
* A JarEntryName parsed from a URL String.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2020 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.
Expand Down Expand Up @@ -61,7 +61,6 @@ void setup(@TempDir File temp) throws Exception {
@AfterEach
void cleanup() throws Exception {
this.parent.close();
this.wrapper.close();
}

private File createTempJar(File temp) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ dependencies {
app project(path: ":spring-boot-project:spring-boot-dependencies", configuration: "mavenRepository")
app project(path: ":spring-boot-project:spring-boot-tools:spring-boot-gradle-plugin", configuration: "mavenRepository")
app project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-web", configuration: "mavenRepository")
app project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter", configuration: "mavenRepository")
app("org.bouncycastle:bcprov-jdk15on:1.70")

intTestImplementation(enforcedPlatform(project(":spring-boot-project:spring-boot-parent")))
intTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
Expand All @@ -41,18 +39,6 @@ task buildApp(type: GradleBuild) {
tasks = ["build"]
}

task syncSignedJarUnpackAppSource(type: org.springframework.boot.build.SyncAppSource) {
sourceDirectory = file("spring-boot-loader-tests-signed-jar-unpack-app")
destinationDirectory = file("${buildDir}/spring-boot-loader-tests-signed-jar-unpack-app")
}

task buildSignedJarUnpackApp(type: GradleBuild) {
dependsOn syncSignedJarUnpackAppSource, syncMavenRepository
dir = "${buildDir}/spring-boot-loader-tests-signed-jar-unpack-app"
startParameter.buildCacheEnabled = false
tasks = ["build"]
}

intTest {
dependsOn buildApp, buildSignedJarUnpackApp
dependsOn buildApp
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,25 @@ class LoaderIntegrationTests {
@ParameterizedTest
@MethodSource("javaRuntimes")
void readUrlsWithoutWarning(JavaRuntime javaRuntime) {
try (GenericContainer<?> container = createContainer(javaRuntime, "spring-boot-loader-tests-app")) {
try (GenericContainer<?> container = createContainer(javaRuntime)) {
container.start();
System.out.println(this.output.toUtf8String());
assertThat(this.output.toUtf8String()).contains(">>>>> 287649 BYTES from").doesNotContain("WARNING:")
.doesNotContain("illegal").doesNotContain("jar written to temp");
}
}

@ParameterizedTest
@MethodSource("javaRuntimes")
void runSignedJarWhenUnpacked(JavaRuntime javaRuntime) {
try (GenericContainer<?> container = createContainer(javaRuntime,
"spring-boot-loader-tests-signed-jar-unpack-app")) {
container.start();
System.out.println(this.output.toUtf8String());
assertThat(this.output.toUtf8String()).contains("Legion of the Bouncy Castle");
}
}

private GenericContainer<?> createContainer(JavaRuntime javaRuntime, String name) {
private GenericContainer<?> createContainer(JavaRuntime javaRuntime) {
return javaRuntime.getContainer().withLogConsumer(this.output)
.withCopyFileToContainer(findApplication(name), "/app.jar")
.withCopyFileToContainer(MountableFile.forHostPath(findApplication().toPath()), "/app.jar")
.withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofMinutes(5)))
.withCommand("java", "-jar", "app.jar");
}

private MountableFile findApplication(String name) {
return MountableFile.forHostPath(findJarFile(name).toPath());
}

private File findJarFile(String name) {
String path = String.format("build/%1$s/build/libs/%1$s.jar", name);
File jar = new File(path);
Assert.state(jar.isFile(), () -> "Could not find " + path + ". Have you built it?");
private File findApplication() {
String name = String.format("build/%1$s/build/libs/%1$s.jar", "spring-boot-loader-tests-app");
File jar = new File(name);
Assert.state(jar.isFile(), () -> "Could not find " + name + ". Have you built it?");
return jar;
}

Expand Down

0 comments on commit 60e1cc5

Please sign in to comment.