1 11 package org.eclipse.update.internal.core; 12 13 14 import java.io.*; 15 import java.util.jar.*; 16 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.osgi.util.NLS; 19 import org.eclipse.update.core.*; 20 import org.eclipse.update.core.JarContentReference.*; 21 import org.eclipse.update.core.model.*; 22 23 26 public class DefaultInstallHandler extends BaseInstallHandler { 27 28 31 public void nonPluginDataDownloaded( 32 INonPluginEntry[] nonPluginData, 33 IVerificationListener listener) 34 throws CoreException { 35 36 if (nonPluginData == null || nonPluginData.length == 0) 40 return; 41 42 this.nonPluginEntries = nonPluginData; 43 IFeatureContentProvider provider = this.feature.getFeatureContentProvider(); 44 IVerifier verifier = provider.getVerifier(); 45 if (verifier == null) 46 return; 47 48 for (int i = 0; i < this.nonPluginEntries.length; i++) { 49 ContentReference[] archives = 50 provider.getNonPluginEntryArchiveReferences(nonPluginEntries[i], this.monitor); 51 IVerificationResult result; 52 for (int j = 0; j < archives.length; j++) { 53 54 ContentReference archive = archives[j]; 56 if (!(archives[j] instanceof JarContentReference) 57 && archives[j].getIdentifier().endsWith(".jar")) { try { 59 archive = 60 new JarContentReference(archives[j].getIdentifier(), archives[j].asFile()); 61 } catch (IOException e) { 62 } 63 } 64 65 result = verifier.verify(this.feature, archive, false, this.monitor); 66 if (result != null) 67 promptForVerification(result, listener); 68 } 69 } 70 } 71 72 75 public void completeInstall(IFeatureContentConsumer consumer) 76 throws CoreException { 77 78 if (this.nonPluginEntries == null || this.nonPluginEntries.length == 0) 81 return; 82 83 IFeatureContentProvider provider = this.feature.getFeatureContentProvider(); 85 for (int i = 0; i < this.nonPluginEntries.length; i++) { 86 ContentReference[] archive = 87 provider.getNonPluginEntryArchiveReferences(nonPluginEntries[i], this.monitor); 88 IContentConsumer nonPluginConsumer = consumer.open(nonPluginEntries[i]); 89 for (int j = 0; j < archive.length; j++) { 90 String id = archive[j].getIdentifier(); 91 if (id.endsWith(".jar")) { try { 95 final String prefix = id.substring(0, id.length() - 4) + "/"; JarContentReference jarRef = new JarContentReference("", archive[j].asFile()); ContentSelector selector = new ContentSelector() { 98 public String defineIdentifier(JarEntry entry) { 99 if (entry == null) 100 return null; 101 else 102 return prefix + entry.getName(); 103 } 104 }; 105 ContentReference[] entries = jarRef.peek(selector, this.monitor); 106 for (int k = 0; k < entries.length; k++) { 107 nonPluginConsumer.store(entries[k], this.monitor); 108 } 109 } catch (IOException e) { 110 throw Utilities 111 .newCoreException(NLS.bind(Messages.JarVerificationService_CancelInstall, (new String [] { id })), 112 e); 113 } 114 115 } else { 116 nonPluginConsumer.store(archive[j], this.monitor); 118 } 119 } 120 nonPluginConsumer.close(); 121 } 122 } 123 124 127 private void promptForVerification( 128 IVerificationResult verificationResult, 129 IVerificationListener listener) 130 throws CoreException { 131 132 if (listener == null) 133 return; 134 int result = listener.prompt(verificationResult); 135 136 if (result == IVerificationListener.CHOICE_ABORT) { 137 Exception e = verificationResult.getVerificationException(); 138 throw new InstallAbortedException(Messages.JarVerificationService_CancelInstall,e); 139 } 140 if (result == IVerificationListener.CHOICE_ERROR) { 141 throw Utilities 142 .newCoreException(Messages.JarVerificationService_UnsucessfulVerification, 143 verificationResult.getVerificationException()); 144 } 145 146 return; 147 } 148 } 149 | Popular Tags |