1 4 package com.tctest.spring.integrationtests.framework; 5 6 import java.io.File ; 7 import java.io.IOException ; 8 9 public class FileSystemPath { 10 11 private final File path; 12 13 public boolean equals(Object obj) { 14 if (!(obj instanceof FileSystemPath)) return false; 15 FileSystemPath other = (FileSystemPath) obj; 16 return path.equals(other.path); 17 } 18 19 public int hashCode() { 20 return path.hashCode(); 21 } 22 23 private FileSystemPath(String path) { 24 this.path = new File (path); 25 } 26 27 public FileSystemPath(File dir) { 28 this.path = dir; 29 } 30 31 public static FileSystemPath existingDir(String path) { 32 FileSystemPath f = new FileSystemPath(path); 33 if (!f.isDirectory()) { throw new RuntimeException ("Non-existent directory: " + path); } 34 return f; 35 } 36 37 boolean isDirectory() { 38 return path.isDirectory(); 39 } 40 41 public static FileSystemPath makeExistingFile(String path) { 42 FileSystemPath f = new FileSystemPath(path); 43 if (!f.isFile()) { 44 throw new RuntimeException ("Non-existent file: " + path); 45 } 46 return f; 47 } 48 49 private boolean isFile() { 50 return path.isFile(); 51 } 52 53 public String toString() { 54 try { 55 return path.getCanonicalPath(); 56 } catch (IOException e) { 57 return path.getAbsolutePath(); 58 } 59 } 60 61 public FileSystemPath existingSubdir(String subdirectoryPath) { 62 return existingDir(path + "/" + subdirectoryPath); 63 } 64 65 public FileSystemPath existingFile(String fileName) { 66 return makeExistingFile(this.path + "/" + fileName); 67 } 68 69 public Deployment warDeployment(String warName) { 70 return new WARDeployment(existingFile(warName)); 71 } 72 73 74 public File getFile() { 75 return path; 76 } 77 78 public FileSystemPath subdir(String subdirectoryPath) { 79 return new FileSystemPath(path + "/" + subdirectoryPath); 80 } 81 82 public void delete() { 83 path.delete(); 84 } 85 86 public FileSystemPath file(String fileName) { 87 return new FileSystemPath((this.path + "/" + fileName)); 88 } 89 90 public FileSystemPath mkdir(String subdir) { 91 return subdir(subdir).mkdir(); 92 } 93 94 private FileSystemPath mkdir() { 95 path.mkdirs(); 96 return this; 97 } 98 99 public static FileSystemPath makeNewFile(String fileName) { 100 return new FileSystemPath(fileName); 101 } 102 103 } 104 | Popular Tags |