001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.pluto.util.install.file.jetty;
018:
019: import org.apache.commons.io.FileUtils;
020: import org.apache.pluto.util.install.InstallationConfig;
021: import org.apache.pluto.util.install.file.FileSystemInstaller;
022: import org.apache.pluto.util.UtilityException;
023:
024: import java.io.File;
025: import java.io.IOException;
026: import java.util.Iterator;
027:
028: public class Jetty5FileSystemInstaller extends FileSystemInstaller {
029:
030: protected File getEndorsedDir(InstallationConfig config) {
031: File installationDirectory = config.getInstallationDirectory();
032: return new File(installationDirectory, "ext");
033: }
034:
035: protected File getSharedDir(InstallationConfig config) {
036: File installationDirectory = config.getInstallationDirectory();
037: // Jetty 5.1 provides commons-logging. Should be a nicer way
038: // for installers to indicate what dependencies are provided by the
039: // servlet container.
040: if (new File(config.getInstallationDirectory(),
041: "ext/commons-logging.jar").exists()) {
042: for (Iterator iter = config.getSharedDependencies()
043: .iterator(); iter.hasNext();) {
044: File dep = (File) iter.next();
045: if (dep.getPath().indexOf("commons-logging-api") != -1) {
046: iter.remove();
047: }
048: }
049: }
050: return new File(installationDirectory, "ext");
051: }
052:
053: protected File getWebAppDir(InstallationConfig config) {
054: File installationDirectory = config.getInstallationDirectory();
055: return new File(installationDirectory, "webapps");
056: }
057:
058: protected File getConfigurationDir(InstallationConfig config) {
059: File installationDirectory = config.getInstallationDirectory();
060: String engine = "Catalina";
061: String host = config.getServerConfig().getHost();
062: return new File(installationDirectory, "conf/" + engine + "/"
063: + host);
064: }
065:
066: public void uninstall(InstallationConfig config) {
067: }
068:
069: public void deploy() {
070:
071: }
072:
073: public boolean isValidInstallationDirectory(File installDir) {
074: File serverConfig = new File(installDir, "etc/jetty.xml");
075: return serverConfig.exists();
076: }
077:
078: /**
079: * NOTE: Order is important. If the server is running, we want to
080: * make sure that the correct order is preserved
081: * <p/>
082: * 1) Install endorsed dependencies
083: * 2) Install shared dependencies
084: * 4) Prep Time
085: * -- Create a domain directory for the portal
086: * -- Init the configs holder
087: * 5) Install the Portlet Applications
088: * 6) Install the Portal Application
089: * 7) Finally, install the configs
090: *
091: * @param config
092: * @throws org.apache.pluto.util.UtilityException
093: *
094: */
095: public void install(InstallationConfig config)
096: throws UtilityException {
097: File endorsedDir = getEndorsedDir(config);
098: File sharedDir = getSharedDir(config);
099: File domainDir = getWebAppDir(config);
100: domainDir.mkdirs();
101: File contextConfigurationDirectory = getConfigurationDir(config);
102:
103: try {
104:
105: // Jetty Doesn't need 'em
106: //copyFilesToDirectory(config.getEndorsedDependencies(), endorsedDir);
107:
108: copyFilesToDirectory(config.getSharedDependencies(),
109: sharedDir);
110:
111: Iterator it = config.getPortletApplications().values()
112: .iterator();
113: while (it.hasNext()) {
114: File portletApp = (File) it.next();
115: FileUtils.copyFileToDirectory(portletApp, domainDir);
116: }
117:
118: FileUtils.copyFileToDirectory(
119: config.getPortalApplication(), domainDir);
120:
121: // it = config.getPortletApplications().entrySet().iterator();
122: // while (it.hasNext()) {
123: // Map.Entry entry = (Map.Entry) it.next();
124: // String context = entry.getKey().toString();
125: // File portletApp = (File) entry.getValue();
126: //
127: // File deployed = new File(domainDir, portletApp.getName());
128: // String contents = getPortletApplicationConfig(context, deployed);
129: // //FileWriter out = new FileWriter(
130: // // new File(contextConfigurationDirectory, context + ".xml"));
131: // out.write(contents);
132: // out.flush();
133: // out.close();
134: // }
135:
136: // File xmlFile = new File(contextConfigurationDirectory, config.getPortalContextPath() + ".xml");
137: // FileWriter out = new FileWriter(xmlFile);
138: // out.write(getPortalApplicationConfig(config));
139: // out.flush();
140: // out.close();
141: } catch (IOException io) {
142: throw new UtilityException(io);
143: }
144: }
145:
146: private String getPortalApplicationConfig(InstallationConfig config) {
147: File domainDir = this .getWebAppDir(config);
148: String war = domainDir.getAbsolutePath() + File.separatorChar
149: + config.getPortalApplication().getName();
150: String contextPath = config.getPortalContextPath();
151: return getConfigContents(war, contextPath);
152: }
153:
154: private String getPortletApplicationConfig(String contextPath,
155: File file) {
156: String war = file.getAbsolutePath();
157: return getConfigContents(war, contextPath);
158: }
159:
160: public void writeConfiguration(InstallationConfig config) {
161:
162: }
163:
164: private String getConfigContents(String war, String contextPath) {
165: return "JettyConfigContents: war=" + war + "contextPath="
166: + contextPath;
167: }
168: }
|