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.common.event.ProgressListener; 31 import org.enhydra.tool.archive.ArchiveException; 32 import org.enhydra.tool.archive.ArchiveTool; 33 import org.enhydra.tool.archive.JarPlan; 34 import org.enhydra.tool.archive.WarPlan; 35 36 import org.enhydra.kelp.KelpInfo; 38 import org.enhydra.kelp.common.AbstractEchoBuilder; 39 import org.enhydra.kelp.common.Constants; 40 import org.enhydra.kelp.common.PathUtil; 41 import org.enhydra.kelp.common.PropUtil; 42 import org.enhydra.kelp.common.event.WriteEvent; 43 import org.enhydra.kelp.common.event.WriteListener; 44 import org.enhydra.kelp.common.node.OtterProject; 45 import org.enhydra.kelp.common.node.OtterNode; 46 import org.enhydra.kelp.common.node.OtterNodeFactory; 47 import org.enhydra.kelp.common.node.OtterTextFileNode; 48 import org.enhydra.kelp.common.node.OtterFolderNode; 49 import org.enhydra.kelp.common.node.OtterTemplateNode; 50 51 import java.awt.Component ; 53 import java.awt.Window ; 54 import java.io.File ; 55 import java.util.StringTokenizer ; 56 import java.util.ResourceBundle ; 57 import javax.swing.JOptionPane ; 58 59 public class DeployBuilder extends AbstractEchoBuilder { 61 static ResourceBundle res = 62 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); 64 private OtterNode[] inputNodes = null; 66 private Window owner = null; 67 private boolean doneDialog = false; 68 69 public static void preBuild(Object source, OtterProject project, 70 WriteListener listener) { 71 PathHandle path = null; 72 WriteEvent event = null; 73 74 path = PathHandle.createPathHandle(project.getDeployRootPath()); 75 if (!path.isDirectory()) { 76 path.getFile().mkdirs(); 77 event = new WriteEvent(source, WriteEvent.OUTPUT, 78 "Created directory: " + path.getPath()); 79 listener.onWrite(event); 80 } 81 } 82 83 public DeployBuilder() { 84 super(null); 85 } 86 87 public DeployBuilder(WriteListener listener) { 88 super(listener); 89 } 90 91 public DeployBuilder(WriteListener listener, boolean buffer) { 92 super(listener, buffer); 93 } 94 95 public void setInputNodes(OtterNode[] n) { 96 inputNodes = n; 97 } 98 99 public OtterNode[] getInputNodes() { 100 return inputNodes; 101 } 102 103 public void buildInput() { 104 InputBuilder builder = null; 105 106 builder = new InputBuilder(getWriteListener()); 107 if (getInputNodes() != null) { 108 builder.setNodes(getInputNodes()); 109 } 110 invoke(builder); 111 } 112 113 public void buildContent() { 114 ContentBuilder builder = null; 115 116 builder = new ContentBuilder(getWriteListener()); 117 invoke(builder); 118 } 119 120 public void buildArchives() { 121 ArchiveBuilder builder = null; 122 123 builder = new ArchiveBuilder(getWriteListener()); 124 invoke(builder); 125 } 126 127 public void buildRun() { 128 RunBuilder builder = null; 129 130 builder = new RunBuilder(getWriteListener()); 131 invoke(builder); 132 } 133 134 138 public void buildImpl() { 139 Exception ex = null; 140 141 try { 142 echo(new String ()); 143 refreshProgress(5, res.getString("Deployment_starting")); 144 echo(res.getString("_Deployment_starting")); 145 if (isFresh()) { 146 refreshProgress(5, res.getString("Processing_input")); 147 echo(res.getString("Processing_input")); 148 buildInput(); 149 } 150 if (isFresh()) { 151 refreshProgress(30, res.getString("Deploying_content")); 152 echo(res.getString("Deploying_content")); 153 buildContent(); 154 } 155 if (isFresh()) { 156 refreshProgress(60, "Creating archives"); 157 echo("Creating archives"); 158 buildArchives(); 159 } 160 if (isFresh()) { 161 if (getProject().isDeployRun()) { 162 refreshProgress(90, "Configuring project run"); 163 echo("Configuring project run"); 164 buildRun(); 165 } else { 166 refreshProgress(90, ""); 167 } 168 } 169 echo("--- Kelp Deployer finished --- "); 170 } catch (Exception e) { 171 ex = e; 172 echo(ex); 173 } 174 refreshProgress(100, new String ()); 175 if (isDoneDialog()) { 176 StringBuffer buf = new StringBuffer (); 177 178 if (ex == null) { 179 buf.append("Deployment Complete"); 180 } else { 181 buf.append("Exception during deployment:\n"); 182 if (ex.getMessage() == null) { 183 buf.append(ex.toString()); 184 } else { 185 buf.append(ex.getMessage()); 186 } 187 buf.append("\n"); 188 buf.append("See messages for more information.\n"); 189 } 190 JOptionPane.showMessageDialog(getOwner(), buf.toString()); 191 } 192 } 193 194 196 protected void setOwner(Window w) { 197 owner = w; 198 } 199 200 protected Window getOwner() { 201 return owner; 202 } 203 204 protected boolean isDoneDialog() { 205 boolean canDone = doneDialog; 206 207 if (getOwner() == null) { 208 canDone = false; 209 } 210 return canDone; 211 } 212 213 protected void setDoneDialog(boolean d) { 214 doneDialog = d; 215 } 216 217 220 private void invoke(AbstractEchoBuilder builder) { 221 ProgressListener[] pl = getProgressListeners(); 222 223 if (pl != null) { 224 for (int i = 0; i < pl.length; i++) { 225 builder.addProgressListener(pl[i]); 226 } 227 } 228 builder.setProject(getProject()); 229 builder.setEcho(isEcho()); 230 builder.buildInCurrentThread(); 231 if (pl != null) { 232 for (int i = 0; i < pl.length; i++) { 233 builder.removeProgressListener(pl[i]); 234 } 235 } 236 } 237 238 } 239 | Popular Tags |