KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > event > SummaryLoggerInstallerListener


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2004 Klaus Bartz
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package com.izforge.izpack.event;
23
24 import java.io.File JavaDoc;
25 import java.io.FileOutputStream JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.PrintWriter JavaDoc;
28
29 import com.izforge.izpack.installer.AutomatedInstallData;
30 import com.izforge.izpack.util.AbstractUIProgressHandler;
31 import com.izforge.izpack.util.Debug;
32 import com.izforge.izpack.util.IoHelper;
33 import com.izforge.izpack.util.SummaryProcessor;
34 import com.izforge.izpack.util.VariableSubstitutor;
35
36 /**
37  * Installer listener which writes the summary of all panels into the logfile which is defined by
38  * info.summarylogfilepath. Default is $INSTALL_PATH/Uninstaller/InstallSummary.htm
39  *
40  * @author Klaus Bartz
41  *
42  */

43 public class SummaryLoggerInstallerListener extends SimpleInstallerListener
44 {
45
46     /**
47      * Default constructor.
48      */

49     public SummaryLoggerInstallerListener()
50     {
51         super(false);
52     }
53
54     /*
55      * (non-Javadoc)
56      *
57      * @see com.izforge.izpack.compiler.InstallerListener#afterPacks(com.izforge.izpack.installer.AutomatedInstallData,
58      * com.izforge.izpack.util.AbstractUIProgressHandler)
59      */

60     public void afterPacks(AutomatedInstallData idata, AbstractUIProgressHandler handler)
61             throws Exception JavaDoc
62     {
63         if (!getInstalldata().installSuccess) return;
64         // No logfile at automated installation because panels are not
65
// involved.
66
if (getInstalldata().panels == null || getInstalldata().panels.size() < 1) return;
67         String JavaDoc path = getInstalldata().info.getSummaryLogFilePath();
68         if (path == null) return;
69         VariableSubstitutor vs = new VariableSubstitutor(getInstalldata().getVariables());
70         path = IoHelper.translatePath(path, vs);
71         File JavaDoc parent = new File JavaDoc(path).getParentFile();
72
73         if (!parent.exists())
74         {
75             parent.mkdirs();
76         }
77       
78         String JavaDoc summary = SummaryProcessor.getSummary(getInstalldata());
79         java.io.OutputStream JavaDoc out = new FileOutputStream JavaDoc(path);
80         
81         out.write(summary.getBytes("utf-8"));
82         out.close();
83     }
84
85 }
86
Popular Tags