Example usage for org.springframework.boot.loader.tools Repackager setLayout

List of usage examples for org.springframework.boot.loader.tools Repackager setLayout

Introduction

In this page you can find the example usage for org.springframework.boot.loader.tools Repackager setLayout.

Prototype

public void setLayout(Layout layout) 

Source Link

Document

Sets the layout to use for the jar.

Usage

From source file:org.springframework.boot.loader.tools.RepackagerTests.java

@Test
public void noMainClassAndLayoutIsNone() throws Exception {
    this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
    File file = this.testJarFile.getFile();
    Repackager repackager = new Repackager(file);
    repackager.setLayout(new Layouts.None());
    repackager.repackage(file, NO_LIBRARIES);
    Manifest actualManifest = getManifest(file);
    assertThat(actualManifest.getMainAttributes().getValue("Main-Class")).isEqualTo("a.b.C");
    assertThat(hasLauncherClasses(file)).isFalse();
}

From source file:org.springframework.boot.loader.tools.RepackagerTests.java

@Test
public void noMainClassAndLayoutIsNoneWithNoMain() throws Exception {
    this.testJarFile.addClass("a/b/C.class", ClassWithoutMainMethod.class);
    File file = this.testJarFile.getFile();
    Repackager repackager = new Repackager(file);
    repackager.setLayout(new Layouts.None());
    repackager.repackage(file, NO_LIBRARIES);
    Manifest actualManifest = getManifest(file);
    assertThat(actualManifest.getMainAttributes().getValue("Main-Class")).isNull();
    assertThat(hasLauncherClasses(file)).isFalse();
}

From source file:org.springframework.boot.loader.tools.RepackagerTests.java

@Test
public void customLayout() throws Exception {
    TestJarFile libJar = new TestJarFile(this.temporaryFolder);
    libJar.addClass("a/b/C.class", ClassWithoutMainMethod.class);
    File libJarFile = libJar.getFile();
    this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
    File file = this.testJarFile.getFile();
    Repackager repackager = new Repackager(file);
    Layout layout = mock(Layout.class);
    LibraryScope scope = mock(LibraryScope.class);
    given(layout.getLauncherClassName()).willReturn("testLauncher");
    given(layout.getLibraryDestination(anyString(), eq(scope))).willReturn("test/");
    given(layout.getLibraryDestination(anyString(), eq(LibraryScope.COMPILE))).willReturn("test-lib/");
    repackager.setLayout(layout);
    repackager.repackage((callback) -> callback.library(new Library(libJarFile, scope)));
    assertThat(hasEntry(file, "test/" + libJarFile.getName())).isTrue();
    assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib")).isEqualTo("test-lib/");
    assertThat(getManifest(file).getMainAttributes().getValue("Main-Class")).isEqualTo("testLauncher");
}

From source file:org.springframework.boot.loader.tools.RepackagerTests.java

@Test
public void customLayoutNoBootLib() throws Exception {
    TestJarFile libJar = new TestJarFile(this.temporaryFolder);
    libJar.addClass("a/b/C.class", ClassWithoutMainMethod.class);
    File libJarFile = libJar.getFile();
    this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
    File file = this.testJarFile.getFile();
    Repackager repackager = new Repackager(file);
    Layout layout = mock(Layout.class);
    LibraryScope scope = mock(LibraryScope.class);
    given(layout.getLauncherClassName()).willReturn("testLauncher");
    repackager.setLayout(layout);
    repackager.repackage((callback) -> callback.library(new Library(libJarFile, scope)));
    assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib")).isNull();
    assertThat(getManifest(file).getMainAttributes().getValue("Main-Class")).isEqualTo("testLauncher");
}

From source file:org.springframework.boot.loader.tools.RepackagerTests.java

@Test
public void nullCustomLayout() throws Exception {
    this.testJarFile.addClass("a/b/C.class", ClassWithoutMainMethod.class);
    Repackager repackager = new Repackager(this.testJarFile.getFile());
    this.thrown.expect(IllegalArgumentException.class);
    this.thrown.expectMessage("Layout must not be null");
    repackager.setLayout(null);
}

From source file:org.springframework.boot.loader.tools.RepackagerTests.java

@Test
public void customLayoutFactoryWithLayout() throws Exception {
    this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
    File source = this.testJarFile.getFile();
    Repackager repackager = new Repackager(source, new TestLayoutFactory());
    repackager.setLayout(new Layouts.Jar());
    repackager.repackage(NO_LIBRARIES);// www .  j av a 2  s  .  c  om
    JarFile jarFile = new JarFile(source);
    assertThat(jarFile.getEntry("test")).isNull();
    jarFile.close();
}

From source file:org.springframework.boot.loader.tools.RepackagerTests.java

@Test
public void existingEntryThatMatchesUnpackLibraryIsMarkedForUnpack() throws IOException {
    File library = createLibrary();
    this.testJarFile.addClass("WEB-INF/classes/com/example/Application.class", ClassWithMainMethod.class);
    this.testJarFile.addFile("WEB-INF/lib/" + library.getName(), library);
    File source = this.testJarFile.getFile("war");
    File dest = this.temporaryFolder.newFile("dest.war");
    Repackager repackager = new Repackager(source);
    repackager.setLayout(new Layouts.War());
    repackager.repackage(dest,/*from  www  .j av a 2 s . c  o  m*/
            (callback) -> callback.library(new Library(library, LibraryScope.COMPILE, true)));
    assertThat(getEntryNames(dest)).containsSubsequence("org/springframework/boot/loader/",
            "WEB-INF/classes/com/example/Application.class", "WEB-INF/lib/" + library.getName());
    JarEntry unpackLibrary = getEntry(dest, "WEB-INF/lib/" + library.getName());
    assertThat(unpackLibrary.getComment()).startsWith("UNPACK:");
}

From source file:org.springframework.boot.loader.tools.RepackagerTests.java

@Test
public void layoutCanOmitLibraries() throws IOException {
    TestJarFile libJar = new TestJarFile(this.temporaryFolder);
    libJar.addClass("a/b/C.class", ClassWithoutMainMethod.class);
    File libJarFile = libJar.getFile();
    this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
    File file = this.testJarFile.getFile();
    Repackager repackager = new Repackager(file);
    Layout layout = mock(Layout.class);
    LibraryScope scope = mock(LibraryScope.class);
    repackager.setLayout(layout);
    repackager.repackage((callback) -> callback.library(new Library(libJarFile, scope)));
    assertThat(getEntryNames(file)).containsExactly("META-INF/", "META-INF/MANIFEST.MF", "a/", "a/b/",
            "a/b/C.class");
}