001: /*
002: * ========================================================================
003: *
004: * Copyright 2003 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * ========================================================================
019: */
020: package org.apache.cactus.integration.ant.container.orion;
021:
022: import java.io.File;
023: import java.io.IOException;
024:
025: import org.apache.cactus.integration.ant.container.AbstractJavaContainer;
026: import org.apache.cactus.integration.ant.util.ResourceUtils;
027: import org.apache.tools.ant.BuildException;
028: import org.apache.tools.ant.taskdefs.Java;
029: import org.apache.tools.ant.types.FileSet;
030: import org.apache.tools.ant.types.FilterChain;
031: import org.apache.tools.ant.types.Path;
032: import org.apache.tools.ant.util.FileUtils;
033:
034: /**
035: * Basic support for the Orin application server.
036: *
037: * @version $Id: AbstractOrionContainer.java 239130 2005-01-29 15:49:18Z vmassol $
038: */
039: public abstract class AbstractOrionContainer extends
040: AbstractJavaContainer {
041:
042: // Instance Variables ------------------------------------------------------
043:
044: /**
045: * The Orion 1.x installation directory.
046: */
047: private File dir;
048:
049: /**
050: * The port to which the container should be bound.
051: */
052: private int port = 8080;
053:
054: /**
055: * The temporary directory from which the container will be started.
056: */
057: private File tmpDir;
058:
059: // Public Methods ----------------------------------------------------------
060:
061: /**
062: * Sets the Orion installation directory.
063: *
064: * @param theDir The directory to set
065: */
066: public final void setDir(File theDir) {
067: this .dir = theDir;
068: }
069:
070: /**
071: * Sets the port to which the container should listen.
072: *
073: * @param thePort The port to set
074: */
075: public final void setPort(int thePort) {
076: this .port = thePort;
077: }
078:
079: /**
080: * Sets the temporary directory from which to start the container.
081: *
082: * @param theTmpDir The directory to set
083: */
084: public final void setTmpDir(File theTmpDir) {
085: this .tmpDir = theTmpDir;
086: }
087:
088: // AbstractContainer Implementation ----------------------------------------
089:
090: /**
091: * Returns the port to which the container should listen.
092: *
093: * @return The port
094: */
095: public final int getPort() {
096: return this .port;
097: }
098:
099: /**
100: * @see org.apache.cactus.integration.ant.container.Container#init
101: */
102: public final void init() {
103: if (!this .dir.isDirectory()) {
104: throw new BuildException(this .dir + " is not a directory");
105: }
106: }
107:
108: /**
109: * @see org.apache.cactus.integration.ant.container.Container#shutDown
110: */
111: public final void shutDown() {
112: // invoke the main class
113: Java java = createJavaForShutDown();
114: Path classpath = java.createClasspath();
115: FileSet fileSet = new FileSet();
116: fileSet.setDir(this .dir);
117: fileSet.createInclude().setName("*.jar");
118: classpath.addFileset(fileSet);
119: java
120: .setClassname("com.evermind.client.orion.OrionConsoleAdmin");
121: java.createArg().setValue(
122: "ormi://" + this .getServer() + ":23791/");
123: java.createArg().setValue("admin");
124: java.createArg().setValue("password");
125: java.createArg().setValue("-shutdown");
126: java.execute();
127: }
128:
129: // Private Methods ---------------------------------------------------------
130:
131: /**
132: * Invokes the command to start the Orion application server.
133: */
134: protected final void invokeServer() {
135: // invoke the main class
136: Java java = createJavaForStartUp();
137: Path classpath = java.createClasspath();
138: FileSet fileSet = new FileSet();
139: fileSet.setDir(this .dir);
140: fileSet.createInclude().setName("*.jar");
141: classpath.addFileset(fileSet);
142: addToolsJarToClasspath(classpath);
143: java.setClassname("com.evermind.server.ApplicationServer");
144: java.createArg().setValue("-config");
145: java.createArg().setFile(new File(tmpDir, "conf/server.xml"));
146: java.execute();
147: }
148:
149: /**
150: * Prepares a temporary installation of the container and deploys the
151: * web-application.
152: *
153: * @param theResourcePrefix The prefix to use when looking up container
154: * resource in the JAR
155: * @param theDirName The name of the temporary container installation
156: * directory
157: * @throws IOException If an I/O error occurs
158: */
159: protected final void prepare(String theResourcePrefix,
160: String theDirName) throws IOException {
161: FileUtils fileUtils = FileUtils.newFileUtils();
162: FilterChain filterChain = createFilterChain();
163:
164: this .tmpDir = setupTempDirectory(this .tmpDir, theDirName);
165: cleanTempDirectory(this .tmpDir);
166:
167: // Copy configuration files into the temporary container directory
168:
169: File confDir = createDirectory(tmpDir, "conf");
170:
171: // Configuration files are not the same whether we deploy a
172: // WAR or an EAR
173: String sharePath = RESOURCE_PATH + theResourcePrefix + "/share";
174: String specificPath;
175: if (getDeployableFile().isWar()) {
176: specificPath = RESOURCE_PATH + theResourcePrefix + "/war";
177: } else {
178: specificPath = RESOURCE_PATH + theResourcePrefix + "/ear";
179: }
180:
181: ResourceUtils.copyResource(getProject(), specificPath
182: + "/server.xml", new File(confDir, "server.xml"),
183: filterChain);
184: ResourceUtils.copyResource(getProject(), specificPath
185: + "/application.xml", new File(confDir,
186: "application.xml"), filterChain);
187: ResourceUtils.copyResource(getProject(), specificPath
188: + "/default-web-site.xml", new File(confDir,
189: "default-web-site.xml"), filterChain);
190:
191: ResourceUtils.copyResource(getProject(), sharePath
192: + "/global-web-application.xml", new File(confDir,
193: "global-web-application.xml"), filterChain);
194: ResourceUtils.copyResource(getProject(), sharePath
195: + "/mime.types", new File(confDir, "mime.types"),
196: filterChain);
197: ResourceUtils.copyResource(getProject(), sharePath
198: + "/principals.xml",
199: new File(confDir, "principals.xml"), filterChain);
200: ResourceUtils.copyResource(getProject(),
201: sharePath + "/rmi.xml", new File(confDir, "rmi.xml"),
202: filterChain);
203:
204: // Create default web app (required by Orion unfortunately...)
205: File defaultWebAppDir = createDirectory(tmpDir,
206: "default-web-app/WEB-INF");
207: ResourceUtils.copyResource(getProject(),
208: sharePath + "/web.xml", new File(defaultWebAppDir,
209: "web.xml"), filterChain);
210:
211: // Orion need to have a /persistence directory created, otherwise it
212: // throws an error
213: createDirectory(tmpDir, "persistence");
214:
215: // Directory where modules to be deployed are located
216: File appDir = createDirectory(tmpDir, "applications");
217:
218: // Deployment directory (i.e. where Orion expands modules)
219: createDirectory(tmpDir, "application-deployments");
220:
221: // Orion log directory
222: createDirectory(tmpDir, "log");
223:
224: fileUtils.copyFile(getDeployableFile().getFile(), new File(
225: appDir, getDeployableFile().getFile().getName()), null,
226: true);
227: }
228:
229: }
|