KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > deployer > DeployBuilder


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.common.deployer;
24
25 // Toolbox imports
26
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 // Kelp imports
37
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 // Standard imports
52
import java.awt.Component JavaDoc;
53 import java.awt.Window JavaDoc;
54 import java.io.File JavaDoc;
55 import java.util.StringTokenizer JavaDoc;
56 import java.util.ResourceBundle JavaDoc;
57 import javax.swing.JOptionPane JavaDoc;
58
59 //
60
public class DeployBuilder extends AbstractEchoBuilder {
61     static ResourceBundle JavaDoc res =
62         ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); // nores
63

64     //
65
private OtterNode[] inputNodes = null;
66     private Window JavaDoc owner = null;
67     private boolean doneDialog = false;
68
69     public static void preBuild(Object JavaDoc 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     /**
135      * Make content, policy file, process templates, configure project for
136      * running enhydra and create archive.
137      */

138     public void buildImpl() {
139         Exception JavaDoc ex = null;
140
141         try {
142             echo(new String JavaDoc());
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 JavaDoc e) {
171             ex = e;
172             echo(ex);
173         }
174         refreshProgress(100, new String JavaDoc());
175         if (isDoneDialog()) {
176             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
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     //
195

196     protected void setOwner(Window JavaDoc w) {
197         owner = w;
198     }
199
200     protected Window JavaDoc 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     //
218
//
219

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