You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2014/06/13 13:13:59 UTC
svn commit: r1602373 - in /sling/trunk/tooling/ide:
eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/
eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/impl/
impl-vlt/src/org/apache/sling/ide/jcr/
Author: rombert
Date: Fri Jun 13 11:13:59 2014
New Revision: 1602373
URL: http://svn.apache.org/r1602373
Log:
SLING-3647 - No repository found at ... URL scheme http not supported.
only
Replaced usage of RepositoryBuilder with direct instantiation of the
single known RepositoryFactory implementation.
Also removed a couple of now-stable TODOs.
Modified:
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/PluginLogger.java
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/impl/Tracer.java
sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/jcr/RepositoryUtils.java
Modified: sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/PluginLogger.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/PluginLogger.java?rev=1602373&r1=1602372&r2=1602373&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/PluginLogger.java (original)
+++ sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/PluginLogger.java Fri Jun 13 11:13:59 2014
@@ -78,4 +78,30 @@ public interface PluginLogger {
*/
void trace(String message, Object... arguments);
+ /**
+ * Sends a trace message using the platform debug facility
+ *
+ * <p>
+ * By default these trace messages are ignored, and are only logged if debugging is enabled for a specific plug-in.
+ * </p>
+ *
+ * <p>
+ * Usage guide:
+ * </p>
+ *
+ * <pre>
+ * try {
+ * // code here
+ * } catch (RuntimeException e) {
+ * logger.trace("An unexpected error has occured", e);
+ * }
+ * </pre>
+ *
+ * @param message A string message
+ * @param error the error that occured
+ *
+ * @see <a href="https://wiki.eclipse.org/FAQ_How_do_I_use_the_platform_debug_tracing_facility%3F">How do I use the
+ * platform debug tracing facility?</a>
+ */
+ void trace(String message, Throwable error);
}
Modified: sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/impl/Tracer.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/impl/Tracer.java?rev=1602373&r1=1602372&r2=1602373&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/impl/Tracer.java (original)
+++ sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/impl/Tracer.java Fri Jun 13 11:13:59 2014
@@ -59,6 +59,14 @@ public class Tracer implements DebugOpti
}
@Override
+ public void trace(String message, Throwable error) {
+ if (!debugEnabled)
+ return;
+
+ trace.trace("/debug", message, error);
+ }
+
+ @Override
public void warn(String message) {
logInternal(IStatus.WARNING, message, null);
}
Modified: sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/jcr/RepositoryUtils.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/jcr/RepositoryUtils.java?rev=1602373&r1=1602372&r2=1602373&view=diff
==============================================================================
--- sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/jcr/RepositoryUtils.java (original)
+++ sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/jcr/RepositoryUtils.java Fri Jun 13 11:13:59 2014
@@ -17,60 +17,34 @@
package org.apache.sling.ide.jcr;
import java.net.URISyntaxException;
-import java.util.Iterator;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
-import javax.imageio.spi.ServiceRegistry;
import javax.jcr.Credentials;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
+import org.apache.jackrabbit.vault.davex.DAVExRepositoryFactory;
import org.apache.jackrabbit.vault.fs.api.RepositoryAddress;
import org.apache.jackrabbit.vault.fs.api.RepositoryFactory;
-import org.apache.jackrabbit.vault.util.RepositoryProvider;
+import org.apache.sling.ide.impl.vlt.Activator;
import org.apache.sling.ide.transport.RepositoryInfo;
public abstract class RepositoryUtils {
- private static final String REPOSITORY_PROVIDER_NOT_YET_READY_MSG = "Repository provider not yet ready, please retry in a moment";
- private static final RepositoryProvider REPOSITORY_PROVIDER = new RepositoryProvider();
private static final Object SYNC = new Object();
private static final String[] WEBDAV_URL_LOCATIONS = new String[] { "server/-/jcr:root", "crx/-/jcr:root" };
- static {
- // force eager loading of class, making sure that it's found by the registry provider
- org.apache.jackrabbit.vault.davex.DAVExRepositoryFactory.class.getName();
- }
-
- /**
- * Tries to figure out, if the repository provider is ready.
- * <p>
- * Also see SLING-3647.
- * <p>
- * This is heuristic at the moment: it assumes readiness as soon as *any*
- * RepositoryFactory is registered. Whether or not a repository with
- * a particular address can be created, is then a second step.
- * <p>
- * @return
- */
- public static boolean isRepositoryProviderReady() {
- final Iterator<RepositoryFactory> providerIt = ServiceRegistry.lookupProviders(RepositoryFactory.class, RepositoryFactory.class.getClassLoader());
- final boolean isReady = providerIt.hasNext();
- return isReady;
- }
+ private static final RepositoryFactory FACTORY = new DAVExRepositoryFactory();
+ private static final Map<RepositoryAddress, Repository> REGISTERED_REPOSITORIES = new HashMap<RepositoryAddress, Repository>();
public static Repository getRepository(RepositoryInfo repositoryInfo) throws RepositoryException {
final RepositoryAddress repositoryAddress = getRepositoryAddress(repositoryInfo);
synchronized (SYNC) {
- try{
- return REPOSITORY_PROVIDER.getRepository(repositoryAddress);
- } catch(RepositoryException re) {
- if (isRepositoryProviderReady()) {
- throw re;
- } else {
- throw new RepositoryException(REPOSITORY_PROVIDER_NOT_YET_READY_MSG, re);
- }
- }
+ // will be populated implicitly by call to getRepositoryAddress
+ return REGISTERED_REPOSITORIES.get(repositoryAddress);
}
}
@@ -78,43 +52,48 @@ public abstract class RepositoryUtils {
StringBuilder errors = new StringBuilder();
for (String webDavUrlLocation : WEBDAV_URL_LOCATIONS) {
- Session session = null;
- String url = repositoryInfo.getUrl() + webDavUrlLocation;
- try {
- // TODO proper error handling
- RepositoryAddress address = new RepositoryAddress(url);
- Repository repository;
- synchronized (SYNC) {
- repository = REPOSITORY_PROVIDER.getRepository(address);
+ Session session = null;
+ String url = repositoryInfo.getUrl() + webDavUrlLocation;
+ try {
+ RepositoryAddress address = new RepositoryAddress(url);
+ Repository repository;
+ synchronized (SYNC) {
+ repository = REGISTERED_REPOSITORIES.get(address);
+
+ if (repository == null) {
+ Set<String> supportedSchemes = FACTORY.getSupportedSchemes();
+ if (!supportedSchemes.contains(address.getURI().getScheme())) {
+ throw new IllegalArgumentException("Unable to create a a repository for "
+ + address.getURI()
+ + ", since the scheme is unsupported. Only schemes '" + supportedSchemes
+ + "' are supported");
+ }
+ repository = FACTORY.createRepository(address);
+ REGISTERED_REPOSITORIES.put(address, repository);
}
+ }
- // TODO - this can be costly performance-wise ; we should cache this information
- session = repository.login(new SimpleCredentials(repositoryInfo.getUsername(), repositoryInfo
- .getPassword().toCharArray()));
- return address;
- } catch (URISyntaxException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- } catch (RepositoryException e) {
- e.printStackTrace();
- errors.append(url).append(" : ").append(e.getMessage()).append('\n');
- continue;
- } finally {
- if (session != null) {
- session.logout();
- }
+ session = repository.login(new SimpleCredentials(repositoryInfo.getUsername(), repositoryInfo
+ .getPassword().toCharArray()));
+ return address;
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ } catch (RepositoryException e) {
+ Activator.getDefault().getPluginLogger().trace("Failed connecting to repository at " + url, e);
+ errors.append(url).append(" : ").append(e.getMessage()).append('\n');
+ continue;
+ } finally {
+ if (session != null) {
+ session.logout();
}
+ }
}
errors.deleteCharAt(errors.length() - 1);
- IllegalArgumentException iae = new IllegalArgumentException("No repository found at " + repositoryInfo.getUrl() + "\n"
+ throw new IllegalArgumentException("No repository found at " + repositoryInfo.getUrl() + "\n"
+ errors.toString());
- if (isRepositoryProviderReady()) {
- throw iae;
- } else {
- throw new IllegalArgumentException(REPOSITORY_PROVIDER_NOT_YET_READY_MSG, iae);
- }
+
}
public static Credentials getCredentials(RepositoryInfo repositoryInfo) {