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: import java.io.IOException;
20:
21: import org.tp23.antinstaller.DefaultPropertiesFileRenderer;
22: import org.tp23.antinstaller.ExplicitPropertiesFileRenderer;
23: import org.tp23.antinstaller.InstallException;
24: import org.tp23.antinstaller.InstallerContext;
25: import org.tp23.antinstaller.PropertiesFileRenderer;
26: import org.tp23.antinstaller.input.ResultContainer;
27:
28: /**
29: * @author Paul Hinds
30: * @version $Id: PropertyPrinterFilter.java,v 1.5 2006/12/28 00:57:53 teknopaul Exp $
31: */
32: public class PropertyPrinterFilter implements ExecuteFilter {
33:
34: /**
35: * @see org.tp23.antinstaller.runtime.exe.ExecuteFilter#exec(org.tp23.antinstaller.InstallerContext)
36: */
37: public void exec(InstallerContext ctx) throws InstallException {
38: ResultContainer results = ctx.getInstaller()
39: .getResultContainer();
40: results.setProperty(PropertiesFileRenderer.FILE_ROOT_PROPERTY,
41: ctx.getFileRoot().getAbsolutePath());
42:
43: printProperties(ctx);
44:
45: if (ctx.getInstaller().isVerbose()) {
46: ctx.log("Properties printed:"
47: + ctx.getFileRoot().getAbsolutePath()
48: + File.separatorChar
49: + PropertiesFileRenderer.PROPERTIES_FILE_NAME);
50: }
51: }
52:
53: /**
54: *
55: * @param installer Installer
56: * @throws IOException
57: */
58: protected void printProperties(InstallerContext ctx) {
59: PropertiesFileRenderer propRenderer;
60: if (ctx.getInstaller().isVerbose()) {
61: propRenderer = new ExplicitPropertiesFileRenderer();
62: } else {
63: propRenderer = new DefaultPropertiesFileRenderer();
64: }
65: // render properties for reuse in auto builds
66: File currentDir = new File(".");
67: ctx.log("auto build supported: "
68: + ctx.getInstaller().supportsAutoBuild());
69: boolean alreadyWritten = false;
70: if (currentDir.canWrite()
71: && ctx.getInstaller().supportsAutoBuild()) {
72: if (ctx.getInstaller().isVerbose()) {
73: try {
74: ctx
75: .log("Rendering properties in the current directory: "
76: + currentDir.getCanonicalPath());
77: } catch (IOException e) {
78: // oh well never mind
79: }
80: }
81: propRenderer.renderProperties(ctx, currentDir);
82: alreadyWritten = true;
83: }
84: if (!currentDir.equals(ctx.getFileRoot()) || !alreadyWritten) {
85: propRenderer.renderProperties(ctx, ctx.getFileRoot());
86: }
87: }
88:
89: }
|