/** * For all components to be uninstalled, find any shared files required by components that will <i>not</i> be uninstalled, and * store them in the component (using {@link ComponentDescription#setSharedFiles(List)}). * {@link ComponentDescription#uninstall()} can then check and refrain from removing those shared files. * * @param uninstallComponents * selected for uninstallation */ private void findAndStoreSharedFiles(List<ComponentDescription> uninstallComponents) { // first, find out which components are *not* selected for removal: Set<ComponentDescription> retainComponents = getAllInstalledComponents(); retainComponents.removeAll(uninstallComponents); // if all components are selected for removal, there is nothing to do here: if (retainComponents.isEmpty()) { return; } // otherwise, list all unique files required by retained components: Set<String> retainFiles = new TreeSet<String>(); for (ComponentDescription retainComponent : retainComponents) { retainFiles.addAll(retainComponent.getInstalledFileNames()); } // finally, store shared files in components to be removed (queried later): for (ComponentDescription uninstallComponent : uninstallComponents) { Set<String> sharedFiles = new HashSet<String>(uninstallComponent.getInstalledFileNames()); sharedFiles.retainAll(retainFiles); if (!sharedFiles.isEmpty()) { uninstallComponent.setSharedFiles(sharedFiles); } } }
/** * For all components to be uninstalled, find any shared files required by components that will <i>not</i> be uninstalled, and * store them in the component (using {@link ComponentDescription#setSharedFiles(List)}). * {@link ComponentDescription#uninstall()} can then check and refrain from removing those shared files. * * @param uninstallComponents * selected for uninstallation */ private void findAndStoreSharedFiles(List<ComponentDescription> uninstallComponents) { // first, find out which components are *not* selected for removal: Set<ComponentDescription> retainComponents = getAllInstalledComponents(); retainComponents.removeAll(uninstallComponents); // if all components are selected for removal, there is nothing to do here: if (retainComponents.isEmpty()) { return; } // otherwise, list all unique files required by retained components: Set<String> retainFiles = new TreeSet<String>(); for (ComponentDescription retainComponent : retainComponents) { retainFiles.addAll(retainComponent.getInstalledFileNames()); } // finally, store shared files in components to be removed (queried later): for (ComponentDescription uninstallComponent : uninstallComponents) { Set<String> sharedFiles = new HashSet<String>(uninstallComponent.getInstalledFileNames()); sharedFiles.retainAll(retainFiles); if (!sharedFiles.isEmpty()) { uninstallComponent.setSharedFiles(sharedFiles); } } }
/** * For all components to be uninstalled, find any shared files required by components that will <i>not</i> be uninstalled, and * store them in the component (using {@link ComponentDescription#setSharedFiles(List)}). * {@link ComponentDescription#uninstall()} can then check and refrain from removing those shared files. * * @param uninstallComponents * selected for uninstallation */ private void findAndStoreSharedFiles(List<ComponentDescription> uninstallComponents) { // first, find out which components are *not* selected for removal: Set<ComponentDescription> retainComponents = getAllInstalledComponents(); retainComponents.removeAll(uninstallComponents); // if all components are selected for removal, there is nothing to do here: if (retainComponents.isEmpty()) { return; } // otherwise, list all unique files required by retained components: Set<String> retainFiles = new TreeSet<String>(); for (ComponentDescription retainComponent : retainComponents) { retainFiles.addAll(retainComponent.getInstalledFileNames()); } // finally, store shared files in components to be removed (queried later): for (ComponentDescription uninstallComponent : uninstallComponents) { Set<String> sharedFiles = new HashSet<String>(uninstallComponent.getInstalledFileNames()); sharedFiles.retainAll(retainFiles); if (!sharedFiles.isEmpty()) { uninstallComponent.setSharedFiles(sharedFiles); } } }