diff options
author | John Arthorne | 2012-01-20 15:38:08 +0000 |
---|---|---|
committer | John Arthorne | 2012-01-20 15:40:43 +0000 |
commit | 8a44f23cc8c3bd7a2fcb884818fe3a8c190d6ec6 (patch) | |
tree | 74b587e8122b51b55f18d1fe564d4f5651f35c42 | |
parent | b3267338367b75b35c318b51d70026ca066e0fa7 (diff) | |
download | rt.equinox.bundles-8a44f23cc8c3bd7a2fcb884818fe3a8c190d6ec6.tar.gz rt.equinox.bundles-8a44f23cc8c3bd7a2fcb884818fe3a8c190d6ec6.tar.xz rt.equinox.bundles-8a44f23cc8c3bd7a2fcb884818fe3a8c190d6ec6.zip |
Bug 369200 - Platform.getResourceBundle should throw exception insteadv20120120-1540
of returning null
3 files changed, 22 insertions, 30 deletions
diff --git a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/Activator.java b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/Activator.java index 4f2420a4a..ab4aac863 100644 --- a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/Activator.java +++ b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/Activator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -22,6 +22,7 @@ import org.eclipse.osgi.service.datalocation.Location; import org.eclipse.osgi.service.debug.DebugOptions; import org.eclipse.osgi.service.localization.BundleLocalization; import org.eclipse.osgi.service.urlconversion.URLConverter; +import org.eclipse.osgi.util.NLS; import org.osgi.framework.*; import org.osgi.service.packageadmin.PackageAdmin; import org.osgi.service.url.URLConstants; @@ -59,20 +60,6 @@ public class Activator implements BundleActivator { return singleton; } - /** - * Print a debug message to the console. - * Pre-pend the message with the current date and the name of the current thread. - */ - public static void message(String message) { - StringBuffer buffer = new StringBuffer(); - buffer.append(new Date(System.currentTimeMillis())); - buffer.append(" - ["); //$NON-NLS-1$ - buffer.append(Thread.currentThread().getName()); - buffer.append("] "); //$NON-NLS-1$ - buffer.append(message); - System.out.println(buffer.toString()); - } - /* (non-Javadoc) * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) */ @@ -225,35 +212,36 @@ public class Activator implements BundleActivator { public String getBundleId(Object object) { if (object == null) return null; - if (bundleTracker == null) { - message("Bundle tracker is not set"); //$NON-NLS-1$ - return null; - } - PackageAdmin packageAdmin = (PackageAdmin) bundleTracker.getService(); + PackageAdmin packageAdmin = getBundleAdmin(); if (packageAdmin == null) return null; - Bundle source = packageAdmin.getBundle(object.getClass()); if (source != null && source.getSymbolicName() != null) return source.getSymbolicName(); return null; } - public ResourceBundle getLocalization(Bundle bundle, String locale) { + /** + * Returns the resource bundle responsible for location of the given bundle + * in the given locale. Does not return null. + * @throws MissingResourceException If the corresponding resource could not be found + */ + public ResourceBundle getLocalization(Bundle bundle, String locale) throws MissingResourceException { if (localizationTracker == null) { BundleContext context = Activator.getContext(); if (context == null) { - message("ResourceTranslator called before plugin is started"); //$NON-NLS-1$ - return null; + throw new MissingResourceException(CommonMessages.activator_resourceBundleNotStarted, bundle.getSymbolicName(), ""); //$NON-NLS-1$ } localizationTracker = new ServiceTracker(context, BundleLocalization.class.getName(), null); localizationTracker.open(); } BundleLocalization location = (BundleLocalization) localizationTracker.getService(); + ResourceBundle result = null; if (location != null) - return location.getLocalization(bundle, locale); - - return null; + result = location.getLocalization(bundle, locale); + if (result == null) + throw new MissingResourceException(NLS.bind(CommonMessages.activator_resourceBundleNotFound, locale), bundle.getSymbolicName(), ""); //$NON-NLS-1$ + return result; } /* (non-Javadoc) diff --git a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/CommonMessages.java b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/CommonMessages.java index bbe69523c..281626e2b 100644 --- a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/CommonMessages.java +++ b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/CommonMessages.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2005, 2006 IBM Corporation and others. All rights reserved. This + * Copyright (c) 2005, 2012 IBM Corporation and others. All rights reserved. This * program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -50,7 +50,9 @@ public class CommonMessages extends NLS { public static String parse_separatorStartVersion; public static String activator_not_available; - + public static String activator_resourceBundleNotFound; + public static String activator_resourceBundleNotStarted; + static { // load message values from bundle file reloadMessages(); diff --git a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/commonMessages.properties b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/commonMessages.properties index 5faef9316..894684181 100644 --- a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/commonMessages.properties +++ b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/commonMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2006 IBM Corporation and others. +# Copyright (c) 2000, 2012 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -44,3 +44,5 @@ url_resolveFragment = Unable to resolve fragment \"{0}\". url_resolvePlugin = Unable to resolve plug-in \"{0}\". activator_not_available = The bundle activator for the org.eclipse.equinox.common bundle is not available. +activator_resourceBundleNotFound=Resource bundle not found for locale: {0} +activator_resourceBundleNotStarted=ResourceTranslator called before plugin is started |