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.Installer.Installer; 28 import org.openoffice.setup.Installer.InstallerFactory; 29 import org.openoffice.setup.SetupData.PackageDescription; 30 import java.util.Enumeration; 31 import java.util.Vector; 32 33 public class PackageCollector { 34 PackageCollector()35 private PackageCollector() { 36 } 37 collectInstallPackages(PackageDescription packageData, Vector allPackages)38 static public void collectInstallPackages(PackageDescription packageData, Vector allPackages) { 39 40 if (( packageData.isLeaf() ) && ( packageData.getSelectionState() == packageData.INSTALL )) { 41 boolean doAdd = true; 42 // Special handling for jre package, because this is not necessarily older, if an older product is updated. 43 if ( packageData.isJavaPackage() ) { 44 Installer installer = InstallerFactory.getInstance(); 45 InstallData data = InstallData.getInstance(); 46 if ( installer.isPackageInstalled(packageData, data) ) { 47 if ( ! installer.isInstalledPackageOlder(packageData, data) ) { 48 doAdd = false; 49 } 50 } 51 } 52 53 if ( doAdd ) { 54 allPackages.add(packageData); 55 System.err.println("Adding to collector 1: " + packageData.getPackageName()); 56 } 57 } 58 59 // also allowing packages at nodes! 60 if (( ! packageData.isLeaf() ) && 61 ( packageData.getPackageName() != null ) && 62 ( ! packageData.getPackageName().equals("")) && 63 (( packageData.getSelectionState() == packageData.INSTALL ) || 64 ( packageData.getSelectionState() == packageData.INSTALL_SOME ))) { 65 boolean doAdd = true; 66 // Special handling for jre package, because this is not necessarily older, if an older product is updated. 67 if ( packageData.isJavaPackage() ) { 68 Installer installer = InstallerFactory.getInstance(); 69 InstallData data = InstallData.getInstance(); 70 if ( installer.isPackageInstalled(packageData, data) ) { 71 if ( ! installer.isInstalledPackageOlder(packageData, data) ) { 72 doAdd = false; 73 } 74 } 75 } 76 77 if ( doAdd ) { 78 allPackages.add(packageData); 79 // System.err.println("Adding to collector 2: " + packageData.getPackageName()); 80 } 81 } 82 83 for (Enumeration e = packageData.children(); e.hasMoreElements(); ) { 84 PackageDescription child = (PackageDescription) e.nextElement(); 85 collectInstallPackages(child, allPackages); 86 } 87 88 } 89 collectUninstallPackages(PackageDescription packageData, Vector allPackages)90 static public void collectUninstallPackages(PackageDescription packageData, Vector allPackages) { 91 if (( packageData.isLeaf() ) && ( packageData.getSelectionState() == packageData.REMOVE )) { 92 allPackages.add(0, packageData); 93 } 94 95 // also allowing packages at nodes! 96 if (( ! packageData.isLeaf() ) && 97 ( packageData.getPackageName() != null ) && 98 ( ! packageData.getPackageName().equals("")) && 99 ( packageData.getSelectionState() == packageData.REMOVE )) { 100 allPackages.add(0, packageData); 101 } 102 103 for (Enumeration e = packageData.children(); e.hasMoreElements(); ) { 104 PackageDescription child = (PackageDescription) e.nextElement(); 105 collectUninstallPackages(child, allPackages); 106 } 107 } 108 109 // Special handling for packages, that change their name, and therefore need to be uninstalled 110 111 // static public void findOldPackages( InstallData installData ) { 112 // 113 // String basis = "ooobasis3"; 114 // if ( installData.getOSType().equalsIgnoreCase("Linux") ) { basis = basis + "."; } 115 // String search = basis + installData.getProductMinor(); 116 117 // Vector allPackages = installData.getInstallPackages(); 118 // Vector oldPackages = new Vector(); 119 120 // for (int i = 0; i < allPackages.size(); i++) { 121 // PackageDescription packageData = (PackageDescription) allPackages.get(i); 122 // int pos = packageData.getPackageName().indexOf(search); 123 124 // if ( pos > -1 ) { 125 // String substring = packageData.getPackageName().substring(pos, pos + 1); 126 // for (int j = 0; j < installData.getProductMinor(); j++) { 127 // String replace = basis + j; 128 // // Creating new package for removal, very simple PackageDescription 129 // PackageDescription localPackage = new PackageDescription(); 130 // localPackage.setUninstallCanFail(true); 131 // localPackage.setIsRelocatable(packageData.isRelocatable()); 132 // String localName = packageData.getPackageName(); 133 // localName = localName.replace(search, replace); 134 // localPackage.setPackageName(localName); 135 136 // if ( ( packageData.getPkgRealName() != null ) && ( ! packageData.getPkgRealName().equals("") )) { 137 // localName = packageData.getPkgRealName(); 138 // localName = localName.replace(search, replace); 139 // localPackage.setPkgRealName(localName); 140 // } 141 142 // if (( packageData.getName() != null ) && ( ! packageData.getName().equals("") )) { 143 // localName = packageData.getName(); 144 // localName = localName.replace(search, replace); 145 // localPackage.setName(localName); 146 // } 147 148 // oldPackages.add(localPackage); 149 // } 150 // } 151 // } 152 153 // // reverse order for uninstallation 154 // int number = oldPackages.size(); 155 // for (int i = 0; i < number; i++) { 156 // if ( i > 0 ) { 157 // PackageDescription oldPackageData = (PackageDescription) oldPackages.remove(i); 158 // oldPackages.add(0,oldPackageData); 159 // } 160 // } 161 162 // installData.setOldPackages(oldPackages); 163 // } 164 sortPackages(Vector allPackages, Vector sortedPackages, String mode)165 static public void sortPackages(Vector allPackages, Vector sortedPackages, String mode) { 166 for (int i = 0; i < allPackages.size(); i++) { 167 boolean integrated = false; 168 PackageDescription packageData = (PackageDescription) allPackages.get(i); 169 170 if ( i == 0 ) { 171 sortedPackages.add(packageData); 172 integrated = true; 173 } else { 174 int position = packageData.getOrder(); 175 for (int j = 0; j < sortedPackages.size(); j++) { 176 PackageDescription sortedPackageData = (PackageDescription) sortedPackages.get(j); 177 int compare = sortedPackageData.getOrder(); 178 179 if ( position < compare ) { 180 sortedPackages.add(j, packageData); 181 integrated = true; 182 break; 183 } 184 } 185 186 // no break used -> adding at the end 187 if ( ! integrated ) { 188 sortedPackages.add(packageData); 189 } 190 } 191 } 192 193 // reverse order for uninstallation 194 if ( mode.equalsIgnoreCase("uninstall")) { 195 int number = sortedPackages.size(); 196 for (int i = 0; i < number; i++) { 197 if ( i > 0 ) { 198 PackageDescription sortPackageData = (PackageDescription) sortedPackages.remove(i); 199 sortedPackages.add(0,sortPackageData); 200 } 201 } 202 } 203 } 204 205 } 206