1 5 package com.tc.test.server.appserver; 6 7 import com.tc.config.Directories; 8 import com.tc.exception.ImplementMe; 9 import com.tc.test.TempDirectoryHelper; 10 import com.tc.test.TestConfigObject; 11 import com.tc.test.server.appserver.jboss4x.JBoss4xAppServerFactory; 12 import com.tc.test.server.appserver.tomcat5x.Tomcat5xAppServerFactory; 13 import com.tc.test.server.appserver.war.War; 14 import com.tc.test.server.appserver.wasce1x.Wasce1xAppServerFactory; 15 import com.tc.test.server.appserver.weblogic8x.Weblogic8xAppServerFactory; 16 import com.tc.test.server.tcconfig.StandardTerracottaAppServerConfig; 17 import com.tc.util.Assert; 18 import com.tc.util.io.FileUtils; 19 20 import java.io.File ; 21 import java.io.IOException ; 22 import java.net.URL ; 23 import java.util.Properties ; 24 25 30 public abstract class NewAppServerFactory { 31 32 public static final String WEBLOGIC = "weblogic"; 33 public static final String JBOSS = "jboss"; 34 public static final String TOMCAT = "tomcat"; 35 public static final String WASCE = "wasce"; 36 37 protected final TestConfigObject config; 38 private boolean licenseIsSet; 39 40 protected NewAppServerFactory(ProtectedKey protectedKey, TestConfigObject config) { 41 Assert.assertNotNull(protectedKey); 42 Assert.assertNotNull(config); 43 copyLicenseIfAvailable(); 44 this.config = config; 45 } 46 47 public abstract AppServerParameters createParameters(String instanceName, Properties props); 48 49 public AppServerParameters createParameters(String instanceName) { 50 return createParameters(instanceName, new Properties ()); 51 } 52 53 public abstract AppServer createAppServer(AppServerInstallation installation); 54 55 public abstract AppServerInstallation createInstallation(URL host, File serverDir, File workingDir) throws Exception ; 56 57 public abstract AppServerInstallation createInstallation(File home, File workingDir) throws Exception ; 58 59 public abstract War createWar(String appName); 60 61 public abstract StandardTerracottaAppServerConfig createTcConfig(File baseDir); 62 63 public static final NewAppServerFactory createFactoryFromProperties(TestConfigObject config) { 64 Assert.assertNotNull(config); 65 String factoryName = config.appserverFactoryName(); 66 String majorVersion = config.appserverMajorVersion(); 67 68 if (TOMCAT.equals(factoryName)) { 69 if ("5".equals(majorVersion)) return new Tomcat5xAppServerFactory(new ProtectedKey(), config); 70 } else if (WEBLOGIC.equals(factoryName)) { 71 if ("8".equals(majorVersion)) return new Weblogic8xAppServerFactory(new ProtectedKey(), config); 72 } else if (WASCE.equals(factoryName)) { 73 if ("1".equals(majorVersion)) return new Wasce1xAppServerFactory(new ProtectedKey(), config); 74 } else if (JBOSS.equals(factoryName)) { 75 if ("4".equals(majorVersion)) return new JBoss4xAppServerFactory(new ProtectedKey(), config); 76 } 77 78 throw new ImplementMe("App server named '" + factoryName + "' with major version " + majorVersion 79 + " is not yet supported."); 80 } 81 82 private final synchronized void copyLicenseIfAvailable() { 83 if (this.licenseIsSet) return; 84 85 try { 86 File licenseFile = new File (Directories.getLicenseLocation(), "license.lic"); 87 88 if (!licenseFile.exists()) { 89 this.licenseIsSet = true; 90 return; 91 } 92 93 TempDirectoryHelper helper = new TempDirectoryHelper(getClass()); 94 File toDir = helper.getDirectory(); 95 File toFile = new File (toDir, licenseFile.getName()); 96 FileUtils.copyFile(licenseFile, toFile); 97 this.licenseIsSet = true; 98 } catch (IOException ioe) { 99 throw new RuntimeException ("Can't set up license file", ioe); 100 } 101 } 102 103 protected static class ProtectedKey { 104 } 106 } 107 | Popular Tags |