/*
* Delete the repository directory as an archive to allow
* any special processing (such as stale file handling)
* to run.
*/
final FileArchive arch = DeploymentUtils.openAsFileArchive(reposDir, archiveFactory);
arch.delete();
}
}
if (!DeploymentUtils.isDomainTarget(target) && enabled) {
// try to disable the enabled version, if exist
try {
versioningService.handleDisable(name,target, report, context.getSubject());
} catch (VersioningSyntaxException e) {
report.failure(logger, e.getMessage());
return;
}
}
File source = new File(archive.getURI().getSchemeSpecificPart());
boolean isDirectoryDeployed = true;
if (!source.isDirectory()) {
isDirectoryDeployed = false;
expansionDir = new File(domain.getApplicationRoot(), VersioningUtils.getRepositoryName(name));
path = expansionDir;
} else {
// test if a version is already directory deployed from this dir
String versionFromSameDir =
versioningService.getVersionFromSameDir(source);
if (!force && versionFromSameDir != null) {
report.failure(logger,
VersioningUtils.LOCALSTRINGS.getLocalString(
"versioning.deployment.dual.inplace",
"GlassFish do not support versioning for directory deployment when using the same directory. The directory {0} is already assigned to the version {1}.",
source.getPath(),
versionFromSameDir));
return;
}
}
// create the parent class loader
deploymentContext =
deployment.getBuilder(logger, this, report).
source(initialContext.getSource()).archiveHandler(archiveHandler).build(initialContext);
if (tracing!=null) {
tracing.addMark(DeploymentTracing.Mark.CONTEXT_CREATED);
deploymentContext.addModuleMetaData(tracing);
}
// reset the properties (might be null) set by the deployers when undeploying.
if (undeployProps!=null) {
deploymentContext.getAppProps().putAll(undeployProps);
}
if (properties != null || property != null) {
// if one of them is not null, let's merge them
// to properties so we don't need to always
// check for both
if (properties == null) {
properties = new Properties();
}
if (property != null) {
properties.putAll(property);
}
}
if (properties != null) {
deploymentContext.getAppProps().putAll(properties);
validateDeploymentProperties(properties, deploymentContext);
}
// clean up any generated files
deploymentContext.clean();
Properties appProps = deploymentContext.getAppProps();
/*
* If the app's location is within the domain's directory then
* express it in the config as ${com.sun.aas.instanceRootURI}/rest-of-path
* so users can relocate the entire installation without having
* to modify the app locations. Leave the location alone if
* it does not fall within the domain directory.
*/
String appLocation = DeploymentUtils.relativizeWithinDomainIfPossible( deploymentContext.getSource().getURI());
appProps.setProperty(ServerTags.LOCATION, appLocation);
// set to default "user", deployers can override it
// during processing
appProps.setProperty(ServerTags.OBJECT_TYPE, "user");
if (contextroot!=null) {
appProps.setProperty(ServerTags.CONTEXT_ROOT, contextroot);
}
appProps.setProperty(ServerTags.DIRECTORY_DEPLOYED, String.valueOf(isDirectoryDeployed));
if (type == null) {
type = archiveHandler.getArchiveType();
}
appProps.setProperty(Application.ARCHIVE_TYPE_PROP_NAME, type);
savedAppConfig.store(appProps);
deploymentContext.addTransientAppMetaData(DeploymentProperties.PREVIOUS_TARGETS, previousTargets);
deploymentContext.addTransientAppMetaData(DeploymentProperties.PREVIOUS_VIRTUAL_SERVERS, previousVirtualServers);
deploymentContext.addTransientAppMetaData(DeploymentProperties.PREVIOUS_ENABLED_ATTRIBUTES, previousEnabledAttributes);
Transaction t = deployment.prepareAppConfigChanges(deploymentContext);
if (tracing!=null) {
tracing.addMark(DeploymentTracing.Mark.DEPLOY);
}
ApplicationInfo appInfo;
appInfo = deployment.deploy(deploymentContext);
/*
* Various deployers might have added to the downloadable or
* generated artifacts. Extract them and, if the command succeeded,
* persist both into the app properties (which will be recorded
* in domain.xml).
*/
final Artifacts downloadableArtifacts =
DeploymentUtils.downloadableArtifacts(deploymentContext);
final Artifacts generatedArtifacts =
DeploymentUtils.generatedArtifacts(deploymentContext);
if (report.getActionExitCode()==ActionReport.ExitCode.SUCCESS) {
try {
moveAppFilesToPermanentLocation(
deploymentContext, logger);
recordFileLocations(appProps);
downloadableArtifacts.record(appProps);
generatedArtifacts.record(appProps);
// register application information in domain.xml
deployment.registerAppInDomainXML(appInfo, deploymentContext, t);
if (tracing!=null) {
tracing.addMark(DeploymentTracing.Mark.REGISTRATION);
}
if (retrieve != null) {
retrieveArtifacts(context, downloadableArtifacts.getArtifacts(), retrieve, false, name);
}
suppInfo.setDeploymentContext(deploymentContext);
//Fix for issue 14442
//We want to report the worst subreport value.
ActionReport.ExitCode worstExitCode = ExitCode.SUCCESS;
for (ActionReport subReport : report.getSubActionsReport()) {
ActionReport.ExitCode actionExitCode = subReport.getActionExitCode();
if ( actionExitCode.isWorse(worstExitCode) ){
worstExitCode = actionExitCode;
}
}
report.setActionExitCode(worstExitCode);
report.setResultType(String.class, name);
} catch (Exception e) {
// roll back the deployment and re-throw the exception
deployment.undeploy(name, deploymentContext);
deploymentContext.clean();
throw e;
}
}
} catch(Throwable e) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(e.getMessage());
report.setFailureCause(e);
} finally {
events.unregister(this);
try {
archive.close();
} catch(IOException e) {
logger.log(Level.FINE, localStrings.getLocalString(
"errClosingArtifact",
"Error while closing deployable artifact : ",
path.getAbsolutePath()), e);
}
if (tracing!=null) {
tracing.print(System.out);
}
if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
// Set the app name in the result so that embedded deployer can retrieve it.
report.setResultType(String.class, name);
report.setMessage(localStrings.getLocalString("deploy.command.success","Application deployed with name {0}", name));
logger.info(localStrings.getLocalString(
"deploy.done",
"Deployment of {0} done is {1} ms",
name,
timing.elapsed()));
} else if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
String errorMessage = report.getMessage();
Throwable cause = report.getFailureCause();
if (cause != null) {
String causeMessage = cause.getMessage();
if (causeMessage != null &&
!causeMessage.equals(errorMessage)) {
errorMessage = errorMessage + " : " + cause.getMessage();
}
logger.log(Level.SEVERE, errorMessage, cause.getCause());
}
report.setMessage(localStrings.getLocalString("deploy.errDuringDepl", "Error occur during deployment: {0}.", errorMessage));
// reset the failure cause so command framework will not try
// to print the same message again
report.setFailureCause(null);
if (expansionDir!=null) {
final FileArchive arch;
try {
/*
* Open and then delete the expansion directory as
* a file archive so stale file handling can run.
*/
arch = DeploymentUtils.openAsFileArchive(expansionDir, archiveFactory);
arch.delete();
} catch (IOException ex) {
final String msg = localStrings.getLocalString(
"deploy.errDelRepos",
"Error deleting repository directory {0}",
expansionDir.getAbsolutePath());