Skip to content

Commit ff1983c

Browse files
committed
Merge branch '2.1.x'
Closes gh-18168
2 parents fc1889e + 795c2f2 commit ff1983c

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/CentralDirectoryEndRecord.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,10 @@ int getNumberOfRecords() {
123123
return (int) numberOfRecords;
124124
}
125125

126+
String getComment() {
127+
int commentLength = (int) Bytes.littleEndianValue(this.block, this.offset + COMMENT_LENGTH_OFFSET, 2);
128+
AsciiBytes comment = new AsciiBytes(this.block, this.offset + COMMENT_LENGTH_OFFSET + 2, commentLength);
129+
return comment.toString();
130+
}
131+
126132
}

spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public class JarFile extends java.util.jar.JarFile {
8080

8181
private boolean signed;
8282

83+
private String comment;
84+
8385
/**
8486
* Create a new {@link JarFile} backed by the specified file.
8587
* @param file the root jar file
@@ -146,6 +148,7 @@ private CentralDirectoryVisitor centralDirectoryVisitor() {
146148

147149
@Override
148150
public void visitStart(CentralDirectoryEndRecord endRecord, RandomAccessData centralDirectoryData) {
151+
JarFile.this.comment = endRecord.getComment();
149152
}
150153

151154
@Override
@@ -290,6 +293,11 @@ private JarFile createJarFileFromFileEntry(JarEntry entry) throws IOException {
290293
JarFileType.NESTED_JAR);
291294
}
292295

296+
@Override
297+
public String getComment() {
298+
return this.comment;
299+
}
300+
293301
@Override
294302
public int size() {
295303
return this.entries.getSize();

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/TestJarCreator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public static void createTestJar(File file) throws Exception {
4141
public static void createTestJar(File file, boolean unpackNested) throws Exception {
4242
FileOutputStream fileOutputStream = new FileOutputStream(file);
4343
try (JarOutputStream jarOutputStream = new JarOutputStream(fileOutputStream)) {
44+
jarOutputStream.setComment("outer");
4445
writeManifest(jarOutputStream, "j1");
4546
writeEntry(jarOutputStream, "1.dat", 1);
4647
writeEntry(jarOutputStream, "2.dat", 2);
@@ -88,6 +89,7 @@ private static void writeNestedEntry(String name, boolean unpackNested, JarOutpu
8889
private static byte[] getNestedJarData(boolean multiRelease) throws Exception {
8990
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
9091
JarOutputStream jarOutputStream = new JarOutputStream(byteArrayOutputStream);
92+
jarOutputStream.setComment("nested");
9193
writeManifest(jarOutputStream, "j2", multiRelease);
9294
if (multiRelease) {
9395
writeEntry(jarOutputStream, "multi-release.dat", 8);

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ void tearDown() throws Exception {
8686
void jdkJarFile() throws Exception {
8787
// Sanity checks to see how the default jar file operates
8888
java.util.jar.JarFile jarFile = new java.util.jar.JarFile(this.rootJarFile);
89+
assertThat(jarFile.getComment()).isEqualTo("outer");
8990
Enumeration<java.util.jar.JarEntry> entries = jarFile.entries();
9091
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/");
9192
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/MANIFEST.MF");
@@ -168,6 +169,11 @@ void getInputStream() throws Exception {
168169
assertThat(inputStream.read()).isEqualTo(-1);
169170
}
170171

172+
@Test
173+
void getComment() {
174+
assertThat(this.jarFile.getComment()).isEqualTo("outer");
175+
}
176+
171177
@Test
172178
void getName() {
173179
assertThat(this.jarFile.getName()).isEqualTo(this.rootJarFile.getPath());
@@ -252,6 +258,7 @@ void getEntryUrlStream() throws Exception {
252258
@Test
253259
void getNestedJarFile() throws Exception {
254260
try (JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"))) {
261+
assertThat(nestedJarFile.getComment()).isEqualTo("nested");
255262
Enumeration<java.util.jar.JarEntry> entries = nestedJarFile.entries();
256263
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/");
257264
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/MANIFEST.MF");

0 commit comments

Comments
 (0)