001/* 002 * Copyright 2012-2014 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.loader.tools; 018 019import java.io.File; 020 021/** 022 * Encapsulates information about a single library that may be packed into the archive. 023 * 024 * @author Phillip Webb 025 * @since 1.1.2 026 * @see Libraries 027 */ 028public class Library { 029 030 private final String name; 031 032 private final File file; 033 034 private final LibraryScope scope; 035 036 private final boolean unpackRequired; 037 038 /** 039 * Create a new {@link Library}. 040 * @param file the source file 041 * @param scope the scope of the library 042 */ 043 public Library(File file, LibraryScope scope) { 044 this(file, scope, false); 045 } 046 047 /** 048 * Create a new {@link Library}. 049 * @param file the source file 050 * @param scope the scope of the library 051 * @param unpackRequired if the library needs to be unpacked before it can be used 052 */ 053 public Library(File file, LibraryScope scope, boolean unpackRequired) { 054 this(null, file, scope, unpackRequired); 055 } 056 057 /** 058 * Create a new {@link Library}. 059 * @param name the name of the library as it should be written or {@code null} to use 060 * the file name 061 * @param file the source file 062 * @param scope the scope of the library 063 * @param unpackRequired if the library needs to be unpacked before it can be used 064 */ 065 public Library(String name, File file, LibraryScope scope, boolean unpackRequired) { 066 this.name = (name == null ? file.getName() : name); 067 this.file = file; 068 this.scope = scope; 069 this.unpackRequired = unpackRequired; 070 } 071 072 /** 073 * Return the name of file as it should be written. 074 * @return the name 075 */ 076 public String getName() { 077 return this.name; 078 } 079 080 /** 081 * Return the library file. 082 * @return the file 083 */ 084 public File getFile() { 085 return this.file; 086 } 087 088 /** 089 * Return the scope of the library. 090 * @return the scope 091 */ 092 public LibraryScope getScope() { 093 return this.scope; 094 } 095 096 /** 097 * Return if the file cannot be used directly as a nested jar and needs to be 098 * unpacked. 099 * @return if unpack is required 100 */ 101 public boolean isUnpackRequired() { 102 return this.unpackRequired; 103 } 104 105}