1 22 package org.jboss.deployment.spi; 23 24 import java.io.File ; 25 import java.io.FileInputStream ; 26 import java.io.FileOutputStream ; 27 import java.io.IOException ; 28 import java.net.InetAddress ; 29 import java.net.UnknownHostException ; 30 31 import javax.enterprise.deploy.shared.ModuleType ; 32 import javax.enterprise.deploy.spi.TargetModuleID ; 33 import javax.enterprise.deploy.spi.exceptions.TargetException ; 34 35 import org.jboss.logging.Logger; 36 37 44 public class LocalhostTarget implements JBossTarget 45 { 46 private static final Logger log = Logger.getLogger(LocalhostTarget.class); 48 49 54 public String getDescription() 55 { 56 return "JBoss localhost deployment target"; 57 } 58 59 64 public String getName() 65 { 66 return "localhost"; 67 } 68 69 72 public String getHostName() 73 { 74 try 75 { 76 return InetAddress.getLocalHost().getHostName(); 77 } 78 catch (UnknownHostException e) 79 { 80 log.error("Cannot obtain localhost", e); 81 return null; 82 } 83 } 84 85 88 public void deploy(TargetModuleID targetModuleID) throws Exception 89 { 90 String deployDir = getDeploydir(); 92 93 FileOutputStream outs = null; 94 FileInputStream ins = null; 95 try 96 { 97 File deployableFile = new File (targetModuleID.getModuleID()); 98 File targetFile = new File (deployDir + "/" + deployableFile.getName()); 99 log.info("Writing deployableFile: " + deployableFile.getAbsolutePath() + " to: " + targetFile.getAbsolutePath()); 100 outs = new FileOutputStream (targetFile); 101 ins = new FileInputStream (deployableFile); 102 JarUtils.copyStream(outs, ins); 103 log.info("Waiting 10 seconds for deploy to finish..."); 104 Thread.sleep(10000); 105 } 106 finally 107 { 108 try 109 { 110 if (outs != null) 111 { 112 outs.close(); 113 } 114 if (ins != null) 115 { 116 ins.close(); 117 } 118 } 119 catch (IOException e) 120 { 121 } 123 } 124 } 125 126 129 public void start(TargetModuleID targetModuleID) throws Exception 130 { 131 } 132 133 136 public void stop(TargetModuleID targetModuleID) throws Exception 137 { 138 } 139 140 143 public void undeploy(TargetModuleID targetModuleID) throws Exception 144 { 145 String deployDir = getDeploydir(); 147 File file = new File (deployDir + "/" + targetModuleID.getModuleID()); 148 file.delete(); 149 } 150 151 154 public TargetModuleID [] getAvailableModules(ModuleType moduleType) throws TargetException 155 { 156 return null; 157 } 158 159 162 private String getDeploydir() 163 { 164 String deployDir = System.getProperty("jboss.deploy.dir"); 166 if (deployDir == null) 167 { 168 String j2eeHome = System.getProperty("J2EE_HOME"); 169 if (j2eeHome == null) 170 throw new RuntimeException ("Cannot obtain system property: jboss.deploy.dir or J2EE_HOME"); 171 deployDir = j2eeHome + "/server/cts/deploy"; 172 } 173 log.info("Using deploy dir: " + deployDir); 174 return deployDir; 175 } 176 } 177 | Popular Tags |