1 9 package org.eclipse.pde.internal.build.site; 10 11 import java.io.*; 12 import java.net.MalformedURLException ; 13 import java.net.URL ; 14 import java.util.ArrayList ; 15 import java.util.Properties ; 16 import org.eclipse.core.runtime.IPath; 17 import org.eclipse.core.runtime.Path; 18 import org.eclipse.pde.internal.build.Utils; 19 import org.eclipse.update.configurator.ConfiguratorUtils; 20 import org.eclipse.update.configurator.IPlatformConfiguration; 21 22 public class PluginPathFinder { 23 private static final String URL_PROPERTY = "org.eclipse.update.resolution_url"; private static final String EMPTY_STRING = ""; 26 33 private static String getSitePath(String platformHome, File linkFile, boolean features) { 34 String prefix = new Path(platformHome).removeLastSegments(1).toString(); 35 Properties properties = new Properties (); 36 try { 37 FileInputStream fis = new FileInputStream(linkFile); 38 properties.load(fis); 39 fis.close(); 40 String path = properties.getProperty("path"); if (path != null) { 42 if (!new Path(path).isAbsolute()) 43 path = prefix + IPath.SEPARATOR + path; 44 path += IPath.SEPARATOR + "eclipse" + IPath.SEPARATOR; if (features) 46 path += "features"; else 48 path += "plugins"; if (new File(path).exists()) { 50 return path; 51 } 52 } 53 } catch (IOException e) { 54 } 55 return null; 56 } 57 58 64 private static File[] getSites(String platformHome, boolean features) { 65 ArrayList sites = new ArrayList (); 66 67 File file = new File(platformHome, features ? "features" : "plugins"); if (!features && !file.exists()) 69 file = new File(platformHome); 70 if (file.exists()) 71 sites.add(file); 72 73 File[] linkFiles = new File(platformHome + IPath.SEPARATOR + "links").listFiles(); if (linkFiles != null) { 75 for (int i = 0; i < linkFiles.length; i++) { 76 String path = getSitePath(platformHome, linkFiles[i], features); 77 if (path != null) { 78 sites.add(new File(path)); 79 } 80 } 81 } 82 return (File[]) sites.toArray(new File[sites.size()]); 83 } 84 85 public static File[] getFeaturePaths(String platformHome) { 86 return getPaths(platformHome, true); 87 } 88 89 public static File[] getPluginPaths(String platformHome) { 90 return getPaths(platformHome, false); 91 } 92 93 public static File[] getPaths(String platformHome, boolean features) { 94 File file = new File(platformHome, "configuration/org.eclipse.update/platform.xml"); if (file.exists()) { 96 try { 97 String value = new Path(platformHome).toFile().toURL().toExternalForm(); 98 System.setProperty(URL_PROPERTY, value); 99 try { 100 IPlatformConfiguration config = ConfiguratorUtils.getPlatformConfiguration(file.toURL()); 101 return Utils.asFile(getConfiguredSitesPaths(platformHome, config, features)); 102 } finally { 103 System.setProperty(URL_PROPERTY, EMPTY_STRING); 104 } 105 } catch (MalformedURLException e) { 106 } catch (IOException e) { 107 } 108 } 109 110 return Utils.asFile(scanLocations(getSites(platformHome, features))); 111 } 112 113 private static URL [] getConfiguredSitesPaths(String platformHome, IPlatformConfiguration configuration, boolean features) { 114 URL [] installPlugins = scanLocations(new File[] {new File(platformHome, features ? "features" : "plugins")}); URL [] extensionPlugins = getExtensionPluginURLs(configuration, features); 116 117 URL [] all = new URL [installPlugins.length + extensionPlugins.length]; 118 System.arraycopy(installPlugins, 0, all, 0, installPlugins.length); 119 System.arraycopy(extensionPlugins, 0, all, installPlugins.length, extensionPlugins.length); 120 return all; 121 } 122 123 129 private static URL [] getExtensionPluginURLs(IPlatformConfiguration config, boolean features) { 130 ArrayList extensionPlugins = new ArrayList (); 131 IPlatformConfiguration.ISiteEntry[] sites = config.getConfiguredSites(); 132 for (int i = 0; i < sites.length; i++) { 133 URL url = sites[i].getURL(); 134 if ("file".equalsIgnoreCase(url.getProtocol())) { String [] entries; 136 if (features) 137 entries = sites[i].getFeatures(); 138 else 139 entries = sites[i].getPlugins(); 140 for (int j = 0; j < entries.length; j++) { 141 try { 142 extensionPlugins.add(new File(url.getFile(), entries[j]).toURL()); 143 } catch (MalformedURLException e) { 144 } 145 } 146 } 147 } 148 return (URL []) extensionPlugins.toArray(new URL [extensionPlugins.size()]); 149 } 150 151 156 private static URL [] scanLocations(File[] sites) { 157 ArrayList result = new ArrayList (); 158 for (int i = 0; i < sites.length; i++) { 159 if (!sites[i].exists()) 160 continue; 161 File[] children = sites[i].listFiles(); 162 if (children != null) { 163 for (int j = 0; j < children.length; j++) { 164 try { 165 result.add(children[j].toURL()); 166 } catch (MalformedURLException e) { 167 } 168 } 169 } 170 } 171 return (URL []) result.toArray(new URL [result.size()]); 172 } 173 } 174 | Popular Tags |