KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > jbuilder > build > DeployBuildTask


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  * Paul Mahar
21  *
22  */

23 package org.enhydra.kelp.jbuilder.build;
24
25 // AddinCore
26
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 // AddinJBuilder
34
import org.enhydra.kelp.jbuilder.node.PrimeProject;
35
36 // JBuilder
37
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 // JDK
44
import java.io.File JavaDoc;
45 import java.util.ArrayList JavaDoc;
46 import java.util.ResourceBundle JavaDoc;
47
48
49 /**
50  * BuildTask implementation for calling XMLC.
51  *
52  */

53 public class DeployBuildTask implements BuildTask, WriteListener {
54
55
56     //
57
static ResourceBundle JavaDoc res =
58         ResourceBundle.getBundle("org.enhydra.kelp.jbuilder.Res"); // nores
59
//
60
public static final Object JavaDoc SHARED_KEY = new Object JavaDoc();
61     //
62
private boolean nodeOnly = true;
63     private BuildProcess buildProcess = null;
64     private ArrayList JavaDoc nodeList = new ArrayList JavaDoc();
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     /**
77      * Copy conf.in to output directory and replace placeholders.
78      */

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         // remove upToDate nodes from vector if not a rebuild.
92
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 JavaDoc());
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     /**
127      * Build messages.
128      *
129      */

130     public void onWrite(WriteEvent e) {
131         if (buildProcess != null) {
132             buildProcess.fireBuildMessage(e.getString(), e.getString());
133         }
134     }
135
136     /**
137      * Collect list of nodes to build.
138      *
139      */

140     public void addNode(OtterTemplateNode n) {
141         nodeList.add(n);
142     }
143
144     /**
145      * Check if node up to date.
146      *
147      */

148     private boolean upToDate(OtterTemplateNode templateNode) {
149         boolean built = false;
150         FileNode fileNode = (FileNode) templateNode.getNativeNode();
151         File JavaDoc outFile = new File JavaDoc(PathUtil.getOutputPath(templateNode));
152
153         if (fileNode.isModified()) {
154             try {
155                 fileNode.save();
156             } catch (Exception JavaDoc 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