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