KickJava   Java API By Example, From Geeks To Geeks.

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


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.dods.DodsGenerate;
32 import org.enhydra.kelp.common.dods.DodsBuilder;
33 import org.enhydra.kelp.common.dods.GeneralPanel;
34
35 // AddinJBuilder
36
import org.enhydra.kelp.jbuilder.node.PrimeProject;
37
38 // JBuilder
39
import com.borland.primetime.build.BuildTask;
40 import com.borland.primetime.build.BuildProcess;
41 import com.borland.primetime.node.FileNode;
42 import com.borland.primetime.node.Project;
43 import com.borland.jbuilder.node.JBProject;
44
45 // JDK
46
import java.io.File JavaDoc;
47 import java.util.ArrayList JavaDoc;
48 import java.util.ResourceBundle JavaDoc;
49
50
51 /**
52  * BuildTask implementation for calling XMLC.
53  *
54  */

55 public class DodsBuildTask implements BuildTask, WriteListener {
56
57
58     //
59
static ResourceBundle JavaDoc res =
60         ResourceBundle.getBundle("org.enhydra.kelp.jbuilder.Res"); // nores
61
//
62
public static final Object JavaDoc SHARED_KEY = new Object JavaDoc();
63     //
64
private boolean nodeOnly = true;
65     private BuildProcess buildProcess = null;
66     private ArrayList JavaDoc nodeList = new ArrayList JavaDoc();
67
68     public DodsBuildTask() {}
69
70     protected void setNodeOnly(boolean b) {
71         nodeOnly = b;
72     }
73
74     protected boolean isNodeOnly() {
75         return nodeOnly;
76     }
77
78     /**
79      * Copy conf.in to output directory and replace placeholders.
80      */

81     public boolean build(BuildProcess buildProcess, Project project,
82                          boolean rebuild) {
83
84         this.buildProcess = buildProcess;
85         OtterProject otterProject =
86             new PrimeProject((JBProject) project);
87         DodsGenerate generate = null;
88
89         // remove upToDate nodes from vector if not a rebuild.
90
if (!rebuild) {
91               return true;
92         }
93         WriteListener[] w = new WriteListener[1];
94
95         w[0] = this;
96         buildProcess.fireBuildStatus(res.getString("Generating_DODS"), true);
97
98         if (otterProject.isDodsBuild()) {
99
100           DodsBuilder builder = null;
101
102 // builder = new DodsBuilder(getWriteListener());
103
builder = new DodsBuilder(this);
104
105 // builder.addProgressListener(getProgressListeners()[0]);
106

107           builder.setProject(otterProject);
108 // builder.setEcho(otterProject.isDeployEcho());
109
builder.setEcho(true);
110           builder.buildInCurrentThread();
111         }
112         return true;
113     }
114
115     /**
116      * Build messages.
117      *
118      */

119     public void onWrite(WriteEvent e) {
120         if (buildProcess != null) {
121             buildProcess.fireBuildMessage(e.getString(), e.getString());
122         }
123     }
124
125     /**
126      * Collect list of nodes to build.
127      *
128      */

129     public void addNode(OtterTemplateNode n) {
130         nodeList.add(n);
131     }
132
133     /**
134      * Check if node up to date.
135      *
136      */

137     private boolean upToDate(OtterTemplateNode templateNode) {
138         boolean built = false;
139         FileNode fileNode = (FileNode) templateNode.getNativeNode();
140         File JavaDoc outFile = new File JavaDoc(PathUtil.getOutputPath(templateNode));
141
142         if (fileNode.isModified()) {
143             try {
144                 fileNode.save();
145             } catch (Exception JavaDoc e) {
146                 e.printStackTrace();
147             }
148         } else if (!outFile.exists()) {}
149         else if (outFile.lastModified()
150                  > fileNode.getUrl().getFileObject().lastModified()) {
151             built = true;
152         }
153         return built;
154     }
155
156 }
157
Popular Tags