1 22 package org.enhydra.kelp.jbuilder.build; 23 24 import com.borland.primetime.build.BuildTask; 26 import com.borland.primetime.build.BuildProcess; 27 import com.borland.primetime.node.Project; 28 import com.borland.primetime.node.TextFileNode; 29 import com.borland.jbuilder.node.JBProject; 30 31 import org.enhydra.kelp.common.event.WriteEvent; 33 import org.enhydra.kelp.common.event.WriteListener; 34 import org.enhydra.kelp.common.node.OtterXMLCNode; 35 import org.enhydra.kelp.common.node.OtterProject; 36 import org.enhydra.kelp.common.xmlc.XMLCNodeBuilder; 37 import org.enhydra.kelp.jbuilder.node.PrimeProject; 38 39 import java.util.Vector ; 41 import java.util.ResourceBundle ; 42 43 44 48 public class XMLCBuildTask implements BuildTask, WriteListener { 49 50 51 static ResourceBundle res = 52 ResourceBundle.getBundle("org.enhydra.kelp.jbuilder.Res"); public static final Object SHARED_KEY = new Object (); 54 private BuildProcess buildProcess; 55 private Vector nodeVector = new Vector (); 56 private Vector writeListeners = new Vector (); 57 private XMLCNodeBuilder nodeBuilder; 58 private int messageCount = 0; 59 private int allNodeCount = 0; 60 61 65 public XMLCBuildTask() {} 66 67 public void increment() { 68 allNodeCount++; 69 } 70 71 74 public boolean build(BuildProcess buildProcess, Project project, 75 boolean rebuild) { 76 77 78 this.buildProcess = buildProcess; 79 OtterProject otterProject = new PrimeProject((JBProject) project); 80 int nodeCount = nodeVector.size(); 81 int compileCount = nodeCount; 82 OtterXMLCNode current = null; 83 84 85 if ((allNodeCount < 3) || otterProject.isXMLCBuild()) { 86 87 } else { 89 nodeVector.clear(); 90 nodeCount = 0; 91 compileCount = 0; 92 } 93 94 95 if (!rebuild) { 97 for (int i = 0; i < nodeCount; i++) { 98 current = (OtterXMLCNode) nodeVector.elementAt(i); 99 if (upToDate(current)) { 100 nodeVector.setElementAt(new Object (), i); 101 compileCount--; 102 } 103 } 104 } 105 OtterXMLCNode[] nodes = new OtterXMLCNode[compileCount]; 106 107 compileCount = 0; 108 for (int i = 0; i < nodeCount; i++) { 109 if (nodeVector.elementAt(i) instanceof OtterXMLCNode) { 110 if (compileCount < nodes.length) { 111 nodes[compileCount] = 112 (OtterXMLCNode) nodeVector.elementAt(i); 113 compileCount++; 114 } 115 } 116 } 117 WriteListener[] w = new WriteListener[1]; 118 boolean recomp = false; 119 120 w[0] = this; 121 buildProcess.fireBuildStatus(res.getString("Generating_DOM"), true); 122 nodeBuilder = new XMLCNodeBuilder(this, true); 123 nodeBuilder.setProject(otterProject); 124 nodeBuilder.setNodes(nodes); 125 nodeBuilder.setEcho(false); 126 nodeBuilder.buildInCurrentThread(); 127 for (int i = 0; i < nodes.length; i++) { 128 recomp = nodes[i].getMetaDataHandler().getRecompilation(); 129 nodes[i].replaceGeneratedSource(recomp); 130 } 131 return true; 132 } 133 134 138 public void onWrite(WriteEvent e) { 139 if (buildProcess != null && messageCount < 200) { 140 buildProcess.fireBuildMessage(e.getString(), e.getString()); 141 messageCount++; 142 if (messageCount == 200) { 143 String message = res.getString("Reached_maximum_XMLC"); 144 145 buildProcess.fireBuildMessage(message, message); 146 } 147 } 148 } 149 150 154 public void addNode(OtterXMLCNode n) { 155 nodeVector.addElement(n); 156 } 157 158 162 private boolean upToDate(OtterXMLCNode xmlcNode) { 163 boolean built = false; 164 TextFileNode docNode = null; 165 166 docNode = (TextFileNode) xmlcNode.getNativeNode(); 167 if (docNode.isModified()) { 168 try { 169 docNode.save(); 170 } catch (Exception e) { 171 e.printStackTrace(); 172 } 173 } else if (!xmlcNode.getClassFile().exists()) {} 174 else if (xmlcNode.getClassFile().lastModified() 175 > docNode.getUrl().getFileObject().lastModified()) { 176 built = true; 177 } 178 return built; 179 } 180 181 } 182 | Popular Tags |