01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.test.server.appserver;
06:
07: import org.apache.commons.io.FileUtils;
08:
09: import com.tc.util.Assert;
10:
11: import java.io.File;
12:
13: /**
14: * Manages the installed environment pertaining to an appserver. This class is supplied as a constructor argument to
15: * {@link AbstractAppServer}.
16: */
17: public abstract class AbstractAppServerInstallation implements
18: AppServerStartupEnvironment {
19:
20: private final String majorVersion;
21: private final String minorVersion;
22: private final File workingDirectory;
23: private final File serverInstall;
24: private final File dataDirectory;
25: private final File sandboxDirectory;
26: private final boolean isRepoInstall;
27:
28: /**
29: * Use existing installation (example: CATALINA_HOME)
30: */
31: public AbstractAppServerInstallation(File home, File workingDir,
32: String majorVersion, String minorVersion) throws Exception {
33: Assert.assertTrue(home.isDirectory());
34: Assert.assertTrue(workingDir.isDirectory());
35: this .majorVersion = majorVersion;
36: this .minorVersion = minorVersion;
37: this .serverInstall = home;
38: this .isRepoInstall = false;
39: this .workingDirectory = workingDir;
40: (this .dataDirectory = new File(workingDirectory
41: + File.separator + AppServerConstants.DATA_DIR))
42: .mkdir();
43: this .sandboxDirectory = workingDirectory;
44: // description file for the working directory with filename indicating the server type. Can add more desciptive
45: // information if needed.
46: new File(workingDir + File.separator + serverType() + "-"
47: + majorVersion + "." + minorVersion).createNewFile();
48:
49: }
50:
51: public final File dataDirectory() {
52: return dataDirectory;
53: }
54:
55: public abstract String serverType();
56:
57: public final String majorVersion() {
58: return majorVersion;
59: }
60:
61: public final String minorVersion() {
62: return minorVersion;
63: }
64:
65: public final void uninstall() throws Exception {
66: FileUtils.deleteDirectory(workingDirectory.getParentFile());
67: }
68:
69: public final File workingDirectory() {
70: return workingDirectory;
71: }
72:
73: public final File serverInstallDirectory() {
74: return serverInstall;
75: }
76:
77: public File sandboxDirectory() {
78: return sandboxDirectory;
79: }
80:
81: public boolean isRepoInstall() {
82: return isRepoInstall;
83: }
84: }
|