Add Library abstraction
Add a Library class update the LibraryCallback interface and implementations to use it. This change is in preparation for an addition `unpack` flag that will be required to allow the automatic unpacking of certain nested jars. See gh-1070
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.loader.tools;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Encapsulates information about a single library that may be packed into the archive.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @since 1.1.2
|
||||
* @see Libraries
|
||||
*/
|
||||
public class Library {
|
||||
|
||||
private final File file;
|
||||
|
||||
private final LibraryScope scope;
|
||||
|
||||
/**
|
||||
* Create a new {@link Library}.
|
||||
* @param file the source file
|
||||
* @param scope the scope of the library
|
||||
*/
|
||||
public Library(File file, LibraryScope scope) {
|
||||
this.file = file;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the library file
|
||||
*/
|
||||
public File getFile() {
|
||||
return this.file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the scope of the library
|
||||
*/
|
||||
public LibraryScope getScope() {
|
||||
return this.scope;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,10 +28,9 @@ public interface LibraryCallback {
|
||||
|
||||
/**
|
||||
* Callback to for a single library backed by a {@link File}.
|
||||
* @param file the library file
|
||||
* @param scope the scope of the library
|
||||
* @param library the library
|
||||
* @throws IOException
|
||||
*/
|
||||
void library(File file, LibraryScope scope) throws IOException;
|
||||
void library(Library library) throws IOException;
|
||||
|
||||
}
|
||||
|
||||
@@ -141,10 +141,11 @@ public class Repackager {
|
||||
|
||||
libraries.doWithLibraries(new LibraryCallback() {
|
||||
@Override
|
||||
public void library(File file, LibraryScope scope) throws IOException {
|
||||
public void library(Library library) throws IOException {
|
||||
File file = library.getFile();
|
||||
if (isZip(file)) {
|
||||
String destination = Repackager.this.layout
|
||||
.getLibraryDestination(file.getName(), scope);
|
||||
.getLibraryDestination(file.getName(), library.getScope());
|
||||
if (destination != null) {
|
||||
writer.writeNestedLibrary(destination, file);
|
||||
}
|
||||
|
||||
@@ -266,8 +266,8 @@ public class RepackagerTests {
|
||||
repackager.repackage(new Libraries() {
|
||||
@Override
|
||||
public void doWithLibraries(LibraryCallback callback) throws IOException {
|
||||
callback.library(libJarFile, LibraryScope.COMPILE);
|
||||
callback.library(libNonJarFile, LibraryScope.COMPILE);
|
||||
callback.library(new Library(libJarFile, LibraryScope.COMPILE));
|
||||
callback.library(new Library(libNonJarFile, LibraryScope.COMPILE));
|
||||
}
|
||||
});
|
||||
assertThat(hasEntry(file, "lib/" + libJarFile.getName()), equalTo(true));
|
||||
@@ -290,7 +290,7 @@ public class RepackagerTests {
|
||||
repackager.repackage(new Libraries() {
|
||||
@Override
|
||||
public void doWithLibraries(LibraryCallback callback) throws IOException {
|
||||
callback.library(libJarFile, scope);
|
||||
callback.library(new Library(libJarFile, scope));
|
||||
}
|
||||
});
|
||||
assertThat(hasEntry(file, "test/" + libJarFile.getName()), equalTo(true));
|
||||
@@ -331,7 +331,7 @@ public class RepackagerTests {
|
||||
repackager.repackage(new Libraries() {
|
||||
@Override
|
||||
public void doWithLibraries(LibraryCallback callback) throws IOException {
|
||||
callback.library(nestedFile, LibraryScope.COMPILE);
|
||||
callback.library(new Library(nestedFile, LibraryScope.COMPILE));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user