SLING-5940 : Revert commit
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1755271 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index a593341..b29004d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,13 +23,13 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>27</version>
+ <version>26</version>
<relativePath />
</parent>
<artifactId>org.apache.sling.i18n</artifactId>
<packaging>bundle</packaging>
- <version>2.4.9-SNAPSHOT</version>
+ <version>2.4.8</version>
<name>Apache Sling Internationalization Support</name>
<description>
@@ -46,9 +46,9 @@
</properties>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/i18n</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/i18n</developerConnection>
- <url>http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/i18n</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.i18n-2.4.8</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.i18n-2.4.8</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.i18n-2.4.8</url>
</scm>
<build>
@@ -71,9 +71,7 @@
jackrabbit-jcr-commons;inline="org/apache/jackrabbit/util/ISO9075.*|org/apache/jackrabbit/util/XMLChar.*|org/apache/jackrabbit/util/Text.*|org/apache/jackrabbit/commons/json/Json*",
org.apache.sling.commons.osgi;inline="org/apache/sling/commons/osgi/ServiceUtil*|org/apache/sling/commons/osgi/PropertiesUtil*"
</Embed-Dependency>
- <Require-Capability>
- osgi.implementation;filter:="(&(osgi.implementation=osgi.http)(version=1.0))"
- </Require-Capability>
+
</instructions>
</configuration>
</plugin>
@@ -132,26 +130,6 @@
</build>
<dependencies>
<dependency>
- <groupId>org.osgi</groupId>
- <artifactId>osgi.core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.http.whiteboard</artifactId>
- <version>1.0.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.event</artifactId>
- <version>1.3.1</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- </dependency>
- <dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-jcr-commons</artifactId>
<version>2.2.4</version>
@@ -174,11 +152,28 @@
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.scheduler</artifactId>
<version>2.4.0</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+
<!-- Testing -->
<dependency>
<groupId>org.apache.sling</groupId>
@@ -191,11 +186,13 @@
<dependency>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
+ <version>2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
@@ -238,13 +235,13 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
- <version>1.7.6</version>
+ <version>1.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
- <version>1.2.17</version>
+ <version>1.2.13</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -274,7 +271,7 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
- <version>5.4.0</version>
+ <version>4.2.1</version>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/src/main/java/org/apache/sling/i18n/impl/I18NFilter.java b/src/main/java/org/apache/sling/i18n/impl/I18NFilter.java
index 6013f9a..d8d7fbf 100644
--- a/src/main/java/org/apache/sling/i18n/impl/I18NFilter.java
+++ b/src/main/java/org/apache/sling/i18n/impl/I18NFilter.java
@@ -53,7 +53,6 @@
import org.apache.sling.i18n.RequestLocaleResolver;
import org.apache.sling.i18n.ResourceBundleProvider;
import org.osgi.framework.Constants;
-import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -64,9 +63,7 @@
@SlingFilter(generateService = true,
order = 700, scope = { SlingFilterScope.REQUEST, SlingFilterScope.ERROR })
@Properties({
- @Property(name = HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN, value="/"),
- @Property(name = HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
- value = "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=org.apache.sling)"),
+ @Property(name = "pattern", value="/.*"),
@Property(name = Constants.SERVICE_DESCRIPTION, value = "Internationalization Support Filter"),
@Property(name = Constants.SERVICE_VENDOR, value = "The Apache Software Foundation") })
public class I18NFilter implements Filter {
@@ -259,7 +256,7 @@
}
@Override
- public Enumeration<Locale> getLocales() {
+ public Enumeration<?> getLocales() {
return Collections.enumeration(getLocaleList());
}
@@ -360,7 +357,7 @@
}
@Override
- public Enumeration<Locale> getLocales() {
+ public Enumeration<?> getLocales() {
return Collections.enumeration(getLocaleList());
}
diff --git a/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java b/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java
index 8065e22..009000b 100644
--- a/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java
+++ b/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java
@@ -48,7 +48,7 @@
/** default primary type (=resource type) for message entry dictionaries */
static final String RT_MESSAGE_ENTRY = "sling:MessageEntry";
-
+
static final String MIXIN_MESSAGE = "sling:Message";
static final String MIXIN_LANGUAGE = "mix:language";
@@ -102,7 +102,7 @@
protected void setParent(ResourceBundle parent) {
super.setParent(parent);
}
-
+
public ResourceBundle getParent() {
return parent;
}
@@ -164,6 +164,7 @@
*
* @throws NullPointerException if either of the parameters is {@code null}.
*/
+ @SuppressWarnings("deprecation")
private Map<String, Object> loadFully(final ResourceResolver resolver, Set<String> roots, Set<String> languageRoots) {
final String[] searchPath = resolver.getSearchPath();
diff --git a/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java b/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
index cd30d42..a034313 100644
--- a/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
+++ b/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
@@ -41,6 +41,8 @@
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingConstants;
import org.apache.sling.api.resource.LoginException;
@@ -54,6 +56,7 @@
import org.apache.sling.i18n.ResourceBundleProvider;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.ComponentContext;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
@@ -116,7 +119,7 @@
private ResourceResolver resourceResolver;
/**
- * Map of cached resource bundles indexed by a key combined of the base name
+ * Map of cached resource bundles indexed by a key combined of the base name
* and <code>Locale</code> used to load and identify the <code>ResourceBundle</code>.
*/
private final ConcurrentHashMap<Key, JcrResourceBundle> resourceBundleCache = new ConcurrentHashMap<Key, JcrResourceBundle>();
@@ -139,7 +142,7 @@
/**
* Each ResourceBundle is registered as a service. Each registration is stored in this map with the locale & base name used as a key.
*/
- private Map<Key, ServiceRegistration<ResourceBundle>> bundleServiceRegistrations;
+ private Map<Key, ServiceRegistration> bundleServiceRegistrations;
private boolean preloadBundles;
@@ -225,7 +228,7 @@
private boolean isDictionaryResource(final String path, final org.osgi.service.event.Event event) {
// language node changes happen quite frequently (https://issues.apache.org/jira/browse/SLING-2881)
- // therefore only consider changes either for sling:MessageEntry's
+ // therefore only consider changes either for sling:MessageEntry's
// or for JSON dictionaries
String resourceType = (String) event.getProperty(SlingConstants.PROPERTY_RESOURCE_TYPE);
if (resourceType == null) {
@@ -304,7 +307,7 @@
String baseName = bundle.getBaseName();
Locale locale = bundle.getLocale();
final Key key = new Key(baseName, locale);
-
+
// defer this job
ScheduleOptions options = scheduler.AT(new Date(System.currentTimeMillis() + invalidationDelay));
final String jobName = "JcrResourceBundleProvider: reload bundle with key " + key.toString();
@@ -324,7 +327,7 @@
resourceBundleCache.remove(key);
log.info("Reloading resource bundle for {}", key);
// unregister bundle
- ServiceRegistration<ResourceBundle> serviceRegistration = null;
+ ServiceRegistration serviceRegistration = null;
synchronized (this) {
serviceRegistration = bundleServiceRegistrations.remove(key);
}
@@ -361,9 +364,11 @@
/**
* Activates and configures this component with the repository access
* details and the default locale to use
- * @throws LoginException
+ * @throws LoginException
*/
- protected void activate(BundleContext context, Map<String, Object> props) throws LoginException {
+ protected void activate(ComponentContext context) throws LoginException {
+ Dictionary<?, ?> props = context.getProperties();
+
Map<String, Object> repoCredentials;
String user = PropertiesUtil.toString(props.get(PROP_USER), null);
if (user == null || user.length() == 0) {
@@ -381,8 +386,8 @@
this.defaultLocale = toLocale(localeString);
this.preloadBundles = PropertiesUtil.toBoolean(props.get(PROP_PRELOAD_BUNDLES), DEFAULT_PRELOAD_BUNDLES);
- this.bundleContext = context;
- this.bundleServiceRegistrations = new HashMap<Key, ServiceRegistration<ResourceBundle>>();
+ this.bundleContext = context.getBundleContext();
+ this.bundleServiceRegistrations = new HashMap<Key, ServiceRegistration>();
invalidationDelay = PropertiesUtil.toLong(props.get(PROP_INVALIDATION_DELAY), DEFAULT_INVALIDATION_DELAY);
if (this.resourceResolverFactory != null) { // this is only null during test execution!
if (repoCredentials == null) {
@@ -443,12 +448,12 @@
}
private void registerResourceBundle(Key key, JcrResourceBundle resourceBundle) {
- Dictionary<String, Object> serviceProps = new Hashtable<String, Object>();
+ Dictionary<Object, Object> serviceProps = new Hashtable<Object, Object>();
if (key.baseName != null) {
serviceProps.put("baseName", key.baseName);
}
serviceProps.put("locale", key.locale.toString());
- ServiceRegistration<ResourceBundle> serviceReg = bundleContext.registerService(ResourceBundle.class,
+ ServiceRegistration serviceReg = bundleContext.registerService(ResourceBundle.class.getName(),
resourceBundle, serviceProps);
synchronized (this) {
bundleServiceRegistrations.put(key, serviceReg);
@@ -532,7 +537,7 @@
languageRootPaths.clear();
synchronized (this) {
- for (ServiceRegistration<ResourceBundle> serviceReg : bundleServiceRegistrations.values()) {
+ for (ServiceRegistration serviceReg : bundleServiceRegistrations.values()) {
serviceReg.unregister();
}
bundleServiceRegistrations.clear();
diff --git a/src/main/java/org/apache/sling/i18n/package-info.java b/src/main/java/org/apache/sling/i18n/package-info.java
index a24a548..654c184 100644
--- a/src/main/java/org/apache/sling/i18n/package-info.java
+++ b/src/main/java/org/apache/sling/i18n/package-info.java
@@ -17,7 +17,8 @@
* under the License.
*/
-@org.osgi.annotation.versioning.Version("2.2.0")
+@Version("2.2.0")
package org.apache.sling.i18n;
+import aQute.bnd.annotation.Version;
diff --git a/src/test/java/org/apache/sling/i18n/impl/ConcurrentJcrResourceBundleLoadingTest.java b/src/test/java/org/apache/sling/i18n/impl/ConcurrentJcrResourceBundleLoadingTest.java
index 90f862c..2c7e476 100644
--- a/src/test/java/org/apache/sling/i18n/impl/ConcurrentJcrResourceBundleLoadingTest.java
+++ b/src/test/java/org/apache/sling/i18n/impl/ConcurrentJcrResourceBundleLoadingTest.java
@@ -26,9 +26,9 @@
import static org.powermock.api.mockito.PowerMockito.spy;
import static org.powermock.api.mockito.PowerMockito.verifyPrivate;
-import java.util.HashMap;
+import java.util.Hashtable;
import java.util.Locale;
-import java.util.Map;
+import java.util.ResourceBundle;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@@ -40,6 +40,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentContext;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@@ -54,15 +55,15 @@
@Mock JcrResourceBundle english;
@Mock JcrResourceBundle german;
-
+
private JcrResourceBundleProvider provider;
-
+
@Before
public void setup() throws Exception {
provider = spy(new JcrResourceBundleProvider());
- Map<String, Object> properties = new HashMap<String, Object>();
+ Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put("locale.default", "en");
- provider.activate(PowerMockito.mock(BundleContext.class), properties);
+ provider.activate(createComponentContext(properties));
doReturn(english).when(provider, "createResourceBundle", eq(null), eq(Locale.ENGLISH));
doReturn(german).when(provider, "createResourceBundle", eq(null), eq(Locale.GERMAN));
Mockito.when(german.getLocale()).thenReturn(Locale.GERMAN);
@@ -99,12 +100,12 @@
verifyPrivate(provider, times(1)).invoke("createResourceBundle", eq(null), eq(Locale.ENGLISH));
verifyPrivate(provider, times(1)).invoke("createResourceBundle", eq(null), eq(Locale.GERMAN));
}
-
+
@Test
public void newBundleUsedAfterReload() throws Exception {
provider.getResourceBundle(Locale.ENGLISH);
provider.getResourceBundle(Locale.GERMAN);
-
+
// reloading german should not reload any other bundle
provider.reloadBundle(new Key(null, Locale.GERMAN));
provider.getResourceBundle(Locale.ENGLISH);
@@ -117,12 +118,12 @@
verifyPrivate(provider, times(1)).invoke("createResourceBundle", eq(null), eq(Locale.ENGLISH));
verifyPrivate(provider, times(2)).invoke("createResourceBundle", eq(null), eq(Locale.GERMAN));
}
-
+
@Test
public void newBundleUsedAsParentAfterReload() throws Exception {
provider.getResourceBundle(Locale.ENGLISH);
provider.getResourceBundle(Locale.GERMAN);
-
+
// reloading english should also reload german (because it has english as a parent)
provider.reloadBundle(new Key(null, Locale.ENGLISH));
provider.getResourceBundle(Locale.ENGLISH);
@@ -135,4 +136,11 @@
verifyPrivate(provider, times(2)).invoke("createResourceBundle", eq(null), eq(Locale.ENGLISH));
verifyPrivate(provider, times(2)).invoke("createResourceBundle", eq(null), eq(Locale.GERMAN));
}
+
+ private ComponentContext createComponentContext(Hashtable<String, Object> config) {
+ final ComponentContext componentContext = PowerMockito.mock(ComponentContext.class);
+ Mockito.when(componentContext.getBundleContext()).thenReturn(PowerMockito.mock(BundleContext.class));
+ Mockito.when(componentContext.getProperties()).thenReturn(config);
+ return componentContext;
+ }
}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/i18n/it/ResourceBundleProviderIT.java b/src/test/java/org/apache/sling/i18n/it/ResourceBundleProviderIT.java
index 736b9f3..1e2fa25 100644
--- a/src/test/java/org/apache/sling/i18n/it/ResourceBundleProviderIT.java
+++ b/src/test/java/org/apache/sling/i18n/it/ResourceBundleProviderIT.java
@@ -21,7 +21,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
-import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import java.io.File;
import java.util.Locale;
@@ -78,8 +77,7 @@
final String launchpadVersion = System.getProperty("sling.launchpad.version", "LAUNCHPAD_VERSION_NOT_SET");
return new DefaultCompositeOption(
SlingPaxOptions.defaultLaunchpadOptions(launchpadVersion),
- CoreOptions.provision(CoreOptions.bundle(thisProjectsBundle.toURI().toString())),
- mavenBundle("org.apache.felix", "org.apache.felix.http.servlet-api", "1.1.2")
+ CoreOptions.provision(CoreOptions.bundle(thisProjectsBundle.toURI().toString()))
).getOptions();
}
@@ -144,7 +142,6 @@
private void assertMessages(final String key, final String deMessage, final String deDeMessage, final String frMessage) {
new Retry(RETRY_TIMEOUT_MSEC) {
- @Override
protected void exec() {
{
final ResourceBundle deDE = resourceBundleProvider.getResourceBundle(Locale.GERMANY); // this is the resource bundle for de_DE
@@ -189,7 +186,7 @@
session.save();
// since "en" is the fallback for all other resource bundle, the value from "en" must be exposed
assertMessages(MSG_KEY2, "EN_message", "EN_message", "EN_message");
-
+
new Message("", MSG_KEY1, "DE_message", false).add(deRoot);
new Message("", MSG_KEY1, "FR_message", false).add(frRoot);
session.save();
@@ -199,13 +196,13 @@
new Message("", MSG_KEY1, "FR_changed", false).add(frRoot);
session.save();
assertMessages(MSG_KEY1, "DE_changed", "DE_changed", "FR_changed");
-
+
new Message("", MSG_KEY1, "DE_message", false).add(deRoot);
new Message("", MSG_KEY1, "DE_DE_message", false).add(deDeRoot);
new Message("", MSG_KEY1, "FR_message", false).add(frRoot);
session.save();
assertMessages(MSG_KEY1, "DE_message", "DE_DE_message", "FR_message");
-
+
// now change a key which is only available in the "en" dictionary
new Message("", MSG_KEY2, "EN_changed", false).add(enRoot);
session.save();