private ExtendedDeploymentContext getContext(ExtendedDeploymentContext initial, DeploymentContextBuilder builder) throws IOException {
DeploymentContextBuilder copy = new DeploymentContextBuidlerImpl(builder);
ReadableArchive archive = getArchive(copy);
copy.source(archive);
if (initial==null) {
initial = new DeploymentContextImpl(copy, env);
}
ArchiveHandler archiveHandler = copy.archiveHandler();
if (archiveHandler == null) {
String type = null;
OpsParams params = builder.params();
if (params != null && params instanceof DeployCommandParameters) {
type = ((DeployCommandParameters)params).type;
}
archiveHandler = getArchiveHandler(archive, type);
}
// this is needed for autoundeploy to find the application
// with the archive name
File sourceFile = new File(archive.getURI().getSchemeSpecificPart());
initial.getAppProps().put(ServerTags.DEFAULT_APP_NAME,
DeploymentUtils.getDefaultEEName(sourceFile.getName()));
if (!(sourceFile.isDirectory())) {
String repositoryBitName = copy.params().name();
try {
repositoryBitName = VersioningUtils.getRepositoryName(repositoryBitName);
} catch (VersioningSyntaxException e) {
ActionReport report = copy.report();
report.setMessage(e.getMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
// create a temporary deployment context
File expansionDir = new File(domain.getApplicationRoot(),
repositoryBitName);
if (!expansionDir.mkdirs()) {
/*
* On Windows especially a previous directory might have
* remainded after an earlier undeployment, for example if
* a JAR file in the earlier deployment had been locked.
* Warn but do not fail in such a case.
*/
logger.fine(localStrings.getLocalString("deploy.cannotcreateexpansiondir", "Error while creating directory for jar expansion: {0}",expansionDir));
}
try {
Long start = System.currentTimeMillis();
final WritableArchive expandedArchive = archiveFactory.createArchive(expansionDir);
archiveHandler.expand(archive, expandedArchive, initial);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Deployment expansion took " + (System.currentTimeMillis() - start));
}
// Close the JAR archive before losing the reference to it or else the JAR remains locked.
try {
archive.close();
} catch(IOException e) {
logger.log(Level.SEVERE, localStrings.getLocalString("deploy.errorclosingarchive","Error while closing deployable artifact {0}", archive.getURI().getSchemeSpecificPart()),e);
throw e;
}
archive = (FileArchive) expandedArchive;
initial.setSource(archive);
} catch(IOException e) {