Better, Faster, Freer

The LXR Cross Referencer

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Architecture: i386 ]
Version: HEAD ]

001 /*************************************************************************
002  *
003  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004  * 
005  * Copyright 2008 by Sun Microsystems, Inc.
006  *
007  * OpenOffice.org - a multi-platform office productivity suite
008  *
009  * $RCSfile: ModuleCtrl.java,v $
010  * $Revision: 1.12 $
011  *
012  * This file is part of OpenOffice.org.
013  *
014  * OpenOffice.org is free software: you can redistribute it and/or modify
015  * it under the terms of the GNU Lesser General Public License version 3
016  * only, as published by the Free Software Foundation.
017  *
018  * OpenOffice.org is distributed in the hope that it will be useful,
019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
021  * GNU Lesser General Public License version 3 for more details
022  * (a copy is included in the LICENSE file that accompanied this code).
023  *
024  * You should have received a copy of the GNU Lesser General Public License
025  * version 3 along with OpenOffice.org.  If not, see
026  * <http://www.openoffice.org/license.html>
027  * for a copy of the LGPLv3 License.
028  *
029  ************************************************************************/
030 
031 package org.openoffice.setup.Util;
032 
033 import java.io.File;
034 import java.util.Enumeration;
035 import java.util.Vector;
036 import org.openoffice.setup.InstallData;
037 import org.openoffice.setup.Installer.Installer;
038 import org.openoffice.setup.Installer.InstallerFactory;
039 import org.openoffice.setup.Panel.ChooseDirectory;
040 import org.openoffice.setup.ResourceManager;
041 import org.openoffice.setup.SetupData.PackageDescription;
042 import org.openoffice.setup.SetupData.SetupDataProvider;
043 import org.openoffice.setup.Util.Informer;
044 
045 public class ModuleCtrl {
046     
047     private ModuleCtrl() {
048     }
049     
050     static public void setModuleSize(PackageDescription packageData) {
051         // Setting the package size for visible node modules, that have hidden children
052         // -> Java module has three hidden children and 0 byte size
053 
054         if (( ! packageData.isLeaf() ) && ( ! packageData.isHidden() )) {
055             boolean setNewSize = false;
056             int size = packageData.getSize();
057             
058             for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
059                 PackageDescription child = (PackageDescription) e.nextElement();
060                 // if (( child.isHidden() ) && ( child.getSelectionState() == PackageDescription.DONT_KNOW )) {
061                 if ( child.isHidden() ) {
062                     setNewSize = true;
063                     size = size + child.getSize();
064                 }
065             }
066             
067             if ( setNewSize ) {
068                 packageData.setSize(size);
069             }
070         }
071 
072         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
073             PackageDescription child = (PackageDescription) e.nextElement();
074             setModuleSize(child);
075         }
076 
077     }
078     
079     static public void setDefaultModuleSettings(PackageDescription data) {
080         // Setting default module settings for modules, that are not hidden
081         // Hidden modules do not get a defined state now
082         boolean isInstalled = false;
083         InstallData installdata = InstallData.getInstance();
084         boolean isUninstall = installdata.isUninstallationMode();
085         
086         if (isUninstall) {
087             isInstalled = true;
088         }
089 
090         if (isUninstall) {
091             if (isInstalled) {
092                 data.setSelectionState(PackageDescription.REMOVE);
093             } else {
094                 data.setSelectionState(PackageDescription.IGNORE);
095                 System.err.println("NEVER");
096             }
097         } else {
098             if (isInstalled) {
099                 data.setSelectionState(PackageDescription.IGNORE);
100                 System.err.println("NEVER");
101             } else if (data.isDefault()) {
102                 data.setSelectionState(PackageDescription.INSTALL);
103             } else if ( ! data.isDefault()) {                
104                 data.setSelectionState(PackageDescription.DONT_INSTALL);
105             } else {
106                 data.setSelectionState(PackageDescription.DONT_INSTALL);
107             }
108         }
109     }
110     
111     static public void setParentDefaultModuleSettings(PackageDescription packageData) {
112         // Setting the module states of parent modules.
113         // Called after ChooseDirectoryCtrl.java, because
114         // the database has to be known. In user installation it is important, 
115         // that the installation directory is known, to find the database.
116         // Called during uninstallation in UninstallationPrologueCtrl.java
117 
118         // Iteration before setting the module states. Because of this, all children
119         // get their final setting before the parent.
120         
121         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
122             PackageDescription child = (PackageDescription) e.nextElement();
123             setParentDefaultModuleSettings(child);
124         }
125 
126         if ( ! packageData.isLeaf() ) {
127             // System.err.println("setParentDefaultModuleSettings: " + packageData.getName());
128             int state = packageData.getSelectionState();
129             InstallData installdata = InstallData.getInstance();
130             boolean allChildrenIgnored = true;
131             boolean atLeastOneInstalled = false;
132             boolean allChildrenHidden = true;
133 
134             // System.err.println("    STATE before iterating over children: " + state);
135 
136             for (Enumeration e = packageData.children(); e.hasMoreElements();) {            
137                 PackageDescription child = (PackageDescription) e.nextElement();
138                 int childState = child.getSelectionState();
139 
140                 // System.err.println("    Child: " + child.getName() + " : " + childState);
141                 
142                 if ( childState != PackageDescription.IGNORE) {
143                     allChildrenIgnored = false;
144                 }
145 
146                 if (( childState == PackageDescription.INSTALL) || ( childState == PackageDescription.INSTALL_SOME)) {
147                     atLeastOneInstalled = true;
148                 }
149 
150                 if ( ! child.isHidden() ) {
151                     allChildrenHidden = false;
152                 }
153                 
154                 if ((state == PackageDescription.DONT_KNOW) || (state == PackageDescription.IGNORE)) {
155                     state = childState;          
156                 // } else if ((state != childState) && (childState != PackageDescription.IGNORE)) {
157                 } else if ((state != childState) && (childState != PackageDescription.IGNORE) && (childState != PackageDescription.DONT_KNOW)) {
158                     if ( installdata.isUninstallationMode() ) {
159                         state = PackageDescription.REMOVE_SOME;
160                     } else {
161                         state = PackageDescription.INSTALL_SOME;
162                     }
163                 }
164                 
165                 // System.err.println("    NEW state after child: " + state);
166             }
167 
168             if ( allChildrenIgnored ) {
169                 state = PackageDescription.IGNORE;
170             }
171             
172             if ( installdata.isInstallationMode() ) {
173                 if (( state == PackageDescription.INSTALL_SOME ) && ( ! atLeastOneInstalled )) {
174                     state = PackageDescription.DONT_INSTALL;
175                 }
176             }
177 
178             if ( allChildrenHidden ) {
179                 packageData.setAllChildrenHidden(true);
180                 // System.err.println("Setting allChildrenHidden for module " + packageData.getName() );
181             }
182 
183             // System.err.println("Setting " + packageData.getName() + " to " + packageData.getSelectionState() );
184             packageData.setSelectionState(state);
185         }
186         
187     }
188 
189     static public void setHiddenModuleSettingsInstall(PackageDescription packageData) {
190         // update selection states for hidden modules during installation
191         if (( packageData.isHidden() ) && ( packageData.getSelectionState() != packageData.IGNORE )) {
192             PackageDescription parent = (PackageDescription)packageData.getParent();
193             if ( parent != null ) {
194                 packageData.setSelectionState(parent.getSelectionState());
195                 // hidden modules at root module always have to be installed, if they are not already installed
196                 if ( parent.getName() == "" ) {
197                     packageData.setSelectionState(packageData.INSTALL);
198                     // System.err.println("Setting 1 INSTALL flag to: " + packageData.getName());
199                 }
200             }
201             
202             // INSTALL_SOME is not valid for leaves
203             if (( packageData.getSelectionState() == packageData.INSTALL_SOME ) && ( packageData.isLeaf() )) {
204                 packageData.setSelectionState(packageData.INSTALL);
205                 // System.err.println("Setting 2 INSTALL flag to: " + packageData.getName());
206             }
207         }
208         
209         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
210             PackageDescription child = (PackageDescription) e.nextElement();
211             setHiddenModuleSettingsInstall(child);
212         }
213     }
214 
215     static public void setHiddenModuleSettingsUninstall(PackageDescription packageData) {
216         InstallData data = InstallData.getInstance();            
217         // update selection states for hidden modules during uninstallation
218         if (( packageData.isHidden() ) && ( packageData.getSelectionState() != packageData.IGNORE )) {
219             // System.err.println("Package name: " + packageData.getName());
220             // System.err.println("Selection: " + packageData.getSelectionState());
221             
222             PackageDescription parent = (PackageDescription)packageData.getParent();
223             if ( parent != null ) {
224                 packageData.setSelectionState(parent.getSelectionState());
225                 // Hidden modules at root module have to be uninstalled at complete uninstallation
226                 // In Uninstallation the complete is the typical installation type
227                 if (( parent.getName() == "" ) && ( data.isTypicalInstallation() ))  {
228                     packageData.setSelectionState(packageData.REMOVE);                    
229                 }
230                 // Hidden modules at root module must not be uninstalled at custom uninstallation
231                 // But if all visible modules are selected for uninstallation, this shall be handled
232                 // as complete uninstallation.
233                 if ( ! data.isMaskedCompleteUninstallation() )
234                 {
235                     if (( parent.getName() == "" ) && ( data.isCustomInstallation() ))  {
236                         packageData.setSelectionState(packageData.IGNORE);
237                     }
238                 }
239             }
240             
241             // REMOVE_SOME is not valid for leaves
242             // if ( data.isTypicalInstallation() ) {
243             if (( packageData.getSelectionState() == packageData.REMOVE_SOME ) && ( packageData.isLeaf() )) {
244                 packageData.setSelectionState(packageData.REMOVE);
245             }
246             // }
247 
248         }
249         
250         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
251             PackageDescription child = (PackageDescription) e.nextElement();
252             setHiddenModuleSettingsUninstall(child);
253         }
254     }
255 
256     static private boolean checkRequiredCoreModule(PackageDescription packageData) {
257 
258         // This function uses a similar mechanism to determine 
259         // core modules as function "setHiddenModuleSettingsInstall"
260         // -> only hidden parents, until there is a module without name (getName)
261         // Only searching until grandpa.
262 
263         boolean requiredCoreModule = false;
264 
265         // if packageData.getSelectionState() DONT_KNOW  && parent auch DONT_KNOW
266         if (( packageData.isHidden() ) &&
267                 ( packageData.getSelectionState() != packageData.IGNORE ) &&
268                 ( packageData.getPackageName() != null )) {
269                 //( packageData.isLeaf() )) {
270             PackageDescription parent = (PackageDescription)packageData.getParent();
271             if ( parent != null ) {
272                 if (( parent.getName().equals("") ) || ( parent.getName() == null )) {
273                     requiredCoreModule = true;
274                 } else {
275                     if ( parent.isHidden() ) {
276                         PackageDescription grandpa = (PackageDescription)parent.getParent();
277                         if ( grandpa != null ) {
278                             if (( grandpa.getName().equals("") ) || ( grandpa.getName() == null )) {
279                                 requiredCoreModule = true;
280                             }                            
281                         }
282                     }
283                 }
284             }
285         }
286         
287         return requiredCoreModule;
288     }
289     
290     static public void setDatabaseSettings(PackageDescription packageData, InstallData installData, Installer installer) {
291         // Analyzing the system database and setting the module states.
292         // Called during installation in ChooseInstallationTypeCtrl.java, because
293         // the database has to be known. In user installation it is important, 
294         // the the installation directory is known, to find the database.
295         // Called during uninstallation in UninstallationPrologueCtrl.java
296 
297         boolean isUninstall = installData.isUninstallationMode();
298         boolean isInstalled = installer.isPackageInstalled(packageData, installData);
299                         
300         if (isUninstall) {
301             if (isInstalled) {
302                 packageData.setSelectionState(PackageDescription.REMOVE);
303                 // The following is no longer required !? (IS, 06/05/08)
304                 // PackageDescription parent = packageData.getParent();
305                 // if ( parent != null ) {
306                 //     if ( parent.getSelectionState() != PackageDescription.REMOVE ) {
307                 //         parent.setSelectionState(PackageDescription.REMOVE);
308                 //         System.err.println("Setting remove to " +  parent.getName());
309                 //     }
310                 // }
311             } else {
312                 // Attention: Setting all nodes to ignore! If a children gets REMOVE,
313                 // then REMOVE is also set to the parent. Setting REMOVE happens after
314                 // setting IGNORE, because children are evaluated after the parents.
315                 // The default for uninstallation is set in setDefaultModuleSettings to REMOVE.
316                 packageData.setSelectionState(PackageDescription.IGNORE);
317             }
318         } else {
319             boolean goodDepends = true;            
320             if ( installData.getOSType().equalsIgnoreCase("SunOS") ) {
321                 if (( packageData.getCheckSolaris() != null ) && ( ! packageData.getCheckSolaris().equals("") )) {
322                     // the package has to be installed. Creating a new package with only packagename
323                     if ( ! installer.isPackageNameInstalled(packageData.getCheckSolaris(), installData) ) {
324                         goodDepends = false; 
325                     }
326                 }
327             }
328             
329             if ( ! goodDepends ) {
330                 // The package dependencies are not valid -> ignoring package.
331                 packageData.setSelectionState(PackageDescription.IGNORE);
332                 // too late to hide the module
333                 // packageData.setIsHidden(true);
334             }
335             else {
336                 if ( isInstalled ) {
337                     if ( packageData.isJavaPackage() ) {   // only selected checks, because of performance reasons
338                         boolean installedPackageIsOlder = installer.isInstalledPackageOlder(packageData, installData);
339                         if ( ! installedPackageIsOlder ) {
340                             // The package is already installed in the same or in a newer version
341                             packageData.setSelectionState(PackageDescription.IGNORE);
342                         } else {
343                             // This is also something like migrating feature states
344                             packageData.setSelectionState(PackageDescription.INSTALL); 
345                         }
346                     } else {  // no version check done -> so what is a good setting for already installed packages?
347                         if ( installData.olderVersionExists() ) {  // should never be the case in this function
348                             packageData.setSelectionState(PackageDescription.INSTALL);                          
349                         } else {
350                             packageData.setSelectionState(PackageDescription.IGNORE);                           
351                         }   
352                     }
353                 }
354                 else {
355                     // Special handling for core modules, which are required, but not installed.
356                     // This can be deinstalled by hand for example.
357                     boolean isRequiredCoreModule = checkRequiredCoreModule(packageData);
358                     if ( isRequiredCoreModule ) {
359                         if ( packageData.getSelectionState() != PackageDescription.INSTALL ) {
360                             packageData.setSelectionState(PackageDescription.INSTALL);
361                             LogManager.addLogfileComment("<b>Adding required package:</b> " + packageData.getPackageName() + "</br>");
362                         }
363                         // This package has to exist!
364                         if ( ! packageExists(packageData, installData) ) {
365 
366                             String packagePath = installData.getPackagePath();
367                             if (( packageData.getPkgSubdir() != null ) && ( ! packageData.getPkgSubdir().equals("") )) {
368                                 File completePackageFile = new File(packagePath, packageData.getPkgSubdir());
369                                 packagePath = completePackageFile.getPath();
370                             }
371                             String packageName = packageData.getPackageName();
372                             File packageFile = new File(packagePath, packageName);
373 
374                             String log = "<b>Error: Missing required package " + packageFile.getPath() + "</b><br>";
375                             System.err.println(log);
376                             String message = ResourceManager.getString("String_File_Not_Found") + ": " + packageFile.getPath();
377                             String title = ResourceManager.getString("String_Error");
378                             Informer.showErrorMessage(message, title);
379                             System.exit(1);
380                         }
381                     }
382                 }
383             }        
384         }      
385 
386         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
387             PackageDescription child = (PackageDescription) e.nextElement();
388             setDatabaseSettings(child, installData, installer);
389         }        
390     }
391 
392     static public void setShowInUserInstallFlags(PackageDescription packageData) {
393 
394         // This function is not needed during deinstallation, because a
395         // module that could not be selected during installation, is always 
396         // not installed during deinstallation and therefore gets "IGNORE"
397         // in function setDatabaseSettings
398         
399         if ( ! packageData.showInUserInstall() ) {
400             packageData.setSelectionState(PackageDescription.IGNORE);
401             // too late to hide the module
402             // packageData.setIsHidden(true);
403             // packageData.setAllChildrenHidden(true);
404         }
405 
406         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
407             PackageDescription child = (PackageDescription) e.nextElement();
408             setShowInUserInstallFlags(child);
409         }
410     }
411 
412     static public void setShowInUserInstallOnlyFlags(PackageDescription packageData) {
413 
414         // This function is not needed during deinstallation, because a
415         // module that could not be selected during installation, is always 
416         // not installed during deinstallation and therefore gets "IGNORE"
417         // in function setDatabaseSettings
418         
419         if ( packageData.showInUserInstallOnly() ) {
420             packageData.setSelectionState(PackageDescription.IGNORE);
421             // too late to hide the module
422             // packageData.setIsHidden(true);
423             // packageData.setAllChildrenHidden(true);
424         }
425 
426         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
427             PackageDescription child = (PackageDescription) e.nextElement();
428             setShowInUserInstallOnlyFlags(child);
429         }
430     }
431 
432     static public void setIgnoreNonRelocatablePackages(PackageDescription packageData) {
433         if ( ! packageData.isRelocatable() ) {
434             packageData.setSelectionState(PackageDescription.IGNORE);
435             System.err.println("Ignoring package " + packageData.getName() + " " + packageData.getPackageName());
436         }
437 
438         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
439             PackageDescription child = (PackageDescription) e.nextElement();
440             setIgnoreNonRelocatablePackages(child);
441         }
442     }
443 
444     static public void setHiddenLanguageModuleDefaultSettings(PackageDescription packageData) {
445 
446         // This function is needed during installation for the language modules,
447         // if there is only one language in the installation set. In this case the language
448         // modules are hidden (no selection possible) and therefore get no value in 
449         // setDefaultModuleSettings(). This default value is set now. 
450 
451         if ( packageData.showMultiLingualOnly() ) {
452             packageData.setSelectionState(PackageDescription.INSTALL);
453         }
454         
455         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
456             PackageDescription child = (PackageDescription) e.nextElement();
457             setHiddenLanguageModuleDefaultSettings(child);
458         }       
459     }
460 
461     static private boolean packageExists(PackageDescription packageData, InstallData installData) {
462         boolean fileExists = false;
463         String packagePath = installData.getPackagePath();
464 
465         if (( packageData.getPkgSubdir() != null ) && ( ! packageData.getPkgSubdir().equals("") )) {
466             File completePackageFile = new File(packagePath, packageData.getPkgSubdir());
467             packagePath = completePackageFile.getPath();
468         }
469 
470         String packageName = packageData.getPackageName();
471         File packageFile = new File(packagePath, packageName);
472 
473         if ( packageFile.exists() ) {
474             fileExists = true;
475         }
476 
477         return fileExists;
478     }
479 
480     static public void disableNonExistingPackages(PackageDescription packageData, InstallData installData) {
481         if ((( packageData.getPackageName() == null ) || ( packageData.getPackageName().equals("") )) 
482                && packageData.isLeaf() ) {
483             packageData.setSelectionState(PackageDescription.IGNORE);                        
484         } else if ( ! packageExists(packageData, installData) ) {
485             packageData.setSelectionState(PackageDescription.IGNORE);            
486         }
487 
488         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
489             PackageDescription child = (PackageDescription) e.nextElement();
490             disableNonExistingPackages(child, installData);
491         }
492     }
493 
494     static public void setDontUninstallFlags(PackageDescription packageData) {
495         if ( packageData.dontUninstall() ) {
496             packageData.setSelectionState(PackageDescription.IGNORE);
497         }
498 
499         for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
500             PackageDescription child = (PackageDescription) e.nextElement();
501             setDontUninstallFlags(child);
502         }
503     
504     }
505     
506     static public void checkVisibleModulesInstall(PackageDescription packageData, InstallData data) {        
507         boolean setToTrue = false;        
508 
509         if (( ! packageData.isHidden() ) && ( packageData.getSelectionState() == packageData.INSTALL )) {
510             setToTrue = true;
511             data.setVisibleModulesChecked(true);
512         }
513 
514         if ( ! setToTrue ) {
515             for (Enumeration e = packageData.children(); e.hasMoreElements(); ) {
516                 PackageDescription child = (PackageDescription) e.nextElement();
517                 checkVisibleModulesInstall(child, data);
518             }
519         }        
520     }
521 
522     static public void checkApplicationSelection(PackageDescription packageData, InstallData data) {
523         boolean setToTrue = false;        
524 
525         if (( packageData.isApplicationPackage() ) &am