001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.test.server.appserver.deployment;
005:
006: import java.io.File;
007: import java.io.IOException;
008:
009: public class FileSystemPath {
010:
011: private final File path;
012:
013: public boolean equals(Object obj) {
014: if (!(obj instanceof FileSystemPath))
015: return false;
016: FileSystemPath other = (FileSystemPath) obj;
017: return path.equals(other.path);
018: }
019:
020: public int hashCode() {
021: return path.hashCode();
022: }
023:
024: private FileSystemPath(String path) {
025: this .path = new File(path);
026: }
027:
028: public FileSystemPath(File dir) {
029: this .path = dir;
030: }
031:
032: public static FileSystemPath existingDir(String path) {
033: FileSystemPath f = new FileSystemPath(path);
034: if (!f.isDirectory()) {
035: throw new RuntimeException("Non-existent directory: "
036: + path);
037: }
038: return f;
039: }
040:
041: boolean isDirectory() {
042: return path.isDirectory();
043: }
044:
045: public static FileSystemPath makeExistingFile(String path) {
046: FileSystemPath f = new FileSystemPath(path);
047: if (!f.isFile()) {
048: throw new RuntimeException("Non-existent file: " + path);
049: }
050: return f;
051: }
052:
053: private boolean isFile() {
054: return path.isFile();
055: }
056:
057: public String toString() {
058: try {
059: return path.getCanonicalPath();
060: } catch (IOException e) {
061: return path.getAbsolutePath();
062: }
063: }
064:
065: public FileSystemPath existingSubdir(String subdirectoryPath) {
066: return existingDir(path + "/" + subdirectoryPath);
067: }
068:
069: public FileSystemPath existingFile(String fileName) {
070: return makeExistingFile(this .path + "/" + fileName);
071: }
072:
073: public Deployment warDeployment(String warName) {
074: return new WARDeployment(existingFile(warName));
075: }
076:
077: public File getFile() {
078: return path;
079: }
080:
081: public FileSystemPath subdir(String subdirectoryPath) {
082: return new FileSystemPath(path + "/" + subdirectoryPath);
083: }
084:
085: public void delete() {
086: path.delete();
087: }
088:
089: public FileSystemPath file(String fileName) {
090: return new FileSystemPath((this .path + "/" + fileName));
091: }
092:
093: public FileSystemPath mkdir(String subdir) {
094: return subdir(subdir).mkdir();
095: }
096:
097: private FileSystemPath mkdir() {
098: path.mkdirs();
099: return this ;
100: }
101:
102: public static FileSystemPath makeNewFile(String fileName) {
103: return new FileSystemPath(fileName);
104: }
105:
106: }
|