1 11 package org.eclipse.update.internal.core; 12 13 import java.util.Collection ; 14 import java.util.HashMap ; 15 import java.util.HashSet ; 16 import java.util.Map ; 17 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.update.core.*; 20 23 public class PatchedFeature { 24 private IFeatureReference feature; 25 private Collection patches = new HashSet (); 26 29 public PatchedFeature(IFeatureReference feature) { 30 super(); 31 this.feature = feature; 32 } 33 public void addPatch(IFeatureReference patch) { 34 patches.add(patch); 35 } 36 39 public IFeatureReference getFeature() { 40 return feature; 41 } 42 45 public IFeatureReference[] getPatches() { 46 return (IFeatureReference[]) patches.toArray(new IFeatureReference[patches.size()]); 47 } 48 51 public IFeatureReference[] getFeatureAndPatches() { 52 IFeatureReference[] features = new IFeatureReference[patches.size() + 1]; 53 features[0] = feature; 54 System.arraycopy(getPatches(), 0, features, 1, patches.size()); 55 return features; 56 } 57 65 public FeaturePlugin[] getPlugins() { 66 Map plugins = new HashMap (); 69 IFeatureReference[] featureRefs = getFeatureAndPatches(); 70 for (int i = 0; i < featureRefs.length; i++) { 72 try { 73 IFeature feature = featureRefs[i].getFeature(null); 74 if (feature == null) { 75 UpdateCore.warn("Null Feature", new Exception ()); continue; 77 } 78 IPluginEntry[] entries = feature.getPluginEntries(); 80 for (int entr = 0; entr < entries.length; entr++) { 81 String pluginId = entries[entr].getVersionedIdentifier().getIdentifier(); 82 PluginVersionIdentifier pluginVersion = entries[entr].getVersionedIdentifier().getVersion(); 83 FeaturePlugin existingPlugin = (FeaturePlugin) plugins.get(pluginId); 85 if (existingPlugin != null && existingPlugin.getEntry().getVersionedIdentifier().getVersion().isGreaterOrEqualTo(pluginVersion)) { 86 continue; 88 } else { 89 plugins.put(pluginId, new FeaturePlugin(entries[entr], feature)); 90 } 91 } 92 } catch (CoreException e) { 93 UpdateCore.warn(null, e); 94 } 95 } 96 return (FeaturePlugin[]) plugins.values().toArray(new FeaturePlugin[plugins.size()]); 97 } 98 public String toString() { 99 StringBuffer str = new StringBuffer (feature.toString()); 100 IFeatureReference[] patches = getFeatureAndPatches(); 101 for (int i = 0; i < patches.length; i++) { 102 str.append(" +patch=" + patches[i].toString() + " "); } 104 return str.toString(); 105 } 106 } 107 | Popular Tags |