1 19 20 package org.netbeans.modules.j2ee.deployment.execution; 21 22 import junit.framework.*; 23 import org.netbeans.junit.*; 24 import org.netbeans.tests.j2eeserver.devmodule.*; 25 import org.netbeans.modules.j2ee.deployment.impl.*; 26 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 27 import org.openide.filesystems.*; 28 import java.io.*; 29 import java.util.*; 30 31 35 public class ServerExecutorTest extends NbTestCase { 36 37 public ServerExecutorTest(java.lang.String testName) { 38 super(testName); 39 } 40 41 private static ServerExecutorTest instance; 42 private static ServerExecutorTest instance() { 43 if (instance == null) 44 instance = new ServerExecutorTest("testNothing"); 45 return instance; 46 } 47 48 public void testNothing() { 49 } 50 51 static private DeployTarget dt; 52 static private LocalFileSystem wfs; 53 static FileSystem getWorkFileSystem() { 54 if (wfs != null) 55 return wfs; 56 try { 57 File workdir = instance().getWorkDir(); 58 wfs = new LocalFileSystem(); 59 wfs.setRootDirectory(workdir); 60 return wfs; 61 } catch (Exception e) { 62 throw new RuntimeException (e); 63 } 64 } 65 66 public static DeployTarget getDeploymentTarget(ServerString targetServer) { 67 if (dt != null) { 68 dt.setServer(targetServer); 69 return dt; 70 } 71 72 try { 73 FileObject testJar = FileUtil.createData(getWorkFileSystem().getRoot(),"test.jar"); 74 dt = new DeployTarget(new TestJ2eeModule(J2eeModule.EJB, testJar), targetServer); 75 } catch (Exception e) { 76 throw new RuntimeException (e); 77 } 78 return dt; 79 } 80 81 public static class DeployTarget implements DeploymentTarget { 82 J2eeModule j2eeMod; 83 ServerString target; 84 85 86 public DeployTarget(J2eeModule mod, ServerString target) { 87 j2eeMod = mod; 88 this.target = target; 89 } 90 91 public boolean doFastDeploy() { 92 return false; 93 } 94 95 public boolean dontDeploy() { 96 return false; 97 } 98 99 public java.io.File getConfigurationFile() { 100 return null; 101 } 102 103 public org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule getModule() { 104 return j2eeMod; 105 } 106 107 public org.netbeans.modules.j2ee.deployment.impl.ServerString getServer() { 108 return target; 109 } 110 public void setServer(ServerString server) { this.target = server; } 111 112 public TargetModule[] getTargetModules() { 113 TargetModule.List l = readTargetModule(getName()); 114 if (l == null) 115 return new TargetModule[0]; 116 return l.getTargetModules(); 117 } 118 119 public void setTargetModules(TargetModule[] targetModules) { 120 System.out.println("-------------SETTARGETMODULES: name="+getName()+","+Arrays.asList(targetModules)); 121 writeTargetModule(getName(), new TargetModule.List(targetModules)); 122 } 123 124 public void startClient() { 125 } 126 public void startClient(String clientURL) { 127 128 } 129 130 String name; 131 public String getName() { 132 try { 133 if (name == null) { 134 String serverName = this.getServer().getUrl(); 135 serverName = serverName.substring(serverName.lastIndexOf(':')+1); 136 name = serverName + getModule().getArchive().getName(); 137 } 138 } catch(Exception e) { 139 throw new RuntimeException (e); 140 } 141 return name; 142 } 143 144 public String getDeploymentName() { 145 return null; 146 } 147 148 public String getClientUrl(String partUrl) { 149 return null; 150 } 151 152 public org.netbeans.modules.j2ee.deployment.devmodules.api.ModuleChangeReporter getModuleChangeReporter() { 153 return null; 154 } 155 156 public org.netbeans.modules.j2ee.deployment.execution.DeploymentConfigurationProvider getDeploymentConfigurationProvider() { 157 return null; 158 } 159 160 public org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider.ConfigSupport getConfigSupport() { 161 return null; 162 } 163 164 } 165 166 public static boolean writeTargetModule(String destFile, TargetModule.List tml) { 167 FileLock lock = null; 168 Writer writer = null; 169 try { 170 if (tml == null) 171 return true; 172 173 FileObject fo = FileUtil.createData(getWorkFileSystem().getRoot(), destFile+".xml"); 174 lock = fo.lock(); 175 writer = new OutputStreamWriter(fo.getOutputStream(lock)); 176 TargetModuleConverter.create().write(writer, tml); 177 return true; 178 179 } catch(Exception ioe) { 180 throw new RuntimeException (ioe); 181 } 182 finally { 183 try { 184 if (lock != null) lock.releaseLock(); 185 if (writer != null) writer.close(); 186 } catch (Exception e) {} 187 } 188 } 189 190 public static TargetModule.List readTargetModule(String fromFile) { 191 Reader reader = null; 192 try { 193 FileObject dir = getWorkFileSystem().getRoot(); 194 FileObject fo = dir.getFileObject (fromFile, "xml"); 195 if (fo == null) { 196 System.out.println(Thread.currentThread()+ " readTargetModule: Can't get FO for "+fromFile+".xml from "+dir.getPath()); 197 return null; 198 } 199 reader = new InputStreamReader(fo.getInputStream()); 200 return (TargetModule.List) TargetModuleConverter.create().read(reader); 201 } catch(Exception ioe) { 202 throw new RuntimeException (ioe); 203 } finally { 204 try { 205 if (reader != null) reader.close(); 206 } catch (Exception e) {} 207 } 208 } 209 } 210 | Popular Tags |