1 11 12 package org.eclipse.update.internal.core; 13 14 import java.io.File ; 15 import java.io.IOException ; 16 import java.io.InputStream ; 17 import java.net.URL ; 18 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.Status; 21 import org.eclipse.update.core.BaseInstallHandler; 22 import org.eclipse.update.core.ContentReference; 23 import org.eclipse.update.core.IFeature; 24 import org.eclipse.update.core.IFeatureContentConsumer; 25 import org.eclipse.update.core.IPluginEntry; 26 import org.eclipse.update.core.PluginEntry; 27 import org.eclipse.update.core.Site; 28 import org.eclipse.update.internal.operations.UpdateUtils; 29 30 34 public class DeltaInstallHandler extends BaseInstallHandler { 35 private final static String PLUGIN_XML = "plugin.xml"; private final static String FRAGMENT_XML = "fragment.xml"; private final static String META_MANIFEST = "META-INF/MANIFEST.MF"; 39 protected IFeature oldFeature; 40 41 44 public void completeInstall(IFeatureContentConsumer consumer) 45 throws CoreException { 46 try { 47 if (pluginEntries == null) 48 return; 49 50 if (!feature.isPatch()) { 51 IFeature[] oldFeatures = UpdateUtils 53 .getInstalledFeatures(feature); 54 if (oldFeatures.length == 0) 55 return; 56 oldFeature = oldFeatures[0]; 57 } else { 58 oldFeature = UpdateUtils.getPatchedFeature(feature); 59 if (oldFeature == null) { 60 return; 61 } 62 } 63 64 IPluginEntry[] oldPlugins = oldFeature.getPluginEntries(); 65 for (int i = 0; i < pluginEntries.length; i++) { 66 IPluginEntry newPlugin = pluginEntries[i]; 67 IPluginEntry oldPlugin = 68 getPluginEntry( 69 oldPlugins, 70 newPlugin.getVersionedIdentifier().getIdentifier()); 71 if (oldPlugin == null) 72 continue; 73 try { 74 overlayPlugin(oldPlugin, newPlugin, consumer); 75 } catch (IOException e) { 76 throw new CoreException( 77 new Status( 78 Status.ERROR, 79 UpdateUtils.getPluginId(), 80 1, 81 "", e)); 83 } 84 } 85 } finally { 86 } 89 } 90 91 protected IPluginEntry getPluginEntry(IPluginEntry[] plugins, String id) { 92 for (int i = 0; i < plugins.length; i++) 93 if (plugins[i].getVersionedIdentifier().getIdentifier().equals(id)) 94 return plugins[i]; 95 return null; 96 } 97 98 protected boolean referenceExists( 99 ContentReference[] references, 100 ContentReference ref) { 101 String id = ref.getIdentifier(); 102 if (id == null) 103 return false; 104 105 for (int i = 0; i < references.length; i++) 106 if (id.equals(references[i].getIdentifier())) 107 return true; 108 return false; 109 } 110 111 protected void overlayPlugin( 112 IPluginEntry oldPlugin, 113 IPluginEntry newPlugin, 114 IFeatureContentConsumer consumer) 115 throws CoreException, IOException { 116 if(newPlugin instanceof PluginEntry && !((PluginEntry)newPlugin).isUnpack()){ 117 return; 119 } 120 121 ContentReference[] oldReferences = 124 oldFeature 125 .getFeatureContentProvider() 126 .getPluginEntryContentReferences( 127 oldPlugin, 128 null); 129 ContentReference[] newReferences = 130 feature 131 .getFeatureContentProvider() 132 .getPluginEntryContentReferences( 133 newPlugin, 134 null); 135 136 URL newURL = new URL (consumer.getFeature().getSite().getURL(), 137 Site.DEFAULT_PLUGIN_PATH 138 + newPlugin.getVersionedIdentifier().toString()); 139 String pluginPath = newURL.getFile(); 140 for (int i = 0; i < oldReferences.length; i++) { 141 if (isPluginManifest(oldReferences[i]) 142 || referenceExists(newReferences, oldReferences[i])) 143 continue; 144 145 InputStream input = null; 146 try { 147 input = oldReferences[i].getInputStream(); 148 File targetFile = 149 new File (pluginPath, oldReferences[i].getIdentifier()); 150 UpdateManagerUtils.copyToLocal( 151 input, 152 targetFile.getAbsolutePath(), 153 null); 154 UpdateManagerUtils.checkPermissions( 155 oldReferences[i], 156 pluginPath); 157 } catch (IOException e) { 159 continue; 160 } finally { 161 if(input != null){ 162 try{ 163 input.close(); 164 } catch (IOException ioe) { 165 } 166 } 167 } 168 } 169 } 170 171 protected boolean isPluginManifest(ContentReference ref) { 172 String id = ref.getIdentifier(); 173 return PLUGIN_XML.equals(id) || FRAGMENT_XML.equals(id) || META_MANIFEST.equals(id); 174 } 175 } 176 | Popular Tags |