Skip to content

Commit 719ef39

Browse files
author
Dave Syer
committed
Ensure Spring-Boot-Lib is never "null"
1 parent ffbbd2a commit 719ef39

File tree

2 files changed

+34
-4
lines changed
  • spring-boot-tools/spring-boot-loader-tools/src

2 files changed

+34
-4
lines changed

spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,11 @@ else if (startClass != null) {
301301
(this.layout instanceof RepackagingLayout)
302302
? ((RepackagingLayout) this.layout).getRepackagedClassesLocation()
303303
: this.layout.getClassesLocation());
304-
manifest.getMainAttributes().putValue(BOOT_LIB_ATTRIBUTE,
305-
this.layout.getLibraryDestination("", LibraryScope.COMPILE));
304+
String libraryDestination = this.layout.getLibraryDestination("",
305+
LibraryScope.COMPILE);
306+
if (libraryDestination != null) {
307+
manifest.getMainAttributes().putValue(BOOT_LIB_ATTRIBUTE, libraryDestination);
308+
}
306309
return manifest;
307310
}
308311

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040

4141
import static org.assertj.core.api.Assertions.assertThat;
4242
import static org.mockito.BDDMockito.given;
43+
import static org.mockito.Matchers.any;
4344
import static org.mockito.Matchers.anyString;
44-
import static org.mockito.Matchers.eq;
4545
import static org.mockito.Mockito.mock;
4646

4747
/**
@@ -346,7 +346,8 @@ public void customLayout() throws Exception {
346346
Layout layout = mock(Layout.class);
347347
final LibraryScope scope = mock(LibraryScope.class);
348348
given(layout.getLauncherClassName()).willReturn("testLauncher");
349-
given(layout.getLibraryDestination(anyString(), eq(scope))).willReturn("test/");
349+
given(layout.getLibraryDestination(anyString(), any(LibraryScope.class)))
350+
.willReturn("test/");
350351
repackager.setLayout(layout);
351352
repackager.repackage(new Libraries() {
352353
@Override
@@ -355,6 +356,32 @@ public void doWithLibraries(LibraryCallback callback) throws IOException {
355356
}
356357
});
357358
assertThat(hasEntry(file, "test/" + libJarFile.getName())).isTrue();
359+
assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib"))
360+
.isEqualTo("test/");
361+
assertThat(getManifest(file).getMainAttributes().getValue("Main-Class"))
362+
.isEqualTo("testLauncher");
363+
}
364+
365+
@Test
366+
public void customLayoutNoBootLib() throws Exception {
367+
TestJarFile libJar = new TestJarFile(this.temporaryFolder);
368+
libJar.addClass("a/b/C.class", ClassWithoutMainMethod.class);
369+
final File libJarFile = libJar.getFile();
370+
this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
371+
File file = this.testJarFile.getFile();
372+
Repackager repackager = new Repackager(file);
373+
Layout layout = mock(Layout.class);
374+
final LibraryScope scope = mock(LibraryScope.class);
375+
given(layout.getLauncherClassName()).willReturn("testLauncher");
376+
repackager.setLayout(layout);
377+
repackager.repackage(new Libraries() {
378+
@Override
379+
public void doWithLibraries(LibraryCallback callback) throws IOException {
380+
callback.library(new Library(libJarFile, scope));
381+
}
382+
});
383+
assertThat(getManifest(file).getMainAttributes())
384+
.doesNotContainKey("Spring-Boot-Lib");
358385
assertThat(getManifest(file).getMainAttributes().getValue("Main-Class"))
359386
.isEqualTo("testLauncher");
360387
}

0 commit comments

Comments
 (0)