001
014
015 package com.liferay.portal.deploy.messaging;
016
017 import com.liferay.portal.kernel.deploy.DeployManagerUtil;
018 import com.liferay.portal.kernel.deploy.auto.AutoDeployDir;
019 import com.liferay.portal.kernel.deploy.auto.AutoDeployUtil;
020 import com.liferay.portal.kernel.log.Log;
021 import com.liferay.portal.kernel.log.LogFactoryUtil;
022 import com.liferay.portal.kernel.messaging.BaseMessageListener;
023 import com.liferay.portal.kernel.messaging.Message;
024 import com.liferay.portal.kernel.util.StreamUtil;
025
026 import java.io.FileOutputStream;
027 import java.io.InputStream;
028
029 import java.util.List;
030
031
038 public class RequiredPluginsMessageListener extends BaseMessageListener {
039
040 @Override
041 protected void doReceive(Message message) throws Exception {
042 if (_firstMessage) {
043
044
045
046 _firstMessage = false;
047
048 return;
049 }
050
051 List<String[]> levelsRequiredDeploymentContexts =
052 DeployManagerUtil.getLevelsRequiredDeploymentContexts();
053 List<String[]> levelsRequiredDeploymentWARFileNames =
054 DeployManagerUtil.getLevelsRequiredDeploymentWARFileNames();
055
056 for (int i = 0; i < levelsRequiredDeploymentContexts.size(); i++) {
057 String[] levelRequiredDeploymentContexts =
058 levelsRequiredDeploymentContexts.get(i);
059 String[] levelRequiredDeploymentWARFileNames =
060 levelsRequiredDeploymentWARFileNames.get(i);
061
062 for (int j = 0; j < levelRequiredDeploymentContexts.length; j++) {
063 String levelRequiredDeploymentContext =
064 levelRequiredDeploymentContexts[j];
065
066 if (DeployManagerUtil.isDeployed(
067 levelRequiredDeploymentContext)) {
068
069 continue;
070 }
071
072 String levelRequiredDeploymentWARFileName =
073 levelRequiredDeploymentWARFileNames[j];
074
075 if (_log.isDebugEnabled()) {
076 _log.debug(
077 "Automatically deploying the required plugin " +
078 levelRequiredDeploymentWARFileName);
079 }
080
081 Class<?> clazz = getClass();
082
083 ClassLoader classLoader = clazz.getClassLoader();
084
085 InputStream inputStream = classLoader.getResourceAsStream(
086 "com/liferay/portal/deploy/dependencies/plugins" +
087 (i + 1) + "/" + levelRequiredDeploymentWARFileNames[j]);
088
089 AutoDeployDir autoDeployDir = AutoDeployUtil.getDir(
090 AutoDeployDir.DEFAULT_NAME);
091
092 if (autoDeployDir == null) {
093
094
095
096 if (_log.isDebugEnabled()) {
097 _log.debug(
098 "The autodeploy directory " +
099 AutoDeployDir.DEFAULT_NAME + " is null");
100 }
101
102 continue;
103 }
104
105 StreamUtil.transfer(
106 inputStream,
107 new FileOutputStream(
108 autoDeployDir.getDeployDir() + "/" +
109 levelRequiredDeploymentWARFileNames[j]));
110 }
111 }
112 }
113
114 private static Log _log = LogFactoryUtil.getLog(
115 RequiredPluginsMessageListener.class);
116
117 private boolean _firstMessage = true;
118
119 }