001
014
015 package com.liferay.portal.tools.deploy;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019
020 import javax.enterprise.deploy.shared.ModuleType;
021 import javax.enterprise.deploy.spi.DeploymentManager;
022 import javax.enterprise.deploy.spi.TargetModuleID;
023 import javax.enterprise.deploy.spi.status.DeploymentStatus;
024 import javax.enterprise.deploy.spi.status.ProgressEvent;
025 import javax.enterprise.deploy.spi.status.ProgressListener;
026 import javax.enterprise.deploy.spi.status.ProgressObject;
027
028
032 public class DeploymentProgressListener implements ProgressListener {
033
034 public DeploymentProgressListener(
035 DeploymentHandler deploymentHandler, String warContext) {
036
037 _deploymentHandler = deploymentHandler;
038 _warContext = warContext;
039 _deploymentManager = _deploymentHandler.getDeploymentManager();
040 }
041
042 @Override
043 public void handleProgressEvent(ProgressEvent progressEvent) {
044 DeploymentStatus deploymentStatus = progressEvent.getDeploymentStatus();
045
046 if (_log.isInfoEnabled()) {
047 _log.info(deploymentStatus.getMessage());
048 }
049
050 if (deploymentStatus.isCompleted()) {
051 try {
052 TargetModuleID[] targetModuleIDs =
053 _deploymentManager.getNonRunningModules(
054 ModuleType.WAR, _deploymentManager.getTargets());
055
056 if ((targetModuleIDs != null) && (targetModuleIDs.length > 0)) {
057 for (TargetModuleID targetModuleID : targetModuleIDs) {
058 if (!_warContext.equals(targetModuleID.getModuleID())) {
059 continue;
060 }
061
062 ProgressObject startProgress = _deploymentManager.start(
063 new TargetModuleID[] {targetModuleID});
064
065 startProgress.addProgressListener(
066 new StartProgressListener(_deploymentHandler));
067
068 _deploymentHandler.setError(false);
069 _deploymentHandler.setStarted(true);
070
071 break;
072 }
073 }
074 else {
075 targetModuleIDs = _deploymentManager.getAvailableModules(
076 ModuleType.WAR, _deploymentManager.getTargets());
077
078 for (TargetModuleID targetModuleID : targetModuleIDs) {
079 if (!_warContext.equals(targetModuleID.getModuleID())) {
080 continue;
081 }
082
083 ProgressObject startProgress = _deploymentManager.start(
084 new TargetModuleID[] {targetModuleID});
085
086 startProgress.addProgressListener(
087 new StartProgressListener(_deploymentHandler));
088
089 _deploymentHandler.setError(false);
090 _deploymentHandler.setStarted(true);
091
092 break;
093 }
094 }
095 }
096 catch (Exception e) {
097 _log.error(e, e);
098
099 _deploymentHandler.setError(true);
100 _deploymentHandler.setStarted(false);
101 }
102 }
103 else if (deploymentStatus.isFailed()) {
104 _deploymentHandler.setError(true);
105 _deploymentHandler.setStarted(false);
106 }
107 }
108
109 private static Log _log = LogFactoryUtil.getLog(
110 DeploymentProgressListener.class);
111
112 private DeploymentHandler _deploymentHandler;
113 private DeploymentManager _deploymentManager;
114 private String _warContext;
115
116 }