Author: spagop
Date: 2009-05-22 09:23:32 -0400 (Fri, 22 May 2009)
New Revision: 929
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java
Log:
changes made to support workspace features
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java 2009-05-22
13:22:45 UTC (rev 928)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java 2009-05-22
13:23:32 UTC (rev 929)
@@ -23,59 +23,58 @@
*/
package org.jboss.dna.connector.svn;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
+import java.util.List;
import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-import javax.naming.BinaryRefAddr;
+import java.util.concurrent.CopyOnWriteArraySet;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.RefAddr;
import javax.naming.Reference;
-import javax.naming.Referenceable;
import javax.naming.StringRefAddr;
import javax.naming.spi.ObjectFactory;
+import net.jcip.annotations.Immutable;
+import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.common.util.Logger;
+import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.graph.cache.CachePolicy;
import org.jboss.dna.graph.connector.RepositoryConnection;
import org.jboss.dna.graph.connector.RepositoryContext;
import org.jboss.dna.graph.connector.RepositorySource;
import org.jboss.dna.graph.connector.RepositorySourceCapabilities;
import org.jboss.dna.graph.connector.RepositorySourceException;
-import org.tmatesoft.svn.core.SVNException;
-import org.tmatesoft.svn.core.SVNURL;
-import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
-import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
-import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
-import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.io.SVNRepository;
-import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
-import org.tmatesoft.svn.core.wc.SVNWCUtil;
/**
- * A repository source that uses a SVN repository instance to manage the content. This
source is capable of using an existing
- * {@link SVNRepository} instance or creating a new instance. This process is controlled
entirely by the JavaBean properties of
- * the SVNRepositorySource instance. Like other {@link RepositorySource} classes,
instances of SVNRepositorySource can be placed
- * into JNDI and do support the creation of {@link Referenceable JNDI referenceable}
objects and resolution of references into
- * SVNRepositorySource. </p>
+ * The {@link RepositorySource} for the connector that exposes an area of the
local/remote svn repository as content in a
+ * repository. This source considers a workspace name to be the path to the directory on
the repository's root directory location
+ * that represents the root of that workspace. New workspaces can be created, as long as
the names represent valid paths to
+ * existing directories.
*
* @author Serge Pagop
*/
+@ThreadSafe
public class SVNRepositorySource implements RepositorySource, ObjectFactory {
- private static final long serialVersionUID = 1L;
/**
- * The default limit is {@value} for retrying {@link RepositoryConnection connection}
calls to the underlying source.
+ * The first serialized version of this source. Version {@value} .
*/
- public static final int DEFAULT_RETRY_LIMIT = 0;
+ private static final long serialVersionUID = 1L;
+ protected static final String SOURCE_NAME = "sourceName";
+ protected static final String SVN_REPOSITORY_ROOT_URL =
"repositoryRootURL";
+ protected static final String SVN_USERNAME = "username";
+ protected static final String SVN_PASSWORD = "password";
+ protected static final String CACHE_TIME_TO_LIVE_IN_MILLISECONDS =
"cacheTimeToLiveInMilliseconds";
+ protected static final String RETRY_LIMIT = "retryLimit";
+ protected static final String DEFAULT_WORKSPACE = "defaultWorkspace";
+ protected static final String PREDEFINED_WORKSPACE_NAMES =
"predefinedWorkspaceNames";
+ protected static final String ALLOW_CREATING_WORKSPACES =
"allowCreatingWorkspaces";
+
/**
* This source supports events.
*/
@@ -85,47 +84,41 @@
*/
protected static final boolean SUPPORTS_SAME_NAME_SIBLINGS = false;
/**
- * This source supports creating workspaces.
+ * This source does support creating workspaces.
*/
- protected static final boolean SUPPORTS_CREATING_WORKSPACES = false;
+ protected static final boolean DEFAULT_SUPPORTS_CREATING_WORKSPACES = true;
/**
+ * This source supports udpates by default, but each instance may be configured to be
read-only or updateable}.
+ */
+ public static final boolean DEFAULT_SUPPORTS_UPDATES = false;
+
+ /**
* This source supports creating references.
*/
protected static final boolean SUPPORTS_REFERENCES = false;
- /**
- * This source supports udpates by default, but each instance may be configured to
{@link #setSupportsUpdates(boolean) be
- * read-only or updateable}.
- */
- public static final boolean DEFAULT_SUPPORTS_UPDATES = true;
- public static final int DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS = 60 * 5; // 5 minutes
+ public static final int DEFAULT_RETRY_LIMIT = 0;
+ public static final int DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS = 60 * 5; // 5
+ // minutes
- protected static final String SOURCE_NAME = "sourceName";
- protected static final String DEFAULT_CACHE_POLICY = "defaultCachePolicy";
- protected static final String SVN_REPOS_JNDI_NAME = "svnReposJndiName";
- protected static final String SVN_REPOS_FACTORY_JNDI_NAME =
"svnReposFactoryJndiName";
- protected static final String SVN_URL = "svnURL";
- protected static final String SVN_USERNAME = "svnUsername";
- protected static final String SVN_PASSWORD = "svnPassword";
- protected static final String RETRY_LIMIT = "retryLimit";
+ private volatile String name;
+ private volatile String repositoryRootURL;
+ private volatile String username;
+ private volatile String password;
+ private volatile int retryLimit = DEFAULT_RETRY_LIMIT;
+ private volatile int cacheTimeToLiveInMilliseconds =
DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS * 1000;
+ private volatile String defaultWorkspace;
+ private volatile String[] predefinedWorkspaces = new String[] {};
+ private volatile RepositorySourceCapabilities capabilities = new
RepositorySourceCapabilities(
+
SUPPORTS_SAME_NAME_SIBLINGS,
+
DEFAULT_SUPPORTS_UPDATES,
+
SUPPORTS_EVENTS,
+
DEFAULT_SUPPORTS_CREATING_WORKSPACES,
+
SUPPORTS_REFERENCES);
- private final AtomicInteger retryLimit = new AtomicInteger(DEFAULT_RETRY_LIMIT);
- private String name;
- private String svnURL;
- private String svnUsername;
- private String svnPassword;
- private CachePolicy defaultCachePolicy;
+ private transient CachePolicy cachePolicy;
+ private transient CopyOnWriteArraySet<String> availableWorspaceNames;
- private RepositorySourceCapabilities capabilities = new
RepositorySourceCapabilities(SUPPORTS_SAME_NAME_SIBLINGS,
-
DEFAULT_SUPPORTS_UPDATES,
-
SUPPORTS_EVENTS,
-
SUPPORTS_CREATING_WORKSPACES,
-
SUPPORTS_REFERENCES);
-
- private transient Context jndiContext;
- private transient RepositoryContext repositoryContext;
- private transient SVNRepository svnRepository;
-
/**
* Create a repository source instance.
*/
@@ -143,187 +136,200 @@
/**
* {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.connector.RepositorySource#initialize(org.jboss.dna.graph.connector.RepositoryContext)
*/
- public void initialize( RepositoryContext context ) throws RepositorySourceException
{
- this.repositoryContext = context;
+ public String getName() {
+ return this.name;
}
/**
- * @return repositoryContext
+ * Set the name for the source
+ *
+ * @param name the new name for the source
*/
- public RepositoryContext getRepositoryContext() {
- return repositoryContext;
+ public synchronized void setName( String name ) {
+ if (name != null) {
+ name = name.trim();
+ if (name.length() == 0) name = null;
+ }
+ this.name = name;
}
/**
- * {@inheritDoc}
+ * @return the url
*/
- public String getName() {
- return this.name;
+ public String getRepositoryRootURL() {
+ return this.repositoryRootURL;
}
/**
- * {@inheritDoc}
+ * Set the url for the subversion repository.
*
- * @see org.jboss.dna.graph.connector.RepositorySource#getRetryLimit()
+ * @param url - the url location.
+ * @throws IllegalArgumentException If svn url is null or empty
*/
- public int getRetryLimit() {
- return retryLimit.get();
+ public void setRepositoryRootURL( String url ) {
+ CheckArg.isNotEmpty(url, "RepositoryRootURL");
+ this.repositoryRootURL = url;
}
+ public String getUsername() {
+ return this.username;
+ }
+
/**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.connector.RepositorySource#setRetryLimit(int)
+ * @param username
*/
- public void setRetryLimit( int limit ) {
- retryLimit.set(limit < 0 ? 0 : limit);
+ public void setUsername( String username ) {
+ this.username = username;
}
+ public String getPassword() {
+ return this.password;
+ }
+
/**
- * Set the name of this source
- *
- * @param name the name for this source
+ * @param password
*/
- public synchronized void setName( String name ) {
- if (this.name == name || this.name != null && this.name.equals(name))
return; // unchanged
- this.name = name;
+ public void setPassword( String password ) {
+ this.password = password;
}
/**
- * Get the default cache policy for this source, or null if the global default cache
policy should be used
+ * Get whether this source supports updates.
*
- * @return the default cache policy, or null if this source has no explicit default
cache policy
+ * @return true if this source supports updates, or false if this source only
supports reading content.
*/
- public CachePolicy getDefaultCachePolicy() {
- return defaultCachePolicy;
+ public boolean getSupportsUpdates() {
+ return capabilities.supportsUpdates();
}
/**
- * @param defaultCachePolicy Sets defaultCachePolicy to the specified value.
+ * Get the file system path to the existing directory that should be used for the
default workspace. If the default is
+ * specified as a null String or is not a valid and resolvable path, this source will
consider the default to be the current
+ * working directory of this virtual machine, as defined by the <code>new
File(".")</code>.
+ *
+ * @return the file system path to the directory representing the default workspace,
or null if the default should be the
+ * current working directory
*/
- public synchronized void setDefaultCachePolicy( CachePolicy defaultCachePolicy ) {
- if (this.defaultCachePolicy == defaultCachePolicy || this.defaultCachePolicy !=
null
- && this.defaultCachePolicy.equals(defaultCachePolicy)) return; //
unchanged
- this.defaultCachePolicy = defaultCachePolicy;
+ public String getDirectoryForDefaultWorkspace() {
+ return defaultWorkspace;
}
- public String getSVNURL() {
- return this.svnURL;
+ /**
+ * Set the file system path to the existing directory that should be used for the
default workspace. If the default is
+ * specified as a null String or is not a valid and resolvable path, this source will
consider the default to be the current
+ * working directory of this virtual machine, as defined by the <code>new
File(".")</code>.
+ *
+ * @param pathToDirectoryForDefaultWorkspace the valid and resolvable file system
path to the directory representing the
+ * default workspace, or null if the current working directory should be used
as the default workspace
+ */
+ public synchronized void setDirectoryForDefaultWorkspace( String
pathToDirectoryForDefaultWorkspace ) {
+ this.defaultWorkspace = pathToDirectoryForDefaultWorkspace;
}
/**
- * Set the url for the subversion repository.
+ * Gets the names of the workspaces that are available when this source is created.
Each workspace name corresponds to a path
+ * to a directory on the file system.
*
- * @param url - the url location.
- * @throws IllegalArgumentException If svn url is null or empty
+ * @return the names of the workspaces that this source starts with, or null if there
are no such workspaces
+ * @see #setPredefinedWorkspaceNames(String[])
+ * @see #setCreatingWorkspacesAllowed(boolean)
*/
- public void setSVNURL( String url ) {
- CheckArg.isNotEmpty(url, "SVNURL");
- this.svnURL = url;
+ public synchronized String[] getPredefinedWorkspaceNames() {
+ String[] copy = new String[predefinedWorkspaces.length];
+ System.arraycopy(predefinedWorkspaces, 0, copy, 0, predefinedWorkspaces.length);
+ return copy;
}
- public String getSVNUsername() {
- return this.svnUsername;
+ /**
+ * Sets the names of the workspaces that are available when this source is created.
Each workspace name corresponds to a path
+ * to a directory on the file system.
+ *
+ * @param predefinedWorkspaceNames the names of the workspaces that this source
should start with, or null if there are no
+ * such workspaces
+ * @see #setCreatingWorkspacesAllowed(boolean)
+ * @see #getPredefinedWorkspaceNames()
+ */
+ public synchronized void setPredefinedWorkspaceNames( String[]
predefinedWorkspaceNames ) {
+ this.predefinedWorkspaces = predefinedWorkspaceNames;
}
/**
- * @param username
+ * Get whether this source allows workspaces to be created dynamically.
+ *
+ * @return true if this source allows workspaces to be created by clients, or false
if the set of workspaces is fixed
+ * @see #setPredefinedWorkspaceNames(String[])
+ * @see #getPredefinedWorkspaceNames()
+ * @see #setCreatingWorkspacesAllowed(boolean)
*/
- public void setSVNUsername( String username ) {
- this.svnUsername = username;
+ public boolean isCreatingWorkspacesAllowed() {
+ return capabilities.supportsCreatingWorkspaces();
}
- public String getSVNPassword() {
- return this.svnPassword;
+ /**
+ * Set whether this source allows workspaces to be created dynamically.
+ *
+ * @param allowWorkspaceCreation true if this source allows workspaces to be created
by clients, or false if the set of
+ * workspaces is fixed
+ * @see #setPredefinedWorkspaceNames(String[])
+ * @see #getPredefinedWorkspaceNames()
+ * @see #isCreatingWorkspacesAllowed()
+ */
+ public synchronized void setCreatingWorkspacesAllowed( boolean allowWorkspaceCreation
) {
+ capabilities = new
RepositorySourceCapabilities(capabilities.supportsSameNameSiblings(),
capabilities.supportsUpdates(),
+ capabilities.supportsEvents(),
allowWorkspaceCreation,
+
capabilities.supportsReferences());
}
/**
- * @param password
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#getRetryLimit()
*/
- public void setSVNPassword( String password ) {
- this.svnPassword = password;
+ public int getRetryLimit() {
+ return retryLimit;
}
/**
- * Get whether this source supports updates.
+ * {@inheritDoc}
*
- * @return true if this source supports updates, or false if this source only
supports reading content.
+ * @see org.jboss.dna.graph.connector.RepositorySource#setRetryLimit(int)
*/
- public boolean getSupportsUpdates() {
- return capabilities.supportsUpdates();
+ public void setRetryLimit( int limit ) {
+ retryLimit = limit < 0 ? 0 : limit;
}
/**
- * Set whether this source supports updates.
+ * Get the time in milliseconds that content returned from this source may used while
in the cache.
*
- * @param supportsUpdates true if this source supports updating content, or false if
this source only supports reading
- * content.
+ * @return the time to live, in milliseconds, or 0 if the time to live is not
specified by this source
*/
- public synchronized void setSupportsUpdates( boolean supportsUpdates ) {
- capabilities = new
RepositorySourceCapabilities(capabilities.supportsSameNameSiblings(), supportsUpdates,
- capabilities.supportsEvents(),
capabilities.supportsCreatingWorkspaces(),
-
capabilities.supportsReferences());
+ public int getCacheTimeToLiveInMilliseconds() {
+ return cacheTimeToLiveInMilliseconds;
}
/**
- * {@inheritDoc}
+ * Set the time in milliseconds that content returned from this source may used while
in the cache.
*
- * @see org.jboss.dna.graph.connector.RepositorySource#getConnection()
+ * @param cacheTimeToLive the time to live, in milliseconds; 0 if the time to live is
not specified by this source; or a
+ * negative number for the default value
*/
- public RepositoryConnection getConnection() throws RepositorySourceException {
- if (getName() == null) {
- I18n msg = SVNRepositoryConnectorI18n.propertyIsRequired;
- throw new RepositorySourceException(getName(), msg.text("name"));
- }
- SVNURL svnURL = null;
- if (this.svnRepository == null) {
- try {
- svnURL = SVNURL.parseURIDecoded(getSVNURL());
- String usedProtocol = this.getSVNURL().substring(0,
this.getSVNURL().indexOf(":"));
- if (usedProtocol.equals(SVNProtocol.SVN.value()) ||
usedProtocol.equals(SVNProtocol.SVN_SSH.value())) {
- SVNRepositoryFactoryImpl.setup();
- this.svnRepository = SVNRepositoryFactory.create(svnURL);
- ISVNAuthenticationManager authManager =
SVNWCUtil.createDefaultAuthenticationManager(this.getSVNUsername(),
-
this.getSVNPassword());
- this.svnRepository.setAuthenticationManager(authManager);
- } else if (usedProtocol.equals(SVNProtocol.HTTP.value()) ||
usedProtocol.equals(SVNProtocol.HTTPS.value())) {
- DAVRepositoryFactory.setup();
- this.svnRepository = DAVRepositoryFactory.create(svnURL);
- ISVNAuthenticationManager authManager =
SVNWCUtil.createDefaultAuthenticationManager(this.getSVNUsername(),
-
this.getSVNPassword());
- this.svnRepository.setAuthenticationManager(authManager);
- } else if (usedProtocol.equals(SVNProtocol.FILE.value())) {
- FSRepositoryFactory.setup();
- this.svnRepository = FSRepositoryFactory.create(svnURL);
- ISVNAuthenticationManager authManager =
SVNWCUtil.createDefaultAuthenticationManager(this.getSVNUsername(),
-
this.getSVNPassword());
- this.svnRepository.setAuthenticationManager(authManager);
- } else {
- // protocol not supported by this connector
- throw new RepositorySourceException(getSVNURL(),
- "Protocol is not supported
by this connector or there is problem in the svn url");
- }
+ public synchronized void setCacheTimeToLiveInMilliseconds( int cacheTimeToLive ) {
+ if (cacheTimeToLive < 0) cacheTimeToLive =
DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS;
+ this.cacheTimeToLiveInMilliseconds = cacheTimeToLive;
+ this.cachePolicy = cacheTimeToLiveInMilliseconds > 0 ? new
SVNRepositoryCachePolicy(cacheTimeToLiveInMilliseconds) : null;
- } catch (SVNException ex) {
- I18n msg = SVNRepositoryConnectorI18n.propertyIsRequired;
- throw new RepositorySourceException(getSVNURL(),
msg.text(this.getSVNURL()), ex);
- }
- }
- boolean supportsUpdates = getSupportsUpdates();
- return new SVNRepositoryConnection(this.getName(), this.getDefaultCachePolicy(),
supportsUpdates, this.svnRepository);
}
- protected Context getContext() {
- return this.jndiContext;
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.graph.connector.RepositorySource#initialize(org.jboss.dna.graph.connector.RepositoryContext)
+ */
+ public synchronized void initialize( RepositoryContext context ) throws
RepositorySourceException {
+ // No need to do anything
}
- protected synchronized void setContext( Context context ) {
- this.jndiContext = context;
- }
-
/**
* {@inheritDoc}
*/
@@ -355,29 +361,25 @@
if (getName() != null) {
ref.add(new StringRefAddr(SOURCE_NAME, getName()));
}
- if (getSVNURL() != null) {
- ref.add(new StringRefAddr(SVN_URL, getSVNURL()));
+ if (getRepositoryRootURL() != null) {
+ ref.add(new StringRefAddr(SVN_REPOSITORY_ROOT_URL, getRepositoryRootURL()));
}
- if (getSVNUsername() != null) {
- ref.add(new StringRefAddr(SVN_USERNAME, getSVNUsername()));
+ if (getUsername() != null) {
+ ref.add(new StringRefAddr(SVN_USERNAME, getUsername()));
}
- if (getSVNPassword() != null) {
- ref.add(new StringRefAddr(SVN_PASSWORD, getSVNPassword()));
+ if (getPassword() != null) {
+ ref.add(new StringRefAddr(SVN_PASSWORD, getPassword()));
}
- if (getDefaultCachePolicy() != null) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- CachePolicy policy = getDefaultCachePolicy();
- try {
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(policy);
- ref.add(new BinaryRefAddr(DEFAULT_CACHE_POLICY, baos.toByteArray()));
- } catch (IOException e) {
- I18n msg =
SVNRepositoryConnectorI18n.errorSerializingCachePolicyInSource;
- throw new RepositorySourceException(getName(),
msg.text(policy.getClass().getName(), getName()), e);
- }
+ ref.add(new StringRefAddr(CACHE_TIME_TO_LIVE_IN_MILLISECONDS,
Integer.toString(getCacheTimeToLiveInMilliseconds())));
+ ref.add(new StringRefAddr(RETRY_LIMIT, Integer.toString(getRetryLimit())));
+ ref.add(new StringRefAddr(DEFAULT_WORKSPACE,
getDirectoryForDefaultWorkspace()));
+ ref.add(new StringRefAddr(ALLOW_CREATING_WORKSPACES,
Boolean.toString(isCreatingWorkspacesAllowed())));
+ String[] workspaceNames = getPredefinedWorkspaceNames();
+ if (workspaceNames != null && workspaceNames.length != 0) {
+ ref.add(new StringRefAddr(PREDEFINED_WORKSPACE_NAMES,
StringUtil.combineLines(workspaceNames)));
}
- ref.add(new StringRefAddr(RETRY_LIMIT, Integer.toString(getRetryLimit())));
return ref;
+
}
/**
@@ -391,7 +393,7 @@
Context nameCtx,
Hashtable<?, ?> environment ) throws Exception
{
if (obj instanceof Reference) {
- Map<String, Object> values = new HashMap<String, Object>();
+ Map<String, String> values = new HashMap<String, String>();
Reference ref = (Reference)obj;
Enumeration<?> en = ref.getAll();
while (en.hasMoreElements()) {
@@ -400,38 +402,153 @@
String key = subref.getType();
Object value = subref.getContent();
if (value != null) values.put(key, value.toString());
- } else if (subref instanceof BinaryRefAddr) {
- String key = subref.getType();
- Object value = subref.getContent();
- if (value instanceof byte[]) {
- // Deserialize ...
- ByteArrayInputStream bais = new
ByteArrayInputStream((byte[])value);
- ObjectInputStream ois = new ObjectInputStream(bais);
- value = ois.readObject();
- values.put(key, value);
- }
}
}
- String sourceName = (String)values.get(SOURCE_NAME);
- String svnURL = (String)values.get(SVN_URL);
- String svnUsername = (String)values.get(SVN_USERNAME);
- String svnPassword = (String)values.get(SVN_PASSWORD);
- Object defaultCachePolicy = values.get(DEFAULT_CACHE_POLICY);
- String retryLimit = (String)values.get(RETRY_LIMIT);
+ String sourceName = values.get(SOURCE_NAME);
+ String repositoryRootURL = values.get(SVN_REPOSITORY_ROOT_URL);
+ String username = values.get(SVN_USERNAME);
+ String password = values.get(SVN_PASSWORD);
+ String cacheTtlInMillis = values.get(CACHE_TIME_TO_LIVE_IN_MILLISECONDS);
+ String retryLimit = values.get(RETRY_LIMIT);
+ String defaultWorkspace = values.get(DEFAULT_WORKSPACE);
+ String createWorkspaces = values.get(ALLOW_CREATING_WORKSPACES);
+ String combinedWorkspaceNames = values.get(PREDEFINED_WORKSPACE_NAMES);
+ String[] workspaceNames = null;
+ if (combinedWorkspaceNames != null) {
+ List<String> paths =
StringUtil.splitLines(combinedWorkspaceNames);
+ workspaceNames = paths.toArray(new String[paths.size()]);
+ }
// Create the source instance ...
SVNRepositorySource source = new SVNRepositorySource();
if (sourceName != null) source.setName(sourceName);
- if (svnURL != null) source.setSVNURL(svnURL);
- if (svnUsername != null) source.setSVNUsername(svnUsername);
- if (svnPassword != null) source.setSVNPassword(svnPassword);
- if (defaultCachePolicy instanceof CachePolicy) {
- source.setDefaultCachePolicy((CachePolicy)defaultCachePolicy);
- }
+ if (cacheTtlInMillis != null)
source.setCacheTimeToLiveInMilliseconds(Integer.parseInt(cacheTtlInMillis));
+ if (repositoryRootURL != null)
source.setRepositoryRootURL(repositoryRootURL);
+ if (username != null) source.setUsername(username);
+ if (password != null) source.setPassword(password);
if (retryLimit != null) source.setRetryLimit(Integer.parseInt(retryLimit));
+ if (defaultWorkspace != null)
source.setDirectoryForDefaultWorkspace(defaultWorkspace);
+ if (createWorkspaces != null)
source.setCreatingWorkspacesAllowed(Boolean.parseBoolean(createWorkspaces));
+ if (workspaceNames != null && workspaceNames.length != 0)
source.setPredefinedWorkspaceNames(workspaceNames);
return source;
}
return null;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#getConnection()
+ */
+ public RepositoryConnection getConnection() throws RepositorySourceException {
+
+ String sourceName = getName();
+ if (sourceName == null || sourceName.trim().length() == 0) {
+ I18n msg = SVNRepositoryConnectorI18n.propertyIsRequired;
+ throw new RepositorySourceException(getName(), msg.text("name"));
+ }
+
+ String sourceUsername = getUsername();
+ if (sourceUsername == null || sourceUsername.trim().length() == 0) {
+ I18n msg = SVNRepositoryConnectorI18n.propertyIsRequired;
+ throw new RepositorySourceException(getUsername(),
msg.text("username"));
+ }
+
+ String sourcePassword = getPassword();
+ if (sourcePassword == null) {
+ I18n msg = SVNRepositoryConnectorI18n.propertyIsRequired;
+ throw new RepositorySourceException(getPassword(),
msg.text("password"));
+ }
+
+ String repositoryRootURL = getRepositoryRootURL();
+ if (repositoryRootURL == null || repositoryRootURL.trim().length() == 0) {
+ I18n msg = SVNRepositoryConnectorI18n.propertyIsRequired;
+ throw new RepositorySourceException(getRepositoryRootURL(),
msg.text("repositoryRootURL"));
+ }
+
+
+ SVNRepository repos = null;
+ // Report the warnings for non-existant predefined workspaces
+ boolean reportWarnings = false;
+ if (this.availableWorspaceNames == null) {
+ // Set up the predefined workspace names ...
+ this.availableWorspaceNames = new CopyOnWriteArraySet<String>();
+ for (String predefined : this.predefinedWorkspaces) {
+ // if exist e.i trunk/ /branches /tags
+ this.availableWorspaceNames.add(predefined);
+ }
+ // Report the warnings for non-existant predefined workspaces and we
+ // take it that if no predefined workspace exist
+ // we will take the repository root url as a pseudo workspace
+ reportWarnings = true;
+ for (String url : this.availableWorspaceNames) {
+ // check if the predefined workspaces exist.
+ if (repos != null) {
+ SVNRepositoryUtil.setNewSVNRepositoryLocation(repos, url, true,
sourceName);
+ } else {
+ repos = SVNRepositoryUtil.createRepository(url, sourceUsername,
sourcePassword);
+ }
+ if (!SVNRepositoryUtil.exist(repos)) {
+
+
Logger.getLogger(getClass()).warn(SVNRepositoryConnectorI18n.pathForPredefinedWorkspaceDoesNotExist,
+ url,
+ name);
+ }
+ if (!SVNRepositoryUtil.isDirectory(repos,"")) {
+
Logger.getLogger(getClass()).warn(SVNRepositoryConnectorI18n.pathForPredefinedWorkspaceIsNotDirectory,
+ url,
+ name);
+ }
+ }
+ }
+
+ boolean supportsUpdates = getSupportsUpdates();
+
+ SVNRepository defaultWorkspace = null;
+ if (repos != null) {
+ SVNRepositoryUtil.setNewSVNRepositoryLocation(repos, getRepositoryRootURL(),
true, sourceName);
+ defaultWorkspace = repos;
+ } else {
+ defaultWorkspace = SVNRepositoryUtil.createRepository(getRepositoryRootURL(),
sourceUsername, sourcePassword);
+ }
+
+ String defaultURL = getDirectoryForDefaultWorkspace();
+ if (defaultURL != null) {
+ // Look for the entry at this path .....
+ SVNRepository repository = SVNRepositoryUtil.createRepository(defaultURL,
+ sourceUsername,
+
sourcePassword);
+ I18n warning = null;
+ if (!SVNRepositoryUtil.exist(repository)) {
+ warning =
SVNRepositoryConnectorI18n.pathForPredefinedWorkspaceDoesNotExist;
+ } else if (!SVNRepositoryUtil.isDirectory(repository,"")) {
+ warning =
SVNRepositoryConnectorI18n.pathForPredefinedWorkspaceIsNotDirectory;
+ } else {
+ // is a directory and is good to use!
+ defaultWorkspace = repository;
+ }
+ if (reportWarnings && warning != null) {
+ Logger.getLogger(getClass()).warn(warning, defaultURL, name);
+ }
+ }
+
this.availableWorspaceNames.add(defaultWorkspace.getLocation().toDecodedString());
+ return new SVNRepositoryConnection(name, defaultWorkspace,
availableWorspaceNames, isCreatingWorkspacesAllowed(),
+ cachePolicy, supportsUpdates, new
RepositoryAccessData(getRepositoryRootURL(),
+
sourceUsername, sourcePassword));
+ }
+
+ @Immutable
+ /* package */class SVNRepositoryCachePolicy implements CachePolicy {
+ private static final long serialVersionUID = 1L;
+ private final int ttl;
+
+ /* package */SVNRepositoryCachePolicy( int ttl ) {
+ this.ttl = ttl;
+ }
+
+ public long getTimeToLive() {
+ return ttl;
+ }
+
+ }
}