List of usage examples for org.springframework.boot.loader.tools Library Library
public Library(File file, LibraryScope scope, boolean unpackRequired)
From source file:org.springframework.boot.loader.tools.RepackagerTests.java
@Test public void duplicateLibraries() 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); this.thrown.expect(IllegalStateException.class); this.thrown.expectMessage("Duplicate library"); repackager.repackage((callback) -> { callback.library(new Library(libJarFile, LibraryScope.COMPILE, false)); callback.library(new Library(libJarFile, LibraryScope.COMPILE, false)); });/*from w w w. j a v a2 s .co m*/ }
From source file:org.springframework.boot.loader.tools.RepackagerTests.java
@Test public void unpackLibrariesTakePrecedenceOverExistingSourceEntries() throws Exception { TestJarFile nested = new TestJarFile(this.temporaryFolder); nested.addClass("a/b/C.class", ClassWithoutMainMethod.class); File nestedFile = nested.getFile(); String name = "BOOT-INF/lib/" + nestedFile.getName(); this.testJarFile.addFile(name, nested.getFile()); this.testJarFile.addClass("A.class", ClassWithMainMethod.class); File file = this.testJarFile.getFile(); Repackager repackager = new Repackager(file); repackager.repackage((callback) -> callback.library(new Library(nestedFile, LibraryScope.COMPILE, true))); try (JarFile jarFile = new JarFile(file)) { assertThat(jarFile.getEntry(name).getComment()).startsWith("UNPACK:"); }/*from www . j a v a 2s.com*/ }
From source file:org.springframework.boot.loader.tools.RepackagerTests.java
@Test public void loaderIsWrittenFirstThenApplicationClassesThenLibraries() throws IOException { this.testJarFile.addClass("com/example/Application.class", ClassWithMainMethod.class); File source = this.testJarFile.getFile(); File dest = this.temporaryFolder.newFile("dest.jar"); File libraryOne = createLibrary(); File libraryTwo = createLibrary(); File libraryThree = createLibrary(); Repackager repackager = new Repackager(source); repackager.repackage(dest, (callback) -> { callback.library(new Library(libraryOne, LibraryScope.COMPILE, false)); callback.library(new Library(libraryTwo, LibraryScope.COMPILE, true)); callback.library(new Library(libraryThree, LibraryScope.COMPILE, false)); });/* w ww . j a v a 2 s . c o m*/ assertThat(getEntryNames(dest)).containsSubsequence("org/springframework/boot/loader/", "BOOT-INF/classes/com/example/Application.class", "BOOT-INF/lib/" + libraryOne.getName(), "BOOT-INF/lib/" + libraryTwo.getName(), "BOOT-INF/lib/" + libraryThree.getName()); }
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 w w w . j ava 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:"); }