1 23 package org.enhydra.kelp.jbuilder.build; 24 25 import org.enhydra.kelp.common.PathUtil; 27 import org.enhydra.kelp.common.event.WriteEvent; 28 import org.enhydra.kelp.common.event.WriteListener; 29 import org.enhydra.kelp.common.node.OtterTemplateNode; 30 import org.enhydra.kelp.common.node.OtterProject; 31 import org.enhydra.kelp.common.deployer.DeployBuilder; 32 33 import org.enhydra.kelp.jbuilder.node.PrimeProject; 35 36 import com.borland.primetime.build.BuildTask; 38 import com.borland.primetime.build.BuildProcess; 39 import com.borland.primetime.node.FileNode; 40 import com.borland.primetime.node.Project; 41 import com.borland.jbuilder.node.JBProject; 42 43 import java.io.File ; 45 import java.util.ArrayList ; 46 import java.util.ResourceBundle ; 47 48 49 53 public class DeployBuildTask implements BuildTask, WriteListener { 54 55 56 static ResourceBundle res = 58 ResourceBundle.getBundle("org.enhydra.kelp.jbuilder.Res"); public static final Object SHARED_KEY = new Object (); 61 private boolean nodeOnly = true; 63 private BuildProcess buildProcess = null; 64 private ArrayList nodeList = new ArrayList (); 65 66 public DeployBuildTask() {} 67 68 protected void setNodeOnly(boolean b) { 69 nodeOnly = b; 70 } 71 72 protected boolean isNodeOnly() { 73 return nodeOnly; 74 } 75 76 79 public boolean build(BuildProcess buildProcess, Project project, 80 boolean rebuild) { 81 82 83 this.buildProcess = buildProcess; 84 OtterProject otterProject = 85 new PrimeProject((JBProject) project); 86 int nodeCount = nodeList.size(); 87 int compileCount = nodeCount; 88 OtterTemplateNode current = null; 89 DeployBuilder builder = null; 90 91 if (!rebuild) { 93 for (int i = 0; i < nodeCount; i++) { 94 current = (OtterTemplateNode) nodeList.get(i); 95 if (upToDate(current)) { 96 nodeList.set(i, new Object ()); 97 compileCount--; 98 } 99 } 100 } 101 102 OtterTemplateNode[] nodes = new OtterTemplateNode[compileCount]; 103 104 for (int i = 0; i < nodeCount; i++) { 105 if (nodeList.get(i) instanceof OtterTemplateNode) { 106 nodes[i] = (OtterTemplateNode) nodeList.get(i); 107 } 108 } 109 WriteListener[] w = new WriteListener[1]; 110 111 w[0] = this; 112 if (otterProject.isDeployBuild()&&!(compileCount==0)) { 113 buildProcess.fireBuildStatus(res.getString("Processing_templates_"), 114 true); 115 builder = new DeployBuilder(this, true); 116 builder.setProject(otterProject); 117 if (isNodeOnly()) { 118 builder.setInputNodes(nodes); 119 } 120 builder.setEcho(otterProject.isDeployEcho()); 121 builder.buildInCurrentThread(); 122 } 123 return true; 124 } 125 126 130 public void onWrite(WriteEvent e) { 131 if (buildProcess != null) { 132 buildProcess.fireBuildMessage(e.getString(), e.getString()); 133 } 134 } 135 136 140 public void addNode(OtterTemplateNode n) { 141 nodeList.add(n); 142 } 143 144 148 private boolean upToDate(OtterTemplateNode templateNode) { 149 boolean built = false; 150 FileNode fileNode = (FileNode) templateNode.getNativeNode(); 151 File outFile = new File (PathUtil.getOutputPath(templateNode)); 152 153 if (fileNode.isModified()) { 154 try { 155 fileNode.save(); 156 } catch (Exception e) { 157 e.printStackTrace(); 158 } 159 } else if (!outFile.exists()) {} 160 else if (outFile.lastModified() 161 > fileNode.getUrl().getFileObject().lastModified()) { 162 built = true; 163 } 164 return built; 165 } 166 167 } 168 | Popular Tags |