1 11 package org.eclipse.core.runtime; 12 13 import java.io.IOException ; 14 import java.lang.reflect.Method ; 15 import java.net.URL ; 16 import java.util.*; 17 import org.eclipse.core.internal.runtime.*; 18 import org.eclipse.core.internal.runtime.auth.AuthorizationHandler; 19 import org.eclipse.core.runtime.content.IContentTypeManager; 20 import org.eclipse.core.runtime.jobs.IJobManager; 21 import org.eclipse.core.runtime.jobs.Job; 22 import org.eclipse.core.runtime.preferences.IPreferencesService; 23 import org.eclipse.osgi.service.datalocation.Location; 24 import org.eclipse.osgi.service.debug.DebugOptions; 25 import org.eclipse.osgi.service.environment.EnvironmentInfo; 26 import org.eclipse.osgi.service.resolver.PlatformAdmin; 27 import org.osgi.framework.Bundle; 28 import org.osgi.service.packageadmin.PackageAdmin; 29 30 48 public final class Platform { 49 50 54 public static final String PI_RUNTIME = "org.eclipse.core.runtime"; 56 64 public static final String PT_APPLICATIONS = "applications"; 66 75 public static final String PT_ADAPTERS = "adapters"; 77 86 public static final String PT_PREFERENCES = Preferences.PT_PREFERENCES; 87 88 98 public static final String PT_PRODUCT = "products"; 100 106 public static final String OPTION_STARTTIME = PI_RUNTIME + "/starttime"; 108 124 public static final String PREF_PLATFORM_PERFORMANCE = "runtime.performance"; 126 133 public static final String PREF_LINE_SEPARATOR = "line.separator"; 135 140 public static final int MIN_PERFORMANCE = 1; 141 142 147 public static final int MAX_PERFORMANCE = 5; 148 149 153 public static final int PARSE_PROBLEM = 1; 154 155 158 public static final int PLUGIN_ERROR = 2; 159 160 164 public static final int INTERNAL_ERROR = 3; 165 166 170 public static final int FAILED_READ_METADATA = 4; 171 172 176 public static final int FAILED_WRITE_METADATA = 5; 177 178 182 public static final int FAILED_DELETE_METADATA = 6; 183 184 193 public static final String OS_WIN32 = "win32"; 195 204 public static final String OS_LINUX = "linux"; 206 215 public static final String OS_AIX = "aix"; 217 226 public static final String OS_SOLARIS = "solaris"; 228 237 public static final String OS_HPUX = "hpux"; 239 248 public static final String OS_QNX = "qnx"; 250 259 public static final String OS_MACOSX = "macosx"; 261 270 public static final String OS_UNKNOWN = "unknown"; 272 281 public static final String ARCH_X86 = "x86"; 283 292 public static final String ARCH_PA_RISC = "PA_RISC"; 294 303 public static final String ARCH_PPC = "ppc"; 305 314 public static final String ARCH_SPARC = "sparc"; 316 322 public static final String ARCH_X86_64 = "x86_64"; 324 332 public static final String ARCH_AMD64 = ARCH_X86_64; 333 334 340 public static final String ARCH_IA64 = "ia64"; 342 348 public static final String ARCH_IA64_32 = "ia64_32"; 350 359 public static final String WS_WIN32 = "win32"; 361 370 public static final String WS_MOTIF = "motif"; 372 381 public static final String WS_GTK = "gtk"; 383 392 public static final String WS_PHOTON = "photon"; 394 403 public static final String WS_CARBON = "carbon"; 405 410 public static final String WS_WPF = "wpf"; 412 421 public static final String WS_UNKNOWN = "unknown"; 423 private static final String LINE_SEPARATOR_KEY_MAC_OS_9 = Messages.line_separator_platform_mac_os_9; 425 private static final String LINE_SEPARATOR_KEY_UNIX = Messages.line_separator_platform_unix; 426 private static final String LINE_SEPARATOR_KEY_WINDOWS = Messages.line_separator_platform_windows; 427 428 private static final String LINE_SEPARATOR_VALUE_CR = "\r"; private static final String LINE_SEPARATOR_VALUE_LF = "\n"; private static final String LINE_SEPARATOR_VALUE_CRLF = "\r\n"; 432 435 private Platform() { 436 super(); 437 } 438 439 465 public static void addAuthorizationInfo(URL serverUrl, String realm, String authScheme, Map info) throws CoreException { 466 try { 467 AuthorizationHandler.addAuthorizationInfo(serverUrl, realm, authScheme, info); 468 } catch (NoClassDefFoundError e) { 469 logAuthNotAvailable(e); 471 } 472 } 473 474 487 public static void addLogListener(ILogListener listener) { 488 InternalPlatform.getDefault().addLogListener(listener); 489 } 490 491 508 public static void addProtectionSpace(URL resourceUrl, String realm) throws CoreException { 509 try { 510 AuthorizationHandler.addProtectionSpace(resourceUrl, realm); 511 } catch (NoClassDefFoundError e) { 512 logAuthNotAvailable(e); 514 } 515 } 516 517 538 public static URL asLocalURL(URL url) throws IOException { 539 return FileLocator.toFileURL(url); 540 } 541 542 546 public static void endSplash() { 547 InternalPlatform.getDefault().endSplash(); 548 } 549 550 570 public static void flushAuthorizationInfo(URL serverUrl, String realm, String authScheme) throws CoreException { 571 try { 572 AuthorizationHandler.flushAuthorizationInfo(serverUrl, realm, authScheme); 573 } catch (NoClassDefFoundError e) { 574 logAuthNotAvailable(e); 576 } 577 } 578 579 private static void logAuthNotAvailable(Throwable e) { 580 InternalPlatform.getDefault().log(new Status(IStatus.WARNING, Platform.PI_RUNTIME, 0, Messages.auth_notAvailable, e)); 581 } 582 583 592 public static IAdapterManager getAdapterManager() { 593 return InternalPlatform.getDefault().getAdapterManager(); 594 } 595 596 613 public static Map getAuthorizationInfo(URL serverUrl, String realm, String authScheme) { 614 try { 615 return AuthorizationHandler.getAuthorizationInfo(serverUrl, realm, authScheme); 616 } catch (NoClassDefFoundError e) { 617 logAuthNotAvailable(e); 619 } 620 return null; 621 } 622 623 635 public static String [] getCommandLineArgs() { 636 return InternalPlatform.getDefault().getCommandLineArgs(); 637 } 638 639 647 public static IContentTypeManager getContentTypeManager() { 648 return InternalPlatform.getDefault().getContentTypeManager(); 649 } 650 651 663 public static String getDebugOption(String option) { 664 return InternalPlatform.getDefault().getOption(option); 665 } 666 667 683 public static IPath getLocation() throws IllegalStateException { 684 return InternalPlatform.getDefault().getLocation(); 685 } 686 687 705 public static IPath getLogFileLocation() { 706 return InternalPlatform.getDefault().getMetaArea().getLogLocation(); 707 } 708 709 728 public static Plugin getPlugin(String id) { 729 try { 730 IPluginRegistry registry = getPluginRegistry(); 731 if (registry == null) 732 throw new IllegalStateException (); 733 IPluginDescriptor pd = registry.getPluginDescriptor(id); 734 if (pd == null) 735 return null; 736 return pd.getPlugin(); 737 } catch (CoreException e) { 738 } 740 return null; 741 } 742 743 752 public static IPluginRegistry getPluginRegistry() { 753 Bundle compatibility = InternalPlatform.getDefault().getBundle(CompatibilityHelper.PI_RUNTIME_COMPATIBILITY); 754 if (compatibility == null) 755 throw new IllegalStateException (); 756 757 Class oldInternalPlatform = null; 758 try { 759 oldInternalPlatform = compatibility.loadClass("org.eclipse.core.internal.plugins.InternalPlatform"); Method getPluginRegistry = oldInternalPlatform.getMethod("getPluginRegistry", null); return (IPluginRegistry) getPluginRegistry.invoke(oldInternalPlatform, null); 762 } catch (Exception e) { 763 } 765 return null; 766 767 } 768 769 785 public static IPath getPluginStateLocation(Plugin plugin) { 786 return plugin.getStateLocation(); 787 } 788 789 798 public static String getProtectionSpace(URL resourceUrl) { 799 try { 800 return AuthorizationHandler.getProtectionSpace(resourceUrl); 801 } catch (NoClassDefFoundError e) { 802 logAuthNotAvailable(e); 804 } 805 return null; 806 } 807 808 817 public static void removeLogListener(ILogListener listener) { 818 InternalPlatform.getDefault().removeLogListener(listener); 819 } 820 821 844 public static URL resolve(URL url) throws IOException { 845 return FileLocator.resolve(url); 846 } 847 848 856 public static void run(ISafeRunnable runnable) { 857 SafeRunner.run(runnable); 858 } 859 860 867 public static IJobManager getJobManager() { 868 return Job.getJobManager(); 869 } 870 871 878 public static IExtensionRegistry getExtensionRegistry() { 879 return InternalPlatform.getDefault().getRegistry(); 880 } 881 882 896 public static URL find(Bundle bundle, IPath path) { 897 return FileLocator.find(bundle, path, null); 898 } 899 900 952 public static URL find(Bundle bundle, IPath path, Map override) { 953 return FileLocator.find(bundle, path, override); 954 } 955 956 975 public static IPath getStateLocation(Bundle bundle) { 976 return InternalPlatform.getDefault().getStateLocation(bundle); 977 } 978 979 990 public static long getStateStamp() { 991 return InternalPlatform.getDefault().getStateTimeStamp(); 992 } 993 994 1005 public static ILog getLog(Bundle bundle) { 1006 return InternalPlatform.getDefault().getLog(bundle); 1007 } 1008 1009 1029 public static ResourceBundle getResourceBundle(Bundle bundle) throws MissingResourceException { 1030 return InternalPlatform.getDefault().getResourceBundle(bundle); 1031 } 1032 1033 1057 public static String getResourceString(Bundle bundle, String value) { 1058 return InternalPlatform.getDefault().getResourceString(bundle, value); 1059 } 1060 1061 1096 public static String getResourceString(Bundle bundle, String value, ResourceBundle resourceBundle) { 1097 return InternalPlatform.getDefault().getResourceString(bundle, value, resourceBundle); 1098 } 1099 1100 1112 public static String getOSArch() { 1113 return InternalPlatform.getDefault().getOSArch(); 1114 } 1115 1116 1126 public static String getNL() { 1127 return InternalPlatform.getDefault().getNL(); 1128 } 1129 1130 1144 public static String getOS() { 1145 return InternalPlatform.getDefault().getOS(); 1146 } 1147 1148 1159 public static String getWS() { 1160 return InternalPlatform.getDefault().getWS(); 1161 } 1162 1163 1172 public static String [] getApplicationArgs() { 1173 return InternalPlatform.getDefault().getApplicationArgs(); 1174 } 1175 1176 1193 public static PlatformAdmin getPlatformAdmin() { 1194 return InternalPlatform.getDefault().getPlatformAdmin(); 1195 } 1196 1197 1208 public static Location getInstanceLocation() { 1209 return InternalPlatform.getDefault().getInstanceLocation(); 1210 } 1211 1212 1221 public static IBundleGroupProvider[] getBundleGroupProviders() { 1222 return InternalPlatform.getDefault().getBundleGroupProviders(); 1223 } 1224 1225 1236 public static IPreferencesService getPreferencesService() { 1237 return InternalPlatform.getDefault().getPreferencesService(); 1238 } 1239 1240 1247 public static IProduct getProduct() { 1248 return InternalPlatform.getDefault().getProduct(); 1249 } 1250 1251 1260 public static void registerBundleGroupProvider(IBundleGroupProvider provider) { 1261 InternalPlatform.getDefault().registerBundleGroupProvider(provider); 1262 } 1263 1264 1274 public static void unregisterBundleGroupProvider(IBundleGroupProvider provider) { 1275 InternalPlatform.getDefault().unregisterBundleGroupProvider(provider); 1276 } 1277 1278 1293 public static Location getConfigurationLocation() { 1294 return InternalPlatform.getDefault().getConfigurationLocation(); 1295 } 1296 1297 1310 public static Location getUserLocation() { 1311 return InternalPlatform.getDefault().getUserLocation(); 1312 } 1313 1314 1325 public static Location getInstallLocation() { 1326 return InternalPlatform.getDefault().getInstallLocation(); 1327 } 1328 1329 1340 public static boolean isFragment(Bundle bundle) { 1341 return InternalPlatform.getDefault().isFragment(bundle); 1342 } 1343 1344 1357 public static Bundle[] getFragments(Bundle bundle) { 1358 return InternalPlatform.getDefault().getFragments(bundle); 1359 } 1360 1361 1377 public static Bundle getBundle(String symbolicName) { 1378 return InternalPlatform.getDefault().getBundle(symbolicName); 1379 } 1380 1381 1400 public static Bundle[] getBundles(String symbolicName, String version) { 1401 return InternalPlatform.getDefault().getBundles(symbolicName, version); 1402 } 1403 1404 1417 public static Bundle[] getHosts(Bundle bundle) { 1418 return InternalPlatform.getDefault().getHosts(bundle); 1419 } 1420 1421 1429 public static boolean isRunning() { 1430 return InternalPlatform.getDefault().isRunning(); 1431 } 1432 1433 1447 public static String [] knownOSArchValues() { 1448 return InternalPlatform.getDefault().knownOSArchValues(); 1449 } 1450 1451 1465 public static String [] knownOSValues() { 1466 return InternalPlatform.getDefault().knownOSValues(); 1467 } 1468 1469 1477 public static Map knownPlatformLineSeparators() { 1478 Map result = new HashMap(); 1479 result.put(LINE_SEPARATOR_KEY_MAC_OS_9, LINE_SEPARATOR_VALUE_CR); 1480 result.put(LINE_SEPARATOR_KEY_UNIX, LINE_SEPARATOR_VALUE_LF); 1481 result.put(LINE_SEPARATOR_KEY_WINDOWS, LINE_SEPARATOR_VALUE_CRLF); 1482 return result; 1483 } 1484 1485 1499 public static String [] knownWSValues() { 1500 return InternalPlatform.getDefault().knownWSValues(); 1501 } 1502 1503 1514 public static boolean inDebugMode() { 1515 return PlatformActivator.getContext().getProperty("osgi.debug") != null; } 1517 1518 1530 public static boolean inDevelopmentMode() { 1531 return PlatformActivator.getContext().getProperty("osgi.dev") != null; } 1533} 1534 | Popular Tags |