Bug 441367 - Backport fix for Translation service and @Message 

Change-Id: I12059398e6575549061dd07d249b80c14d382bd3
Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>

diff --git a/bundles/org.eclipse.e4.core.services/.settings/.api_filters b/bundles/org.eclipse.e4.core.services/.settings/.api_filters
new file mode 100644
index 0000000..c22078e
--- /dev/null
+++ b/bundles/org.eclipse.e4.core.services/.settings/.api_filters
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<component id="org.eclipse.e4.core.services" version="2">
+    <resource path="META-INF/MANIFEST.MF">
+        <filter id="924844039">
+            <message_arguments>
+                <message_argument value="1.2.1"/>
+                <message_argument value="1.2.0"/>
+            </message_arguments>
+        </filter>
+    </resource>
+    <resource path="src/org/eclipse/e4/core/services/nls/Message.java" type="org.eclipse.e4.core.services.nls.Message">
+        <filter id="1092616195">
+            <message_arguments>
+                <message_argument value="1.2.1"/>
+                <message_argument value="contributionURI()"/>
+            </message_arguments>
+        </filter>
+    </resource>
+</component>
diff --git a/bundles/org.eclipse.e4.core.services/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.core.services/META-INF/MANIFEST.MF
index 3b45e03..2ea12eb 100644
--- a/bundles/org.eclipse.e4.core.services/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.e4.core.services/META-INF/MANIFEST.MF
@@ -4,7 +4,7 @@
 Bundle-Name: %pluginName
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
-Bundle-Version: 1.2.0.qualifier
+Bundle-Version: 1.2.1.qualifier
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Import-Package: javax.annotation;version="1.1.0",
diff --git a/bundles/org.eclipse.e4.core.services/pom.xml b/bundles/org.eclipse.e4.core.services/pom.xml
index f347542..05c4964 100644
--- a/bundles/org.eclipse.e4.core.services/pom.xml
+++ b/bundles/org.eclipse.e4.core.services/pom.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-  Copyright (c) 2012 Eclipse Foundation.
+  Copyright (c) 2012, 2014 Eclipse Foundation.
   All rights reserved. This program and the accompanying materials
   are made available under the terms of the Eclipse Distribution License v1.0
   which accompanies this distribution, and is available at
@@ -19,6 +19,6 @@
   </parent>
   <groupId>org.eclipse.e4</groupId>
   <artifactId>org.eclipse.e4.core.services</artifactId>
-  <version>1.2.0-SNAPSHOT</version>
+  <version>1.2.1-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 </project>
diff --git a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/MessageFactoryServiceImpl.java b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/MessageFactoryServiceImpl.java
index f45b639..03c8312 100644
--- a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/MessageFactoryServiceImpl.java
+++ b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/MessageFactoryServiceImpl.java
@@ -157,9 +157,19 @@
 			ResourceBundleProvider rbProvider) {
 
 		ResourceBundle resourceBundle = null;
-		if (annotation != null && annotation.contributorURI().length() > 0) {
-			resourceBundle = ResourceBundleHelper.getResourceBundleForUri(
+		if (annotation != null) {
+			if (annotation.contributionURI().length() > 0) {
+				resourceBundle = ResourceBundleHelper.getResourceBundleForUri(
+						annotation.contributionURI(), locale, rbProvider);
+			} else if (annotation.contributorURI().length() > 0) {
+				if (logService != null) {
+					logService
+							.log(LogService.LOG_WARNING,
+									"Usage of @Message#contributorURI detected! Please use @Message#contributionURI instead!"); //$NON-NLS-1$
+				}
+				resourceBundle = ResourceBundleHelper.getResourceBundleForUri(
 					annotation.contributorURI(), locale, rbProvider);
+			}
 		}
 
 		if (resourceBundle == null) {
diff --git a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/ResourceBundleHelper.java b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/ResourceBundleHelper.java
index 1ac4749..a1c26af 100644
--- a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/ResourceBundleHelper.java
+++ b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/ResourceBundleHelper.java
@@ -62,7 +62,7 @@
 	private static final String PATH_SEPARATOR = "/"; //$NON-NLS-1$
 
 	/**
-	 * Parses the specified contributor URI and loads the {@link ResourceBundle} for the specified
+	 * Parses the specified contribution URI and loads the {@link ResourceBundle} for the specified
 	 * {@link Locale} out of an OSGi {@link Bundle}.
 	 * <p>
 	 * Following URIs are supported:
@@ -79,7 +79,7 @@
 	 * </ul>
 	 * </p>
 	 * 
-	 * @param contributorURI
+	 * @param contributionURI
 	 *            The URI that points to a {@link ResourceBundle}
 	 * @param locale
 	 *            The {@link Locale} to use for loading the {@link ResourceBundle}
@@ -88,19 +88,20 @@
 	 *            of the given {@link Bundle} which is specified by URI.
 	 * @return
 	 */
-	public static ResourceBundle getResourceBundleForUri(String contributorURI, Locale locale,
+	public static ResourceBundle getResourceBundleForUri(String contributionURI, Locale locale,
 			ResourceBundleProvider provider) {
-		if (contributorURI == null)
+		if (contributionURI == null)
 			return null;
 
 		LogService logService = ServicesActivator.getDefault().getLogService();
 
 		URI uri;
 		try {
-			uri = new URI(contributorURI);
+			uri = new URI(contributionURI);
 		} catch (URISyntaxException e) {
 			if (logService != null)
-				logService.log(LogService.LOG_ERROR, "Invalid contributor URI: " + contributorURI); //$NON-NLS-1$
+				logService
+						.log(LogService.LOG_ERROR, "Invalid contribution URI: " + contributionURI); //$NON-NLS-1$
 			return null;
 		}
 
@@ -126,7 +127,7 @@
 			if (uri.getAuthority() == null) {
 				if (logService != null)
 					logService.log(LogService.LOG_ERROR,
-							"Failed to get bundle for: " + contributorURI); //$NON-NLS-1$
+							"Failed to get bundle for: " + contributionURI); //$NON-NLS-1$
 			}
 			bundleName = uri.getAuthority();
 			// remove the leading /
@@ -134,8 +135,8 @@
 				classPath = uri.getPath().substring(1);
 			} else {
 				if (logService != null) {
-					logService.log(LogService.LOG_ERROR, "Called with invalid contributor URI: "
-							+ contributorURI);
+					logService.log(LogService.LOG_ERROR, "Called with invalid contribution URI: "
+							+ contributionURI);
 				}
 			}
 		}
@@ -157,7 +158,7 @@
 						if (logService != null)
 							logService
 									.log(LogService.LOG_ERROR,
-											"Failed to load specified ResourceBundle: " + contributorURI, e); //$NON-NLS-1$
+											"Failed to load specified ResourceBundle: " + contributionURI, e); //$NON-NLS-1$
 					}
 				} else if (resourcePath != null && resourcePath.length() > 0) {
 					// the specified URI points to a resource
diff --git a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/nls/Message.java b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/nls/Message.java
index d35c9c4..ab9e855 100644
--- a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/nls/Message.java
+++ b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/nls/Message.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013 Tom Schindl <tom.schindl@bestsolution.at> and others.
+ * Copyright (c) 2013, 2014 Tom Schindl <tom.schindl@bestsolution.at> 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
@@ -7,6 +7,9 @@
  *
  * Contributors:
  *     Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ *     Dirk Fauth <dirk.fauth@googlemail.com - Bug 440444, 440445
+ *     Lars Vogel <Lars.Vogel@gmail.com> - Bug 440444, 440445
+ *     Markus Keller <markus_keller@ch.ibm.com> - Bug 440445
  *******************************************************************************/
 package org.eclipse.e4.core.services.nls;
 
@@ -16,28 +19,145 @@
 /**
  * Annotation for message classes to control
  * <ul>
+ * <li>contribution uri to point to resource bundles in a different location</li>
  * <li>caching behavior</li>
- * <li>contribution uri to point it to a class or other file</li>
  * </ul>
- * 
+ *
+ * <p>
+ * <b>ResourceBundle location</b>
+ * </p>
+ *
+ * <p>
+ * Via the <code>contributionURI</code> parameter it is possible to specify the location of the
+ * resource bundle files. It supports the following location patterns:
+ * </p>
+ * <ul>
+ * <li>
+ * <code>platform:/[plugin|fragment]/[Bundle-SymbolicName]</code><br>
+ * Load the OSGi resource bundle out of the bundle/fragment named [Bundle-SymbolicName].<br>
+ * For example:<br>
+ * <code>@Message(contributionURI="platform:/plugin/com.example.e4.translation.extension")</code><br>
+ * will load the OSGi resource bundle that is configured in the <code>MANIFEST.MF</code> of the
+ * <code>com.example.e4.translation.extension</code> plug-in.</li>
+ * <li>
+ * <code>platform:/[plugin|fragment]/[Bundle-SymbolicName]/[Path]/[Basename]</code><br>
+ * Load the resource bundle specified by [Path] and [Basename] out of the bundle/fragment named
+ * [Bundle-SymbolicName].<br>
+ * For example:<br>
+ * <code>@Message(contributionURI="platform:/plugin/com.example.e4.translation/resources/another")</code>
+ * <br>
+ * will load the resource bundle that is located in the folder <i>resources/another</i> in the
+ * <code>com.example.e4.translation</code> plug-in.</li>
+ * <li>
+ * <code>bundleclass://[plugin|fragment]/[Bundle-SymbolicName]/[Fully-Qualified-Classname]</code><br>
+ * Instantiate the class-based resource bundle specified by [Fully-Qualified-Classname] out of the
+ * bundle/fragment named [Bundle-SymbolicName]. Note that the class needs to be a subtype of
+ * <code>ResourceBundle</code>.<br>
+ * For example:<br>
+ * <code>@Message(contributionURI="bundleclass://com.example.e4.translation/com.example.e4.translation.resources.MockBundle")</code>
+ * <br>
+ * will load the class-based resource bundle <code>MockBundle</code> in package
+ * <code>com.example.e4.translation.resources</code> in the <code>com.example.e4.translation</code>
+ * plug-in.</li>
+ * </ul>
+ *
+ * <p>
+ * <b>Note:</b><br>
+ * If the resource bundle files are located in the same package as the messages class having the
+ * same base name, or the OSGI resource bundle should be used (by default located in
+ * <i>OSGI-INF/l10n</i> with base name <i>bundle</i>) it is not necessary to specify the
+ * <code>contributionURI</code> parameter.
+ * </p>
+ *
+ * <p>
+ * <b>Caching behavior</b>
+ * </p>
+ *
+ * <p>
+ * Via the <code>referenceType</code> parameter it is possible to specify the caching behavior of
+ * message class instances.
+ * </p>
+ * <ul>
+ * <li>
+ * <code>ReferenceType.NONE</code><br>
+ * The message instance is not cached. Each requestor gets its own instance.</li>
+ * <li>
+ * <code>ReferenceType.WEAK</code><br>
+ * The message instance is cached as a weak reference. If every requestor was garbage collected, the
+ * message instance is also discarded at the next garbage collection cycle.</li>
+ * <li>
+ * <code>ReferenceType.SOFT</code><br>
+ * The message instance is cached as a soft reference. If every requestor was garbage collected, the
+ * message instance is not immediately discarded with the next garbage collection cycle, but will be
+ * retained for a while in memory. <b>This is the default configuration!</b></li>
+ * </ul>
+ *
+ * <p>
+ * <b>Examples:</b>
+ * </p>
+ *
+ * <p>
  * <b>Loading through a dedicated class</b>
- * 
+ * </p>
+ *
  * <pre>
- * &#064;Message(contributorURI = &quot;bundleclass://mybundle/my.ResourceBundleClass&quot;)
+ * &#064;Message(contributionURI = &quot;bundleclass://mybundle/my.ResourceBundleClass&quot;)
  * public class ResourceBundleClassMessages {
  * 	public String message_1;
  * }
  * </pre>
- * 
+ *
+ * <p>
+ * <b>No caching</b>
+ * </p>
+ *
+ * <pre>
+ * &#064;Message(referenceType = ReferenceType.NONE)
+ * public class ResourceBundleClassMessages {
+ * 	public String message_1;
+ * }
+ * </pre>
+ *
+ * <p>
+ * <b>Loading through a dedicated class with weak reference type</b>
+ * </p>
+ *
+ * <pre>
+ * &#064;Message(contributionURI = &quot;bundleclass://mybundle/my.ResourceBundleClass&quot;, referenceType = ReferenceType.WEAK)
+ * public class ResourceBundleClassMessages {
+ * 	public String message_1;
+ * }
+ * </pre>
+ *
  * @since 1.2
  */
 @Retention(RetentionPolicy.RUNTIME)
 public @interface Message {
+	/**
+	 * Caching behaviors.
+	 * 
+	 * @see Message
+	 */
 	public enum ReferenceType {
 		NONE, SOFT, WEAK
 	}
 
+	/**
+	 * @return optional caching behavior
+	 * @see Message
+	 */
 	ReferenceType referenceType() default ReferenceType.SOFT;
 
+	/**
+	 * @deprecated Use contributionURI instead
+	 */
+	@Deprecated
 	String contributorURI() default "";
+
+	/**
+	 * @return optional parameter to point to resource bundles in a different location
+	 * @see Message
+	 * @since 1.2.1
+	 */
+	String contributionURI() default "";
 }