1 11 package org.eclipse.update.core; 12 13 import java.net.URL ; 14 import java.util.ArrayList ; 15 import java.util.Arrays ; 16 import java.util.HashSet ; 17 import java.util.List ; 18 import java.util.Set ; 19 import java.util.Vector ; 20 21 import org.eclipse.core.runtime.CoreException; 22 import org.eclipse.core.runtime.IProgressMonitor; 23 import org.eclipse.core.runtime.NullProgressMonitor; 24 import org.eclipse.core.runtime.SubProgressMonitor; 25 import org.eclipse.osgi.util.NLS; 26 import org.eclipse.update.core.model.ContentEntryModel; 27 import org.eclipse.update.core.model.FeatureModel; 28 import org.eclipse.update.core.model.FeatureReferenceModel; 29 import org.eclipse.update.core.model.ImportModel; 30 import org.eclipse.update.core.model.InstallAbortedException; 31 import org.eclipse.update.core.model.NonPluginEntryModel; 32 import org.eclipse.update.core.model.PluginEntryModel; 33 import org.eclipse.update.core.model.URLEntryModel; 34 import org.eclipse.update.internal.core.ErrorRecoveryLog; 35 import org.eclipse.update.internal.core.InstallHandlerProxy; 36 import org.eclipse.update.internal.core.InstallRegistry; 37 import org.eclipse.update.internal.core.Messages; 38 import org.eclipse.update.internal.core.TargetFeature; 39 import org.eclipse.update.internal.core.UpdateCore; 40 import org.eclipse.update.internal.core.UpdateManagerUtils; 41 import org.eclipse.update.internal.core.UpdateSiteIncludedFeatureReference; 42 43 58 public class Feature extends FeatureModel implements IFeature { 59 60 64 public static final String FEATURE_FILE = "feature"; 66 70 public static final String FEATURE_XML = FEATURE_FILE + ".xml"; 72 private ISite site; private IFeatureContentProvider featureContentProvider; private List 75 includedFeatureReferences; 76 77 private VersionedIdentifier versionId; 79 80 private InstallAbortedException abortedException = null; 81 82 87 public Feature() { 88 } 89 90 98 public boolean equals(Object object) { 99 if (!(object instanceof IFeature)) 100 return false; 101 IFeature f = (IFeature) object; 102 return getVersionedIdentifier().equals(f.getVersionedIdentifier()); 103 } 104 105 111 public VersionedIdentifier getVersionedIdentifier() { 112 if (versionId != null) 113 return versionId; 114 115 String id = getFeatureIdentifier(); 116 String ver = getFeatureVersion(); 117 if (id != null && ver != null) { 118 try { 119 versionId = new VersionedIdentifier(id, ver); 120 return versionId; 121 } catch (Exception e) { 122 UpdateCore.warn( 123 "Unable to create versioned identifier:" + id + ":" + ver); } 125 } 126 127 versionId = new VersionedIdentifier(getURL().toExternalForm(), null); 128 return versionId; 129 } 130 131 137 public ISite getSite() { 138 return site; 139 } 140 141 147 public URL getURL() { 148 IFeatureContentProvider contentProvider = null; 149 try { 150 contentProvider = getFeatureContentProvider(); 151 } catch (CoreException e) { 152 UpdateCore.warn("No content Provider", e); } 154 return (contentProvider != null) ? contentProvider.getURL() : null; 155 } 156 157 164 public IURLEntry getUpdateSiteEntry() { 165 return (IURLEntry) getUpdateSiteEntryModel(); 166 } 167 168 175 public IURLEntry[] getDiscoverySiteEntries() { 176 URLEntryModel[] result = getDiscoverySiteEntryModels(); 177 if (result.length == 0) 178 return new IURLEntry[0]; 179 else 180 return (IURLEntry[]) result; 181 } 182 183 189 public IInstallHandlerEntry getInstallHandlerEntry() { 190 return (IInstallHandlerEntry) getInstallHandlerModel(); 191 } 192 193 199 public IURLEntry getDescription() { 200 return (IURLEntry) getDescriptionModel(); 201 } 202 203 209 public IURLEntry getCopyright() { 210 return (IURLEntry) getCopyrightModel(); 211 } 212 213 219 public IURLEntry getLicense() { 220 return (IURLEntry) getLicenseModel(); 221 } 222 223 229 public URL getImage() { 230 return getImageURL(); 231 } 232 233 239 public IImport[] getRawImports() { 240 ImportModel[] result = getImportModels(); 241 if (result.length == 0) 242 return new IImport[0]; 243 else 244 return (IImport[]) result; 245 } 246 247 256 public IFeatureReference install( 257 IFeature targetFeature, 258 IVerificationListener verificationListener, 259 IProgressMonitor progress) 260 throws InstallAbortedException, CoreException { 261 return install(targetFeature, null, verificationListener, progress); 263 } 264 265 274 public IFeatureReference install( 275 IFeature targetFeature, 276 IFeatureReference[] optionalfeatures, 277 IVerificationListener verificationListener, 278 IProgressMonitor progress) 279 throws InstallAbortedException, CoreException { 280 281 debug("Installing...:" + getURL().toExternalForm()); ErrorRecoveryLog recoveryLog = ErrorRecoveryLog.getLog(); 284 285 InstallMonitor monitor; 287 if (progress == null) 288 monitor = new InstallMonitor(new NullProgressMonitor()); 289 else if (progress instanceof InstallMonitor) 290 monitor = (InstallMonitor) progress; 291 else 292 monitor = new InstallMonitor(progress); 293 294 InstallHandlerProxy handler = 296 new InstallHandlerProxy( 297 IInstallHandler.HANDLER_ACTION_INSTALL, 298 this, 299 this.getInstallHandlerEntry(), 300 monitor); 301 boolean success = false; 302 Throwable originalException = null; 303 abortedException = null; 304 305 IFeatureContentProvider provider = getFeatureContentProvider(); 308 IVerifier verifier = provider.getVerifier(); 309 IFeatureReference result = null; 310 IFeatureReference alreadyInstalledFeature = null; 311 IFeatureContentConsumer consumer = null; 312 IPluginEntry[] targetSitePluginEntries = null; 313 ArrayList justInstalledPlugins = new ArrayList (); 314 315 try { 316 IPluginEntry[] sourceFeaturePluginEntries = getPluginEntries(); 320 ISite targetSite = targetFeature.getSite(); 321 if (targetSite == null) { 322 debug("The site to install in is null"); targetSitePluginEntries = new IPluginEntry[0]; 324 } else { 325 targetSitePluginEntries = targetSite.getPluginEntries(); 326 } 327 IPluginEntry[] pluginsToInstall = 328 UpdateManagerUtils.diff( 329 sourceFeaturePluginEntries, 330 targetSitePluginEntries); 331 INonPluginEntry[] nonPluginsToInstall = getNonPluginEntries(); 332 333 IFeatureReference[] children = getIncludedFeatureReferences(); 334 if (optionalfeatures != null) { 335 children = 336 UpdateManagerUtils.optionalChildrenToInstall( 337 children, 338 optionalfeatures); 339 } 340 341 int taskCount = 348 2 349 + 2 * pluginsToInstall.length 350 + nonPluginsToInstall.length 351 + 1 352 + 5 * children.length; 353 monitor.beginTask("", taskCount); SubProgressMonitor subMonitor = null; 355 356 recoveryLog.open(ErrorRecoveryLog.START_INSTALL_LOG); 358 359 handler.installInitiated(); 361 362 ContentReference[] references = 364 provider.getFeatureEntryArchiveReferences(monitor); 365 verifyReferences( 366 verifier, 367 references, 368 monitor, 369 verificationListener, 370 true); 371 monitorWork(monitor, 1); 372 373 for (int i = 0; i < pluginsToInstall.length; i++) { 375 references = provider.getPluginEntryArchiveReferences( 376 pluginsToInstall[i], monitor); 377 verifyReferences(verifier, references, monitor, 378 verificationListener, false); 379 monitorWork(monitor, 1); 380 } 381 382 handler.pluginsDownloaded(pluginsToInstall); 383 384 Vector filteredPlugins = new Vector (); 385 for (int i = 0; i < nonPluginsToInstall.length; i++) { 388 if (handler.acceptNonPluginData(nonPluginsToInstall[i])) { 389 references = provider.getNonPluginEntryArchiveReferences( 390 nonPluginsToInstall[i], monitor); 391 monitorWork(monitor, 1); 392 filteredPlugins.add(nonPluginsToInstall[i]); 393 } 394 } 395 nonPluginsToInstall = (INonPluginEntry[]) filteredPlugins 396 .toArray(new INonPluginEntry[0]); 397 handler.nonPluginDataDownloaded(nonPluginsToInstall, 398 verificationListener); 399 400 consumer = targetFeature.getFeatureContentConsumer(); 402 403 for (int i = 0; i < children.length; i++) { 406 IFeature childFeature = null; 407 try { 408 childFeature = children[i].getFeature(null); 409 } catch (CoreException e) { 410 UpdateCore.warn(null, e); 411 } 412 if (childFeature != null) { 413 subMonitor = new SubProgressMonitor(monitor, 5); 414 ((Site) targetSite).install( childFeature, 416 optionalfeatures, 417 consumer, 418 verifier, 419 verificationListener, 420 subMonitor); 421 } 422 } 423 424 for (int i = 0; i < pluginsToInstall.length; i++) { 426 if (InstallRegistry.getInstance().isPluginJustInstalled(pluginsToInstall[i])) { 428 monitor.worked(1); 429 continue; 430 } 431 IContentConsumer pluginConsumer = 432 consumer.open(pluginsToInstall[i]); 433 440 if(pluginsToInstall[i] instanceof PluginEntryModel && !((PluginEntryModel)pluginsToInstall[i]).isUnpack()){ 441 references = provider.getPluginEntryArchiveReferences( 443 pluginsToInstall[i], monitor); 444 } else{ 445 references = 447 provider.getPluginEntryContentReferences( 448 pluginsToInstall[i], 449 monitor); 450 } 451 452 String msg = ""; subMonitor = new SubProgressMonitor(monitor, 1); 454 VersionedIdentifier pluginVerId = 455 pluginsToInstall[i].getVersionedIdentifier(); 456 String pluginID = 457 (pluginVerId == null) ? "" : pluginVerId.getIdentifier(); msg = NLS.bind(Messages.Feature_TaskInstallPluginFiles, (new String [] { pluginID })); 459 460 for (int j = 0; j < references.length; j++) { 461 setMonitorTaskName( 462 subMonitor, 463 msg + references[j].getIdentifier()); 464 pluginConsumer.store(references[j], subMonitor); 465 } 466 467 if (monitor.isCanceled()) 468 abort(); 469 else { 470 justInstalledPlugins.add(pluginsToInstall[i]); 471 InstallRegistry.registerPlugin(pluginsToInstall[i]); 472 } 473 } 474 475 alreadyInstalledFeature = featureAlreadyInstalled(targetSite); 479 if (alreadyInstalledFeature == null) { 481 references = provider.getFeatureEntryContentReferences(monitor); 483 484 String msg = ""; subMonitor = new SubProgressMonitor(monitor, 1); 486 msg = Messages.Feature_TaskInstallFeatureFiles; 487 488 for (int i = 0; i < references.length; i++) { 489 setMonitorTaskName( 490 subMonitor, 491 msg + " " + references[i].getIdentifier()); consumer.store(references[i], subMonitor); 493 } 494 495 if (monitor.isCanceled()) 496 abort(); 497 else 498 InstallRegistry.registerFeature(this); 499 } else { 500 if (monitor.isCanceled()) 501 abort(); 502 else 503 monitor.worked(1); 504 } 505 506 handler.completeInstall(consumer); 508 monitorWork(monitor, 1); 509 510 success = true; 512 513 } catch (InstallAbortedException e) { 514 abortedException = e; 515 } catch (CoreException e) { 516 originalException = e; 517 } finally { 518 Exception newException = null; 519 try { 520 if (consumer != null) { 521 if (success) { 522 result = consumer.close(); 523 if (result == null) { 524 result = alreadyInstalledFeature; if (result != null 526 && optionalfeatures != null 527 && optionalfeatures.length > 0) { 528 reinitializeFeature(result); 530 } 531 } 532 recoveryLog.close(ErrorRecoveryLog.END_INSTALL_LOG); 534 } else { 535 for (int i=0; i<justInstalledPlugins.size(); i++) 537 InstallRegistry.unregisterPlugin(((IPluginEntry)justInstalledPlugins.get(i))); 538 consumer.abort(); 539 } 540 } 541 handler.installCompleted(success); 542 recoveryLog.delete(); 544 } catch (CoreException e) { 545 newException = e; 546 } 547 548 if (originalException != null) { 551 throw Utilities.newCoreException( 552 NLS.bind(Messages.InstallHandler_error, (new String [] { this.getLabel() })), 553 originalException); 554 } 555 556 if (newException != null) 557 throw Utilities.newCoreException( 558 NLS.bind(Messages.InstallHandler_error, (new String [] { this.getLabel() })), 559 newException); 560 561 if (abortedException != null) { 562 throw abortedException; 563 } 564 565 } 566 return result; 567 } 568 569 575 public IPluginEntry[] getRawPluginEntries() { 576 PluginEntryModel[] result = getPluginEntryModels(); 577 if (result.length == 0) 578 return new IPluginEntry[0]; 579 else 580 return (IPluginEntry[]) result; 581 } 582 583 588 private IPluginEntry[] filterPluginEntry(IPluginEntry[] all) { 589 List list = new ArrayList (); 590 if (all != null) { 591 for (int i = 0; i < all.length; i++) { 592 if (UpdateManagerUtils.isValidEnvironment(all[i])) 593 list.add(all[i]); 594 } 595 } 596 597 IPluginEntry[] result = new IPluginEntry[list.size()]; 598 if (!list.isEmpty()) { 599 list.toArray(result); 600 } 601 602 return result; 603 } 604 605 611 public int getPluginEntryCount() { 612 return getPluginEntries().length; 613 } 614 615 621 public INonPluginEntry[] getRawNonPluginEntries() { 622 NonPluginEntryModel[] result = getNonPluginEntryModels(); 623 if (result.length == 0) 624 return new INonPluginEntry[0]; 625 else 626 return (INonPluginEntry[]) result; 627 } 628 629 635 public int getNonPluginEntryCount() { 636 return getNonPluginEntryModels().length; 637 } 638 639 645 public IIncludedFeatureReference[] getRawIncludedFeatureReferences() 646 throws CoreException { 647 if (includedFeatureReferences == null) 648 initializeIncludedReferences(); 649 650 if (includedFeatureReferences.size() == 0) 651 return new IncludedFeatureReference[0]; 652 653 return (IIncludedFeatureReference[]) includedFeatureReferences.toArray( 654 new IIncludedFeatureReference[includedFeatureReferences.size()]); 655 } 656 662 public long getDownloadSize() { 663 try { 664 Set allPluginEntries = new HashSet (); 665 Set allNonPluginEntries = new HashSet (); 666 667 IPluginEntry[] plugins = getPluginEntries(); 668 allPluginEntries.addAll(Arrays.asList(plugins)); 669 INonPluginEntry[] nonPlugins = getNonPluginEntries(); 670 allNonPluginEntries.addAll(Arrays.asList(nonPlugins)); 671 672 IFeatureReference[] children = getIncludedFeatureReferences(); 673 for (int i = 0; i < children.length; i++) { 674 plugins = children[i].getFeature(null).getPluginEntries(); 675 allPluginEntries.addAll(Arrays.asList(plugins)); 676 nonPlugins = children[i].getFeature(null).getNonPluginEntries(); 677 allNonPluginEntries.addAll(Arrays.asList(nonPlugins)); 678 } 679 680 IPluginEntry[] totalPlugins = 681 new IPluginEntry[allPluginEntries.size()]; 682 INonPluginEntry[] totalNonPlugins = 683 new INonPluginEntry[allNonPluginEntries.size()]; 684 if (allPluginEntries.size() != 0) { 685 allPluginEntries.toArray(totalPlugins); 686 } 687 if (allNonPluginEntries.size() != 0) { 688 allNonPluginEntries.toArray(totalNonPlugins); 689 } 690 691 return getFeatureContentProvider().getDownloadSizeFor( 692 totalPlugins, 693 totalNonPlugins); 694 695 } catch (CoreException e) { 696 UpdateCore.warn(null, e); 697 return ContentEntryModel.UNKNOWN_SIZE; 698 } 699 } 700 701 707 public long getInstallSize() { 708 try { 709 Set allPluginEntries = new HashSet (); 710 Set allNonPluginEntries = new HashSet (); 711 712 IPluginEntry[] plugins = getPluginEntries(); 713 allPluginEntries.addAll(Arrays.asList(plugins)); 714 INonPluginEntry[] nonPlugins = getNonPluginEntries(); 715 allNonPluginEntries.addAll(Arrays.asList(nonPlugins)); 716 717 IFeatureReference[] children = getIncludedFeatureReferences(); 718 for (int i = 0; i < children.length; i++) { 719 plugins = children[i].getFeature(null).getPluginEntries(); 720 allPluginEntries.addAll(Arrays.asList(plugins)); 721 nonPlugins = children[i].getFeature(null).getNonPluginEntries(); 722 allNonPluginEntries.addAll(Arrays.asList(nonPlugins)); 723 } 724 725 IPluginEntry[] totalPlugins = 726 new IPluginEntry[allPluginEntries.size()]; 727 INonPluginEntry[] totalNonPlugins = 728 new INonPluginEntry[allNonPluginEntries.size()]; 729 if (allPluginEntries.size() != 0) { 730 allPluginEntries.toArray(totalPlugins); 731 } 732 if (allNonPluginEntries.size() != 0) { 733 allNonPluginEntries.toArray(totalNonPlugins); 734 } 735 736 return getFeatureContentProvider().getInstallSizeFor( 737 totalPlugins, 738 totalNonPlugins); 739 740 } catch (CoreException e) { 741 UpdateCore.warn(null, e); 742 return ContentEntryModel.UNKNOWN_SIZE; 743 } 744 } 745 746 752 public IFeatureContentProvider getFeatureContentProvider() 753 throws CoreException { 754 if (featureContentProvider == null) { 755 throw Utilities.newCoreException( 756 NLS.bind(Messages.Feature_NoContentProvider, (new String [] { getVersionedIdentifier().toString() })), 757 null); 758 } 759 return this.featureContentProvider; 760 } 761 762 768 public IFeatureContentConsumer getFeatureContentConsumer() 769 throws CoreException { 770 throw new UnsupportedOperationException (); 771 } 772 773 779 public void setSite(ISite site) throws CoreException { 780 if (this.site != null) { 781 String featureURLString = 782 (getURL() != null) ? getURL().toExternalForm() : ""; throw Utilities.newCoreException( 784 NLS.bind(Messages.Feature_SiteAlreadySet, (new String [] { featureURLString })), 785 null); 786 } 787 this.site = site; 788 } 789 790 796 public void setFeatureContentProvider(IFeatureContentProvider featureContentProvider) { 797 this.featureContentProvider = featureContentProvider; 798 featureContentProvider.setFeature(this); 799 } 800 801 807 public String toString() { 808 String URLString = 809 (getURL() == null) 810 ? Messages.Feature_NoURL 811 : getURL().toExternalForm(); 812 813 String verString = 814 NLS.bind(Messages.Feature_FeatureVersionToString, (new String [] { URLString, getVersionedIdentifier().toString() })); 815 String label = getLabel() == null ? "" : getLabel(); return verString + " [" + label + "]"; } 818 819 822 private void abort() throws CoreException { 823 String msg = Messages.Feature_InstallationCancelled; 824 throw new InstallAbortedException(msg, null); 825 } 826 827 833 private void initializeIncludedReferences() throws CoreException { 834 includedFeatureReferences = new ArrayList (); 835 836 IIncludedFeatureReference[] nestedFeatures = getFeatureIncluded(); 837 if (nestedFeatures.length == 0) 838 return; 839 840 ISite site = getSite(); 841 if (site == null) 842 return; 843 844 for (int i = 0; i < nestedFeatures.length; i++) { 845 IIncludedFeatureReference include = nestedFeatures[i]; 846 IIncludedFeatureReference newRef = 847 getPerfectIncludeFeature(site, include); 848 includedFeatureReferences.add(newRef); 849 } 850 } 851 852 855 private IIncludedFeatureReference getPerfectIncludeFeature( 856 ISite site, 857 IIncludedFeatureReference include) 858 throws CoreException { 859 860 ISiteFeatureReference[] refs = site.getFeatureReferences(); 862 VersionedIdentifier identifier = include.getVersionedIdentifier(); 863 864 if ("file".equals(site.getURL().getProtocol())) { if (refs != null) { 870 for (int ref = 0; ref < refs.length; ref++) { 871 if (refs[ref] != null) { 872 VersionedIdentifier id = 873 refs[ref].getVersionedIdentifier(); 874 if (identifier.equals(id)) { 875 IncludedFeatureReference newRef = 877 new IncludedFeatureReference(refs[ref]); 878 newRef.isOptional(include.isOptional()); 879 if (include instanceof FeatureReferenceModel) 880 newRef.setLabel( 881 ((FeatureReferenceModel) include) 882 .getLabel()); 883 newRef.setSearchLocation( 884 include.getSearchLocation()); 885 return newRef; 886 } 887 } 888 } 889 } 890 } 891 892 IncludedFeatureReference newRef = new UpdateSiteIncludedFeatureReference(include); 895 newRef.setSite(getSite()); 896 IFeatureReference parentRef = getSite().getFeatureReference(this); 897 if (parentRef instanceof FeatureReference) { 898 newRef.setType(((FeatureReference) parentRef).getType()); 899 } 900 String featureID = Site.DEFAULT_FEATURE_PATH + identifier.toString(); 901 if(this instanceof TargetFeature) 902 featureID = featureID + "/"; else 904 featureID = featureID + ".jar"; URL featureURL = 906 getSite().getSiteContentProvider().getArchiveReference(featureID); 907 newRef.setURL(featureURL); 908 newRef.setFeatureIdentifier(identifier.getIdentifier()); 909 newRef.setFeatureVersion(identifier.getVersion().toString()); 910 try { 911 newRef.resolve(getSite().getURL(), null); 912 return newRef; 914 } catch (Exception e) { 915 throw Utilities.newCoreException( 916 NLS.bind(Messages.Feature_UnableToInitializeFeatureReference, (new String [] { identifier.toString() })), 917 e); 918 } 919 } 920 921 924 private void debug(String trace) { 925 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_INSTALL) { 927 UpdateCore.debug(trace); 928 } 929 } 930 931 934 private void setMonitorTaskName( 935 IProgressMonitor monitor, 936 String taskName) { 937 if (monitor != null) 938 monitor.setTaskName(taskName); 939 } 940 941 944 private void monitorWork(IProgressMonitor monitor, int tick) 945 throws CoreException { 946 if (monitor != null) { 947 monitor.worked(tick); 948 if (monitor.isCanceled()) { 949 abort(); 950 } 951 } 952 } 953 954 957 private void verifyReferences( 958 IVerifier verifier, 959 ContentReference[] references, 960 InstallMonitor monitor, 961 IVerificationListener verificationListener, 962 boolean isFeature) 963 throws CoreException { 964 IVerificationResult vr = null; 965 if (verifier != null) { 966 for (int j = 0; j < references.length; j++) { 967 vr = verifier.verify(this, references[j], isFeature, monitor); 968 if (vr != null) { 969 if (verificationListener == null) 970 return; 971 972 int result = verificationListener.prompt(vr); 973 974 if (result == IVerificationListener.CHOICE_ABORT) { 975 String msg = Messages.JarVerificationService_CancelInstall; 976 Exception e = vr.getVerificationException(); 977 throw new InstallAbortedException(msg, e); 978 } 979 if (result == IVerificationListener.CHOICE_ERROR) { 980 throw Utilities 981 .newCoreException( 982 Messages.JarVerificationService_UnsucessfulVerification, 983 vr.getVerificationException()); 984 } 985 } 986 } 987 } 988 } 989 990 994 private IFeatureReference featureAlreadyInstalled(ISite targetSite) { 995 996 ISiteFeatureReference[] references = targetSite.getFeatureReferences(); 997 IFeatureReference currentReference = null; 998 for (int i = 0; i < references.length; i++) { 999 currentReference = references[i]; 1000 try { 1002 if (this.equals(currentReference.getFeature(null))) 1003 return currentReference; } catch (CoreException e) { 1005 UpdateCore.warn(null, e); 1006 } 1007 } 1008 1009 UpdateCore.warn( 1010 "ValidateAlreadyInstalled:Feature " + this 1012 + " not found on site:" + this.getURL()); 1014 return null; 1015 } 1016 1017 1021 private void reinitializeFeature(IFeatureReference referenceToReinitialize) { 1022 1023 if (referenceToReinitialize == null) 1024 return; 1025 1026 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_CONFIGURATION) 1027 UpdateCore.debug( 1028 "Re initialize feature reference:" + referenceToReinitialize); 1030 IFeature feature = null; 1031 try { 1032 feature = referenceToReinitialize.getFeature(null); 1033 if (feature != null && feature instanceof Feature) { 1034 ((Feature) feature).initializeIncludedReferences(); 1035 } 1036 ISite site = referenceToReinitialize.getSite(); 1039 if (site == null) 1040 return; 1041 URL url = site.getURL(); 1042 if (url == null) 1043 return; 1044 if ("file".equals(url.getProtocol())) { IFeatureReference[] included = 1046 feature.getIncludedFeatureReferences(); 1047 for (int i = 0; i < included.length; i++) { 1048 reinitializeFeature(included[i]); 1049 } 1050 } 1051 } catch (CoreException e) { 1052 UpdateCore.warn("", e); } 1054 } 1055 1056 1059 public IIncludedFeatureReference[] getIncludedFeatureReferences() 1060 throws CoreException { 1061 return filterFeatures(getRawIncludedFeatureReferences()); 1062 } 1063 1064 1071 private IIncludedFeatureReference[] filterFeatures(IIncludedFeatureReference[] allIncluded) { 1072 List list = new ArrayList (); 1073 if (allIncluded != null) { 1074 for (int i = 0; i < allIncluded.length; i++) { 1075 IIncludedFeatureReference included = allIncluded[i]; 1076 if (UpdateManagerUtils.isValidEnvironment(included)) 1077 list.add(included); 1078 else { 1079 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_WARNINGS) { 1080 UpdateCore.warn( 1081 "Filtered out feature reference:" + included); } 1083 } 1084 } 1085 } 1086 1087 IIncludedFeatureReference[] result = 1088 new IIncludedFeatureReference[list.size()]; 1089 if (!list.isEmpty()) { 1090 list.toArray(result); 1091 } 1092 1093 return result; 1094 } 1095 1096 1099 public INonPluginEntry[] getNonPluginEntries() { 1100 return filterNonPluginEntry(getRawNonPluginEntries()); 1101 } 1102 1103 1108 private INonPluginEntry[] filterNonPluginEntry(INonPluginEntry[] all) { 1109 List list = new ArrayList (); 1110 if (all != null) { 1111 for (int i = 0; i < all.length; i++) { 1112 if (UpdateManagerUtils.isValidEnvironment(all[i])) 1113 list.add(all[i]); 1114 } 1115 } 1116 1117 INonPluginEntry[] result = new INonPluginEntry[list.size()]; 1118 if (!list.isEmpty()) { 1119 list.toArray(result); 1120 } 1121 1122 return result; 1123 } 1124 1125 1128 public IPluginEntry[] getPluginEntries() { 1129 return filterPluginEntry(getRawPluginEntries()); 1130 } 1131 1132 1135 public IImport[] getImports() { 1136 return filterImports(getRawImports()); 1137 } 1138 1139 1144 private IImport[] filterImports(IImport[] all) { 1145 List list = new ArrayList (); 1146 if (all != null) { 1147 for (int i = 0; i < all.length; i++) { 1148 if (UpdateManagerUtils.isValidEnvironment(all[i])) 1149 list.add(all[i]); 1150 } 1151 } 1152 1153 IImport[] result = new IImport[list.size()]; 1154 if (!list.isEmpty()) { 1155 list.toArray(result); 1156 } 1157 1158 return result; 1159 } 1160 1161} | Popular Tags |