01: /*
02: * Copyright 2005 Paul Hinds
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.runtime.exe;
17:
18: import java.io.File;
19:
20: import org.tp23.antinstaller.InstallerContext;
21: import org.tp23.antinstaller.runtime.SimpleLogger;
22:
23: /**
24: * Creates a suitable logger for the install. The logging does not
25: * throw exceptions since it is mainly for debug and we dont want to
26: * stop an install just because logging is not working
27: * @author Paul Hinds
28: * @version $Id: CreateLoggerFilter.java,v 1.3 2007/01/09 22:41:40 teknopaul Exp $
29: */
30: public class CreateLoggerFilter implements ExecuteFilter {
31:
32: public static final String LOG_FILE_NAME = "ant.install.log";
33:
34: /**
35: */
36: public void exec(InstallerContext ctx) {
37: SimpleLogger logger = new SimpleLogger();
38: ctx.setLogger(logger);
39: try {
40: String defaultName = "./ant.install.log";
41: // @since 0.7.1 RFE-1154368 for installs from CD where ./ is not writable
42: File defaultFile = new File(defaultName);
43: try {
44: if (!defaultFile.exists()) {
45: defaultFile.createNewFile();
46: }
47: } catch (Exception e) {
48: ;// ignore canWrite() will return false
49: }
50: if (defaultFile.canWrite()) {
51: logger.setFileName(defaultName);
52: } else {
53: String tempDir = ctx.getFileRoot().getAbsolutePath();
54: logger.setFileName(tempDir
55: + System.getProperty("file.separator")
56: + LOG_FILE_NAME);
57: }
58: ctx.log("Ant basedir:"
59: + ctx.getFileRoot().getCanonicalPath());
60: } catch (Throwable ex1) {
61: ex1.printStackTrace();
62: logger.close();
63: // swallow exceptions
64: }
65: }
66:
67: }
|