public NestedJarFile(JarFile jarFile, String path) throws IOException {
super(DeploymentUtil.DUMMY_JAR_FILE);
// verify that the jar actually contains that path
JarEntry targetEntry = jarFile.getJarEntry(path + "/");
if (targetEntry == null) {
targetEntry = jarFile.getJarEntry(path);
if (targetEntry == null) {
throw new IOException("Jar entry does not exist: jarFile=" + jarFile.getName() + ", path=" + path);
}
}
if (targetEntry.isDirectory()) {
if(targetEntry instanceof UnpackedJarEntry) {
//unpacked nested module inside unpacked ear
File targetFile = ((UnpackedJarEntry) targetEntry).getFile();
baseJar = new UnpackedJarFile(targetFile);
basePath = "";
} else {
baseJar = jarFile;
if (!path.endsWith("/")) {
path += "/";
}
basePath = path;
}
} else {
if (targetEntry instanceof UnpackedJarEntry) {
// for unpacked jars we don't need to copy the jar file
// out to a temp directory, since it is already available
// as a raw file
File targetFile = ((UnpackedJarEntry) targetEntry).getFile();
baseJar = new JarFile(targetFile);
basePath = "";
} else {
tempFile = DeploymentUtil.toFile(jarFile, targetEntry.getName());
baseJar = new JarFile(tempFile);
basePath = "";
}
}
}