Upgrade to spring-javaformat 0.0.11
This commit is contained in:
@@ -60,23 +60,21 @@ public abstract class ExecutableArchiveLauncher extends Launcher {
|
||||
mainClass = manifest.getMainAttributes().getValue("Start-Class");
|
||||
}
|
||||
if (mainClass == null) {
|
||||
throw new IllegalStateException(
|
||||
"No 'Start-Class' manifest entry specified in " + this);
|
||||
throw new IllegalStateException("No 'Start-Class' manifest entry specified in " + this);
|
||||
}
|
||||
return mainClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Archive> getClassPathArchives() throws Exception {
|
||||
List<Archive> archives = new ArrayList<Archive>(
|
||||
this.archive.getNestedArchives(new EntryFilter() {
|
||||
List<Archive> archives = new ArrayList<Archive>(this.archive.getNestedArchives(new EntryFilter() {
|
||||
|
||||
@Override
|
||||
public boolean matches(Entry entry) {
|
||||
return isNestedArchive(entry);
|
||||
}
|
||||
@Override
|
||||
public boolean matches(Entry entry) {
|
||||
return isNestedArchive(entry);
|
||||
}
|
||||
|
||||
}));
|
||||
}));
|
||||
postProcessClassPathArchives(archives);
|
||||
return archives;
|
||||
}
|
||||
|
||||
@@ -74,8 +74,7 @@ public class LaunchedURLClassLoader extends URLClassLoader {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> loadClass(String name, boolean resolve)
|
||||
throws ClassNotFoundException {
|
||||
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
|
||||
Handler.setUseFastConnectionExceptions(true);
|
||||
try {
|
||||
try {
|
||||
@@ -87,8 +86,8 @@ public class LaunchedURLClassLoader extends URLClassLoader {
|
||||
// This should never happen as the IllegalArgumentException indicates
|
||||
// that the package has already been defined and, therefore,
|
||||
// getPackage(name) should not return null.
|
||||
throw new AssertionError("Package " + name + " has already been "
|
||||
+ "defined but it could not be found");
|
||||
throw new AssertionError(
|
||||
"Package " + name + " has already been " + "defined but it could not be found");
|
||||
}
|
||||
}
|
||||
return super.loadClass(name, resolve);
|
||||
@@ -119,8 +118,7 @@ public class LaunchedURLClassLoader extends URLClassLoader {
|
||||
// indicates that the package has already been defined and,
|
||||
// therefore, getPackage(name) should not have returned null.
|
||||
throw new AssertionError(
|
||||
"Package " + packageName + " has already been defined "
|
||||
+ "but it could not be found");
|
||||
"Package " + packageName + " has already been defined " + "but it could not be found");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,13 +136,11 @@ public class LaunchedURLClassLoader extends URLClassLoader {
|
||||
try {
|
||||
URLConnection connection = url.openConnection();
|
||||
if (connection instanceof JarURLConnection) {
|
||||
JarFile jarFile = ((JarURLConnection) connection)
|
||||
.getJarFile();
|
||||
JarFile jarFile = ((JarURLConnection) connection).getJarFile();
|
||||
if (jarFile.getEntry(classEntryName) != null
|
||||
&& jarFile.getEntry(packageEntryName) != null
|
||||
&& jarFile.getManifest() != null) {
|
||||
definePackage(packageName, jarFile.getManifest(),
|
||||
url);
|
||||
definePackage(packageName, jarFile.getManifest(), url);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,8 +81,7 @@ public abstract class Launcher {
|
||||
* @param classLoader the classloader
|
||||
* @throws Exception if the launch fails
|
||||
*/
|
||||
protected void launch(String[] args, String mainClass, ClassLoader classLoader)
|
||||
throws Exception {
|
||||
protected void launch(String[] args, String mainClass, ClassLoader classLoader) throws Exception {
|
||||
Thread.currentThread().setContextClassLoader(classLoader);
|
||||
createMainMethodRunner(mainClass, args, classLoader).run();
|
||||
}
|
||||
@@ -94,8 +93,7 @@ public abstract class Launcher {
|
||||
* @param classLoader the classloader
|
||||
* @return the main method runner
|
||||
*/
|
||||
protected MainMethodRunner createMainMethodRunner(String mainClass, String[] args,
|
||||
ClassLoader classLoader) {
|
||||
protected MainMethodRunner createMainMethodRunner(String mainClass, String[] args, ClassLoader classLoader) {
|
||||
return new MainMethodRunner(mainClass, args);
|
||||
}
|
||||
|
||||
@@ -123,11 +121,9 @@ public abstract class Launcher {
|
||||
}
|
||||
File root = new File(path);
|
||||
if (!root.exists()) {
|
||||
throw new IllegalStateException(
|
||||
"Unable to determine code source archive from " + root);
|
||||
throw new IllegalStateException("Unable to determine code source archive from " + root);
|
||||
}
|
||||
return (root.isDirectory() ? new ExplodedArchive(root)
|
||||
: new JarFileArchive(root));
|
||||
return (root.isDirectory() ? new ExplodedArchive(root) : new JarFileArchive(root));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,8 +42,7 @@ public class MainMethodRunner {
|
||||
}
|
||||
|
||||
public void run() throws Exception {
|
||||
Class<?> mainClass = Thread.currentThread().getContextClassLoader()
|
||||
.loadClass(this.mainClassName);
|
||||
Class<?> mainClass = Thread.currentThread().getContextClassLoader().loadClass(this.mainClassName);
|
||||
Method mainMethod = mainClass.getDeclaredMethod("main", String[].class);
|
||||
mainMethod.invoke(null, new Object[] { this.args });
|
||||
}
|
||||
|
||||
@@ -159,8 +159,7 @@ public class PropertiesLauncher extends Launcher {
|
||||
configs.add(getProperty(CONFIG_LOCATION));
|
||||
}
|
||||
else {
|
||||
String[] names = getPropertyWithDefault(CONFIG_NAME, "loader,application")
|
||||
.split(",");
|
||||
String[] names = getPropertyWithDefault(CONFIG_NAME, "loader,application").split(",");
|
||||
for (String name : names) {
|
||||
configs.add("file:" + getHomeDirectory() + "/" + name + ".properties");
|
||||
configs.add("classpath:" + name + ".properties");
|
||||
@@ -178,13 +177,11 @@ public class PropertiesLauncher extends Launcher {
|
||||
resource.close();
|
||||
}
|
||||
for (Object key : Collections.list(this.properties.propertyNames())) {
|
||||
if (config.endsWith("application.properties")
|
||||
&& ((String) key).startsWith("loader.")) {
|
||||
if (config.endsWith("application.properties") && ((String) key).startsWith("loader.")) {
|
||||
warn("Use of application.properties for PropertiesLauncher is deprecated");
|
||||
}
|
||||
String text = this.properties.getProperty((String) key);
|
||||
String value = SystemPropertyUtils
|
||||
.resolvePlaceholders(this.properties, text);
|
||||
String value = SystemPropertyUtils.resolvePlaceholders(this.properties, text);
|
||||
if (value != null) {
|
||||
this.properties.put(key, value);
|
||||
}
|
||||
@@ -273,8 +270,7 @@ public class PropertiesLauncher extends Launcher {
|
||||
// Try a URL connection content-length header...
|
||||
URLConnection connection = url.openConnection();
|
||||
try {
|
||||
connection.setUseCaches(
|
||||
connection.getClass().getSimpleName().startsWith("JNLP"));
|
||||
connection.setUseCaches(connection.getClass().getSimpleName().startsWith("JNLP"));
|
||||
if (connection instanceof HttpURLConnection) {
|
||||
HttpURLConnection httpConnection = (HttpURLConnection) connection;
|
||||
httpConnection.setRequestMethod("HEAD");
|
||||
@@ -324,8 +320,7 @@ public class PropertiesLauncher extends Launcher {
|
||||
String[] additionalArgs = args;
|
||||
args = new String[defaultArgs.length + additionalArgs.length];
|
||||
System.arraycopy(defaultArgs, 0, args, 0, defaultArgs.length);
|
||||
System.arraycopy(additionalArgs, 0, args, defaultArgs.length,
|
||||
additionalArgs.length);
|
||||
System.arraycopy(additionalArgs, 0, args, defaultArgs.length, additionalArgs.length);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
@@ -334,8 +329,7 @@ public class PropertiesLauncher extends Launcher {
|
||||
protected String getMainClass() throws Exception {
|
||||
String mainClass = getProperty(MAIN, "Start-Class");
|
||||
if (mainClass == null) {
|
||||
throw new IllegalStateException(
|
||||
"No '" + MAIN + "' or 'Start-Class' specified");
|
||||
throw new IllegalStateException("No '" + MAIN + "' or 'Start-Class' specified");
|
||||
}
|
||||
return mainClass;
|
||||
}
|
||||
@@ -346,8 +340,7 @@ public class PropertiesLauncher extends Launcher {
|
||||
for (Archive archive : archives) {
|
||||
urls.add(archive.getUrl());
|
||||
}
|
||||
ClassLoader loader = new LaunchedURLClassLoader(urls.toArray(new URL[0]),
|
||||
getClass().getClassLoader());
|
||||
ClassLoader loader = new LaunchedURLClassLoader(urls.toArray(new URL[0]), getClass().getClassLoader());
|
||||
debug("Classpath: " + urls);
|
||||
String customLoaderClassName = getProperty("loader.classLoader");
|
||||
if (customLoaderClassName != null) {
|
||||
@@ -358,10 +351,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private ClassLoader wrapWithCustomClassLoader(ClassLoader parent,
|
||||
String loaderClassName) throws Exception {
|
||||
Class<ClassLoader> loaderClass = (Class<ClassLoader>) Class
|
||||
.forName(loaderClassName, true, parent);
|
||||
private ClassLoader wrapWithCustomClassLoader(ClassLoader parent, String loaderClassName) throws Exception {
|
||||
Class<ClassLoader> loaderClass = (Class<ClassLoader>) Class.forName(loaderClassName, true, parent);
|
||||
|
||||
try {
|
||||
return loaderClass.getConstructor(ClassLoader.class).newInstance(parent);
|
||||
@@ -370,8 +361,7 @@ public class PropertiesLauncher extends Launcher {
|
||||
// Ignore and try with URLs
|
||||
}
|
||||
try {
|
||||
return loaderClass.getConstructor(URL[].class, ClassLoader.class)
|
||||
.newInstance(new URL[0], parent);
|
||||
return loaderClass.getConstructor(URL[].class, ClassLoader.class).newInstance(new URL[0], parent);
|
||||
}
|
||||
catch (NoSuchMethodException ex) {
|
||||
// Ignore and try without any arguments
|
||||
@@ -387,21 +377,18 @@ public class PropertiesLauncher extends Launcher {
|
||||
return getProperty(propertyKey, manifestKey, null);
|
||||
}
|
||||
|
||||
private String getPropertyWithDefault(String propertyKey, String defaultValue)
|
||||
throws Exception {
|
||||
private String getPropertyWithDefault(String propertyKey, String defaultValue) throws Exception {
|
||||
return getProperty(propertyKey, null, defaultValue);
|
||||
}
|
||||
|
||||
private String getProperty(String propertyKey, String manifestKey,
|
||||
String defaultValue) throws Exception {
|
||||
private String getProperty(String propertyKey, String manifestKey, String defaultValue) throws Exception {
|
||||
if (manifestKey == null) {
|
||||
manifestKey = propertyKey.replace('.', '-');
|
||||
manifestKey = toCamelCase(manifestKey);
|
||||
}
|
||||
String property = SystemPropertyUtils.getProperty(propertyKey);
|
||||
if (property != null) {
|
||||
String value = SystemPropertyUtils.resolvePlaceholders(this.properties,
|
||||
property);
|
||||
String value = SystemPropertyUtils.resolvePlaceholders(this.properties, property);
|
||||
debug("Property '" + propertyKey + "' from environment: " + value);
|
||||
return value;
|
||||
}
|
||||
@@ -418,10 +405,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
if (manifest != null) {
|
||||
String value = manifest.getMainAttributes().getValue(manifestKey);
|
||||
if (value != null) {
|
||||
debug("Property '" + manifestKey
|
||||
+ "' from home directory manifest: " + value);
|
||||
return SystemPropertyUtils.resolvePlaceholders(this.properties,
|
||||
value);
|
||||
debug("Property '" + manifestKey + "' from home directory manifest: " + value);
|
||||
return SystemPropertyUtils.resolvePlaceholders(this.properties, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -438,8 +423,7 @@ public class PropertiesLauncher extends Launcher {
|
||||
return SystemPropertyUtils.resolvePlaceholders(this.properties, value);
|
||||
}
|
||||
}
|
||||
return (defaultValue != null)
|
||||
? SystemPropertyUtils.resolvePlaceholders(this.properties, defaultValue)
|
||||
return (defaultValue != null) ? SystemPropertyUtils.resolvePlaceholders(this.properties, defaultValue)
|
||||
: defaultValue;
|
||||
}
|
||||
|
||||
@@ -449,8 +433,7 @@ public class PropertiesLauncher extends Launcher {
|
||||
for (String path : this.paths) {
|
||||
for (Archive archive : getClassPathArchives(path)) {
|
||||
if (archive instanceof ExplodedArchive) {
|
||||
List<Archive> nested = new ArrayList<Archive>(
|
||||
archive.getNestedArchives(new ArchiveEntryFilter()));
|
||||
List<Archive> nested = new ArrayList<Archive>(archive.getNestedArchives(new ArchiveEntryFilter()));
|
||||
nested.add(0, archive);
|
||||
lib.addAll(nested);
|
||||
}
|
||||
@@ -506,8 +489,7 @@ public class PropertiesLauncher extends Launcher {
|
||||
private List<Archive> getNestedArchives(String path) throws Exception {
|
||||
Archive parent = this.parent;
|
||||
String root = path;
|
||||
if (!root.equals("/") && root.startsWith("/")
|
||||
|| parent.getUrl().equals(this.home.toURI().toURL())) {
|
||||
if (!root.equals("/") && root.startsWith("/") || parent.getUrl().equals(this.home.toURI().toURL())) {
|
||||
// If home dir is same as parent archive, no need to add it twice.
|
||||
return null;
|
||||
}
|
||||
@@ -536,8 +518,7 @@ public class PropertiesLauncher extends Launcher {
|
||||
}
|
||||
EntryFilter filter = new PrefixMatchingArchiveFilter(root);
|
||||
List<Archive> archives = new ArrayList<Archive>(parent.getNestedArchives(filter));
|
||||
if (("".equals(root) || ".".equals(root)) && !path.endsWith(".jar")
|
||||
&& parent != this.parent) {
|
||||
if (("".equals(root) || ".".equals(root)) && !path.endsWith(".jar") && parent != this.parent) {
|
||||
// You can't find the root with an entry filter so it has to be added
|
||||
// explicitly. But don't add the root of the parent archive.
|
||||
archives.add(parent);
|
||||
|
||||
@@ -50,8 +50,7 @@ public class WarLauncher extends ExecutableArchiveLauncher {
|
||||
return entry.getName().equals(WEB_INF_CLASSES);
|
||||
}
|
||||
else {
|
||||
return entry.getName().startsWith(WEB_INF_LIB)
|
||||
|| entry.getName().startsWith(WEB_INF_LIB_PROVIDED);
|
||||
return entry.getName().startsWith(WEB_INF_LIB) || entry.getName().startsWith(WEB_INF_LIB_PROVIDED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +42,7 @@ import java.util.jar.Manifest;
|
||||
*/
|
||||
public class ExplodedArchive implements Archive {
|
||||
|
||||
private static final Set<String> SKIPPED_NAMES = new HashSet<String>(
|
||||
Arrays.asList(".", ".."));
|
||||
private static final Set<String> SKIPPED_NAMES = new HashSet<String>(Arrays.asList(".", ".."));
|
||||
|
||||
private final File root;
|
||||
|
||||
@@ -120,8 +119,7 @@ public class ExplodedArchive implements Archive {
|
||||
|
||||
protected Archive getNestedArchive(Entry entry) throws IOException {
|
||||
File file = ((FileEntry) entry).getFile();
|
||||
return (file.isDirectory() ? new ExplodedArchive(file)
|
||||
: new JarFileArchive(file));
|
||||
return (file.isDirectory() ? new ExplodedArchive(file) : new JarFileArchive(file));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -167,13 +165,11 @@ public class ExplodedArchive implements Archive {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
File file = this.current;
|
||||
if (file.isDirectory()
|
||||
&& (this.recursive || file.getParentFile().equals(this.root))) {
|
||||
if (file.isDirectory() && (this.recursive || file.getParentFile().equals(this.root))) {
|
||||
this.stack.addFirst(listFiles(file));
|
||||
}
|
||||
this.current = poll();
|
||||
String name = file.toURI().getPath()
|
||||
.substring(this.root.toURI().getPath().length());
|
||||
String name = file.toURI().getPath().substring(this.root.toURI().getPath().length());
|
||||
return new FileEntry(name, file);
|
||||
}
|
||||
|
||||
|
||||
@@ -105,8 +105,7 @@ public class JarFileArchive implements Archive {
|
||||
return new JarFileArchive(jarFile);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(
|
||||
"Failed to get nested archive for entry " + entry.getName(), ex);
|
||||
throw new IllegalStateException("Failed to get nested archive for entry " + entry.getName(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,14 +133,12 @@ public class JarFileArchive implements Archive {
|
||||
int attempts = 0;
|
||||
while (attempts++ < 1000) {
|
||||
String fileName = new File(this.jarFile.getName()).getName();
|
||||
File unpackFolder = new File(parent,
|
||||
fileName + "-spring-boot-libs-" + UUID.randomUUID());
|
||||
File unpackFolder = new File(parent, fileName + "-spring-boot-libs-" + UUID.randomUUID());
|
||||
if (unpackFolder.mkdirs()) {
|
||||
return unpackFolder;
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException(
|
||||
"Failed to create unpack folder in directory '" + parent + "'");
|
||||
throw new IllegalStateException("Failed to create unpack folder in directory '" + parent + "'");
|
||||
}
|
||||
|
||||
private void unpack(JarEntry entry, File file) throws IOException {
|
||||
|
||||
@@ -64,8 +64,7 @@ public class RandomAccessDataFile implements RandomAccessData {
|
||||
throw new IllegalArgumentException("File must not be null");
|
||||
}
|
||||
if (!file.exists()) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("File %s must exist", file.getAbsolutePath()));
|
||||
throw new IllegalArgumentException(String.format("File %s must exist", file.getAbsolutePath()));
|
||||
}
|
||||
this.file = file;
|
||||
this.filePool = new FilePool(file, concurrentReads);
|
||||
@@ -105,8 +104,7 @@ public class RandomAccessDataFile implements RandomAccessData {
|
||||
if (offset < 0 || length < 0 || offset + length > this.length) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
return new RandomAccessDataFile(this.file, this.filePool, this.offset + offset,
|
||||
length);
|
||||
return new RandomAccessDataFile(this.file, this.filePool, this.offset + offset, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -100,8 +100,8 @@ final class AsciiBytes {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < postfix.length; i++) {
|
||||
if (this.bytes[this.offset + (this.length - 1)
|
||||
- i] != postfix.bytes[postfix.offset + (postfix.length - 1) - i]) {
|
||||
if (this.bytes[this.offset + (this.length - 1) - i] != postfix.bytes[postfix.offset + (postfix.length - 1)
|
||||
- i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +59,7 @@ final class Bytes {
|
||||
return fill(inputStream, bytes, 0, bytes.length);
|
||||
}
|
||||
|
||||
private static boolean fill(InputStream inputStream, byte[] bytes, int offset,
|
||||
int length) throws IOException {
|
||||
private static boolean fill(InputStream inputStream, byte[] bytes, int offset, int length) throws IOException {
|
||||
while (length > 0) {
|
||||
int read = inputStream.read(bytes, offset, length);
|
||||
if (read == -1) {
|
||||
|
||||
@@ -62,8 +62,8 @@ class CentralDirectoryEndRecord {
|
||||
this.size++;
|
||||
if (this.size > this.block.length) {
|
||||
if (this.size >= MAXIMUM_SIZE || this.size > data.getSize()) {
|
||||
throw new IOException("Unable to find ZIP central directory "
|
||||
+ "records after reading " + this.size + " bytes");
|
||||
throw new IOException(
|
||||
"Unable to find ZIP central directory " + "records after reading " + this.size + " bytes");
|
||||
}
|
||||
this.block = createBlockFromEndOfData(data, this.size + READ_BLOCK_SIZE);
|
||||
}
|
||||
@@ -71,20 +71,17 @@ class CentralDirectoryEndRecord {
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] createBlockFromEndOfData(RandomAccessData data, int size)
|
||||
throws IOException {
|
||||
private byte[] createBlockFromEndOfData(RandomAccessData data, int size) throws IOException {
|
||||
int length = (int) Math.min(data.getSize(), size);
|
||||
return Bytes.get(data.getSubsection(data.getSize() - length, length));
|
||||
}
|
||||
|
||||
private boolean isValid() {
|
||||
if (this.block.length < MINIMUM_SIZE
|
||||
|| Bytes.littleEndianValue(this.block, this.offset + 0, 4) != SIGNATURE) {
|
||||
if (this.block.length < MINIMUM_SIZE || Bytes.littleEndianValue(this.block, this.offset + 0, 4) != SIGNATURE) {
|
||||
return false;
|
||||
}
|
||||
// Total size must be the structure size + comment
|
||||
long commentLength = Bytes.littleEndianValue(this.block,
|
||||
this.offset + COMMENT_LENGTH_OFFSET, 2);
|
||||
long commentLength = Bytes.littleEndianValue(this.block, this.offset + COMMENT_LENGTH_OFFSET, 2);
|
||||
return this.size == MINIMUM_SIZE + commentLength;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ final class CentralDirectoryFileHeader implements FileHeader {
|
||||
CentralDirectoryFileHeader() {
|
||||
}
|
||||
|
||||
CentralDirectoryFileHeader(byte[] header, int headerOffset, AsciiBytes name,
|
||||
byte[] extra, AsciiBytes comment, long localHeaderOffset) {
|
||||
CentralDirectoryFileHeader(byte[] header, int headerOffset, AsciiBytes name, byte[] extra, AsciiBytes comment,
|
||||
long localHeaderOffset) {
|
||||
super();
|
||||
this.header = header;
|
||||
this.headerOffset = headerOffset;
|
||||
@@ -64,8 +64,8 @@ final class CentralDirectoryFileHeader implements FileHeader {
|
||||
this.localHeaderOffset = localHeaderOffset;
|
||||
}
|
||||
|
||||
void load(byte[] data, int dataOffset, RandomAccessData variableData,
|
||||
int variableOffset, JarEntryFilter filter) throws IOException {
|
||||
void load(byte[] data, int dataOffset, RandomAccessData variableData, int variableOffset, JarEntryFilter filter)
|
||||
throws IOException {
|
||||
// Load fixed part
|
||||
this.header = data;
|
||||
this.headerOffset = dataOffset;
|
||||
@@ -76,8 +76,7 @@ final class CentralDirectoryFileHeader implements FileHeader {
|
||||
// Load variable part
|
||||
dataOffset += 46;
|
||||
if (variableData != null) {
|
||||
data = Bytes.get(variableData.getSubsection(variableOffset + 46,
|
||||
nameLength + extraLength + commentLength));
|
||||
data = Bytes.get(variableData.getSubsection(variableOffset + 46, nameLength + extraLength + commentLength));
|
||||
dataOffset = 0;
|
||||
}
|
||||
this.name = new AsciiBytes(data, dataOffset, (int) nameLength);
|
||||
@@ -88,12 +87,10 @@ final class CentralDirectoryFileHeader implements FileHeader {
|
||||
this.comment = NO_COMMENT;
|
||||
if (extraLength > 0) {
|
||||
this.extra = new byte[(int) extraLength];
|
||||
System.arraycopy(data, (int) (dataOffset + nameLength), this.extra, 0,
|
||||
this.extra.length);
|
||||
System.arraycopy(data, (int) (dataOffset + nameLength), this.extra, 0, this.extra.length);
|
||||
}
|
||||
if (commentLength > 0) {
|
||||
this.comment = new AsciiBytes(data,
|
||||
(int) (dataOffset + nameLength + extraLength), (int) commentLength);
|
||||
this.comment = new AsciiBytes(data, (int) (dataOffset + nameLength + extraLength), (int) commentLength);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,12 +167,11 @@ final class CentralDirectoryFileHeader implements FileHeader {
|
||||
public CentralDirectoryFileHeader clone() {
|
||||
byte[] header = new byte[46];
|
||||
System.arraycopy(this.header, this.headerOffset, header, 0, header.length);
|
||||
return new CentralDirectoryFileHeader(header, 0, this.name, header, this.comment,
|
||||
this.localHeaderOffset);
|
||||
return new CentralDirectoryFileHeader(header, 0, this.name, header, this.comment, this.localHeaderOffset);
|
||||
}
|
||||
|
||||
public static CentralDirectoryFileHeader fromRandomAccessData(RandomAccessData data,
|
||||
int offset, JarEntryFilter filter) throws IOException {
|
||||
public static CentralDirectoryFileHeader fromRandomAccessData(RandomAccessData data, int offset,
|
||||
JarEntryFilter filter) throws IOException {
|
||||
CentralDirectoryFileHeader fileHeader = new CentralDirectoryFileHeader();
|
||||
byte[] bytes = Bytes.get(data.getSubsection(offset, 46));
|
||||
fileHeader.load(bytes, 0, data, offset, filter);
|
||||
|
||||
@@ -46,8 +46,7 @@ class CentralDirectoryParser {
|
||||
* @return the actual archive data without any prefix bytes
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public RandomAccessData parse(RandomAccessData data, boolean skipPrefixBytes)
|
||||
throws IOException {
|
||||
public RandomAccessData parse(RandomAccessData data, boolean skipPrefixBytes) throws IOException {
|
||||
CentralDirectoryEndRecord endRecord = new CentralDirectoryEndRecord(data);
|
||||
if (skipPrefixBytes) {
|
||||
data = getArchiveData(endRecord, data);
|
||||
@@ -59,22 +58,20 @@ class CentralDirectoryParser {
|
||||
return data;
|
||||
}
|
||||
|
||||
private void parseEntries(CentralDirectoryEndRecord endRecord,
|
||||
RandomAccessData centralDirectoryData) throws IOException {
|
||||
private void parseEntries(CentralDirectoryEndRecord endRecord, RandomAccessData centralDirectoryData)
|
||||
throws IOException {
|
||||
byte[] bytes = Bytes.get(centralDirectoryData);
|
||||
CentralDirectoryFileHeader fileHeader = new CentralDirectoryFileHeader();
|
||||
int dataOffset = 0;
|
||||
for (int i = 0; i < endRecord.getNumberOfRecords(); i++) {
|
||||
fileHeader.load(bytes, dataOffset, null, 0, null);
|
||||
visitFileHeader(dataOffset, fileHeader);
|
||||
dataOffset += this.CENTRAL_DIRECTORY_HEADER_BASE_SIZE
|
||||
+ fileHeader.getName().length() + fileHeader.getComment().length()
|
||||
+ fileHeader.getExtra().length;
|
||||
dataOffset += this.CENTRAL_DIRECTORY_HEADER_BASE_SIZE + fileHeader.getName().length()
|
||||
+ fileHeader.getComment().length() + fileHeader.getExtra().length;
|
||||
}
|
||||
}
|
||||
|
||||
private RandomAccessData getArchiveData(CentralDirectoryEndRecord endRecord,
|
||||
RandomAccessData data) {
|
||||
private RandomAccessData getArchiveData(CentralDirectoryEndRecord endRecord, RandomAccessData data) {
|
||||
long offset = endRecord.getStartOfArchive(data);
|
||||
if (offset == 0) {
|
||||
return data;
|
||||
@@ -82,8 +79,7 @@ class CentralDirectoryParser {
|
||||
return data.getSubsection(offset, data.getSize() - offset);
|
||||
}
|
||||
|
||||
private void visitStart(CentralDirectoryEndRecord endRecord,
|
||||
RandomAccessData centralDirectoryData) {
|
||||
private void visitStart(CentralDirectoryEndRecord endRecord, RandomAccessData centralDirectoryData) {
|
||||
for (CentralDirectoryVisitor visitor : this.visitors) {
|
||||
visitor.visitStart(endRecord, centralDirectoryData);
|
||||
}
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.springframework.boot.loader.data.RandomAccessData;
|
||||
*/
|
||||
interface CentralDirectoryVisitor {
|
||||
|
||||
void visitStart(CentralDirectoryEndRecord endRecord,
|
||||
RandomAccessData centralDirectoryData);
|
||||
void visitStart(CentralDirectoryEndRecord endRecord, RandomAccessData centralDirectoryData);
|
||||
|
||||
void visitFileHeader(CentralDirectoryFileHeader fileHeader, int dataOffset);
|
||||
|
||||
|
||||
@@ -55,16 +55,14 @@ public class Handler extends URLStreamHandler {
|
||||
|
||||
private static final String PARENT_DIR = "/../";
|
||||
|
||||
private static final String[] FALLBACK_HANDLERS = {
|
||||
"sun.net.www.protocol.jar.Handler" };
|
||||
private static final String[] FALLBACK_HANDLERS = { "sun.net.www.protocol.jar.Handler" };
|
||||
|
||||
private static final Method OPEN_CONNECTION_METHOD;
|
||||
|
||||
static {
|
||||
Method method = null;
|
||||
try {
|
||||
method = URLStreamHandler.class.getDeclaredMethod("openConnection",
|
||||
URL.class);
|
||||
method = URLStreamHandler.class.getDeclaredMethod("openConnection", URL.class);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Swallow and ignore
|
||||
@@ -92,8 +90,7 @@ public class Handler extends URLStreamHandler {
|
||||
|
||||
@Override
|
||||
protected URLConnection openConnection(URL url) throws IOException {
|
||||
if (this.jarFile != null
|
||||
&& url.toString().startsWith(this.jarFile.getUrl().toString())) {
|
||||
if (this.jarFile != null && url.toString().startsWith(this.jarFile.getUrl().toString())) {
|
||||
return JarURLConnection.get(url, this.jarFile);
|
||||
}
|
||||
try {
|
||||
@@ -104,8 +101,7 @@ public class Handler extends URLStreamHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private URLConnection openFallbackConnection(URL url, Exception reason)
|
||||
throws IOException {
|
||||
private URLConnection openFallbackConnection(URL url, Exception reason) throws IOException {
|
||||
try {
|
||||
return openConnection(getFallbackHandler(), url);
|
||||
}
|
||||
@@ -124,8 +120,7 @@ public class Handler extends URLStreamHandler {
|
||||
|
||||
private void log(boolean warning, String message, Exception cause) {
|
||||
try {
|
||||
Logger.getLogger(getClass().getName())
|
||||
.log((warning ? Level.WARNING : Level.FINEST), message, cause);
|
||||
Logger.getLogger(getClass().getName()).log((warning ? Level.WARNING : Level.FINEST), message, cause);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (warning) {
|
||||
@@ -151,11 +146,9 @@ public class Handler extends URLStreamHandler {
|
||||
throw new IllegalStateException("Unable to find fallback handler");
|
||||
}
|
||||
|
||||
private URLConnection openConnection(URLStreamHandler handler, URL url)
|
||||
throws Exception {
|
||||
private URLConnection openConnection(URLStreamHandler handler, URL url) throws Exception {
|
||||
if (OPEN_CONNECTION_METHOD == null) {
|
||||
throw new IllegalStateException(
|
||||
"Unable to invoke fallback open connection method");
|
||||
throw new IllegalStateException("Unable to invoke fallback open connection method");
|
||||
}
|
||||
OPEN_CONNECTION_METHOD.setAccessible(true);
|
||||
return (URLConnection) OPEN_CONNECTION_METHOD.invoke(handler, url);
|
||||
@@ -195,8 +188,7 @@ public class Handler extends URLStreamHandler {
|
||||
}
|
||||
int lastSlashIndex = file.lastIndexOf('/');
|
||||
if (lastSlashIndex == -1) {
|
||||
throw new IllegalArgumentException(
|
||||
"No / found in context URL's file '" + file + "'");
|
||||
throw new IllegalArgumentException("No / found in context URL's file '" + file + "'");
|
||||
}
|
||||
return file.substring(0, lastSlashIndex + 1) + spec;
|
||||
}
|
||||
@@ -204,8 +196,7 @@ public class Handler extends URLStreamHandler {
|
||||
private String trimToJarRoot(String file) {
|
||||
int lastSeparatorIndex = file.lastIndexOf(SEPARATOR);
|
||||
if (lastSeparatorIndex == -1) {
|
||||
throw new IllegalArgumentException(
|
||||
"No !/ found in context URL's file '" + file + "'");
|
||||
throw new IllegalArgumentException("No !/ found in context URL's file '" + file + "'");
|
||||
}
|
||||
return file.substring(0, lastSeparatorIndex);
|
||||
}
|
||||
@@ -218,8 +209,7 @@ public class Handler extends URLStreamHandler {
|
||||
query = path.substring(queryIndex + 1);
|
||||
path = path.substring(0, queryIndex);
|
||||
}
|
||||
setURL(context, JAR_PROTOCOL, null, -1, null, null, path, query,
|
||||
context.getRef());
|
||||
setURL(context, JAR_PROTOCOL, null, -1, null, null, path, query, context.getRef());
|
||||
}
|
||||
|
||||
private String normalize(String file) {
|
||||
@@ -238,8 +228,7 @@ public class Handler extends URLStreamHandler {
|
||||
while ((parentDirIndex = file.indexOf(PARENT_DIR)) >= 0) {
|
||||
int precedingSlashIndex = file.lastIndexOf('/', parentDirIndex - 1);
|
||||
if (precedingSlashIndex >= 0) {
|
||||
file = file.substring(0, precedingSlashIndex)
|
||||
+ file.substring(parentDirIndex + 3);
|
||||
file = file.substring(0, precedingSlashIndex) + file.substring(parentDirIndex + 3);
|
||||
}
|
||||
else {
|
||||
file = file.substring(parentDirIndex + 4);
|
||||
@@ -359,8 +348,7 @@ public class Handler extends URLStreamHandler {
|
||||
* which are then swallowed.
|
||||
* @param useFastConnectionExceptions if fast connection exceptions can be used.
|
||||
*/
|
||||
public static void setUseFastConnectionExceptions(
|
||||
boolean useFastConnectionExceptions) {
|
||||
public static void setUseFastConnectionExceptions(boolean useFastConnectionExceptions) {
|
||||
JarURLConnection.setUseFastExceptions(useFastConnectionExceptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,8 +55,8 @@ class JarEntry extends java.util.jar.JarEntry implements FileHeader {
|
||||
|
||||
@Override
|
||||
public boolean hasName(String name, String suffix) {
|
||||
return getName().length() == name.length() + suffix.length()
|
||||
&& getName().startsWith(name) && getName().endsWith(suffix);
|
||||
return getName().length() == name.length() + suffix.length() && getName().startsWith(name)
|
||||
&& getName().endsWith(suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -101,14 +101,13 @@ public class JarFile extends java.util.jar.JarFile {
|
||||
* @param type the type of the jar file
|
||||
* @throws IOException if the file cannot be read
|
||||
*/
|
||||
private JarFile(RandomAccessDataFile rootFile, String pathFromRoot,
|
||||
RandomAccessData data, JarFileType type) throws IOException {
|
||||
private JarFile(RandomAccessDataFile rootFile, String pathFromRoot, RandomAccessData data, JarFileType type)
|
||||
throws IOException {
|
||||
this(rootFile, pathFromRoot, data, null, type);
|
||||
}
|
||||
|
||||
private JarFile(RandomAccessDataFile rootFile, String pathFromRoot,
|
||||
RandomAccessData data, JarEntryFilter filter, JarFileType type)
|
||||
throws IOException {
|
||||
private JarFile(RandomAccessDataFile rootFile, String pathFromRoot, RandomAccessData data, JarEntryFilter filter,
|
||||
JarFileType type) throws IOException {
|
||||
super(rootFile.getFile());
|
||||
this.rootFile = rootFile;
|
||||
this.pathFromRoot = pathFromRoot;
|
||||
@@ -123,16 +122,13 @@ public class JarFile extends java.util.jar.JarFile {
|
||||
return new CentralDirectoryVisitor() {
|
||||
|
||||
@Override
|
||||
public void visitStart(CentralDirectoryEndRecord endRecord,
|
||||
RandomAccessData centralDirectoryData) {
|
||||
public void visitStart(CentralDirectoryEndRecord endRecord, RandomAccessData centralDirectoryData) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFileHeader(CentralDirectoryFileHeader fileHeader,
|
||||
int dataOffset) {
|
||||
public void visitFileHeader(CentralDirectoryFileHeader fileHeader, int dataOffset) {
|
||||
AsciiBytes name = fileHeader.getName();
|
||||
if (name.startsWith(META_INF)
|
||||
&& name.endsWith(SIGNATURE_FILE_EXTENSION)) {
|
||||
if (name.startsWith(META_INF) && name.endsWith(SIGNATURE_FILE_EXTENSION)) {
|
||||
JarFile.this.signed = true;
|
||||
}
|
||||
}
|
||||
@@ -160,8 +156,7 @@ public class JarFile extends java.util.jar.JarFile {
|
||||
manifest = new JarFile(this.getRootJarFile()).getManifest();
|
||||
}
|
||||
else {
|
||||
InputStream inputStream = getInputStream(MANIFEST_NAME,
|
||||
ResourceAccess.ONCE);
|
||||
InputStream inputStream = getInputStream(MANIFEST_NAME, ResourceAccess.ONCE);
|
||||
if (inputStream == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -214,8 +209,7 @@ public class JarFile extends java.util.jar.JarFile {
|
||||
return getInputStream(ze, ResourceAccess.PER_READ);
|
||||
}
|
||||
|
||||
public InputStream getInputStream(ZipEntry ze, ResourceAccess access)
|
||||
throws IOException {
|
||||
public InputStream getInputStream(ZipEntry ze, ResourceAccess access) throws IOException {
|
||||
if (ze instanceof JarEntry) {
|
||||
return this.entries.getInputStream((JarEntry) ze, access);
|
||||
}
|
||||
@@ -232,8 +226,7 @@ public class JarFile extends java.util.jar.JarFile {
|
||||
* @return a {@link JarFile} for the entry
|
||||
* @throws IOException if the nested jar file cannot be read
|
||||
*/
|
||||
public synchronized JarFile getNestedJarFile(final ZipEntry entry)
|
||||
throws IOException {
|
||||
public synchronized JarFile getNestedJarFile(final ZipEntry entry) throws IOException {
|
||||
return getNestedJarFile((JarEntry) entry);
|
||||
}
|
||||
|
||||
@@ -248,8 +241,7 @@ public class JarFile extends java.util.jar.JarFile {
|
||||
return createJarFileFromEntry(entry);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IOException(
|
||||
"Unable to open nested jar file '" + entry.getName() + "'", ex);
|
||||
throw new IOException("Unable to open nested jar file '" + entry.getName() + "'", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,21 +266,20 @@ public class JarFile extends java.util.jar.JarFile {
|
||||
|
||||
};
|
||||
return new JarFile(this.rootFile,
|
||||
this.pathFromRoot + "!/"
|
||||
+ entry.getName().substring(0, sourceName.length() - 1),
|
||||
this.data, filter, JarFileType.NESTED_DIRECTORY);
|
||||
this.pathFromRoot + "!/" + entry.getName().substring(0, sourceName.length() - 1), this.data, filter,
|
||||
JarFileType.NESTED_DIRECTORY);
|
||||
}
|
||||
|
||||
private JarFile createJarFileFromFileEntry(JarEntry entry) throws IOException {
|
||||
if (entry.getMethod() != ZipEntry.STORED) {
|
||||
throw new IllegalStateException("Unable to open nested entry '"
|
||||
+ entry.getName() + "'. It has been compressed and nested "
|
||||
+ "jar files must be stored without compression. Please check the "
|
||||
+ "mechanism used to create your executable jar file");
|
||||
throw new IllegalStateException(
|
||||
"Unable to open nested entry '" + entry.getName() + "'. It has been compressed and nested "
|
||||
+ "jar files must be stored without compression. Please check the "
|
||||
+ "mechanism used to create your executable jar file");
|
||||
}
|
||||
RandomAccessData entryData = this.entries.getEntryData(entry.getName());
|
||||
return new JarFile(this.rootFile, this.pathFromRoot + "!/" + entry.getName(),
|
||||
entryData, JarFileType.NESTED_JAR);
|
||||
return new JarFile(this.rootFile, this.pathFromRoot + "!/" + entry.getName(), entryData,
|
||||
JarFileType.NESTED_JAR);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -336,8 +327,7 @@ public class JarFile extends java.util.jar.JarFile {
|
||||
// Fallback to JarInputStream to obtain certificates, not fast but hopefully not
|
||||
// happening that often.
|
||||
try {
|
||||
JarInputStream inputStream = new JarInputStream(
|
||||
getData().getInputStream(ResourceAccess.ONCE));
|
||||
JarInputStream inputStream = new JarInputStream(getData().getInputStream(ResourceAccess.ONCE));
|
||||
try {
|
||||
java.util.jar.JarEntry certEntry = inputStream.getNextJarEntry();
|
||||
while (certEntry != null) {
|
||||
@@ -382,8 +372,8 @@ public class JarFile extends java.util.jar.JarFile {
|
||||
*/
|
||||
public static void registerUrlProtocolHandler() {
|
||||
String handlers = System.getProperty(PROTOCOL_HANDLER, "");
|
||||
System.setProperty(PROTOCOL_HANDLER, ("".equals(handlers) ? HANDLERS_PACKAGE
|
||||
: handlers + "|" + HANDLERS_PACKAGE));
|
||||
System.setProperty(PROTOCOL_HANDLER,
|
||||
("".equals(handlers) ? HANDLERS_PACKAGE : handlers + "|" + HANDLERS_PACKAGE));
|
||||
resetCachedUrlHandlers();
|
||||
}
|
||||
|
||||
|
||||
@@ -70,8 +70,7 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
|
||||
.synchronizedMap(new LinkedHashMap<Integer, FileHeader>(16, 0.75f, true) {
|
||||
|
||||
@Override
|
||||
protected boolean removeEldestEntry(
|
||||
Map.Entry<Integer, FileHeader> eldest) {
|
||||
protected boolean removeEldestEntry(Map.Entry<Integer, FileHeader> eldest) {
|
||||
if (JarFileEntries.this.jarFile.isSigned()) {
|
||||
return false;
|
||||
}
|
||||
@@ -86,8 +85,7 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitStart(CentralDirectoryEndRecord endRecord,
|
||||
RandomAccessData centralDirectoryData) {
|
||||
public void visitStart(CentralDirectoryEndRecord endRecord, RandomAccessData centralDirectoryData) {
|
||||
int maxSize = endRecord.getNumberOfRecords();
|
||||
this.centralDirectoryData = centralDirectoryData;
|
||||
this.hashCodes = new int[maxSize];
|
||||
@@ -103,8 +101,7 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
|
||||
}
|
||||
}
|
||||
|
||||
private void add(AsciiBytes name, CentralDirectoryFileHeader fileHeader,
|
||||
int dataOffset) {
|
||||
private void add(AsciiBytes name, CentralDirectoryFileHeader fileHeader, int dataOffset) {
|
||||
this.hashCodes[this.size] = name.hashCode();
|
||||
this.centralDirectoryOffsets[this.size] = dataOffset;
|
||||
this.positions[this.size] = this.size;
|
||||
@@ -178,14 +175,12 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
|
||||
return getEntry(name, JarEntry.class, true);
|
||||
}
|
||||
|
||||
public InputStream getInputStream(String name, ResourceAccess access)
|
||||
throws IOException {
|
||||
public InputStream getInputStream(String name, ResourceAccess access) throws IOException {
|
||||
FileHeader entry = getEntry(name, FileHeader.class, false);
|
||||
return getInputStream(entry, access);
|
||||
}
|
||||
|
||||
public InputStream getInputStream(FileHeader entry, ResourceAccess access)
|
||||
throws IOException {
|
||||
public InputStream getInputStream(FileHeader entry, ResourceAccess access) throws IOException {
|
||||
if (entry == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -209,16 +204,14 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
|
||||
// local directory to the central directory. We need to re-read
|
||||
// here to skip them
|
||||
RandomAccessData data = this.jarFile.getData();
|
||||
byte[] localHeader = Bytes.get(
|
||||
data.getSubsection(entry.getLocalHeaderOffset(), LOCAL_FILE_HEADER_SIZE));
|
||||
byte[] localHeader = Bytes.get(data.getSubsection(entry.getLocalHeaderOffset(), LOCAL_FILE_HEADER_SIZE));
|
||||
long nameLength = Bytes.littleEndianValue(localHeader, 26, 2);
|
||||
long extraLength = Bytes.littleEndianValue(localHeader, 28, 2);
|
||||
return data.getSubsection(entry.getLocalHeaderOffset() + LOCAL_FILE_HEADER_SIZE
|
||||
+ nameLength + extraLength, entry.getCompressedSize());
|
||||
return data.getSubsection(entry.getLocalHeaderOffset() + LOCAL_FILE_HEADER_SIZE + nameLength + extraLength,
|
||||
entry.getCompressedSize());
|
||||
}
|
||||
|
||||
private <T extends FileHeader> T getEntry(String name, Class<T> type,
|
||||
boolean cacheEntry) {
|
||||
private <T extends FileHeader> T getEntry(String name, Class<T> type, boolean cacheEntry) {
|
||||
int hashCode = AsciiBytes.hashCode(name);
|
||||
T entry = getEntry(hashCode, name, NO_SUFFIX, type, cacheEntry);
|
||||
if (entry == null) {
|
||||
@@ -228,8 +221,8 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
|
||||
return entry;
|
||||
}
|
||||
|
||||
private <T extends FileHeader> T getEntry(int hashCode, String name, String suffix,
|
||||
Class<T> type, boolean cacheEntry) {
|
||||
private <T extends FileHeader> T getEntry(int hashCode, String name, String suffix, Class<T> type,
|
||||
boolean cacheEntry) {
|
||||
int index = getFirstIndex(hashCode);
|
||||
while (index >= 0 && index < this.size && this.hashCodes[index] == hashCode) {
|
||||
T entry = getEntry(index, type, cacheEntry);
|
||||
@@ -242,16 +235,12 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends FileHeader> T getEntry(int index, Class<T> type,
|
||||
boolean cacheEntry) {
|
||||
private <T extends FileHeader> T getEntry(int index, Class<T> type, boolean cacheEntry) {
|
||||
try {
|
||||
FileHeader cached = this.entriesCache.get(index);
|
||||
FileHeader entry = (cached != null) ? cached
|
||||
: CentralDirectoryFileHeader.fromRandomAccessData(
|
||||
this.centralDirectoryData,
|
||||
this.centralDirectoryOffsets[index], this.filter);
|
||||
if (CentralDirectoryFileHeader.class.equals(entry.getClass())
|
||||
&& type.equals(JarEntry.class)) {
|
||||
FileHeader entry = (cached != null) ? cached : CentralDirectoryFileHeader
|
||||
.fromRandomAccessData(this.centralDirectoryData, this.centralDirectoryOffsets[index], this.filter);
|
||||
if (CentralDirectoryFileHeader.class.equals(entry.getClass()) && type.equals(JarEntry.class)) {
|
||||
entry = new JarEntry(this.jarFile, (CentralDirectoryFileHeader) entry);
|
||||
}
|
||||
if (cacheEntry && cached != entry) {
|
||||
|
||||
@@ -72,8 +72,7 @@ final class JarURLConnection extends java.net.JarURLConnection {
|
||||
|
||||
private static final String READ_ACTION = "read";
|
||||
|
||||
private static final JarURLConnection NOT_FOUND_CONNECTION = JarURLConnection
|
||||
.notFound();
|
||||
private static final JarURLConnection NOT_FOUND_CONNECTION = JarURLConnection.notFound();
|
||||
|
||||
private final JarFile jarFile;
|
||||
|
||||
@@ -85,8 +84,7 @@ final class JarURLConnection extends java.net.JarURLConnection {
|
||||
|
||||
private JarEntry jarEntry;
|
||||
|
||||
private JarURLConnection(URL url, JarFile jarFile, JarEntryName jarEntryName)
|
||||
throws IOException {
|
||||
private JarURLConnection(URL url, JarFile jarFile, JarEntryName jarEntryName) throws IOException {
|
||||
// What we pass to super is ultimately ignored
|
||||
super(EMPTY_JAR_URL);
|
||||
this.url = url;
|
||||
@@ -163,8 +161,7 @@ final class JarURLConnection extends java.net.JarURLConnection {
|
||||
if (this.jarFile == null) {
|
||||
throw FILE_NOT_FOUND_EXCEPTION;
|
||||
}
|
||||
if (this.jarEntryName.isEmpty()
|
||||
&& this.jarFile.getType() == JarFile.JarFileType.DIRECT) {
|
||||
if (this.jarEntryName.isEmpty() && this.jarFile.getType() == JarFile.JarFileType.DIRECT) {
|
||||
throw new IOException("no entry name specified");
|
||||
}
|
||||
connect();
|
||||
@@ -177,13 +174,11 @@ final class JarURLConnection extends java.net.JarURLConnection {
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
private void throwFileNotFound(Object entry, JarFile jarFile)
|
||||
throws FileNotFoundException {
|
||||
private void throwFileNotFound(Object entry, JarFile jarFile) throws FileNotFoundException {
|
||||
if (Boolean.TRUE.equals(useFastExceptions.get())) {
|
||||
throw FILE_NOT_FOUND_EXCEPTION;
|
||||
}
|
||||
throw new FileNotFoundException(
|
||||
"JAR entry " + entry + " not found in " + jarFile.getName());
|
||||
throw new FileNotFoundException("JAR entry " + entry + " not found in " + jarFile.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -229,8 +224,7 @@ final class JarURLConnection extends java.net.JarURLConnection {
|
||||
throw FILE_NOT_FOUND_EXCEPTION;
|
||||
}
|
||||
if (this.permission == null) {
|
||||
this.permission = new FilePermission(
|
||||
this.jarFile.getRootJarFile().getFile().getPath(), READ_ACTION);
|
||||
this.permission = new FilePermission(this.jarFile.getRootJarFile().getFile().getPath(), READ_ACTION);
|
||||
}
|
||||
return this.permission;
|
||||
}
|
||||
@@ -272,8 +266,7 @@ final class JarURLConnection extends java.net.JarURLConnection {
|
||||
}
|
||||
JarEntryName jarEntryName = JarEntryName.get(spec, index);
|
||||
if (Boolean.TRUE.equals(useFastExceptions.get())) {
|
||||
if (!jarEntryName.isEmpty()
|
||||
&& !jarFile.containsEntry(jarEntryName.toString())) {
|
||||
if (!jarEntryName.isEmpty() && !jarFile.containsEntry(jarEntryName.toString())) {
|
||||
return NOT_FOUND_CONNECTION;
|
||||
}
|
||||
}
|
||||
@@ -299,8 +292,7 @@ final class JarURLConnection extends java.net.JarURLConnection {
|
||||
}
|
||||
}
|
||||
|
||||
private static JarURLConnection notFound(JarFile jarFile, JarEntryName jarEntryName)
|
||||
throws IOException {
|
||||
private static JarURLConnection notFound(JarFile jarFile, JarEntryName jarEntryName) throws IOException {
|
||||
if (Boolean.TRUE.equals(useFastExceptions.get())) {
|
||||
return NOT_FOUND_CONNECTION;
|
||||
}
|
||||
@@ -336,8 +328,7 @@ final class JarURLConnection extends java.net.JarURLConnection {
|
||||
int c = source.charAt(i);
|
||||
if (c > 127) {
|
||||
try {
|
||||
String encoded = URLEncoder.encode(String.valueOf((char) c),
|
||||
"UTF-8");
|
||||
String encoded = URLEncoder.encode(String.valueOf((char) c), "UTF-8");
|
||||
write(encoded, outputStream);
|
||||
}
|
||||
catch (UnsupportedEncodingException ex) {
|
||||
@@ -348,8 +339,7 @@ final class JarURLConnection extends java.net.JarURLConnection {
|
||||
if (c == '%') {
|
||||
if ((i + 2) >= length) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid encoded sequence \"" + source.substring(i)
|
||||
+ "\"");
|
||||
"Invalid encoded sequence \"" + source.substring(i) + "\"");
|
||||
}
|
||||
c = decodeEscapeSequence(source, i);
|
||||
i += 2;
|
||||
@@ -363,8 +353,7 @@ final class JarURLConnection extends java.net.JarURLConnection {
|
||||
int hi = Character.digit(source.charAt(i + 1), 16);
|
||||
int lo = Character.digit(source.charAt(i + 2), 16);
|
||||
if (hi == -1 || lo == -1) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid encoded sequence \"" + source.substring(i) + "\"");
|
||||
throw new IllegalArgumentException("Invalid encoded sequence \"" + source.substring(i) + "\"");
|
||||
}
|
||||
return ((char) ((hi << 4) + lo));
|
||||
}
|
||||
|
||||
@@ -87,8 +87,8 @@ public abstract class SystemPropertyUtils {
|
||||
return parseStringValue(properties, text, text, new HashSet<String>());
|
||||
}
|
||||
|
||||
private static String parseStringValue(Properties properties, String value,
|
||||
String current, Set<String> visitedPlaceholders) {
|
||||
private static String parseStringValue(Properties properties, String value, String current,
|
||||
Set<String> visitedPlaceholders) {
|
||||
|
||||
StringBuilder buf = new StringBuilder(current);
|
||||
|
||||
@@ -96,29 +96,24 @@ public abstract class SystemPropertyUtils {
|
||||
while (startIndex != -1) {
|
||||
int endIndex = findPlaceholderEndIndex(buf, startIndex);
|
||||
if (endIndex != -1) {
|
||||
String placeholder = buf
|
||||
.substring(startIndex + PLACEHOLDER_PREFIX.length(), endIndex);
|
||||
String placeholder = buf.substring(startIndex + PLACEHOLDER_PREFIX.length(), endIndex);
|
||||
String originalPlaceholder = placeholder;
|
||||
if (!visitedPlaceholders.add(originalPlaceholder)) {
|
||||
throw new IllegalArgumentException("Circular placeholder reference '"
|
||||
+ originalPlaceholder + "' in property definitions");
|
||||
throw new IllegalArgumentException(
|
||||
"Circular placeholder reference '" + originalPlaceholder + "' in property definitions");
|
||||
}
|
||||
// Recursive invocation, parsing placeholders contained in the
|
||||
// placeholder
|
||||
// key.
|
||||
placeholder = parseStringValue(properties, value, placeholder,
|
||||
visitedPlaceholders);
|
||||
placeholder = parseStringValue(properties, value, placeholder, visitedPlaceholders);
|
||||
// Now obtain the value for the fully resolved key...
|
||||
String propVal = resolvePlaceholder(properties, value, placeholder);
|
||||
if (propVal == null && VALUE_SEPARATOR != null) {
|
||||
int separatorIndex = placeholder.indexOf(VALUE_SEPARATOR);
|
||||
if (separatorIndex != -1) {
|
||||
String actualPlaceholder = placeholder.substring(0,
|
||||
separatorIndex);
|
||||
String defaultValue = placeholder
|
||||
.substring(separatorIndex + VALUE_SEPARATOR.length());
|
||||
propVal = resolvePlaceholder(properties, value,
|
||||
actualPlaceholder);
|
||||
String actualPlaceholder = placeholder.substring(0, separatorIndex);
|
||||
String defaultValue = placeholder.substring(separatorIndex + VALUE_SEPARATOR.length());
|
||||
propVal = resolvePlaceholder(properties, value, actualPlaceholder);
|
||||
if (propVal == null) {
|
||||
propVal = defaultValue;
|
||||
}
|
||||
@@ -127,17 +122,13 @@ public abstract class SystemPropertyUtils {
|
||||
if (propVal != null) {
|
||||
// Recursive invocation, parsing placeholders contained in the
|
||||
// previously resolved placeholder value.
|
||||
propVal = parseStringValue(properties, value, propVal,
|
||||
visitedPlaceholders);
|
||||
buf.replace(startIndex, endIndex + PLACEHOLDER_SUFFIX.length(),
|
||||
propVal);
|
||||
startIndex = buf.indexOf(PLACEHOLDER_PREFIX,
|
||||
startIndex + propVal.length());
|
||||
propVal = parseStringValue(properties, value, propVal, visitedPlaceholders);
|
||||
buf.replace(startIndex, endIndex + PLACEHOLDER_SUFFIX.length(), propVal);
|
||||
startIndex = buf.indexOf(PLACEHOLDER_PREFIX, startIndex + propVal.length());
|
||||
}
|
||||
else {
|
||||
// Proceed with unprocessed value.
|
||||
startIndex = buf.indexOf(PLACEHOLDER_PREFIX,
|
||||
endIndex + PLACEHOLDER_SUFFIX.length());
|
||||
startIndex = buf.indexOf(PLACEHOLDER_PREFIX, endIndex + PLACEHOLDER_SUFFIX.length());
|
||||
}
|
||||
visitedPlaceholders.remove(originalPlaceholder);
|
||||
}
|
||||
@@ -149,8 +140,7 @@ public abstract class SystemPropertyUtils {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static String resolvePlaceholder(Properties properties, String text,
|
||||
String placeholderName) {
|
||||
private static String resolvePlaceholder(Properties properties, String text, String placeholderName) {
|
||||
String propVal = getProperty(placeholderName, null, text);
|
||||
if (propVal != null) {
|
||||
return propVal;
|
||||
@@ -189,8 +179,7 @@ public abstract class SystemPropertyUtils {
|
||||
}
|
||||
if (propVal == null) {
|
||||
// Try uppercase with underscores as well.
|
||||
propVal = System
|
||||
.getenv(key.toUpperCase(Locale.ENGLISH).replace('.', '_'));
|
||||
propVal = System.getenv(key.toUpperCase(Locale.ENGLISH).replace('.', '_'));
|
||||
}
|
||||
if (propVal != null) {
|
||||
return propVal;
|
||||
@@ -227,8 +216,7 @@ public abstract class SystemPropertyUtils {
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static boolean substringMatch(CharSequence str, int index,
|
||||
CharSequence substring) {
|
||||
private static boolean substringMatch(CharSequence str, int index, CharSequence substring) {
|
||||
for (int j = 0; j < substring.length(); j++) {
|
||||
int i = index + j;
|
||||
if (i >= str.length() || str.charAt(i) != substring.charAt(j)) {
|
||||
|
||||
@@ -50,8 +50,7 @@ public class AbstractExecutableArchiveLauncherTests {
|
||||
|
||||
protected File createJarArchive(String name, String entryPrefix) throws IOException {
|
||||
File archive = this.temp.newFile(name);
|
||||
JarOutputStream jarOutputStream = new JarOutputStream(
|
||||
new FileOutputStream(archive));
|
||||
JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(archive));
|
||||
jarOutputStream.putNextEntry(new JarEntry(entryPrefix + "/"));
|
||||
jarOutputStream.putNextEntry(new JarEntry(entryPrefix + "/classes/"));
|
||||
jarOutputStream.putNextEntry(new JarEntry(entryPrefix + "/lib/"));
|
||||
@@ -80,8 +79,7 @@ public class AbstractExecutableArchiveLauncherTests {
|
||||
entryFile.mkdirs();
|
||||
}
|
||||
else {
|
||||
FileCopyUtils.copy(jarFile.getInputStream(entry),
|
||||
new FileOutputStream(entryFile));
|
||||
FileCopyUtils.copy(jarFile.getInputStream(entry), new FileOutputStream(entryFile));
|
||||
}
|
||||
}
|
||||
jarFile.close();
|
||||
|
||||
@@ -36,28 +36,22 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class JarLauncherTests extends AbstractExecutableArchiveLauncherTests {
|
||||
|
||||
@Test
|
||||
public void explodedJarHasOnlyBootInfClassesAndContentsOfBootInfLibOnClasspath()
|
||||
throws Exception {
|
||||
public void explodedJarHasOnlyBootInfClassesAndContentsOfBootInfLibOnClasspath() throws Exception {
|
||||
File explodedRoot = explode(createJarArchive("archive.jar", "BOOT-INF"));
|
||||
JarLauncher launcher = new JarLauncher(new ExplodedArchive(explodedRoot, true));
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
assertThat(archives).hasSize(2);
|
||||
assertThat(getUrls(archives)).containsOnly(
|
||||
new File(explodedRoot, "BOOT-INF/classes").toURI().toURL(),
|
||||
new URL("jar:"
|
||||
+ new File(explodedRoot, "BOOT-INF/lib/foo.jar").toURI().toURL()
|
||||
+ "!/"));
|
||||
assertThat(getUrls(archives)).containsOnly(new File(explodedRoot, "BOOT-INF/classes").toURI().toURL(),
|
||||
new URL("jar:" + new File(explodedRoot, "BOOT-INF/lib/foo.jar").toURI().toURL() + "!/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void archivedJarHasOnlyBootInfClassesAndContentsOfBootInfLibOnClasspath()
|
||||
throws Exception {
|
||||
public void archivedJarHasOnlyBootInfClassesAndContentsOfBootInfLibOnClasspath() throws Exception {
|
||||
File jarRoot = createJarArchive("archive.jar", "BOOT-INF");
|
||||
JarLauncher launcher = new JarLauncher(new JarFileArchive(jarRoot));
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
assertThat(archives).hasSize(2);
|
||||
assertThat(getUrls(archives)).containsOnly(
|
||||
new URL("jar:" + jarRoot.toURI().toURL() + "!/BOOT-INF/classes!/"),
|
||||
assertThat(getUrls(archives)).containsOnly(new URL("jar:" + jarRoot.toURI().toURL() + "!/BOOT-INF/classes!/"),
|
||||
new URL("jar:" + jarRoot.toURI().toURL() + "!/BOOT-INF/lib/foo.jar!/"));
|
||||
}
|
||||
|
||||
|
||||
@@ -43,33 +43,28 @@ public class LaunchedURLClassLoaderTests {
|
||||
@Test
|
||||
public void resolveResourceFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") }, getClass().getClassLoader());
|
||||
assertThat(loader.getResource("demo/Application.java")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourcesFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
assertThat(loader.getResources("demo/Application.java").hasMoreElements())
|
||||
.isTrue();
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") }, getClass().getClassLoader());
|
||||
assertThat(loader.getResources("demo/Application.java").hasMoreElements()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveRootPathFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") }, getClass().getClassLoader());
|
||||
assertThat(loader.getResource("")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveRootResourcesFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") }, getClass().getClassLoader());
|
||||
assertThat(loader.getResources("").hasMoreElements()).isTrue();
|
||||
}
|
||||
|
||||
@@ -79,8 +74,7 @@ public class LaunchedURLClassLoaderTests {
|
||||
TestJarCreator.createTestJar(file);
|
||||
JarFile jarFile = new JarFile(file);
|
||||
URL url = jarFile.getUrl();
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { url },
|
||||
null);
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { url }, null);
|
||||
URL resource = loader.getResource("nested.jar!/3.dat");
|
||||
assertThat(resource.toString()).isEqualTo(url + "nested.jar!/3.dat");
|
||||
assertThat(resource.openConnection().getInputStream().read()).isEqualTo(3);
|
||||
@@ -92,8 +86,7 @@ public class LaunchedURLClassLoaderTests {
|
||||
TestJarCreator.createTestJar(file);
|
||||
JarFile jarFile = new JarFile(file);
|
||||
URL url = jarFile.getUrl();
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { url },
|
||||
null);
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { url }, null);
|
||||
try {
|
||||
Thread.currentThread().interrupt();
|
||||
URL resource = loader.getResource("nested.jar!/3.dat");
|
||||
|
||||
@@ -67,8 +67,7 @@ public class PropertiesLauncherTests {
|
||||
public void setup() throws IOException {
|
||||
this.contextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
MockitoAnnotations.initMocks(this);
|
||||
System.setProperty("loader.home",
|
||||
new File("src/test/resources").getAbsolutePath());
|
||||
System.setProperty("loader.home", new File("src/test/resources").getAbsolutePath());
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -87,16 +86,14 @@ public class PropertiesLauncherTests {
|
||||
public void testDefaultHome() {
|
||||
System.clearProperty("loader.home");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(launcher.getHomeDirectory())
|
||||
.isEqualTo(new File(System.getProperty("user.dir")));
|
||||
assertThat(launcher.getHomeDirectory()).isEqualTo(new File(System.getProperty("user.dir")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlternateHome() throws Exception {
|
||||
System.setProperty("loader.home", "src/test/resources/home");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(launcher.getHomeDirectory())
|
||||
.isEqualTo(new File(System.getProperty("loader.home")));
|
||||
assertThat(launcher.getHomeDirectory()).isEqualTo(new File(System.getProperty("loader.home")));
|
||||
assertThat(launcher.getMainClass()).isEqualTo("demo.HomeApplication");
|
||||
}
|
||||
|
||||
@@ -105,8 +102,7 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.home", "src/test/resources/nonexistent");
|
||||
this.expected.expectMessage("Invalid source folder");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(launcher.getHomeDirectory())
|
||||
.isNotEqualTo(new File(System.getProperty("loader.home")));
|
||||
assertThat(launcher.getHomeDirectory()).isNotEqualTo(new File(System.getProperty("loader.home")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,8 +117,7 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.config.name", "foo");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(launcher.getMainClass()).isEqualTo("my.Application");
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
|
||||
.isEqualTo("[etc/]");
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString()).isEqualTo("[etc/]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,16 +131,14 @@ public class PropertiesLauncherTests {
|
||||
public void testUserSpecifiedDotPath() throws Exception {
|
||||
System.setProperty("loader.path", ".");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
|
||||
.isEqualTo("[.]");
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString()).isEqualTo("[.]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedSlashPath() throws Exception {
|
||||
System.setProperty("loader.path", "jars/");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
|
||||
.isEqualTo("[jars/]");
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString()).isEqualTo("[jars/]");
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
assertThat(archives).areExactly(1, endingWith("app.jar!/"));
|
||||
}
|
||||
@@ -155,8 +148,7 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "jars/*");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
|
||||
.isEqualTo("[jars/]");
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString()).isEqualTo("[jars/]");
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
@@ -166,16 +158,14 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "jars/app.jar");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
|
||||
.isEqualTo("[jars/app.jar]");
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString()).isEqualTo("[jars/app.jar]");
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedRootOfJarPath() throws Exception {
|
||||
System.setProperty("loader.path",
|
||||
"jar:file:./src/test/resources/nested-jars/app.jar!/");
|
||||
System.setProperty("loader.path", "jar:file:./src/test/resources/nested-jars/app.jar!/");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
|
||||
.isEqualTo("[jar:file:./src/test/resources/nested-jars/app.jar!/]");
|
||||
@@ -195,8 +185,7 @@ public class PropertiesLauncherTests {
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedRootOfJarPathWithDotAndJarPrefix() throws Exception {
|
||||
System.setProperty("loader.path",
|
||||
"jar:file:./src/test/resources/nested-jars/app.jar!/./");
|
||||
System.setProperty("loader.path", "jar:file:./src/test/resources/nested-jars/app.jar!/./");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
assertThat(archives).areExactly(1, endingWith("foo.jar!/"));
|
||||
@@ -213,8 +202,7 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedDirectoryContainingJarFileWithNestedArchives()
|
||||
throws Exception {
|
||||
public void testUserSpecifiedDirectoryContainingJarFileWithNestedArchives() throws Exception {
|
||||
System.setProperty("loader.path", "nested-jars");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
@@ -227,8 +215,7 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "./jars/app.jar");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
|
||||
.isEqualTo("[jars/app.jar]");
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString()).isEqualTo("[jars/app.jar]");
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
@@ -238,8 +225,7 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "jars/app.jar");
|
||||
System.setProperty("loader.classLoader", URLClassLoader.class.getName());
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
|
||||
.isEqualTo("[jars/app.jar]");
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString()).isEqualTo("[jars/app.jar]");
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
@@ -308,25 +294,21 @@ public class PropertiesLauncherTests {
|
||||
public void testArgsEnhanced() throws Exception {
|
||||
System.setProperty("loader.args", "foo");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(Arrays.asList(launcher.getArgs("bar")).toString())
|
||||
.isEqualTo("[foo, bar]");
|
||||
assertThat(Arrays.asList(launcher.getArgs("bar")).toString()).isEqualTo("[foo, bar]");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testLoadPathCustomizedUsingManifest() throws Exception {
|
||||
System.setProperty("loader.home",
|
||||
this.temporaryFolder.getRoot().getAbsolutePath());
|
||||
System.setProperty("loader.home", this.temporaryFolder.getRoot().getAbsolutePath());
|
||||
Manifest manifest = new Manifest();
|
||||
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
|
||||
manifest.getMainAttributes().putValue("Loader-Path", "/foo.jar, /bar");
|
||||
File manifestFile = new File(this.temporaryFolder.getRoot(),
|
||||
"META-INF/MANIFEST.MF");
|
||||
File manifestFile = new File(this.temporaryFolder.getRoot(), "META-INF/MANIFEST.MF");
|
||||
manifestFile.getParentFile().mkdirs();
|
||||
manifest.write(new FileOutputStream(manifestFile));
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat((List<String>) ReflectionTestUtils.getField(launcher, "paths"))
|
||||
.containsExactly("/foo.jar", "/bar/");
|
||||
assertThat((List<String>) ReflectionTestUtils.getField(launcher, "paths")).containsExactly("/foo.jar", "/bar/");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -59,8 +59,8 @@ public abstract class TestJarCreator {
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeNestedEntry(String name, boolean unpackNested,
|
||||
JarOutputStream jarOutputStream) throws Exception, IOException {
|
||||
private static void writeNestedEntry(String name, boolean unpackNested, JarOutputStream jarOutputStream)
|
||||
throws Exception, IOException {
|
||||
JarEntry nestedEntry = new JarEntry(name);
|
||||
byte[] nestedJarData = getNestedJarData();
|
||||
nestedEntry.setSize(nestedJarData.length);
|
||||
@@ -89,8 +89,7 @@ public abstract class TestJarCreator {
|
||||
return byteArrayOutputStream.toByteArray();
|
||||
}
|
||||
|
||||
private static void writeManifest(JarOutputStream jarOutputStream, String name)
|
||||
throws Exception {
|
||||
private static void writeManifest(JarOutputStream jarOutputStream, String name) throws Exception {
|
||||
writeDirEntry(jarOutputStream, "META-INF/");
|
||||
Manifest manifest = new Manifest();
|
||||
manifest.getMainAttributes().putValue("Built-By", name);
|
||||
@@ -100,14 +99,12 @@ public abstract class TestJarCreator {
|
||||
jarOutputStream.closeEntry();
|
||||
}
|
||||
|
||||
private static void writeDirEntry(JarOutputStream jarOutputStream, String name)
|
||||
throws IOException {
|
||||
private static void writeDirEntry(JarOutputStream jarOutputStream, String name) throws IOException {
|
||||
jarOutputStream.putNextEntry(new JarEntry(name));
|
||||
jarOutputStream.closeEntry();
|
||||
}
|
||||
|
||||
private static void writeEntry(JarOutputStream jarOutputStream, String name, int data)
|
||||
throws IOException {
|
||||
private static void writeEntry(JarOutputStream jarOutputStream, String name, int data) throws IOException {
|
||||
jarOutputStream.putNextEntry(new JarEntry(name));
|
||||
jarOutputStream.write(new byte[] { (byte) data });
|
||||
jarOutputStream.closeEntry();
|
||||
|
||||
@@ -36,28 +36,22 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class WarLauncherTests extends AbstractExecutableArchiveLauncherTests {
|
||||
|
||||
@Test
|
||||
public void explodedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath()
|
||||
throws Exception {
|
||||
public void explodedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath() throws Exception {
|
||||
File explodedRoot = explode(createJarArchive("archive.war", "WEB-INF"));
|
||||
WarLauncher launcher = new WarLauncher(new ExplodedArchive(explodedRoot, true));
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
assertThat(archives).hasSize(2);
|
||||
assertThat(getUrls(archives)).containsOnly(
|
||||
new File(explodedRoot, "WEB-INF/classes").toURI().toURL(),
|
||||
new URL("jar:"
|
||||
+ new File(explodedRoot, "WEB-INF/lib/foo.jar").toURI().toURL()
|
||||
+ "!/"));
|
||||
assertThat(getUrls(archives)).containsOnly(new File(explodedRoot, "WEB-INF/classes").toURI().toURL(),
|
||||
new URL("jar:" + new File(explodedRoot, "WEB-INF/lib/foo.jar").toURI().toURL() + "!/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void archivedWarHasOnlyWebInfClassesAndContentsOWebInfLibOnClasspath()
|
||||
throws Exception {
|
||||
public void archivedWarHasOnlyWebInfClassesAndContentsOWebInfLibOnClasspath() throws Exception {
|
||||
File jarRoot = createJarArchive("archive.war", "WEB-INF");
|
||||
WarLauncher launcher = new WarLauncher(new JarFileArchive(jarRoot));
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
assertThat(archives).hasSize(2);
|
||||
assertThat(getUrls(archives)).containsOnly(
|
||||
new URL("jar:" + jarRoot.toURI().toURL() + "!/WEB-INF/classes!/"),
|
||||
assertThat(getUrls(archives)).containsOnly(new URL("jar:" + jarRoot.toURI().toURL() + "!/WEB-INF/classes!/"),
|
||||
new URL("jar:" + jarRoot.toURI().toURL() + "!/WEB-INF/lib/foo.jar!/"));
|
||||
}
|
||||
|
||||
|
||||
@@ -69,15 +69,13 @@ public class ExplodedArchiveTests {
|
||||
File file = this.temporaryFolder.newFile();
|
||||
TestJarCreator.createTestJar(file);
|
||||
|
||||
this.rootFolder = (StringUtils.hasText(folderName)
|
||||
? this.temporaryFolder.newFolder(folderName)
|
||||
this.rootFolder = (StringUtils.hasText(folderName) ? this.temporaryFolder.newFolder(folderName)
|
||||
: this.temporaryFolder.newFolder());
|
||||
JarFile jarFile = new JarFile(file);
|
||||
Enumeration<JarEntry> entries = jarFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
JarEntry entry = entries.nextElement();
|
||||
File destination = new File(
|
||||
this.rootFolder.getAbsolutePath() + File.separator + entry.getName());
|
||||
File destination = new File(this.rootFolder.getAbsolutePath() + File.separator + entry.getName());
|
||||
destination.getParentFile().mkdirs();
|
||||
if (entry.isDirectory()) {
|
||||
destination.mkdir();
|
||||
@@ -101,8 +99,7 @@ public class ExplodedArchiveTests {
|
||||
|
||||
@Test
|
||||
public void getManifest() throws Exception {
|
||||
assertThat(this.archive.getManifest().getMainAttributes().getValue("Built-By"))
|
||||
.isEqualTo("j1");
|
||||
assertThat(this.archive.getManifest().getMainAttributes().getValue("Built-By")).isEqualTo("j1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,8 +123,7 @@ public class ExplodedArchiveTests {
|
||||
public void getNestedArchive() throws Exception {
|
||||
Entry entry = getEntriesMap(this.archive).get("nested.jar");
|
||||
Archive nested = this.archive.getNestedArchive(entry);
|
||||
assertThat(nested.getUrl().toString())
|
||||
.isEqualTo("jar:" + this.rootFolder.toURI() + "nested.jar!/");
|
||||
assertThat(nested.getUrl().toString()).isEqualTo("jar:" + this.rootFolder.toURI() + "nested.jar!/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,8 +132,7 @@ public class ExplodedArchiveTests {
|
||||
Archive nested = this.archive.getNestedArchive(entry);
|
||||
Map<String, Entry> nestedEntries = getEntriesMap(nested);
|
||||
assertThat(nestedEntries.size()).isEqualTo(1);
|
||||
assertThat(nested.getUrl().toString())
|
||||
.isEqualTo("file:" + this.rootFolder.toURI().getPath() + "d/");
|
||||
assertThat(nested.getUrl().toString()).isEqualTo("file:" + this.rootFolder.toURI().getPath() + "d/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -149,8 +144,7 @@ public class ExplodedArchiveTests {
|
||||
|
||||
@Test
|
||||
public void getNonRecursiveManifest() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(
|
||||
new File("src/test/resources/root"));
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"));
|
||||
assertThat(archive.getManifest()).isNotNull();
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(archive);
|
||||
assertThat(entries.size()).isEqualTo(4);
|
||||
@@ -158,8 +152,7 @@ public class ExplodedArchiveTests {
|
||||
|
||||
@Test
|
||||
public void getNonRecursiveManifestEvenIfNonRecursive() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"),
|
||||
false);
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"), false);
|
||||
assertThat(archive.getManifest()).isNotNull();
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(archive);
|
||||
assertThat(entries.size()).isEqualTo(3);
|
||||
@@ -167,23 +160,19 @@ public class ExplodedArchiveTests {
|
||||
|
||||
@Test
|
||||
public void getResourceAsStream() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(
|
||||
new File("src/test/resources/root"));
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"));
|
||||
assertThat(archive.getManifest()).isNotNull();
|
||||
URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() });
|
||||
assertThat(loader.getResourceAsStream("META-INF/spring/application.xml"))
|
||||
.isNotNull();
|
||||
assertThat(loader.getResourceAsStream("META-INF/spring/application.xml")).isNotNull();
|
||||
loader.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getResourceAsStreamNonRecursive() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"),
|
||||
false);
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"), false);
|
||||
assertThat(archive.getManifest()).isNotNull();
|
||||
URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() });
|
||||
assertThat(loader.getResourceAsStream("META-INF/spring/application.xml"))
|
||||
.isNotNull();
|
||||
assertThat(loader.getResourceAsStream("META-INF/spring/application.xml")).isNotNull();
|
||||
loader.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -75,8 +75,7 @@ public class JarFileArchiveTests {
|
||||
|
||||
@Test
|
||||
public void getManifest() throws Exception {
|
||||
assertThat(this.archive.getManifest().getMainAttributes().getValue("Built-By"))
|
||||
.isEqualTo("j1");
|
||||
assertThat(this.archive.getManifest().getMainAttributes().getValue("Built-By")).isEqualTo("j1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,8 +94,7 @@ public class JarFileArchiveTests {
|
||||
public void getNestedArchive() throws Exception {
|
||||
Entry entry = getEntriesMap(this.archive).get("nested.jar");
|
||||
Archive nested = this.archive.getNestedArchive(entry);
|
||||
assertThat(nested.getUrl().toString())
|
||||
.isEqualTo("jar:" + this.rootJarFileUrl + "!/nested.jar!/");
|
||||
assertThat(nested.getUrl().toString()).isEqualTo("jar:" + this.rootJarFileUrl + "!/nested.jar!/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -122,12 +120,10 @@ public class JarFileArchiveTests {
|
||||
@Test
|
||||
public void unpackedLocationsFromSameArchiveShareSameParent() throws Exception {
|
||||
setup(true);
|
||||
File nested = new File(this.archive
|
||||
.getNestedArchive(getEntriesMap(this.archive).get("nested.jar")).getUrl()
|
||||
.toURI());
|
||||
File anotherNested = new File(this.archive
|
||||
.getNestedArchive(getEntriesMap(this.archive).get("another-nested.jar"))
|
||||
.getUrl().toURI());
|
||||
File nested = new File(
|
||||
this.archive.getNestedArchive(getEntriesMap(this.archive).get("nested.jar")).getUrl().toURI());
|
||||
File anotherNested = new File(
|
||||
this.archive.getNestedArchive(getEntriesMap(this.archive).get("another-nested.jar")).getUrl().toURI());
|
||||
assertThat(nested.getParent()).isEqualTo(anotherNested.getParent());
|
||||
}
|
||||
|
||||
@@ -156,10 +152,8 @@ public class JarFileArchiveTests {
|
||||
output.closeEntry();
|
||||
output.close();
|
||||
JarFileArchive jarFileArchive = new JarFileArchive(file);
|
||||
this.thrown.expectMessage(
|
||||
equalTo("Failed to get nested archive for entry nested/zip64.jar"));
|
||||
jarFileArchive
|
||||
.getNestedArchive(getEntriesMap(jarFileArchive).get("nested/zip64.jar"));
|
||||
this.thrown.expectMessage(equalTo("Failed to get nested archive for entry nested/zip64.jar"));
|
||||
jarFileArchive.getNestedArchive(getEntriesMap(jarFileArchive).get("nested/zip64.jar"));
|
||||
}
|
||||
|
||||
private byte[] writeZip64Jar() throws IOException {
|
||||
|
||||
@@ -47,8 +47,7 @@ public class ByteArrayRandomAccessDataTests {
|
||||
RandomAccessData data = new ByteArrayRandomAccessData(bytes);
|
||||
data = data.getSubsection(1, 4).getSubsection(1, 2);
|
||||
InputStream inputStream = data.getInputStream(ResourceAccess.PER_READ);
|
||||
assertThat(FileCopyUtils.copyToByteArray(inputStream))
|
||||
.isEqualTo(new byte[] { 2, 3 });
|
||||
assertThat(FileCopyUtils.copyToByteArray(inputStream)).isEqualTo(new byte[] { 2, 3 });
|
||||
assertThat(data.getSize()).isEqualTo(2L);
|
||||
}
|
||||
|
||||
|
||||
@@ -106,8 +106,7 @@ public class RandomAccessDataFileTests {
|
||||
@Test
|
||||
public void fileExists() throws Exception {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage(String.format("File %s must exist",
|
||||
new File("/does/not/exist").getAbsolutePath()));
|
||||
this.thrown.expectMessage(String.format("File %s must exist", new File("/does/not/exist").getAbsolutePath()));
|
||||
new RandomAccessDataFile(new File("/does/not/exist"));
|
||||
}
|
||||
|
||||
@@ -121,8 +120,7 @@ public class RandomAccessDataFileTests {
|
||||
@Test
|
||||
public void fileExistsWithConcurrentReads() throws Exception {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage(String.format("File %s must exist",
|
||||
new File("/does/not/exist").getAbsolutePath()));
|
||||
this.thrown.expectMessage(String.format("File %s must exist", new File("/does/not/exist").getAbsolutePath()));
|
||||
new RandomAccessDataFile(new File("/does/not/exist"), 1);
|
||||
}
|
||||
|
||||
@@ -225,8 +223,7 @@ public class RandomAccessDataFileTests {
|
||||
@Test
|
||||
public void subsectionZeroLength() throws Exception {
|
||||
RandomAccessData subsection = this.file.getSubsection(0, 0);
|
||||
assertThat(subsection.getInputStream(ResourceAccess.PER_READ).read())
|
||||
.isEqualTo(-1);
|
||||
assertThat(subsection.getInputStream(ResourceAccess.PER_READ).read()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -246,8 +243,7 @@ public class RandomAccessDataFileTests {
|
||||
@Test
|
||||
public void subsection() throws Exception {
|
||||
RandomAccessData subsection = this.file.getSubsection(1, 1);
|
||||
assertThat(subsection.getInputStream(ResourceAccess.PER_READ).read())
|
||||
.isEqualTo(1);
|
||||
assertThat(subsection.getInputStream(ResourceAccess.PER_READ).read()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -296,8 +292,7 @@ public class RandomAccessDataFileTests {
|
||||
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
InputStream subsectionInputStream = RandomAccessDataFileTests.this.file
|
||||
.getSubsection(0, 256)
|
||||
InputStream subsectionInputStream = RandomAccessDataFileTests.this.file.getSubsection(0, 256)
|
||||
.getInputStream(ResourceAccess.PER_READ);
|
||||
byte[] b = new byte[256];
|
||||
subsectionInputStream.read(b);
|
||||
@@ -325,22 +320,19 @@ public class RandomAccessDataFileTests {
|
||||
|
||||
@Test
|
||||
public void seekFailuresDoNotPreventSubsequentReads() throws Exception {
|
||||
FilePool filePool = (FilePool) ReflectionTestUtils.getField(this.file,
|
||||
"filePool");
|
||||
FilePool filePool = (FilePool) ReflectionTestUtils.getField(this.file, "filePool");
|
||||
FilePool spiedPool = spy(filePool);
|
||||
ReflectionTestUtils.setField(this.file, "filePool", spiedPool);
|
||||
willAnswer(new Answer<RandomAccessFile>() {
|
||||
|
||||
@Override
|
||||
public RandomAccessFile answer(InvocationOnMock invocation) throws Throwable {
|
||||
RandomAccessFile originalFile = (RandomAccessFile) invocation
|
||||
.callRealMethod();
|
||||
RandomAccessFile originalFile = (RandomAccessFile) invocation.callRealMethod();
|
||||
if (new MockUtil().isSpy(originalFile)) {
|
||||
return originalFile;
|
||||
}
|
||||
RandomAccessFile spiedFile = spy(originalFile);
|
||||
willThrow(new IOException("Seek failed")).given(spiedFile)
|
||||
.seek(anyLong());
|
||||
willThrow(new IOException("Seek failed")).given(spiedFile).seek(anyLong());
|
||||
return spiedFile;
|
||||
}
|
||||
|
||||
|
||||
@@ -126,8 +126,7 @@ public class AsciiBytesTests {
|
||||
public void hashCodeAndEquals() throws Exception {
|
||||
AsciiBytes abcd = new AsciiBytes(new byte[] { 65, 66, 67, 68 });
|
||||
AsciiBytes bc = new AsciiBytes(new byte[] { 66, 67 });
|
||||
AsciiBytes bc_substring = new AsciiBytes(new byte[] { 65, 66, 67, 68 })
|
||||
.substring(1, 3);
|
||||
AsciiBytes bc_substring = new AsciiBytes(new byte[] { 65, 66, 67, 68 }).substring(1, 3);
|
||||
AsciiBytes bc_string = new AsciiBytes("BC");
|
||||
assertThat(bc.hashCode()).isEqualTo(bc.hashCode());
|
||||
assertThat(bc.hashCode()).isEqualTo(bc_substring.hashCode());
|
||||
|
||||
@@ -66,10 +66,8 @@ public class CentralDirectoryParserTests {
|
||||
parser.addVisitor(visitor);
|
||||
parser.parse(this.jarData, false);
|
||||
InOrder ordered = inOrder(visitor);
|
||||
ordered.verify(visitor).visitStart(any(CentralDirectoryEndRecord.class),
|
||||
any(RandomAccessData.class));
|
||||
ordered.verify(visitor, atLeastOnce())
|
||||
.visitFileHeader(any(CentralDirectoryFileHeader.class), anyInt());
|
||||
ordered.verify(visitor).visitStart(any(CentralDirectoryEndRecord.class), any(RandomAccessData.class));
|
||||
ordered.verify(visitor, atLeastOnce()).visitFileHeader(any(CentralDirectoryFileHeader.class), anyInt());
|
||||
ordered.verify(visitor).visitEnd();
|
||||
}
|
||||
|
||||
@@ -99,13 +97,11 @@ public class CentralDirectoryParserTests {
|
||||
private List<CentralDirectoryFileHeader> headers = new ArrayList<CentralDirectoryFileHeader>();
|
||||
|
||||
@Override
|
||||
public void visitStart(CentralDirectoryEndRecord endRecord,
|
||||
RandomAccessData centralDirectoryData) {
|
||||
public void visitStart(CentralDirectoryEndRecord endRecord, RandomAccessData centralDirectoryData) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFileHeader(CentralDirectoryFileHeader fileHeader,
|
||||
int dataOffset) {
|
||||
public void visitFileHeader(CentralDirectoryFileHeader fileHeader, int dataOffset) {
|
||||
this.headers.add(fileHeader.clone());
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,7 @@ public class HandlerTests {
|
||||
private final Handler handler = new Handler();
|
||||
|
||||
@Test
|
||||
public void parseUrlWithJarRootContextAndAbsoluteSpecThatUsesContext()
|
||||
throws MalformedURLException {
|
||||
public void parseUrlWithJarRootContextAndAbsoluteSpecThatUsesContext() throws MalformedURLException {
|
||||
String spec = "/entry.txt";
|
||||
URL context = createUrl("file:example.jar!/");
|
||||
this.handler.parseURL(context, spec, 0, spec.length());
|
||||
@@ -42,8 +41,7 @@ public class HandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseUrlWithDirectoryEntryContextAndAbsoluteSpecThatUsesContext()
|
||||
throws MalformedURLException {
|
||||
public void parseUrlWithDirectoryEntryContextAndAbsoluteSpecThatUsesContext() throws MalformedURLException {
|
||||
String spec = "/entry.txt";
|
||||
URL context = createUrl("file:example.jar!/dir/");
|
||||
this.handler.parseURL(context, spec, 0, spec.length());
|
||||
@@ -51,8 +49,7 @@ public class HandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseUrlWithJarRootContextAndRelativeSpecThatUsesContext()
|
||||
throws MalformedURLException {
|
||||
public void parseUrlWithJarRootContextAndRelativeSpecThatUsesContext() throws MalformedURLException {
|
||||
String spec = "entry.txt";
|
||||
URL context = createUrl("file:example.jar!/");
|
||||
this.handler.parseURL(context, spec, 0, spec.length());
|
||||
@@ -60,23 +57,19 @@ public class HandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseUrlWithDirectoryEntryContextAndRelativeSpecThatUsesContext()
|
||||
throws MalformedURLException {
|
||||
public void parseUrlWithDirectoryEntryContextAndRelativeSpecThatUsesContext() throws MalformedURLException {
|
||||
String spec = "entry.txt";
|
||||
URL context = createUrl("file:example.jar!/dir/");
|
||||
this.handler.parseURL(context, spec, 0, spec.length());
|
||||
assertThat(context.toExternalForm())
|
||||
.isEqualTo("jar:file:example.jar!/dir/entry.txt");
|
||||
assertThat(context.toExternalForm()).isEqualTo("jar:file:example.jar!/dir/entry.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseUrlWithFileEntryContextAndRelativeSpecThatUsesContext()
|
||||
throws MalformedURLException {
|
||||
public void parseUrlWithFileEntryContextAndRelativeSpecThatUsesContext() throws MalformedURLException {
|
||||
String spec = "entry.txt";
|
||||
URL context = createUrl("file:example.jar!/dir/file");
|
||||
this.handler.parseURL(context, spec, 0, spec.length());
|
||||
assertThat(context.toExternalForm())
|
||||
.isEqualTo("jar:file:example.jar!/dir/entry.txt");
|
||||
assertThat(context.toExternalForm()).isEqualTo("jar:file:example.jar!/dir/entry.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,96 +78,77 @@ public class HandlerTests {
|
||||
String spec = "jar:file:/other.jar!/nested!/entry.txt";
|
||||
URL context = createUrl("file:example.jar!/dir/file");
|
||||
this.handler.parseURL(context, spec, 0, spec.length());
|
||||
assertThat(context.toExternalForm())
|
||||
.isEqualTo("jar:jar:file:/other.jar!/nested!/entry.txt");
|
||||
assertThat(context.toExternalForm()).isEqualTo("jar:jar:file:/other.jar!/nested!/entry.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameFileReturnsFalseForUrlsWithDifferentProtocols()
|
||||
throws MalformedURLException {
|
||||
assertThat(this.handler.sameFile(new URL("jar:file:foo.jar!/content.txt"),
|
||||
new URL("file:/foo.jar"))).isFalse();
|
||||
public void sameFileReturnsFalseForUrlsWithDifferentProtocols() throws MalformedURLException {
|
||||
assertThat(this.handler.sameFile(new URL("jar:file:foo.jar!/content.txt"), new URL("file:/foo.jar"))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameFileReturnsFalseForDifferentFileInSameJar()
|
||||
throws MalformedURLException {
|
||||
assertThat(this.handler.sameFile(
|
||||
new URL("jar:file:foo.jar!/the/path/to/the/first/content.txt"),
|
||||
public void sameFileReturnsFalseForDifferentFileInSameJar() throws MalformedURLException {
|
||||
assertThat(this.handler.sameFile(new URL("jar:file:foo.jar!/the/path/to/the/first/content.txt"),
|
||||
new URL("jar:file:/foo.jar!/content.txt"))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameFileReturnsFalseForSameFileInDifferentJars()
|
||||
throws MalformedURLException {
|
||||
assertThat(this.handler.sameFile(
|
||||
new URL("jar:file:/the/path/to/the/first.jar!/content.txt"),
|
||||
public void sameFileReturnsFalseForSameFileInDifferentJars() throws MalformedURLException {
|
||||
assertThat(this.handler.sameFile(new URL("jar:file:/the/path/to/the/first.jar!/content.txt"),
|
||||
new URL("jar:file:/second.jar!/content.txt"))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameFileReturnsTrueForSameFileInSameJar() throws MalformedURLException {
|
||||
assertThat(this.handler.sameFile(
|
||||
new URL("jar:file:/the/path/to/the/first.jar!/content.txt"),
|
||||
assertThat(this.handler.sameFile(new URL("jar:file:/the/path/to/the/first.jar!/content.txt"),
|
||||
new URL("jar:file:/the/path/to/the/first.jar!/content.txt"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameFileReturnsTrueForUrlsThatReferenceSameFileViaNestedArchiveAndFromRootOfJar()
|
||||
throws MalformedURLException {
|
||||
assertThat(this.handler.sameFile(
|
||||
new URL("jar:file:/test.jar!/BOOT-INF/classes!/foo.txt"),
|
||||
assertThat(this.handler.sameFile(new URL("jar:file:/test.jar!/BOOT-INF/classes!/foo.txt"),
|
||||
new URL("jar:file:/test.jar!/BOOT-INF/classes/foo.txt"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashcodesAreEqualForUrlsThatReferenceSameFileViaNestedArchiveAndFromRootOfJar()
|
||||
throws MalformedURLException {
|
||||
assertThat(this.handler
|
||||
.hashCode(new URL("jar:file:/test.jar!/BOOT-INF/classes!/foo.txt")))
|
||||
.isEqualTo(this.handler.hashCode(
|
||||
new URL("jar:file:/test.jar!/BOOT-INF/classes/foo.txt")));
|
||||
assertThat(this.handler.hashCode(new URL("jar:file:/test.jar!/BOOT-INF/classes!/foo.txt")))
|
||||
.isEqualTo(this.handler.hashCode(new URL("jar:file:/test.jar!/BOOT-INF/classes/foo.txt")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlWithSpecReferencingParentDirectory() throws MalformedURLException {
|
||||
assertStandardAndCustomHandlerUrlsAreEqual(
|
||||
"file:/test.jar!/BOOT-INF/classes!/xsd/folderA/a.xsd",
|
||||
assertStandardAndCustomHandlerUrlsAreEqual("file:/test.jar!/BOOT-INF/classes!/xsd/folderA/a.xsd",
|
||||
"../folderB/b.xsd");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlWithSpecReferencingAncestorDirectoryOutsideJarStopsAtJarRoot()
|
||||
throws MalformedURLException {
|
||||
assertStandardAndCustomHandlerUrlsAreEqual(
|
||||
"file:/test.jar!/BOOT-INF/classes!/xsd/folderA/a.xsd",
|
||||
public void urlWithSpecReferencingAncestorDirectoryOutsideJarStopsAtJarRoot() throws MalformedURLException {
|
||||
assertStandardAndCustomHandlerUrlsAreEqual("file:/test.jar!/BOOT-INF/classes!/xsd/folderA/a.xsd",
|
||||
"../../../../../../folderB/b.xsd");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlWithSpecReferencingCurrentDirectory() throws MalformedURLException {
|
||||
assertStandardAndCustomHandlerUrlsAreEqual(
|
||||
"file:/test.jar!/BOOT-INF/classes!/xsd/folderA/a.xsd",
|
||||
assertStandardAndCustomHandlerUrlsAreEqual("file:/test.jar!/BOOT-INF/classes!/xsd/folderA/a.xsd",
|
||||
"./folderB/./b.xsd");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlWithRef() throws MalformedURLException {
|
||||
assertStandardAndCustomHandlerUrlsAreEqual("file:/test.jar!/BOOT-INF/classes",
|
||||
"!/foo.txt#alpha");
|
||||
assertStandardAndCustomHandlerUrlsAreEqual("file:/test.jar!/BOOT-INF/classes", "!/foo.txt#alpha");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlWithQuery() throws MalformedURLException {
|
||||
assertStandardAndCustomHandlerUrlsAreEqual("file:/test.jar!/BOOT-INF/classes",
|
||||
"!/foo.txt?alpha");
|
||||
assertStandardAndCustomHandlerUrlsAreEqual("file:/test.jar!/BOOT-INF/classes", "!/foo.txt?alpha");
|
||||
}
|
||||
|
||||
private void assertStandardAndCustomHandlerUrlsAreEqual(String context, String spec)
|
||||
throws MalformedURLException {
|
||||
private void assertStandardAndCustomHandlerUrlsAreEqual(String context, String spec) throws MalformedURLException {
|
||||
URL standardUrl = new URL(new URL("jar:" + context), spec);
|
||||
URL customHandlerUrl = new URL(new URL("jar", null, -1, context, this.handler),
|
||||
spec);
|
||||
URL customHandlerUrl = new URL(new URL("jar", null, -1, context, this.handler), spec);
|
||||
assertThat(customHandlerUrl.toString()).isEqualTo(standardUrl.toString());
|
||||
assertThat(customHandlerUrl.getFile()).isEqualTo(standardUrl.getFile());
|
||||
assertThat(customHandlerUrl.getPath()).isEqualTo(standardUrl.getPath());
|
||||
|
||||
@@ -38,21 +38,17 @@ public class JarEntryNameTests {
|
||||
|
||||
@Test
|
||||
public void nameWithSingleByteEncodedCharacters() {
|
||||
assertThat(new JarEntryName("%61/%62/%43.class").toString())
|
||||
.isEqualTo("a/b/C.class");
|
||||
assertThat(new JarEntryName("%61/%62/%43.class").toString()).isEqualTo("a/b/C.class");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nameWithDoubleByteEncodedCharacters() {
|
||||
assertThat(new JarEntryName("%c3%a1/b/C.class").toString())
|
||||
.isEqualTo("\u00e1/b/C.class");
|
||||
assertThat(new JarEntryName("%c3%a1/b/C.class").toString()).isEqualTo("\u00e1/b/C.class");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nameWithMixtureOfEncodedAndUnencodedDoubleByteCharacters()
|
||||
throws UnsupportedEncodingException {
|
||||
assertThat(new JarEntryName("%c3%a1/b/\u00c7.class").toString())
|
||||
.isEqualTo("\u00e1/b/\u00c7.class");
|
||||
public void nameWithMixtureOfEncodedAndUnencodedDoubleByteCharacters() throws UnsupportedEncodingException {
|
||||
assertThat(new JarEntryName("%c3%a1/b/\u00c7.class").toString()).isEqualTo("\u00e1/b/\u00c7.class");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -112,8 +112,7 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void getManifest() throws Exception {
|
||||
assertThat(this.jarFile.getManifest().getMainAttributes().getValue("Built-By"))
|
||||
.isEqualTo("j1");
|
||||
assertThat(this.jarFile.getManifest().getMainAttributes().getValue("Built-By")).isEqualTo("j1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -142,8 +141,7 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void getSpecialResourceViaClassLoader() throws Exception {
|
||||
URLClassLoader urlClassLoader = new URLClassLoader(
|
||||
new URL[] { this.jarFile.getUrl() });
|
||||
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { this.jarFile.getUrl() });
|
||||
assertThat(urlClassLoader.getResource("special/\u00EB.dat")).isNotNull();
|
||||
urlClassLoader.close();
|
||||
}
|
||||
@@ -157,8 +155,7 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void getInputStream() throws Exception {
|
||||
InputStream inputStream = this.jarFile
|
||||
.getInputStream(this.jarFile.getEntry("1.dat"));
|
||||
InputStream inputStream = this.jarFile.getInputStream(this.jarFile.getEntry("1.dat"));
|
||||
assertThat(inputStream.available()).isEqualTo(1);
|
||||
assertThat(inputStream.read()).isEqualTo(1);
|
||||
assertThat(inputStream.available()).isEqualTo(0);
|
||||
@@ -191,8 +188,7 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void close() throws Exception {
|
||||
RandomAccessDataFile randomAccessDataFile = spy(
|
||||
new RandomAccessDataFile(this.rootJarFile, 1));
|
||||
RandomAccessDataFile randomAccessDataFile = spy(new RandomAccessDataFile(this.rootJarFile, 1));
|
||||
JarFile jarFile = new JarFile(randomAccessDataFile);
|
||||
jarFile.close();
|
||||
verify(randomAccessDataFile).close();
|
||||
@@ -208,19 +204,16 @@ public class JarFileTests {
|
||||
assertThat(jarURLConnection.getContentLength()).isGreaterThan(1);
|
||||
assertThat(jarURLConnection.getContent()).isSameAs(this.jarFile);
|
||||
assertThat(jarURLConnection.getContentType()).isEqualTo("x-java/jar");
|
||||
assertThat(jarURLConnection.getJarFileURL().toURI())
|
||||
.isEqualTo(this.rootJarFile.toURI());
|
||||
assertThat(jarURLConnection.getJarFileURL().toURI()).isEqualTo(this.rootJarFile.toURI());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createEntryUrl() throws Exception {
|
||||
URL url = new URL(this.jarFile.getUrl(), "1.dat");
|
||||
assertThat(url.toString())
|
||||
.isEqualTo("jar:" + this.rootJarFile.toURI() + "!/1.dat");
|
||||
assertThat(url.toString()).isEqualTo("jar:" + this.rootJarFile.toURI() + "!/1.dat");
|
||||
JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection();
|
||||
assertThat(jarURLConnection.getJarFile()).isSameAs(this.jarFile);
|
||||
assertThat(jarURLConnection.getJarEntry())
|
||||
.isSameAs(this.jarFile.getJarEntry("1.dat"));
|
||||
assertThat(jarURLConnection.getJarEntry()).isSameAs(this.jarFile.getJarEntry("1.dat"));
|
||||
assertThat(jarURLConnection.getContentLength()).isEqualTo(1);
|
||||
assertThat(jarURLConnection.getContent()).isInstanceOf(InputStream.class);
|
||||
assertThat(jarURLConnection.getContentType()).isEqualTo("content/unknown");
|
||||
@@ -233,8 +226,7 @@ public class JarFileTests {
|
||||
@Test
|
||||
public void getMissingEntryUrl() throws Exception {
|
||||
URL url = new URL(this.jarFile.getUrl(), "missing.dat");
|
||||
assertThat(url.toString())
|
||||
.isEqualTo("jar:" + this.rootJarFile.toURI() + "!/missing.dat");
|
||||
assertThat(url.toString()).isEqualTo("jar:" + this.rootJarFile.toURI() + "!/missing.dat");
|
||||
this.thrown.expect(FileNotFoundException.class);
|
||||
((JarURLConnection) url.openConnection()).getJarEntry();
|
||||
}
|
||||
@@ -258,8 +250,7 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void getNestedJarFile() throws Exception {
|
||||
JarFile nestedJarFile = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
|
||||
Enumeration<java.util.jar.JarEntry> entries = nestedJarFile.entries();
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/");
|
||||
@@ -269,18 +260,15 @@ public class JarFileTests {
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("\u00E4.dat");
|
||||
assertThat(entries.hasMoreElements()).isFalse();
|
||||
|
||||
InputStream inputStream = nestedJarFile
|
||||
.getInputStream(nestedJarFile.getEntry("3.dat"));
|
||||
InputStream inputStream = nestedJarFile.getInputStream(nestedJarFile.getEntry("3.dat"));
|
||||
assertThat(inputStream.read()).isEqualTo(3);
|
||||
assertThat(inputStream.read()).isEqualTo(-1);
|
||||
|
||||
URL url = nestedJarFile.getUrl();
|
||||
assertThat(url.toString())
|
||||
.isEqualTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar!/");
|
||||
assertThat(url.toString()).isEqualTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar!/");
|
||||
JarURLConnection conn = (JarURLConnection) url.openConnection();
|
||||
assertThat(conn.getJarFile()).isSameAs(nestedJarFile);
|
||||
assertThat(conn.getJarFileURL().toString())
|
||||
.isEqualTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar");
|
||||
assertThat(conn.getJarFileURL().toString()).isEqualTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar");
|
||||
assertThat(conn.getInputStream()).isNotNull();
|
||||
JarInputStream jarInputStream = new JarInputStream(conn.getInputStream());
|
||||
assertThat(jarInputStream.getNextJarEntry().getName()).isEqualTo("3.dat");
|
||||
@@ -295,31 +283,26 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void getNestedJarDirectory() throws Exception {
|
||||
JarFile nestedJarFile = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("d/"));
|
||||
JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile.getEntry("d/"));
|
||||
|
||||
Enumeration<java.util.jar.JarEntry> entries = nestedJarFile.entries();
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("9.dat");
|
||||
assertThat(entries.hasMoreElements()).isFalse();
|
||||
|
||||
InputStream inputStream = nestedJarFile
|
||||
.getInputStream(nestedJarFile.getEntry("9.dat"));
|
||||
InputStream inputStream = nestedJarFile.getInputStream(nestedJarFile.getEntry("9.dat"));
|
||||
assertThat(inputStream.read()).isEqualTo(9);
|
||||
assertThat(inputStream.read()).isEqualTo(-1);
|
||||
|
||||
URL url = nestedJarFile.getUrl();
|
||||
assertThat(url.toString()).isEqualTo("jar:" + this.rootJarFile.toURI() + "!/d!/");
|
||||
assertThat(((JarURLConnection) url.openConnection()).getJarFile())
|
||||
.isSameAs(nestedJarFile);
|
||||
assertThat(((JarURLConnection) url.openConnection()).getJarFile()).isSameAs(nestedJarFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNestedJarEntryUrl() throws Exception {
|
||||
JarFile nestedJarFile = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
URL url = nestedJarFile.getJarEntry("3.dat").getUrl();
|
||||
assertThat(url.toString())
|
||||
.isEqualTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar!/3.dat");
|
||||
assertThat(url.toString()).isEqualTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar!/3.dat");
|
||||
InputStream inputStream = url.openStream();
|
||||
assertThat(inputStream).isNotNull();
|
||||
assertThat(inputStream.read()).isEqualTo(3);
|
||||
@@ -336,8 +319,7 @@ public class JarFileTests {
|
||||
assertThat(inputStream.read()).isEqualTo(3);
|
||||
JarURLConnection connection = (JarURLConnection) url.openConnection();
|
||||
assertThat(connection.getURL().toString()).isEqualTo(spec);
|
||||
assertThat(connection.getJarFileURL().toString())
|
||||
.isEqualTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar");
|
||||
assertThat(connection.getJarFileURL().toString()).isEqualTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar");
|
||||
assertThat(connection.getEntryName()).isEqualTo("3.dat");
|
||||
}
|
||||
|
||||
@@ -348,8 +330,7 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void createNonNestedUrlFromPathString() throws Exception {
|
||||
nonNestedJarFileFromString(
|
||||
"jar:" + this.rootJarFile.toPath().toUri() + "!/2.dat");
|
||||
nonNestedJarFileFromString("jar:" + this.rootJarFile.toPath().toUri() + "!/2.dat");
|
||||
}
|
||||
|
||||
private void nonNestedJarFileFromString(String spec) throws Exception {
|
||||
@@ -361,15 +342,13 @@ public class JarFileTests {
|
||||
assertThat(inputStream.read()).isEqualTo(2);
|
||||
JarURLConnection connection = (JarURLConnection) url.openConnection();
|
||||
assertThat(connection.getURL().toString()).isEqualTo(spec);
|
||||
assertThat(connection.getJarFileURL().toURI())
|
||||
.isEqualTo(this.rootJarFile.toURI());
|
||||
assertThat(connection.getJarFileURL().toURI()).isEqualTo(this.rootJarFile.toURI());
|
||||
assertThat(connection.getEntryName()).isEqualTo("2.dat");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDirectoryInputStream() throws Exception {
|
||||
InputStream inputStream = this.jarFile
|
||||
.getInputStream(this.jarFile.getEntry("d/"));
|
||||
InputStream inputStream = this.jarFile.getInputStream(this.jarFile.getEntry("d/"));
|
||||
assertThat(inputStream).isNotNull();
|
||||
assertThat(inputStream.read()).isEqualTo(-1);
|
||||
}
|
||||
@@ -384,8 +363,8 @@ public class JarFileTests {
|
||||
@Test
|
||||
public void sensibleToString() throws Exception {
|
||||
assertThat(this.jarFile.toString()).isEqualTo(this.rootJarFile.getPath());
|
||||
assertThat(this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"))
|
||||
.toString()).isEqualTo(this.rootJarFile.getPath() + "!/nested.jar");
|
||||
assertThat(this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar")).toString())
|
||||
.isEqualTo(this.rootJarFile.getPath() + "!/nested.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -432,8 +411,7 @@ public class JarFileTests {
|
||||
@Test
|
||||
public void cannotLoadMissingJar() throws Exception {
|
||||
// relates to gh-1070
|
||||
JarFile nestedJarFile = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
URL nestedUrl = nestedJarFile.getUrl();
|
||||
URL url = new URL(nestedUrl, nestedJarFile.getUrl() + "missing.jar!/3.dat");
|
||||
this.thrown.expect(FileNotFoundException.class);
|
||||
@@ -493,14 +471,12 @@ public class JarFileTests {
|
||||
JarURLConnection.setUseFastExceptions(true);
|
||||
try {
|
||||
JarFile.registerUrlProtocolHandler();
|
||||
JarFile nested = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
URL context = nested.getUrl();
|
||||
new URL(context, "jar:" + this.rootJarFile.toURI() + "!/nested.jar!/3.dat")
|
||||
.openConnection().getInputStream().close();
|
||||
new URL(context, "jar:" + this.rootJarFile.toURI() + "!/nested.jar!/3.dat").openConnection()
|
||||
.getInputStream().close();
|
||||
this.thrown.expect(FileNotFoundException.class);
|
||||
new URL(context, "jar:" + this.rootJarFile.toURI() + "!/no.dat")
|
||||
.openConnection().getInputStream().close();
|
||||
new URL(context, "jar:" + this.rootJarFile.toURI() + "!/no.dat").openConnection().getInputStream().close();
|
||||
}
|
||||
finally {
|
||||
JarURLConnection.setUseFastExceptions(false);
|
||||
|
||||
@@ -60,15 +60,13 @@ public class JarURLConnectionTests {
|
||||
@Test
|
||||
public void connectionToRootUsingAbsoluteUrl() throws Exception {
|
||||
URL url = new URL("jar:file:" + getAbsolutePath() + "!/");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getContent())
|
||||
.isSameAs(this.jarFile);
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getContent()).isSameAs(this.jarFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToRootUsingRelativeUrl() throws Exception {
|
||||
URL url = new URL("jar:file:" + getRelativePath() + "!/");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getContent())
|
||||
.isSameAs(this.jarFile);
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getContent()).isSameAs(this.jarFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,8 +84,7 @@ public class JarURLConnectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingAbsoluteUrlWithFileColonSlashSlashPrefix()
|
||||
throws Exception {
|
||||
public void connectionToEntryUsingAbsoluteUrlWithFileColonSlashSlashPrefix() throws Exception {
|
||||
URL url = new URL("jar:file:/" + getAbsolutePath() + "!/1.dat");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
|
||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 1 }));
|
||||
@@ -108,32 +105,26 @@ public class JarURLConnectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingAbsoluteUrlForEntryFromNestedJarFile()
|
||||
throws Exception {
|
||||
public void connectionToEntryUsingAbsoluteUrlForEntryFromNestedJarFile() throws Exception {
|
||||
URL url = new URL("jar:file:" + getAbsolutePath() + "!/nested.jar!/3.dat");
|
||||
JarFile nested = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
assertThat(JarURLConnection.get(url, nested).getInputStream())
|
||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingRelativeUrlForEntryFromNestedJarFile()
|
||||
throws Exception {
|
||||
public void connectionToEntryUsingRelativeUrlForEntryFromNestedJarFile() throws Exception {
|
||||
URL url = new URL("jar:file:" + getRelativePath() + "!/nested.jar!/3.dat");
|
||||
JarFile nested = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
assertThat(JarURLConnection.get(url, nested).getInputStream())
|
||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryInNestedJarFromUrlThatUsesExistingUrlAsContext()
|
||||
throws Exception {
|
||||
URL url = new URL(new URL("jar", null, -1,
|
||||
"file:" + getAbsolutePath() + "!/nested.jar!/", new Handler()), "/3.dat");
|
||||
JarFile nested = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
public void connectionToEntryInNestedJarFromUrlThatUsesExistingUrlAsContext() throws Exception {
|
||||
URL url = new URL(new URL("jar", null, -1, "file:" + getAbsolutePath() + "!/nested.jar!/", new Handler()),
|
||||
"/3.dat");
|
||||
JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
assertThat(JarURLConnection.get(url, nested).getInputStream())
|
||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
|
||||
}
|
||||
@@ -147,33 +138,30 @@ public class JarURLConnectionTests {
|
||||
|
||||
@Test
|
||||
public void connectionToEntryWithEncodedSpaceNestedEntry() throws Exception {
|
||||
URL url = new URL(
|
||||
"jar:file:" + getRelativePath() + "!/space%20nested.jar!/3.dat");
|
||||
URL url = new URL("jar:file:" + getRelativePath() + "!/space%20nested.jar!/3.dat");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
|
||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingWrongAbsoluteUrlForEntryFromNestedJarFile()
|
||||
throws Exception {
|
||||
public void connectionToEntryUsingWrongAbsoluteUrlForEntryFromNestedJarFile() throws Exception {
|
||||
URL url = new URL("jar:file:" + getAbsolutePath() + "!/w.jar!/3.dat");
|
||||
JarFile nested = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
this.thrown.expect(FileNotFoundException.class);
|
||||
JarURLConnection.get(url, nested).getInputStream();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContentLengthReturnsLengthOfUnderlyingEntry() throws Exception {
|
||||
URL url = new URL(new URL("jar", null, -1,
|
||||
"file:" + getAbsolutePath() + "!/nested.jar!/", new Handler()), "/3.dat");
|
||||
URL url = new URL(new URL("jar", null, -1, "file:" + getAbsolutePath() + "!/nested.jar!/", new Handler()),
|
||||
"/3.dat");
|
||||
assertThat(url.openConnection().getContentLength()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContentLengthLongReturnsLengthOfUnderlyingEntry() throws Exception {
|
||||
URL url = new URL(new URL("jar", null, -1,
|
||||
"file:" + getAbsolutePath() + "!/nested.jar!/", new Handler()), "/3.dat");
|
||||
URL url = new URL(new URL("jar", null, -1, "file:" + getAbsolutePath() + "!/nested.jar!/", new Handler()),
|
||||
"/3.dat");
|
||||
assertThat(url.openConnection().getContentLengthLong()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@@ -181,8 +169,7 @@ public class JarURLConnectionTests {
|
||||
public void getLastModifiedReturnsLastModifiedTimeOfJarEntry() throws Exception {
|
||||
URL url = new URL("jar:file:" + getAbsolutePath() + "!/1.dat");
|
||||
JarURLConnection connection = JarURLConnection.get(url, this.jarFile);
|
||||
assertThat(connection.getLastModified())
|
||||
.isEqualTo(connection.getJarEntry().getTime());
|
||||
assertThat(connection.getLastModified()).isEqualTo(connection.getJarEntry().getTime());
|
||||
}
|
||||
|
||||
private String getAbsolutePath() {
|
||||
|
||||
@@ -46,20 +46,17 @@ public class SystemPropertyUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testDefaultValue() {
|
||||
assertThat(SystemPropertyUtils.resolvePlaceholders("${bar:foo}"))
|
||||
.isEqualTo("foo");
|
||||
assertThat(SystemPropertyUtils.resolvePlaceholders("${bar:foo}")).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedPlaceholder() {
|
||||
assertThat(SystemPropertyUtils.resolvePlaceholders("${bar:${spam:foo}}"))
|
||||
.isEqualTo("foo");
|
||||
assertThat(SystemPropertyUtils.resolvePlaceholders("${bar:${spam:foo}}")).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnvVar() {
|
||||
assertThat(SystemPropertyUtils.getProperty("lang"))
|
||||
.isEqualTo(System.getenv("LANG"));
|
||||
assertThat(SystemPropertyUtils.getProperty("lang")).isEqualTo(System.getenv("LANG"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user