throw new DeploymentException("Fail to create static resoruce cache for jar files in WEB-INF folder", e);
}
}
for (File resourceDirectory : jarResourceRootDirectory.listFiles()) {
if (resourceDirectory.isDirectory() && resourceDirectory.getName().endsWith(".jar") && resourceDirectory.listFiles().length > 0) {
FileDirContext fileDirContext = new FileDirContext();
fileDirContext.setAllowLinking(allowLinking);
fileDirContext.setDocBase(resourceDirectory.getAbsolutePath());
altDirContexts.add(fileDirContext);
}
}
//If it is system artifact, or no getRealPath and development stage support is required, just use BundleDirContext
if (!(getRealPathSupportRequired || developmentStage)) {
return new BundleDirContext(tomcatContext.getBundle(), tomcatContext.getModulePath(), altDirContexts, null);
}
File realPathTempDirectory = new File(tempRootDirectory, "real_path");
if (refreshmentRequired || !realPathTempDirectory.exists()) {
FileUtils.recursiveDelete(realPathTempDirectory);
realPathTempDirectory.mkdirs();
String modulePath = tomcatContext.getModulePath() == null ? "" : tomcatContext.getModulePath();
try {
File bundleFile = BundleUtils.toFile(bundle);
if (bundleFile != null) {
if (bundleFile.isFile()) {
JarUtils.unzipToDirectory(new ZipFile(bundleFile), realPathTempDirectory, modulePath, true);
} else {
FileUtils.copyFile(new File(bundleFile, modulePath), realPathTempDirectory);
}
} else {
ZipInputStream zipIn = null;
try {
zipIn = new ZipInputStream(new URL(bundle.getLocation()).openStream());
JarUtils.unzipToDirectory(zipIn, realPathTempDirectory, modulePath, true);
} finally {
IOUtils.close(zipIn);
}
}
} catch (IOException e) {
checksumFile.delete();
getLogger().warn("fail to extract the bundle, getRealPath might not work", e);
}
}
if (developmentStage) {
GeronimoFileDirContext fileDirContext = new GeronimoFileDirContext(altDirContexts);
fileDirContext.setAllowLinking(allowLinking);
setDocBase(realPathTempDirectory.getAbsolutePath());
return fileDirContext;
} else {
return new BundleDirContext(tomcatContext.getBundle(), tomcatContext.getModulePath(), altDirContexts, realPathTempDirectory);
}