Merge branch '1.2.x'
This commit is contained in:
@@ -190,7 +190,8 @@ public class LaunchedURLClassLoader extends URLClassLoader {
|
||||
// manifest
|
||||
if (jarFile.getJarEntryData(path) != null
|
||||
&& jarFile.getManifest() != null) {
|
||||
definePackage(packageName, jarFile.getManifest(), url);
|
||||
definePackage(packageName, jarFile.getManifest(),
|
||||
url);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,8 @@ public abstract class Launcher {
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ public class MainMethodRunner implements Runnable {
|
||||
.loadClass(this.mainClassName);
|
||||
Method mainMethod = mainClass.getDeclaredMethod("main", String[].class);
|
||||
if (mainMethod == null) {
|
||||
throw new IllegalStateException(this.mainClassName
|
||||
+ " does not have a main method");
|
||||
throw new IllegalStateException(
|
||||
this.mainClassName + " does not have a main method");
|
||||
}
|
||||
mainMethod.invoke(null, new Object[] { this.args });
|
||||
}
|
||||
|
||||
@@ -169,16 +169,17 @@ public class PropertiesLauncher extends Launcher {
|
||||
}
|
||||
|
||||
protected File getHomeDirectory() {
|
||||
return new File(SystemPropertyUtils.resolvePlaceholders(System.getProperty(HOME,
|
||||
"${user.dir}")));
|
||||
return new File(SystemPropertyUtils
|
||||
.resolvePlaceholders(System.getProperty(HOME, "${user.dir}")));
|
||||
}
|
||||
|
||||
private void initializeProperties(File home) throws Exception, IOException {
|
||||
String config = "classpath:"
|
||||
+ SystemPropertyUtils.resolvePlaceholders(SystemPropertyUtils
|
||||
.getProperty(CONFIG_NAME, "application")) + ".properties";
|
||||
config = SystemPropertyUtils.resolvePlaceholders(SystemPropertyUtils.getProperty(
|
||||
CONFIG_LOCATION, config));
|
||||
+ SystemPropertyUtils.resolvePlaceholders(
|
||||
SystemPropertyUtils.getProperty(CONFIG_NAME, "application"))
|
||||
+ ".properties";
|
||||
config = SystemPropertyUtils.resolvePlaceholders(
|
||||
SystemPropertyUtils.getProperty(CONFIG_LOCATION, config));
|
||||
InputStream resource = getResource(config);
|
||||
|
||||
if (resource != null) {
|
||||
@@ -197,8 +198,9 @@ public class PropertiesLauncher extends Launcher {
|
||||
this.properties.put(key, value);
|
||||
}
|
||||
}
|
||||
if (SystemPropertyUtils.resolvePlaceholders(
|
||||
"${" + SET_SYSTEM_PROPERTIES + ":false}").equals("true")) {
|
||||
if (SystemPropertyUtils
|
||||
.resolvePlaceholders("${" + SET_SYSTEM_PROPERTIES + ":false}")
|
||||
.equals("true")) {
|
||||
this.logger.info("Adding resolved properties to System properties");
|
||||
for (Object key : Collections.list(this.properties.propertyNames())) {
|
||||
String value = this.properties.getProperty((String) key);
|
||||
@@ -277,8 +279,8 @@ 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");
|
||||
@@ -305,7 +307,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
path = this.properties.getProperty(PATH);
|
||||
}
|
||||
if (path != null) {
|
||||
this.paths = parsePathsProperty(SystemPropertyUtils.resolvePlaceholders(path));
|
||||
this.paths = parsePathsProperty(
|
||||
SystemPropertyUtils.resolvePlaceholders(path));
|
||||
}
|
||||
this.logger.info("Nested archive paths: " + this.paths);
|
||||
}
|
||||
@@ -343,8 +346,8 @@ 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;
|
||||
}
|
||||
@@ -364,8 +367,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
private ClassLoader wrapWithCustomClassLoader(ClassLoader parent,
|
||||
String loaderClassName) throws Exception {
|
||||
|
||||
Class<ClassLoader> loaderClass = (Class<ClassLoader>) Class.forName(
|
||||
loaderClassName, true, parent);
|
||||
Class<ClassLoader> loaderClass = (Class<ClassLoader>) Class
|
||||
.forName(loaderClassName, true, parent);
|
||||
|
||||
try {
|
||||
return loaderClass.getConstructor(ClassLoader.class).newInstance(parent);
|
||||
@@ -403,8 +406,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
}
|
||||
|
||||
if (this.properties.containsKey(propertyKey)) {
|
||||
String value = SystemPropertyUtils.resolvePlaceholders(this.properties
|
||||
.getProperty(propertyKey));
|
||||
String value = SystemPropertyUtils
|
||||
.resolvePlaceholders(this.properties.getProperty(propertyKey));
|
||||
this.logger.fine("Property '" + propertyKey + "' from properties: " + value);
|
||||
return value;
|
||||
}
|
||||
@@ -428,8 +431,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
if (manifest != null) {
|
||||
String value = manifest.getMainAttributes().getValue(manifestKey);
|
||||
if (value != null) {
|
||||
this.logger.fine("Property '" + manifestKey + "' from archive manifest: "
|
||||
+ value);
|
||||
this.logger.fine(
|
||||
"Property '" + manifestKey + "' from archive manifest: " + value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -465,14 +468,14 @@ public class PropertiesLauncher extends Launcher {
|
||||
}
|
||||
Archive archive = getArchive(file);
|
||||
if (archive != null) {
|
||||
this.logger.info("Adding classpath entries from archive " + archive.getUrl()
|
||||
+ root);
|
||||
this.logger.info(
|
||||
"Adding classpath entries from archive " + archive.getUrl() + root);
|
||||
lib.add(archive);
|
||||
}
|
||||
Archive nested = getNestedArchive(root);
|
||||
if (nested != null) {
|
||||
this.logger.info("Adding classpath entries from nested " + nested.getUrl()
|
||||
+ root);
|
||||
this.logger.info(
|
||||
"Adding classpath entries from nested " + nested.getUrl() + root);
|
||||
lib.add(nested);
|
||||
}
|
||||
return lib;
|
||||
@@ -506,8 +509,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
return new FilteredArchive(this.parent, filter);
|
||||
}
|
||||
|
||||
private void addParentClassLoaderEntries(List<Archive> lib) throws IOException,
|
||||
URISyntaxException {
|
||||
private void addParentClassLoaderEntries(List<Archive> lib)
|
||||
throws IOException, URISyntaxException {
|
||||
ClassLoader parentClassLoader = getClass().getClassLoader();
|
||||
List<Archive> urls = new ArrayList<Archive>();
|
||||
for (URL url : getURLs(parentClassLoader)) {
|
||||
@@ -518,8 +521,8 @@ public class PropertiesLauncher extends Launcher {
|
||||
String name = url.getFile();
|
||||
File dir = new File(name.substring(0, name.length() - 1));
|
||||
if (dir.exists()) {
|
||||
urls.add(new ExplodedArchive(new File(name.substring(0,
|
||||
name.length() - 1)), false));
|
||||
urls.add(new ExplodedArchive(
|
||||
new File(name.substring(0, name.length() - 1)), false));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -44,8 +44,8 @@ import org.springframework.boot.loader.util.AsciiBytes;
|
||||
*/
|
||||
public class ExplodedArchive extends Archive {
|
||||
|
||||
private static final Set<String> SKIPPED_NAMES = new HashSet<String>(Arrays.asList(
|
||||
".", ".."));
|
||||
private static final Set<String> SKIPPED_NAMES = new HashSet<String>(
|
||||
Arrays.asList(".", ".."));
|
||||
|
||||
private static final AsciiBytes MANIFEST_ENTRY_NAME = new AsciiBytes(
|
||||
"META-INF/MANIFEST.MF");
|
||||
@@ -152,7 +152,8 @@ public class ExplodedArchive extends 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
|
||||
@@ -201,8 +202,8 @@ public class ExplodedArchive extends Archive {
|
||||
|
||||
@Override
|
||||
protected URLConnection openConnection(URL url) throws IOException {
|
||||
String name = url.getPath().substring(
|
||||
ExplodedArchive.this.root.toURI().getPath().length());
|
||||
String name = url.getPath()
|
||||
.substring(ExplodedArchive.this.root.toURI().getPath().length());
|
||||
if (ExplodedArchive.this.entries.containsKey(new AsciiBytes(name))) {
|
||||
return new URL(url.toString()).openConnection();
|
||||
}
|
||||
|
||||
@@ -85,8 +85,8 @@ public class FilteredArchive extends Archive {
|
||||
return this.parent.getFilteredArchive(new EntryRenameFilter() {
|
||||
@Override
|
||||
public AsciiBytes apply(AsciiBytes entryName, Entry entry) {
|
||||
return FilteredArchive.this.filter.matches(entry) ? filter.apply(
|
||||
entryName, entry) : null;
|
||||
return FilteredArchive.this.filter.matches(entry)
|
||||
? filter.apply(entryName, entry) : null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -248,8 +248,9 @@ public class RandomAccessDataFile implements RandomAccessData {
|
||||
try {
|
||||
this.available.acquire();
|
||||
RandomAccessFile file = this.files.poll();
|
||||
return (file == null ? new RandomAccessFile(
|
||||
RandomAccessDataFile.this.file, "r") : file);
|
||||
return (file == null
|
||||
? new RandomAccessFile(RandomAccessDataFile.this.file, "r")
|
||||
: file);
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
throw new IOException(ex);
|
||||
|
||||
@@ -82,8 +82,8 @@ class CentralDirectoryEndRecord {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,14 +45,16 @@ public class Handler extends URLStreamHandler {
|
||||
|
||||
private static final String SEPARATOR = "!/";
|
||||
|
||||
private static final String[] FALLBACK_HANDLERS = { "sun.net.www.protocol.jar.Handler" };
|
||||
private static final String[] FALLBACK_HANDLERS = {
|
||||
"sun.net.www.protocol.jar.Handler" };
|
||||
|
||||
private static final Method OPEN_CONNECTION_METHOD;
|
||||
|
||||
static {
|
||||
Method method = null;
|
||||
try {
|
||||
method = URLStreamHandler.class
|
||||
.getDeclaredMethod("openConnection", URL.class);
|
||||
method = URLStreamHandler.class.getDeclaredMethod("openConnection",
|
||||
URL.class);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Swallow and ignore
|
||||
@@ -61,6 +63,7 @@ public class Handler extends URLStreamHandler {
|
||||
}
|
||||
|
||||
private static SoftReference<Map<File, JarFile>> rootFileCache;
|
||||
|
||||
static {
|
||||
rootFileCache = new SoftReference<Map<File, JarFile>>(null);
|
||||
}
|
||||
@@ -187,7 +190,8 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,13 +108,13 @@ public final class JarEntryData {
|
||||
// aspectjrt-1.7.4.jar has a different ext bytes length in the
|
||||
// local directory to the central directory. We need to re-read
|
||||
// here to skip them
|
||||
byte[] localHeader = Bytes.get(this.source.getData().getSubsection(
|
||||
this.localHeaderOffset, LOCAL_FILE_HEADER_SIZE));
|
||||
byte[] localHeader = Bytes.get(this.source.getData()
|
||||
.getSubsection(this.localHeaderOffset, LOCAL_FILE_HEADER_SIZE));
|
||||
long nameLength = Bytes.littleEndianValue(localHeader, 26, 2);
|
||||
long extraLength = Bytes.littleEndianValue(localHeader, 28, 2);
|
||||
this.data = this.source.getData().getSubsection(
|
||||
this.localHeaderOffset + LOCAL_FILE_HEADER_SIZE + nameLength
|
||||
+ extraLength, getCompressedSize());
|
||||
this.data = this.source.getData().getSubsection(this.localHeaderOffset
|
||||
+ LOCAL_FILE_HEADER_SIZE + nameLength + extraLength,
|
||||
getCompressedSize());
|
||||
}
|
||||
return this.data;
|
||||
}
|
||||
@@ -155,8 +155,8 @@ public final class JarEntryData {
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode MSDOS Date Time details. See <a
|
||||
* href="http://mindprod.com/jgloss/zip.html">mindprod.com/jgloss/zip.html</a> for
|
||||
* Decode MSDOS Date Time details. See
|
||||
* <a href="http://mindprod.com/jgloss/zip.html">mindprod.com/jgloss/zip.html</a> for
|
||||
* more details of the format.
|
||||
* @param date the date part
|
||||
* @param time the time part
|
||||
|
||||
@@ -124,7 +124,7 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
|
||||
|
||||
private JarFile(RandomAccessDataFile rootFile, String pathFromRoot,
|
||||
RandomAccessData data, List<JarEntryData> entries, JarEntryFilter... filters)
|
||||
throws IOException {
|
||||
throws IOException {
|
||||
super(rootFile.getFile());
|
||||
this.rootFile = rootFile;
|
||||
this.pathFromRoot = pathFromRoot;
|
||||
@@ -167,7 +167,8 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
|
||||
for (JarEntryData entry : entries) {
|
||||
AsciiBytes name = entry.getName();
|
||||
for (JarEntryFilter filter : filters) {
|
||||
name = (filter == null || name == null ? name : filter.apply(name, entry));
|
||||
name = (filter == null || name == null ? name
|
||||
: filter.apply(name, entry));
|
||||
}
|
||||
if (name != null) {
|
||||
JarEntryData filteredCopy = entry.createFilteredCopy(this, name);
|
||||
@@ -291,8 +292,8 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
|
||||
// Fallback to JarInputStream to obtain certificates, not fast but hopefully not
|
||||
// happening that often.
|
||||
try {
|
||||
JarInputStream inputStream = new JarInputStream(getData().getInputStream(
|
||||
ResourceAccess.ONCE));
|
||||
JarInputStream inputStream = new JarInputStream(
|
||||
getData().getInputStream(ResourceAccess.ONCE));
|
||||
try {
|
||||
java.util.jar.JarEntry entry = inputStream.getNextJarEntry();
|
||||
while (entry != null) {
|
||||
@@ -343,8 +344,8 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
|
||||
return sourceEntry.nestedJar;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IOException("Unable to open nested jar file '"
|
||||
+ sourceEntry.getName() + "'", ex);
|
||||
throw new IOException(
|
||||
"Unable to open nested jar file '" + sourceEntry.getName() + "'", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,9 +368,10 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
|
||||
return null;
|
||||
}
|
||||
};
|
||||
return new JarFile(this.rootFile, this.pathFromRoot + "!/"
|
||||
+ sourceEntry.getName().substring(0, sourceName.length() - 1), this.data,
|
||||
this.entries, filter);
|
||||
return new JarFile(this.rootFile,
|
||||
this.pathFromRoot + "!/"
|
||||
+ sourceEntry.getName().substring(0, sourceName.length() - 1),
|
||||
this.data, this.entries, filter);
|
||||
}
|
||||
|
||||
private JarFile createJarFileFromFileEntry(JarEntryData sourceEntry)
|
||||
@@ -380,8 +382,8 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
|
||||
+ "jar files must be stored without compression. Please check the "
|
||||
+ "mechanism used to create your executable jar file");
|
||||
}
|
||||
return new JarFile(this.rootFile, this.pathFromRoot + "!/"
|
||||
+ sourceEntry.getName(), sourceEntry.getData());
|
||||
return new JarFile(this.rootFile,
|
||||
this.pathFromRoot + "!/" + sourceEntry.getName(), sourceEntry.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -101,8 +101,8 @@ class JarURLConnection extends java.net.JarURLConnection {
|
||||
@Override
|
||||
public void connect() throws IOException {
|
||||
if (!this.jarEntryName.isEmpty()) {
|
||||
this.jarEntryData = this.jarFile.getJarEntryData(this.jarEntryName
|
||||
.asAsciiBytes());
|
||||
this.jarEntryData = this.jarFile
|
||||
.getJarEntryData(this.jarEntryName.asAsciiBytes());
|
||||
if (this.jarEntryData == null) {
|
||||
throwFileNotFound(this.jarEntryName, this.jarFile);
|
||||
}
|
||||
@@ -115,8 +115,8 @@ class JarURLConnection extends java.net.JarURLConnection {
|
||||
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
|
||||
@@ -247,8 +247,8 @@ 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));
|
||||
}
|
||||
|
||||
@@ -101,8 +101,8 @@ public 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,8 +96,8 @@ 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 '"
|
||||
@@ -115,9 +115,10 @@ public abstract class SystemPropertyUtils {
|
||||
if (separatorIndex != -1) {
|
||||
String actualPlaceholder = placeholder.substring(0,
|
||||
separatorIndex);
|
||||
String defaultValue = placeholder.substring(separatorIndex
|
||||
+ VALUE_SEPARATOR.length());
|
||||
propVal = resolvePlaceholder(properties, value, actualPlaceholder);
|
||||
String defaultValue = placeholder
|
||||
.substring(separatorIndex + VALUE_SEPARATOR.length());
|
||||
propVal = resolvePlaceholder(properties, value,
|
||||
actualPlaceholder);
|
||||
if (propVal == null) {
|
||||
propVal = defaultValue;
|
||||
}
|
||||
@@ -135,8 +136,8 @@ public abstract class SystemPropertyUtils {
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -34,38 +34,39 @@ import static org.junit.Assert.assertTrue;
|
||||
public class InputArgumentsJavaAgentDetectorTests {
|
||||
|
||||
@Test
|
||||
public void nonAgentJarsDoNotProduceFalsePositives() throws MalformedURLException,
|
||||
IOException {
|
||||
public void nonAgentJarsDoNotProduceFalsePositives()
|
||||
throws MalformedURLException, IOException {
|
||||
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
|
||||
Arrays.asList("-javaagent:my-agent.jar"));
|
||||
assertFalse(detector.isJavaAgentJar(new File("something-else.jar")
|
||||
.getCanonicalFile().toURI().toURL()));
|
||||
assertFalse(detector.isJavaAgentJar(
|
||||
new File("something-else.jar").getCanonicalFile().toURI().toURL()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleJavaAgent() throws MalformedURLException, IOException {
|
||||
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
|
||||
Arrays.asList("-javaagent:my-agent.jar"));
|
||||
assertTrue(detector.isJavaAgentJar(new File("my-agent.jar").getCanonicalFile()
|
||||
.toURI().toURL()));
|
||||
assertTrue(detector.isJavaAgentJar(
|
||||
new File("my-agent.jar").getCanonicalFile().toURI().toURL()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleJavaAgentWithOptions() throws MalformedURLException, IOException {
|
||||
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
|
||||
Arrays.asList("-javaagent:my-agent.jar=a=alpha,b=bravo"));
|
||||
assertTrue(detector.isJavaAgentJar(new File("my-agent.jar").getCanonicalFile()
|
||||
.toURI().toURL()));
|
||||
assertTrue(detector.isJavaAgentJar(
|
||||
new File("my-agent.jar").getCanonicalFile().toURI().toURL()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleJavaAgents() throws MalformedURLException, IOException {
|
||||
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
|
||||
Arrays.asList("-javaagent:my-agent.jar", "-javaagent:my-other-agent.jar"));
|
||||
assertTrue(detector.isJavaAgentJar(new File("my-agent.jar").getCanonicalFile()
|
||||
.toURI().toURL()));
|
||||
assertTrue(detector.isJavaAgentJar(new File("my-other-agent.jar")
|
||||
.getCanonicalFile().toURI().toURL()));
|
||||
Arrays.asList("-javaagent:my-agent.jar",
|
||||
"-javaagent:my-other-agent.jar"));
|
||||
assertTrue(detector.isJavaAgentJar(
|
||||
new File("my-agent.jar").getCanonicalFile().toURI().toURL()));
|
||||
assertTrue(detector.isJavaAgentJar(
|
||||
new File("my-other-agent.jar").getCanonicalFile().toURI().toURL()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,44 +46,44 @@ public class LaunchedURLClassLoaderTests {
|
||||
public void resolveResourceFromWindowsFilesystem() throws Exception {
|
||||
// This path is invalid - it should return null even on Windows.
|
||||
// A regular URLClassLoader will deal with it gracefully.
|
||||
assertNull(getClass().getClassLoader().getResource(
|
||||
"c:\\Users\\user\\bar.properties"));
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL(
|
||||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass()
|
||||
.getClassLoader());
|
||||
assertNull(getClass().getClassLoader()
|
||||
.getResource("c:\\Users\\user\\bar.properties"));
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
// So we should too...
|
||||
assertNull(loader.getResource("c:\\Users\\user\\bar.properties"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourceFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL(
|
||||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass()
|
||||
.getClassLoader());
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
assertNotNull(loader.getResource("demo/Application.java"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourcesFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL(
|
||||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass()
|
||||
.getClassLoader());
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
assertTrue(loader.getResources("demo/Application.java").hasMoreElements());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveRootPathFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL(
|
||||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass()
|
||||
.getClassLoader());
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
assertNotNull(loader.getResource(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveRootResourcesFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL(
|
||||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass()
|
||||
.getClassLoader());
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
assertTrue(loader.getResources("").hasMoreElements());
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.config.name", "foo");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("my.Application", launcher.getMainClass());
|
||||
assertEquals("[etc/]", ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
assertEquals("[etc/]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,8 +96,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "jars/*");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("[jars/]", ReflectionTestUtils.getField(launcher, "paths")
|
||||
.toString());
|
||||
assertEquals("[jars/]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
@@ -106,8 +107,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "jars/app.jar");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("[jars/app.jar]", ReflectionTestUtils.getField(launcher, "paths")
|
||||
.toString());
|
||||
assertEquals("[jars/app.jar]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
@@ -117,8 +118,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "./jars/app.jar");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("[jars/app.jar]", ReflectionTestUtils.getField(launcher, "paths")
|
||||
.toString());
|
||||
assertEquals("[jars/app.jar]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
@@ -128,8 +129,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "jars/app.jar");
|
||||
System.setProperty("loader.classLoader", URLClassLoader.class.getName());
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("[jars/app.jar]", ReflectionTestUtils.getField(launcher, "paths")
|
||||
.toString());
|
||||
assertEquals("[jars/app.jar]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
|
||||
@@ -65,10 +65,8 @@ public class WarLauncherTests {
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
assertEquals(2, archives.size());
|
||||
|
||||
assertThat(
|
||||
getUrls(archives),
|
||||
hasItems(webInfClasses.toURI().toURL(), new URL("jar:"
|
||||
+ webInfLibFoo.toURI().toURL() + "!/")));
|
||||
assertThat(getUrls(archives), hasItems(webInfClasses.toURI().toURL(),
|
||||
new URL("jar:" + webInfLibFoo.toURI().toURL() + "!/")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,12 +78,10 @@ public class WarLauncherTests {
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
assertEquals(2, archives.size());
|
||||
|
||||
assertThat(
|
||||
getUrls(archives),
|
||||
hasItems(
|
||||
new URL("jar:" + warRoot.toURI().toURL() + "!/WEB-INF/classes!/"),
|
||||
new URL("jar:" + warRoot.toURI().toURL()
|
||||
+ "!/WEB-INF/lib/foo.jar!/")));
|
||||
assertThat(getUrls(archives),
|
||||
hasItems(new URL("jar:" + warRoot.toURI().toURL()
|
||||
+ "!/WEB-INF/classes!/"),
|
||||
new URL("jar:" + warRoot.toURI().toURL() + "!/WEB-INF/lib/foo.jar!/")));
|
||||
}
|
||||
|
||||
private Set<URL> getUrls(List<Archive> archives) throws MalformedURLException {
|
||||
@@ -100,8 +96,8 @@ public class WarLauncherTests {
|
||||
File warRoot = new File("target/archive.war");
|
||||
warRoot.delete();
|
||||
|
||||
JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(
|
||||
warRoot));
|
||||
JarOutputStream jarOutputStream = new JarOutputStream(
|
||||
new FileOutputStream(warRoot));
|
||||
|
||||
jarOutputStream.putNextEntry(new JarEntry("WEB-INF/"));
|
||||
jarOutputStream.putNextEntry(new JarEntry("WEB-INF/classes/"));
|
||||
|
||||
@@ -69,8 +69,8 @@ public class ExplodedArchiveTests {
|
||||
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();
|
||||
@@ -115,8 +115,8 @@ 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(), equalTo("jar:" + this.rootFolder.toURI()
|
||||
+ "nested.jar!/"));
|
||||
assertThat(nested.getUrl().toString(),
|
||||
equalTo("jar:" + this.rootFolder.toURI() + "nested.jar!/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,8 +125,8 @@ public class ExplodedArchiveTests {
|
||||
Archive nested = this.archive.getNestedArchive(entry);
|
||||
Map<String, Entry> nestedEntries = getEntriesMap(nested);
|
||||
assertThat(nestedEntries.size(), equalTo(1));
|
||||
assertThat(nested.getUrl().toString(), equalTo("file:"
|
||||
+ this.rootFolder.toURI().getPath() + "d/"));
|
||||
assertThat(nested.getUrl().toString(),
|
||||
equalTo("file:" + this.rootFolder.toURI().getPath() + "d/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,7 +159,8 @@ 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"));
|
||||
assertNotNull(archive.getManifest());
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(archive);
|
||||
assertThat(entries.size(), equalTo(4));
|
||||
@@ -167,8 +168,8 @@ 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);
|
||||
assertNotNull(archive.getManifest());
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(archive);
|
||||
assertThat(entries.size(), equalTo(3));
|
||||
@@ -176,7 +177,8 @@ 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"));
|
||||
assertNotNull(archive.getManifest());
|
||||
URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() });
|
||||
assertNotNull(loader.getResourceAsStream("META-INF/spring/application.xml"));
|
||||
@@ -185,8 +187,8 @@ public class ExplodedArchiveTests {
|
||||
|
||||
@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);
|
||||
assertNotNull(archive.getManifest());
|
||||
URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() });
|
||||
assertNotNull(loader.getResourceAsStream("META-INF/spring/application.xml"));
|
||||
|
||||
@@ -85,8 +85,8 @@ 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(), equalTo("jar:" + this.rootJarFileUrl
|
||||
+ "!/nested.jar!/"));
|
||||
assertThat(nested.getUrl().toString(),
|
||||
equalTo("jar:" + this.rootJarFileUrl + "!/nested.jar!/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -34,8 +34,8 @@ public class ByteArrayRandomAccessDataTests {
|
||||
public void testGetInputStream() throws Exception {
|
||||
byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5 };
|
||||
RandomAccessData data = new ByteArrayRandomAccessData(bytes);
|
||||
assertThat(FileCopyUtils.copyToByteArray(data
|
||||
.getInputStream(ResourceAccess.PER_READ)), equalTo(bytes));
|
||||
assertThat(FileCopyUtils.copyToByteArray(
|
||||
data.getInputStream(ResourceAccess.PER_READ)), equalTo(bytes));
|
||||
assertThat(data.getSize(), equalTo((long) bytes.length));
|
||||
}
|
||||
|
||||
@@ -44,8 +44,10 @@ public class ByteArrayRandomAccessDataTests {
|
||||
byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5 };
|
||||
RandomAccessData data = new ByteArrayRandomAccessData(bytes);
|
||||
data = data.getSubsection(1, 4).getSubsection(1, 2);
|
||||
assertThat(FileCopyUtils.copyToByteArray(data
|
||||
.getInputStream(ResourceAccess.PER_READ)), equalTo(new byte[] { 2, 3 }));
|
||||
assertThat(
|
||||
FileCopyUtils
|
||||
.copyToByteArray(data.getInputStream(ResourceAccess.PER_READ)),
|
||||
equalTo(new byte[] { 2, 3 }));
|
||||
assertThat(data.getSize(), equalTo(2L));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ import static org.junit.Assert.assertThat;
|
||||
public class RandomAccessDataFileTests {
|
||||
|
||||
private static final byte[] BYTES;
|
||||
|
||||
static {
|
||||
BYTES = new byte[256];
|
||||
for (int i = 0; i < BYTES.length; i++) {
|
||||
@@ -212,7 +213,8 @@ public class RandomAccessDataFileTests {
|
||||
@Test
|
||||
public void subsectionZeroLength() throws Exception {
|
||||
RandomAccessData subsection = this.file.getSubsection(0, 0);
|
||||
assertThat(subsection.getInputStream(ResourceAccess.PER_READ).read(), equalTo(-1));
|
||||
assertThat(subsection.getInputStream(ResourceAccess.PER_READ).read(),
|
||||
equalTo(-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -152,8 +152,8 @@ 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(), equalTo(1));
|
||||
assertThat(inputStream.read(), equalTo(1));
|
||||
assertThat(inputStream.available(), equalTo(0));
|
||||
@@ -180,8 +180,8 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void close() throws Exception {
|
||||
RandomAccessDataFile randomAccessDataFile = spy(new RandomAccessDataFile(
|
||||
this.rootJarFile, 1));
|
||||
RandomAccessDataFile randomAccessDataFile = spy(
|
||||
new RandomAccessDataFile(this.rootJarFile, 1));
|
||||
JarFile jarFile = new JarFile(randomAccessDataFile);
|
||||
jarFile.close();
|
||||
verify(randomAccessDataFile).close();
|
||||
@@ -204,7 +204,8 @@ public class JarFileTests {
|
||||
@Test
|
||||
public void createEntryUrl() throws Exception {
|
||||
URL url = new URL(this.jarFile.getUrl(), "1.dat");
|
||||
assertThat(url.toString(), equalTo("jar:" + this.rootJarFile.toURI() + "!/1.dat"));
|
||||
assertThat(url.toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/1.dat"));
|
||||
JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection();
|
||||
assertThat(jarURLConnection.getJarFile(), sameInstance(this.jarFile));
|
||||
assertThat(jarURLConnection.getJarEntry(),
|
||||
@@ -217,8 +218,8 @@ public class JarFileTests {
|
||||
@Test
|
||||
public void getMissingEntryUrl() throws Exception {
|
||||
URL url = new URL(this.jarFile.getUrl(), "missing.dat");
|
||||
assertThat(url.toString(), equalTo("jar:" + this.rootJarFile.toURI()
|
||||
+ "!/missing.dat"));
|
||||
assertThat(url.toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/missing.dat"));
|
||||
this.thrown.expect(FileNotFoundException.class);
|
||||
((JarURLConnection) url.openConnection()).getJarEntry();
|
||||
}
|
||||
@@ -242,8 +243,8 @@ 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(), equalTo("META-INF/"));
|
||||
@@ -253,14 +254,14 @@ public class JarFileTests {
|
||||
assertThat(entries.nextElement().getName(), equalTo("\u00E4.dat"));
|
||||
assertThat(entries.hasMoreElements(), equalTo(false));
|
||||
|
||||
InputStream inputStream = nestedJarFile.getInputStream(nestedJarFile
|
||||
.getEntry("3.dat"));
|
||||
InputStream inputStream = nestedJarFile
|
||||
.getInputStream(nestedJarFile.getEntry("3.dat"));
|
||||
assertThat(inputStream.read(), equalTo(3));
|
||||
assertThat(inputStream.read(), equalTo(-1));
|
||||
|
||||
URL url = nestedJarFile.getUrl();
|
||||
assertThat(url.toString(), equalTo("jar:" + this.rootJarFile.toURI()
|
||||
+ "!/nested.jar!/"));
|
||||
assertThat(url.toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar!/"));
|
||||
JarURLConnection conn = (JarURLConnection) url.openConnection();
|
||||
assertThat(conn.getJarFile(), sameInstance(nestedJarFile));
|
||||
assertThat(conn.getJarFileURL().toString(),
|
||||
@@ -276,8 +277,8 @@ public class JarFileTests {
|
||||
assertThat(entries.nextElement().getName(), equalTo("9.dat"));
|
||||
assertThat(entries.hasMoreElements(), equalTo(false));
|
||||
|
||||
InputStream inputStream = nestedJarFile.getInputStream(nestedJarFile
|
||||
.getEntry("9.dat"));
|
||||
InputStream inputStream = nestedJarFile
|
||||
.getInputStream(nestedJarFile.getEntry("9.dat"));
|
||||
assertThat(inputStream.read(), equalTo(9));
|
||||
assertThat(inputStream.read(), equalTo(-1));
|
||||
|
||||
@@ -289,11 +290,11 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void getNestJarEntryUrl() 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(), equalTo("jar:" + this.rootJarFile.toURI()
|
||||
+ "!/nested.jar!/3.dat"));
|
||||
assertThat(url.toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar!/3.dat"));
|
||||
InputStream inputStream = url.openStream();
|
||||
assertThat(inputStream, notNullValue());
|
||||
assertThat(inputStream.read(), equalTo(3));
|
||||
@@ -310,8 +311,8 @@ public class JarFileTests {
|
||||
assertThat(inputStream.read(), equalTo(3));
|
||||
JarURLConnection connection = (JarURLConnection) url.openConnection();
|
||||
assertThat(connection.getURL().toString(), equalTo(spec));
|
||||
assertThat(connection.getJarFileURL().toString(), equalTo("jar:"
|
||||
+ this.rootJarFile.toURI() + "!/nested.jar"));
|
||||
assertThat(connection.getJarFileURL().toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar"));
|
||||
assertThat(connection.getEntryName(), equalTo("3.dat"));
|
||||
}
|
||||
|
||||
@@ -360,8 +361,8 @@ public class JarFileTests {
|
||||
assertThat(entries.nextElement().getName(), equalTo("x.dat"));
|
||||
assertThat(entries.hasMoreElements(), equalTo(false));
|
||||
|
||||
InputStream inputStream = filteredJarFile.getInputStream(filteredJarFile
|
||||
.getEntry("x.dat"));
|
||||
InputStream inputStream = filteredJarFile
|
||||
.getInputStream(filteredJarFile.getEntry("x.dat"));
|
||||
assertThat(inputStream.read(), equalTo(1));
|
||||
assertThat(inputStream.read(), equalTo(-1));
|
||||
}
|
||||
@@ -369,8 +370,10 @@ public class JarFileTests {
|
||||
@Test
|
||||
public void sensibleToString() throws Exception {
|
||||
assertThat(this.jarFile.toString(), equalTo(this.rootJarFile.getPath()));
|
||||
assertThat(this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"))
|
||||
.toString(), equalTo(this.rootJarFile.getPath() + "!/nested.jar"));
|
||||
assertThat(
|
||||
this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"))
|
||||
.toString(),
|
||||
equalTo(this.rootJarFile.getPath() + "!/nested.jar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -418,8 +421,8 @@ public class JarFileTests {
|
||||
@Test
|
||||
public void cannotLoadMissingJar() throws Exception {
|
||||
// relates to gh-1070
|
||||
JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile
|
||||
.getEntry("nested.jar"));
|
||||
JarFile nestedJarFile = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
URL nestedUrl = nestedJarFile.getUrl();
|
||||
URL url = new URL(nestedUrl, nestedJarFile.getUrl() + "missing.jar!/3.dat");
|
||||
this.thrown.expect(FileNotFoundException.class);
|
||||
|
||||
@@ -49,7 +49,8 @@ public class SystemPropertyUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testNestedPlaceholder() {
|
||||
assertEquals("foo", SystemPropertyUtils.resolvePlaceholders("${bar:${spam:foo}}"));
|
||||
assertEquals("foo",
|
||||
SystemPropertyUtils.resolvePlaceholders("${bar:${spam:foo}}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user