Author: bcarothers
Date: 2010-01-05 07:43:25 -0500 (Tue, 05 Jan 2010)
New Revision: 1524
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnActionExecutor.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepository.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorI18n.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositoryLexicon.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositorySource.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositoryUtil.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/package-info.java
trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn2/
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnConnectorTestUtil.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnIntegrationTest.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorI18nTest.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorNoCreateWorkspaceTest.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorNotWritableTest.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorWritableTest.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositorySourceTest.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRespositoryConnectorReadableTest.java
Removed:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/RepositoryAccessData.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNActionExecutor.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNProtocol.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnection.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryLexicon.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
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/SVNRepositoryUtil.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/package-info.java
trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn/
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/
Modified:
trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/svn/SvnAndJcrIntegrationTest.java
trunk/extensions/dna-connector-svn/pom.xml
trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn2/SVNRepositoryConnectorI18n.properties
Log:
DNA-519
Applied patch that has passed Serge's review. This will be committed in two parts to
work around case sensitivity issues on Windows. In the first part, this patch will be
applied and all files will move into an svn2 package with the class name case corrected
from SVN* to Svn*. A subsequent patch will move the classes back into the svn package.
Modified:
trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/svn/SvnAndJcrIntegrationTest.java
===================================================================
---
trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/svn/SvnAndJcrIntegrationTest.java 2010-01-04
20:58:21 UTC (rev 1523)
+++
trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/svn/SvnAndJcrIntegrationTest.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -31,7 +31,7 @@
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.Session;
-import org.jboss.dna.connector.svn.SVNRepositorySource;
+import org.jboss.dna.connector.svn2.SvnRepositorySource;
import org.jboss.dna.graph.SecurityContext;
import org.jboss.dna.jcr.JcrConfiguration;
import org.jboss.dna.jcr.JcrEngine;
@@ -56,15 +56,16 @@
final String repositoryName = "svnRepository";
final JcrConfiguration configuration = new JcrConfiguration();
configuration.repositorySource(svnRepositorySource)
- .usingClass(SVNRepositorySource.class)
+ .usingClass(SvnRepositorySource.class)
.setProperty("password", "")
.setProperty("username", "anonymous")
- .setProperty("repositoryRootURL", repositoryUrl)
+ .setProperty("repositoryRootUrl", repositoryUrl)
.setProperty("predefinedWorkspaceNames",
predefinedWorkspaceNames)
.setProperty("directoryForDefaultWorkspace",
predefinedWorkspaceNames[0])
.setProperty("creatingWorkspacesAllowed", false);
-
configuration.repository(repositoryName).setSource(svnRepositorySource).setOption(Option.READ_DEPTH,
"1");
+
configuration.repository(repositoryName).setSource(svnRepositorySource).setOption(Option.QUERY_EXECUTION_ENABLED,
"false");
+
configuration.save();
this.engine = configuration.build();
this.engine.start();
@@ -107,6 +108,19 @@
}
}
+ @Test
+ public void shouldProvideAccessToJcrDataNodeUnderDeepFileNode() throws Exception {
+ String path =
"extensions/dna-sequencer-text/src/test/resources/delimited/multiLineCommaDelimitedFile.csv/jcr:content";
+ System.out.println("Getting " + path + " and then walking its
properties ...");
+ Node resourceNodeOfPomFile = this.session.getRootNode().getNode(path);
+ assertThat(resourceNodeOfPomFile, is(notNullValue()));
+
+ for (PropertyIterator iter = resourceNodeOfPomFile.getProperties();
iter.hasNext();) {
+ Property property = iter.nextProperty();
+ assertThat(property.getName(), is(notNullValue()));
+ }
+ }
+
protected class MyCustomSecurityContext implements SecurityContext {
/**
* {@inheritDoc}
Modified: trunk/extensions/dna-connector-svn/pom.xml
===================================================================
--- trunk/extensions/dna-connector-svn/pom.xml 2010-01-04 20:58:21 UTC (rev 1523)
+++ trunk/extensions/dna-connector-svn/pom.xml 2010-01-05 12:43:25 UTC (rev 1524)
@@ -51,6 +51,11 @@
<artifactId>svnkit</artifactId>
<version>1.3.0.5847</version>
</dependency>
+ <dependency>
+ <groupId>com.sun.jna</groupId>
+ <artifactId>jna</artifactId>
+ <version>3.0.9</version>
+ </dependency>
<!--
Testing (note the scope)
-->
Deleted:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/RepositoryAccessData.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/RepositoryAccessData.java 2010-01-04
20:58:21 UTC (rev 1523)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/RepositoryAccessData.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -1,49 +0,0 @@
-/**
- *
- */
-package org.jboss.dna.connector.svn;
-
-import net.jcip.annotations.ThreadSafe;
-
-@ThreadSafe
-public class RepositoryAccessData {
-
-
- private String repositoryRootUrl;
- private String username;
- private String password;
-
- /**
- * @param password
- * @param username
- * @param repositoryRootUrl
- */
- public RepositoryAccessData( String repositoryRootUrl,
- String username,
- String password ) {
- this.repositoryRootUrl = repositoryRootUrl;
- this.username = username;
- this.password = password;
- }
-
- /**
- * @return the repositoryRootUrl
- */
- public String getRepositoryRootUrl() {
- return repositoryRootUrl;
- }
-
- /**
- * @return the username
- */
- public String getUsername() {
- return username;
- }
-
- /**
- * @return the password
- */
- public String getPassword() {
- return password;
- }
-}
Deleted:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNActionExecutor.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNActionExecutor.java 2010-01-04
20:58:21 UTC (rev 1523)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNActionExecutor.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -1,73 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.connector.svn;
-
-import org.jboss.dna.connector.scm.ScmAction;
-import org.jboss.dna.connector.scm.ScmActionExecutor;
-import org.tmatesoft.svn.core.SVNErrorCode;
-import org.tmatesoft.svn.core.SVNErrorMessage;
-import org.tmatesoft.svn.core.SVNException;
-import org.tmatesoft.svn.core.io.ISVNEditor;
-import org.tmatesoft.svn.core.io.SVNRepository;
-
-/**
- */
-public class SVNActionExecutor implements ScmActionExecutor {
-
- private SVNRepository repository;
-
- /**
- * @param repository
- */
- public SVNActionExecutor( SVNRepository repository ) {
- this.repository = repository;
- }
-
- /**
- * @return repository
- */
- public SVNRepository getRepository() {
- return repository;
- }
-
- /**
- * @param action
- * @param message
- * @throws SVNException
- */
- public void execute( ScmAction action,
- String message ) throws SVNException {
- ISVNEditor editor = this.repository.getCommitEditor(message, null);
- editor.openRoot(-1);
- try {
- action.applyAction(editor);
- } catch (Exception e) {
- SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN, "This
error is appeared: '{0}'", e.getMessage());
- throw new SVNException(err);
- }
- editor.closeDir();
- editor.closeEdit();
-
- }
-}
Deleted:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNProtocol.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNProtocol.java 2010-01-04
20:58:21 UTC (rev 1523)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNProtocol.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -1,44 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.connector.svn;
-
-/**
- */
-public enum SVNProtocol {
- FILE("file"),
- SVN("svn"),
- SVN_SSH("svn+ssh"),
- HTTP("http"),
- HTTPS("https");
-
- SVNProtocol( String value ) {
- this.value = value;
- }
-
- private final String value;
-
- public String value() {
- return value;
- }
-}
Deleted:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnection.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnection.java 2010-01-04
20:58:21 UTC (rev 1523)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnection.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -1,186 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.connector.svn;
-
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-import javax.transaction.xa.XAResource;
-import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.cache.CachePolicy;
-import org.jboss.dna.graph.connector.RepositoryConnection;
-import org.jboss.dna.graph.connector.RepositorySourceException;
-import org.jboss.dna.graph.request.Request;
-import org.jboss.dna.graph.request.processor.RequestProcessor;
-import org.tmatesoft.svn.core.SVNErrorCode;
-import org.tmatesoft.svn.core.SVNErrorMessage;
-import org.tmatesoft.svn.core.SVNException;
-import org.tmatesoft.svn.core.SVNNodeKind;
-import org.tmatesoft.svn.core.io.SVNRepository;
-
-/**
- * The defaultRepository connection to a SVN Repository instance.
- */
-public class SVNRepositoryConnection implements RepositoryConnection {
-
- private final String sourceName;
- private final CachePolicy cachePolicy;
- private final SVNRepository defaultWorkspace;
- private final boolean updatesAllowed;
- private final Set<String> availableWorkspaceNames;
- private final boolean creatingWorkspacesAllowed;
- private final RepositoryAccessData accessData;
-
- /**
- * default workspace must can be a root repository or any folders from the root
directory. available workspace names must
- * consist of URLs from repository folders.
- *
- * @param sourceName
- * @param defaultWorkspace
- * @param availableWorkspaceNames
- * @param creatingWorkspacesAllowed
- * @param cachePolicy
- * @param updatesAllowed
- * @param accessData
- */
- public SVNRepositoryConnection( String sourceName,
- SVNRepository defaultWorkspace,
- Set<String> availableWorkspaceNames,
- boolean creatingWorkspacesAllowed,
- CachePolicy cachePolicy,
- boolean updatesAllowed,
- RepositoryAccessData accessData ) {
-
- CheckArg.isNotNull(defaultWorkspace, "defaultWorkspace");
- CheckArg.isNotEmpty(sourceName, "sourceName");
- assert availableWorkspaceNames != null;
- assert accessData != null;
-
- // Check if the default workspace is a folder.
- SVNNodeKind nodeKind = null;
- try {
- nodeKind = defaultWorkspace.checkPath("", -1);
- if (nodeKind == SVNNodeKind.NONE) {
- SVNErrorMessage error = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
- "No entry at URL
''{0}''",
-
defaultWorkspace.getLocation().getPath());
- throw new SVNException(error);
- } else if (nodeKind == SVNNodeKind.UNKNOWN) {
- SVNErrorMessage error = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
- "Entry at URL
''{0}'' is a file while directory was expected",
-
defaultWorkspace.getLocation().getPath());
- throw new SVNException(error);
- } else if (nodeKind == SVNNodeKind.FILE) {
- SVNErrorMessage error = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
- "Entry at URL
''{0}'' is a file while directory was expected",
-
defaultWorkspace.getLocation().getPath());
- throw new SVNException(error);
- }
- } catch (SVNException e) {
- // deal with the exception
- throw new RuntimeException(e);
- }
-
- this.sourceName = sourceName;
- this.cachePolicy = cachePolicy;
- this.defaultWorkspace = defaultWorkspace;
- this.updatesAllowed = updatesAllowed;
- this.availableWorkspaceNames = availableWorkspaceNames;
- this.creatingWorkspacesAllowed = creatingWorkspacesAllowed;
- this.accessData = accessData;
- }
-
- SVNRepository getDefaultWorkspace() {
- return defaultWorkspace;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getSourceName() {
- return sourceName;
- }
-
- /**
- * {@inheritDoc}
- */
- public CachePolicy getDefaultCachePolicy() {
- return cachePolicy;
- }
-
- /**
- * {@inheritDoc}
- */
- public XAResource getXAResource() {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean ping( long time,
- TimeUnit unit ) {
- try {
- this.defaultWorkspace.getRepositoryRoot(true);
- } catch (SVNException e) {
- return false;
- }
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.connector.RepositoryConnection#close()
- */
- public void close() {
- // do not care about.
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.connector.RepositoryConnection#execute(org.jboss.dna.graph.ExecutionContext,
- * org.jboss.dna.graph.request.Request)
- */
- public void execute( final ExecutionContext context,
- final Request request ) throws RepositorySourceException {
-
- RequestProcessor processor = new SVNRepositoryRequestProcessor(sourceName,
defaultWorkspace, availableWorkspaceNames,
-
creatingWorkspacesAllowed, context, updatesAllowed,
- accessData);
- try {
- processor.process(request);
- } finally {
- processor.close();
- }
- }
-
- /**
- * @return the accessData
- */
- public RepositoryAccessData getAccessData() {
- return accessData;
- }
-}
Deleted:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java 2010-01-04
20:58:21 UTC (rev 1523)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -1,89 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
-* See the AUTHORS.txt file in the distribution for a full listing of
-* individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.connector.svn;
-
-import java.util.Locale;
-import java.util.Set;
-import org.jboss.dna.common.i18n.I18n;
-
-/**
- * The internationalized string constants for the
<code>org.jboss.dna.connector.svn*</code> packages.
- */
-public final class SVNRepositoryConnectorI18n {
-
- public static I18n connectorName;
- public static I18n nodeDoesNotExist;
- public static I18n nodeIsActuallyUnknow;
- public static I18n propertyIsRequired;
- public static I18n errorSerializingCachePolicyInSource;
- public static I18n locationInRequestMustHavePath;
- public static I18n sourceIsReadOnly;
- public static I18n sourceDoesNotSupportCreatingWorkspaces;
- public static I18n sourceDoesNotSupportCloningWorkspaces;
- public static I18n sourceDoesNotSupportDeletingWorkspaces;
- public static I18n connectingFailureOrUserAuthenticationProblem;
- public static I18n pathForPredefinedWorkspaceDoesNotExist;
- public static I18n pathForPredefinedWorkspaceIsNotDirectory;
- public static I18n pathForPredefinedWorkspaceCannotBeRead;
- public static I18n workspaceDoesNotExist;
- public static I18n pathForDefaultWorkspaceDoesNotExist;
- public static I18n pathForDefaultWorkspaceIsNotDirectory;
- public static I18n pathForDefaultWorkspaceCannotBeRead;
- public static I18n sameNameSiblingsAreNotAllowed;
- public static I18n onlyTheDefaultNamespaceIsAllowed;
- public static I18n unableToCreateWorkspaces;
- public static I18n pathForRequestIsNotCorrect;
- public static I18n pathForRequestMustStartWithAForwardSlash;
- public static I18n nodeAlreadyExist;
- public static I18n unsupportedPrimaryType;
- public static I18n invalidPropertyNames;
- public static I18n invalidNameForResource;
- public static I18n invalidPathForResource;
- public static I18n missingRequiredProperty;
- public static I18n couldNotCreateFile;
- public static I18n couldNotReadData;
- public static I18n deleteFailed;
-
- static {
- try {
- I18n.initialize(SVNRepositoryConnectorI18n.class);
- } catch (final Exception err) {
- System.err.println(err);
- }
- }
-
- public static Set<Locale> getLocalizationProblemLocales() {
- return I18n.getLocalizationProblemLocales(SVNRepositoryConnectorI18n.class);
- }
-
- public static Set<String> getLocalizationProblems() {
- return I18n.getLocalizationProblems(SVNRepositoryConnectorI18n.class);
- }
-
- public static Set<String> getLocalizationProblems( Locale locale ) {
- return I18n.getLocalizationProblems(SVNRepositoryConnectorI18n.class, locale);
- }
-
-
-}
Deleted:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryLexicon.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryLexicon.java 2010-01-04
20:58:21 UTC (rev 1523)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryLexicon.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -1,42 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.connector.svn;
-
-import org.jboss.dna.graph.property.Name;
-import org.jboss.dna.graph.property.basic.BasicName;
-
-/**
- * The namespace and property names used within a {@link SVNRepositorySource} to store
internal information.
- */
-public class SVNRepositoryLexicon {
-
- public static class Namespace {
- public static final String URI =
"http://www.jboss.org/dna/connector/svn";
- public static final String PREFIX = "dnasvn";
- }
-
- public static final Name CHILD_PATH_SEGMENT_LIST = new BasicName(Namespace.URI,
"orderedChildNames");
- public static final Name UUID = new BasicName(Namespace.URI, "uuid");
-
-}
Deleted:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2010-01-04
20:58:21 UTC (rev 1523)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -1,1379 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.connector.svn;
-
-import java.io.ByteArrayOutputStream;
-import java.io.OutputStream;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.jboss.dna.common.i18n.I18n;
-import org.jboss.dna.common.util.Logger;
-import org.jboss.dna.connector.scm.ScmAction;
-import org.jboss.dna.connector.scm.ScmActionFactory;
-import org.jboss.dna.connector.svn.mgnt.AddDirectory;
-import org.jboss.dna.connector.svn.mgnt.AddFile;
-import org.jboss.dna.connector.svn.mgnt.DeleteEntry;
-import org.jboss.dna.connector.svn.mgnt.UpdateFile;
-import org.jboss.dna.graph.DnaIntLexicon;
-import org.jboss.dna.graph.DnaLexicon;
-import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.JcrLexicon;
-import org.jboss.dna.graph.JcrNtLexicon;
-import org.jboss.dna.graph.Location;
-import org.jboss.dna.graph.NodeConflictBehavior;
-import org.jboss.dna.graph.connector.RepositorySourceException;
-import org.jboss.dna.graph.property.Binary;
-import org.jboss.dna.graph.property.BinaryFactory;
-import org.jboss.dna.graph.property.DateTimeFactory;
-import org.jboss.dna.graph.property.Name;
-import org.jboss.dna.graph.property.NameFactory;
-import org.jboss.dna.graph.property.NamespaceRegistry;
-import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.graph.property.PathFactory;
-import org.jboss.dna.graph.property.PathNotFoundException;
-import org.jboss.dna.graph.property.Property;
-import org.jboss.dna.graph.property.PropertyFactory;
-import org.jboss.dna.graph.property.ValueFactory;
-import org.jboss.dna.graph.request.CloneBranchRequest;
-import org.jboss.dna.graph.request.CloneWorkspaceRequest;
-import org.jboss.dna.graph.request.CopyBranchRequest;
-import org.jboss.dna.graph.request.CreateNodeRequest;
-import org.jboss.dna.graph.request.CreateWorkspaceRequest;
-import org.jboss.dna.graph.request.DeleteBranchRequest;
-import org.jboss.dna.graph.request.DestroyWorkspaceRequest;
-import org.jboss.dna.graph.request.GetWorkspacesRequest;
-import org.jboss.dna.graph.request.InvalidRequestException;
-import org.jboss.dna.graph.request.InvalidWorkspaceException;
-import org.jboss.dna.graph.request.MoveBranchRequest;
-import org.jboss.dna.graph.request.ReadAllChildrenRequest;
-import org.jboss.dna.graph.request.ReadAllPropertiesRequest;
-import org.jboss.dna.graph.request.ReadNodeRequest;
-import org.jboss.dna.graph.request.RenameNodeRequest;
-import org.jboss.dna.graph.request.Request;
-import org.jboss.dna.graph.request.UpdatePropertiesRequest;
-import org.jboss.dna.graph.request.VerifyWorkspaceRequest;
-import org.jboss.dna.graph.request.processor.RequestProcessor;
-import org.tmatesoft.svn.core.SVNDirEntry;
-import org.tmatesoft.svn.core.SVNErrorCode;
-import org.tmatesoft.svn.core.SVNErrorMessage;
-import org.tmatesoft.svn.core.SVNException;
-import org.tmatesoft.svn.core.SVNNodeKind;
-import org.tmatesoft.svn.core.SVNProperties;
-import org.tmatesoft.svn.core.SVNProperty;
-import org.tmatesoft.svn.core.io.SVNRepository;
-
-/**
- * The {@link RequestProcessor} implementation for the file subversion repository
connector. This is the class that does the bulk
- * of the work in the subversion repository connector, since it processes all requests.
- */
-public class SVNRepositoryRequestProcessor extends RequestProcessor implements
ScmActionFactory {
-
- protected static final String BACK_SLASH = "/";
-
- private static final String DEFAULT_MIME_TYPE =
"application/octet-stream";
-
- /**
- * Only certain properties are tolerated when writing content (dna:resource or
jcr:resource) nodes. These properties are
- * implicitly stored (primary type, data) or silently ignored (encoded, mimetype,
last modified). The silently ignored
- * properties must be accepted to stay compatible with the JCR specification.
- */
- private final Set<Name> ALLOWABLE_PROPERTIES_FOR_CONTENT =
Collections.unmodifiableSet(new HashSet<Name>(
-
Arrays.asList(new Name[] {
-
JcrLexicon.PRIMARY_TYPE,
-
JcrLexicon.DATA,
-
JcrLexicon.ENCODED,
-
JcrLexicon.MIMETYPE,
-
JcrLexicon.LAST_MODIFIED,
-
JcrLexicon.UUID,
-
DnaIntLexicon.NODE_DEFINITON})));
- /**
- * Only certain properties are tolerated when writing files (nt:file) or folders
(nt:folder) nodes. These properties are
- * implicitly stored in the file or folder (primary type, created).
- */
- private final Set<Name> ALLOWABLE_PROPERTIES_FOR_FILE_OR_FOLDER =
Collections.unmodifiableSet(new HashSet<Name>(
-
Arrays.asList(new Name[] {
-
JcrLexicon.PRIMARY_TYPE,
-
JcrLexicon.CREATED,
-
JcrLexicon.UUID,
-
DnaIntLexicon.NODE_DEFINITON})));
-
- private final String defaultNamespaceUri;
- private final boolean updatesAllowed;
- private SVNRepository defaultWorkspace;
- protected final Logger logger;
- private final Set<String> availableWorkspaceNames;
- private final boolean creatingWorkspacesAllowed;
- private final RepositoryAccessData accessData;
-
- /**
- * @param sourceName
- * @param context
- * @param defaultWorkspace
- * @param availableWorkspaceNames
- * @param creatingWorkspacesAllowed
- * @param updatesAllowed true if this connector supports updating the subversion
repository, or false if the connector is read
- * only
- * @param accessData
- */
- protected SVNRepositoryRequestProcessor( String sourceName,
- SVNRepository defaultWorkspace,
- Set<String> availableWorkspaceNames,
- boolean creatingWorkspacesAllowed,
- ExecutionContext context,
- boolean updatesAllowed,
- RepositoryAccessData accessData ) {
- super(sourceName, context, null);
- assert defaultWorkspace != null;
- assert availableWorkspaceNames != null;
- this.defaultNamespaceUri =
getExecutionContext().getNamespaceRegistry().getDefaultNamespaceUri();
- this.updatesAllowed = updatesAllowed;
- this.defaultWorkspace = defaultWorkspace;
- this.logger = getExecutionContext().getLogger(getClass());
- this.availableWorkspaceNames = availableWorkspaceNames;
- this.creatingWorkspacesAllowed = creatingWorkspacesAllowed;
- this.accessData = accessData;
- }
-
- protected void addProperty( List<Property> properties,
- PropertyFactory factory,
- Name propertyName,
- Object value ) {
- if (value != null) {
- properties.add(factory.create(propertyName, value));
- }
- }
-
- protected boolean readNode( String workspaceName,
- Location myLocation,
- List<Property> properties,
- List<Location> children,
- Request request ) {
-
- // Get the SVNRepository object that represents the workspace ...
- SVNRepository workspaceRoot = getWorkspaceDirectory(workspaceName);
- if (workspaceRoot == null) {
- request.setError(new
InvalidWorkspaceException(SVNRepositoryConnectorI18n.workspaceDoesNotExist.text(workspaceName)));
- return false;
- }
- Path requestedPath = getPathFor(myLocation, request);
- checkThePath(requestedPath, request); // same-name-sibling indexes are not
supported
-
- if (requestedPath.isRoot()) {
- // workspace root must be a directory
- if (children != null) {
- final Collection<SVNDirEntry> entries =
SVNRepositoryUtil.getDir(workspaceRoot, "");
- for (SVNDirEntry entry : entries) {
- // All of the children of a directory will be another directory or a
file, but never a "jcr:content" node ...
- String localName = entry.getName();
- Name childName = nameFactory().create(defaultNamespaceUri,
localName);
- Path childPath = pathFactory().create(requestedPath, childName);
- children.add(Location.create(childPath));
- }
- }
- // There are no properties on the root ...
- } else {
- try {
- // Generate the properties for this File object ...
- PropertyFactory factory = getExecutionContext().getPropertyFactory();
- DateTimeFactory dateFactory =
getExecutionContext().getValueFactories().getDateFactory();
-
- // Figure out the kind of node this represents ...
- SVNNodeKind kind = getNodeKind(workspaceRoot, requestedPath,
accessData.getRepositoryRootUrl(), workspaceName);
- if (kind == SVNNodeKind.DIR) {
- String directoryPath = getPathAsString(requestedPath);
- if (!accessData.getRepositoryRootUrl().equals(workspaceName)) {
- directoryPath = directoryPath.substring(1);
- }
- if (children != null) {
- // Decide how to represent the children ...
- Collection<SVNDirEntry> dirEntries =
SVNRepositoryUtil.getDir(workspaceRoot, directoryPath);
- for (SVNDirEntry entry : dirEntries) {
- // All of the children of a directory will be another
directory or a file,
- // but never a "jcr:content" node ...
- String localName = entry.getName();
- Name childName = nameFactory().create(defaultNamespaceUri,
localName);
- Path childPath = pathFactory().create(requestedPath,
childName);
- children.add(Location.create(childPath));
- }
- }
- if (properties != null) {
- // Load the properties for this directory ......
- addProperty(properties, factory, JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FOLDER);
- SVNDirEntry entry = getEntryInfo(workspaceRoot, directoryPath);
- if (entry != null) {
- addProperty(properties, factory, JcrLexicon.LAST_MODIFIED,
dateFactory.create(entry.getDate()));
- }
- }
- } else {
- // It's not a directory, so must be a file; the only child of an
nt:file is the "jcr:content" node
- // ...
- if (requestedPath.endsWith(JcrLexicon.CONTENT)) {
- // There are never any children of these nodes, just properties
...
- if (properties != null) {
- String contentPath =
getPathAsString(requestedPath.getParent());
- if (!accessData.getRepositoryRootUrl().equals(workspaceName))
{
- contentPath = contentPath.substring(1);
- }
- SVNDirEntry entry = getEntryInfo(workspaceRoot,
contentPath);
- if (entry != null) {
- // The request is to get properties of the
"jcr:content" child node ...
- // Do NOT use "nt:resource", since it extends
"mix:referenceable". The JCR spec
- // does not require that "jcr:content" is of
type "nt:resource", but rather just
- // suggests it. Therefore, we can use
"dna:resource", which is identical to
- // "nt:resource" except it does not extend
"mix:referenceable"
- addProperty(properties, factory, JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE);
- addProperty(properties, factory,
JcrLexicon.LAST_MODIFIED, dateFactory.create(entry.getDate()));
- }
-
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- SVNProperties fileProperties = new SVNProperties();
- getData(contentPath, fileProperties, os);
- String mimeType =
fileProperties.getStringValue(SVNProperty.MIME_TYPE);
- if (mimeType == null) mimeType = DEFAULT_MIME_TYPE;
- addProperty(properties, factory, JcrLexicon.MIMETYPE,
mimeType);
-
- if (os.toByteArray().length > 0) {
- // Now put the file's content into the
"jcr:data" property ...
- BinaryFactory binaryFactory =
getExecutionContext().getValueFactories().getBinaryFactory();
- addProperty(properties, factory, JcrLexicon.DATA,
binaryFactory.create(os.toByteArray()));
- }
- }
- } else {
- // Determine the corresponding file path for this object ...
- String filePath = getPathAsString(requestedPath);
- if (!accessData.getRepositoryRootUrl().equals(workspaceName)) {
- filePath = filePath.substring(1);
- }
- if (children != null) {
- // Not a "jcr:content" child node but rather an
nt:file node, so add the child ...
- Path contentPath = pathFactory().create(requestedPath,
JcrLexicon.CONTENT);
- children.add(Location.create(contentPath));
- }
- if (properties != null) {
- // Now add the properties to "nt:file" ...
- addProperty(properties, factory, JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE);
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- SVNProperties fileProperties = new SVNProperties();
- getData(filePath, fileProperties, os);
- String created =
fileProperties.getStringValue(SVNProperty.COMMITTED_DATE);
- addProperty(properties, factory, JcrLexicon.CREATED,
dateFactory.create(created));
- }
- }
- }
- } catch (SVNException e) {
- request.setError(e);
- }
- }
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.ReadNodeRequest)
- */
- @Override
- public void process( ReadNodeRequest request ) {
- logger.trace(request.toString());
- List<Location> children = new LinkedList<Location>();
- List<Property> properties = new LinkedList<Property>();
- if (readNode(request.inWorkspace(), request.at(), properties, children, request))
{
- request.addChildren(children);
- request.addProperties(properties);
- request.setActualLocationOfNode(request.at());
- setCacheableInfo(request);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.ReadAllChildrenRequest)
- */
- @Override
- public void process( ReadAllChildrenRequest request ) {
- logger.trace(request.toString());
- List<Location> children = new LinkedList<Location>();
- if (readNode(request.inWorkspace(), request.of(), null, children, request)) {
- request.addChildren(children);
- request.setActualLocationOfNode(request.of());
- setCacheableInfo(request);
- }
-
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.ReadAllPropertiesRequest)
- */
- @Override
- public void process( ReadAllPropertiesRequest request ) {
- logger.trace(request.toString());
- List<Property> properties = new LinkedList<Property>();
- if (readNode(request.inWorkspace(), request.at(), properties, null, request)) {
- request.addProperties(properties);
- request.setActualLocationOfNode(request.at());
- setCacheableInfo(request);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.CreateNodeRequest)
- */
- @Override
- public void process( CreateNodeRequest request ) {
- logger.trace(request.toString());
- if (!updatesAllowed(request)) return;
-
- // continue
- Path parentPath = getPathFor(request.under(), request);
- if (parentPath == null) return;
-
- // svn connector does not support same name sibling
- sameNameSiblingIsNotSupported(parentPath);
-
- SVNRepository workspaceRoot = getWorkspaceDirectory(request.inWorkspace());
- assert workspaceRoot != null;
-
- SVNNodeKind parent = getSVNNodeKindFor(workspaceRoot, parentPath,
request.under(), request.inWorkspace(), request);
- if (parent == null) {
- return;
- }
-
- NamespaceRegistry registry = getExecutionContext().getNamespaceRegistry();
- // New name to commit into the svn repos workspace
- String newName = request.named().getString(registry);
-
- // Collect all the properties of the node in a hash map
- Map<Name, Property> properties = new HashMap<Name,
Property>(request.properties().size());
- for (Property property : request.properties()) {
- properties.put(property.getName(), property);
- }
-
- Property primaryTypeProp = properties.get(JcrLexicon.PRIMARY_TYPE);
- Name primaryType = primaryTypeProp == null ? null :
nameFactory().create(primaryTypeProp.getFirstValue());
-
- Path newPath = pathFactory().create(parentPath, request.named());
- Location actualLocation = Location.create(newPath);
-
- String newChildPath = null;
-
- // File
- if (JcrNtLexicon.FILE.equals(primaryType)) {
- ensureValidProperties(request.properties(),
ALLOWABLE_PROPERTIES_FOR_FILE_OR_FOLDER);
- // Parent node already exist
- boolean skipWrite = false;
-
- if (request.under().getPath().isRoot()) {
- if (!accessData.getRepositoryRootUrl().equals(request.inWorkspace())) {
- newChildPath = newName;
- } else {
- newChildPath = "/" + newName;
- }
- } else {
- newChildPath = getPathAsString(request.under().getPath()) + "/"
+ newName;
- if (!accessData.getRepositoryRootUrl().equals(request.inWorkspace())) {
- newChildPath = newChildPath.substring(1);
- }
- }
-
- // check if the new name already exist
- try {
- if (SVNRepositoryUtil.exists(workspaceRoot, newChildPath)) {
- if (request.conflictBehavior().equals(NodeConflictBehavior.APPEND))
{
- I18n msg =
SVNRepositoryConnectorI18n.sameNameSiblingsAreNotAllowed;
- throw new InvalidRequestException(msg.text("SVN Connector
does not support Same Name Sibling"));
- } else if
(request.conflictBehavior().equals(NodeConflictBehavior.DO_NOT_REPLACE)) {
- skipWrite = true;
- }
- }
- } catch (SVNException e1) {
- throw new RepositorySourceException(getSourceName(), e1.getMessage());
- }
-
- // Don't try to write if the node conflict behavior is DO_NOT_REPLACE
- if (!skipWrite) {
- // create a new, empty file
- if (newChildPath != null) {
- try {
- String rootPath = null;
- if (request.under().getPath().isRoot()) {
- rootPath = "";
- } else {
- rootPath = getPathAsString(request.under().getPath());
- }
- newFile(rootPath, newName, "".getBytes(), null,
request.inWorkspace(), workspaceRoot);
- } catch (SVNException e) {
- I18n msg = SVNRepositoryConnectorI18n.couldNotCreateFile;
- request.setError(new RepositorySourceException(getSourceName(),
-
msg.text(getPathAsString(request.under().getPath()),
-
request.inWorkspace(),
-
getSourceName(),
-
e.getMessage()), e));
- return;
- }
- }
- }
- } else if (JcrNtLexicon.RESOURCE.equals(primaryType) ||
DnaLexicon.RESOURCE.equals(primaryType)) { // Resource
- ensureValidProperties(request.properties(),
ALLOWABLE_PROPERTIES_FOR_CONTENT);
- if (request.under().getPath().isRoot()) {
- newChildPath = getPathAsString(parentPath);
- if (!accessData.getRepositoryRootUrl().equals(request.inWorkspace())) {
- newChildPath = getPathAsString(parentPath).substring(1);
- }
- } else {
- newChildPath = getPathAsString(parentPath);
- if (!accessData.getRepositoryRootUrl().equals(request.inWorkspace())) {
- newChildPath = newChildPath.substring(1);
- }
- }
-
- if (!JcrLexicon.CONTENT.equals(request.named())) {
- I18n msg = SVNRepositoryConnectorI18n.invalidNameForResource;
- String nodeName = request.named().getString(registry);
- request.setError(new RepositorySourceException(getSourceName(),
-
msg.text(getPathAsString(request.under().getPath()),
-
request.inWorkspace(),
- getSourceName(),
- nodeName)));
- return;
- }
-
- if (parent != SVNNodeKind.FILE) {
- I18n msg = SVNRepositoryConnectorI18n.invalidPathForResource;
- request.setError(new RepositorySourceException(getSourceName(),
-
msg.text(getPathAsString(request.under().getPath()),
-
request.inWorkspace(),
-
getSourceName())));
- return;
- }
-
- boolean skipWrite = false;
- if (parent != SVNNodeKind.NONE || parent != SVNNodeKind.UNKNOWN) {
- if (request.conflictBehavior().equals(NodeConflictBehavior.APPEND)) {
- I18n msg = SVNRepositoryConnectorI18n.sameNameSiblingsAreNotAllowed;
- throw new InvalidRequestException(msg.text("SVN Connector does
not support Same Name Sibling"));
- } else if
(request.conflictBehavior().equals(NodeConflictBehavior.DO_NOT_REPLACE)) {
- // TODO check if the file already has content
- skipWrite = true;
- }
- }
-
- if (!skipWrite) {
- Property dataProperty = properties.get(JcrLexicon.DATA);
- if (dataProperty == null) {
- I18n msg = SVNRepositoryConnectorI18n.missingRequiredProperty;
- String dataPropName = JcrLexicon.DATA.getString(registry);
- request.setError(new RepositorySourceException(getSourceName(),
-
msg.text(getPathAsString(request.under().getPath()),
-
request.inWorkspace(),
-
getSourceName(),
-
dataPropName)));
- return;
- }
-
- BinaryFactory binaryFactory =
getExecutionContext().getValueFactories().getBinaryFactory();
- Binary binary =
binaryFactory.create(properties.get(JcrLexicon.DATA).getFirstValue());
- // get old data
- ByteArrayOutputStream contents = new ByteArrayOutputStream();
- SVNProperties svnProperties = new SVNProperties();
- try {
- workspaceRoot.getFile(newChildPath, -1, svnProperties, contents);
- byte[] oldData = contents.toByteArray();
- // modify the empty old data with the new resource
- if (oldData != null) {
- String rootPath = null;
- String fileName = null;
-
- Path p = request.under().getPath();
- rootPath = getPathAsString(p.getAncestor(1));
- fileName = p.getLastSegment().getString(registry);
-
- if (request.under().getPath().isRoot()) {
- rootPath = "";
- }
-
- modifyFile(rootPath, fileName, oldData, binary.getBytes(), null,
request.inWorkspace(), workspaceRoot);
- }
- } catch (SVNException e) {
- I18n msg = SVNRepositoryConnectorI18n.couldNotReadData;
- request.setError(new RepositorySourceException(getSourceName(),
-
msg.text(getPathAsString(request.under().getPath()),
-
request.inWorkspace(),
-
getSourceName(),
-
e.getMessage()), e));
- return;
- }
- }
-
- } else if (JcrNtLexicon.FOLDER.equals(primaryType) || primaryType == null) { //
Folder
- ensureValidProperties(request.properties(),
ALLOWABLE_PROPERTIES_FOR_FILE_OR_FOLDER);
- try {
- String rootDirPath = getPathAsString(request.under().getPath());
- mkdir(rootDirPath, newName, null, request.inWorkspace(), workspaceRoot);
- } catch (SVNException e) {
- I18n msg = SVNRepositoryConnectorI18n.couldNotCreateFile;
- request.setError(new RepositorySourceException(getSourceName(),
-
msg.text(getPathAsString(request.under().getPath()),
-
request.inWorkspace(),
- getSourceName(),
- e.getMessage()),
e));
- return;
- }
- } else {
- I18n msg = SVNRepositoryConnectorI18n.unsupportedPrimaryType;
- request.setError(new RepositorySourceException(getSourceName(),
msg.text(primaryType.getString(registry),
-
getPathAsString(request.under().getPath()),
-
request.inWorkspace(),
-
getSourceName())));
- return;
- }
-
- request.setActualLocationOfNode(actualLocation);
- }
-
- /**
- * @param workspaceRoot
- * @param path
- * @param location
- * @param inWorkspace
- * @param request
- * @return a svn node kind
- */
- protected SVNNodeKind getSVNNodeKindFor( SVNRepository workspaceRoot,
- Path path,
- Location location,
- String inWorkspace,
- Request request ) {
- assert path != null;
- assert location != null;
- assert request != null;
-
- SVNNodeKind rootNode = SVNRepositoryUtil.checkThePath(workspaceRoot,
"", -1, getSourceName());
-
- if (rootNode != SVNNodeKind.DIR) return null;
-
- if (path.isRoot()) {
- return rootNode;
- }
-
- // See if the path is a "jcr:content" node ...
- if (path.getLastSegment().getName().equals(JcrLexicon.CONTENT)) {
- // We only want to use the parent path to find the actual file ...
- path = path.getParent();
- }
- SVNNodeKind kind = rootNode;
- for (Path.Segment segment : path) {
- if (segment.getIndex() > 1) {
- I18n msg = SVNRepositoryConnectorI18n.sameNameSiblingsAreNotAllowed;
- throw new RepositorySourceException(getSourceName(), msg.text("SVN
Connector does not support Same Name Sibling"));
- }
- }
-
- String currentPath = getPathAsString(path);
- if (!this.accessData.getRepositoryRootUrl().equals(inWorkspace)) {
- if (currentPath.startsWith("/")) {
- currentPath = currentPath.substring(1);
- }
- }
- kind = SVNRepositoryUtil.checkThePath(workspaceRoot, currentPath, -1,
getSourceName());
-
- if (kind != null) {
- if (kind == SVNNodeKind.NONE || kind == SVNNodeKind.UNKNOWN) {
- // Unable to complete the path, so prepare the exception by determining
the lowest path that exists ...
- request.setError(new RepositorySourceException(getSourceName(), "
Node kind with path " + currentPath
- + "
is missing or actually unknown"));
- return null;
- }
- }
-
- assert kind != null;
- return kind;
- }
-
- protected void sameNameSiblingIsNotSupported( Path path ) {
- for (Path.Segment segment : path) {
- // Verify the segment is valid ...
- if (segment.getIndex() > 1) {
- I18n msg = SVNRepositoryConnectorI18n.sameNameSiblingsAreNotAllowed;
- throw new RepositorySourceException(getSourceName(), msg.text("SVN
Connector does not support Same Name Sibling"));
- }
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.UpdatePropertiesRequest)
- */
- @Override
- public void process( UpdatePropertiesRequest request ) {
- logger.trace(request.toString());
- verifyUpdatesAllowed();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.CopyBranchRequest)
- */
- @Override
- public void process( CopyBranchRequest request ) {
- updatesAllowed(request);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.CloneBranchRequest)
- */
- @Override
- public void process( CloneBranchRequest request ) {
- updatesAllowed(request);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.DeleteBranchRequest)
- */
- @Override
- public void process( DeleteBranchRequest request ) {
- logger.trace(request.toString());
- if (!updatesAllowed(request)) return;
-
- SVNRepository workspaceRoot = getWorkspaceDirectory(request.inWorkspace());
- assert workspaceRoot != null;
-
- NamespaceRegistry registry = getExecutionContext().getNamespaceRegistry();
-
- Path requestedPath = request.at().getPath();
- // svn connector does not support same name sibling
- sameNameSiblingIsNotSupported(requestedPath);
-
- if (!requestedPath.isRoot() &&
JcrLexicon.CONTENT.equals(requestedPath.getLastSegment().getName())) {
- Path p = requestedPath.getAncestor(1);
- if(p != null) {
- String itemPath = getPathAsString(p);
- if (itemPath.equals("") || itemPath.equals("/")) {
- return;
- }
- String filePath = null;
- if (!accessData.getRepositoryRootUrl().equals(request.inWorkspace())) {
- filePath = itemPath.substring(1);
- }
- try {
- //check if the file exist
- if (!SVNRepositoryUtil.exists(workspaceRoot, filePath)) return;
-
- //update the file
- SVNProperties fileProperties = new SVNProperties();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- workspaceRoot.getFile(filePath, -1, fileProperties, baos);
-
- String rootPath = getPathAsString(p.getAncestor(1));
- String fileName = p.getLastSegment().getString(registry);
- modifyFile(rootPath, fileName, baos.toByteArray(),
"".getBytes(), null, request.inWorkspace(), workspaceRoot);
-
- } catch (SVNException e) {
- throw new RepositorySourceException(getSourceName(),
-
SVNRepositoryConnectorI18n.deleteFailed.text(itemPath, getSourceName()));
-
- }
- }
-
-
- } else {
-
- String nodePath = getPathAsString(requestedPath);
-
- if (!accessData.getRepositoryRootUrl().equals(request.inWorkspace())) {
- nodePath = nodePath.substring(1);
- }
-
- try {
- if (!SVNRepositoryUtil.exists(workspaceRoot, nodePath)) return;
- eraseEntry(nodePath, null, request.inWorkspace(), workspaceRoot);
- } catch (SVNException e) {
- throw new RepositorySourceException(getSourceName(),
-
SVNRepositoryConnectorI18n.deleteFailed.text(nodePath, getSourceName()));
-
- }
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.MoveBranchRequest)
- */
- @Override
- public void process( MoveBranchRequest request ) {
- updatesAllowed(request);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.RenameNodeRequest)
- */
- @Override
- public void process( RenameNodeRequest request ) {
- if (updatesAllowed(request)) super.process(request);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.VerifyWorkspaceRequest)
- */
- @Override
- public void process( VerifyWorkspaceRequest request ) {
- // If the request contains a null name, then we use the default ...
- String workspaceName = request.workspaceName();
- if (workspaceName == null) workspaceName =
defaultWorkspace.getLocation().toDecodedString();
-
- SVNRepository repository = null;
- if (!this.creatingWorkspacesAllowed) {
- // Then the workspace name must be one of the available names ...
- boolean found = false;
- for (String available : this.availableWorkspaceNames) {
- if (workspaceName.equals(available)) {
- found = true;
- break;
- }
- repository = SVNRepositoryUtil.createRepository(available,
accessData.getUsername(), accessData.getPassword());
- // check if the workspace is conform
- if (SVNRepositoryUtil.isDirectory(repository, "")
- &&
repository.getLocation().toDecodedString().equals(workspaceName)) {
- found = true;
- break;
- }
- }
- if (!found) {
- request.setError(new InvalidWorkspaceException(
-
SVNRepositoryConnectorI18n.workspaceDoesNotExist.text(workspaceName)));
- return;
- }
- }
-
- // Verify that there is a repos at the path given by the workspace name ...
- repository = SVNRepositoryUtil.createRepository(workspaceName,
accessData.getUsername(), accessData.getPassword());
- if (SVNRepositoryUtil.isDirectory(repository, "")) {
- request.setActualWorkspaceName(repository.getLocation().toDecodedString());
-
request.setActualRootLocation(Location.create(pathFactory().createRootPath()));
- } else {
- request.setError(new
InvalidWorkspaceException(SVNRepositoryConnectorI18n.workspaceDoesNotExist.text(workspaceName)));
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.GetWorkspacesRequest)
- */
- @Override
- public void process( GetWorkspacesRequest request ) {
- // Return the set of available workspace names, even if new workspaces can be
created ...
- Set<String> names = new HashSet<String>();
- for (String name : this.availableWorkspaceNames) {
- SVNRepository repos = SVNRepositoryUtil.createRepository(name,
accessData.getUsername(), accessData.getPassword());
- if (repos != null && SVNRepositoryUtil.isDirectory(repos,
"")) {
- names.add(repos.getLocation().toDecodedString());
- } else {
- request.setError(new
InvalidWorkspaceException(SVNRepositoryConnectorI18n.workspaceDoesNotExist.text(name)));
- }
- }
- request.setAvailableWorkspaceNames(Collections.unmodifiableSet(names));
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.CloneWorkspaceRequest)
- */
- @Override
- public void process( CloneWorkspaceRequest request ) {
- if (!updatesAllowed) {
- request.setError(new InvalidRequestException(
-
SVNRepositoryConnectorI18n.sourceDoesNotSupportCloningWorkspaces.text(getSourceName())));
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.CreateWorkspaceRequest)
- */
- @Override
- public void process( CreateWorkspaceRequest request ) {
- final String workspaceName = request.desiredNameOfNewWorkspace();
- if (!creatingWorkspacesAllowed) {
- String msg =
SVNRepositoryConnectorI18n.unableToCreateWorkspaces.text(getSourceName(), workspaceName);
- request.setError(new InvalidRequestException(msg));
- return;
- }
- // This doesn't create the directory representing the workspace (it must
already exist), but it will add
- // the workspace name to the available names ...
- SVNRepository repository = SVNRepositoryUtil.createRepository(workspaceName,
-
accessData.getUsername(),
-
accessData.getPassword());
- if (SVNRepositoryUtil.isDirectory(repository, "")) {
- request.setActualWorkspaceName(repository.getLocation().toDecodedString());
-
request.setActualRootLocation(Location.create(pathFactory().createRootPath()));
- availableWorkspaceNames.add(repository.getLocation().toDecodedString());
- } else {
- request.setError(new
InvalidWorkspaceException(SVNRepositoryConnectorI18n.workspaceDoesNotExist.text(workspaceName)));
- }
-
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.DestroyWorkspaceRequest)
- */
- @Override
- public void process( DestroyWorkspaceRequest request ) {
- final String workspaceName = request.workspaceName();
- if (!creatingWorkspacesAllowed) {
- String msg =
SVNRepositoryConnectorI18n.unableToCreateWorkspaces.text(getSourceName(), workspaceName);
- request.setError(new InvalidRequestException(msg));
- }
- // This doesn't delete the file/directory; rather, it just remove the
workspace from the available set ...
- if (!this.availableWorkspaceNames.remove(workspaceName)) {
- request.setError(new
InvalidWorkspaceException(SVNRepositoryConnectorI18n.workspaceDoesNotExist.text(workspaceName)));
- }
- }
-
- /**
- * Get the repository driver.
- *
- * @return repository
- */
- public SVNRepository getDefaultWorkspace() {
- return defaultWorkspace;
- }
-
- /**
- * Get the last revision.
- *
- * @param repos
- * @return the last revision number.
- * @throws Exception
- */
- public long getLatestRevision( SVNRepository repos ) throws Exception {
- try {
- return repos.getLatestRevision();
- } catch (SVNException e) {
- e.printStackTrace();
- // logger.error( "svn error: " );
- throw e;
- }
- }
-
- /**
- * Create a directory .
- *
- * @param rootDirPath - the root directory where the created directory will reside
- * @param childDirPath - the name of the created directory.
- * @param comment - comment for the creation.
- * @param inWorkspace
- * @param currentRepository
- * @throws SVNException - if during the creation, there is an error.
- */
- private void mkdir( String rootDirPath,
- String childDirPath,
- String comment,
- String inWorkspace,
- SVNRepository currentRepository ) throws SVNException {
-
- String tempParentPath = rootDirPath;
- if (!this.accessData.getRepositoryRootUrl().equals(inWorkspace)) {
- if (!tempParentPath.equals("/") &&
tempParentPath.startsWith("/")) {
- tempParentPath = tempParentPath.substring(1);
- } else if (tempParentPath.equals("/")) {
- tempParentPath = "";
- }
- }
- String checkPath = tempParentPath.length() == 0 ? childDirPath : tempParentPath +
"/" + childDirPath;
- SVNNodeKind nodeKind = null;
- try {
- nodeKind = currentRepository.checkPath(checkPath, -1);
- } catch (SVNException e) {
- SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
- "May be a Connecting
problem to the repository or a user's authentication failure: {0}",
- e.getMessage());
- throw new SVNException(err);
- }
-
- if (nodeKind != null && nodeKind == SVNNodeKind.NONE) {
- ScmAction addNodeAction = addDirectory(rootDirPath, childDirPath);
- SVNActionExecutor executor = new SVNActionExecutor(currentRepository);
- comment = comment == null ? "Create a new file " + childDirPath :
comment;
- executor.execute(addNodeAction, comment);
- } else {
- SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
- "Node with name
'{0}' can't be created",
- childDirPath);
- throw new SVNException(err);
- }
- }
-
- /**
- * Create a file.
- *
- * @param rootDirPath
- * @param childFilePath
- * @param content
- * @param comment
- * @param inWorkspace
- * @param currentRepository
- * @throws SVNException
- */
- private void newFile( String rootDirPath,
- String childFilePath,
- byte[] content,
- String comment,
- String inWorkspace,
- SVNRepository currentRepository ) throws SVNException {
-
- String tempParentPath = rootDirPath;
- if (!this.accessData.getRepositoryRootUrl().equals(inWorkspace)) {
- if (!tempParentPath.equals("/") &&
tempParentPath.startsWith("/")) {
- tempParentPath = tempParentPath.substring(1);
- }
- }
- String checkPath = tempParentPath + "/" + childFilePath;
- SVNNodeKind nodeKind = null;
- try {
- nodeKind = currentRepository.checkPath(checkPath, -1);
- } catch (SVNException e) {
- SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
- "May be a Connecting
problem to the repository or a user's authentication failure: {0}",
- e.getMessage());
- throw new SVNException(err);
- }
-
- if (nodeKind != null && nodeKind == SVNNodeKind.NONE) {
- ScmAction addFileNodeAction = addFile(rootDirPath, childFilePath, content);
- SVNActionExecutor executor = new SVNActionExecutor(currentRepository);
- comment = comment == null ? "Create a new file " + childFilePath :
comment;
- executor.execute(addFileNodeAction, comment);
- } else {
- SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
- "Item with name
'{0}' can't be created (already exist)",
- childFilePath);
- throw new SVNException(err);
- }
- }
-
- /**
- * Modify a file
- *
- * @param rootPath
- * @param fileName
- * @param oldData
- * @param newData
- * @param comment
- * @param inWorkspace
- * @param currentRepository
- * @throws SVNException
- */
- private void modifyFile( String rootPath,
- String fileName,
- byte[] oldData,
- byte[] newData,
- String comment,
- String inWorkspace,
- SVNRepository currentRepository ) throws SVNException {
- assert rootPath != null;
- assert fileName != null;
- assert oldData != null;
- assert inWorkspace != null;
- assert currentRepository != null;
-
- try {
-
- if (!this.accessData.getRepositoryRootUrl().equals(inWorkspace)) {
- if (rootPath.equals("/")) {
- rootPath = "";
- } else {
- rootPath = rootPath.substring(1) + "/";
- }
- } else {
- if (!rootPath.equals("/")) {
- rootPath = rootPath + "/";
- }
- }
- String path = rootPath + fileName;
-
- SVNNodeKind nodeKind = currentRepository.checkPath(path, -1);
- if (nodeKind == SVNNodeKind.NONE || nodeKind == SVNNodeKind.UNKNOWN) {
- SVNErrorMessage err =
SVNErrorMessage.create(SVNErrorCode.ENTRY_NOT_FOUND,
- "Item with name
'{0}' can't be found",
- path);
- throw new SVNException(err);
- }
-
- ScmAction modifyFileAction = updateFile(rootPath, fileName, oldData,
newData);
- SVNActionExecutor executor = new SVNActionExecutor(currentRepository);
- comment = comment == null ? "modify the " + fileName : comment;
- executor.execute(modifyFileAction, comment);
-
- } catch (SVNException e) {
- SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN, "This
error is appeared: '{0}'", e.getMessage());
- throw new SVNException(err);
- }
-
- }
-
- /**
- * Delete entry from the repository
- *
- * @param path
- * @param comment
- * @param inWorkspace
- * @param currentRepository
- * @throws SVNException
- */
- private void eraseEntry( String path,
- String comment,
- String inWorkspace,
- SVNRepository currentRepository ) throws SVNException {
- assert path != null;
- assert inWorkspace != null;
- if (path.equals("/") || path.equals("")) {
- SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.BAD_URL, "The
root directory cannot be deleted");
- throw new SVNException(err);
- }
-
- try {
- ScmAction deleteEntryAction = deleteEntry(path);
- SVNActionExecutor executor = new SVNActionExecutor(currentRepository);
- comment = comment == null ? "Delete the " + path : comment;
- executor.execute(deleteEntryAction, comment);
- } catch (SVNException e) {
- SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
- "unknow error during delete
action: {0)",
- e.getMessage());
- throw new SVNException(err);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.connector.scm.ScmActionFactory#addDirectory(java.lang.String,
java.lang.String)
- */
- public ScmAction addDirectory( String root,
- String path ) {
- return new AddDirectory(root, path);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.connector.scm.ScmActionFactory#addFile(java.lang.String,
java.lang.String, byte[])
- */
- public ScmAction addFile( String path,
- String file,
- byte[] content ) {
- return new AddFile(path, file, content);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.connector.scm.ScmActionFactory#updateFile(java.lang.String,
java.lang.String, byte[], byte[])
- */
- public ScmAction updateFile( String rootPath,
- String fileName,
- byte[] oldData,
- byte[] newData ) {
- return new UpdateFile(rootPath, fileName, oldData, newData);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.connector.scm.ScmActionFactory#deleteEntry(java.lang.String)
- */
- public ScmAction deleteEntry( String path ) {
- return new DeleteEntry(path);
- }
-
- protected void checkThePath( Path path,
- Request request ) {
- for (Path.Segment segment : path) {
- // Verify the segment is valid ...
- if (segment.getIndex() > 1) {
- I18n msg = SVNRepositoryConnectorI18n.sameNameSiblingsAreNotAllowed;
- throw new RepositorySourceException(getSourceName(), msg.text("SVN
Connector does not support Same Name Sibling"));
- }
- }
- }
-
- protected SVNRepository getWorkspaceDirectory( String workspaceName ) {
- SVNRepository repository = defaultWorkspace;
- if (workspaceName != null) {
- SVNRepository repos = SVNRepositoryUtil.createRepository(workspaceName,
-
accessData.getUsername(),
-
accessData.getPassword());
- if (SVNRepositoryUtil.isDirectory(repos, "")) {
- repository = repos;
- } else {
- return null;
- }
- }
- return repository;
- }
-
- protected SVNNodeKind getNodeKind( SVNRepository repository,
- Path path,
- String repositoryRootUrl,
- String inWorkspace ) throws SVNException {
- assert path != null;
- assert repositoryRootUrl != null;
- assert inWorkspace != null;
- // See if the path is a "jcr:content" node ...
- if (path.endsWith(JcrLexicon.CONTENT)) {
- // We only want to use the parent path to find the actual file ...
- path = path.getParent();
- }
- String pathAsString = getPathAsString(path);
- if (!repositoryRootUrl.equals(inWorkspace)) {
- pathAsString = pathAsString.substring(1);
- }
- SVNNodeKind kind = repository.checkPath(pathAsString, -1);
- if (kind == SVNNodeKind.NONE) {
- // node does not exist or requested node is not correct.
- throw new PathNotFoundException(Location.create(path), null,
-
SVNRepositoryConnectorI18n.nodeDoesNotExist.text(pathAsString));
- } else if (kind == SVNNodeKind.UNKNOWN) {
- // node is unknown
- throw new PathNotFoundException(Location.create(path), null,
-
SVNRepositoryConnectorI18n.nodeIsActuallyUnknow.text(pathAsString));
- }
- return kind;
- }
-
- /**
- * Checks that the collection of {@code properties} only contains properties with
allowable names.
- *
- * @param properties
- * @param validPropertyNames
- * @throws RepositorySourceException if {@code properties} contains a
- * @see #ALLOWABLE_PROPERTIES_FOR_CONTENT
- * @see #ALLOWABLE_PROPERTIES_FOR_FILE_OR_FOLDER
- */
- protected void ensureValidProperties( Collection<Property> properties,
- Set<Name> validPropertyNames ) {
- List<String> invalidNames = new LinkedList<String>();
- NamespaceRegistry registry = getExecutionContext().getNamespaceRegistry();
-
- for (Property property : properties) {
- if (!validPropertyNames.contains(property.getName())) {
- invalidNames.add(property.getName().getString(registry));
- }
- }
-
- if (!invalidNames.isEmpty()) {
- throw new RepositorySourceException(this.getSourceName(),
-
SVNRepositoryConnectorI18n.invalidPropertyNames.text(invalidNames.toString()));
- }
- }
-
- /**
- * Validate the kind of node and throws an exception if necessary.
- *
- * @param repos
- * @param requestedPath
- * @return the kind.
- */
- protected SVNNodeKind validateNodeKind( SVNRepository repos,
- Path requestedPath ) {
- SVNNodeKind kind;
- String myPath;
- if (getPathAsString(requestedPath).trim().equals("/")) {
- myPath = getPathAsString(requestedPath);
- } else if (requestedPath.endsWith(JcrLexicon.CONTENT)) {
- myPath = getPathAsString(requestedPath.getParent());
- } else {
- // directory and file
- myPath = getPathAsString(requestedPath);
- }
-
- try {
-
- kind = repos.checkPath(myPath, -1);
- if (kind == SVNNodeKind.NONE) {
- // node does not exist or requested node is not correct.
- throw new PathNotFoundException(Location.create(requestedPath), null,
-
SVNRepositoryConnectorI18n.nodeDoesNotExist.text(myPath));
- } else if (kind == SVNNodeKind.UNKNOWN) {
- // node is unknown
- throw new PathNotFoundException(Location.create(requestedPath), null,
-
SVNRepositoryConnectorI18n.nodeIsActuallyUnknow.text(myPath));
- }
- } catch (SVNException e) {
- throw new RepositorySourceException(
- getSourceName(),
-
SVNRepositoryConnectorI18n.connectingFailureOrUserAuthenticationProblem.text(getSourceName()));
- }
-
- return kind;
- }
-
- /**
- * Verify if change is allowed on a specific source.
- *
- * @throws RepositorySourceException if change on that repository source is not
allowed.
- */
- protected void verifyUpdatesAllowed() {
- if (!updatesAllowed) {
- throw new
InvalidRequestException(SVNRepositoryConnectorI18n.sourceIsReadOnly.text(getSourceName()));
- }
- }
-
- protected boolean updatesAllowed( Request request ) {
- if (!updatesAllowed) {
- request.setError(new
InvalidRequestException(SVNRepositoryConnectorI18n.sourceIsReadOnly.text(getSourceName())));
- }
- return !request.hasError();
- }
-
- /**
- * Factory for sample name.
- *
- * @return the name factory
- */
- protected NameFactory nameFactory() {
- return getExecutionContext().getValueFactories().getNameFactory();
- }
-
- /**
- * Factory for path creation.
- *
- * @return a path factory.
- */
- protected PathFactory pathFactory() {
- return getExecutionContext().getValueFactories().getPathFactory();
- }
-
- /**
- * Factory for property creation.
- *
- * @return the property factory.
- */
- protected PropertyFactory propertyFactory() {
- return getExecutionContext().getPropertyFactory();
- }
-
- /**
- * Factory for date creation.
- *
- * @return the date factory.
- */
- protected DateTimeFactory dateFactory() {
- return getExecutionContext().getValueFactories().getDateFactory();
- }
-
- /**
- * Factory for binary creation.
- *
- * @return the binary factory..
- */
- protected ValueFactory<Binary> binaryFactory() {
- return getExecutionContext().getValueFactories().getBinaryFactory();
- }
-
- /**
- * Get the path for a locarion and check if the path is null or not.
- *
- * @param location - the location.
- * @param request - the requested path.
- * @return the path.
- * @throws RepositorySourceException if the path of a location is null.
- */
- protected Path getPathFor( Location location,
- Request request ) {
- Path path = location.getPath();
- if (path == null) {
- I18n msg = SVNRepositoryConnectorI18n.locationInRequestMustHavePath;
- throw new RepositorySourceException(getSourceName(),
msg.text(getSourceName(), request));
- }
- return path;
- }
-
- /**
- * Get the content of a file.
- *
- * @param path - the path to that file.
- * @param properties - the properties of the file.
- * @param os - the output stream where to store the content.
- * @throws SVNException - throws if such path is not at that revision or in case of a
connection problem.
- */
- protected void getData( String path,
- SVNProperties properties,
- OutputStream os ) throws SVNException {
- getDefaultWorkspace().getFile(path, -1, properties, os);
-
- }
-
- protected String getPathAsString( Path path ) {
- return path.getString(getExecutionContext().getNamespaceRegistry());
- }
-
- /**
- * Get some important informations of a path
- *
- * @param repos
- * @param path - the path
- * @return - the {@link SVNDirEntry}, or null if there is no such entry
- */
- protected SVNDirEntry getEntryInfo( SVNRepository repos,
- String path ) {
- assert path != null;
- SVNDirEntry entry = null;
- try {
- entry = repos.info(path, -1);
- } catch (SVNException e) {
- throw new RepositorySourceException(
- getSourceName(),
-
SVNRepositoryConnectorI18n.connectingFailureOrUserAuthenticationProblem.text(getSourceName()));
- }
- return entry;
- }
-}
Deleted:
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 2010-01-04
20:58:21 UTC (rev 1523)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -1,581 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.connector.svn;
-
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.CopyOnWriteArraySet;
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.RefAddr;
-import javax.naming.Reference;
-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.io.SVNRepository;
-
-/**
- * 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.
- */
-@ThreadSafe
-public class SVNRepositorySource implements RepositorySource, ObjectFactory {
-
- /**
- * The first serialized version of this source. Version {@value} .
- */
- 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.
- */
- protected static final boolean SUPPORTS_EVENTS = true;
- /**
- * This source supports same-name-siblings.
- */
- protected static final boolean SUPPORTS_SAME_NAME_SIBLINGS = false;
- /**
- * This source does support creating workspaces.
- */
- 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;
-
- public static final int DEFAULT_RETRY_LIMIT = 0;
- public static final int DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS = 60 * 5; // 5
- // minutes
-
- 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 transient CachePolicy cachePolicy;
- private transient CopyOnWriteArraySet<String> availableWorspaceNames;
-
- /**
- * Create a repository source instance.
- */
- public SVNRepositorySource() {
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.connector.RepositorySource#getCapabilities()
- */
- public RepositorySourceCapabilities getCapabilities() {
- return capabilities;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getName() {
- return this.name;
- }
-
- /**
- * Set the name for the source
- *
- * @param name the new name for the source
- */
- public synchronized void setName( String name ) {
- if (name != null) {
- name = name.trim();
- if (name.length() == 0) name = null;
- }
- this.name = name;
- }
-
- /**
- * @return the url
- */
- public String getRepositoryRootURL() {
- return this.repositoryRootURL;
- }
-
- /**
- * Set the url for the subversion repository.
- *
- * @param url - the url location.
- * @throws IllegalArgumentException If svn url is null or empty
- */
- public synchronized void setRepositoryRootURL( String url ) {
- CheckArg.isNotEmpty(url, "RepositoryRootURL");
- this.repositoryRootURL = url;
- }
-
- public String getUsername() {
- return this.username;
- }
-
- /**
- * @param username
- */
- public synchronized void setUsername( String username ) {
- this.username = username;
- }
-
- public String getPassword() {
- return this.password;
- }
-
- /**
- * @param password
- */
- public synchronized void setPassword( String password ) {
- this.password = password;
- }
-
- /**
- * Get whether this source supports updates.
- *
- * @return true if this source supports updates, or false if this source only
supports reading content.
- */
- public boolean getSupportsUpdates() {
- return capabilities.supportsUpdates();
- }
-
- /**
- * 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 String getDirectoryForDefaultWorkspace() {
- return defaultWorkspace;
- }
-
- /**
- * 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;
- }
-
- /**
- * 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.
- *
- * @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 synchronized String[] getPredefinedWorkspaceNames() {
- String[] copy = new String[predefinedWorkspaces.length];
- System.arraycopy(predefinedWorkspaces, 0, copy, 0, predefinedWorkspaces.length);
- return copy;
- }
-
- /**
- * 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;
- }
-
- /**
- * 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 boolean isCreatingWorkspacesAllowed() {
- return capabilities.supportsCreatingWorkspaces();
- }
-
- /**
- * 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());
- }
-
- /**
- * Get whether this source allows updates.
- *
- * @return true if this source allows updates by clients, or false if no updates are
allowed
- * @see #setUpdatesAllowed(boolean)
- */
- public boolean areUpdatesAllowed() {
- return capabilities.supportsUpdates();
- }
-
- /**
- * Set whether this source allows updates to data within workspaces
- *
- * @param allowUpdates true if this source allows updates to data within workspaces
clients, or false if updates are not
- * allowed.
- * @see #areUpdatesAllowed()
- */
- public synchronized void setUpdatesAllowed( boolean allowUpdates ) {
- capabilities = new
RepositorySourceCapabilities(capabilities.supportsSameNameSiblings(), allowUpdates,
- capabilities.supportsEvents(),
capabilities.supportsCreatingWorkspaces(),
-
capabilities.supportsReferences());
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.connector.RepositorySource#getRetryLimit()
- */
- public int getRetryLimit() {
- return retryLimit;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.connector.RepositorySource#setRetryLimit(int)
- */
- public void setRetryLimit( int limit ) {
- retryLimit = limit < 0 ? 0 : limit;
- }
-
- /**
- * Get the time in milliseconds that content returned from this source may used while
in the cache.
- *
- * @return the time to live, in milliseconds, or 0 if the time to live is not
specified by this source
- */
- public int getCacheTimeToLiveInMilliseconds() {
- return cacheTimeToLiveInMilliseconds;
- }
-
- /**
- * Set the time in milliseconds that content returned from this source may used while
in the cache.
- *
- * @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 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;
-
- }
-
- /**
- * {@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
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals( Object obj ) {
- if (obj == this) return true;
- if (obj instanceof SVNRepositorySource) {
- SVNRepositorySource that = (SVNRepositorySource)obj;
- if (this.getName() == null) {
- if (that.getName() != null) return false;
- } else {
- if (!this.getName().equals(that.getName())) return false;
- }
- return true;
- }
- return false;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.naming.Referenceable#getReference()
- */
- public synchronized Reference getReference() {
- String className = getClass().getName();
- String factoryClassName = this.getClass().getName();
- Reference ref = new Reference(className, factoryClassName, null);
-
- if (getName() != null) {
- ref.add(new StringRefAddr(SOURCE_NAME, getName()));
- }
- if (getRepositoryRootURL() != null) {
- ref.add(new StringRefAddr(SVN_REPOSITORY_ROOT_URL, getRepositoryRootURL()));
- }
- if (getUsername() != null) {
- ref.add(new StringRefAddr(SVN_USERNAME, getUsername()));
- }
- if (getPassword() != null) {
- ref.add(new StringRefAddr(SVN_PASSWORD, getPassword()));
- }
- 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)));
- }
- return ref;
-
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object,
javax.naming.Name, javax.naming.Context,
- * java.util.Hashtable)
- */
- public Object getObjectInstance( Object obj,
- Name name,
- Context nameCtx,
- Hashtable<?, ?> environment ) throws Exception
{
- if (obj instanceof Reference) {
- Map<String, String> values = new HashMap<String, String>();
- Reference ref = (Reference)obj;
- Enumeration<?> en = ref.getAll();
- while (en.hasMoreElements()) {
- RefAddr subref = (RefAddr)en.nextElement();
- if (subref instanceof StringRefAddr) {
- String key = subref.getType();
- Object value = subref.getContent();
- if (value != null) values.put(key, value.toString());
- }
- }
- 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 (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 synchronized 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));
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.connector.RepositorySource#close()
- */
- public synchronized void close() {
- this.availableWorspaceNames = null;
- }
-
- @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;
- }
-
- }
-}
Deleted:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryUtil.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryUtil.java 2010-01-04
20:58:21 UTC (rev 1523)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryUtil.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -1,235 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.connector.svn;
-
-import java.util.Collection;
-import java.util.Collections;
-import org.jboss.dna.graph.connector.RepositorySourceException;
-import org.jboss.dna.graph.request.InvalidWorkspaceException;
-import org.tmatesoft.svn.core.SVNDirEntry;
-import org.tmatesoft.svn.core.SVNErrorCode;
-import org.tmatesoft.svn.core.SVNErrorMessage;
-import org.tmatesoft.svn.core.SVNException;
-import org.tmatesoft.svn.core.SVNNodeKind;
-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;
-
-/**
- */
-public class SVNRepositoryUtil {
-
- /**
- * @param url
- * @param sourceName
- * @return SVNURL
- */
- public static SVNURL createSVNURL( String url,
- String sourceName ) {
-
- SVNURL theUrl;
- try {
- theUrl = SVNURL.parseURIDecoded(url);
- } catch (SVNException e) {
- // protocol not supported by this connector
- throw new RepositorySourceException(sourceName,
- "Protocol is not supported by this
connector or there is problem in the svn url");
- }
- return theUrl;
- }
-
- public static void setNewSVNRepositoryLocation( SVNRepository oldRespository,
- String url,
- boolean forceReconnect,
- String sourceName ) {
- try {
- oldRespository.setLocation(createSVNURL(url, sourceName), forceReconnect);
- } catch (SVNException e) {
- throw new RepositorySourceException(sourceName, "the old url and a new
one has got different protocols");
- }
- }
-
- /**
- * @param repository
- * @param path
- * @param revisionNumber
- * @param sourceName
- * @return SVNNodeKind
- */
- public static SVNNodeKind checkThePath( SVNRepository repository,
- String path,
- long revisionNumber,
- String sourceName ) {
- SVNNodeKind kind;
- try {
- kind = repository.checkPath(path, revisionNumber);
-
- } catch (SVNException e) {
- return null;
- }
- return kind;
- }
-
- /**
- * Create a {@link SVNRepository} from a http protocol.
- *
- * @param url - the url of the repository.
- * @param username - username credential.
- * @param password - password credential
- * @return {@link SVNRepository}.
- */
- public static SVNRepository createRepository( String url,
- String username,
- String password ) {
- // for DAV (over http and https)
- DAVRepositoryFactory.setup();
- // For File
- FSRepositoryFactory.setup();
- // for SVN (over svn and svn+ssh)
- SVNRepositoryFactoryImpl.setup();
-
- // The factory knows how to create a DAVRepository
- SVNRepository repository;
- try {
- repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url));
-
- ISVNAuthenticationManager authManager =
SVNWCUtil.createDefaultAuthenticationManager(username, password);
- repository.setAuthenticationManager(authManager);
- } catch (SVNException e) {
- throw new
InvalidWorkspaceException(SVNRepositoryConnectorI18n.workspaceDoesNotExist.text(e.getMessage()));
- }
- return repository;
- }
-
- /**
- * Util to get the last segment from a path.
- *
- * @param repository
- * @return last segment.
- */
- public static String getRepositoryWorspaceName( SVNRepository repository ) {
- String[] segments = repository.getLocation().getPath().split("/");
- return segments[segments.length - 1];
- }
-
- private SVNRepositoryUtil() {
- // prvent construction
- }
-
- /**
- * Check if the repository path exist.
- *
- * @param repos
- * @return true if repository exist and false otherwise.
- */
- public static boolean exist( SVNRepository repos ) {
- try {
- SVNNodeKind kind = repos.checkPath("", -1);
- if (kind == SVNNodeKind.NONE) {
- return false;
- }
- return true;
-
- } catch (SVNException e) {
- return false;
- }
- }
-
- /**
- * Check if repository path is a directory.
- *
- * @param repos
- * @param path
- * @return true if repository path is a directory and false otherwise.
- */
- public static boolean isDirectory( SVNRepository repos,
- String path ) {
- try {
- SVNNodeKind kind = repos.checkPath(path, -1);
- if (kind == SVNNodeKind.DIR) {
- return true;
- }
- } catch (SVNException e) {
- return false;
- }
- return false;
- }
-
- /**
- * @param repos
- * @param path
- * @return a collect of entry from directory path; never null
- */
- @SuppressWarnings( "unchecked" )
- public static Collection<SVNDirEntry> getDir( SVNRepository repos,
- String path ) {
- try {
- return repos.getDir(path, -1, null, (Collection<SVNDirEntry>)null);
- } catch (SVNException e) {
- return Collections.emptyList();
- }
- }
-
- /**
- * Check if the path is a file.
- *
- * @param repos
- * @param path
- * @return true if the path is a file and false otherwise.
- */
- public static boolean isFile( SVNRepository repos,
- String path ) {
- try {
- SVNNodeKind kind = repos.checkPath(path, -1);
- if (kind == SVNNodeKind.FILE) {
- return true;
- }
- } catch (SVNException e) {
- return false;
- }
- return false;
- }
-
- public static boolean exists( SVNRepository repository,
- String path ) throws SVNException{
- try {
- if (repository.checkPath(path, -1) == SVNNodeKind.NONE) {
- return false;
- } else if (repository.checkPath(path, -1) == SVNNodeKind.UNKNOWN) {
- return false;
- }
- } catch (SVNException e) {
- SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
- "unknow error during delete
action: {0)",
- e.getMessage());
- throw new SVNException(err);
- }
- return true;
- }
-}
Deleted:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/package-info.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/package-info.java 2010-01-04
20:58:21 UTC (rev 1523)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/package-info.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -1,29 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-/**
- * The classes that make up the connector that accesses content from an SVN repository.
- */
-
-package org.jboss.dna.connector.svn;
-
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnActionExecutor.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnActionExecutor.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnActionExecutor.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -0,0 +1,73 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn2;
+
+import org.jboss.dna.connector.scm.ScmAction;
+import org.jboss.dna.connector.scm.ScmActionExecutor;
+import org.tmatesoft.svn.core.SVNErrorCode;
+import org.tmatesoft.svn.core.SVNErrorMessage;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.io.ISVNEditor;
+import org.tmatesoft.svn.core.io.SVNRepository;
+
+/**
+ */
+public class SvnActionExecutor implements ScmActionExecutor {
+
+ private final SVNRepository repository;
+
+ /**
+ * @param repository
+ */
+ public SvnActionExecutor( SVNRepository repository ) {
+ this.repository = repository;
+ }
+
+ /**
+ * @return repository
+ */
+ public SVNRepository getRepository() {
+ return repository;
+ }
+
+ /**
+ * @param action
+ * @param message
+ * @throws SVNException
+ */
+ public void execute( ScmAction action,
+ String message ) throws SVNException {
+ ISVNEditor editor = this.repository.getCommitEditor(message, null);
+ editor.openRoot(-1);
+ try {
+ action.applyAction(editor);
+ } catch (Exception e) {
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN, "This
error is appeared: '{0}'", e.getMessage());
+ throw new SVNException(err, e);
+ }
+ editor.closeDir();
+ editor.closeEdit();
+
+ }
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnActionExecutor.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepository.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepository.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepository.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -0,0 +1,889 @@
+package org.jboss.dna.connector.svn2;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import org.jboss.dna.common.i18n.I18n;
+import org.jboss.dna.connector.scm.ScmAction;
+import org.jboss.dna.connector.svn.mgnt.AddDirectory;
+import org.jboss.dna.connector.svn.mgnt.AddFile;
+import org.jboss.dna.connector.svn.mgnt.DeleteEntry;
+import org.jboss.dna.connector.svn.mgnt.UpdateFile;
+import org.jboss.dna.graph.DnaIntLexicon;
+import org.jboss.dna.graph.DnaLexicon;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.JcrLexicon;
+import org.jboss.dna.graph.JcrNtLexicon;
+import org.jboss.dna.graph.NodeConflictBehavior;
+import org.jboss.dna.graph.connector.RepositorySourceException;
+import org.jboss.dna.graph.connector.path.AbstractWritablePathWorkspace;
+import org.jboss.dna.graph.connector.path.DefaultPathNode;
+import org.jboss.dna.graph.connector.path.PathNode;
+import org.jboss.dna.graph.connector.path.WritablePathRepository;
+import org.jboss.dna.graph.connector.path.WritablePathWorkspace;
+import org.jboss.dna.graph.connector.path.cache.WorkspaceCache;
+import org.jboss.dna.graph.property.Binary;
+import org.jboss.dna.graph.property.BinaryFactory;
+import org.jboss.dna.graph.property.DateTimeFactory;
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.NameFactory;
+import org.jboss.dna.graph.property.NamespaceRegistry;
+import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.graph.property.PathFactory;
+import org.jboss.dna.graph.property.Property;
+import org.jboss.dna.graph.property.PropertyFactory;
+import org.jboss.dna.graph.property.Path.Segment;
+import org.jboss.dna.graph.request.InvalidRequestException;
+import org.tmatesoft.svn.core.SVNDirEntry;
+import org.tmatesoft.svn.core.SVNErrorCode;
+import org.tmatesoft.svn.core.SVNErrorMessage;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.SVNNodeKind;
+import org.tmatesoft.svn.core.SVNProperties;
+import org.tmatesoft.svn.core.SVNProperty;
+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;
+
+public class SvnRepository extends WritablePathRepository {
+
+ private static final String DEFAULT_MIME_TYPE =
"application/octet-stream";
+ private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
+
+ private final SvnRepositorySource source;
+
+ static {
+ // for DAV (over http and https)
+ DAVRepositoryFactory.setup();
+ // For File
+ FSRepositoryFactory.setup();
+ // for SVN (over svn and svn+ssh)
+ SVNRepositoryFactoryImpl.setup();
+ }
+
+ public SvnRepository( SvnRepositorySource source ) {
+ super(source);
+
+ this.source = source;
+ initialize();
+ }
+
+ @Override
+ protected void initialize() {
+ ExecutionContext context = source.getRepositoryContext().getExecutionContext();
+ for (String workspaceName : source.getPredefinedWorkspaceNames()) {
+ doCreateWorkspace(context, workspaceName);
+ }
+
+ String defaultWorkspaceName = source.getDirectoryForDefaultWorkspace();
+ if (defaultWorkspaceName != null &&
!workspaces.containsKey(defaultWorkspaceName)) {
+ doCreateWorkspace(context, defaultWorkspaceName);
+ }
+
+ }
+
+ public WorkspaceCache getCache( String workspaceName ) {
+ return source.getPathRepositoryCache().getCache(workspaceName);
+ }
+
+ /**
+ * Internal method that creates a workspace and adds it to the map of active
workspaces without checking to see if the source
+ * allows creating workspaces. This is useful when setting up predefined workspaces.
+ *
+ * @param context the current execution context; may not be null
+ * @param name the name of the workspace to create; may not be null
+ * @return the newly created workspace; never null
+ */
+ private WritablePathWorkspace doCreateWorkspace( ExecutionContext context,
+ String name ) {
+ SvnWorkspace workspace = new SvnWorkspace(name, source.getRootNodeUuid());
+
+ workspaces.putIfAbsent(name, workspace);
+ return (WritablePathWorkspace)workspaces.get(name);
+
+ }
+
+ @Override
+ protected WritablePathWorkspace createWorkspace( ExecutionContext context,
+ String name ) {
+ if (!source.isCreatingWorkspacesAllowed()) {
+ String msg =
SvnRepositoryConnectorI18n.unableToCreateWorkspaces.text(getSourceName(), name);
+ throw new InvalidRequestException(msg);
+ }
+
+ return doCreateWorkspace(context, name);
+ }
+
+ class SvnWorkspace extends AbstractWritablePathWorkspace {
+
+ /**
+ * Only certain properties are tolerated when writing content (dna:resource or
jcr:resource) nodes. These properties are
+ * implicitly stored (primary type, data) or silently ignored (encoded, mimetype,
last modified). The silently ignored
+ * properties must be accepted to stay compatible with the JCR specification.
+ */
+ private final Set<Name> ALLOWABLE_PROPERTIES_FOR_CONTENT =
Collections.unmodifiableSet(new HashSet<Name>(
+
Arrays.asList(new Name[] {
+
JcrLexicon.PRIMARY_TYPE,
+
JcrLexicon.DATA,
+
JcrLexicon.ENCODED,
+
JcrLexicon.MIMETYPE,
+
JcrLexicon.LAST_MODIFIED,
+
JcrLexicon.UUID,
+
DnaIntLexicon.NODE_DEFINITON})));
+ /**
+ * Only certain properties are tolerated when writing files (nt:file) or folders
(nt:folder) nodes. These properties are
+ * implicitly stored in the file or folder (primary type, created).
+ */
+ private final Set<Name> ALLOWABLE_PROPERTIES_FOR_FILE_OR_FOLDER =
Collections.unmodifiableSet(new HashSet<Name>(
+
Arrays.asList(new Name[] {
+
JcrLexicon.PRIMARY_TYPE,
+
JcrLexicon.CREATED,
+
JcrLexicon.UUID,
+
DnaIntLexicon.NODE_DEFINITON})));
+
+ private final SVNRepository workspaceRoot;
+
+ public SvnWorkspace( String name,
+ UUID rootNodeUuid ) {
+ super(name, rootNodeUuid);
+
+ try {
+ workspaceRoot =
SVNRepositoryFactory.create(SVNURL.parseURIDecoded(name));
+
+ ISVNAuthenticationManager authManager =
SVNWCUtil.createDefaultAuthenticationManager(source.getUsername(),
+
source.getPassword());
+ workspaceRoot.setAuthenticationManager(authManager);
+ } catch (SVNException ex) {
+ throw new IllegalStateException(ex);
+ }
+ }
+
+ public Path getLowestExistingPath( Path path ) {
+ do {
+ path = path.getParent();
+
+ if (getNode(path) != null) {
+ return path;
+ }
+ } while (path != null);
+
+ assert false : "workspace root path was not a valid path";
+ return null;
+ }
+
+ public PathNode getNode( Path path ) {
+ WorkspaceCache cache = getCache(getName());
+
+ PathNode node = cache.get(path);
+ if (node != null) return node;
+
+ ExecutionContext context =
source.getRepositoryContext().getExecutionContext();
+ List<Property> properties = new LinkedList<Property>();
+ List<Segment> children = new LinkedList<Segment>();
+
+ try {
+ boolean result = readNode(context, this.getName(), path, properties,
children);
+ if (!result) return null;
+ } catch (SVNException ex) {
+ return null;
+ }
+
+ UUID uuid = path.isRoot() ? source.getRootNodeUuid() : null;
+ node = new DefaultPathNode(path, uuid, properties, children);
+
+ cache.set(node);
+ return node;
+ }
+
+ public PathNode createNode( ExecutionContext context,
+ PathNode parentNode,
+ Name name,
+ Map<Name, Property> properties,
+ NodeConflictBehavior conflictBehavior ) {
+
+ NamespaceRegistry registry = context.getNamespaceRegistry();
+ NameFactory nameFactory = context.getValueFactories().getNameFactory();
+ PathFactory pathFactory = context.getValueFactories().getPathFactory();
+
+ // New name to commit into the svn repos workspace
+ String newName = name.getString(registry);
+
+ Property primaryTypeProp = properties.get(JcrLexicon.PRIMARY_TYPE);
+ Name primaryType = primaryTypeProp == null ? null :
nameFactory.create(primaryTypeProp.getFirstValue());
+
+ Path parentPath = parentNode.getPath();
+ String parentPathAsString = parentPath.getString(registry);
+ Path newPath = pathFactory.create(parentPath, name);
+
+ String newChildPath = null;
+
+ // File
+ if (JcrNtLexicon.FILE.equals(primaryType)) {
+ ensureValidProperties(context, properties.values(),
ALLOWABLE_PROPERTIES_FOR_FILE_OR_FOLDER);
+ // Parent node already exist
+ boolean skipWrite = false;
+
+ if (parentPath.isRoot()) {
+ if (!source.getRepositoryRootUrl().equals(getName())) {
+ newChildPath = newName;
+ } else {
+ newChildPath = "/" + newName;
+ }
+ } else {
+ newChildPath = newPath.getString(registry);
+ if (!source.getRepositoryRootUrl().equals(getName())) {
+ newChildPath = newChildPath.substring(1);
+ }
+ }
+
+ // check if the new name already exist
+ try {
+ if (SvnRepositoryUtil.exists(workspaceRoot, newChildPath)) {
+ if (conflictBehavior.equals(NodeConflictBehavior.APPEND)) {
+ I18n msg =
SvnRepositoryConnectorI18n.sameNameSiblingsAreNotAllowed;
+ throw new InvalidRequestException(msg.text("SVN
Connector does not support Same Name Sibling"));
+ } else if
(conflictBehavior.equals(NodeConflictBehavior.DO_NOT_REPLACE)) {
+ skipWrite = true;
+ }
+ }
+ } catch (SVNException e1) {
+ throw new RepositorySourceException(getSourceName(),
e1.getMessage());
+ }
+
+ // Don't try to write if the node conflict behavior is
DO_NOT_REPLACE
+ if (!skipWrite) {
+ // create a new, empty file
+ if (newChildPath != null) {
+ try {
+ String rootPath = null;
+ if (parentPath.isRoot()) {
+ rootPath = "";
+ } else {
+ rootPath = parentPathAsString;
+ }
+ newFile(rootPath, newName, EMPTY_BYTE_ARRAY, null, getName(),
workspaceRoot);
+ } catch (SVNException e) {
+ I18n msg = SvnRepositoryConnectorI18n.couldNotCreateFile;
+ throw new RepositorySourceException(getSourceName(),
msg.text(parentPathAsString,
+
getName(),
+
getSourceName(),
+
e.getMessage()), e);
+ }
+ }
+ }
+ } else if (JcrNtLexicon.RESOURCE.equals(primaryType) ||
DnaLexicon.RESOURCE.equals(primaryType)) { // Resource
+ ensureValidProperties(context, properties.values(),
ALLOWABLE_PROPERTIES_FOR_CONTENT);
+ if (parentPath.isRoot()) {
+ newChildPath = parentPathAsString;
+ if (!source.getRepositoryRootUrl().equals(getName())) {
+ newChildPath = parentPathAsString.substring(1);
+ }
+ } else {
+ newChildPath = parentPathAsString;
+ if (!source.getRepositoryRootUrl().equals(getName())) {
+ newChildPath = newChildPath.substring(1);
+ }
+ }
+
+ if (!JcrLexicon.CONTENT.equals(name)) {
+ I18n msg = SvnRepositoryConnectorI18n.invalidNameForResource;
+ throw new RepositorySourceException(getSourceName(),
msg.text(parentPathAsString,
+
getName(),
+
getSourceName(),
+
newName));
+ }
+
+ Property parentPrimaryType =
parentNode.getProperty(JcrLexicon.PRIMARY_TYPE);
+ Name parentPrimaryTypeName = parentPrimaryType == null ? null :
nameFactory.create(parentPrimaryType.getFirstValue());
+ if (!JcrNtLexicon.FILE.equals(parentPrimaryTypeName)) {
+ I18n msg = SvnRepositoryConnectorI18n.invalidPathForResource;
+ throw new RepositorySourceException(getSourceName(),
msg.text(parentPathAsString, getName(), getSourceName()));
+ }
+
+ boolean skipWrite = false;
+ if (conflictBehavior.equals(NodeConflictBehavior.APPEND)) {
+ I18n msg = SvnRepositoryConnectorI18n.sameNameSiblingsAreNotAllowed;
+ throw new InvalidRequestException(msg.text("SVN Connector does
not support Same Name Sibling"));
+ } else if (conflictBehavior.equals(NodeConflictBehavior.DO_NOT_REPLACE))
{
+ // TODO check if the file already has content
+ skipWrite = true;
+ }
+
+ if (!skipWrite) {
+ Property dataProperty = properties.get(JcrLexicon.DATA);
+ if (dataProperty == null) {
+ I18n msg = SvnRepositoryConnectorI18n.missingRequiredProperty;
+ String dataPropName = JcrLexicon.DATA.getString(registry);
+ throw new RepositorySourceException(getSourceName(),
msg.text(parentPathAsString,
+
getName(),
+
getSourceName(),
+
dataPropName));
+ }
+
+ BinaryFactory binaryFactory =
context.getValueFactories().getBinaryFactory();
+ Binary binary =
binaryFactory.create(properties.get(JcrLexicon.DATA).getFirstValue());
+ // get old data
+ ByteArrayOutputStream contents = new ByteArrayOutputStream();
+ SVNProperties svnProperties = new SVNProperties();
+ try {
+ workspaceRoot.getFile(newChildPath, -1, svnProperties,
contents);
+ byte[] oldData = contents.toByteArray();
+
+ // modify the empty old data with the new resource
+ if (oldData != null) {
+ String pathToFile;
+ if (parentPath.isRoot()) {
+ pathToFile = "";
+ } else {
+ pathToFile = parentPath.getParent().getString(registry);
+ }
+ String fileName =
parentPath.getLastSegment().getString(registry);
+
+ modifyFile(pathToFile, fileName, oldData, binary.getBytes(),
null, getName(), workspaceRoot);
+ }
+ } catch (SVNException e) {
+ I18n msg = SvnRepositoryConnectorI18n.couldNotReadData;
+ throw new RepositorySourceException(getSourceName(),
msg.text(parentPathAsString,
+
getName(),
+
getSourceName(),
+
e.getMessage()), e);
+ }
+ }
+
+ } else if (JcrNtLexicon.FOLDER.equals(primaryType) || primaryType == null) {
// Folder
+ ensureValidProperties(context, properties.values(),
ALLOWABLE_PROPERTIES_FOR_FILE_OR_FOLDER);
+ try {
+ mkdir(parentPathAsString, newName, null, getName(), workspaceRoot);
+ } catch (SVNException e) {
+ I18n msg = SvnRepositoryConnectorI18n.couldNotCreateFile;
+ throw new RepositorySourceException(getSourceName(),
msg.text(parentPathAsString,
+
getName(),
+
getSourceName(),
+
e.getMessage()), e);
+ }
+ } else {
+ I18n msg = SvnRepositoryConnectorI18n.unsupportedPrimaryType;
+ throw new RepositorySourceException(getSourceName(),
msg.text(primaryType.getString(registry),
+
parentPathAsString,
+ getName(),
+
getSourceName()));
+ }
+
+ PathNode node = getNode(newPath);
+
+ List<Segment> newChildren = new
ArrayList<Segment>(parentNode.getChildSegments().size() + 1);
+ newChildren.addAll(parentNode.getChildSegments());
+ newChildren.add(node.getPath().getLastSegment());
+
+ WorkspaceCache cache = getCache(getName());
+ cache.set(new DefaultPathNode(parentNode.getPath(), parentNode.getUuid(),
parentNode.getProperties(), newChildren));
+ cache.set(node);
+
+ return node;
+ }
+
+ /**
+ * Create a directory .
+ *
+ * @param rootDirPath - the root directory where the created directory will
reside
+ * @param childDirPath - the name of the created directory.
+ * @param comment - comment for the creation.
+ * @param inWorkspace
+ * @param currentRepository
+ * @throws SVNException - if during the creation, there is an error.
+ */
+ private void mkdir( String rootDirPath,
+ String childDirPath,
+ String comment,
+ String inWorkspace,
+ SVNRepository currentRepository ) throws SVNException {
+
+ String tempParentPath = rootDirPath;
+ if (!source.getRepositoryRootUrl().equals(inWorkspace)) {
+ if (!tempParentPath.equals("/") &&
tempParentPath.startsWith("/")) {
+ tempParentPath = tempParentPath.substring(1);
+ } else if (tempParentPath.equals("/")) {
+ tempParentPath = "";
+ }
+ }
+ String checkPath = tempParentPath.length() == 0 ? childDirPath :
tempParentPath + "/" + childDirPath;
+ SVNNodeKind nodeKind = null;
+ try {
+ nodeKind = currentRepository.checkPath(checkPath, -1);
+ } catch (SVNException e) {
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+ "May be a Connecting
problem to the repository or a user's authentication failure: {0}",
+ e.getMessage());
+ throw new SVNException(err);
+ }
+
+ if (nodeKind != null && nodeKind == SVNNodeKind.NONE) {
+ ScmAction addNodeAction = new AddDirectory(rootDirPath, childDirPath);
+ SvnActionExecutor executor = new SvnActionExecutor(currentRepository);
+ comment = comment == null ? "Create a new file " + childDirPath
: comment;
+ executor.execute(addNodeAction, comment);
+ } else {
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+ "Node with name
'{0}' can't be created",
+ childDirPath);
+ throw new SVNException(err);
+ }
+ }
+
+ /**
+ * Create a file.
+ *
+ * @param rootDirPath
+ * @param childFilePath
+ * @param content
+ * @param comment
+ * @param inWorkspace
+ * @param currentRepository
+ * @throws SVNException
+ */
+ private void newFile( String rootDirPath,
+ String childFilePath,
+ byte[] content,
+ String comment,
+ String inWorkspace,
+ SVNRepository currentRepository ) throws SVNException {
+
+ String tempParentPath = rootDirPath;
+ if (!source.getRepositoryRootUrl().equals(inWorkspace)) {
+ if (!tempParentPath.equals("/") &&
tempParentPath.startsWith("/")) {
+ tempParentPath = tempParentPath.substring(1);
+ }
+ }
+ String checkPath = tempParentPath + "/" + childFilePath;
+ SVNNodeKind nodeKind = null;
+ try {
+ nodeKind = currentRepository.checkPath(checkPath, -1);
+ } catch (SVNException e) {
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+ "May be a Connecting
problem to the repository or a user's authentication failure: {0}",
+ e.getMessage());
+ throw new SVNException(err);
+ }
+
+ if (nodeKind != null && nodeKind == SVNNodeKind.NONE) {
+ ScmAction addFileNodeAction = new AddFile(rootDirPath, childFilePath,
content);
+ SvnActionExecutor executor = new SvnActionExecutor(currentRepository);
+ comment = comment == null ? "Create a new file " +
childFilePath : comment;
+ executor.execute(addFileNodeAction, comment);
+ } else {
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+ "Item with name
'{0}' can't be created (already exist)",
+ childFilePath);
+ throw new SVNException(err);
+ }
+ }
+
+ /**
+ * Modify a file
+ *
+ * @param rootPath
+ * @param fileName
+ * @param oldData
+ * @param newData
+ * @param comment
+ * @param inWorkspace
+ * @param currentRepository
+ * @throws SVNException
+ */
+ private void modifyFile( String rootPath,
+ String fileName,
+ byte[] oldData,
+ byte[] newData,
+ String comment,
+ String inWorkspace,
+ SVNRepository currentRepository ) throws SVNException {
+ assert rootPath != null;
+ assert fileName != null;
+ assert oldData != null;
+ assert inWorkspace != null;
+ assert currentRepository != null;
+
+ try {
+
+ if (!source.getRepositoryRootUrl().equals(inWorkspace)) {
+ if (rootPath.equals("/")) {
+ rootPath = "";
+ } else {
+ rootPath = rootPath.substring(1) + "/";
+ }
+ } else {
+ if (!rootPath.equals("/")) {
+ rootPath = rootPath + "/";
+ }
+ }
+ String path = rootPath + fileName;
+
+ SVNNodeKind nodeKind = currentRepository.checkPath(path, -1);
+ if (nodeKind == SVNNodeKind.NONE || nodeKind == SVNNodeKind.UNKNOWN) {
+ SVNErrorMessage err =
SVNErrorMessage.create(SVNErrorCode.ENTRY_NOT_FOUND,
+ "Item with name
'{0}' can't be found",
+ path);
+ throw new SVNException(err);
+ }
+
+ ScmAction modifyFileAction = new UpdateFile(rootPath, fileName, oldData,
newData);
+ SvnActionExecutor executor = new SvnActionExecutor(currentRepository);
+ comment = comment == null ? "modify the " + fileName :
comment;
+ executor.execute(modifyFileAction, comment);
+
+ } catch (SVNException e) {
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
"This error is appeared: " + e.getMessage());
+ throw new SVNException(err, e);
+ }
+
+ }
+
+ /**
+ * Delete entry from the repository
+ *
+ * @param path
+ * @param comment
+ * @param inWorkspace
+ * @param currentRepository
+ * @throws SVNException
+ */
+ private void eraseEntry( String path,
+ String comment,
+ String inWorkspace,
+ SVNRepository currentRepository ) throws SVNException {
+ assert path != null;
+ assert inWorkspace != null;
+ if (path.equals("/") || path.equals("")) {
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.BAD_URL,
"The root directory cannot be deleted");
+ throw new SVNException(err);
+ }
+
+ try {
+ ScmAction deleteEntryAction = new DeleteEntry(path);
+ SvnActionExecutor executor = new SvnActionExecutor(currentRepository);
+ comment = comment == null ? "Delete the " + path : comment;
+ executor.execute(deleteEntryAction, comment);
+ } catch (SVNException e) {
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+ "unknow error during
delete action: {0)",
+ e.getMessage());
+ throw new SVNException(err);
+ }
+ }
+
+ public boolean removeNode( ExecutionContext context,
+ Path nodePath ) {
+
+ NamespaceRegistry registry = context.getNamespaceRegistry();
+
+ boolean isContentNode = !nodePath.isRoot() &&
JcrLexicon.CONTENT.equals(nodePath.getLastSegment().getName());
+ Path actualPath = isContentNode ? nodePath.getParent() : nodePath;
+
+ try {
+ SVNNodeKind kind = getNodeKind(context, actualPath,
source.getRepositoryRootUrl());
+
+ if (kind == SVNNodeKind.NONE) {
+ return false;
+ }
+
+ if (isContentNode) {
+ String rootPath = actualPath.getParent().getString(registry);
+ String fileName = actualPath.getLastSegment().getString(registry);
+ modifyFile(rootPath, fileName, EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY,
null, getName(), workspaceRoot);
+ } else {
+ eraseEntry(actualPath.getString(registry), null, getName(),
workspaceRoot);
+ }
+ } catch (SVNException e) {
+ throw new RepositorySourceException(getSourceName(),
+
SvnRepositoryConnectorI18n.deleteFailed.text(nodePath, getSourceName()));
+ }
+
+ getCache(getName()).invalidate(nodePath);
+
+ return true;
+ }
+
+ public PathNode setProperties( ExecutionContext context,
+ Path nodePath,
+ Map<Name, Property> properties ) {
+ PathNode targetNode = getNode(nodePath);
+ if (targetNode == null) return null;
+
+ /*
+ * You can't really remove any properties from SVN nodes.
+ * You can clear the data of a dna:resource though
+ */
+
+ NameFactory nameFactory = context.getValueFactories().getNameFactory();
+ Property primaryTypeProperty =
targetNode.getProperty(JcrLexicon.PRIMARY_TYPE);
+ Name primaryTypeName = primaryTypeProperty == null ? null :
nameFactory.create(primaryTypeProperty.getFirstValue());
+ if (DnaLexicon.RESOURCE.equals(primaryTypeName)) {
+
+ for (Map.Entry<Name, Property> entry : properties.entrySet()) {
+ if (JcrLexicon.DATA.equals(entry.getKey())) {
+ NamespaceRegistry registry = context.getNamespaceRegistry();
+ byte[] data;
+ if (entry.getValue() == null) {
+ data = EMPTY_BYTE_ARRAY;
+ } else {
+ BinaryFactory binaryFactory =
context.getValueFactories().getBinaryFactory();
+ data =
binaryFactory.create(entry.getValue().getFirstValue()).getBytes();
+
+ }
+
+ try {
+ Path actualPath = nodePath.getParent();
+ modifyFile(actualPath.getParent().getString(registry),
+ actualPath.getLastSegment().getString(registry),
+ EMPTY_BYTE_ARRAY,
+ data,
+ "",
+ getName(),
+ workspaceRoot);
+
+ PathNode node = getNode(nodePath);
+ getCache(getName()).set(node);
+
+ return node;
+ } catch (SVNException ex) {
+ throw new RepositorySourceException(getSourceName(),
+
SvnRepositoryConnectorI18n.deleteFailed.text(nodePath,
+
getSourceName()), ex);
+ }
+ }
+ }
+ }
+
+ return targetNode;
+ }
+
+ protected boolean readNode( ExecutionContext context,
+ String workspaceName,
+ Path requestedPath,
+ List<Property> properties,
+ List<Segment> children ) throws SVNException {
+ PathFactory pathFactory = context.getValueFactories().getPathFactory();
+ NamespaceRegistry registry = context.getNamespaceRegistry();
+
+ if (requestedPath.isRoot()) {
+ // workspace root must be a directory
+ if (children != null) {
+ final Collection<SVNDirEntry> entries =
SvnRepositoryUtil.getDir(workspaceRoot, "");
+ for (SVNDirEntry entry : entries) {
+ // All of the children of a directory will be another directory
or a file, but never a "jcr:content" node
+ // ...
+ children.add(pathFactory.createSegment(entry.getName()));
+ }
+ }
+ // There are no properties on the root ...
+ } else {
+ // Generate the properties for this File object ...
+ PropertyFactory factory = context.getPropertyFactory();
+ DateTimeFactory dateFactory =
context.getValueFactories().getDateFactory();
+
+ // Figure out the kind of node this represents ...
+ SVNNodeKind kind = getNodeKind(context, requestedPath,
source.getRepositoryRootUrl());
+ if (kind == SVNNodeKind.NONE) {
+ // The node doesn't exist
+ return false;
+ }
+ if (kind == SVNNodeKind.DIR) {
+ String directoryPath = requestedPath.getString(registry);
+ if (!source.getRepositoryRootUrl().equals(workspaceName)) {
+ directoryPath = directoryPath.substring(1);
+ }
+ if (children != null) {
+ // Decide how to represent the children ...
+ Collection<SVNDirEntry> dirEntries =
SvnRepositoryUtil.getDir(workspaceRoot, directoryPath);
+ for (SVNDirEntry entry : dirEntries) {
+ // All of the children of a directory will be another
directory or a file,
+ // but never a "jcr:content" node ...
+ children.add(pathFactory.createSegment(entry.getName()));
+ }
+ }
+ if (properties != null) {
+ // Load the properties for this directory ......
+ properties.add(factory.create(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FOLDER));
+ SVNDirEntry entry = getEntryInfo(workspaceRoot, directoryPath);
+ if (entry != null) {
+ properties.add(factory.create(JcrLexicon.CREATED,
dateFactory.create(entry.getDate())));
+ }
+ }
+ } else {
+ // It's not a directory, so must be a file; the only child of an
nt:file is the "jcr:content" node
+ // ...
+ if (requestedPath.endsWith(JcrLexicon.CONTENT)) {
+ // There are never any children of these nodes, just properties
...
+ if (properties != null) {
+ String contentPath =
requestedPath.getParent().getString(registry);
+ if (!source.getRepositoryRootUrl().equals(workspaceName)) {
+ contentPath = contentPath.substring(1);
+ }
+ SVNDirEntry entry = getEntryInfo(workspaceRoot,
contentPath);
+ if (entry != null) {
+ // The request is to get properties of the
"jcr:content" child node ...
+ // Do NOT use "nt:resource", since it extends
"mix:referenceable". The JCR spec
+ // does not require that "jcr:content" is of
type "nt:resource", but rather just
+ // suggests it. Therefore, we can use
"dna:resource", which is identical to
+ // "nt:resource" except it does not extend
"mix:referenceable"
+ properties.add(factory.create(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE));
+ properties.add(factory.create(JcrLexicon.LAST_MODIFIED,
dateFactory.create(entry.getDate())));
+ }
+
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ SVNProperties fileProperties = new SVNProperties();
+ getData(contentPath, fileProperties, os);
+ String mimeType =
fileProperties.getStringValue(SVNProperty.MIME_TYPE);
+ if (mimeType == null) mimeType = DEFAULT_MIME_TYPE;
+ properties.add(factory.create(JcrLexicon.MIMETYPE,
mimeType));
+
+ if (os.toByteArray().length > 0) {
+ // Now put the file's content into the
"jcr:data" property ...
+ BinaryFactory binaryFactory =
context.getValueFactories().getBinaryFactory();
+ properties.add(factory.create(JcrLexicon.DATA,
binaryFactory.create(os.toByteArray())));
+ }
+ }
+ } else {
+ // Determine the corresponding file path for this object ...
+ String filePath = requestedPath.getString(registry);
+ if (!source.getRepositoryRootUrl().equals(workspaceName)) {
+ filePath = filePath.substring(1);
+ }
+ if (children != null) {
+ // Not a "jcr:content" child node but rather an
nt:file node, so add the child ...
+ children.add(pathFactory.createSegment(JcrLexicon.CONTENT));
+ }
+ if (properties != null) {
+ // Now add the properties to "nt:file" ...
+ properties.add(factory.create(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE));
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ SVNProperties fileProperties = new SVNProperties();
+ getData(filePath, fileProperties, os);
+ String created =
fileProperties.getStringValue(SVNProperty.COMMITTED_DATE);
+ properties.add(factory.create(JcrLexicon.CREATED,
dateFactory.create(created)));
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Get some important informations of a path
+ *
+ * @param repos
+ * @param path - the path
+ * @return - the {@link SVNDirEntry}, or null if there is no such entry
+ */
+ protected SVNDirEntry getEntryInfo( SVNRepository repos,
+ String path ) {
+ assert path != null;
+ SVNDirEntry entry = null;
+ try {
+ entry = repos.info(path, -1);
+ } catch (SVNException e) {
+ throw new RepositorySourceException(
+ getSourceName(),
+
SvnRepositoryConnectorI18n.connectingFailureOrUserAuthenticationProblem.text(getSourceName()));
+ }
+ return entry;
+ }
+
+ /**
+ * Get the content of a file.
+ *
+ * @param path - the path to that file.
+ * @param properties - the properties of the file.
+ * @param os - the output stream where to store the content.
+ * @throws SVNException - throws if such path is not at that revision or in case
of a connection problem.
+ */
+ protected void getData( String path,
+ SVNProperties properties,
+ OutputStream os ) throws SVNException {
+ workspaceRoot.getFile(path, -1, properties, os);
+
+ }
+
+ protected SVNNodeKind getNodeKind( ExecutionContext context,
+ Path path,
+ String repositoryRootUrl ) throws SVNException
{
+ assert path != null;
+ assert repositoryRootUrl != null;
+
+ // See if the path is a "jcr:content" node ...
+ if (path.endsWith(JcrLexicon.CONTENT)) {
+ // We only want to use the parent path to find the actual file ...
+ path = path.getParent();
+ }
+ String pathAsString = path.getString(context.getNamespaceRegistry());
+ if (!repositoryRootUrl.equals(getName())) {
+ pathAsString = pathAsString.substring(1);
+ }
+
+ String absolutePath = pathAsString;
+ SVNNodeKind kind = workspaceRoot.checkPath(absolutePath, -1);
+ if (kind == SVNNodeKind.UNKNOWN) {
+ // node is unknown
+ throw new RepositorySourceException(getSourceName(),
+
SvnRepositoryConnectorI18n.nodeIsActuallyUnknow.text(pathAsString));
+ }
+ return kind;
+ }
+
+ protected SVNRepository getWorkspaceDirectory( String workspaceName ) {
+ if (workspaceName == null) workspaceName =
source.getDirectoryForDefaultWorkspace();
+ SVNRepository repository = null;
+ SVNRepository repos = SvnRepositoryUtil.createRepository(workspaceName,
source.getUsername(), source.getPassword());
+ if (SvnRepositoryUtil.isDirectory(repos, "")) {
+ repository = repos;
+ } else {
+ return null;
+ }
+ return repository;
+ }
+
+ /**
+ * Checks that the collection of {@code properties} only contains properties with
allowable names.
+ *
+ * @param context
+ * @param properties
+ * @param validPropertyNames
+ * @throws RepositorySourceException if {@code properties} contains a
+ * @see #ALLOWABLE_PROPERTIES_FOR_CONTENT
+ * @see #ALLOWABLE_PROPERTIES_FOR_FILE_OR_FOLDER
+ */
+ protected void ensureValidProperties( ExecutionContext context,
+ Collection<Property> properties,
+ Set<Name> validPropertyNames ) {
+ List<String> invalidNames = new LinkedList<String>();
+ NamespaceRegistry registry = context.getNamespaceRegistry();
+
+ for (Property property : properties) {
+ if (!validPropertyNames.contains(property.getName())) {
+ invalidNames.add(property.getName().getString(registry));
+ }
+ }
+
+ if (!invalidNames.isEmpty()) {
+ throw new RepositorySourceException(getSourceName(),
+
SvnRepositoryConnectorI18n.invalidPropertyNames.text(invalidNames.toString()));
+ }
+ }
+
+ }
+
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepository.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorI18n.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorI18n.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorI18n.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -0,0 +1,89 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+* See the AUTHORS.txt file in the distribution for a full listing of
+* individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn2;
+
+import java.util.Locale;
+import java.util.Set;
+import org.jboss.dna.common.i18n.I18n;
+
+/**
+ * The internationalized string constants for the
<code>org.jboss.dna.connector.svn*</code> packages.
+ */
+public final class SvnRepositoryConnectorI18n {
+
+ public static I18n connectorName;
+ public static I18n nodeDoesNotExist;
+ public static I18n nodeIsActuallyUnknow;
+ public static I18n propertyIsRequired;
+ public static I18n errorSerializingCachePolicyInSource;
+ public static I18n locationInRequestMustHavePath;
+ public static I18n sourceIsReadOnly;
+ public static I18n sourceDoesNotSupportCreatingWorkspaces;
+ public static I18n sourceDoesNotSupportCloningWorkspaces;
+ public static I18n sourceDoesNotSupportDeletingWorkspaces;
+ public static I18n connectingFailureOrUserAuthenticationProblem;
+ public static I18n pathForPredefinedWorkspaceDoesNotExist;
+ public static I18n pathForPredefinedWorkspaceIsNotDirectory;
+ public static I18n pathForPredefinedWorkspaceCannotBeRead;
+ public static I18n workspaceDoesNotExist;
+ public static I18n pathForDefaultWorkspaceDoesNotExist;
+ public static I18n pathForDefaultWorkspaceIsNotDirectory;
+ public static I18n pathForDefaultWorkspaceCannotBeRead;
+ public static I18n sameNameSiblingsAreNotAllowed;
+ public static I18n onlyTheDefaultNamespaceIsAllowed;
+ public static I18n unableToCreateWorkspaces;
+ public static I18n pathForRequestIsNotCorrect;
+ public static I18n pathForRequestMustStartWithAForwardSlash;
+ public static I18n nodeAlreadyExist;
+ public static I18n unsupportedPrimaryType;
+ public static I18n invalidPropertyNames;
+ public static I18n invalidNameForResource;
+ public static I18n invalidPathForResource;
+ public static I18n missingRequiredProperty;
+ public static I18n couldNotCreateFile;
+ public static I18n couldNotReadData;
+ public static I18n deleteFailed;
+
+ static {
+ try {
+ I18n.initialize(SvnRepositoryConnectorI18n.class);
+ } catch (final Exception err) {
+ System.err.println(err);
+ }
+ }
+
+ public static Set<Locale> getLocalizationProblemLocales() {
+ return I18n.getLocalizationProblemLocales(SvnRepositoryConnectorI18n.class);
+ }
+
+ public static Set<String> getLocalizationProblems() {
+ return I18n.getLocalizationProblems(SvnRepositoryConnectorI18n.class);
+ }
+
+ public static Set<String> getLocalizationProblems( Locale locale ) {
+ return I18n.getLocalizationProblems(SvnRepositoryConnectorI18n.class, locale);
+ }
+
+
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorI18n.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositoryLexicon.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositoryLexicon.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositoryLexicon.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -0,0 +1,43 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn2;
+
+import org.jboss.dna.connector.svn2.SvnRepositorySource;
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.basic.BasicName;
+
+/**
+ * The namespace and property names used within a {@link SvnRepositorySource} to store
internal information.
+ */
+public class SvnRepositoryLexicon {
+
+ public static class Namespace {
+ public static final String URI =
"http://www.jboss.org/dna/connector/svn";
+ public static final String PREFIX = "dnasvn";
+ }
+
+ public static final Name CHILD_PATH_SEGMENT_LIST = new BasicName(Namespace.URI,
"orderedChildNames");
+ public static final Name UUID = new BasicName(Namespace.URI, "uuid");
+
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositoryLexicon.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositorySource.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositorySource.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositorySource.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -0,0 +1,408 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn2;
+
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import javax.naming.spi.ObjectFactory;
+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.StringUtil;
+import org.jboss.dna.graph.connector.RepositoryConnection;
+import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.connector.RepositorySourceCapabilities;
+import org.jboss.dna.graph.connector.RepositorySourceException;
+import org.jboss.dna.graph.connector.path.AbstractPathRepositorySource;
+import org.jboss.dna.graph.connector.path.PathRepositoryConnection;
+
+/**
+ * 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.
+ */
+@ThreadSafe
+public class SvnRepositorySource extends AbstractPathRepositorySource implements
ObjectFactory {
+
+ /**
+ * The first serialized version of this source. Version {@value} .
+ */
+ 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 ROOT_NODE_UUID = "rootNodeUuid";
+ 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.
+ */
+ protected static final boolean SUPPORTS_EVENTS = true;
+ /**
+ * This source supports same-name-siblings.
+ */
+ protected static final boolean SUPPORTS_SAME_NAME_SIBLINGS = false;
+ /**
+ * This source does support creating workspaces.
+ */
+ 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;
+
+ private volatile String repositoryRootUrl;
+ private volatile String username;
+ private volatile String password;
+ 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 transient SvnRepository repository;
+
+ /**
+ * Create a repository source instance.
+ */
+ public SvnRepositorySource() {
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#getCapabilities()
+ */
+ public RepositorySourceCapabilities getCapabilities() {
+ return capabilities;
+ }
+
+ /**
+ * @return the url
+ */
+ public String getRepositoryRootUrl() {
+ return this.repositoryRootUrl;
+ }
+
+ /**
+ * Set the url for the subversion repository.
+ *
+ * @param url - the url location.
+ * @throws IllegalArgumentException If svn url is null or empty
+ */
+ public synchronized void setRepositoryRootUrl( String url ) {
+ CheckArg.isNotEmpty(url, "RepositoryRootUrl");
+ this.repositoryRootUrl = url;
+ }
+
+ public String getUsername() {
+ return this.username;
+ }
+
+ /**
+ * @param username
+ */
+ public synchronized void setUsername( String username ) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return this.password;
+ }
+
+ /**
+ * @param password
+ */
+ public synchronized void setPassword( String password ) {
+ this.password = password;
+ }
+
+ /**
+ * Get whether this source supports updates.
+ *
+ * @return true if this source supports updates, or false if this source only
supports reading content.
+ */
+ public boolean getSupportsUpdates() {
+ return capabilities.supportsUpdates();
+ }
+
+ /**
+ * 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 String getDirectoryForDefaultWorkspace() {
+ return defaultWorkspace;
+ }
+
+ public String getDefaultWorkspaceName() {
+ return defaultWorkspace;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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.
+ *
+ * @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 synchronized String[] getPredefinedWorkspaceNames() {
+ String[] copy = new String[predefinedWorkspaces.length];
+ System.arraycopy(predefinedWorkspaces, 0, copy, 0, predefinedWorkspaces.length);
+ return copy;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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 boolean isCreatingWorkspacesAllowed() {
+ return capabilities.supportsCreatingWorkspaces();
+ }
+
+ /**
+ * 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());
+ }
+
+ /**
+ * Get whether this source allows updates.
+ *
+ * @return true if this source allows updates by clients, or false if no updates are
allowed
+ * @see #setUpdatesAllowed(boolean)
+ */
+ @Override
+ public boolean areUpdatesAllowed() {
+ return capabilities.supportsUpdates();
+ }
+
+ /**
+ * Set whether this source allows updates to data within workspaces
+ *
+ * @param allowUpdates true if this source allows updates to data within workspaces
clients, or false if updates are not
+ * allowed.
+ * @see #areUpdatesAllowed()
+ */
+ public synchronized void setUpdatesAllowed( boolean allowUpdates ) {
+ capabilities = new
RepositorySourceCapabilities(capabilities.supportsSameNameSiblings(), allowUpdates,
+ capabilities.supportsEvents(),
capabilities.supportsCreatingWorkspaces(),
+
capabilities.supportsReferences());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj == this) return true;
+ if (obj instanceof SvnRepositorySource) {
+ SvnRepositorySource that = (SvnRepositorySource)obj;
+ if (this.getName() == null) {
+ if (that.getName() != null) return false;
+ } else {
+ if (!this.getName().equals(that.getName())) return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.naming.Referenceable#getReference()
+ */
+ public synchronized Reference getReference() {
+ String className = getClass().getName();
+ String factoryClassName = this.getClass().getName();
+ Reference ref = new Reference(className, factoryClassName, null);
+
+ if (getName() != null) {
+ ref.add(new StringRefAddr(SOURCE_NAME, getName()));
+ }
+ if (getRepositoryRootUrl() != null) {
+ ref.add(new StringRefAddr(SVN_REPOSITORY_ROOT_URL, getRepositoryRootUrl()));
+ }
+ if (getUsername() != null) {
+ ref.add(new StringRefAddr(SVN_USERNAME, getUsername()));
+ }
+ if (getPassword() != null) {
+ ref.add(new StringRefAddr(SVN_PASSWORD, getPassword()));
+ }
+ ref.add(new StringRefAddr(RETRY_LIMIT, Integer.toString(getRetryLimit())));
+ ref.add(new StringRefAddr(ROOT_NODE_UUID, rootNodeUuid.toString()));
+ 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)));
+ }
+ return ref;
+
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object,
javax.naming.Name, javax.naming.Context,
+ * java.util.Hashtable)
+ */
+ public Object getObjectInstance( Object obj,
+ Name name,
+ Context nameCtx,
+ Hashtable<?, ?> environment ) throws Exception
{
+ if (!(obj instanceof Reference)) return null;
+
+ Map<String, Object> values = valuesFrom((Reference)obj);
+
+ String sourceName = (String)values.get(SOURCE_NAME);
+ String repositoryRootUrl = (String)values.get(SVN_REPOSITORY_ROOT_URL);
+ String username = (String)values.get(SVN_USERNAME);
+ String password = (String)values.get(SVN_PASSWORD);
+ String retryLimit = (String)values.get(RETRY_LIMIT);
+ String rootNodeUuid = (String)values.get(ROOT_NODE_UUID);
+ String defaultWorkspace = (String)values.get(DEFAULT_WORKSPACE);
+ String createWorkspaces = (String)values.get(ALLOW_CREATING_WORKSPACES);
+
+ String combinedWorkspaceNames = (String)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 (repositoryRootUrl != null && repositoryRootUrl.length() > 0)
source.setRepositoryRootUrl(repositoryRootUrl);
+ if (username != null) source.setUsername(username);
+ if (password != null) source.setPassword(password);
+ if (retryLimit != null) source.setRetryLimit(Integer.parseInt(retryLimit));
+ if (rootNodeUuid != null) source.setRootNodeUuid(rootNodeUuid);
+ 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;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#getConnection()
+ */
+ public synchronized 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"));
+ }
+
+ if (this.repository == null) {
+ this.repository = new SvnRepository(this);
+ }
+
+ return new PathRepositoryConnection(this, this.repository);
+ }
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositorySource.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositoryUtil.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositoryUtil.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositoryUtil.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -0,0 +1,235 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn2;
+
+import java.util.Collection;
+import java.util.Collections;
+import org.jboss.dna.graph.connector.RepositorySourceException;
+import org.jboss.dna.graph.request.InvalidWorkspaceException;
+import org.tmatesoft.svn.core.SVNDirEntry;
+import org.tmatesoft.svn.core.SVNErrorCode;
+import org.tmatesoft.svn.core.SVNErrorMessage;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.SVNNodeKind;
+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;
+
+/**
+ */
+public class SvnRepositoryUtil {
+
+ /**
+ * @param url
+ * @param sourceName
+ * @return SVNURL
+ */
+ public static SVNURL createSVNURL( String url,
+ String sourceName ) {
+
+ SVNURL theUrl;
+ try {
+ theUrl = SVNURL.parseURIDecoded(url);
+ } catch (SVNException e) {
+ // protocol not supported by this connector
+ throw new RepositorySourceException(sourceName,
+ "Protocol is not supported by this
connector or there is problem in the svn url");
+ }
+ return theUrl;
+ }
+
+ public static void setNewSVNRepositoryLocation( SVNRepository oldRespository,
+ String url,
+ boolean forceReconnect,
+ String sourceName ) {
+ try {
+ oldRespository.setLocation(createSVNURL(url, sourceName), forceReconnect);
+ } catch (SVNException e) {
+ throw new RepositorySourceException(sourceName, "the old url and a new
one has got different protocols");
+ }
+ }
+
+ /**
+ * @param repository
+ * @param path
+ * @param revisionNumber
+ * @param sourceName
+ * @return SVNNodeKind
+ */
+ public static SVNNodeKind checkThePath( SVNRepository repository,
+ String path,
+ long revisionNumber,
+ String sourceName ) {
+ SVNNodeKind kind;
+ try {
+ kind = repository.checkPath(path, revisionNumber);
+
+ } catch (SVNException e) {
+ return null;
+ }
+ return kind;
+ }
+
+ /**
+ * Create a {@link SVNRepository} from a http protocol.
+ *
+ * @param url - the url of the repository.
+ * @param username - username credential.
+ * @param password - password credential
+ * @return {@link SVNRepository}.
+ */
+ public static SVNRepository createRepository( String url,
+ String username,
+ String password ) {
+ // for DAV (over http and https)
+ DAVRepositoryFactory.setup();
+ // For File
+ FSRepositoryFactory.setup();
+ // for SVN (over svn and svn+ssh)
+ SVNRepositoryFactoryImpl.setup();
+
+ // The factory knows how to create a DAVRepository
+ SVNRepository repository;
+ try {
+ repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url));
+
+ ISVNAuthenticationManager authManager =
SVNWCUtil.createDefaultAuthenticationManager(username, password);
+ repository.setAuthenticationManager(authManager);
+ } catch (SVNException e) {
+ throw new
InvalidWorkspaceException(SvnRepositoryConnectorI18n.workspaceDoesNotExist.text(e.getMessage()));
+ }
+ return repository;
+ }
+
+ /**
+ * Util to get the last segment from a path.
+ *
+ * @param repository
+ * @return last segment.
+ */
+ public static String getRepositoryWorspaceName( SVNRepository repository ) {
+ String[] segments = repository.getLocation().getPath().split("/");
+ return segments[segments.length - 1];
+ }
+
+ private SvnRepositoryUtil() {
+ // prvent construction
+ }
+
+ /**
+ * Check if the repository path exist.
+ *
+ * @param repos
+ * @return true if repository exist and false otherwise.
+ */
+ public static boolean exist( SVNRepository repos ) {
+ try {
+ SVNNodeKind kind = repos.checkPath("", -1);
+ if (kind == SVNNodeKind.NONE) {
+ return false;
+ }
+ return true;
+
+ } catch (SVNException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Check if repository path is a directory.
+ *
+ * @param repos
+ * @param path
+ * @return true if repository path is a directory and false otherwise.
+ */
+ public static boolean isDirectory( SVNRepository repos,
+ String path ) {
+ try {
+ SVNNodeKind kind = repos.checkPath(path, -1);
+ if (kind == SVNNodeKind.DIR) {
+ return true;
+ }
+ } catch (SVNException e) {
+ return false;
+ }
+ return false;
+ }
+
+ /**
+ * @param repos
+ * @param path
+ * @return a collect of entry from directory path; never null
+ */
+ @SuppressWarnings( "unchecked" )
+ public static Collection<SVNDirEntry> getDir( SVNRepository repos,
+ String path ) {
+ try {
+ return repos.getDir(path, -1, null, (Collection<SVNDirEntry>)null);
+ } catch (SVNException e) {
+ return Collections.emptyList();
+ }
+ }
+
+ /**
+ * Check if the path is a file.
+ *
+ * @param repos
+ * @param path
+ * @return true if the path is a file and false otherwise.
+ */
+ public static boolean isFile( SVNRepository repos,
+ String path ) {
+ try {
+ SVNNodeKind kind = repos.checkPath(path, -1);
+ if (kind == SVNNodeKind.FILE) {
+ return true;
+ }
+ } catch (SVNException e) {
+ return false;
+ }
+ return false;
+ }
+
+ public static boolean exists( SVNRepository repository,
+ String path ) throws SVNException{
+ try {
+ if (repository.checkPath(path, -1) == SVNNodeKind.NONE) {
+ return false;
+ } else if (repository.checkPath(path, -1) == SVNNodeKind.UNKNOWN) {
+ return false;
+ }
+ } catch (SVNException e) {
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+ "unknow error during delete
action: {0)",
+ e.getMessage());
+ throw new SVNException(err);
+ }
+ return true;
+ }
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/SvnRepositoryUtil.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/package-info.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/package-info.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/package-info.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -0,0 +1,29 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+/**
+ * The classes that make up the connector that accesses content from an SVN repository.
+ */
+
+package org.jboss.dna.connector.svn2;
+
Property changes on:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn2/package-info.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn2
(from rev 1520,
trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn)
Modified:
trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn2/SVNRepositoryConnectorI18n.properties
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.properties 2010-01-04
15:33:19 UTC (rev 1520)
+++
trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn2/SVNRepositoryConnectorI18n.properties 2010-01-05
12:43:25 UTC (rev 1524)
@@ -54,6 +54,6 @@
# Writable tests
-couldNotCreateFile =Error reading data in workspace "{1}" "{0}"
"{2}" "{3}"
+couldNotCreateFile =Error reading data at path "{0}" in workspace
"{1}" in source "{2}": "{3}"
couldNotReadData= Error reading data in workspace "{1}" "{0}"
"{2}" "{3}"
deleteFailed=Error deleting path {0} in workspace with source name {1}
\ No newline at end of file
Added:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnConnectorTestUtil.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnConnectorTestUtil.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnConnectorTestUtil.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -0,0 +1,177 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn2;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import org.jboss.dna.common.util.FileUtil;
+import org.tmatesoft.svn.core.SVNDirEntry;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.SVNNodeKind;
+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;
+
+/**
+ * @author Serge Pagop
+ */
+public class SvnConnectorTestUtil {
+
+ @SuppressWarnings( "unchecked" )
+ public static void main( String[] args ) throws Exception {
+ try {
+ System.out.println("My repos. ......");
+ String svnUrl =
SvnConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos",
"target/copy_of dummy_svn_repos");
+ String username = "sp";
+ String password = "";
+ System.out.println(svnUrl);
+ SVNRepository trunkWorkspace = createRepository(svnUrl + "/trunk",
username, password);
+ System.out.println("Repository location: " +
trunkWorkspace.getLocation().toString());
+ System.out.println("Repository Root: " +
trunkWorkspace.getRepositoryRoot(true));
+ System.out.println("Repository UUID: " +
trunkWorkspace.getRepositoryUUID(true));
+ /**
+ * Returns the repository location to which this object is set. It may be the
location that was used to create this
+ * object (see {@link SVNRepositoryFactory#create(SVNURL)}), or the recent
one the object was set to.
+ */
+ System.out.println("location: " +
trunkWorkspace.getLocation().getPath());
+ System.out.println("decoded location: " +
trunkWorkspace.getLocation().toDecodedString());
+ System.out.println("last seg: " +
getRepositoryWorspaceName(trunkWorkspace));
+
+ final Collection<SVNDirEntry> dirEntries =
trunkWorkspace.getDir("", -1, null, (Collection<SVNDirEntry>)null);
+ for (SVNDirEntry dirEntry : dirEntries) {
+ System.out.println("name: " + dirEntry.getName());
+ }
+
+ // //
+ // SVNNodeKind nodeKind = trunkWorkspace.checkPath( "/" , -1 );
+ // if ( nodeKind == SVNNodeKind.NONE ) {
+ // System.err.println( "There is no entry in the workspace "+
trunkWorkspace );
+ // System.exit( 1 );
+ // } else if ( nodeKind == SVNNodeKind.FILE ) {
+ // System.err.println( "The entry at '" + trunkWorkspace +
"' is a file while a directory was expected." );
+ // System.exit( 1 );
+ // } else {
+ // listEntries(trunkWorkspace, "/root");
+ // // long latestRevision = trunkWorkspace.getLatestRevision( );
+ // // System.out.println( "workspace latest revision: " +
latestRevision );
+ //
+ // //// SVNNodeKind kind = trunkWorkspace.checkPath("/", -1);
+ // // if(kind == SVNNodeKind.NONE) {
+ // // System.out.println("none");
+ // // } else if(kind == SVNNodeKind.UNKNOWN) {
+ // // System.out.println("unknown");
+ // // } else if(kind == SVNNodeKind.FILE) {
+ // // System.out.println("file");
+ // // } else if(kind == SVNNodeKind.DIR) {
+ // System.out.println("dir");
+ // // listEntries(trunkWorkspace,"root");
+ // }
+
+ } catch (SVNException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Create a {@link SVNRepository} from a http protocol.
+ *
+ * @param url - the url of the repository.
+ * @param username - username credential.
+ * @param password - password credential
+ * @return {@link SVNRepository}.
+ * @throws SVNException - when error situation.
+ */
+ public static SVNRepository createRepository( String url,
+ String username,
+ String password ) throws SVNException
{
+ // for DAV (over http and https)
+ DAVRepositoryFactory.setup();
+ // For File
+ FSRepositoryFactory.setup();
+ // for SVN (over svn and svn+ssh)
+ SVNRepositoryFactoryImpl.setup();
+
+ // The factory knows how to create a DAVRepository
+ SVNRepository repository =
SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url));
+ ISVNAuthenticationManager authManager =
SVNWCUtil.createDefaultAuthenticationManager(username, password);
+ repository.setAuthenticationManager(authManager);
+ return repository;
+ }
+
+ public static String createURL( String src,
+ String dst ) throws IOException, SVNException {
+ // First we need to find the absolute path. Note that Maven always runs the tests
from the project's directory,
+ // so use new File to create an instance at the current location ...
+ File mySrc = new File(src);
+ File myDst = new File(dst);
+
+ // make sure the destination is empty before we copy
+ FileUtil.delete(myDst);
+ FileUtil.copy(mySrc, myDst);
+
+ // Now set the two path roots
+ String url = myDst.getCanonicalFile().toURI().toURL().toExternalForm();
+
+ url = url.replaceFirst("file:/", "file://localhost/");
+
+ // Have to decode the URL ...
+ SVNURL encodedUrl = SVNURL.parseURIEncoded(url);
+ url = encodedUrl.toDecodedString();
+
+ if (!url.endsWith("/")) url = url + "/";
+ return url;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ public static void listEntries( SVNRepository workspace,
+ String path ) throws SVNException {
+ Collection<SVNDirEntry> entries = workspace.getDir(path, -1, null,
(Collection)null);
+ Iterator<SVNDirEntry> iterator = entries.iterator();
+ while (iterator.hasNext()) {
+ SVNDirEntry entry = iterator.next();
+ System.out.println("/" + (path.equals("") ? ""
: path + "/") + entry.getName() + " ( author: '" +
entry.getAuthor()
+ + "'; revision: " + entry.getRevision() +
"; date: " + entry.getDate() + ")");
+ if (entry.getKind() == SVNNodeKind.DIR) {
+ listEntries(workspace, (path.equals("")) ? entry.getName() :
path + "/" + entry.getName());
+ }
+ }
+ }
+
+ public static String getRepositoryWorspaceName( SVNRepository repository ) {
+ String[] segments = repository.getLocation().getPath().split("/");
+ return segments[segments.length - 1];
+ }
+
+ private SvnConnectorTestUtil() {
+ // prevent constructor
+ }
+
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnConnectorTestUtil.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnIntegrationTest.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnIntegrationTest.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnIntegrationTest.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -0,0 +1,110 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn2;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.util.Map;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.Location;
+import org.jboss.dna.graph.Node;
+import org.jboss.dna.graph.Subgraph;
+import org.jboss.dna.graph.connector.RepositoryConnection;
+import org.jboss.dna.graph.connector.RepositoryConnectionFactory;
+import org.jboss.dna.graph.connector.RepositoryContext;
+import org.jboss.dna.graph.connector.RepositorySourceException;
+import org.jboss.dna.graph.observe.Observer;
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.Property;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SvnIntegrationTest {
+
+ private ExecutionContext context;
+ private SvnRepositorySource source;
+ private String repositoryUrl;
+ private String[] predefinedWorkspaceNames;
+
+ @Before
+ public void beforeEach() {
+ repositoryUrl = "http://anonsvn.jboss.org/repos/dna/";
+ predefinedWorkspaceNames = new String[] {repositoryUrl + "trunk",
repositoryUrl + "tags", repositoryUrl + "branches"};
+ context = new ExecutionContext();
+ source = new SvnRepositorySource();
+ source.setName("svn repository source");
+ source.setRepositoryRootUrl(repositoryUrl);
+ source.setUsername("anonymous");
+ source.setPassword("");
+ source.setCreatingWorkspacesAllowed(true);
+ source.setPredefinedWorkspaceNames(predefinedWorkspaceNames);
+ source.setDirectoryForDefaultWorkspace(predefinedWorkspaceNames[0]);
+ source.setCreatingWorkspacesAllowed(false);
+ source.initialize(new RepositoryContext() {
+
+ public Subgraph getConfiguration( int depth ) {
+ return null;
+ }
+
+ public ExecutionContext getExecutionContext() {
+ return context;
+ }
+
+ public Observer getObserver() {
+ return null;
+ }
+
+ public RepositoryConnectionFactory getRepositoryConnectionFactory() {
+ return new RepositoryConnectionFactory() {
+
+ public RepositoryConnection createConnection( String sourceName )
throws RepositorySourceException {
+ return null;
+ }
+
+ };
+ }
+
+ });
+ }
+
+ @Test
+ public void shouldConnectAndReadRootNode() {
+ Graph graph = Graph.create(source, context);
+ Map<Name, Property> properties =
graph.getPropertiesByName().on("/");
+ assertThat(properties, is(notNullValue()));
+
+ Node root = graph.getNodeAt("/");
+ assertThat(root, is(notNullValue()));
+ assertThat(root.getLocation(), is(notNullValue()));
+ assertThat(root.getChildren().isEmpty(), is(false));
+ for (Location childLocation : root.getChildren()) {
+ assertThat(childLocation.getPath().getParent().isRoot(), is(true));
+ // Node child = graph.getNodeAt(childLocation);
+ // assertThat(child.getLocation(), is(childLocation));
+ // assertThat(child.getLocation().getPath().getParent().isRoot(), is(true));
+ }
+ }
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnIntegrationTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorI18nTest.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorI18nTest.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorI18nTest.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -0,0 +1,35 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn2;
+
+import org.jboss.dna.common.AbstractI18nTest;
+
+/**
+ */
+public class SvnRepositoryConnectorI18nTest extends AbstractI18nTest {
+
+ public SvnRepositoryConnectorI18nTest() {
+ super(SvnRepositoryConnectorI18n.class);
+ }
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorI18nTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorNoCreateWorkspaceTest.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorNoCreateWorkspaceTest.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorNoCreateWorkspaceTest.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -0,0 +1,68 @@
+package org.jboss.dna.connector.svn2;
+
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.connector.test.WorkspaceConnectorTest;
+import org.junit.BeforeClass;
+
+public class SvnRepositoryConnectorNoCreateWorkspaceTest extends WorkspaceConnectorTest
{
+
+ private static String url;
+
+ @BeforeClass
+ public static void beforeAny() throws Exception {
+ url =
SvnConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos",
"target/copy_of dummy_svn_repos");
+
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.test.AbstractConnectorTest#setUpSource()
+ */
+ @Override
+ protected RepositorySource setUpSource() throws Exception {
+ String[] predefinedWorkspaceNames = new String[] {url + "trunk", url +
"tags"};
+ SvnRepositorySource source = new SvnRepositorySource();
+ source.setName("Test Repository");
+ source.setUsername("sp");
+ source.setPassword("");
+ source.setRepositoryRootUrl(url);
+ source.setPredefinedWorkspaceNames(predefinedWorkspaceNames);
+ source.setDirectoryForDefaultWorkspace(predefinedWorkspaceNames[0]);
+ source.setCreatingWorkspacesAllowed(false);
+
+ return source;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.graph.connector.test.AbstractConnectorTest#initializeContent(org.jboss.dna.graph.Graph)
+ */
+ @Override
+ protected void initializeContent( Graph graph ) throws Exception {
+ // No need to initialize any content ...
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.graph.connector.test.WorkspaceConnectorTest#generateInvalidNamesForNewWorkspaces()
+ */
+ @Override
+ protected String[] generateInvalidNamesForNewWorkspaces() {
+ return null; // nothing is considered invalid
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.graph.connector.test.WorkspaceConnectorTest#generateValidNamesForNewWorkspaces()
+ */
+ @Override
+ protected String[] generateValidNamesForNewWorkspaces() {
+ return new String[] {url + "branches"};
+ }
+
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorNoCreateWorkspaceTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorNotWritableTest.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorNotWritableTest.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorNotWritableTest.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -0,0 +1,48 @@
+package org.jboss.dna.connector.svn2;
+
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.connector.test.NotWritableConnectorTest;
+import org.junit.BeforeClass;
+
+public class SvnRepositoryConnectorNotWritableTest extends NotWritableConnectorTest {
+
+ private static String url;
+
+ @BeforeClass
+ public static void beforeAny() throws Exception {
+ url =
SvnConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos",
"target/copy_of dummy_svn_repos");
+
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.test.AbstractConnectorTest#setUpSource()
+ */
+ @Override
+ protected RepositorySource setUpSource() throws Exception {
+ String[] predefinedWorkspaceNames = new String[]{url+"trunk",
url+"tags"};
+ SvnRepositorySource source = new SvnRepositorySource();
+ source.setName("Test Repository");
+ source.setUsername("sp");
+ source.setPassword("");
+ source.setRepositoryRootUrl(url);
+ source.setPredefinedWorkspaceNames(predefinedWorkspaceNames);
+ source.setDirectoryForDefaultWorkspace(predefinedWorkspaceNames[0]);
+ source.setCreatingWorkspacesAllowed(false);
+
+ return source;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.graph.connector.test.AbstractConnectorTest#initializeContent(org.jboss.dna.graph.Graph)
+ */
+ @Override
+ protected void initializeContent( Graph graph ) {
+ // No need to initialize any content ...
+ }
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorNotWritableTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorWritableTest.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorWritableTest.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorWritableTest.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -0,0 +1,360 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn2;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.io.ByteArrayOutputStream;
+import org.jboss.dna.graph.DnaLexicon;
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.JcrLexicon;
+import org.jboss.dna.graph.JcrMixLexicon;
+import org.jboss.dna.graph.JcrNtLexicon;
+import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.connector.RepositorySourceException;
+import org.jboss.dna.graph.connector.test.AbstractConnectorTest;
+import org.jboss.dna.graph.property.PathNotFoundException;
+import org.junit.Test;
+import org.tmatesoft.svn.core.SVNNodeKind;
+import org.tmatesoft.svn.core.SVNProperties;
+import org.tmatesoft.svn.core.io.SVNRepository;
+
+/**
+ * @author Serge Pagop
+ */
+public class SvnRepositoryConnectorWritableTest extends AbstractConnectorTest {
+
+ protected static final String EMPTY_CONTENT = "";
+ protected static final String TEST_CONTENT = "Test content";
+ protected SVNRepository remoteRepos = null;
+ protected String url;
+ protected SVNNodeKind kind = null;
+ protected SVNProperties fileProperties = null;
+ protected ByteArrayOutputStream baos = null;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.test.AbstractConnectorTest#setUpSource()
+ */
+ @Override
+ protected RepositorySource setUpSource() throws Exception {
+ url =
SvnConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos",
"target/copy_of dummy_svn_repos");
+ String[] predefinedWorkspaceNames = new String[] {url + "trunk", url +
"tags"};
+ SvnRepositorySource source = new SvnRepositorySource();
+ source.setName("Test Repository");
+ source.setUsername("sp");
+ source.setPassword("");
+ source.setRepositoryRootUrl(url);
+ source.setPredefinedWorkspaceNames(predefinedWorkspaceNames);
+ source.setDirectoryForDefaultWorkspace(predefinedWorkspaceNames[0]);
+ source.setCreatingWorkspacesAllowed(Boolean.TRUE);
+ source.setUpdatesAllowed(true);
+
+ remoteRepos = SvnConnectorTestUtil.createRepository(url + "trunk",
"sp", "");
+
+ return source;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.graph.connector.test.AbstractConnectorTest#initializeContent(org.jboss.dna.graph.Graph)
+ */
+ @Override
+ protected void initializeContent( Graph graph ) throws Exception {
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.test.AbstractConnectorTest#afterEach()
+ */
+ @Override
+ public void afterEach() throws Exception {
+ remoteRepos = null;
+ super.afterEach();
+ }
+
+ @Test( expected = RepositorySourceException.class )
+ public void shouldNotBeAbleToCreateInvalidTypeForRepository() {
+ graph.create("/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.UNSTRUCTURED).orReplace().and();
+ }
+
+ @Test( expected = RepositorySourceException.class )
+ public void shouldNotBeAbleToSetArbitraryProperties() {
+ graph.create("/testFile").with(JcrLexicon.MIXIN_TYPES,
JcrMixLexicon.LOCKABLE).orReplace().and();
+ }
+
+ @Test
+ public void shouldBeAbleToCreateNodeFileWithContentLevel1() throws Exception {
+
+ // LEVEL 0
+ graph.create("/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+ graph.create("/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+ kind = remoteRepos.checkPath("testFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFile", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+
+ graph.create("/testFile1").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+ graph.create("/testFile1/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+ kind = remoteRepos.checkPath("testFile1", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFile1", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+
+ // LEVEL 1
+ graph.create("/root/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+
graph.create("/root/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+ kind = remoteRepos.checkPath("root/testFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("root/testFile", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+
+ // LEVEL 2
+ graph.create("/root/a/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+
graph.create("/root/a/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+ kind = remoteRepos.checkPath("root/a/testFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("root/a/testFile", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+ }
+
+ @Test
+ public void shouldRespectConflictBehaviorOnCreate() throws Exception {
+ graph.create("/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+ graph.create("/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+
+ graph.create("/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
"Should not overwrite".getBytes()).ifAbsent().and();
+
+ kind = remoteRepos.checkPath("testFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFile", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+ }
+
+ @Test
+ public void shouldBeAbleToCreateFileWithNoContent() throws Exception {
+ graph.create("/testEmptyFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+
+ kind = remoteRepos.checkPath("testEmptyFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testEmptyFile", -1, fileProperties, baos);
+ assertContents(baos, EMPTY_CONTENT);
+ }
+
+ @Test
+ public void shouldBeAbleToCreateFolder() throws Exception {
+ graph.create("/testFolder").orReplace().and();
+
+ kind = remoteRepos.checkPath("testFolder", -1);
+ assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
+
+ graph.create("/root/testFolder").orReplace().and();
+
+ kind = remoteRepos.checkPath("root/testFolder", -1);
+ assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
+
+ graph.create("/root/a/testFolder").orReplace().and();
+
+ kind = remoteRepos.checkPath("root/a/testFolder", -1);
+ assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
+ }
+
+ @Test
+ public void shouldBeAbleToAddChildrenToFolder() throws Exception {
+ graph.create("/testFolder").orReplace().and();
+
+ kind = remoteRepos.checkPath("testFolder", -1);
+ assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
+
+ graph.create("/testFolder/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+
graph.create("/testFolder/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+
+ kind = remoteRepos.checkPath("testFolder/testFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFolder/testFile", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+
+ graph.create("/root/testFolder").orReplace().and();
+
+ kind = remoteRepos.checkPath("root/testFolder", -1);
+ assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
+
+ graph.create("/root/testFolder/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+
graph.create("/root/testFolder/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+
+ kind = remoteRepos.checkPath("root/testFolder/testFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("root/testFolder/testFile", -1, fileProperties,
baos);
+ assertContents(baos, TEST_CONTENT);
+ }
+
+ @Test
+ public void shouldBeAbleToCopyFile() throws Exception {
+ graph.create("/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+ graph.create("/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+
+ kind = remoteRepos.checkPath("testFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFile", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+
+ graph.copy("/testFile").to("/copiedFile");
+ kind = remoteRepos.checkPath("copiedFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("copiedFile", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+ }
+
+ @Test
+ public void shouldBeAbleToCopyFolder() throws Exception {
+ graph.create("/testFolder").orReplace().and();
+ graph.create("/testFolder/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+
graph.create("/testFolder/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+
+ kind = remoteRepos.checkPath("testFolder/testFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFolder/testFile", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+
+ graph.copy("/testFolder").to("/copiedFolder");
+ kind = remoteRepos.checkPath("copiedFolder", -1);
+ assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("copiedFolder/testFile", -1, fileProperties,
baos);
+ assertContents(baos, TEST_CONTENT);
+ }
+
+ @Test
+ public void shouldBeAbleToDeleteFolder() throws Exception {
+ graph.create("/testFolder").orReplace().and();
+ graph.create("/testFolder/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+
graph.create("/testFolder/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+ kind = remoteRepos.checkPath("testFolder/testFile", -1);
+ assertThat(kind, is(SVNNodeKind.FILE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFolder/testFile", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+
+ graph.getNodeAt("/testFolder");
+
+ graph.delete("/testFolder").and();
+
+ try {
+ graph.getNodeAt("/testFolder");
+ } catch (PathNotFoundException expected) {
+ // Expected
+ }
+ }
+
+ @Test
+ public void shouldBeAbleToDeleteFile() throws Exception {
+ graph.create("/testFolder").orReplace().and();
+ graph.create("/testFolder/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+
graph.create("/testFolder/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+ kind = remoteRepos.checkPath("testFolder/testFile", -1);
+ assertThat(kind, is(SVNNodeKind.FILE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFolder/testFile", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+
+ graph.getNodeAt("/testFolder/testFile");
+
+ graph.delete("/testFolder/testFile").and();
+
+ try {
+ graph.getNodeAt("/testFolder/testFile");
+ } catch (PathNotFoundException expected) {
+ // Expected
+ }
+ }
+
+ @Test
+ public void shouldBeAbleToClearFileByRemovingDataProperty() throws Exception {
+ graph.create("/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+ graph.create("/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+ kind = remoteRepos.checkPath("testFile", -1);
+ assertThat(kind, is(SVNNodeKind.FILE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFile", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+
+ graph.remove("jcr:data").on("/testFile/jcr:content").and();
+
+ kind = remoteRepos.checkPath("testFile", -1);
+ assertThat(kind, is(SVNNodeKind.FILE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFile", -1, fileProperties, baos);
+ assertContents(baos, "");
+ }
+
+ protected void assertContents( ByteArrayOutputStream baos,
+ String contents ) {
+ assertThat(baos, notNullValue());
+ assertThat(baos.toString(), is(contents));
+ }
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositoryConnectorWritableTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositorySourceTest.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositorySourceTest.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositorySourceTest.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -0,0 +1,310 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn2;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.isNull;
+import static org.mockito.Mockito.mock;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.Subgraph;
+import org.jboss.dna.graph.cache.BasicCachePolicy;
+import org.jboss.dna.graph.connector.RepositoryConnection;
+import org.jboss.dna.graph.connector.RepositoryConnectionFactory;
+import org.jboss.dna.graph.connector.RepositoryContext;
+import org.jboss.dna.graph.connector.RepositorySourceException;
+import org.jboss.dna.graph.observe.Observer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * @author Serge Pagop
+ */
+public class SvnRepositorySourceTest {
+
+ private SvnRepositorySource source;
+ private RepositoryConnection connection;
+ private String validName;
+ private String validUuidPropertyName;
+ private static String url;
+ private String username;
+ private String password;
+ private UUID validRootNodeUuid;
+ private final ExecutionContext context = new ExecutionContext();
+
+ @BeforeClass
+ public static void beforeAny() throws Exception {
+ url =
SvnConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos",
"target/copy_of dummy_svn_repos");
+
+ }
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ this.source = new SvnRepositorySource();
+ // Set the mandatory properties ...
+ this.source.setName("Test Repository");
+ this.source.setUsername("sp");
+ this.source.setPassword("");
+ this.source.setRepositoryRootUrl(url);
+ this.source.initialize(new RepositoryContext() {
+
+ public Subgraph getConfiguration( int depth ) {
+ return null;
+ }
+
+ public ExecutionContext getExecutionContext() {
+ return context;
+ }
+
+ public Observer getObserver() {
+ return null;
+ }
+
+ public RepositoryConnectionFactory getRepositoryConnectionFactory() {
+ return new RepositoryConnectionFactory() {
+
+ public RepositoryConnection createConnection( String sourceName )
throws RepositorySourceException {
+ return null;
+ }
+
+ };
+ }
+
+ });
+ }
+
+ @After
+ public void afterEach() throws Exception {
+ if (this.connection != null) {
+ this.connection.close();
+ }
+ }
+
+ @Test
+ public void shouldReturnNonNullCapabilities() {
+ assertThat(source.getCapabilities(), is(notNullValue()));
+ }
+
+ @Test
+ public void shouldNotSupportSameNameSiblings() {
+ assertThat(source.getCapabilities().supportsSameNameSiblings(), is(false));
+ }
+
+ @Test
+ public void shouldSupportUpdates() {
+ assertThat(source.getCapabilities().supportsUpdates(), is(false));
+ }
+
+ @Test
+ public void shouldHaveNullSourceNameUponConstruction() {
+ source = new SvnRepositorySource();
+ assertThat(source.getName(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldAllowSettingName() {
+ source.setName("name you like");
+ assertThat(source.getName(), is("name you like"));
+ source.setName("name you do not like");
+ assertThat(source.getName(), is("name you do not like"));
+ }
+
+ @Test
+ public void shouldAllowSettingNameToNull() {
+ source.setName("something that can change the world");
+ source.setName(null);
+ assertThat(source.getName(), is(isNull()));
+ }
+
+
+ @Test
+ public void shouldHaveDefaultRetryLimit() {
+ assertThat(source.getRetryLimit(), is(SvnRepositorySource.DEFAULT_RETRY_LIMIT));
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNullSVNUrl() {
+ source.setRepositoryRootUrl(null);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowEmptySVNUrl() {
+ source.setRepositoryRootUrl("");
+ }
+
+ @Test
+ public void shouldSetRetryLimitToZeroWhenSetWithNonPositiveValue() {
+ source.setRetryLimit(0);
+ assertThat(source.getRetryLimit(), is(0));
+ source.setRetryLimit(-1);
+ assertThat(source.getRetryLimit(), is(0));
+ source.setRetryLimit(-100);
+ assertThat(source.getRetryLimit(), is(0));
+ }
+
+ @Test
+ public void shouldAllowRetryLimitToBeSet() {
+ for (int i = 0; i != 100; ++i) {
+ source.setRetryLimit(i);
+ assertThat(source.getRetryLimit(), is(i));
+ }
+ }
+
+ @Test( expected = RepositorySourceException.class )
+ public void shouldFailToCreateConnectionIfSourceHasNoName() {
+ source.setName(null);
+ source.getConnection();
+ }
+
+ @Test( expected = RepositorySourceException.class )
+ public void shouldFailToCreateConnectionIfSourceHasNoUsername() {
+ source.setUsername(null);
+ source.getConnection();
+ }
+
+ @Test( expected = RepositorySourceException.class )
+ public void shouldFailToCreateConnectionIfSourceHasNoPassword() {
+ source.setPassword(null);
+ source.getConnection();
+ }
+
+ @Test
+ public void shouldCreateConnection() throws Exception {
+ connection = source.getConnection();
+ assertThat(connection, is(notNullValue()));
+ }
+
+
+ @Test
+ public void shouldCreateJndiReferenceAndRecreatedObjectFromReference() throws
Exception {
+ BasicCachePolicy cachePolicy = new BasicCachePolicy();
+ cachePolicy.setTimeToLive(1000L, TimeUnit.MILLISECONDS);
+ convertToAndFromJndiReference(validName, validRootNodeUuid, url, username,
password, validUuidPropertyName, 100);
+ }
+
+ @Test
+ public void
shouldCreateJndiReferenceAndRecreatedObjectFromReferenceWithNullProperties() throws
Exception {
+ BasicCachePolicy cachePolicy = new BasicCachePolicy();
+ cachePolicy.setTimeToLive(1000L, TimeUnit.MILLISECONDS);
+ convertToAndFromJndiReference("some source", null, "url1",
null, null, null, 100);
+ convertToAndFromJndiReference(null, null, "url2", null, null, null,
100);
+ }
+
+ private void convertToAndFromJndiReference( String sourceName,
+ UUID rootNodeUuid,
+ String url,
+ String username,
+ String password,
+ String uuidPropertyName,
+ int retryLimit ) throws Exception {
+ source.setRetryLimit(retryLimit);
+ source.setName(sourceName);
+ source.setRepositoryRootUrl(url);
+ source.setUsername(username);
+ source.setPassword(password);
+
+ Reference ref = source.getReference();
+
+ assertThat(ref.getClassName(), is(SvnRepositorySource.class.getName()));
+ assertThat(ref.getFactoryClassName(), is(SvnRepositorySource.class.getName()));
+
+ Map<String, Object> refAttributes = new HashMap<String, Object>();
+ Enumeration<RefAddr> enumeration = ref.getAll();
+ while (enumeration.hasMoreElements()) {
+ RefAddr addr = enumeration.nextElement();
+ refAttributes.put(addr.getType(), addr.getContent());
+ }
+
+ assertThat((String)refAttributes.remove(SvnRepositorySource.SOURCE_NAME),
is(source.getName()));
+
assertThat((String)refAttributes.remove(SvnRepositorySource.SVN_REPOSITORY_ROOT_URL),
is(source.getRepositoryRootUrl()));
+ assertThat((String)refAttributes.remove(SvnRepositorySource.SVN_USERNAME),
is(source.getUsername()));
+ assertThat((String)refAttributes.remove(SvnRepositorySource.SVN_PASSWORD),
is(source.getPassword()));
+ assertThat((String)refAttributes.remove(SvnRepositorySource.ROOT_NODE_UUID),
is(source.getRootNodeUuid().toString()));
+ assertThat((String)refAttributes.remove(SvnRepositorySource.RETRY_LIMIT),
is(Integer.toString(source.getRetryLimit())));
+
assertThat((String)refAttributes.remove(SvnRepositorySource.ALLOW_CREATING_WORKSPACES),
+ is(Boolean.toString(source.isCreatingWorkspacesAllowed())));
+ assertThat((String)refAttributes.remove(SvnRepositorySource.DEFAULT_WORKSPACE),
+ is(source.getDirectoryForDefaultWorkspace()));
+ refAttributes.remove(SvnRepositorySource.PREDEFINED_WORKSPACE_NAMES);
+ assertThat(refAttributes.isEmpty(), is(true));
+
+ // Recreate the object, use a newly constructed source ...
+ ObjectFactory factory = new SvnRepositorySource();
+ Name name = mock(Name.class);
+ Context context = mock(Context.class);
+ Hashtable<?, ?> env = new Hashtable<Object, Object>();
+ SvnRepositorySource recoveredSource =
(SvnRepositorySource)factory.getObjectInstance(ref, name, context, env);
+ assertThat(recoveredSource, is(notNullValue()));
+
+ assertThat(recoveredSource.getName(), is(source.getName()));
+ assertThat(recoveredSource.getRepositoryRootUrl(),
is(source.getRepositoryRootUrl()));
+ assertThat(recoveredSource.getUsername(), is(source.getUsername()));
+ assertThat(recoveredSource.getPassword(), is(source.getPassword()));
+
+ assertThat(recoveredSource.equals(source), is(true));
+ assertThat(source.equals(recoveredSource), is(true));
+ }
+
+ @Test
+ public void shouldAllowMultipleConnectionsToBeOpenAtTheSameTime() throws Exception {
+ List<RepositoryConnection> connections = new
ArrayList<RepositoryConnection>();
+ try {
+ for (int i = 0; i != 10; ++i) {
+ RepositoryConnection conn = source.getConnection();
+ assertThat(conn, is(notNullValue()));
+ connections.add(conn);
+ }
+ } finally {
+ // Close all open connections ...
+ for (RepositoryConnection conn : connections) {
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRepositorySourceTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRespositoryConnectorReadableTest.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRespositoryConnectorReadableTest.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRespositoryConnectorReadableTest.java 2010-01-05
12:43:25 UTC (rev 1524)
@@ -0,0 +1,119 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn2;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.util.List;
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.JcrLexicon;
+import org.jboss.dna.graph.JcrNtLexicon;
+import org.jboss.dna.graph.Location;
+import org.jboss.dna.graph.Node;
+import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.connector.test.ReadableConnectorTest;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author Serge Pagop
+ *
+ */
+public class SvnRespositoryConnectorReadableTest extends ReadableConnectorTest {
+
+ private static String url;
+
+ @BeforeClass
+ public static void beforeAny() throws Exception {
+ url =
SvnConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos",
"target/copy_of dummy_svn_repos");
+
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.test.AbstractConnectorTest#setUpSource()
+ */
+ @Override
+ protected RepositorySource setUpSource() throws Exception {
+ String[] predefinedWorkspaceNames = new String[]{url + "trunk", url +
"tags"};
+ SvnRepositorySource source = new SvnRepositorySource();
+ source.setName("Test Repository");
+ source.setUsername("sp");
+ source.setPassword("");
+ source.setRepositoryRootUrl(url);
+ source.setPredefinedWorkspaceNames(predefinedWorkspaceNames);
+ source.setDirectoryForDefaultWorkspace(predefinedWorkspaceNames[0]);
+ source.setCreatingWorkspacesAllowed(false);
+
+ return source;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.graph.connector.test.AbstractConnectorTest#initializeContent(org.jboss.dna.graph.Graph)
+ */
+ @Override
+ protected void initializeContent( Graph graph ) throws Exception {
+ // No need to initialize any content ...
+ }
+
+ @Test
+ public void shouldFindFolderSpecifiedInPathsAsNodesBelowRoot() {
+ Node root = graph.getNodeAt("/root");
+ assertThatNodeIsFolder(root);
+ Node dnaSubmission = graph.getNodeAt("/root/c/h/JBoss DNA Submission Receipt
for JBoss World 2009.pdf");
+ assertThatNodeIsFile(dnaSubmission, "application/octet-stream", null);
+ }
+
+ public void assertThatNodeIsFolder( Node node ) {
+ assertThat(node, is(notNullValue()));
+ assertThat(node.getProperty(JcrLexicon.PRIMARY_TYPE).getFirstValue(),
is((Object)JcrNtLexicon.FOLDER));
+ }
+
+ public void assertThatNodeIsFile( Node node,
+ String mimeType,
+ String contents ) {
+ assertThat(node, is(notNullValue()));
+ assertThat(node.getProperty(JcrLexicon.PRIMARY_TYPE).getFirstValue(),
is((Object)JcrNtLexicon.FILE));
+
+ // Check that there is one child, and that the child is "jcr:content"
...
+ List<Location> children = node.getChildren();
+ assertThat(children.size(), is(1));
+ Location jcrContentLocation = children.get(0);
+ assertThat(jcrContentLocation.getPath().getLastSegment().getName(),
is(JcrLexicon.CONTENT));
+
+ // Check that the "jcr:content" node is correct ...
+ Node jcrContent = graph.getNodeAt(jcrContentLocation);
+ assertThat(string(jcrContent.getProperty(JcrLexicon.MIMETYPE).getFirstValue()),
is(mimeType));
+ if (contents != null) {
+ assertThat(string(jcrContent.getProperty(JcrLexicon.DATA).getFirstValue()),
is(contents));
+ }
+
+ }
+
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn2/SvnRespositoryConnectorReadableTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF