1 23 package org.enhydra.kelp.common.deployer; 24 25 import org.enhydra.tool.ToolBoxInfo; 27 import org.enhydra.tool.common.ToolException; 28 import org.enhydra.tool.common.FileUtil; 29 import org.enhydra.tool.common.PathHandle; 30 import org.enhydra.tool.archive.ArchiveException; 31 import org.enhydra.tool.archive.ArchiveTool; 32 import org.enhydra.tool.archive.JarPlan; 33 import org.enhydra.tool.archive.WarPlan; 34 35 import org.enhydra.kelp.KelpInfo; 37 import org.enhydra.kelp.common.AbstractEchoBuilder; 38 import org.enhydra.kelp.common.Constants; 39 import org.enhydra.kelp.common.PathUtil; 40 import org.enhydra.kelp.common.PropUtil; 41 import org.enhydra.kelp.common.Writer; 42 import org.enhydra.kelp.common.node.OtterProject; 43 import org.enhydra.kelp.common.node.OtterNode; 44 import org.enhydra.kelp.common.node.OtterNodeFactory; 45 import org.enhydra.kelp.common.node.OtterTextFileNode; 46 import org.enhydra.kelp.common.node.OtterFolderNode; 47 import org.enhydra.kelp.common.node.OtterTemplateNode; 48 import org.enhydra.kelp.common.event.WriteListener; 49 50 import java.awt.Component ; 52 import java.io.File ; 53 import java.io.FileWriter ; 54 import java.io.PrintWriter ; 55 import java.util.StringTokenizer ; 56 import java.util.ResourceBundle ; 57 import java.util.Properties ; 58 59 public class RunBuilder extends AbstractEchoBuilder { 61 static ResourceBundle res = 62 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); 64 private File startServerDirectory = null; 66 67 75 public static File createPolicyFile(String path) { 76 77 final String POLICY_LINE1 = "grant {"; final String POLICY_LINE2 = 80 "permission java.security.AllPermission;"; final String POLICY_LINE3 = "};"; File in = new File (path); 83 File out = null; 84 85 if (in.exists()) { 86 in.delete(); 87 in = null; 88 } 89 try { 90 out = new File (path); 91 out.getParentFile().mkdirs(); 92 out.createNewFile(); 93 PrintWriter writer = new PrintWriter (new FileWriter (out)); 94 95 writer.println(POLICY_LINE1); 96 writer.println(POLICY_LINE2); 97 writer.println(POLICY_LINE3); 98 writer.flush(); 99 writer.close(); 100 out = null; 101 out = new File (path); 102 } catch (java.io.IOException e) { 103 e.printStackTrace(); 104 } 105 return out; 106 } 107 108 112 public RunBuilder(WriteListener listener) { 113 super(listener); 114 } 115 116 120 public void buildImpl() { 121 PathHandle ph = null; 122 123 if (getProject().isDeployRun()) { 124 echo(new String ()); 125 ph = 126 PathHandle.createPathHandle(getProject().getDeployBootstrapPath()); 127 if (ph.isFile()) { 128 129 if (isFresh()) { 131 if (!ToolBoxInfo.isEnhydra3()) { 132 refreshProgress(25, 133 res.getString("Deploying_policy_file")); 134 echo(res.getString("Deploying_policy_file")); 135 makePolicy(); 136 } 137 } 138 if (isFresh()) { 139 if (getProject().isDeployStartupJava() 140 || getProject().isDeployStartupRun()) { 141 refreshProgress(65, 142 res.getString("Configuring_project")); 143 echo(res.getString("Configuring_project")); 144 makeStartup(); 145 } 146 } 147 } else if (ph.isDirectory()) { 148 149 ph = 151 PathHandle.createPathHandle(getProject().getAutoDeployFilePath()); 152 if (ph.isEmpty()) { 153 echo("No archive to deploy"); 154 } else if (ph.getFile().isFile()) { 155 File out = null; 156 157 out = new File (getProject().getDeployBootstrapPath()); 158 out = new File (out, ph.getFile().getName()); 159 try { 160 FileUtil.copy(ph.getFile(), out); 161 } catch (ToolException e) { 162 echo(e); 163 } 164 } else { 165 echo("Deployment archive not found: " + ph.getPath()); 166 } 167 } 168 } 169 refreshProgress(100, new String ()); 170 } 171 172 176 179 private File createPolicy() { 180 StringBuffer policyPath = new StringBuffer (); 181 File policy = null; 182 183 policyPath.append(PathUtil.getDeployConfPath(getProject())); 184 policyPath.append(File.separator); 185 policyPath.append(Constants.FILE_JAVA_POLICY); 186 policy = 187 RunBuilder.createPolicyFile(policyPath.toString().replace('\\', 188 '/')); 189 return policy; 190 } 191 192 195 private void makePolicy() { 196 197 OtterTextFileNode node = getProject().getFirstPolicy(); 200 201 if (node == null) { 202 File file = null; 203 204 file = createPolicy(); 205 echo(res.getString("Creating_policy_file") 206 + PathHandle.createPathString(file)); 207 } else { 208 File source = null; 209 File dest = null; 210 211 source = new File (node.getFilePath()); 212 dest = new File (PathUtil.getDeployConfPath(getProject()), 213 source.getName()); 214 try { 215 FileUtil.copy(source, dest); 216 } catch (ToolException e) { 217 echo(e); 218 e.printStackTrace(); 219 } 220 } 221 } 222 223 226 private void makeStartup() { 227 if (getProject().isDeployStartupJava()) { 228 OtterNodeFactory factory = null; 229 StartServerGenerator start = null; 230 PathHandle startPath = null; 231 232 factory = getProject().getNodeFactory(); 233 start = new StartServerGenerator(getProject()); 234 try { 235 start.create(); 236 startPath = PathHandle.createPathHandle(start.getFile()); 237 factory.createJavaFileNode(getProject(), startPath.getPath()); 238 echo(res.getString("Creating_startup") + startPath.getPath()); 239 } catch (java.io.IOException e) { 240 echo(e); 241 e.printStackTrace(); 242 } 243 } 244 if (getProject().isDeployStartupRun()) { 245 getProject().configureRunClass(); 246 } 247 } 248 249 } 250 | Popular Tags |