You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2014/01/24 10:04:55 UTC
svn commit: r1560925 - in /sling/trunk/contrib/extensions/i18n: ./
src/main/java/org/apache/sling/i18n/impl/
src/test/java/org/apache/sling/i18n/impl/
src/test/java/org/apache/sling/i18n/it/
Author: fmeschbe
Date: Fri Jan 24 09:04:55 2014
New Revision: 1560925
URL: http://svn.apache.org/r1560925
Log:
SLING-2881 JcrResourceBundleProvider clears the cache on mix:language changes
- Apply patch by Tobias Bocanegra (thanks alot).
- Completely disabled the integration test due to unavailability
of the pax test support (as well as the launchpad snapshot reference)
- Updated requirement to Java 6 due to use of Collections.newSetFromMap
Modified:
sling/trunk/contrib/extensions/i18n/pom.xml
sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java
sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java
sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/it/ResourceBundleProviderIT.java
Modified: sling/trunk/contrib/extensions/i18n/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/pom.xml?rev=1560925&r1=1560924&r2=1560925&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/i18n/pom.xml (original)
+++ sling/trunk/contrib/extensions/i18n/pom.xml Fri Jan 24 09:04:55 2014
@@ -41,6 +41,7 @@
<url.version>1.5.2</url.version>
<org.ops4j.pax.logging.DefaultServiceLog.level>INFO</org.ops4j.pax.logging.DefaultServiceLog.level>
<bundle.file.name>${basedir}/target/${project.build.finalName}.jar</bundle.file.name>
+ <sling.java.version>6</sling.java.version>
</properties>
<scm>
@@ -185,12 +186,15 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <!--
+ No release yet available, omit for now
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.paxexam.util</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
+ -->
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.testing</artifactId>
Modified: sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java?rev=1560925&r1=1560924&r2=1560925&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java (original)
+++ sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java Fri Jan 24 09:04:55 2014
@@ -19,8 +19,10 @@
package org.apache.sling.i18n.impl;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@@ -32,9 +34,12 @@ import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.query.Query;
+import org.apache.jackrabbit.util.ISO9075;
import org.apache.sling.api.SlingException;
+import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,23 +57,36 @@ public class JcrResourceBundle extends R
static final String PROP_LANGUAGE = "jcr:language";
+ /**
+ * java.util.Formatter pattern to build the XPath query to search for
+ * messages in a given root path (%s argument).
+ *
+ * @see #loadFully(ResourceResolver, Set, Set)
+ */
+ private static final String QUERY_MESSAGES_FORMAT = "/jcr:root%s//element(*,sling:Message)";
+
private final Map<String, Object> resources;
private final Locale locale;
+ private final Set<String> languageRoots = new HashSet<String>();
+
JcrResourceBundle(Locale locale, String baseName,
ResourceResolver resourceResolver) {
this.locale = locale;
-
+
long start = System.currentTimeMillis();
refreshSession(resourceResolver, true);
- final String loadQuery = getFullLoadQuery(locale, baseName);
- this.resources = loadFully(resourceResolver, loadQuery);
+ Set<String> roots = loadPotentialLanguageRoots(resourceResolver, locale, baseName);
+ this.resources = loadFully(resourceResolver, roots, this.languageRoots);
long end = System.currentTimeMillis();
- log.debug(
- "JcrResourceBundle: Fully loaded {} entries for {} (base: {}) in {}ms",
- new Object[] { resources.size(), locale, baseName,
- (end - start) });
+ if (log.isDebugEnabled()) {
+ log.debug(
+ "JcrResourceBundle: Fully loaded {} entries for {} (base: {}) in {}ms",
+ new Object[] { resources.size(), locale, baseName,
+ (end - start) });
+ log.debug("JcrResourceBundle: Language roots: {}", languageRoots);
+ }
}
static void refreshSession(ResourceResolver resolver, boolean keepChanges) {
@@ -84,6 +102,10 @@ public class JcrResourceBundle extends R
}
}
+ protected Set<String> getLanguageRootPaths() {
+ return languageRoots;
+ }
+
@Override
protected void setParent(ResourceBundle parent) {
super.setParent(parent);
@@ -120,98 +142,113 @@ public class JcrResourceBundle extends R
return resources.get(key);
}
+ /**
+ * Fully loads the resource bundle from the storage.
+ * <p>
+ * This method adds entries to the {@code languageRoots} set of strings.
+ * Therefore this method must not be called concurrently or the set
+ * must either be thread safe.
+ *
+ * @param resourceResolver The storage access (must not be {@code null})
+ * @param roots The set of (potential) disctionary subtrees. This must
+ * not be {@code null}. If empty, no resources will actually be
+ * loaded.
+ * @param languageRoots The set of actualy dictionary subtrees. While
+ * processing the resources, all subtrees listed in the {@code roots}
+ * set is added to this set if it actually contains resources. This
+ * must not be {@code null}.
+ * @return
+ *
+ * @throws NullPointerException if either of the parameters is {@code null}.
+ */
@SuppressWarnings("deprecation")
- private Map<String, Object> loadFully(
- final ResourceResolver resourceResolver, final String fullLoadQuery) {
- log.debug("Executing full load query {}", fullLoadQuery);
-
- // do an XPath query because this won't go away soon and still
- // (2011/04/04) is the fastest query language ...
- Iterator<Map<String, Object>> bundles = null;
- try {
- bundles = resourceResolver.queryResources(fullLoadQuery, Query.XPATH);
- } catch (final SlingException se) {
- log.error("Exception during resource query " + fullLoadQuery, se);
- }
-
+ private Map<String, Object> loadFully(final ResourceResolver resourceResolver, Set<String> roots, Set<String> languageRoots) {
final Map<String, Object> rest = new HashMap<String, Object>();
- if ( bundles != null ) {
- final String[] path = resourceResolver.getSearchPath();
+ for (String root: roots) {
+ String fullLoadQuery = String.format(QUERY_MESSAGES_FORMAT, ISO9075.encodePath(root));
- final List<Map<String, Object>> res0 = new ArrayList<Map<String, Object>>();
- for (int i = 0; i < path.length; i++) {
- res0.add(new HashMap<String, Object>());
+ log.debug("Executing full load query {}", fullLoadQuery);
+
+ // do an XPath query because this won't go away soon and still
+ // (2011/04/04) is the fastest query language ...
+ Iterator<Map<String, Object>> bundles = null;
+ try {
+ bundles = resourceResolver.queryResources(fullLoadQuery, Query.XPATH);
+ } catch (final SlingException se) {
+ log.error("Exception during resource query " + fullLoadQuery, se);
}
- while (bundles.hasNext()) {
- final Map<String, Object> row = bundles.next();
- final String jcrPath = (String) row.get(JCR_PATH);
- String key = (String) row.get(PROP_KEY);
+ if ( bundles != null ) {
+ final String[] path = resourceResolver.getSearchPath();
- if (key == null) {
- key = ResourceUtil.getName(jcrPath);
+ final List<Map<String, Object>> res0 = new ArrayList<Map<String, Object>>();
+ for (int i = 0; i < path.length; i++) {
+ res0.add(new HashMap<String, Object>());
}
- Map<String, Object> dst = rest;
- for (int i = 0; i < path.length; i++) {
- if (jcrPath.startsWith(path[i])) {
- dst = res0.get(i);
- break;
+ while (bundles.hasNext()) {
+ final Map<String, Object> row = bundles.next();
+ if (row.containsKey(PROP_VALUE)) {
+ final String jcrPath = (String) row.get(JCR_PATH);
+ String key = (String) row.get(PROP_KEY);
+
+ if (key == null) {
+ key = ResourceUtil.getName(jcrPath);
+ }
+
+ Map<String, Object> dst = rest;
+ for (int i = 0; i < path.length; i++) {
+ if (jcrPath.startsWith(path[i])) {
+ dst = res0.get(i);
+ break;
+ }
+ }
+
+ dst.put(key, row.get(PROP_VALUE));
}
}
- dst.put(key, row.get(PROP_VALUE));
- }
+ for (int i = path.length - 1; i >= 0; i--) {
+ final Map<String, Object> resources = res0.get(i);
+ if (!resources.isEmpty()) {
+ rest.putAll(resources);
+ // also remember root
+ languageRoots.add(root);
- for (int i = path.length - 1; i >= 0; i--) {
- rest.putAll(res0.get(i));
+ }
+ }
}
}
+
return rest;
}
- private static String getFullLoadQuery(final Locale locale,
- final String baseName) {
- final StringBuilder buf = new StringBuilder(64);
-
- buf.append("//element(*,mix:language)[");
-
+ private Set<String> loadPotentialLanguageRoots(ResourceResolver resourceResolver, Locale locale, String baseName) {
final String localeString = locale.toString();
- buf.append("@jcr:language='").
- append(localeString).
- append('\'');
final String localeStringLower = localeString.toLowerCase();
- if (!localeStringLower.equals(localeString)) {
- buf.append(" or @jcr:language='").
- append(localeStringLower).
- append('\'');
- }
final String localeRFC4646String = toRFC4646String(locale);
- if (!localeRFC4646String.equals(localeString)) {
- buf.append(" or @jcr:language='").
- append(localeRFC4646String).
- append('\'');
- final String localeRFC4646StringLower = localeRFC4646String.toLowerCase();
- if (!localeRFC4646StringLower.equals(localeRFC4646String)) {
- buf.append(" or @jcr:language='").
- append(localeRFC4646StringLower).
- append('\'');
- }
- }
+ final String localeRFC4646StringLower = localeRFC4646String.toLowerCase();
+
+ Set<String> paths = new HashSet<String>();
+ @SuppressWarnings("deprecation")
+ Iterator<Resource> bundles = resourceResolver.findResources("//element(*,mix:language)", Query.XPATH);
+ while (bundles.hasNext()) {
+ Resource bundle = bundles.next();
+ ValueMap properties = bundle.adaptTo(ValueMap.class);
+ String language = properties.get(PROP_LANGUAGE, String.class);
+ if (language != null && language.length() > 0) {
+ if (language.equals(localeString)
+ || language.equals(localeStringLower)
+ || language.equals(localeRFC4646String)
+ || language.equals(localeRFC4646StringLower)) {
- if (baseName != null) {
- buf.append(" and @");
- buf.append(PROP_BASENAME);
- if (baseName.length() > 0) {
- buf.append("='").append(baseName).append('\'');
+ if (baseName == null || baseName.equals(properties.get(PROP_BASENAME, ""))) {
+ paths.add(bundle.getPath());
+ }
+ }
}
}
-
- buf.append("]//element(*,sling:Message)");
- buf.append("[@").append(PROP_VALUE).append("]/(@");
- buf.append(PROP_KEY).append("|@").append(PROP_VALUE).append(")");
-
- return buf.toString();
+ return Collections.unmodifiableSet(paths);
}
// Would be nice if Locale.toString() output RFC 4646, but it doesn't
Modified: sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java?rev=1560925&r1=1560924&r2=1560925&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java (original)
+++ sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java Fri Jan 24 09:04:55 2014
@@ -22,6 +22,7 @@ import static org.apache.sling.i18n.impl
import static org.apache.sling.i18n.impl.JcrResourceBundle.PROP_LANGUAGE;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
@@ -37,6 +38,7 @@ import java.util.concurrent.ConcurrentHa
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.observation.Event;
import javax.jcr.observation.EventIterator;
import javax.jcr.observation.EventListener;
import javax.jcr.observation.ObservationManager;
@@ -67,8 +69,7 @@ import org.slf4j.LoggerFactory;
*/
@Component(immediate = true, metatype = true, label = "%provider.name", description = "%provider.description")
@Service(ResourceBundleProvider.class)
-public class JcrResourceBundleProvider implements ResourceBundleProvider,
- EventListener {
+public class JcrResourceBundleProvider implements ResourceBundleProvider {
private static final boolean DEFAULT_PRELOAD_BUNDLES = false;
@@ -117,7 +118,9 @@ public class JcrResourceBundleProvider i
* base name and <code>Locale</code> used to load and identify the
* <code>ResourceBundle</code>.
*/
- private final ConcurrentHashMap<Key, ResourceBundle> resourceBundleCache = new ConcurrentHashMap<JcrResourceBundleProvider.Key, ResourceBundle>();
+ private final ConcurrentHashMap<Key, JcrResourceBundle> resourceBundleCache = new ConcurrentHashMap<JcrResourceBundleProvider.Key, JcrResourceBundle>();
+
+ private final Set<String> languageRootPaths = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
/**
* Return root resource bundle as created on-demand by
@@ -168,21 +171,45 @@ public class JcrResourceBundleProvider i
// ---------- EventListener ------------------------------------------------
/**
- * Called whenever something is changed inside of <code>jcr:language</code>
- * or <code>sling:Message</code> nodes. We just removed all cached
+ * Observation support class that is used whenever something is changed inside of
+ * <code>sling:Message</code> nodes. We just removed all cached
* resource bundles in this case to force reloading them.
* <p>
* This is much simpler than analyzing the events and trying to be clever
* about which exact resource bundles to remove from the cache and at the
* same time care for any resource bundle dependencies.
- *
- * @param events The actual JCR events are ignored by this implementation.
*/
- public void onEvent(EventIterator events) {
- log.debug("onEvent: Resource changes, removing cached ResourceBundles");
- clearCache();
- preloadBundles();
- }
+ private final EventListener messageChangeHandler = new EventListener() {
+
+ public void onEvent(EventIterator events) {
+ log.debug("onEvent: Resource changes, removing cached ResourceBundles");
+ clearCache();
+ preloadBundles();
+ }
+ };
+
+ /**
+ * Observation support class that listens for changes of <code>mix:language</code> nodes.
+ * In this case we check if the given language is already loaded and only then invalidate the cache.
+ */
+ private final EventListener languageChangeHandler = new EventListener() {
+ public void onEvent(EventIterator events) {
+ log.debug("onEvent: Resource changes. checking for cached bundle.");
+ while (events.hasNext()) {
+ Event e = events.nextEvent();
+ try {
+ if (languageRootPaths.contains(e.getPath())) {
+ log.debug("onEvent: Detected change of cached language root {}, removing cached ResourceBundles", e.getPath());
+ clearCache();
+ preloadBundles();
+ return;
+ }
+ } catch (RepositoryException e1) {
+ // ignore
+ }
+ }
+ }
+ };
// ---------- SCR Integration ----------------------------------------------
@@ -267,7 +294,7 @@ public class JcrResourceBundleProvider i
Locale locale) {
final Key key = new Key(baseName, locale);
- ResourceBundle resourceBundle = resourceBundleCache.get(key);
+ JcrResourceBundle resourceBundle = resourceBundleCache.get(key);
if (resourceBundle == null) {
log.debug(
@@ -291,6 +318,9 @@ public class JcrResourceBundleProvider i
synchronized (this) {
bundleServiceRegistrations.add(serviceReg);
}
+
+ // register language root paths
+ languageRootPaths.addAll(resourceBundle.getLanguageRootPaths());
}
}
@@ -308,7 +338,7 @@ public class JcrResourceBundleProvider i
* @throws MissingResourceException If the <code>ResourceResolver</code>
* is not available to access the resources.
*/
- private ResourceBundle createResourceBundle(String baseName, Locale locale) {
+ private JcrResourceBundle createResourceBundle(String baseName, Locale locale) {
ResourceResolver resolver = getResourceResolver();
if (resolver == null) {
@@ -399,6 +429,7 @@ public class JcrResourceBundleProvider i
ResourceResolver resolver = null;
try {
if (repoCredentials == null) {
+ // TODO: use ServiceResourceResolver if available
resolver = fac.getAdministrativeResourceResolver(null);
} else {
resolver = fac.getResourceResolver(repoCredentials);
@@ -406,8 +437,10 @@ public class JcrResourceBundleProvider i
final Session s = resolver.adaptTo(Session.class);
ObservationManager om = s.getWorkspace().getObservationManager();
- om.addEventListener(this, 255, "/", true, null,
- new String[] { "mix:language", "sling:Message" }, true);
+ om.addEventListener(messageChangeHandler, 255, "/", true, null,
+ new String[] { "sling:Message" }, true);
+ om.addEventListener(languageChangeHandler, 255, "/", true, null,
+ new String[] { "mix:language" }, true);
resourceResolver = resolver;
@@ -433,6 +466,7 @@ public class JcrResourceBundleProvider i
private void clearCache() {
resourceBundleCache.clear();
+ languageRootPaths.clear();
ServiceRegistration[] serviceRegs;
synchronized (this) {
@@ -484,7 +518,8 @@ public class JcrResourceBundleProvider i
try {
ObservationManager om = s.getWorkspace().getObservationManager();
- om.removeEventListener(this);
+ om.removeEventListener(messageChangeHandler);
+ om.removeEventListener(languageChangeHandler);
} catch (Throwable t) {
log.info(
"releaseRepository: Problem unregistering as event listener",
Modified: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java?rev=1560925&r1=1560924&r2=1560925&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java (original)
+++ sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java Fri Jan 24 09:04:55 2014
@@ -40,6 +40,7 @@ import org.apache.sling.api.resource.Res
import org.apache.sling.commons.testing.jcr.RepositoryTestBase;
import org.apache.sling.commons.testing.jcr.RepositoryUtil;
import org.apache.sling.jcr.resource.JcrResourceUtil;
+import org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -66,8 +67,33 @@ public class JcrResourceBundleTest exten
public Iterator<Resource> findResources(String query,
String language) {
- // TODO Auto-generated method stub
- return null;
+ try {
+ final Query q = getSession().getWorkspace().getQueryManager().createQuery(query, language);
+ final QueryResult result = q.execute();
+ final NodeIterator nodes = result.getNodes();
+ return new Iterator<Resource>() {
+ public boolean hasNext() {
+ return nodes.hasNext();
+ }
+
+ public Resource next() {
+ Node node = nodes.nextNode();
+ try {
+ return new JcrNodeResource(resolver, node, null ,null);
+ } catch (RepositoryException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException("remove");
+ }
+ };
+ } catch (NamingException ne) {
+ return null;
+ } catch (RepositoryException re) {
+ return null;
+ }
}
public Resource getResource(Resource base, String path) {
@@ -109,7 +135,7 @@ public class JcrResourceBundleTest exten
return new Iterator<Map<String, Object>>() {
public boolean hasNext() {
return rows.hasNext();
- };
+ }
public Map<String, Object> next() {
Map<String, Object> row = new HashMap<String, Object>();
Modified: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/it/ResourceBundleProviderIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/it/ResourceBundleProviderIT.java?rev=1560925&r1=1560924&r2=1560925&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/it/ResourceBundleProviderIT.java (original)
+++ sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/it/ResourceBundleProviderIT.java Fri Jan 24 09:04:55 2014
@@ -18,27 +18,10 @@
*/
package org.apache.sling.i18n.it;
-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.bundle;
-import static org.ops4j.pax.exam.CoreOptions.provision;
import java.io.File;
-import java.util.Locale;
-import java.util.ResourceBundle;
-import javax.inject.Inject;
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.apache.sling.i18n.ResourceBundleProvider;
-import org.apache.sling.i18n.impl.Message;
-import org.apache.sling.jcr.api.SlingRepository;
-import org.apache.sling.paxexam.util.SlingPaxOptions;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
@@ -46,38 +29,36 @@ import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.options.DefaultCompositeOption;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class ResourceBundleProviderIT {
- private final Logger log = LoggerFactory.getLogger(getClass());
-
- public static final int RETRY_TIMEOUT_MSEC = 5000;
- public static final String MSG_KEY = "foo";
-
- @Inject
- private SlingRepository repository;
-
- @Inject
- private ResourceBundleProvider resourceBundleProvider;
-
- private Session session;
- private Node i18nRoot;
- private Node deRoot;
- private Node frRoot;
-
+// private final Logger log = LoggerFactory.getLogger(getClass());
+//
+// public static final int RETRY_TIMEOUT_MSEC = 5000;
+// public static final String MSG_KEY = "foo";
+//
+// @Inject
+// private SlingRepository repository;
+//
+// @Inject
+// private ResourceBundleProvider resourceBundleProvider;
+//
+// private Session session;
+// private Node i18nRoot;
+// private Node deRoot;
+// private Node frRoot;
+
@org.ops4j.pax.exam.Configuration
public Option[] config() {
final File thisProjectsBundle = new File(System.getProperty( "bundle.file.name", "BUNDLE_FILE_NOT_SET" ));
return new DefaultCompositeOption(
- SlingPaxOptions.defaultLaunchpadOptions("7-SNAPSHOT"),
- provision(bundle(thisProjectsBundle.toURI().toString()))
+// SlingPaxOptions.defaultLaunchpadOptions("7-SNAPSHOT"),
+// provision(bundle(thisProjectsBundle.toURI().toString()))
).getOptions();
}
-
+
static abstract class Retry {
Retry(int timeoutMsec) {
final long timeout = System.currentTimeMillis() + timeoutMsec;
@@ -91,45 +72,51 @@ public class ResourceBundleProviderIT {
lastT = t;
}
}
-
+
if(lastT != null) {
fail("Failed after " + timeoutMsec + " msec: " + lastT);
}
}
-
+
protected abstract void exec() throws Exception;
}
-
+
+ @Test
+ public void test_dummy() {
+ System.err.println("All tests are disabled for now ....");
+ }
+
+/*
@Before
public void setup() throws RepositoryException {
session = repository.loginAdministrative(null);
final Node root = session.getRootNode();
Node libs = null;
if(root.hasNode("libs")) {
- libs = root.getNode("libs");
+ libs = root.getNode("libs");
} else {
- libs = root.addNode("libs", "nt:unstructured");
+ libs = root.addNode("libs", "nt:unstructured");
}
i18nRoot = libs.addNode("i18n", "nt:unstructured");
deRoot = addLanguageNode(i18nRoot, "de");
frRoot = addLanguageNode(i18nRoot, "fr");
session.save();
}
-
+
@After
public void cleanup() throws RepositoryException {
i18nRoot.remove();
session.save();
session.logout();
}
-
+
private Node addLanguageNode(Node parent, String language) throws RepositoryException {
final Node child = parent.addNode(language, "nt:folder");
child.addMixin("mix:language");
child.setProperty("jcr:language", language);
return child;
}
-
+
private void assertMessages(final String deMessage, final String frMessage) {
new Retry(RETRY_TIMEOUT_MSEC) {
protected void exec() {
@@ -150,12 +137,12 @@ public class ResourceBundleProviderIT {
@Test
public void testRepositoryName() {
final String name = repository.getDescriptor("jcr.repository.name");
- log.info("Test running on {} repository {}",
- name,
+ log.info("Test running on {} repository {}",
+ name,
repository.getDescriptor("jcr.repository.version"));
-
+
// We could use JUnit categories to select tests, as we
- // do in our integration tests, but let's avoid a dependency on
+ // do in our integration tests, but let's avoid a dependency on
// that in this module
if(System.getProperty("sling.run.modes", "").contains("oak")) {
assertEquals("Apache Jackrabbit Oak", name);
@@ -170,10 +157,11 @@ public class ResourceBundleProviderIT {
new Message("", MSG_KEY, "FR_message", false).add(frRoot);
session.save();
assertMessages("DE_message", "FR_message");
-
+
new Message("", MSG_KEY, "DE_changed", false).add(deRoot);
new Message("", MSG_KEY, "FR_changed", false).add(frRoot);
session.save();
assertMessages("DE_changed", "FR_changed");
}
+*/
}