001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: * Paul Mahar
021: *
022: */
023: package org.enhydra.kelp.common.deployer;
024:
025: // Toolbox imports
026: import org.enhydra.tool.common.PathHandle;
027: import org.enhydra.tool.common.event.ProgressListener;
028:
029: // Kelp imports
030: import org.enhydra.kelp.common.AbstractEchoBuilder;
031: import org.enhydra.kelp.common.event.WriteEvent;
032: import org.enhydra.kelp.common.event.WriteListener;
033: import org.enhydra.kelp.common.node.OtterProject;
034: import org.enhydra.kelp.common.node.OtterNode;
035:
036: // Standard imports
037: import java.awt.Window;
038: import java.util.ResourceBundle;
039: import javax.swing.JOptionPane;
040:
041: //
042: public class DeployBuilder extends AbstractEchoBuilder {
043: static ResourceBundle res = ResourceBundle
044: .getBundle("org.enhydra.kelp.common.Res"); // nores
045:
046: //
047: private OtterNode[] inputNodes = null;
048: private Window owner = null;
049: private boolean doneDialog = false;
050:
051: public static void preBuild(Object source, OtterProject project,
052: WriteListener listener) {
053: PathHandle path = null;
054: WriteEvent event = null;
055:
056: path = PathHandle.createPathHandle(project.getDeployRootPath());
057: if (!path.isDirectory()) {
058: path.getFile().mkdirs();
059: event = new WriteEvent(source, WriteEvent.OUTPUT,
060: "Created directory: " + path.getPath());
061: listener.onWrite(event);
062: }
063: }
064:
065: public DeployBuilder() {
066: super (null);
067: }
068:
069: public DeployBuilder(WriteListener listener) {
070: super (listener);
071: }
072:
073: public DeployBuilder(WriteListener listener, boolean buffer) {
074: super (listener, buffer);
075: }
076:
077: public void setInputNodes(OtterNode[] n) {
078: inputNodes = n;
079: }
080:
081: public OtterNode[] getInputNodes() {
082: return inputNodes;
083: }
084:
085: public void buildInput() {
086: InputBuilder builder = null;
087:
088: builder = new InputBuilder(getWriteListener());
089: if (getInputNodes() != null) {
090: builder.setNodes(getInputNodes());
091: }
092: invoke(builder);
093: }
094:
095: public void buildContent() {
096: ContentBuilder builder = null;
097:
098: builder = new ContentBuilder(getWriteListener());
099: invoke(builder);
100: }
101:
102: public void buildArchives() {
103: ArchiveBuilder builder = null;
104:
105: builder = new ArchiveBuilder(getWriteListener());
106: invoke(builder);
107: }
108:
109: public void buildRun() {
110: RunBuilder builder = null;
111:
112: builder = new RunBuilder(getWriteListener());
113: invoke(builder);
114: }
115:
116: /**
117: * Make content, policy file, process templates, configure project for
118: * running enhydra and create archive.
119: */
120: public void buildImpl() {
121: Exception ex = null;
122:
123: try {
124: echo(new String());
125: refreshProgress(5, res.getString("Deployment_starting"));
126: echo(res.getString("_Deployment_starting"));
127: if (isFresh()) {
128: refreshProgress(5, res.getString("Processing_input"));
129: echo(res.getString("Processing_input"));
130: buildInput();
131: }
132: if (isFresh()) {
133: refreshProgress(30, res.getString("Deploying_content"));
134: echo(res.getString("Deploying_content"));
135: buildContent();
136: }
137: if (isFresh()) {
138: refreshProgress(60, "Creating archives");
139: echo("Creating archives");
140: buildArchives();
141: }
142: if (isFresh()) {
143: if (getProject().isDeployRun()) {
144: refreshProgress(90, "Configuring project run");
145: echo("Configuring project run");
146: buildRun();
147: } else {
148: refreshProgress(90, "");
149: }
150: }
151: echo("--- Kelp Deployer finished --- ");
152: } catch (Exception e) {
153: ex = e;
154: echo(ex);
155: }
156: refreshProgress(100, new String());
157: if (isDoneDialog()) {
158: StringBuffer buf = new StringBuffer();
159:
160: if (ex == null) {
161: buf.append("Deployment Complete");
162: } else {
163: buf.append("Exception during deployment:\n");
164: if (ex.getMessage() == null) {
165: buf.append(ex.toString());
166: } else {
167: buf.append(ex.getMessage());
168: }
169: buf.append("\n");
170: buf.append("See messages for more information.\n");
171: }
172: JOptionPane.showMessageDialog(getOwner(), buf.toString());
173: }
174: }
175:
176: //
177:
178: protected void setOwner(Window w) {
179: owner = w;
180: }
181:
182: protected Window getOwner() {
183: return owner;
184: }
185:
186: protected boolean isDoneDialog() {
187: boolean canDone = doneDialog;
188:
189: if (getOwner() == null) {
190: canDone = false;
191: }
192: return canDone;
193: }
194:
195: protected void setDoneDialog(boolean d) {
196: doneDialog = d;
197: }
198:
199: //
200: //
201:
202: private void invoke(AbstractEchoBuilder builder) {
203: ProgressListener[] pl = getProgressListeners();
204:
205: if (pl != null) {
206: for (int i = 0; i < pl.length; i++) {
207: builder.addProgressListener(pl[i]);
208: }
209: }
210: builder.setProject(getProject());
211: builder.setEcho(isEcho());
212: builder.buildInCurrentThread();
213: if (pl != null) {
214: for (int i = 0; i < pl.length; i++) {
215: builder.removeProgressListener(pl[i]);
216: }
217: }
218: }
219:
220: }
|