source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/runtime/TextRunner.java@ 15210

Last change on this file since 15210 was 15210, checked in by oranfry, 16 years ago

Lots of changes to the installer. Now only look in LanguagePack resource bundle for strings.

File size: 4.2 KB
Line 
1/*
2 * Copyright 2005 Paul Hinds
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.tp23.antinstaller.runtime;
17
18import java.io.BufferedReader;
19import java.io.IOException;
20import java.io.InputStreamReader;
21import java.io.PrintStream;
22import java.util.ResourceBundle;
23
24import org.tp23.antinstaller.InstallException;
25import org.tp23.antinstaller.Installer;
26import org.tp23.antinstaller.InstallerContext;
27import org.tp23.antinstaller.page.Page;
28import org.tp23.antinstaller.page.SimpleInputPage;
29import org.tp23.antinstaller.renderer.AntOutputRenderer;
30import org.tp23.antinstaller.renderer.RendererFactory;
31import org.tp23.antinstaller.renderer.text.AbstractTextPageRenderer;
32import org.tp23.antinstaller.renderer.text.TextMessageRenderer;
33
34
35
36/**
37 *
38 * <p>Runs the installer from the text only command line (console) </p>
39 * <p>This class uses the Installer object tree as its data source and renderers
40 * from the org.tp23.antinstaller.renderer.text package </p>
41 * <p>Copyright (c) 2004</p>
42 * <p>Company: tp23</p>
43 * @author Paul Hinds
44 * @version $Id: TextRunner.java,v 1.10 2007/01/19 00:24:36 teknopaul Exp $
45 */
46public class TextRunner extends AntRunner
47 implements Runner {
48
49 private static final ResourceBundle res = ResourceBundle.getBundle("resources.LanguagePack");
50
51 protected final InstallerContext ctx;
52 protected final Installer installer;
53 private final Logger logger;
54 protected final IfPropertyHelper ifHelper;
55
56 public TextRunner(InstallerContext ctx) throws IOException {
57 super(ctx);
58 this.ctx = ctx;
59 this.installer = ctx.getInstaller();
60 this.logger = ctx.getLogger();
61 ctx.setMessageRenderer(new TextMessageRenderer());
62 ctx.setAntOutputRenderer(new AntOutputRenderer(){
63 public PrintStream getErr() {
64 return System.err;
65 }
66 public PrintStream getOut() {
67 return System.out;
68 }
69
70 });
71 this.ifHelper = new IfPropertyHelper(ctx);
72 }
73
74 /**
75 * Renders the installer on the command line, this method blocks until
76 * the UI has finished
77 * @throws InstallException
78 * @return boolean false implies the install was aborted
79 */
80 public boolean runInstaller() throws InstallException {
81 try {
82 return renderPages(installer.getPages());
83 }
84 catch (Exception ex) {
85 logger.log("FATAL exception during installation:"+ex.getMessage());
86 logger.log(installer, ex);
87
88 ctx.getMessageRenderer().printMessage(res.getString("installationFailed") + ":" + ex.getMessage());
89 //Fixed BUG: ctx.getMessageRenderer().printMessage("Installation failed:"+ex.getMessage());
90 throw new InstallException("Installation failed", ex);
91 }
92 }
93
94
95 private boolean renderPages(Page[] pages) throws ClassNotFoundException, InstallException{
96 Page next = null;
97 for (int i = 0; i < pages.length; i++) {
98 next = pages[i];
99
100 if(next instanceof SimpleInputPage){
101 // skip iftarget specified and missing
102 if(!ifHelper.ifTarget(next, pages))continue;
103 // skip page if ifProperty is specified and property is missing
104 if(!ifHelper.ifProperty(next))continue;
105 }
106
107 AbstractTextPageRenderer renderer = RendererFactory.getTextPageRenderer(next);
108 renderer.setContext(ctx);
109 renderer.init( new BufferedReader(new InputStreamReader(System.in)), System.out);
110 ctx.setCurrentPage(next);
111 renderer.renderPage(next);
112 if (next.isAbort()){
113 return false;
114 }
115 runPost(next);
116 }
117 return true;
118 }
119 public InstallerContext getInstallerContext() {
120 return ctx;
121 }
122
123
124
125 /**
126 * Called when Ant has finished its work
127 */
128 public void antFinished() {
129 System.out.println(res.getString("finished"));
130 //System.exit(0);
131 }
132 /**
133 * Called is Ant failed to install correctly
134 */
135 public void fatalError(){
136 System.out.println(res.getString("failed"));
137 //System.exit(1);
138 }
139
140 public String toString() {
141 return "TextRunner";
142 }
143}
Note: See TracBrowser for help on using the repository browser.