1 11 package org.eclipse.update.internal.core; 12 13 14 import java.io.*; 15 import java.net.*; 16 import java.util.ArrayList ; 17 import java.util.List ; 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.osgi.util.NLS; 20 import org.eclipse.update.core.*; 21 22 25 26 public class FeatureExecutableContentProvider extends FeatureContentProvider { 27 28 31 public FeatureExecutableContentProvider(URL url) { 32 super(url); 33 } 34 35 38 private String getPath(IPluginEntry pluginEntry) 39 throws IOException, CoreException { 40 41 ISiteContentProvider provider = getFeature().getSite().getSiteContentProvider(); 43 URL fileURL = provider.getArchiveReference(getPathID(pluginEntry)); 44 String result = fileURL.getFile(); 45 46 if (!result.endsWith(".jar") && !result.endsWith("/") && !result.endsWith(File.separator)) result += File.separator; 48 File pluginPath = new File(result); 49 if (!pluginPath.exists()) 50 throw new IOException( 51 NLS.bind(Messages.FeatureExecutableContentProvider_FileDoesNotExist, (new String [] { result }))); 52 53 return result; 54 } 55 56 59 private String getFeaturePath() throws IOException { 60 String result = getFeature().getURL().getFile(); 61 62 if (!(result.endsWith(File.separator) || result.endsWith("/"))) result += File.separator; 65 File pluginDir = new File(result); 66 if (!pluginDir.exists()) 67 throw new IOException( 68 NLS.bind(Messages.FeatureExecutableContentProvider_FileDoesNotExist, (new String [] { result }))); 69 70 return result; 71 } 72 73 77 private List getFiles(File dir) throws IOException { 78 List result = new ArrayList (); 79 80 if (!dir.isDirectory()) { 81 String msg = 82 NLS.bind(Messages.FeatureExecutableContentProvider_InvalidDirectory, (new String [] { dir.getAbsolutePath() })); 83 84 throw new IOException(msg); 85 86 } 87 88 File[] files = dir.listFiles(); 89 if (files != null) 90 for (int i = 0; i < files.length; ++i) { 91 if (files[i].isDirectory()) { 92 result.addAll(getFiles(files[i])); 93 } else { 94 result.add(files[i]); 95 } 96 } 97 98 return result; 99 } 100 101 104 public IVerifier getVerifier() throws CoreException { 105 return null; 106 } 107 108 111 public ContentReference getFeatureManifestReference(InstallMonitor monitor) 112 throws CoreException { 113 ContentReference result = null; 114 try { 115 result = new ContentReference(Feature.FEATURE_XML, new URL(getURL(), Feature.FEATURE_XML)); 116 117 } catch (MalformedURLException e) { 118 throw Utilities.newCoreException( 119 NLS.bind(Messages.FeatureExecutableContentProvider_UnableToCreateURLFor, (new String [] { getURL().toExternalForm() + " " + Feature.FEATURE_XML })), e); 121 } 122 return result; 123 } 124 125 128 public ContentReference[] getArchiveReferences(InstallMonitor monitor) 129 throws CoreException { 130 return new ContentReference[0]; 132 } 133 134 137 public ContentReference[] getPluginEntryArchiveReferences( 138 IPluginEntry pluginEntry, 139 InstallMonitor monitor) 140 throws CoreException { 141 ContentReference[] result = new ContentReference[1]; 142 String archiveID = getPathID(pluginEntry); 143 try { 144 File archiveFile = new File(getPath(pluginEntry)); 145 if(!archiveFile.isDirectory() && archiveFile.getName().endsWith(".jar")){ result[0] = new JarContentReference(archiveID, archiveFile); 147 } else { 148 result[0] = 149 new ContentReference(archiveID, archiveFile); 150 } 151 } catch (IOException e) { 152 throw Utilities.newCoreException( 153 NLS.bind(Messages.FeatureExecutableContentProvider_UnableToRetrievePluginEntry, (new String [] { pluginEntry.getVersionedIdentifier().toString() })), 154 e); 155 } 156 return result; 157 } 158 159 162 public ContentReference[] getNonPluginEntryArchiveReferences( 163 INonPluginEntry nonPluginEntry, 164 InstallMonitor monitor) 165 throws CoreException { 166 167 ContentReference[] result = new ContentReference[1]; 168 URL fileURL; 169 170 ISiteContentProvider provider = getFeature().getSite().getSiteContentProvider(); 173 fileURL = provider.getArchiveReference(getPathID(nonPluginEntry)); 174 175 String fileString = fileURL.getFile(); 176 File nonPluginData = new File(fileString); 177 if (!nonPluginData.exists()) 178 throw Utilities.newCoreException( 179 NLS.bind(Messages.FeatureExecutableContentProvider_FileDoesNotExist, (new String [] { fileString })), 180 null); 181 182 try { 183 result[0] = 184 new ContentReference(nonPluginEntry.getIdentifier(), nonPluginData.toURL()); 185 } catch (MalformedURLException e) { 186 throw Utilities.newCoreException( 187 NLS.bind(Messages.FeatureExecutableContentProvider_UnableToRetrieveNonPluginEntry, (new String [] { nonPluginEntry.getIdentifier().toString() })), 188 e); 189 } 190 return result; 191 } 192 193 196 public ContentReference[] getFeatureEntryArchiveReferences(InstallMonitor monitor) 197 throws CoreException { 198 ContentReference[] contentReferences = new ContentReference[1]; 199 contentReferences[0] = new ContentReference(null, getURL()); 200 return contentReferences; 201 } 202 203 206 public ContentReference[] getFeatureEntryContentReferences(InstallMonitor monitor) 207 throws CoreException { 208 ContentReference[] result = new ContentReference[0]; 209 try { 210 File featureDir = new File(getFeaturePath()); 211 List files = getFiles(featureDir); 212 result = new ContentReference[files.size()]; 213 for (int i = 0; i < result.length; i++) { 214 File currentFile = (File) files.get(i); 215 result[i] = new ContentReference(currentFile.getName(), currentFile.toURL()); 216 } 217 } catch (IOException e) { 218 throw Utilities.newCoreException( 219 NLS.bind(Messages.FeatureExecutableContentProvider_UnableToRetrieveFeatureEntry, (new String [] { getFeature().getVersionedIdentifier().toString() })), 220 e); 221 } 222 return result; 223 } 224 225 228 public ContentReference[] getPluginEntryContentReferences( 229 IPluginEntry pluginEntry, 230 InstallMonitor monitor) 231 throws CoreException { 232 233 ContentReference[] references = getPluginEntryArchiveReferences(pluginEntry, monitor); 234 ContentReference[] result = new ContentReference[0]; 235 236 try { 237 if (references[0] instanceof JarContentReference) { 238 result = ((JarContentReference)references[0]).peek(null, monitor); 239 } else { 240 File pluginDir = new File(getPath(pluginEntry)); 242 URL pluginURL = pluginDir.toURL(); 243 List files = getFiles(pluginDir); 244 result = new ContentReference[files.size()]; 245 for (int i = 0; i < result.length; i++) { 246 File currentFile = (File) files.get(i); 247 String relativeString = UpdateManagerUtils.getURLAsString(pluginURL, currentFile.toURL()); 248 result[i] = new ContentReference(relativeString, currentFile.toURL()); 249 } 250 } 251 } catch (IOException e) { 252 throw Utilities.newCoreException( 253 Messages.FeatureExecutableContentProvider_UnableToRetriveArchiveContentRef 254 + pluginEntry.getVersionedIdentifier().toString(), 255 e); 256 } 257 258 validatePermissions(result); 260 261 return result; 262 } 263 } 264 | Popular Tags |