1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package org.openoffice.setup.Util;
25 
26 import org.openoffice.setup.InstallData;
27 import org.openoffice.setup.SetupData.PackageDescription;
28 import java.util.Enumeration;
29 import java.util.Iterator;
30 import java.util.Map;
31 import java.util.Properties;
32 import java.util.Vector;
33 
34 
35 public class Dumper {
36 
Dumper()37     private Dumper() {
38     }
39 
dumpPackageSettings(PackageDescription packageData)40     static public void dumpPackageSettings(PackageDescription packageData) {
41 
42         if ( packageData.isLeaf() ) {
43             System.out.println("Name: " + packageData.getName() +
44                                " State: " + packageData.getSelectionState()  +
45                                " " + packageData.getPackageName());
46         } else {
47             System.out.println("Nod-Name: " + packageData.getName() +
48                                " State: " + packageData.getSelectionState());
49         }
50 
51         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
52             PackageDescription child = (PackageDescription) e.nextElement();
53             dumpPackageSettings(child);
54         }
55 
56     }
57 
dumpModuleStates(PackageDescription packageData)58     static public void dumpModuleStates(PackageDescription packageData) {
59 
60         System.err.println("Name: " + packageData.getName() +
61                            " State: " + packageData.getSelectionState() +
62                            " " + packageData.getPackageName());
63 
64         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
65             PackageDescription child = (PackageDescription) e.nextElement();
66             dumpModuleStates(child);
67         }
68     }
69 
getStateString(int state)70     static private String getStateString(int state) {
71         String stateString = null;
72 
73         if ( state == 0 ) {
74             stateString = "DONT_INSTALL";
75         } else if ( state == 1 ) {
76             stateString = "INSTALL";
77         } else if ( state == 2 ) {
78             stateString = "INSTALL_SOME";
79         } else if ( state == 3 ) {
80             stateString = "REMOVE";
81         } else if ( state == 4 ) {
82             stateString = "DONT_REMOVE";
83         } else if ( state == 5 ) {
84             stateString = "REMOVE_SOME";
85         } else if ( state == 6 ) {
86             stateString = "IGNORE";
87         } else if ( state == 7 ) {
88             stateString = "DONT_KNOW";
89         } else {
90             stateString = null;
91         }
92 
93         return stateString;
94     }
95 
logModuleStatesHelper(PackageDescription packageData)96     static private void logModuleStatesHelper(PackageDescription packageData) {
97         int state = packageData.getSelectionState();
98         String stateStr = getStateString(state);
99 
100         LogManager.addModulesLogfileComment("Name: " + packageData.getName() +
101                            " State: " + stateStr +
102                            " " + packageData.getPackageName());
103 
104         // System.err.println("Name: " + packageData.getName() +
105         //                    " State: " + stateStr +
106         //                    " " + packageData.getPackageName());
107 
108         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
109             PackageDescription child = (PackageDescription) e.nextElement();
110             logModuleStatesHelper(child);
111         }
112     }
113 
logModuleStates(PackageDescription packageData, String text)114     static public void logModuleStates(PackageDescription packageData, String text) {
115         LogManager.setModulesLogFileHeaderLine(text);
116         logModuleStatesHelper(packageData);
117     }
118 
logPackagesToInstall(Vector packages, String text)119     static public void logPackagesToInstall(Vector packages, String text) {
120         PackageDescription packageData = null;
121         LogManager.setModulesLogFileHeaderLine(text);
122         for (int i = 0; i < packages.size(); i++) {
123             packageData = (PackageDescription)packages.get(i);
124             LogManager.addModulesLogfileComment("Name: " + packageData.getName() +
125                                                 " " + packageData.getPackageName());
126         }
127     }
128 
dumpInstallPackages(PackageDescription packageData)129     static public void dumpInstallPackages(PackageDescription packageData) {
130 
131         if (( packageData.isLeaf() ) && ( packageData.getSelectionState() == packageData.INSTALL )) {
132             System.out.println("Now installing: " + packageData.getPackageName());
133         }
134 
135         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
136             PackageDescription child = (PackageDescription) e.nextElement();
137             dumpInstallPackages(child);
138         }
139     }
140 
dumpUninstallPackages(PackageDescription packageData)141     static public void dumpUninstallPackages(PackageDescription packageData) {
142 
143         if (( packageData.isLeaf() ) && ( packageData.getSelectionState() == packageData.REMOVE )) {
144             System.out.println("Now uninstalling: " + packageData.getPackageName());
145         }
146 
147         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
148             PackageDescription child = (PackageDescription) e.nextElement();
149             dumpUninstallPackages(child);
150         }
151     }
152 
dumpAllRpmInfo(PackageDescription packageData)153     static public void dumpAllRpmInfo(PackageDescription packageData) {
154 
155         if (( packageData.getPackageName() != null ) && ( ! packageData.getPackageName().equals(""))) {
156             if ( packageData.pkgExists() ) {
157                 System.err.println("RPM data: " + packageData.getPkgRealName() + " : " +
158                                                   packageData.getPkgVersion() + " : " +
159                                                   packageData.getPkgRelease() + " : " +
160                                                   packageData.getPackageName() );
161             }
162         }
163 
164         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
165             PackageDescription child = (PackageDescription) e.nextElement();
166             dumpAllRpmInfo(child);
167         }
168 
169     }
170 
dumpNewInstallData()171     static public void dumpNewInstallData() {
172         InstallData data = InstallData.getInstance();
173         System.err.println("PackagePath: " + data.getPackagePath());
174         System.err.println("AdminFileReloc: " + data.getAdminFileNameReloc());
175         System.err.println("AdminFileRelocNoDepends: " + data.getAdminFileNameRelocNoDepends());
176         System.err.println("AdminFileNoReloc: " + data.getAdminFileNameNoReloc());
177         System.err.println("AdminFileNoRelocNoDepends: " + data.getAdminFileNameNoRelocNoDepends());
178         System.err.println("DatabasePath: " + data.getDatabasePath());
179         System.err.println("InstallDir: " + data.getInstallDir());
180         System.err.println("Original privileges: " + data.getStoredInstallationPrivileges());
181         System.err.println("getuid.so File: " + data.getGetUidPath());
182     }
183 
dumpAllProperties()184     static public void dumpAllProperties() {
185         Properties properties = System.getProperties();
186 
187         int size = properties.size();
188         Iterator m = properties.entrySet().iterator();
189         int counter = 0;
190 
191         while ( m.hasNext() ) {
192             Map.Entry entry = (Map.Entry) m.next();
193             String env = entry.getKey() + "=" + entry.getValue();
194             System.err.println(env);
195         }
196     }
197 
198 }
199