// now start to expand the sub modules
for (ModuleDescriptor md : holder.app.getModules()) {
String moduleUri = md.getArchiveUri();
ReadableArchive subArchive = null;
WritableArchive subTarget = null;
ReadableArchive subArchiveToExpand = null;
try {
subArchive = source2.getSubArchive(moduleUri);
if (subArchive == null) {
_logger.log(Level.WARNING,
"Exception while locating sub archive: " +
moduleUri);
continue;
}
// optimize performance by retrieving the archive handler
// based on module type first
ArchiveHandler subHandler = getArchiveHandlerFromModuleType(md.getModuleType());
if (subHandler == null) {
subHandler = deployment.getArchiveHandler(subArchive);
}
context.getModuleArchiveHandlers().put(
moduleUri, subHandler);
if (subHandler!=null) {
subTarget = target.createSubArchive(
FileUtils.makeFriendlyFilenameExtension(moduleUri));
/*
* A subarchive might be packaged as a subdirectory
* (instead of a nested JAR) in an EAR. If so and if it
* has the same name as the directory into which we'll
* expand the submodule, make sure it is also of the
* correct archive type (i.e., directory and not JAR)
* in which case we don't need to expand it because the developer
* already did so before packaging.
*/
subArchiveToExpand = chooseSubArchiveToExpand(moduleUri, subTarget, subArchive, source2);
if (subArchiveToExpand != null) {
subHandler.expand(subArchiveToExpand, subTarget, context);
} else {
/*
* The target for expansion is the same URI as the
* subarchive. Make sure they are the same type;
* if so, we just skip the expansion. Otherwise,
* we would leave a JAR where the rest of
* deployment expects a subdirectory so throw an
* exception in that case.
*/
if ( ! areSameStorageType(subTarget, subArchive)) {
final String msg = MessageFormat.format(
_logger.getResourceBundle().getString("enterprise.deployment.backend.badSubModPackaging"),
subArchive.getURI().toASCIIString(),
subArchive.getClass().getName());
throw new RuntimeException(msg);
}
}
// Keep the original submodule file because the app client deployer needs it.
/*
// delete the original module file
File origSubArchiveFile = new File(
target.getURI().getSchemeSpecificPart(), moduleUri);
origSubArchiveFile.delete();
*/
}
} catch(IOException ioe) {
_logger.log(Level.FINE, "Exception while processing " +
moduleUri, ioe);
} finally {
try {
if (subArchive != null) {
subArchive.close();
}
if (subTarget != null) {
subTarget.close();
}
if (subArchiveToExpand != null) {
subArchiveToExpand.close();
}
} catch (IOException ioe) {