Example usage for org.springframework.boot.loader.tools TestJarFile addClass

List of usage examples for org.springframework.boot.loader.tools TestJarFile addClass

Introduction

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

Prototype

public void addClass(String filename, Class<?> classToCopy, Long time) throws IOException 

Source Link

Usage

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

@Test
public void libraries() throws Exception {
    TestJarFile libJar = new TestJarFile(this.temporaryFolder);
    libJar.addClass("a/b/C.class", ClassWithoutMainMethod.class, JAN_1_1985);
    File libJarFile = libJar.getFile();
    File libJarFileToUnpack = libJar.getFile();
    File libNonJarFile = this.temporaryFolder.newFile();
    FileCopyUtils.copy(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }, libNonJarFile);
    this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
    this.testJarFile.addFile("BOOT-INF/lib/" + libJarFileToUnpack.getName(), libJarFileToUnpack);
    File file = this.testJarFile.getFile();
    libJarFile.setLastModified(JAN_1_1980);
    Repackager repackager = new Repackager(file);
    repackager.repackage((callback) -> {
        callback.library(new Library(libJarFile, LibraryScope.COMPILE));
        callback.library(new Library(libJarFileToUnpack, LibraryScope.COMPILE, true));
        callback.library(new Library(libNonJarFile, LibraryScope.COMPILE));
    });/*www .j a  v  a2  s.  com*/
    assertThat(hasEntry(file, "BOOT-INF/lib/" + libJarFile.getName())).isTrue();
    assertThat(hasEntry(file, "BOOT-INF/lib/" + libJarFileToUnpack.getName())).isTrue();
    assertThat(hasEntry(file, "BOOT-INF/lib/" + libNonJarFile.getName())).isFalse();
    JarEntry entry = getEntry(file, "BOOT-INF/lib/" + libJarFile.getName());
    assertThat(entry.getTime()).isEqualTo(JAN_1_1985);
    entry = getEntry(file, "BOOT-INF/lib/" + libJarFileToUnpack.getName());
    assertThat(entry.getComment()).startsWith("UNPACK:");
    assertThat(entry.getComment().length()).isEqualTo(47);
}