1 11 package org.eclipse.update.internal.core; 12 13 import java.io.File ; 14 import java.io.IOException ; 15 import java.net.MalformedURLException ; 16 import java.net.URL ; 17 import java.util.ArrayList ; 18 import java.util.Arrays ; 19 import java.util.Collection ; 20 import java.util.Date ; 21 import java.util.HashMap ; 22 import java.util.HashSet ; 23 import java.util.Hashtable ; 24 import java.util.Iterator ; 25 import java.util.Map ; 26 import java.util.Set ; 27 28 import org.eclipse.core.runtime.CoreException; 29 import org.eclipse.core.runtime.FileLocator; 30 import org.eclipse.core.runtime.IProgressMonitor; 31 import org.eclipse.core.runtime.IStatus; 32 import org.eclipse.core.runtime.Platform; 33 import org.eclipse.core.runtime.Status; 34 import org.eclipse.osgi.util.NLS; 35 import org.eclipse.update.configuration.IActivity; 36 import org.eclipse.update.configuration.IConfiguredSite; 37 import org.eclipse.update.configuration.IInstallConfiguration; 38 import org.eclipse.update.configuration.IInstallConfigurationChangedListener; 39 import org.eclipse.update.configuration.IProblemHandler; 40 import org.eclipse.update.configurator.ConfiguratorUtils; 41 import org.eclipse.update.configurator.IPlatformConfiguration; 42 import org.eclipse.update.core.FeatureContentProvider; 43 import org.eclipse.update.core.IFeature; 44 import org.eclipse.update.core.IFeatureReference; 45 import org.eclipse.update.core.IPluginEntry; 46 import org.eclipse.update.core.ISite; 47 import org.eclipse.update.core.ISiteContentProvider; 48 import org.eclipse.update.core.ISiteFeatureReference; 49 import org.eclipse.update.core.Site; 50 import org.eclipse.update.core.SiteManager; 51 import org.eclipse.update.core.Utilities; 52 import org.eclipse.update.core.VersionedIdentifier; 53 import org.eclipse.update.core.model.SiteModel; 54 import org.eclipse.update.internal.configurator.ConfigurationActivator; 55 import org.eclipse.update.internal.configurator.FeatureEntry; 56 import org.eclipse.update.internal.configurator.PlatformConfiguration; 57 import org.eclipse.update.internal.configurator.PluginEntry; 58 import org.eclipse.update.internal.configurator.SiteEntry; 59 import org.eclipse.update.internal.model.ConfigurationActivityModel; 60 import org.eclipse.update.internal.model.ConfiguredSiteModel; 61 import org.eclipse.update.internal.model.InstallConfigurationModel; 62 import org.osgi.framework.Bundle; 63 64 68 69 public class InstallConfiguration extends InstallConfigurationModel implements IInstallConfiguration { 70 private static boolean isWindows = System.getProperty("os.name").startsWith("Win"); private ListenersList listeners = new ListenersList(); 72 73 76 public InstallConfiguration() { 77 } 78 79 83 public InstallConfiguration(IInstallConfiguration config) throws MalformedURLException , CoreException { 84 this(config, null, null); 85 } 86 87 90 public InstallConfiguration(IInstallConfiguration config, URL newLocation, String label) throws CoreException, MalformedURLException { 91 Date now = new Date (); 94 setCreationDate(now); 95 setCurrent(false); 96 97 if (newLocation == null) { 98 String newFileName = UpdateManagerUtils.getLocalRandomIdentifier(LocalSite.CONFIG_FILE, now); 99 newLocation = UpdateManagerUtils.getURL(((LocalSite)SiteManager.getLocalSite()).getLocationURL(), newFileName, null); 100 } 101 setLocationURLString(newLocation.toExternalForm()); 102 103 if (label == null) 104 label = Utilities.format(now); 105 setLabel(label); 106 107 if (config != null) { 110 IConfiguredSite[] csites = config.getConfiguredSites(); 111 if (csites != null) { 112 for (int i = 0; i < csites.length; i++) { 113 ConfiguredSite configSite = new ConfiguredSite(csites[i]); 114 addConfigurationSiteModel(configSite); 115 } 116 } 117 } 118 119 resolve(newLocation, null); 120 initialized = true; 122 } 123 124 125 128 public IConfiguredSite[] getConfiguredSites() { 129 ConfiguredSiteModel[] result = getConfigurationSitesModel(); 130 if (result.length == 0) 131 return new IConfiguredSite[0]; 132 else 133 return (IConfiguredSite[]) result; 134 } 135 136 139 private int getDefaultPolicy() { 140 return PlatformConfiguration.getDefaultPolicy(); 141 } 142 143 147 public IConfiguredSite createConfiguredSite(File file) throws CoreException { 148 149 if (!file.getName().equals("eclipse")) { file = new File (file, "eclipse"); file.mkdirs(); 152 } 153 154 if (isDuplicateSite(file)) 155 throw Utilities.newCoreException(NLS.bind(Messages.InstallConfiguration_location_exists, (new String [] { file.getPath() })),null); 156 ISite site = InternalSiteManager.createSite(file); 157 158 BaseSiteLocalFactory factory = new BaseSiteLocalFactory(); 161 ConfiguredSite configSite = (ConfiguredSite) factory.createConfigurationSiteModel((SiteModel) site, getDefaultPolicy()); 162 163 if (configSite.isNativelyLinked()) { 164 throw Utilities.newCoreException(Messages.InstallConfiguration_AlreadyNativelyLinked, null); 165 } 166 167 if (configSite.isProductSite()) { 168 throw Utilities.newCoreException(Messages.InstallConfiguration_AlreadyProductSite, null); 169 } 170 171 if (site != null) { 172 configSite.setPlatformURLString(site.getURL().toExternalForm()); 173 174 IPlatformConfiguration runtimeConfiguration = ConfiguratorUtils.getCurrentPlatformConfiguration(); 176 ConfigurationPolicy configurationPolicy = configSite.getConfigurationPolicy(); 177 String [] pluginPath = new String [0]; 178 if (configurationPolicy.getPolicy() == IPlatformConfiguration.ISitePolicy.USER_INCLUDE) 179 pluginPath = configurationPolicy.getPluginPath(site); 180 181 IPlatformConfiguration.ISitePolicy sitePolicy = runtimeConfiguration.createSitePolicy(configurationPolicy.getPolicy(), pluginPath); 183 184 IPlatformConfiguration.ISiteEntry siteEntry = runtimeConfiguration.createSiteEntry(site.getURL(), sitePolicy); 186 runtimeConfiguration.configureSite(siteEntry); 187 188 configSite.createPrivateSiteMarker(); 190 ((SiteModel)site).setConfiguredSiteModel(configSite); 191 } 192 configure(configSite); 194 195 return configSite; 196 } 197 198 202 public IConfiguredSite createLinkedConfiguredSite(File file) throws CoreException { 203 return createConfiguredSite(file); 204 } 247 248 251 private void configure(ConfiguredSite linkedSite) throws CoreException { 252 ISite site = linkedSite.getSite(); 253 ISiteFeatureReference[] newFeaturesRef = site.getFeatureReferences(); 254 255 for (int i = 0; i < newFeaturesRef.length; i++) { 256 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_RECONCILER) { 258 String reconciliationType = "enable (optimistic)"; UpdateCore.debug("New Linked Site:New Feature: " + newFeaturesRef[i].getURL() + " as " + reconciliationType); } 261 ConfigurationPolicy policy = linkedSite.getConfigurationPolicy(); 262 policy.configure(newFeaturesRef[i], true, false); 263 } 264 SiteReconciler.checkConfiguredFeatures(linkedSite); 265 } 266 267 270 public void addConfiguredSite(IConfiguredSite site) { 271 if (!isCurrent() && isReadOnly()) 272 return; 273 274 ConfigurationActivity activity = new ConfigurationActivity(IActivity.ACTION_SITE_INSTALL); 275 activity.setLabel(site.getSite().getURL().toExternalForm()); 276 activity.setDate(new Date ()); 277 ConfiguredSiteModel configSiteModel = (ConfiguredSiteModel) site; 278 addConfigurationSiteModel(configSiteModel); 279 configSiteModel.setInstallConfigurationModel(this); 280 281 Object [] configurationListeners = listeners.getListeners(); 283 for (int i = 0; i < configurationListeners.length; i++) { 284 IInstallConfigurationChangedListener listener = ((IInstallConfigurationChangedListener) configurationListeners[i]); 285 listener.installSiteAdded(site); 286 } 287 288 activity.setStatus(IActivity.STATUS_OK); 290 this.addActivity(activity); 291 } 292 293 297 public void addActivity(IActivity activity) { 298 addActivityModel((ConfigurationActivityModel)activity); 299 } 300 301 304 public void removeConfiguredSite(IConfiguredSite site) { 305 if (!isCurrent() && isReadOnly()) 306 return; 307 308 if (removeConfigurationSiteModel((ConfiguredSiteModel) site)) { 309 Object [] configurationListeners = listeners.getListeners(); 311 for (int i = 0; i < configurationListeners.length; i++) { 312 IInstallConfigurationChangedListener listener = ((IInstallConfigurationChangedListener) configurationListeners[i]); 313 listener.installSiteRemoved(site); 314 } 315 316 ConfigurationActivity activity = new ConfigurationActivity(IActivity.ACTION_SITE_REMOVE); 318 activity.setLabel(site.getSite().getURL().toExternalForm()); 319 activity.setDate(new Date ()); 320 activity.setStatus(IActivity.STATUS_OK); 321 this.addActivity(activity); 322 } 323 } 324 325 328 public void addInstallConfigurationChangedListener(IInstallConfigurationChangedListener listener) { 329 synchronized (listeners) { 330 listeners.add(listener); 331 } 332 } 333 334 337 public void removeInstallConfigurationChangedListener(IInstallConfigurationChangedListener listener) { 338 synchronized (listeners) { 339 listeners.remove(listener); 340 } 341 } 342 343 344 347 public void remove() { 348 if ("file".equalsIgnoreCase(getURL().getProtocol())) { File file = new File (getURL().getFile()); 352 UpdateManagerUtils.removeFromFileSystem(file); 353 } 354 } 355 356 363 public boolean save() throws CoreException { 364 365 IPlatformConfiguration runtimeConfiguration = ConfiguratorUtils.getCurrentPlatformConfiguration(); 367 ConfiguredSiteModel[] configurationSites = getConfigurationSitesModel(); 368 369 IPlatformConfiguration.IFeatureEntry[] configuredFeatureEntries = runtimeConfiguration.getConfiguredFeatureEntries(); 371 for (int i = 0; i < configuredFeatureEntries.length; i++) { 372 runtimeConfiguration.unconfigureFeatureEntry(configuredFeatureEntries[i]); 373 } 374 375 IPlatformConfiguration tempConfig = null; 379 try { 380 tempConfig = ConfiguratorUtils.getPlatformConfiguration(null); 381 IPlatformConfiguration.ISiteEntry[] tmpSites = runtimeConfiguration.getConfiguredSites(); 382 for (int i = 0; i < tmpSites.length; i++) { 383 tempConfig.configureSite(tmpSites[i]); 384 } 385 } catch (IOException e) { 386 } 388 389 checkSites(configurationSites, runtimeConfiguration); 391 392 for (int i = 0; i < configurationSites.length; i++) { 394 ConfiguredSite cSite = ((ConfiguredSite) configurationSites[i]); 395 ConfigurationPolicy configurationPolicy = cSite.getConfigurationPolicy(); 396 397 savePluginPath(cSite, runtimeConfiguration, tempConfig); 398 399 IFeatureReference[] configuredFeaturesRef = configurationPolicy.getConfiguredFeatures(); 402 for (int j = 0; j < configuredFeaturesRef.length; j++) { 403 IFeature feature = null; 404 try { 405 feature = configuredFeaturesRef[j].getFeature(null); 406 } catch (CoreException e) { 407 UpdateCore.warn(null, e); 408 } 409 saveFeatureEntry(cSite, feature, runtimeConfiguration); 410 } 411 } 412 413 if (tempConfig != null) { 416 IPlatformConfiguration.ISiteEntry[] tmpSites = tempConfig.getConfiguredSites(); 417 for (int i = 0; i < tmpSites.length; i++) { 418 runtimeConfiguration.unconfigureSite(tmpSites[i]); 419 } 420 } 421 422 try { 423 runtimeConfiguration.save(); 424 this.date = new Date (runtimeConfiguration.getChangeStamp()); 426 if ("file".equalsIgnoreCase(getURL().getProtocol())) UpdateCore.log(this); 428 resetActivities(); 429 return isRestartNeeded(runtimeConfiguration); 430 } catch (IOException e) { 431 CoreException exc = Utilities.newCoreException(NLS.bind(Messages.InstallConfiguration_UnableToSavePlatformConfiguration, (new String [] { runtimeConfiguration.getConfigurationLocation().toExternalForm() })), e); 432 UpdateCore.warn("",exc); } 434 return true; 435 } 436 437 442 private void savePluginPath(ConfiguredSite cSite, IPlatformConfiguration runtimeConfiguration, IPlatformConfiguration tempConfig) throws CoreException { 444 445 ConfigurationPolicy configurationPolicy = cSite.getConfigurationPolicy(); 446 447 String [] pluginPath = configurationPolicy.getPluginPath(cSite.getSite()); 450 IPlatformConfiguration.ISitePolicy sitePolicy = runtimeConfiguration.createSitePolicy(configurationPolicy.getPolicy(), pluginPath); 451 452 URL urlToCheck = null; 454 try { 455 urlToCheck = new URL (cSite.getPlatformURLString()); 456 } catch (MalformedURLException e) { 457 throw Utilities.newCoreException(NLS.bind(Messages.InstallConfiguration_UnableToCreateURL, (new String [] { cSite.getPlatformURLString() })), e); 458 } catch (ClassCastException e) { 459 throw Utilities.newCoreException(Messages.InstallConfiguration_UnableToCast, e); 460 } 461 462 IPlatformConfiguration.ISiteEntry siteEntry = runtimeConfiguration.findConfiguredSite(urlToCheck); 466 if (siteEntry == null) 467 siteEntry = runtimeConfiguration.createSiteEntry(urlToCheck, sitePolicy); 468 else { 469 siteEntry.setSitePolicy(sitePolicy); 470 ((SiteEntry)siteEntry).refreshPlugins(); 471 if (tempConfig != null) tempConfig.unconfigureSite(siteEntry); 473 } 474 ((SiteEntry)siteEntry).setEnabled(cSite.isEnabled()); 475 runtimeConfiguration.configureSite(siteEntry, true ); 476 } 477 478 482 private void saveFeatureEntry(ConfiguredSite cSite, IFeature feature, IPlatformConfiguration runtimeConfiguration) throws CoreException { 483 if (feature == null) 484 return; 485 486 String id = feature.getVersionedIdentifier().getIdentifier(); 488 IPluginEntry[] entries = feature.getPluginEntries(); 489 URL url = null; 490 IPluginEntry featurePlugin = null; 491 for (int k = 0; k < entries.length; k++) { 492 if (id.equalsIgnoreCase(entries[k].getVersionedIdentifier().getIdentifier())) { 493 url = getRuntimeConfigurationURL(entries[k], cSite); 494 featurePlugin = entries[k]; 495 break; 496 } 497 } 498 String pluginVersion = null; 499 if (featurePlugin != null) 500 pluginVersion = featurePlugin.getVersionedIdentifier().getVersion().toString(); 501 502 SiteEntry siteEntry = null; 504 try { 505 URL featureUrl = new URL (cSite.getPlatformURLString()); 506 siteEntry = (SiteEntry)runtimeConfiguration.findConfiguredSite(featureUrl); 507 } catch (MalformedURLException e) { 508 throw Utilities.newCoreException(NLS.bind(Messages.InstallConfiguration_UnableToCreateURL, (new String [] { cSite.getPlatformURLString() })), e); 509 } catch (ClassCastException e) { 510 throw Utilities.newCoreException(Messages.InstallConfiguration_UnableToCast, e); 511 } 512 513 if (siteEntry == null) { 515 throw new CoreException( 516 new Status(IStatus.ERROR, UpdateCore.getPlugin().getBundle().getSymbolicName(), 517 NLS.bind(Messages.InstallConfiguration_unableToFindSite, (new String [] { cSite.getSite().getURL().toExternalForm(), runtimeConfiguration.getConfigurationLocation().toExternalForm() })))); 518 } 519 520 if (feature.isPrimary()) { 522 ArrayList list = new ArrayList (); 524 if (url != null) 525 list.add(url); 526 if (featurePlugin != null) { 527 URL [] fragments = getRuntimeFragmentURLs(featurePlugin); 528 list.addAll(Arrays.asList(fragments)); 529 } 530 URL [] roots = (URL []) list.toArray(new URL [0]); 531 String pluginIdentifier = feature.getPrimaryPluginID(); 532 533 String version = feature.getVersionedIdentifier().getVersion().toString(); 535 String application = feature.getApplication(); 536 FeatureEntry featureEntry = (FeatureEntry)runtimeConfiguration.createFeatureEntry(id, version, pluginIdentifier, pluginVersion, true, application, roots); 537 featureEntry.setURL(getFeatureRelativeURL(feature)); 538 siteEntry.addFeatureEntry(featureEntry); 539 } else { 540 String version = feature.getVersionedIdentifier().getVersion().toString(); 542 String pluginIdentifier = feature.getPrimaryPluginID(); 543 FeatureEntry featureEntry = (FeatureEntry)runtimeConfiguration.createFeatureEntry(id, version, pluginIdentifier, pluginVersion, false, null, null); 544 featureEntry.setURL(getFeatureRelativeURL(feature)); 545 siteEntry.addFeatureEntry(featureEntry); 546 } 547 548 IPluginEntry[] platformPlugins = getPlatformPlugins(feature, runtimeConfiguration); 550 for (int k = 0; k < platformPlugins.length; k++) { 551 id = platformPlugins[k].getVersionedIdentifier().getIdentifier(); 552 url = getRuntimeConfigurationURL(platformPlugins[k], cSite); 553 if (url != null) { 554 runtimeConfiguration.setBootstrapPluginLocation(id, url); 555 } 556 } 557 } 558 559 563 private void checkSites(ConfiguredSiteModel[] configurationSites, IPlatformConfiguration runtimeConfiguration) throws CoreException { 564 565 for (int i = 0; i < configurationSites.length; i++) { 569 URL urlToCheck = null; 571 try { 572 urlToCheck = new URL (configurationSites[i].getPlatformURLString()); 573 } catch (MalformedURLException e) { 574 UpdateCore.warn(NLS.bind(Messages.InstallConfiguration_UnableToCreateURL, (new String [] { configurationSites[i].getPlatformURLString() })), e); 575 } catch (ClassCastException e) { 576 UpdateCore.warn(Messages.InstallConfiguration_UnableToCast, e); 577 } 578 579 IPlatformConfiguration.ISiteEntry siteEntry = runtimeConfiguration.findConfiguredSite(urlToCheck); 581 if (siteEntry == null) { 582 UpdateCore.warn(NLS.bind(Messages.InstallConfiguration_unableToFindSite, (new String [] { urlToCheck.toExternalForm(), runtimeConfiguration.getConfigurationLocation().toExternalForm() }))); 583 } 584 } 585 } 586 587 588 600 public void revertTo(IInstallConfiguration configuration, IProgressMonitor monitor, IProblemHandler handler) throws CoreException, InterruptedException { 601 602 IConfiguredSite[] oldConfigSites = configuration.getConfiguredSites(); 603 IConfiguredSite[] nowConfigSites = this.getConfiguredSites(); 604 605 Map oldSitesMap = new Hashtable (0); 607 Map newSitesMap = new Hashtable (0); 608 for (int i = 0; i < oldConfigSites.length; i++) { 609 IConfiguredSite element = oldConfigSites[i]; 610 oldSitesMap.put(element.getSite().getURL().toExternalForm(), element); 611 newSitesMap.put(element.getSite().getURL().toExternalForm(), element); 612 } 613 if (nowConfigSites != null) { 616 String key = null; 617 618 for (int i = 0; i < nowConfigSites.length; i++) { 619 key = nowConfigSites[i].getSite().getURL().toExternalForm(); 620 IConfiguredSite oldSite = (IConfiguredSite) oldSitesMap.get(key); 621 if (oldSite != null) { 622 ((ConfiguredSite) nowConfigSites[i]).revertTo(oldSite, monitor, handler); 625 } else { 626 ISiteFeatureReference[] featuresToUnconfigure = nowConfigSites[i].getSite().getFeatureReferences(); 629 for (int j = 0; j < featuresToUnconfigure.length; j++) { 630 IFeature featureToUnconfigure = null; 631 try { 632 featureToUnconfigure = featuresToUnconfigure[j].getFeature(null); 633 } catch (CoreException e) { 634 UpdateCore.warn(null, e); 635 } 636 if (featureToUnconfigure != null) 637 nowConfigSites[i].unconfigure(featureToUnconfigure); 638 } 639 } 640 newSitesMap.put(key,nowConfigSites[i]); 641 } 642 643 Collection sites = newSitesMap.values(); 647 if (sites != null && !sites.isEmpty()) { 648 ConfiguredSiteModel[] sitesModel = new ConfiguredSiteModel[sites.size()]; 649 sites.toArray(sitesModel); 650 setConfigurationSiteModel(sitesModel); 651 } 652 } 653 } 654 655 658 public IActivity[] getActivities() { 659 if (getActivityModel().length == 0) 660 return new IActivity[0]; 661 return (IActivity[]) getActivityModel(); 662 } 663 664 668 private IPluginEntry[] getPlatformPlugins(IFeature feature, IPlatformConfiguration runtimeConfiguration) { 669 Map featurePlatformPlugins = new HashMap (); 670 String [] platformPluginID = runtimeConfiguration.getBootstrapPluginIdentifiers(); 671 IPluginEntry[] featurePlugins = feature.getPluginEntries(); 672 673 for (int i = 0; i < platformPluginID.length; i++) { 674 String featurePluginId = null; 675 for (int j = 0; j < featurePlugins.length; j++) { 676 featurePluginId = featurePlugins[j].getVersionedIdentifier().getIdentifier(); 677 if (platformPluginID[i].equals(featurePluginId)) { 678 featurePlatformPlugins.put(platformPluginID[i], featurePlugins[j]); 679 } 680 } 681 } 682 683 Collection values = featurePlatformPlugins.values(); 684 if (values == null || values.size() == 0) 685 return new IPluginEntry[0]; 686 687 IPluginEntry[] result = new IPluginEntry[values.size()]; 688 Iterator iter = values.iterator(); 689 int index = 0; 690 while (iter.hasNext()) { 691 result[index] = ((IPluginEntry) iter.next()); 692 index++; 693 } 694 return result; 695 } 696 697 702 private URL getRuntimeConfigurationURL(IPluginEntry entry, ConfiguredSite cSite) throws CoreException { 703 704 String rootString = cSite.getPlatformURLString(); 705 String pluginPathID = getPathID(entry); 706 try { 707 ISiteContentProvider siteContentProvider = cSite.getSite().getSiteContentProvider(); 708 URL pluginEntryfullURL = siteContentProvider.getArchiveReference(pluginPathID); 709 710 if (!rootString.startsWith("platform")) { if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_CONFIGURATION) 714 UpdateCore.debug("getRuntimeConfiguration Plugin Entry Full URL:" + pluginEntryfullURL + " Platform String:" + rootString + " [NON PLATFORM URL]."); return pluginEntryfullURL; 716 } 717 718 URL pluginEntryRootURL = cSite.getSite().getURL(); 725 String relativeString = UpdateManagerUtils.getURLAsString(pluginEntryRootURL, pluginEntryfullURL); 726 URL result = new URL (new URL (rootString), relativeString); 727 728 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_CONFIGURATION) 730 UpdateCore.debug("getRuntimeConfiguration plugin Entry Full URL:" + pluginEntryfullURL + " Platform String:" + rootString + " Site URL:" + pluginEntryRootURL + " Relative:" + relativeString); 732 if (pluginEntryfullURL != null) { 735 if ("file".equals(pluginEntryfullURL.getProtocol())) { String fileString = pluginEntryfullURL.getFile(); 737 if (!new File (fileString).exists()) { 738 UpdateCore.warn("The URL:" + result + " doesn't point to a valid platform plugin.The URL will not be written in the platform configuration", new Exception ()); return null; 740 } 741 } 742 } 743 744 return result; 745 } catch (IOException e) { 746 throw Utilities.newCoreException(NLS.bind(Messages.InstallConfiguration_UnableToCreateURL, (new String [] { rootString })), e); 747 } 748 } 749 750 753 private URL [] getRuntimeFragmentURLs(IPluginEntry entry) throws CoreException { 754 755 VersionedIdentifier vid = entry.getVersionedIdentifier(); 757 758 Bundle bundle = Platform.getBundle(vid.getIdentifier()); 760 ArrayList list = new ArrayList (); 761 if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.INSTALLED) { 762 FragmentEntry[] fragments = UpdateManagerUtils.getFragments(bundle); 763 for (int i = 0; fragments != null && i < fragments.length; i++) { 764 String location = fragments[i].getLocation(); 765 try { 766 URL locationURL = new URL (location); 767 locationURL = FileLocator.toFileURL(FileLocator.resolve(locationURL)); 768 list.add(asInstallRelativeURL(locationURL)); 769 } catch (IOException e) { 770 } 772 } 773 } 774 return (URL []) list.toArray(new URL [0]); 775 } 776 777 782 private String getPathID(IPluginEntry entry) { 783 return Site.DEFAULT_PLUGIN_PATH + entry.getVersionedIdentifier().toString() + FeatureContentProvider.JAR_EXTENSION; 784 } 785 786 789 private URL asInstallRelativeURL(URL url) { 790 URL install = ConfiguratorUtils.getInstallURL(); 792 793 if (install.getProtocol().equals(url.getProtocol())) { 795 if (install.getProtocol().equals("file")) { String installS = new File (install.getFile()).getAbsolutePath().replace(File.separatorChar, '/'); 797 if (!installS.endsWith("/")) installS += "/"; String urlS = new File (url.getFile()).getAbsolutePath().replace(File.separatorChar, '/'); 800 if (!urlS.endsWith("/")) urlS += "/"; int ix = installS.lastIndexOf("/"); if (ix != -1) { 804 installS = installS.substring(0, ix + 1); 805 if (urlS.startsWith(installS)) { 806 try { 807 return new URL ("platform:/base/" + urlS.substring(installS.length())); } catch (MalformedURLException e) { 809 } 810 } 811 } 812 } 813 } 814 return url; 815 } 816 817 private boolean isDuplicateSite(File siteDirectory) { 818 IConfiguredSite[] sites = getConfiguredSites(); 819 URL fileURL; 820 try { 821 fileURL = siteDirectory.toURL(); 822 } catch (MalformedURLException e) { 823 return false; 824 } 825 for (int i = 0; i < sites.length; i++) { 826 URL url = sites[i].getSite().getURL(); 827 if (UpdateManagerUtils.sameURL(fileURL, url)) 828 return true; 829 } 830 return false; 831 } 832 833 836 private String getFeatureRelativeURL(IFeature feature) { 837 String url = feature.getURL().toExternalForm(); 838 String siteURL = feature.getSite().getURL().toExternalForm(); 839 844 if (url.startsWith(siteURL)) 845 return url.substring(siteURL.length()); 846 else 847 return url; 848 } 849 850 853 private boolean isRestartNeeded(IPlatformConfiguration runtimeConfig) { 854 855 Set newPluginsSet = null; 857 if (runtimeConfig instanceof PlatformConfiguration) { 858 newPluginsSet = ((PlatformConfiguration)runtimeConfig).getPluginPaths(); 859 if (isWindows) { 861 String [] newPluginsSetArray = (String [])newPluginsSet.toArray( new String [newPluginsSet.size()]); 862 for (int i = 0; i < newPluginsSetArray.length; i++) { 863 newPluginsSet.add(newPluginsSetArray[i].toLowerCase()); 864 } 865 } 866 } else { 867 URL [] newBundlePaths = runtimeConfig.getPluginPath(); 868 newPluginsSet = new HashSet (newBundlePaths.length); 869 for (int i=0; i<newBundlePaths.length; i++) { 870 871 String pluginLocation = newBundlePaths[i].getFile(); 872 newPluginsSet.add(pluginLocation); 873 if (isWindows) 875 newPluginsSet.add(pluginLocation.toLowerCase()); 876 } 877 } 878 879 880 881 Bundle[] oldBundles = UpdateCore.getPlugin().getBundleContext().getBundles(); 882 883 int offset = ConfigurationActivator.UPDATE_PREFIX.length(); 884 for (int i=0; i<oldBundles.length; i++) { 885 if (oldBundles[i].getBundleId() == 0) 886 continue; String oldBundleLocation = oldBundles[i].getLocation(); 888 if (!oldBundleLocation.startsWith(ConfigurationActivator.UPDATE_PREFIX)) 890 continue; 891 oldBundleLocation = oldBundleLocation.substring(offset); 892 893 if (newPluginsSet.contains(oldBundleLocation)) 894 continue; 895 if (isWindows && newPluginsSet.contains(oldBundleLocation.toLowerCase())) 896 continue; 897 898 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_CONFIGURATION) 899 UpdateCore.debug("Bundle " + oldBundleLocation + " has been removed"); return true; 901 } 902 903 if (runtimeConfig instanceof PlatformConfiguration) { 904 return areThereNewVersionOfOldPlugins( ((PlatformConfiguration)runtimeConfig).getPlugins(), oldBundles); 905 } 906 907 return false; 908 } 909 910 920 private boolean areThereNewVersionOfOldPlugins(PluginEntry[] newConfigurationPlugins, Bundle[] oldConfigurationBundles) { 921 922 923 for ( int i = 0; i < oldConfigurationBundles.length; i++) { 924 if (oldConfigurationBundles[i].getBundleId() == 0) 925 continue; if ( getNumberOfPlugins(oldConfigurationBundles[i].getSymbolicName(), oldConfigurationBundles) != getNumberOfPlugins(oldConfigurationBundles[i].getSymbolicName(), newConfigurationPlugins)) { 927 return true; 928 } 929 } 930 return false; 931 } 932 933 private int getNumberOfPlugins(String symbolicName, PluginEntry[] newConfigurationPlugins) { 934 935 int numberOfPlugins = 0; 936 937 for ( int i = 0; i < newConfigurationPlugins.length; i++) { 938 if ( symbolicName.equals(newConfigurationPlugins[i].getPluginIdentifier())) { 939 numberOfPlugins++; 940 } 941 } 942 943 return numberOfPlugins; 944 } 945 946 private int getNumberOfPlugins(String symbolicName, Bundle[] oldConfigurationBundles) { 947 948 int numberOfPlugins = 0; 949 950 for ( int i = 0; i < oldConfigurationBundles.length; i++) { 951 if ( symbolicName.equals(oldConfigurationBundles[i].getSymbolicName())) { 952 numberOfPlugins++; 953 } 954 } 955 956 return numberOfPlugins; 957 } 958 959 962 public boolean equals(Object obj) { 963 if (this == obj) 964 return true; 965 if (!(obj instanceof InstallConfiguration)) 966 return false; 967 968 InstallConfiguration config = (InstallConfiguration)obj; 969 970 return getCreationDate().equals(config.getCreationDate()) && 971 getLabel().equals(config.getLabel()) && 972 getLocationURLString().equals(config.getLocationURLString()); 973 } 974 } 975 | Popular Tags |