Merge branch '2.0.x' into 2.1.x

Closes gh-17078
This commit is contained in:
Andy Wilkinson
2019-06-07 10:50:34 +01:00
2691 changed files with 27746 additions and 46049 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,16 +58,14 @@ 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<>(
this.archive.getNestedArchives(this::isNestedArchive));
List<Archive> archives = new ArrayList<>(this.archive.getNestedArchives(this::isNestedArchive));
postProcessClassPathArchives(archives);
return archives;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -73,8 +73,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 {
@@ -86,8 +85,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);
@@ -118,8 +117,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");
}
}
}
@@ -135,10 +133,8 @@ public class LaunchedURLClassLoader extends URLClassLoader {
try {
URLConnection connection = url.openConnection();
if (connection instanceof JarURLConnection) {
JarFile jarFile = ((JarURLConnection) connection)
.getJarFile();
if (jarFile.getEntry(classEntryName) != null
&& jarFile.getEntry(packageEntryName) != null
JarFile jarFile = ((JarURLConnection) connection).getJarFile();
if (jarFile.getEntry(classEntryName) != null && jarFile.getEntry(packageEntryName) != null
&& jarFile.getManifest() != null) {
definePackage(packageName, jarFile.getManifest(), url);
return null;
@@ -182,8 +178,7 @@ public class LaunchedURLClassLoader extends URLClassLoader {
}
}
private static class UseFastConnectionExceptionsEnumeration
implements Enumeration<URL> {
private static class UseFastConnectionExceptionsEnumeration implements Enumeration<URL> {
private final Enumeration<URL> delegate;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -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));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -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 });
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -269,8 +269,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");
@@ -320,8 +319,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;
}
@@ -330,8 +328,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;
}
@@ -342,8 +339,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) {
@@ -354,10 +350,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);
@@ -366,8 +360,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
@@ -383,21 +376,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;
}
@@ -414,10 +404,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);
}
}
}
@@ -434,8 +422,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;
}
@@ -445,8 +432,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.getNestedArchives(new ArchiveEntryFilter()));
List<Archive> nested = new ArrayList<>(archive.getNestedArchives(new ArchiveEntryFilter()));
nested.add(0, archive);
lib.addAll(nested);
}
@@ -509,8 +495,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;
}
@@ -539,8 +524,7 @@ public class PropertiesLauncher extends Launcher {
}
EntryFilter filter = new PrefixMatchingArchiveFilter(root);
List<Archive> archives = new ArrayList<>(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);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,8 +49,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);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,8 +42,7 @@ import java.util.jar.Manifest;
*/
public class ExplodedArchive implements Archive {
private static final Set<String> SKIPPED_NAMES = new HashSet<>(
Arrays.asList(".", ".."));
private static final Set<String> SKIPPED_NAMES = new HashSet<>(Arrays.asList(".", ".."));
private final File root;
@@ -116,8 +115,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
@@ -163,13 +161,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);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -104,8 +104,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);
}
}
@@ -133,14 +132,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 {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -109,8 +109,7 @@ public class RandomAccessDataFile implements RandomAccessData {
return this.fileAccess.readByte(this.offset + position);
}
private int read(byte[] bytes, long position, int offset, int length)
throws IOException {
private int read(byte[] bytes, long position, int offset, int length) throws IOException {
if (position > this.length) {
return -1;
}
@@ -172,8 +171,7 @@ public class RandomAccessDataFile implements RandomAccessData {
if (cappedLen <= 0) {
return -1;
}
return (int) moveOn(
RandomAccessDataFile.this.read(b, this.position, off, cappedLen));
return (int) moveOn(RandomAccessDataFile.this.read(b, this.position, off, cappedLen));
}
@Override
@@ -216,8 +214,7 @@ public class RandomAccessDataFile implements RandomAccessData {
openIfNecessary();
}
private int read(byte[] bytes, long position, int offset, int length)
throws IOException {
private int read(byte[] bytes, long position, int offset, int length) throws IOException {
synchronized (this.monitor) {
openIfNecessary();
this.randomAccessFile.seek(position);
@@ -231,8 +228,8 @@ public class RandomAccessDataFile implements RandomAccessData {
this.randomAccessFile = new RandomAccessFile(this.file, "r");
}
catch (FileNotFoundException ex) {
throw new IllegalArgumentException(String.format("File %s must exist",
this.file.getAbsolutePath()));
throw new IllegalArgumentException(
String.format("File %s must exist", this.file.getAbsolutePath()));
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -104,8 +104,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;
}
}
@@ -229,8 +229,7 @@ final class AsciiBytes {
this.string = EMPTY_STRING;
}
else {
this.string = new String(this.bytes, this.offset, this.length,
StandardCharsets.UTF_8);
this.string = new String(this.bytes, this.offset, this.length, StandardCharsets.UTF_8);
}
}
return this.string;

View File

@@ -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 data.read(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;
}

View File

@@ -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) {
this.header = header;
this.headerOffset = headerOffset;
this.name = name;
@@ -63,8 +63,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;
@@ -75,8 +75,7 @@ final class CentralDirectoryFileHeader implements FileHeader {
// Load variable part
dataOffset += 46;
if (variableData != null) {
data = variableData.read(variableOffset + 46,
nameLength + extraLength + commentLength);
data = variableData.read(variableOffset + 46, nameLength + extraLength + commentLength);
dataOffset = 0;
}
this.name = new AsciiBytes(data, dataOffset, (int) nameLength);
@@ -87,12 +86,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);
}
}
@@ -127,12 +124,10 @@ final class CentralDirectoryFileHeader implements FileHeader {
* @return the date and time as milliseconds since the epoch
*/
private long decodeMsDosFormatDateTime(long datetime) {
LocalDateTime localDateTime = LocalDateTime.of(
(int) (((datetime >> 25) & 0x7f) + 1980), (int) ((datetime >> 21) & 0x0f),
(int) ((datetime >> 16) & 0x1f), (int) ((datetime >> 11) & 0x1f),
LocalDateTime localDateTime = LocalDateTime.of((int) (((datetime >> 25) & 0x7f) + 1980),
(int) ((datetime >> 21) & 0x0f), (int) ((datetime >> 16) & 0x1f), (int) ((datetime >> 11) & 0x1f),
(int) ((datetime >> 5) & 0x3f), (int) ((datetime << 1) & 0x3e));
return localDateTime.toEpochSecond(
ZoneId.systemDefault().getRules().getOffset(localDateTime)) * 1000;
return localDateTime.toEpochSecond(ZoneId.systemDefault().getRules().getOffset(localDateTime)) * 1000;
}
public long getCrc() {
@@ -166,12 +161,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 = data.read(offset, 46);
fileHeader.load(bytes, 0, data, offset, filter);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,8 +47,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);
@@ -60,22 +59,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 = centralDirectoryData.read(0, centralDirectoryData.getSize());
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 += CENTRAL_DIRECTORY_HEADER_BASE_SIZE
+ fileHeader.getName().length() + fileHeader.getComment().length()
+ fileHeader.getExtra().length;
dataOffset += 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;
@@ -83,8 +80,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);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -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);

View File

@@ -54,8 +54,7 @@ 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 SoftReference<Map<File, JarFile>> rootFileCache;
@@ -88,15 +87,13 @@ public class Handler extends URLStreamHandler {
}
}
private boolean isUrlInJarFile(URL url, JarFile jarFile)
throws MalformedURLException {
private boolean isUrlInJarFile(URL url, JarFile jarFile) throws MalformedURLException {
// Try the path first to save building a new url string each time
return url.getPath().startsWith(jarFile.getUrl().getPath())
&& url.toString().startsWith(jarFile.getUrlString());
}
private URLConnection openFallbackConnection(URL url, Exception reason)
throws IOException {
private URLConnection openFallbackConnection(URL url, Exception reason) throws IOException {
try {
return openConnection(getFallbackHandler(), url);
}
@@ -142,8 +139,7 @@ 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 {
return new URL(null, url.toExternalForm(), handler).openConnection();
}
@@ -181,8 +177,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;
}
@@ -190,8 +185,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);
}
@@ -204,8 +198,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) {
@@ -224,8 +217,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);
@@ -345,8 +337,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);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -106,14 +106,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, null);
}
private JarFile(RandomAccessDataFile rootFile, String pathFromRoot,
RandomAccessData data, JarEntryFilter filter, JarFileType type,
Supplier<Manifest> manifestSupplier) throws IOException {
private JarFile(RandomAccessDataFile rootFile, String pathFromRoot, RandomAccessData data, JarEntryFilter filter,
JarFileType type, Supplier<Manifest> manifestSupplier) throws IOException {
super(rootFile.getFile());
this.rootFile = rootFile;
this.pathFromRoot = pathFromRoot;
@@ -139,16 +138,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;
}
}
@@ -252,8 +248,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);
}
}
@@ -272,22 +267,20 @@ public class JarFile extends java.util.jar.JarFile {
}
return null;
};
return new JarFile(this.rootFile,
this.pathFromRoot + "!/"
+ entry.getName().substring(0, name.length() - 1),
return new JarFile(this.rootFile, this.pathFromRoot + "!/" + entry.getName().substring(0, name.length() - 1),
this.data, filter, JarFileType.NESTED_DIRECTORY, this.manifestSupplier);
}
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
@@ -344,8 +337,7 @@ public class JarFile extends java.util.jar.JarFile {
// Fallback to JarInputStream to obtain certificates, not fast but hopefully not
// happening that often.
try {
try (JarInputStream inputStream = new JarInputStream(
getData().getInputStream())) {
try (JarInputStream inputStream = new JarInputStream(getData().getInputStream())) {
java.util.jar.JarEntry certEntry = inputStream.getNextJarEntry();
while (certEntry != null) {
inputStream.closeEntry();
@@ -386,8 +378,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();
}

View File

@@ -59,8 +59,7 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
int version;
try {
Object runtimeVersion = Runtime.class.getMethod("version").invoke(null);
version = (int) runtimeVersion.getClass().getMethod("major")
.invoke(runtimeVersion);
version = (int) runtimeVersion.getClass().getMethod("major").invoke(runtimeVersion);
}
catch (Throwable ex) {
version = 8;
@@ -96,8 +95,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;
}
@@ -115,8 +113,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];
@@ -235,25 +232,21 @@ 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 = data.read(entry.getLocalHeaderOffset(),
LOCAL_FILE_HEADER_SIZE);
byte[] localHeader = data.read(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(CharSequence name, Class<T> type,
boolean cacheEntry) {
private <T extends FileHeader> T getEntry(CharSequence name, Class<T> type, boolean cacheEntry) {
T entry = doGetEntry(name, type, cacheEntry, null);
if (!isMetaInfEntry(name) && isMultiReleaseJar()) {
int version = RUNTIME_VERSION;
AsciiBytes nameAlias = (entry instanceof JarEntry)
? ((JarEntry) entry).getAsciiBytesName()
AsciiBytes nameAlias = (entry instanceof JarEntry) ? ((JarEntry) entry).getAsciiBytesName()
: new AsciiBytes(name.toString());
while (version > BASE_VERSION) {
T versionedEntry = doGetEntry("META-INF/versions/" + version + "/" + name,
type, cacheEntry, nameAlias);
T versionedEntry = doGetEntry("META-INF/versions/" + version + "/" + name, type, cacheEntry, nameAlias);
if (versionedEntry != null) {
return versionedEntry;
}
@@ -289,8 +282,8 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
return multiRelease;
}
private <T extends FileHeader> T doGetEntry(CharSequence name, Class<T> type,
boolean cacheEntry, AsciiBytes nameAlias) {
private <T extends FileHeader> T doGetEntry(CharSequence name, Class<T> type, boolean cacheEntry,
AsciiBytes nameAlias) {
int hashCode = AsciiBytes.hashCode(name);
T entry = getEntry(hashCode, name, NO_SUFFIX, type, cacheEntry, nameAlias);
if (entry == null) {
@@ -300,8 +293,8 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
return entry;
}
private <T extends FileHeader> T getEntry(int hashCode, CharSequence name,
char suffix, Class<T> type, boolean cacheEntry, AsciiBytes nameAlias) {
private <T extends FileHeader> T getEntry(int hashCode, CharSequence name, char suffix, Class<T> type,
boolean cacheEntry, AsciiBytes nameAlias) {
int index = getFirstIndex(hashCode);
while (index >= 0 && index < this.size && this.hashCodes[index] == hashCode) {
T entry = getEntry(index, type, cacheEntry, nameAlias);
@@ -314,18 +307,13 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
}
@SuppressWarnings("unchecked")
private <T extends FileHeader> T getEntry(int index, Class<T> type,
boolean cacheEntry, AsciiBytes nameAlias) {
private <T extends FileHeader> T getEntry(int index, Class<T> type, boolean cacheEntry, AsciiBytes nameAlias) {
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)) {
entry = new JarEntry(this.jarFile, (CentralDirectoryFileHeader) entry,
nameAlias);
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, nameAlias);
}
if (cacheEntry && cached != entry) {
this.entriesCache.put(index, entry);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -66,13 +66,11 @@ final class JarURLConnection extends java.net.JarURLConnection {
}
}
private static final JarEntryName EMPTY_JAR_ENTRY_NAME = new JarEntryName(
new StringSequence(""));
private static final JarEntryName EMPTY_JAR_ENTRY_NAME = new JarEntryName(new StringSequence(""));
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;
@@ -84,8 +82,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;
@@ -162,13 +159,11 @@ 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();
InputStream inputStream = (this.jarEntryName.isEmpty()
? this.jarFile.getData().getInputStream()
InputStream inputStream = (this.jarEntryName.isEmpty() ? this.jarFile.getData().getInputStream()
: this.jarFile.getInputStream(this.jarEntry));
if (inputStream == null) {
throwFileNotFound(this.jarEntryName, this.jarFile);
@@ -176,13 +171,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
@@ -228,8 +221,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;
}
@@ -294,8 +286,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;
}
@@ -331,8 +322,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) {
@@ -343,8 +333,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;
@@ -358,8 +347,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));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -87,8 +87,8 @@ public abstract class SystemPropertyUtils {
return parseStringValue(properties, text, text, new HashSet<>());
}
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;
@@ -228,8 +218,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)) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,8 +50,7 @@ public abstract 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 abstract class AbstractExecutableArchiveLauncherTests {
entryFile.mkdirs();
}
else {
FileCopyUtils.copy(jarFile.getInputStream(entry),
new FileOutputStream(entryFile));
FileCopyUtils.copy(jarFile.getInputStream(entry), new FileOutputStream(entryFile));
}
}
jarFile.close();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -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!/"));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -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");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -63,8 +63,7 @@ public class PropertiesLauncherTests {
@Before
public void setup() {
this.contextClassLoader = Thread.currentThread().getContextClassLoader();
System.setProperty("loader.home",
new File("src/test/resources").getAbsolutePath());
System.setProperty("loader.home", new File("src/test/resources").getAbsolutePath());
}
@After
@@ -83,16 +82,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");
}
@@ -100,8 +97,7 @@ public class PropertiesLauncherTests {
public void testNonExistentHome() {
System.setProperty("loader.home", "src/test/resources/nonexistent");
assertThatIllegalStateException().isThrownBy(PropertiesLauncher::new)
.withMessageContaining("Invalid source folder")
.withCauseInstanceOf(IllegalArgumentException.class);
.withMessageContaining("Invalid source folder").withCauseInstanceOf(IllegalArgumentException.class);
}
@Test
@@ -116,8 +112,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
@@ -131,16 +126,14 @@ public class PropertiesLauncherTests {
public void testUserSpecifiedDotPath() {
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!/"));
}
@@ -150,8 +143,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");
}
@@ -161,16 +153,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!/]");
@@ -190,8 +180,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!/"));
@@ -217,8 +206,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();
@@ -231,8 +219,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");
}
@@ -242,8 +229,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");
}
@@ -312,25 +298,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

View File

@@ -52,23 +52,22 @@ public abstract class TestJarCreator {
writeNestedEntry("nested.jar", unpackNested, jarOutputStream);
writeNestedEntry("another-nested.jar", unpackNested, jarOutputStream);
writeNestedEntry("space nested.jar", unpackNested, jarOutputStream);
writeNestedMultiReleaseEntry("multi-release.jar", unpackNested,
jarOutputStream);
writeNestedMultiReleaseEntry("multi-release.jar", unpackNested, jarOutputStream);
}
}
private static void writeNestedEntry(String name, boolean unpackNested,
JarOutputStream jarOutputStream) throws Exception {
private static void writeNestedEntry(String name, boolean unpackNested, JarOutputStream jarOutputStream)
throws Exception {
writeNestedEntry(name, unpackNested, jarOutputStream, false);
}
private static void writeNestedMultiReleaseEntry(String name, boolean unpackNested,
JarOutputStream jarOutputStream) throws Exception {
private static void writeNestedMultiReleaseEntry(String name, boolean unpackNested, JarOutputStream jarOutputStream)
throws Exception {
writeNestedEntry(name, unpackNested, jarOutputStream, true);
}
private static void writeNestedEntry(String name, boolean unpackNested,
JarOutputStream jarOutputStream, boolean multiRelease) throws Exception {
private static void writeNestedEntry(String name, boolean unpackNested, JarOutputStream jarOutputStream,
boolean multiRelease) throws Exception {
JarEntry nestedEntry = new JarEntry(name);
byte[] nestedJarData = getNestedJarData(multiRelease);
nestedEntry.setSize(nestedJarData.length);
@@ -106,34 +105,30 @@ 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 {
writeManifest(jarOutputStream, name, false);
}
private static void writeManifest(JarOutputStream jarOutputStream, String name,
boolean multiRelease) throws Exception {
private static void writeManifest(JarOutputStream jarOutputStream, String name, boolean multiRelease)
throws Exception {
writeDirEntry(jarOutputStream, "META-INF/");
Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue("Built-By", name);
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
if (multiRelease) {
manifest.getMainAttributes().putValue("Multi-Release",
Boolean.toString(true));
manifest.getMainAttributes().putValue("Multi-Release", Boolean.toString(true));
}
jarOutputStream.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
manifest.write(jarOutputStream);
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();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -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!/"));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -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();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -71,8 +71,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
@@ -91,8 +90,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
@@ -118,12 +116,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());
}
@@ -153,10 +149,9 @@ public class JarFileArchiveTests {
output.close();
JarFileArchive jarFileArchive = new JarFileArchive(file);
assertThatIllegalStateException()
.isThrownBy(() -> jarFileArchive.getNestedArchive(
getEntriesMap(jarFileArchive).get("nested/zip64.jar")))
.withMessageContaining(
"Failed to get nested archive for entry nested/zip64.jar");
.isThrownBy(
() -> jarFileArchive.getNestedArchive(getEntriesMap(jarFileArchive).get("nested/zip64.jar")))
.withMessageContaining("Failed to get nested archive for entry nested/zip64.jar");
}
private byte[] writeZip64Jar() throws IOException {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -82,17 +82,15 @@ public class RandomAccessDataFileTests {
@Test
public void fileNotNull() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new RandomAccessDataFile(null))
assertThatIllegalArgumentException().isThrownBy(() -> new RandomAccessDataFile(null))
.withMessageContaining("File must not be null");
}
@Test
public void fileExists() {
File file = new File("/does/not/exist");
assertThatIllegalArgumentException()
.isThrownBy(() -> new RandomAccessDataFile(file)).withMessageContaining(
String.format("File %s must exist", file.getAbsolutePath()));
assertThatIllegalArgumentException().isThrownBy(() -> new RandomAccessDataFile(file))
.withMessageContaining(String.format("File %s must exist", file.getAbsolutePath()));
}
@Test
@@ -103,31 +101,24 @@ public class RandomAccessDataFileTests {
@Test
public void readWhenOffsetIsBeyondEOFShouldThrowException() throws Exception {
assertThatExceptionOfType(IndexOutOfBoundsException.class)
.isThrownBy(() -> this.file.read(257, 0));
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> this.file.read(257, 0));
}
@Test
public void readWhenOffsetIsBeyondEndOfSubsectionShouldThrowException()
throws Exception {
public void readWhenOffsetIsBeyondEndOfSubsectionShouldThrowException() throws Exception {
RandomAccessData subsection = this.file.getSubsection(0, 10);
assertThatExceptionOfType(IndexOutOfBoundsException.class)
.isThrownBy(() -> subsection.read(11, 0));
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> subsection.read(11, 0));
}
@Test
public void readWhenOffsetPlusLengthGreaterThanEOFShouldThrowException()
throws Exception {
assertThatExceptionOfType(EOFException.class)
.isThrownBy(() -> this.file.read(256, 1));
public void readWhenOffsetPlusLengthGreaterThanEOFShouldThrowException() throws Exception {
assertThatExceptionOfType(EOFException.class).isThrownBy(() -> this.file.read(256, 1));
}
@Test
public void readWhenOffsetPlusLengthGreaterThanEndOfSubsectionShouldThrowException()
throws Exception {
public void readWhenOffsetPlusLengthGreaterThanEndOfSubsectionShouldThrowException() throws Exception {
RandomAccessData subsection = this.file.getSubsection(0, 10);
assertThatExceptionOfType(EOFException.class)
.isThrownBy(() -> subsection.read(10, 1));
assertThatExceptionOfType(EOFException.class).isThrownBy(() -> subsection.read(10, 1));
}
@Test
@@ -145,8 +136,7 @@ public class RandomAccessDataFileTests {
@Test
public void inputStreamReadNullBytesWithOffset() throws Exception {
assertThatNullPointerException()
.isThrownBy(() -> this.inputStream.read(null, 0, 1))
assertThatNullPointerException().isThrownBy(() -> this.inputStream.read(null, 0, 1))
.withMessage("Bytes must not be null");
}
@@ -215,14 +205,12 @@ public class RandomAccessDataFileTests {
@Test
public void subsectionNegativeOffset() {
assertThatExceptionOfType(IndexOutOfBoundsException.class)
.isThrownBy(() -> this.file.getSubsection(-1, 1));
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> this.file.getSubsection(-1, 1));
}
@Test
public void subsectionNegativeLength() {
assertThatExceptionOfType(IndexOutOfBoundsException.class)
.isThrownBy(() -> this.file.getSubsection(0, -1));
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> this.file.getSubsection(0, -1));
}
@Test
@@ -234,15 +222,13 @@ public class RandomAccessDataFileTests {
@Test
public void subsectionTooBig() {
this.file.getSubsection(0, 256);
assertThatExceptionOfType(IndexOutOfBoundsException.class)
.isThrownBy(() -> this.file.getSubsection(0, 257));
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> this.file.getSubsection(0, 257));
}
@Test
public void subsectionTooBigWithOffset() {
this.file.getSubsection(1, 255);
assertThatExceptionOfType(IndexOutOfBoundsException.class)
.isThrownBy(() -> this.file.getSubsection(1, 256));
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> this.file.getSubsection(1, 256));
}
@Test
@@ -294,8 +280,8 @@ public class RandomAccessDataFileTests {
List<Future<Boolean>> results = new ArrayList<>();
for (int i = 0; i < 100; i++) {
results.add(executorService.submit(() -> {
InputStream subsectionInputStream = RandomAccessDataFileTests.this.file
.getSubsection(0, 256).getInputStream();
InputStream subsectionInputStream = RandomAccessDataFileTests.this.file.getSubsection(0, 256)
.getInputStream();
byte[] b = new byte[256];
subsectionInputStream.read(b);
return Arrays.equals(b, BYTES);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -89,8 +89,7 @@ public class AsciiBytesTests {
assertThat(abcd.substring(2).toString()).isEqualTo("CD");
assertThat(abcd.substring(3).toString()).isEqualTo("D");
assertThat(abcd.substring(4).toString()).isEqualTo("");
assertThatExceptionOfType(IndexOutOfBoundsException.class)
.isThrownBy(() -> abcd.substring(5));
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> abcd.substring(5));
}
@Test
@@ -100,16 +99,14 @@ public class AsciiBytesTests {
assertThat(abcd.substring(1, 3).toString()).isEqualTo("BC");
assertThat(abcd.substring(3, 4).toString()).isEqualTo("D");
assertThat(abcd.substring(3, 3).toString()).isEqualTo("");
assertThatExceptionOfType(IndexOutOfBoundsException.class)
.isThrownBy(() -> abcd.substring(3, 5));
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> abcd.substring(3, 5));
}
@Test
public void hashCodeAndEquals() {
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());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,8 +60,7 @@ public class CentralDirectoryParserTests {
parser.addVisitor(visitor);
parser.parse(this.jarData, false);
List<String> invocations = visitor.getInvocations();
assertThat(invocations).startsWith("visitStart").endsWith("visitEnd")
.contains("visitFileHeader");
assertThat(invocations).startsWith("visitStart").endsWith("visitEnd").contains("visitFileHeader");
}
@Test
@@ -91,13 +90,11 @@ public class CentralDirectoryParserTests {
private List<CentralDirectoryFileHeader> headers = new ArrayList<>();
@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());
}
@@ -116,14 +113,12 @@ public class CentralDirectoryParserTests {
private final List<String> invocations = new ArrayList<>();
@Override
public void visitStart(CentralDirectoryEndRecord endRecord,
RandomAccessData centralDirectoryData) {
public void visitStart(CentralDirectoryEndRecord endRecord, RandomAccessData centralDirectoryData) {
this.invocations.add("visitStart");
}
@Override
public void visitFileHeader(CentralDirectoryFileHeader fileHeader,
int dataOffset) {
public void visitFileHeader(CentralDirectoryFileHeader fileHeader, int dataOffset) {
this.invocations.add("visitFileHeader");
}

View File

@@ -42,8 +42,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());
@@ -51,8 +50,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());
@@ -60,8 +58,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());
@@ -69,23 +66,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
@@ -94,110 +87,89 @@ 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");
}
@Test
public void fallbackToJdksJarUrlStreamHandler() throws Exception {
File testJar = this.temporaryFolder.newFile("test.jar");
TestJarCreator.createTestJar(testJar);
URLConnection connection = new URL(null,
"jar:file:" + testJar.getAbsolutePath() + "!/nested.jar!/", this.handler)
.openConnection();
URLConnection connection = new URL(null, "jar:file:" + testJar.getAbsolutePath() + "!/nested.jar!/",
this.handler).openConnection();
assertThat(connection).isInstanceOf(JarURLConnection.class);
URLConnection jdkConnection = new URL(null,
"jar:file:file:" + testJar.getAbsolutePath() + "!/nested.jar!/",
URLConnection jdkConnection = new URL(null, "jar:file:file:" + testJar.getAbsolutePath() + "!/nested.jar!/",
this.handler).openConnection();
assertThat(jdkConnection).isNotInstanceOf(JarURLConnection.class);
}
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());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -110,8 +110,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
@@ -141,8 +140,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();
}
@@ -156,8 +154,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);
@@ -186,8 +183,7 @@ public class JarFileTests {
@Test
public void close() throws Exception {
RandomAccessDataFile randomAccessDataFile = spy(
new RandomAccessDataFile(this.rootJarFile));
RandomAccessDataFile randomAccessDataFile = spy(new RandomAccessDataFile(this.rootJarFile));
JarFile jarFile = new JarFile(randomAccessDataFile);
jarFile.close();
verify(randomAccessDataFile).close();
@@ -203,19 +199,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");
@@ -228,8 +221,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");
assertThatExceptionOfType(FileNotFoundException.class)
.isThrownBy(((JarURLConnection) url.openConnection())::getJarEntry);
}
@@ -252,8 +244,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/");
@@ -263,18 +254,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");
@@ -289,31 +277,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);
@@ -330,8 +313,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");
}
@@ -342,8 +324,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 {
@@ -355,15 +336,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);
}
@@ -378,8 +357,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
@@ -426,12 +405,10 @@ 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");
assertThatExceptionOfType(FileNotFoundException.class)
.isThrownBy(url.openConnection()::getInputStream);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(url.openConnection()::getInputStream);
}
@Test
@@ -487,14 +464,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();
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(
new URL(context, "jar:" + this.rootJarFile.toURI() + "!/no.dat")
.openConnection()::getInputStream);
new URL(context, "jar:" + this.rootJarFile.toURI() + "!/no.dat").openConnection()::getInputStream);
}
finally {
JarURLConnection.setUseFastExceptions(false);
@@ -503,8 +478,7 @@ public class JarFileTests {
@Test
public void multiReleaseEntry() throws Exception {
JarFile multiRelease = this.jarFile
.getNestedJarFile(this.jarFile.getEntry("multi-release.jar"));
JarFile multiRelease = this.jarFile.getNestedJarFile(this.jarFile.getEntry("multi-release.jar"));
ZipEntry entry = multiRelease.getEntry("multi-release.dat");
assertThat(entry.getName()).isEqualTo("multi-release.dat");
InputStream inputStream = multiRelease.getInputStream(entry);
@@ -515,8 +489,7 @@ public class JarFileTests {
private int getJavaVersion() {
try {
Object runtimeVersion = Runtime.class.getMethod("version").invoke(null);
return (int) runtimeVersion.getClass().getMethod("major")
.invoke(runtimeVersion);
return (int) runtimeVersion.getClass().getMethod("major").invoke(runtimeVersion);
}
catch (Throwable ex) {
return 8;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,15 +58,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
@@ -84,8 +82,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 }));
@@ -106,32 +103,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 }));
}
@@ -145,33 +136,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"));
assertThatExceptionOfType(FileNotFoundException.class)
.isThrownBy(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);
}
@@ -179,33 +167,28 @@ 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());
}
@Test
public void jarEntryBasicName() {
assertThat(new JarEntryName(new StringSequence("a/b/C.class")).toString())
.isEqualTo("a/b/C.class");
assertThat(new JarEntryName(new StringSequence("a/b/C.class")).toString()).isEqualTo("a/b/C.class");
}
@Test
public void jarEntryNameWithSingleByteEncodedCharacters() {
assertThat(new JarEntryName(new StringSequence("%61/%62/%43.class")).toString())
.isEqualTo("a/b/C.class");
assertThat(new JarEntryName(new StringSequence("%61/%62/%43.class")).toString()).isEqualTo("a/b/C.class");
}
@Test
public void jarEntryNameWithDoubleByteEncodedCharacters() {
assertThat(new JarEntryName(new StringSequence("%c3%a1/b/C.class")).toString())
.isEqualTo("\u00e1/b/C.class");
assertThat(new JarEntryName(new StringSequence("%c3%a1/b/C.class")).toString()).isEqualTo("\u00e1/b/C.class");
}
@Test
public void jarEntryNameWithMixtureOfEncodedAndUnencodedDoubleByteCharacters() {
assertThat(
new JarEntryName(new StringSequence("%c3%a1/b/\u00c7.class")).toString())
.isEqualTo("\u00e1/b/\u00c7.class");
assertThat(new JarEntryName(new StringSequence("%c3%a1/b/\u00c7.class")).toString())
.isEqualTo("\u00e1/b/\u00c7.class");
}
private String getAbsolutePath() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,22 +60,18 @@ public class StringSequenceTests {
@Test
public void subSequenceWithJustStartShouldReturnSubSequence() {
assertThat(new StringSequence("smiles").subSequence(1).toString())
.isEqualTo("miles");
assertThat(new StringSequence("smiles").subSequence(1).toString()).isEqualTo("miles");
}
@Test
public void subSequenceShouldReturnSubSequence() {
assertThat(new StringSequence("hamburger").subSequence(4, 8).toString())
.isEqualTo("urge");
assertThat(new StringSequence("smiles").subSequence(1, 5).toString())
.isEqualTo("mile");
assertThat(new StringSequence("hamburger").subSequence(4, 8).toString()).isEqualTo("urge");
assertThat(new StringSequence("smiles").subSequence(1, 5).toString()).isEqualTo("mile");
}
@Test
public void subSequenceWhenCalledMultipleTimesShouldReturnSubSequence() {
assertThat(new StringSequence("hamburger").subSequence(4, 8).subSequence(1, 3)
.toString()).isEqualTo("rg");
assertThat(new StringSequence("hamburger").subSequence(4, 8).subSequence(1, 3).toString()).isEqualTo("rg");
}
@Test
@@ -83,8 +79,7 @@ public class StringSequenceTests {
StringSequence sequence = new StringSequence("abcde").subSequence(1, 4);
assertThat(sequence.toString()).isEqualTo("bcd");
assertThat(sequence.subSequence(2, 3).toString()).isEqualTo("d");
assertThatExceptionOfType(IndexOutOfBoundsException.class)
.isThrownBy(() -> sequence.subSequence(3, 4));
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> sequence.subSequence(3, 4));
}
@Test
@@ -92,8 +87,7 @@ public class StringSequenceTests {
StringSequence sequence = new StringSequence("abcde").subSequence(1, 4);
assertThat(sequence.toString()).isEqualTo("bcd");
assertThat(sequence.subSequence(2, 3).toString()).isEqualTo("d");
assertThatExceptionOfType(IndexOutOfBoundsException.class)
.isThrownBy(() -> sequence.subSequence(4, 3));
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> sequence.subSequence(4, 3));
}
@Test
@@ -148,10 +142,8 @@ public class StringSequenceTests {
@Test
public void hashCodeShouldBeSameAsString() {
assertThat(new StringSequence("hamburger").hashCode())
.isEqualTo("hamburger".hashCode());
assertThat(new StringSequence("hamburger").subSequence(4, 8).hashCode())
.isEqualTo("urge".hashCode());
assertThat(new StringSequence("hamburger").hashCode()).isEqualTo("hamburger".hashCode());
assertThat(new StringSequence("hamburger").subSequence(4, 8).hashCode()).isEqualTo("urge".hashCode());
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -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"));
}
}