1 4 package com.tc.config; 5 6 import org.apache.commons.lang.StringUtils; 7 8 import java.io.File ; 9 import java.io.FileNotFoundException ; 10 11 16 public class Directories { 17 18 22 public static final String TC_INSTALL_ROOT_PROPERTY_NAME = "tc.install-root"; 23 public static final String TC_INSTALL_ROOT_IGNORE_CHECKS_PROPERTY_NAME = "tc.install-root.ignore-checks"; 24 public static final String TC_LICENSE_LOCATION_PROPERTY_NAME = "tc.license-location"; 25 26 public static File getLicenseLocation() throws FileNotFoundException { 27 String path = System.getProperty(TC_LICENSE_LOCATION_PROPERTY_NAME); 28 if (StringUtils.isBlank(path)) { throw new FileNotFoundException ( 29 "The system property '" 30 + TC_LICENSE_LOCATION_PROPERTY_NAME 31 + "' has not been set. As such, the Terracotta license location directory cannot be located."); } 32 File licenseDir = new File (path).getAbsoluteFile(); 33 if (!licenseDir.exists() || !licenseDir.isDirectory()) { throw new FileNotFoundException ( 34 "The specified Terracotta installation directory, '" 35 + licenseDir 36 + "', located via the value of the system property '" 37 + TC_LICENSE_LOCATION_PROPERTY_NAME 38 + "', does not actually exist."); } 39 return licenseDir; 40 } 41 42 public static File getInstallationRoot() throws FileNotFoundException { 43 String path = System.getProperty(TC_INSTALL_ROOT_PROPERTY_NAME); 44 45 if (StringUtils.isBlank(path)) { 46 throw new FileNotFoundException ( 48 "The system property '" 49 + TC_INSTALL_ROOT_PROPERTY_NAME 50 + "' has not been set. As such, the Terracotta installation directory cannot be located."); 51 } 52 53 File theFile = new File (path).getAbsoluteFile(); 54 55 if (System.getProperty(TC_INSTALL_ROOT_IGNORE_CHECKS_PROPERTY_NAME) == null) { 56 String absolutePath = theFile.getAbsolutePath(); 57 58 if (!theFile.exists()) { 59 throw new FileNotFoundException ("The specified Terracotta installation directory, '" + absolutePath 61 + "', located via the value of the system property '" 62 + TC_INSTALL_ROOT_PROPERTY_NAME + "', does not actually exist."); 63 } 64 65 if (!theFile.isDirectory()) { 66 throw new FileNotFoundException ("The specified Terracotta installation directory, '" + absolutePath 68 + "', located via the value of the system property '" 69 + TC_INSTALL_ROOT_PROPERTY_NAME + "', does not actually exist."); 70 } 71 72 File searchFile = new File (new File (theFile, "lib"), "tc.jar"); 73 74 if (!searchFile.exists() || !searchFile.isFile()) { 75 if (new File (theFile, ".force-is-terracotta-install-dir").exists()) return theFile; 77 else { 78 throw new FileNotFoundException ("The specified Terracotta installation directory, '" + absolutePath 80 + "', located via the value of the system property '" 81 + TC_INSTALL_ROOT_PROPERTY_NAME + "', does not seem to actually " 82 + "be the root of the Terracotta installation. (The required " 83 + "Terracotta JAR file, '" + searchFile.getAbsolutePath() 84 + "', does not exist or is not a file.)"); 85 } 86 } 87 } 88 89 return theFile; 90 } 91 92 } 93 | Popular Tags |