001
014
015 package com.liferay.portal.kernel.deploy.hot;
016
017 import com.liferay.portal.kernel.deploy.DeployManagerUtil;
018 import com.liferay.portal.kernel.log.Log;
019 import com.liferay.portal.kernel.log.LogFactoryUtil;
020 import com.liferay.portal.kernel.plugin.PluginPackage;
021 import com.liferay.portal.kernel.util.ArrayUtil;
022 import com.liferay.portal.kernel.util.PortalLifecycle;
023 import com.liferay.portal.kernel.util.PropertiesUtil;
024 import com.liferay.portal.kernel.util.StringUtil;
025
026 import java.io.IOException;
027 import java.io.InputStream;
028
029 import java.util.List;
030 import java.util.Properties;
031 import java.util.Queue;
032 import java.util.Set;
033 import java.util.TreeSet;
034 import java.util.concurrent.ConcurrentLinkedQueue;
035
036 import javax.servlet.ServletContext;
037
038
044 public class HotDeployEvent {
045
046 public HotDeployEvent(
047 ServletContext servletContext, ClassLoader contextClassLoader) {
048
049 _servletContext = servletContext;
050 _contextClassLoader = contextClassLoader;
051
052 try {
053 initDependentServletContextNames();
054 }
055 catch (IOException ioe) {
056 _log.error(ioe, ioe);
057 }
058 }
059
060 public void addPortalLifecycle(PortalLifecycle portalLifecycle) {
061 _portalLifecycles.add(portalLifecycle);
062 }
063
064 public void flushInits() {
065 for (PortalLifecycle portalLifecycle : _portalLifecycles) {
066 portalLifecycle.portalInit();
067 }
068
069 _portalLifecycles.clear();
070 }
071
072 public ClassLoader getContextClassLoader() {
073 return _contextClassLoader;
074 }
075
076 public Set<String> getDependentServletContextNames() {
077 return _dependentServletContextNames;
078 }
079
080 public PluginPackage getPluginPackage() {
081 return _pluginPackage;
082 }
083
084 public ServletContext getServletContext() {
085 return _servletContext;
086 }
087
088 public String getServletContextName() {
089 return _servletContext.getServletContextName();
090 }
091
092 public void setPluginPackage(PluginPackage pluginPackage) {
093 _pluginPackage = pluginPackage;
094 }
095
096 protected void initDependentServletContextNames() throws IOException {
097 if (!DependencyManagementThreadLocal.isEnabled()) {
098 return;
099 }
100
101 List<String[]> levelsRequiredDeploymentContexts =
102 DeployManagerUtil.getLevelsRequiredDeploymentContexts();
103
104 for (String[] levelRequiredDeploymentContexts :
105 levelsRequiredDeploymentContexts) {
106
107 if (ArrayUtil.contains(
108 levelRequiredDeploymentContexts,
109 _servletContext.getServletContextName())) {
110
111 break;
112 }
113
114 for (String levelRequiredDeploymentContext :
115 levelRequiredDeploymentContexts) {
116
117 _dependentServletContextNames.add(
118 levelRequiredDeploymentContext);
119 }
120 }
121
122 InputStream inputStream = _servletContext.getResourceAsStream(
123 "/WEB-INF/liferay-plugin-package.properties");
124
125 if (inputStream != null) {
126 String propertiesString = StringUtil.read(inputStream);
127
128 Properties properties = PropertiesUtil.load(propertiesString);
129
130 String[] pluginPackgeRequiredDeploymentContexts =
131 StringUtil.split(
132 properties.getProperty("required-deployment-contexts"));
133
134 for (String pluginPackageRequiredDeploymentContext :
135 pluginPackgeRequiredDeploymentContexts) {
136
137 _dependentServletContextNames.add(
138 pluginPackageRequiredDeploymentContext.trim());
139 }
140 }
141
142 if (!_dependentServletContextNames.isEmpty() && _log.isInfoEnabled()) {
143 String servletContextName = _servletContext.getServletContextName();
144
145 _log.info(
146 "Plugin " + servletContextName + " requires " +
147 StringUtil.merge(_dependentServletContextNames, ", "));
148 }
149 }
150
151 private static Log _log = LogFactoryUtil.getLog(HotDeployEvent.class);
152
153 private ClassLoader _contextClassLoader;
154 private Set<String> _dependentServletContextNames = new TreeSet<String>();
155 private PluginPackage _pluginPackage;
156 private Queue<PortalLifecycle> _portalLifecycles =
157 new ConcurrentLinkedQueue<PortalLifecycle>();
158 private ServletContext _servletContext;
159
160 }