}
}
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 (systemArtifact || !(getRealPathSupportRequired || developmentStage)) {
return new BundleDirContext(tomcatContext.getBundle(), tomcatContext.getModulePath(), altDirContexts, null);
}
File realPathTempDirecotory = new File(tempRootDirectory, "real_path");
if (refreshmentRequired || ! realPathTempDirecotory.exists()) {
FileUtils.recursiveDelete(realPathTempDirecotory);
realPathTempDirecotory.mkdirs();
ZipInputStream zipIn = null;
try {
zipIn = new ZipInputStream(new URL(bundle.getLocation()).openStream());
ZipEntry entry = null;
String modulePath = tomcatContext.getModulePath() == null ? "" : tomcatContext.getModulePath();
while ((entry = zipIn.getNextEntry()) != null) {
if(!entry.getName().startsWith(modulePath)){
continue;
}
String subPath = entry.getName().equals(modulePath) ? "" : entry.getName().substring(modulePath.length());
if (entry.isDirectory()) {
File dir = new File(realPathTempDirecotory, subPath);
dir.mkdirs();
} else {
File file = new File(realPathTempDirecotory, subPath);
file.getParentFile().mkdirs();
OutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(file));
IOUtils.copy(zipIn, out);
out.flush();
} finally {
IOUtils.close(out);
}
}
}
} catch (IOException e) {
checksumFile.delete();
getLogger().warn("fail to extract the bundle, getRealPath might not work", e);
} finally {
IOUtils.close(zipIn);
}
}
if (developmentStage) {
GeronimoFileDirContext fileDirContext = new GeronimoFileDirContext(altDirContexts);
fileDirContext.setAllowLinking(allowLinking);
setDocBase(realPathTempDirecotory.getAbsolutePath());
return fileDirContext;
} else {
return new BundleDirContext(tomcatContext.getBundle(), tomcatContext.getModulePath(), altDirContexts, realPathTempDirecotory);
}