throws IOException, DeploymentException {
File explodedManifest = null;
File preservedManifestFromArchive = null;
FileArchive target = new FileArchive();
target.create(directory.toURI());
explodeJar(new File(source.getURI()), directory);
if (preserveManifest) {
explodedManifest = new File(directory, java.util.jar.JarFile.MANIFEST_NAME);
if (explodedManifest.exists()) {
/* Rename the manifest so it can be restored later. */
preservedManifestFromArchive = new File(directory, PRESERVED_MANIFEST_NAME);
if ( ! explodedManifest.renameTo(preservedManifestFromArchive)) {
throw new RuntimeException(localStrings.getString(
"enterprise.deployment.backend.error_saving_manifest",
new Object[]
{ explodedManifest.getAbsolutePath(),
preservedManifestFromArchive.getAbsolutePath()
} ) ) ;
}
}
}
// now explode all top level jar files and delete them.
// this cannot be done before since the optionalPkgDependency
// require access to the manifest file of each .jar file.
for (Enumeration itr = source.entries();itr.hasMoreElements();) {
String fileName = (String) itr.nextElement();
// check for optional packages depencies
// XXX : JEROME look if this is still done
// resolveDependencies(new File(directory, fileName));
/*
*Expand the file only if it is a jar and only if it does not lie in WEB-INF/lib.
*/
if (fileName.toLowerCase(Locale.US).endsWith(".jar") &&
( ! fileName.replace('\\', '/').toUpperCase(Locale.getDefault()).startsWith(WEB_INF_PREFIX)) ) {
try {
File f = new File(directory, fileName);
ZipFile zip = new ZipFile(f, directory);
zip.explode();
} catch(ZipFileException e) {
IOException ioe = new IOException(e.getMessage());
ioe.initCause(e);
throw ioe;
}
}
}
/*
*If the archive's manifest was renamed to protect it from being overwritten by manifests from
*jar files, then rename it back. Delete an existing manifest file first if needed.
*/
if (preservedManifestFromArchive != null) {
if (explodedManifest.exists()) {
if ( ! explodedManifest.delete()) {
throw new RuntimeException(localStrings.getString(
"enterprise.deployment.backend.error_deleting_manifest",
new Object []
{ explodedManifest.getAbsolutePath(),
preservedManifestFromArchive.getAbsolutePath()
}
) );
}
}
if ( ! preservedManifestFromArchive.renameTo(explodedManifest)) {
throw new RuntimeException(localStrings.getString(
"enterprise.deployment.backend.error_restoring_manifest",
new Object []
{ preservedManifestFromArchive.getAbsolutePath(),
explodedManifest.getAbsolutePath()
}
) );
}
}
source.close();
target.close();
}