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 | */
|
---|
16 | package org.tp23.antinstaller;
|
---|
17 |
|
---|
18 | import java.io.File;
|
---|
19 | import java.util.Enumeration;
|
---|
20 | import java.util.Iterator;
|
---|
21 | import java.util.Properties;
|
---|
22 | import java.util.Vector;
|
---|
23 |
|
---|
24 | import org.apache.tools.ant.BuildListener;
|
---|
25 | import org.apache.tools.ant.taskdefs.Execute;
|
---|
26 | import org.tp23.antinstaller.page.Page;
|
---|
27 | import org.tp23.antinstaller.renderer.AntOutputRenderer;
|
---|
28 | import org.tp23.antinstaller.renderer.MessageRenderer;
|
---|
29 | import org.tp23.antinstaller.runtime.Logger;
|
---|
30 | import org.tp23.antinstaller.runtime.Runner;
|
---|
31 | import org.tp23.antinstaller.runtime.exe.AntLauncherFilter;
|
---|
32 | import org.tp23.antinstaller.runtime.exe.LoadConfigFilter;
|
---|
33 | /**
|
---|
34 | *
|
---|
35 | * <p>A single InstallerContext is created by the ExecInstall class and
|
---|
36 | * exist for the duration of the Install screens and the runing of
|
---|
37 | * the Ant Script. </p>
|
---|
38 | * @author Paul Hinds
|
---|
39 | * @version $Id: InstallerContext.java,v 1.10 2007/01/28 08:44:41 teknopaul Exp $
|
---|
40 | */
|
---|
41 | public class InstallerContext {
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * This is the prefix for environment variables, unlike Ant this is fixed to
|
---|
45 | * the common prefix of "env". If you dont like this complain to the bug reports
|
---|
46 | * on sourceforge
|
---|
47 | */
|
---|
48 | public static final String ENV_PREFIX = "env.";
|
---|
49 | /**
|
---|
50 | * This is the prefix for Java system property variables.
|
---|
51 | * This is fixed to "java."
|
---|
52 | */
|
---|
53 | public static final String JAVA_PREFIX = "java.";
|
---|
54 |
|
---|
55 | private Logger logger = null;
|
---|
56 | private Installer installer = null;
|
---|
57 | private MessageRenderer messageRenderer = null;
|
---|
58 | private AntOutputRenderer antOutputRenderer = null;
|
---|
59 | private Runner runner = null;
|
---|
60 | private Page currentPage = null;
|
---|
61 | private java.io.File fileRoot = null; // ant basedir
|
---|
62 | private BuildListener buildListener = null;
|
---|
63 | private AntLauncherFilter antRunner = null;
|
---|
64 | private String uIOverride = null;
|
---|
65 | private String installerConfigFile = LoadConfigFilter.INSTALLER_CONFIG_FILE;
|
---|
66 | private String antBuildFile = "build.xml";
|
---|
67 | private String configResource;
|
---|
68 |
|
---|
69 |
|
---|
70 | // called after the Ant part has been run
|
---|
71 | private boolean installedSucceded = false;
|
---|
72 |
|
---|
73 | public InstallerContext() {
|
---|
74 | }
|
---|
75 |
|
---|
76 | public void setInstallSucceded(boolean installedSucceded){
|
---|
77 | this.installedSucceded=installedSucceded;
|
---|
78 | }
|
---|
79 | public boolean isInstallSucceded(){
|
---|
80 | return installedSucceded;
|
---|
81 | }
|
---|
82 |
|
---|
83 | public void log(String message){
|
---|
84 | if(logger != null) {
|
---|
85 | logger.log(message);
|
---|
86 | }
|
---|
87 | }
|
---|
88 | public void log(Throwable message){
|
---|
89 | if(logger != null) {
|
---|
90 | logger.log(message);
|
---|
91 | }
|
---|
92 | }
|
---|
93 | public void log(boolean vebose, Throwable message){
|
---|
94 | if(vebose && logger != null) {
|
---|
95 | logger.log(message);
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Check to see if the system is windoze to be able to return the correct prompted
|
---|
101 | * directories. This method should be IsNotWindows since it assumes anything
|
---|
102 | * that is not windows is Unix
|
---|
103 | * @return boolean true if not windows in the os.name System Property
|
---|
104 | */
|
---|
105 | public static boolean isUnix(){
|
---|
106 | return System.getProperty("os.name").toLowerCase().indexOf("windows") == -1;
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Use the standard Ant way to load the environment variables, this is not all inclusive
|
---|
111 | * (but will be come Java 1.5 I imagine)
|
---|
112 | * @return Properties
|
---|
113 | */
|
---|
114 | public static Properties getEnvironment(){
|
---|
115 | Properties props = new Properties();
|
---|
116 | try {
|
---|
117 | Vector osEnv = Execute.getProcEnvironment();
|
---|
118 | for (Enumeration e = osEnv.elements(); e.hasMoreElements(); ) {
|
---|
119 | String entry = (String) e.nextElement();
|
---|
120 | int pos = entry.indexOf('=');
|
---|
121 | if (pos != -1) {
|
---|
122 | props.put(ENV_PREFIX + entry.substring(0, pos),
|
---|
123 | entry.substring(pos + 1));
|
---|
124 | }
|
---|
125 | }
|
---|
126 | }
|
---|
127 | catch (Exception ex) {
|
---|
128 | // swallow exceptions so this can be loaded statically
|
---|
129 | // bit of a bugger if you need the environment on Mac OS 9 but not all apps
|
---|
130 | // do so we don't want to die inother situations
|
---|
131 | System.out.println("Can't load environment:"+ex.getClass()+","+ex.getMessage());
|
---|
132 | }
|
---|
133 | Properties javaSysProps = System.getProperties();
|
---|
134 | Iterator iter = javaSysProps.keySet().iterator();
|
---|
135 | while (iter.hasNext()) {
|
---|
136 | Object key = (Object)iter.next();
|
---|
137 | props.put(JAVA_PREFIX+key.toString(),javaSysProps.get(key));
|
---|
138 | }
|
---|
139 | return props;
|
---|
140 | }
|
---|
141 |
|
---|
142 | // Bean methods
|
---|
143 | public Installer getInstaller() {
|
---|
144 | return installer;
|
---|
145 | }
|
---|
146 |
|
---|
147 | public String getMinJavaVersion() {
|
---|
148 | return installer.getMinJavaVersion();
|
---|
149 | }
|
---|
150 |
|
---|
151 | public MessageRenderer getMessageRenderer() {
|
---|
152 | return messageRenderer;
|
---|
153 | }
|
---|
154 |
|
---|
155 | public void setMessageRenderer(MessageRenderer messageRenderer) {
|
---|
156 | this.messageRenderer = messageRenderer;
|
---|
157 | this.messageRenderer.setInstallerContext(this);
|
---|
158 | }
|
---|
159 |
|
---|
160 | public AntOutputRenderer getAntOutputRenderer() {
|
---|
161 | return antOutputRenderer;
|
---|
162 | }
|
---|
163 |
|
---|
164 | public void setAntOutputRenderer(AntOutputRenderer antOutputRenderer) {
|
---|
165 | this.antOutputRenderer = antOutputRenderer;
|
---|
166 | }
|
---|
167 |
|
---|
168 | public Page getCurrentPage() {
|
---|
169 | return currentPage;
|
---|
170 | }
|
---|
171 |
|
---|
172 | public void setCurrentPage(Page currentPage) {
|
---|
173 | this.currentPage = currentPage;
|
---|
174 | }
|
---|
175 | /**
|
---|
176 | * in SelfExtractor - the directory the install has extracted to <br/>
|
---|
177 | * in Scripted installs - the base directory of the install <br/>
|
---|
178 | * in NonExtractor - the temporary space created for the build <br/>
|
---|
179 | * @return
|
---|
180 | */
|
---|
181 | public File getFileRoot() {
|
---|
182 | return fileRoot;
|
---|
183 | }
|
---|
184 |
|
---|
185 | public void setFileRoot(File fileRoot) {
|
---|
186 | this.fileRoot = fileRoot;
|
---|
187 | }
|
---|
188 |
|
---|
189 | public org.apache.tools.ant.BuildListener getBuildListener() {
|
---|
190 | return buildListener;
|
---|
191 | }
|
---|
192 |
|
---|
193 | public void setBuildListener(org.apache.tools.ant.BuildListener buildListener) {
|
---|
194 | this.buildListener = buildListener;
|
---|
195 | }
|
---|
196 |
|
---|
197 | public AntLauncherFilter getAntRunner() {
|
---|
198 | return antRunner;
|
---|
199 | }
|
---|
200 |
|
---|
201 | public void setAntRunner(AntLauncherFilter antRunner) {
|
---|
202 | this.antRunner = antRunner;
|
---|
203 | }
|
---|
204 |
|
---|
205 | public Logger getLogger() {
|
---|
206 | return logger;
|
---|
207 | }
|
---|
208 |
|
---|
209 | public void setLogger(Logger logger) {
|
---|
210 | this.logger = logger;
|
---|
211 | }
|
---|
212 |
|
---|
213 | public Runner getRunner() {
|
---|
214 | return runner;
|
---|
215 | }
|
---|
216 |
|
---|
217 | public void setRunner(Runner runner) {
|
---|
218 | this.runner = runner;
|
---|
219 | }
|
---|
220 |
|
---|
221 | public void setInstaller(Installer installer) {
|
---|
222 | this.installer = installer;
|
---|
223 | }
|
---|
224 |
|
---|
225 | public String getUIOverride() {
|
---|
226 | return uIOverride;
|
---|
227 | }
|
---|
228 |
|
---|
229 | public void setUIOverride(String override) {
|
---|
230 | uIOverride = override;
|
---|
231 | }
|
---|
232 |
|
---|
233 | public boolean isAutoBuild(){
|
---|
234 | return uIOverride != null && uIOverride.indexOf("-auto") > -1;
|
---|
235 | }
|
---|
236 |
|
---|
237 | /**
|
---|
238 | * RFE 1569628, the antinstaller config file to use, defaults to antinstall-config.xml
|
---|
239 | * @return
|
---|
240 | */
|
---|
241 | public String getInstallerConfigFile() {
|
---|
242 | return installerConfigFile;
|
---|
243 | }
|
---|
244 |
|
---|
245 | public void setInstallerConfigFile(String installerConfigFile) {
|
---|
246 | this.installerConfigFile = installerConfigFile;
|
---|
247 | }
|
---|
248 | /**
|
---|
249 | * RFE 1569628, the build file to use, defaults to build.xml
|
---|
250 | * There should never be any path info, that is derived elsewhere
|
---|
251 | * @return
|
---|
252 | */
|
---|
253 | public String getAntBuildFile() {
|
---|
254 | return antBuildFile;
|
---|
255 | }
|
---|
256 |
|
---|
257 | public void setAntBuildFile(String antBuildFile) {
|
---|
258 | this.antBuildFile = antBuildFile;
|
---|
259 | }
|
---|
260 |
|
---|
261 | public String getConfigResource() {
|
---|
262 | return configResource;
|
---|
263 | }
|
---|
264 |
|
---|
265 | public void setConfigResource(String configResource) {
|
---|
266 | this.configResource = configResource;
|
---|
267 | }
|
---|
268 | }
|
---|
269 |
|
---|
270 |
|
---|
271 |
|
---|