Merge branch '2.0.x' into 2.1.x
Closes gh-17078
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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!/"));
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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!/"));
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user