DNA SVN: r934 - trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2009-05-22 09:34:17 -0400 (Fri, 22 May 2009)
New Revision: 934
Added:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRespositoryConnectorReadableTest.java
Log:
new test cases to test the workspace features
Added: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRespositoryConnectorReadableTest.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRespositoryConnectorReadableTest.java (rev 0)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRespositoryConnectorReadableTest.java 2009-05-22 13:34:17 UTC (rev 934)
@@ -0,0 +1,112 @@
+/*
+ * 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.List;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+
+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.Test;
+
+/**
+ * @author Serge Pagop
+ *
+ */
+public class SVNRespositoryConnectorReadableTest extends ReadableConnectorTest {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.test.AbstractConnectorTest#setUpSource()
+ */
+ @Override
+ protected RepositorySource setUpSource() throws Exception {
+ String repositoryRootURL = SVNConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos", "target/copy_of dummy_svn_repos");
+ String[] predefinedWorkspaceNames = new String[]{repositoryRootURL + "trunk", repositoryRootURL + "tags"};
+ SVNRepositorySource source = new SVNRepositorySource();
+ source.setName("Test Repository");
+ source.setUsername("sp");
+ source.setPassword("");
+ source.setRepositoryRootURL(repositoryRootURL);
+ 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));
+ }
+
+ }
+
+}
15 years, 1 month
DNA SVN: r933 - trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2009-05-22 09:34:03 -0400 (Fri, 22 May 2009)
New Revision: 933
Added:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorCreateWorspaceTest.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorNoCreateWorspaceTest.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorNoWritableTest.java
Log:
new test cases to test the workspace features
Added: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorCreateWorspaceTest.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorCreateWorspaceTest.java (rev 0)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorCreateWorspaceTest.java 2009-05-22 13:34:03 UTC (rev 933)
@@ -0,0 +1,88 @@
+package org.jboss.dna.connector.svn;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import java.util.HashSet;
+import java.util.Set;
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.Workspace;
+import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.connector.test.WorkspaceConnectorTest;
+import org.junit.Test;
+
+public class SVNRepositoryConnectorCreateWorspaceTest extends WorkspaceConnectorTest {
+
+
+ private String repositoryRootURL;
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.test.AbstractConnectorTest#setUpSource()
+ */
+ @Override
+ protected RepositorySource setUpSource() throws Exception {
+ repositoryRootURL = SVNConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos", "target/copy_of dummy_svn_repos");
+ String[] predefinedWorkspaceNames = new String[]{repositoryRootURL + "trunk", repositoryRootURL + "tags"};
+ SVNRepositorySource source = new SVNRepositorySource();
+ source.setName("Test Repository");
+ source.setUsername("sp");
+ source.setPassword("");
+ source.setRepositoryRootURL(repositoryRootURL);
+ source.setPredefinedWorkspaceNames(predefinedWorkspaceNames);
+ source.setDirectoryForDefaultWorkspace(predefinedWorkspaceNames[0]);
+ source.setCreatingWorkspacesAllowed(true);
+
+ 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[] { repositoryRootURL + "branches"};
+ }
+
+ @Test
+ public void shouldReturnListOfWorkspacesMatchingRepositoryURLs() throws Exception {
+ // The the actual names of the workspaces ...
+ Set<String> workspaceNames = new HashSet<String>();
+ for (String workspaceName : graph.getWorkspaces()) {
+ Workspace workspace = graph.useWorkspace(workspaceName);
+ workspaceNames.add(workspace.getName());
+ }
+
+ assertThat(workspaceNames.remove(repositoryRootURL + "trunk"), is(true));
+ assertThat(workspaceNames.remove(repositoryRootURL + "tags"), is(true));
+ assertThat(workspaceNames.isEmpty(), is(true));
+
+ // The actual names of the workspaces should also be canonical paths ...
+ workspaceNames = new HashSet<String>(graph.getWorkspaces());
+ assertThat(workspaceNames.remove(repositoryRootURL + "trunk"), is(true));
+ assertThat(workspaceNames.remove(repositoryRootURL + "tags"), is(true));
+ assertThat(workspaceNames.isEmpty(), is(true));
+ }
+
+}
Added: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorNoCreateWorspaceTest.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorNoCreateWorspaceTest.java (rev 0)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorNoCreateWorspaceTest.java 2009-05-22 13:34:03 UTC (rev 933)
@@ -0,0 +1,62 @@
+package org.jboss.dna.connector.svn;
+
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.connector.test.WorkspaceConnectorTest;
+
+public class SVNRepositoryConnectorNoCreateWorspaceTest extends WorkspaceConnectorTest {
+
+
+ private String repositoryRootURL;
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.test.AbstractConnectorTest#setUpSource()
+ */
+ @Override
+ protected RepositorySource setUpSource() throws Exception {
+ repositoryRootURL = SVNConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos", "target/copy_of dummy_svn_repos");
+ String[] predefinedWorkspaceNames = new String[]{repositoryRootURL+"trunk", repositoryRootURL+"tags"};
+ SVNRepositorySource source = new SVNRepositorySource();
+ source.setName("Test Repository");
+ source.setUsername("sp");
+ source.setPassword("");
+ source.setRepositoryRootURL(repositoryRootURL);
+ 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[] {repositoryRootURL + "branches"};
+ }
+
+}
Added: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorNoWritableTest.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorNoWritableTest.java (rev 0)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorNoWritableTest.java 2009-05-22 13:34:03 UTC (rev 933)
@@ -0,0 +1,41 @@
+package org.jboss.dna.connector.svn;
+
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.connector.test.NotWritableConnectorTest;
+
+public class SVNRepositoryConnectorNoWritableTest extends NotWritableConnectorTest {
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.test.AbstractConnectorTest#setUpSource()
+ */
+ @Override
+ protected RepositorySource setUpSource() throws Exception {
+ String repositoryRootURL = SVNConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos", "target/copy_of dummy_svn_repos");
+ String[] predefinedWorkspaceNames = new String[]{repositoryRootURL+"trunk", repositoryRootURL+"tags"};
+ SVNRepositorySource source = new SVNRepositorySource();
+ source.setName("Test Repository");
+ source.setUsername("sp");
+ source.setPassword("");
+ source.setRepositoryRootURL(repositoryRootURL);
+ 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 ...
+ }
+}
15 years, 1 month
DNA SVN: r932 - trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2009-05-22 09:33:13 -0400 (Fri, 22 May 2009)
New Revision: 932
Modified:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java
Log:
changes made to support workspace features and enhanced tests
Modified: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java 2009-05-22 13:32:37 UTC (rev 931)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java 2009-05-22 13:33:13 UTC (rev 932)
@@ -25,8 +25,12 @@
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;
@@ -41,17 +45,64 @@
*/
public class SVNConnectorTestUtil {
+ @SuppressWarnings("unchecked")
public static void main( String[] args ) throws Exception {
try {
- System.out.println("hello ......");
+ 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 = "";
- SVNRepository repos = createRepository(svnUrl, username, password);
- System.out.println("Repository Root: " + repos.getRepositoryRoot(true));
- System.out.println("Repository UUID: " + repos.getRepositoryUUID(true));
- System.out.println("hello ......");
+ 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();
}
}
@@ -80,8 +131,9 @@
repository.setAuthenticationManager(authManager);
return repository;
}
-
- public static String createURL(String src, String dst) throws IOException {
+
+ public static String createURL( String src,
+ String dst ) throws IOException {
// 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);
@@ -95,8 +147,29 @@
String url = myDst.getCanonicalFile().toURL().toString();
return url.replaceFirst("file:/", "file://localhost/");
}
+
+ @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
}
-}
\ No newline at end of file
+}
15 years, 1 month
DNA SVN: r931 - trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2009-05-22 09:32:37 -0400 (Fri, 22 May 2009)
New Revision: 931
Modified:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositorySourceTest.java
Log:
changes made to support workspace features and enhanced tests
Modified: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositorySourceTest.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositorySourceTest.java 2009-05-22 13:32:05 UTC (rev 930)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositorySourceTest.java 2009-05-22 13:32:37 UTC (rev 931)
@@ -44,6 +44,7 @@
import javax.naming.spi.ObjectFactory;
import org.jboss.dna.graph.cache.BasicCachePolicy;
import org.jboss.dna.graph.connector.RepositoryConnection;
+import org.jboss.dna.graph.connector.RepositorySourceException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -58,7 +59,7 @@
private RepositoryConnection connection;
private String validName;
private String validUuidPropertyName;
- private String url;
+ private String repositoryRootURL;
private String username;
private String password;
private UUID validRootNodeUuid;
@@ -66,17 +67,20 @@
@Before
public void beforeEach() throws Exception {
MockitoAnnotations.initMocks(this);
- validName = "svn source";
- validUuidPropertyName = "dna:uuid";
- url = SVNConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos", "target/copy_of dummy_svn_repos");
- validRootNodeUuid = UUID.randomUUID();
- source = new SVNRepositorySource();
+ repositoryRootURL = SVNConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos",
+ "target/copy_of dummy_svn_repos");
+ this.source = new SVNRepositorySource();
+ // Set the mandatory properties ...
+ this.source.setName("Test Repository");
+ this.source.setUsername("sp");
+ this.source.setPassword("");
+ this.source.setRepositoryRootURL(repositoryRootURL);
}
@After
public void afterEach() throws Exception {
- if (connection != null) {
- connection.close();
+ if (this.connection != null) {
+ this.connection.close();
}
}
@@ -92,11 +96,12 @@
@Test
public void shouldSupportUpdates() {
- assertThat(source.getCapabilities().supportsUpdates(), is(true));
+ assertThat(source.getCapabilities().supportsUpdates(), is(false));
}
@Test
public void shouldHaveNullSourceNameUponConstruction() {
+ source = new SVNRepositorySource();
assertThat(source.getName(), is(nullValue()));
}
@@ -115,31 +120,23 @@
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.setSVNURL(null);
+ source.setRepositoryRootURL(null);
}
@Test( expected = IllegalArgumentException.class )
public void shouldNotAllowEmptySVNUrl() {
- source.setSVNURL("");
+ source.setRepositoryRootURL("");
}
@Test
- public void shouldAllowSettingEmptyCredentialsForAnnonymousAccess() {
- source.setSVNUsername("");
- assertThat(source.getSVNUsername(), is(notNullValue()));
- source.setSVNPassword("");
- assertThat(source.getSVNPassword(), is(notNullValue()));
-
- }
-
- @Test
- public void shouldHaveDefaultRetryLimit() {
- assertThat(source.getRetryLimit(), is(SVNRepositorySource.DEFAULT_RETRY_LIMIT));
- }
-
- @Test
public void shouldSetRetryLimitToZeroWhenSetWithNonPositiveValue() {
source.setRetryLimit(0);
assertThat(source.getRetryLimit(), is(0));
@@ -156,27 +153,45 @@
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,
- cachePolicy,
- 100);
+ convertToAndFromJndiReference(validName, validRootNodeUuid, repositoryRootURL, 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, null, 100);
- convertToAndFromJndiReference(null, null, "url2", null, null, null, null, 100);
+ convertToAndFromJndiReference("some source", null, "url1", null, null, null, 100);
+ convertToAndFromJndiReference(null, null, "url2", null, null, null, 100);
}
private void convertToAndFromJndiReference( String sourceName,
@@ -185,14 +200,12 @@
String username,
String password,
String uuidPropertyName,
- BasicCachePolicy cachePolicy,
int retryLimit ) throws Exception {
source.setRetryLimit(retryLimit);
source.setName(sourceName);
- source.setSVNURL(url);
- source.setSVNUsername(username);
- source.setSVNPassword(password);
- source.setDefaultCachePolicy(cachePolicy);
+ source.setRepositoryRootURL(url);
+ source.setUsername(username);
+ source.setPassword(password);
Reference ref = source.getReference();
@@ -207,11 +220,16 @@
}
assertThat((String)refAttributes.remove(SVNRepositorySource.SOURCE_NAME), is(source.getName()));
- assertThat((String)refAttributes.remove(SVNRepositorySource.SVN_URL), is(source.getSVNURL()));
- assertThat((String)refAttributes.remove(SVNRepositorySource.SVN_USERNAME), is(source.getSVNUsername()));
- assertThat((String)refAttributes.remove(SVNRepositorySource.SVN_PASSWORD), is(source.getSVNPassword()));
+ 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.RETRY_LIMIT), is(Integer.toString(source.getRetryLimit())));
- refAttributes.remove(SVNRepositorySource.DEFAULT_CACHE_POLICY);
+ assertThat((String)refAttributes.remove(SVNRepositorySource.ALLOW_CREATING_WORKSPACES),
+ is(Boolean.toString(source.isCreatingWorkspacesAllowed())));
+ assertThat((String)refAttributes.remove(SVNRepositorySource.CACHE_TIME_TO_LIVE_IN_MILLISECONDS), is(Integer.toString(source.getCacheTimeToLiveInMilliseconds())));
+ 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 ...
@@ -223,31 +241,19 @@
assertThat(recoveredSource, is(notNullValue()));
assertThat(recoveredSource.getName(), is(source.getName()));
- assertThat(recoveredSource.getSVNURL(), is(source.getSVNURL()));
- assertThat(recoveredSource.getSVNUsername(), is(source.getSVNUsername()));
- assertThat(recoveredSource.getSVNPassword(), is(source.getSVNPassword()));
- assertThat(recoveredSource.getDefaultCachePolicy(), is(source.getDefaultCachePolicy()));
+ 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));
}
- // Only with local file protocol
@Test
- public void shouldCreateFSRepositoryIfProtocolIsOfTypeFile() throws Exception {
- this.source.setName(validName);
- this.source.setSVNURL(url);
- this.connection = source.getConnection();
- assertThat(this.connection, is(notNullValue()));
- }
-
- @Test
public void shouldAllowMultipleConnectionsToBeOpenAtTheSameTime() throws Exception {
List<RepositoryConnection> connections = new ArrayList<RepositoryConnection>();
try {
for (int i = 0; i != 10; ++i) {
- this.source.setName(validName);
- this.source.setSVNURL(url);
RepositoryConnection conn = source.getConnection();
assertThat(conn, is(notNullValue()));
connections.add(conn);
15 years, 1 month
DNA SVN: r930 - trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2009-05-22 09:32:05 -0400 (Fri, 22 May 2009)
New Revision: 930
Modified:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java
Log:
changes made to support workspace features and enhanced tests
Modified: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java 2009-05-22 13:23:32 UTC (rev 929)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java 2009-05-22 13:32:05 UTC (rev 930)
@@ -26,83 +26,50 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsSame.sameInstance;
-import static org.jboss.dna.graph.IsNodeWithChildren.hasChild;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
import java.util.concurrent.TimeUnit;
-import org.jboss.dna.common.text.UrlEncoder;
-import org.jboss.dna.graph.DnaLexicon;
-import org.jboss.dna.graph.ExecutionContext;
-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.cache.CachePolicy;
-import org.jboss.dna.graph.property.Binary;
-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.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.ReadAllChildrenRequest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations.Mock;
-import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.io.SVNRepository;
/**
* @author Serge Pagop
*/
-@SuppressWarnings( "unused" )
public class SVNRepositoryConnectionTest {
private SVNRepositoryConnection connection;
- private ExecutionContext context;
- private PathFactory pathFactory;
- private NameFactory nameFactory;
- private PropertyFactory propertyFactory;
- private SVNRepository repository;
- private String uuidPropertyName;
+ private SVNRepository selectedRepository;
private String sourceName;
- private Graph graph;
- private String svnUrl;
+ private String url;
+ String username;
+ String password;
+ private Set<String> availableWorkspaceNames;
@Mock
private CachePolicy policy;
- @Mock
- private ReadAllChildrenRequest request;
@Before
public void beforeEach() throws Exception {
MockitoAnnotations.initMocks(this);
- context = new ExecutionContext();
- context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
- context.getNamespaceRegistry().register(JcrLexicon.Namespace.PREFIX, JcrLexicon.Namespace.URI);
- context.getNamespaceRegistry().register(JcrNtLexicon.Namespace.PREFIX, JcrNtLexicon.Namespace.URI);
- pathFactory = context.getValueFactories().getPathFactory();
- propertyFactory = context.getPropertyFactory();
- nameFactory = context.getValueFactories().getNameFactory();
- svnUrl = SVNConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos", "target/copy_of dummy_svn_repos");
- String username = "sp";
- String password = "";
+ url = SVNConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos", "target/copy_of dummy_svn_repos");
+ username = "sp";
+ password = "";
// Set up the appropriate factory for a particular protocol
- repository = SVNConnectorTestUtil.createRepository(svnUrl, username, password);
+ selectedRepository = SVNConnectorTestUtil.createRepository(url, username, password);
sourceName = "the source name";
- connection = new SVNRepositoryConnection(sourceName, policy, Boolean.TRUE, repository);
- // And create the graph ...
- graph = Graph.create(connection, context);
+ availableWorkspaceNames = new HashSet<String>();
+ availableWorkspaceNames.add(url + "trunk");
+ availableWorkspaceNames.add(url + "tags");
+ connection = new SVNRepositoryConnection(sourceName, selectedRepository, availableWorkspaceNames,
+ Boolean.FALSE, policy, Boolean.TRUE, new RepositoryAccessData(url, username,password));
+
}
@After
@@ -117,13 +84,15 @@
@Test( expected = IllegalArgumentException.class )
public void shouldFailToInstantiateIfSourceNameIsNull() {
sourceName = null;
- connection = new SVNRepositoryConnection(sourceName, policy, Boolean.FALSE, repository);
+ connection = new SVNRepositoryConnection(sourceName, selectedRepository, availableWorkspaceNames,
+ Boolean.FALSE, policy, Boolean.FALSE, new RepositoryAccessData(url, username,password));
}
@Test( expected = IllegalArgumentException.class )
public void shouldFailToInstantiateIfRepositoryIsNull() {
- repository = null;
- connection = new SVNRepositoryConnection(sourceName, policy, Boolean.FALSE, repository);
+ selectedRepository = null;
+ connection = new SVNRepositoryConnection(sourceName, selectedRepository, availableWorkspaceNames,
+ Boolean.FALSE, policy, Boolean.FALSE, new RepositoryAccessData(url, username,password));
}
@Test
@@ -144,201 +113,9 @@
@Test
public void shouldGetTheSVNRepositoryRootFromTheSVNRepositoryWhenPinged() throws Exception {
CachePolicy policy = mock(CachePolicy.class);
- repository = SVNConnectorTestUtil.createRepository(svnUrl, "sp", "");
- connection = new SVNRepositoryConnection("the source name", policy, false, repository);
+ selectedRepository = SVNConnectorTestUtil.createRepository(url, "sp", "");
+ connection = new SVNRepositoryConnection("the source name", selectedRepository, availableWorkspaceNames,
+ Boolean.FALSE, policy, Boolean.FALSE, new RepositoryAccessData(url, username,password));
assertThat(connection.ping(1, TimeUnit.SECONDS), is(true));
}
-
- @Test( expected = PathNotFoundException.class )
- public void shouldFailToGetChildrenFromAWrongRequestedPath() {
- List<Location> l = graph.getChildren().of(pathFactory.create("wrongRequestedPath"));
- }
-
- @Test
- public void shouldReturnTheContentNodePathOfTheFile() {
- List<Location> locations00 = graph.getChildren().of(pathFactory.create("/nodeA/itemA1.txt"));
- assertThat(locations00.isEmpty(), is(false));
- assertThat(containsPaths(locations00).contains("/nodeA/itemA1.txt/jcr:content"), is(true));
-
- }
-
- @Test
- public void shouldListChildrenLocationPathsOfASpecificPath() {
-
- // read children from the root node.
- List<Location> l = graph.getChildren().of(pathFactory.create("/"));
- assertThat(containsPaths(l).contains("/nodeA"), is(true));
- assertThat(containsPaths(l).contains("/nodeB"), is(true));
-
- List<Location> locations02 = graph.getChildren().of(pathFactory.create("/nodeA"));
- assertThat(locations02.size() > 0, is(true));
- assertThat(containsPaths(locations02).contains("/nodeA/itemA1.txt/jcr:content"), is(true));
- assertThat(containsPaths(locations02).contains("/nodeA/itemA2.txt/jcr:content"), is(true));
-
- List<Location> locations03 = graph.getChildren().of(pathFactory.create("/nodeB"));
- assertThat(locations03.size() > 0, is(true));
- assertThat(containsPaths(locations03).contains("/nodeB/JBossORG-EULA.txt/jcr:content"), is(true));
- assertThat(containsPaths(locations03).contains("/nodeB/nodeB1"), is(true));
- }
-
- @Test
- public void shouldNotHaveProperties() {
- // Root location does not need properties.
- Location root = Location.create(pathFactory.create("/"));
- Collection<Property> nilProperties = graph.getProperties().on(root);
- assertThat(nilProperties, is(notNullValue()));
- assertThat(nilProperties.isEmpty(), is(true));
- }
-
- @Test
- public void shouldJustCatchThePropertiesOnLocation() {
- // directory nodeA has "jcr:primaryType" with value "nt:folder" and also "jcr:created" with value folder created date
- Location nodeA = Location.create(pathFactory.create("/nodeA"));
- Collection<Property> nodeAProperties = graph.getProperties().on(nodeA);
- assertThat(nodeAProperties, is(notNullValue()));
- assertThat(nodeAProperties.isEmpty(), is(false));
- assertThat(nodeAProperties.size(), is(2));
-
- // file itemA.txt has "jcr:primaryType" property whose value is "nt:file" and also "jcr:created" with value folder created
- // date
- Location itemA1 = Location.create(pathFactory.create("/nodeA/itemA1.txt"));
- Collection<Property> itemA1Properties = graph.getProperties().on(itemA1);
- assertThat(itemA1Properties, is(notNullValue()));
- assertThat(itemA1Properties.isEmpty(), is(false));
- assertThat(itemA1Properties.size(), is(2));
-
- // content itemA1.txt/jcr:content
- // //"jcr:primaryType" property value of "nt:resource",
- // "jcr:data" property whose value are the contents of the file
- // and a few other properties, like "jcr:encoding", "jcr:mimeType" and "jcr:lastModified" and
- // also "jcr:created" property
- Location content = Location.create(pathFactory.create("/nodeA/itemA2.txt/jcr:content"));
- Collection<Property> itemA2ContentProperties = graph.getProperties().on(content);
- assertThat(itemA2ContentProperties, is(notNullValue()));
- assertThat(itemA2ContentProperties.isEmpty(), is(false));
- // then for any causes that I do not know now mimeType of this content is null.
- assertThat(itemA2ContentProperties.size(), is(3));
- }
-
- @Test
- public void shouldAlwaysReadRootNodeByPath() {
- Node root = graph.getNodeAt("/");
- assertThat(root, is(notNullValue()));
- assertThat(root.getLocation().getPath(), is(path("/")));
- }
-
- @Test
- public void shouldAddAndDeleteChildUnderRootNode() throws Exception {
- graph.batch()
- .create("/nodeC")
- .with(propertyFactory().create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FOLDER))
- .and(propertyFactory().create(JcrLexicon.CREATED, dateFactory().create(new Date())))
- .execute();
- // Now look up the root node ...
- Node root = graph.getNodeAt("/");
- assertThat(root, is(notNullValue()));
- assertThat(root.getChildren(), hasChild(child("nodeC")));
- SVNNodeKind nodeCKind = repository.checkPath("nodeC", -1);
- assertThat(nodeCKind, is(SVNNodeKind.DIR));
- graph.batch()
- .create("/nodeC/nodeC_1")
- .with(propertyFactory().create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FOLDER))
- .and(propertyFactory().create(JcrLexicon.CREATED, dateFactory().create(new Date())))
- .execute();
- // Now look up the root node ...
- Node nodeC = graph.getNodeAt("/nodeC");
- assertThat(nodeC, is(notNullValue()));
- assertThat(nodeC.getChildren(), hasChild(child("nodeC_1")));
- SVNNodeKind nodeC1Kind = repository.checkPath("nodeC/nodeC_1", -1);
- assertThat(nodeC1Kind, is(SVNNodeKind.DIR));
-
- byte[] content1 = "My content".getBytes();
- Property jcrDataProperty = propertyFactory().create(JcrLexicon.DATA, binaryFactory().create(content1));
- graph.batch()
- .create("/nodeC/nodeC_1/file1.txt")
- .with(propertyFactory().create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FILE))
- .and(propertyFactory().create(JcrLexicon.CREATED, new Date()))
- .and(jcrDataProperty)
- .execute();
-
- // Look up the file
- Node nodeC1 = graph.getNodeAt("/nodeC/nodeC_1");
- assertThat(nodeC1, is(notNullValue()));
- assertThat(nodeC1.getChildren().size(), is(1));
- SVNNodeKind fileKind = repository.checkPath("/nodeC/nodeC_1/file1.txt", -1);
- assertThat(fileKind, is(SVNNodeKind.FILE));
-
- }
-
- protected Collection<String> containsPaths( Collection<Location> locations ) {
- List<String> paths = new ArrayList<String>();
- for (Location location : locations) {
- paths.add(location.getPath().getString(context.getNamespaceRegistry(), new UrlEncoder()));
- }
- return paths;
- }
-
- protected Path path( String path ) {
- return context.getValueFactories().getPathFactory().create(path);
- }
-
- /**
- * Factory for sample name.
- *
- * @return the name factory
- */
- protected NameFactory nameFactory() {
- return context.getValueFactories().getNameFactory();
- }
-
- /**
- * Factory for path creation.
- *
- * @return a path factory.
- */
- protected PathFactory pathFactory() {
- return context.getValueFactories().getPathFactory();
- }
-
- /**
- * Factory for property creation.
- *
- * @return the property factory.
- */
- protected PropertyFactory propertyFactory() {
- return context.getPropertyFactory();
- }
-
- /**
- * Factory for date creation.
- *
- * @return the date factory.
- */
- protected DateTimeFactory dateFactory() {
- return context.getValueFactories().getDateFactory();
- }
-
- /**
- * Factory for binary creation.
- *
- * @return the binary factory..
- */
- protected ValueFactory<Binary> binaryFactory() {
- return context.getValueFactories().getBinaryFactory();
- }
-
- protected Name name( String name ) {
- return context.getValueFactories().getNameFactory().create(name);
- }
-
- protected Property property( String name,
- Object... values ) {
- Name propName = name(name);
- return context.getPropertyFactory().create(propName, values);
- }
-
- protected Path.Segment child( String name ) {
- return context.getValueFactories().getPathFactory().createSegment(name);
- }
-
-}
+}
\ No newline at end of file
15 years, 1 month
DNA SVN: r929 - trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2009-05-22 09:23:32 -0400 (Fri, 22 May 2009)
New Revision: 929
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java
Log:
changes made to support workspace features
Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java 2009-05-22 13:22:45 UTC (rev 928)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java 2009-05-22 13:23:32 UTC (rev 929)
@@ -23,59 +23,58 @@
*/
package org.jboss.dna.connector.svn;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
+import java.util.List;
import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-import javax.naming.BinaryRefAddr;
+import java.util.concurrent.CopyOnWriteArraySet;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.RefAddr;
import javax.naming.Reference;
-import javax.naming.Referenceable;
import javax.naming.StringRefAddr;
import javax.naming.spi.ObjectFactory;
+import net.jcip.annotations.Immutable;
+import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.common.util.Logger;
+import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.graph.cache.CachePolicy;
import org.jboss.dna.graph.connector.RepositoryConnection;
import org.jboss.dna.graph.connector.RepositoryContext;
import org.jboss.dna.graph.connector.RepositorySource;
import org.jboss.dna.graph.connector.RepositorySourceCapabilities;
import org.jboss.dna.graph.connector.RepositorySourceException;
-import org.tmatesoft.svn.core.SVNException;
-import org.tmatesoft.svn.core.SVNURL;
-import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
-import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
-import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
-import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.io.SVNRepository;
-import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
-import org.tmatesoft.svn.core.wc.SVNWCUtil;
/**
- * A repository source that uses a SVN repository instance to manage the content. This source is capable of using an existing
- * {@link SVNRepository} instance or creating a new instance. This process is controlled entirely by the JavaBean properties of
- * the SVNRepositorySource instance. Like other {@link RepositorySource} classes, instances of SVNRepositorySource can be placed
- * into JNDI and do support the creation of {@link Referenceable JNDI referenceable} objects and resolution of references into
- * SVNRepositorySource. </p>
+ * The {@link RepositorySource} for the connector that exposes an area of the local/remote svn repository as content in a
+ * repository. This source considers a workspace name to be the path to the directory on the repository's root directory location
+ * that represents the root of that workspace. New workspaces can be created, as long as the names represent valid paths to
+ * existing directories.
*
* @author Serge Pagop
*/
+@ThreadSafe
public class SVNRepositorySource implements RepositorySource, ObjectFactory {
- private static final long serialVersionUID = 1L;
/**
- * The default limit is {@value} for retrying {@link RepositoryConnection connection} calls to the underlying source.
+ * The first serialized version of this source. Version {@value} .
*/
- public static final int DEFAULT_RETRY_LIMIT = 0;
+ private static final long serialVersionUID = 1L;
+ protected static final String SOURCE_NAME = "sourceName";
+ protected static final String SVN_REPOSITORY_ROOT_URL = "repositoryRootURL";
+ protected static final String SVN_USERNAME = "username";
+ protected static final String SVN_PASSWORD = "password";
+ protected static final String CACHE_TIME_TO_LIVE_IN_MILLISECONDS = "cacheTimeToLiveInMilliseconds";
+ protected static final String RETRY_LIMIT = "retryLimit";
+ protected static final String DEFAULT_WORKSPACE = "defaultWorkspace";
+ protected static final String PREDEFINED_WORKSPACE_NAMES = "predefinedWorkspaceNames";
+ protected static final String ALLOW_CREATING_WORKSPACES = "allowCreatingWorkspaces";
+
/**
* This source supports events.
*/
@@ -85,47 +84,41 @@
*/
protected static final boolean SUPPORTS_SAME_NAME_SIBLINGS = false;
/**
- * This source supports creating workspaces.
+ * This source does support creating workspaces.
*/
- protected static final boolean SUPPORTS_CREATING_WORKSPACES = false;
+ protected static final boolean DEFAULT_SUPPORTS_CREATING_WORKSPACES = true;
/**
+ * This source supports udpates by default, but each instance may be configured to be read-only or updateable}.
+ */
+ public static final boolean DEFAULT_SUPPORTS_UPDATES = false;
+
+ /**
* This source supports creating references.
*/
protected static final boolean SUPPORTS_REFERENCES = false;
- /**
- * This source supports udpates by default, but each instance may be configured to {@link #setSupportsUpdates(boolean) be
- * read-only or updateable}.
- */
- public static final boolean DEFAULT_SUPPORTS_UPDATES = true;
- public static final int DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS = 60 * 5; // 5 minutes
+ public static final int DEFAULT_RETRY_LIMIT = 0;
+ public static final int DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS = 60 * 5; // 5
+ // minutes
- protected static final String SOURCE_NAME = "sourceName";
- protected static final String DEFAULT_CACHE_POLICY = "defaultCachePolicy";
- protected static final String SVN_REPOS_JNDI_NAME = "svnReposJndiName";
- protected static final String SVN_REPOS_FACTORY_JNDI_NAME = "svnReposFactoryJndiName";
- protected static final String SVN_URL = "svnURL";
- protected static final String SVN_USERNAME = "svnUsername";
- protected static final String SVN_PASSWORD = "svnPassword";
- protected static final String RETRY_LIMIT = "retryLimit";
+ private volatile String name;
+ private volatile String repositoryRootURL;
+ private volatile String username;
+ private volatile String password;
+ private volatile int retryLimit = DEFAULT_RETRY_LIMIT;
+ private volatile int cacheTimeToLiveInMilliseconds = DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS * 1000;
+ private volatile String defaultWorkspace;
+ private volatile String[] predefinedWorkspaces = new String[] {};
+ private volatile RepositorySourceCapabilities capabilities = new RepositorySourceCapabilities(
+ SUPPORTS_SAME_NAME_SIBLINGS,
+ DEFAULT_SUPPORTS_UPDATES,
+ SUPPORTS_EVENTS,
+ DEFAULT_SUPPORTS_CREATING_WORKSPACES,
+ SUPPORTS_REFERENCES);
- private final AtomicInteger retryLimit = new AtomicInteger(DEFAULT_RETRY_LIMIT);
- private String name;
- private String svnURL;
- private String svnUsername;
- private String svnPassword;
- private CachePolicy defaultCachePolicy;
+ private transient CachePolicy cachePolicy;
+ private transient CopyOnWriteArraySet<String> availableWorspaceNames;
- private RepositorySourceCapabilities capabilities = new RepositorySourceCapabilities(SUPPORTS_SAME_NAME_SIBLINGS,
- DEFAULT_SUPPORTS_UPDATES,
- SUPPORTS_EVENTS,
- SUPPORTS_CREATING_WORKSPACES,
- SUPPORTS_REFERENCES);
-
- private transient Context jndiContext;
- private transient RepositoryContext repositoryContext;
- private transient SVNRepository svnRepository;
-
/**
* Create a repository source instance.
*/
@@ -143,187 +136,200 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.graph.connector.RepositorySource#initialize(org.jboss.dna.graph.connector.RepositoryContext)
*/
- public void initialize( RepositoryContext context ) throws RepositorySourceException {
- this.repositoryContext = context;
+ public String getName() {
+ return this.name;
}
/**
- * @return repositoryContext
+ * Set the name for the source
+ *
+ * @param name the new name for the source
*/
- public RepositoryContext getRepositoryContext() {
- return repositoryContext;
+ public synchronized void setName( String name ) {
+ if (name != null) {
+ name = name.trim();
+ if (name.length() == 0) name = null;
+ }
+ this.name = name;
}
/**
- * {@inheritDoc}
+ * @return the url
*/
- public String getName() {
- return this.name;
+ public String getRepositoryRootURL() {
+ return this.repositoryRootURL;
}
/**
- * {@inheritDoc}
+ * Set the url for the subversion repository.
*
- * @see org.jboss.dna.graph.connector.RepositorySource#getRetryLimit()
+ * @param url - the url location.
+ * @throws IllegalArgumentException If svn url is null or empty
*/
- public int getRetryLimit() {
- return retryLimit.get();
+ public void setRepositoryRootURL( String url ) {
+ CheckArg.isNotEmpty(url, "RepositoryRootURL");
+ this.repositoryRootURL = url;
}
+ public String getUsername() {
+ return this.username;
+ }
+
/**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.connector.RepositorySource#setRetryLimit(int)
+ * @param username
*/
- public void setRetryLimit( int limit ) {
- retryLimit.set(limit < 0 ? 0 : limit);
+ public void setUsername( String username ) {
+ this.username = username;
}
+ public String getPassword() {
+ return this.password;
+ }
+
/**
- * Set the name of this source
- *
- * @param name the name for this source
+ * @param password
*/
- public synchronized void setName( String name ) {
- if (this.name == name || this.name != null && this.name.equals(name)) return; // unchanged
- this.name = name;
+ public void setPassword( String password ) {
+ this.password = password;
}
/**
- * Get the default cache policy for this source, or null if the global default cache policy should be used
+ * Get whether this source supports updates.
*
- * @return the default cache policy, or null if this source has no explicit default cache policy
+ * @return true if this source supports updates, or false if this source only supports reading content.
*/
- public CachePolicy getDefaultCachePolicy() {
- return defaultCachePolicy;
+ public boolean getSupportsUpdates() {
+ return capabilities.supportsUpdates();
}
/**
- * @param defaultCachePolicy Sets defaultCachePolicy to the specified value.
+ * Get the file system path to the existing directory that should be used for the default workspace. If the default is
+ * specified as a null String or is not a valid and resolvable path, this source will consider the default to be the current
+ * working directory of this virtual machine, as defined by the <code>new File(".")</code>.
+ *
+ * @return the file system path to the directory representing the default workspace, or null if the default should be the
+ * current working directory
*/
- public synchronized void setDefaultCachePolicy( CachePolicy defaultCachePolicy ) {
- if (this.defaultCachePolicy == defaultCachePolicy || this.defaultCachePolicy != null
- && this.defaultCachePolicy.equals(defaultCachePolicy)) return; // unchanged
- this.defaultCachePolicy = defaultCachePolicy;
+ public String getDirectoryForDefaultWorkspace() {
+ return defaultWorkspace;
}
- public String getSVNURL() {
- return this.svnURL;
+ /**
+ * Set the file system path to the existing directory that should be used for the default workspace. If the default is
+ * specified as a null String or is not a valid and resolvable path, this source will consider the default to be the current
+ * working directory of this virtual machine, as defined by the <code>new File(".")</code>.
+ *
+ * @param pathToDirectoryForDefaultWorkspace the valid and resolvable file system path to the directory representing the
+ * default workspace, or null if the current working directory should be used as the default workspace
+ */
+ public synchronized void setDirectoryForDefaultWorkspace( String pathToDirectoryForDefaultWorkspace ) {
+ this.defaultWorkspace = pathToDirectoryForDefaultWorkspace;
}
/**
- * Set the url for the subversion repository.
+ * Gets the names of the workspaces that are available when this source is created. Each workspace name corresponds to a path
+ * to a directory on the file system.
*
- * @param url - the url location.
- * @throws IllegalArgumentException If svn url is null or empty
+ * @return the names of the workspaces that this source starts with, or null if there are no such workspaces
+ * @see #setPredefinedWorkspaceNames(String[])
+ * @see #setCreatingWorkspacesAllowed(boolean)
*/
- public void setSVNURL( String url ) {
- CheckArg.isNotEmpty(url, "SVNURL");
- this.svnURL = url;
+ public synchronized String[] getPredefinedWorkspaceNames() {
+ String[] copy = new String[predefinedWorkspaces.length];
+ System.arraycopy(predefinedWorkspaces, 0, copy, 0, predefinedWorkspaces.length);
+ return copy;
}
- public String getSVNUsername() {
- return this.svnUsername;
+ /**
+ * Sets the names of the workspaces that are available when this source is created. Each workspace name corresponds to a path
+ * to a directory on the file system.
+ *
+ * @param predefinedWorkspaceNames the names of the workspaces that this source should start with, or null if there are no
+ * such workspaces
+ * @see #setCreatingWorkspacesAllowed(boolean)
+ * @see #getPredefinedWorkspaceNames()
+ */
+ public synchronized void setPredefinedWorkspaceNames( String[] predefinedWorkspaceNames ) {
+ this.predefinedWorkspaces = predefinedWorkspaceNames;
}
/**
- * @param username
+ * Get whether this source allows workspaces to be created dynamically.
+ *
+ * @return true if this source allows workspaces to be created by clients, or false if the set of workspaces is fixed
+ * @see #setPredefinedWorkspaceNames(String[])
+ * @see #getPredefinedWorkspaceNames()
+ * @see #setCreatingWorkspacesAllowed(boolean)
*/
- public void setSVNUsername( String username ) {
- this.svnUsername = username;
+ public boolean isCreatingWorkspacesAllowed() {
+ return capabilities.supportsCreatingWorkspaces();
}
- public String getSVNPassword() {
- return this.svnPassword;
+ /**
+ * Set whether this source allows workspaces to be created dynamically.
+ *
+ * @param allowWorkspaceCreation true if this source allows workspaces to be created by clients, or false if the set of
+ * workspaces is fixed
+ * @see #setPredefinedWorkspaceNames(String[])
+ * @see #getPredefinedWorkspaceNames()
+ * @see #isCreatingWorkspacesAllowed()
+ */
+ public synchronized void setCreatingWorkspacesAllowed( boolean allowWorkspaceCreation ) {
+ capabilities = new RepositorySourceCapabilities(capabilities.supportsSameNameSiblings(), capabilities.supportsUpdates(),
+ capabilities.supportsEvents(), allowWorkspaceCreation,
+ capabilities.supportsReferences());
}
/**
- * @param password
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#getRetryLimit()
*/
- public void setSVNPassword( String password ) {
- this.svnPassword = password;
+ public int getRetryLimit() {
+ return retryLimit;
}
/**
- * Get whether this source supports updates.
+ * {@inheritDoc}
*
- * @return true if this source supports updates, or false if this source only supports reading content.
+ * @see org.jboss.dna.graph.connector.RepositorySource#setRetryLimit(int)
*/
- public boolean getSupportsUpdates() {
- return capabilities.supportsUpdates();
+ public void setRetryLimit( int limit ) {
+ retryLimit = limit < 0 ? 0 : limit;
}
/**
- * Set whether this source supports updates.
+ * Get the time in milliseconds that content returned from this source may used while in the cache.
*
- * @param supportsUpdates true if this source supports updating content, or false if this source only supports reading
- * content.
+ * @return the time to live, in milliseconds, or 0 if the time to live is not specified by this source
*/
- public synchronized void setSupportsUpdates( boolean supportsUpdates ) {
- capabilities = new RepositorySourceCapabilities(capabilities.supportsSameNameSiblings(), supportsUpdates,
- capabilities.supportsEvents(), capabilities.supportsCreatingWorkspaces(),
- capabilities.supportsReferences());
+ public int getCacheTimeToLiveInMilliseconds() {
+ return cacheTimeToLiveInMilliseconds;
}
/**
- * {@inheritDoc}
+ * Set the time in milliseconds that content returned from this source may used while in the cache.
*
- * @see org.jboss.dna.graph.connector.RepositorySource#getConnection()
+ * @param cacheTimeToLive the time to live, in milliseconds; 0 if the time to live is not specified by this source; or a
+ * negative number for the default value
*/
- public RepositoryConnection getConnection() throws RepositorySourceException {
- if (getName() == null) {
- I18n msg = SVNRepositoryConnectorI18n.propertyIsRequired;
- throw new RepositorySourceException(getName(), msg.text("name"));
- }
- SVNURL svnURL = null;
- if (this.svnRepository == null) {
- try {
- svnURL = SVNURL.parseURIDecoded(getSVNURL());
- String usedProtocol = this.getSVNURL().substring(0, this.getSVNURL().indexOf(":"));
- if (usedProtocol.equals(SVNProtocol.SVN.value()) || usedProtocol.equals(SVNProtocol.SVN_SSH.value())) {
- SVNRepositoryFactoryImpl.setup();
- this.svnRepository = SVNRepositoryFactory.create(svnURL);
- ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(this.getSVNUsername(),
- this.getSVNPassword());
- this.svnRepository.setAuthenticationManager(authManager);
- } else if (usedProtocol.equals(SVNProtocol.HTTP.value()) || usedProtocol.equals(SVNProtocol.HTTPS.value())) {
- DAVRepositoryFactory.setup();
- this.svnRepository = DAVRepositoryFactory.create(svnURL);
- ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(this.getSVNUsername(),
- this.getSVNPassword());
- this.svnRepository.setAuthenticationManager(authManager);
- } else if (usedProtocol.equals(SVNProtocol.FILE.value())) {
- FSRepositoryFactory.setup();
- this.svnRepository = FSRepositoryFactory.create(svnURL);
- ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(this.getSVNUsername(),
- this.getSVNPassword());
- this.svnRepository.setAuthenticationManager(authManager);
- } else {
- // protocol not supported by this connector
- throw new RepositorySourceException(getSVNURL(),
- "Protocol is not supported by this connector or there is problem in the svn url");
- }
+ public synchronized void setCacheTimeToLiveInMilliseconds( int cacheTimeToLive ) {
+ if (cacheTimeToLive < 0) cacheTimeToLive = DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS;
+ this.cacheTimeToLiveInMilliseconds = cacheTimeToLive;
+ this.cachePolicy = cacheTimeToLiveInMilliseconds > 0 ? new SVNRepositoryCachePolicy(cacheTimeToLiveInMilliseconds) : null;
- } catch (SVNException ex) {
- I18n msg = SVNRepositoryConnectorI18n.propertyIsRequired;
- throw new RepositorySourceException(getSVNURL(), msg.text(this.getSVNURL()), ex);
- }
- }
- boolean supportsUpdates = getSupportsUpdates();
- return new SVNRepositoryConnection(this.getName(), this.getDefaultCachePolicy(), supportsUpdates, this.svnRepository);
}
- protected Context getContext() {
- return this.jndiContext;
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#initialize(org.jboss.dna.graph.connector.RepositoryContext)
+ */
+ public synchronized void initialize( RepositoryContext context ) throws RepositorySourceException {
+ // No need to do anything
}
- protected synchronized void setContext( Context context ) {
- this.jndiContext = context;
- }
-
/**
* {@inheritDoc}
*/
@@ -355,29 +361,25 @@
if (getName() != null) {
ref.add(new StringRefAddr(SOURCE_NAME, getName()));
}
- if (getSVNURL() != null) {
- ref.add(new StringRefAddr(SVN_URL, getSVNURL()));
+ if (getRepositoryRootURL() != null) {
+ ref.add(new StringRefAddr(SVN_REPOSITORY_ROOT_URL, getRepositoryRootURL()));
}
- if (getSVNUsername() != null) {
- ref.add(new StringRefAddr(SVN_USERNAME, getSVNUsername()));
+ if (getUsername() != null) {
+ ref.add(new StringRefAddr(SVN_USERNAME, getUsername()));
}
- if (getSVNPassword() != null) {
- ref.add(new StringRefAddr(SVN_PASSWORD, getSVNPassword()));
+ if (getPassword() != null) {
+ ref.add(new StringRefAddr(SVN_PASSWORD, getPassword()));
}
- if (getDefaultCachePolicy() != null) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- CachePolicy policy = getDefaultCachePolicy();
- try {
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(policy);
- ref.add(new BinaryRefAddr(DEFAULT_CACHE_POLICY, baos.toByteArray()));
- } catch (IOException e) {
- I18n msg = SVNRepositoryConnectorI18n.errorSerializingCachePolicyInSource;
- throw new RepositorySourceException(getName(), msg.text(policy.getClass().getName(), getName()), e);
- }
+ ref.add(new StringRefAddr(CACHE_TIME_TO_LIVE_IN_MILLISECONDS, Integer.toString(getCacheTimeToLiveInMilliseconds())));
+ ref.add(new StringRefAddr(RETRY_LIMIT, Integer.toString(getRetryLimit())));
+ ref.add(new StringRefAddr(DEFAULT_WORKSPACE, getDirectoryForDefaultWorkspace()));
+ ref.add(new StringRefAddr(ALLOW_CREATING_WORKSPACES, Boolean.toString(isCreatingWorkspacesAllowed())));
+ String[] workspaceNames = getPredefinedWorkspaceNames();
+ if (workspaceNames != null && workspaceNames.length != 0) {
+ ref.add(new StringRefAddr(PREDEFINED_WORKSPACE_NAMES, StringUtil.combineLines(workspaceNames)));
}
- ref.add(new StringRefAddr(RETRY_LIMIT, Integer.toString(getRetryLimit())));
return ref;
+
}
/**
@@ -391,7 +393,7 @@
Context nameCtx,
Hashtable<?, ?> environment ) throws Exception {
if (obj instanceof Reference) {
- Map<String, Object> values = new HashMap<String, Object>();
+ Map<String, String> values = new HashMap<String, String>();
Reference ref = (Reference)obj;
Enumeration<?> en = ref.getAll();
while (en.hasMoreElements()) {
@@ -400,38 +402,153 @@
String key = subref.getType();
Object value = subref.getContent();
if (value != null) values.put(key, value.toString());
- } else if (subref instanceof BinaryRefAddr) {
- String key = subref.getType();
- Object value = subref.getContent();
- if (value instanceof byte[]) {
- // Deserialize ...
- ByteArrayInputStream bais = new ByteArrayInputStream((byte[])value);
- ObjectInputStream ois = new ObjectInputStream(bais);
- value = ois.readObject();
- values.put(key, value);
- }
}
}
- String sourceName = (String)values.get(SOURCE_NAME);
- String svnURL = (String)values.get(SVN_URL);
- String svnUsername = (String)values.get(SVN_USERNAME);
- String svnPassword = (String)values.get(SVN_PASSWORD);
- Object defaultCachePolicy = values.get(DEFAULT_CACHE_POLICY);
- String retryLimit = (String)values.get(RETRY_LIMIT);
+ String sourceName = values.get(SOURCE_NAME);
+ String repositoryRootURL = values.get(SVN_REPOSITORY_ROOT_URL);
+ String username = values.get(SVN_USERNAME);
+ String password = values.get(SVN_PASSWORD);
+ String cacheTtlInMillis = values.get(CACHE_TIME_TO_LIVE_IN_MILLISECONDS);
+ String retryLimit = values.get(RETRY_LIMIT);
+ String defaultWorkspace = values.get(DEFAULT_WORKSPACE);
+ String createWorkspaces = values.get(ALLOW_CREATING_WORKSPACES);
+ String combinedWorkspaceNames = values.get(PREDEFINED_WORKSPACE_NAMES);
+ String[] workspaceNames = null;
+ if (combinedWorkspaceNames != null) {
+ List<String> paths = StringUtil.splitLines(combinedWorkspaceNames);
+ workspaceNames = paths.toArray(new String[paths.size()]);
+ }
// Create the source instance ...
SVNRepositorySource source = new SVNRepositorySource();
if (sourceName != null) source.setName(sourceName);
- if (svnURL != null) source.setSVNURL(svnURL);
- if (svnUsername != null) source.setSVNUsername(svnUsername);
- if (svnPassword != null) source.setSVNPassword(svnPassword);
- if (defaultCachePolicy instanceof CachePolicy) {
- source.setDefaultCachePolicy((CachePolicy)defaultCachePolicy);
- }
+ if (cacheTtlInMillis != null) source.setCacheTimeToLiveInMilliseconds(Integer.parseInt(cacheTtlInMillis));
+ if (repositoryRootURL != null) source.setRepositoryRootURL(repositoryRootURL);
+ if (username != null) source.setUsername(username);
+ if (password != null) source.setPassword(password);
if (retryLimit != null) source.setRetryLimit(Integer.parseInt(retryLimit));
+ if (defaultWorkspace != null) source.setDirectoryForDefaultWorkspace(defaultWorkspace);
+ if (createWorkspaces != null) source.setCreatingWorkspacesAllowed(Boolean.parseBoolean(createWorkspaces));
+ if (workspaceNames != null && workspaceNames.length != 0) source.setPredefinedWorkspaceNames(workspaceNames);
return source;
}
return null;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#getConnection()
+ */
+ public RepositoryConnection getConnection() throws RepositorySourceException {
+
+ String sourceName = getName();
+ if (sourceName == null || sourceName.trim().length() == 0) {
+ I18n msg = SVNRepositoryConnectorI18n.propertyIsRequired;
+ throw new RepositorySourceException(getName(), msg.text("name"));
+ }
+
+ String sourceUsername = getUsername();
+ if (sourceUsername == null || sourceUsername.trim().length() == 0) {
+ I18n msg = SVNRepositoryConnectorI18n.propertyIsRequired;
+ throw new RepositorySourceException(getUsername(), msg.text("username"));
+ }
+
+ String sourcePassword = getPassword();
+ if (sourcePassword == null) {
+ I18n msg = SVNRepositoryConnectorI18n.propertyIsRequired;
+ throw new RepositorySourceException(getPassword(), msg.text("password"));
+ }
+
+ String repositoryRootURL = getRepositoryRootURL();
+ if (repositoryRootURL == null || repositoryRootURL.trim().length() == 0) {
+ I18n msg = SVNRepositoryConnectorI18n.propertyIsRequired;
+ throw new RepositorySourceException(getRepositoryRootURL(), msg.text("repositoryRootURL"));
+ }
+
+
+ SVNRepository repos = null;
+ // Report the warnings for non-existant predefined workspaces
+ boolean reportWarnings = false;
+ if (this.availableWorspaceNames == null) {
+ // Set up the predefined workspace names ...
+ this.availableWorspaceNames = new CopyOnWriteArraySet<String>();
+ for (String predefined : this.predefinedWorkspaces) {
+ // if exist e.i trunk/ /branches /tags
+ this.availableWorspaceNames.add(predefined);
+ }
+ // Report the warnings for non-existant predefined workspaces and we
+ // take it that if no predefined workspace exist
+ // we will take the repository root url as a pseudo workspace
+ reportWarnings = true;
+ for (String url : this.availableWorspaceNames) {
+ // check if the predefined workspaces exist.
+ if (repos != null) {
+ SVNRepositoryUtil.setNewSVNRepositoryLocation(repos, url, true, sourceName);
+ } else {
+ repos = SVNRepositoryUtil.createRepository(url, sourceUsername, sourcePassword);
+ }
+ if (!SVNRepositoryUtil.exist(repos)) {
+
+ Logger.getLogger(getClass()).warn(SVNRepositoryConnectorI18n.pathForPredefinedWorkspaceDoesNotExist,
+ url,
+ name);
+ }
+ if (!SVNRepositoryUtil.isDirectory(repos,"")) {
+ Logger.getLogger(getClass()).warn(SVNRepositoryConnectorI18n.pathForPredefinedWorkspaceIsNotDirectory,
+ url,
+ name);
+ }
+ }
+ }
+
+ boolean supportsUpdates = getSupportsUpdates();
+
+ SVNRepository defaultWorkspace = null;
+ if (repos != null) {
+ SVNRepositoryUtil.setNewSVNRepositoryLocation(repos, getRepositoryRootURL(), true, sourceName);
+ defaultWorkspace = repos;
+ } else {
+ defaultWorkspace = SVNRepositoryUtil.createRepository(getRepositoryRootURL(), sourceUsername, sourcePassword);
+ }
+
+ String defaultURL = getDirectoryForDefaultWorkspace();
+ if (defaultURL != null) {
+ // Look for the entry at this path .....
+ SVNRepository repository = SVNRepositoryUtil.createRepository(defaultURL,
+ sourceUsername,
+ sourcePassword);
+ I18n warning = null;
+ if (!SVNRepositoryUtil.exist(repository)) {
+ warning = SVNRepositoryConnectorI18n.pathForPredefinedWorkspaceDoesNotExist;
+ } else if (!SVNRepositoryUtil.isDirectory(repository,"")) {
+ warning = SVNRepositoryConnectorI18n.pathForPredefinedWorkspaceIsNotDirectory;
+ } else {
+ // is a directory and is good to use!
+ defaultWorkspace = repository;
+ }
+ if (reportWarnings && warning != null) {
+ Logger.getLogger(getClass()).warn(warning, defaultURL, name);
+ }
+ }
+ this.availableWorspaceNames.add(defaultWorkspace.getLocation().toDecodedString());
+ return new SVNRepositoryConnection(name, defaultWorkspace, availableWorspaceNames, isCreatingWorkspacesAllowed(),
+ cachePolicy, supportsUpdates, new RepositoryAccessData(getRepositoryRootURL(),
+ sourceUsername, sourcePassword));
+ }
+
+ @Immutable
+ /* package */class SVNRepositoryCachePolicy implements CachePolicy {
+ private static final long serialVersionUID = 1L;
+ private final int ttl;
+
+ /* package */SVNRepositoryCachePolicy( int ttl ) {
+ this.ttl = ttl;
+ }
+
+ public long getTimeToLive() {
+ return ttl;
+ }
+
+ }
}
15 years, 1 month
DNA SVN: r928 - trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2009-05-22 09:22:45 -0400 (Fri, 22 May 2009)
New Revision: 928
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
Log:
changes made to support workspace features
Modified: 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 2009-05-22 13:19:37 UTC (rev 927)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2009-05-22 13:22:45 UTC (rev 928)
@@ -28,7 +28,6 @@
import java.io.OutputStream;
import java.util.Collection;
import java.util.Collections;
-import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import org.jboss.dna.common.i18n.I18n;
@@ -41,6 +40,7 @@
import org.jboss.dna.graph.Location;
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;
@@ -58,6 +58,7 @@
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;
@@ -81,107 +82,230 @@
* 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.
*
- * @author Serge Emmanuel Pagop
+ * @author Serge Pagop
*/
public class SVNRepositoryRequestProcessor extends RequestProcessor implements ScmActionFactory {
protected static final String BACK_SLASH = "/";
+ private static final String DEFAULT_MIME_TYPE = "application/octet-stream";
+
private final String defaultNamespaceUri;
private final boolean updatesAllowed;
- private SVNRepository repository;
+ 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 repository
+ * @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,
- SVNRepository repository,
- boolean updatesAllowed ) {
- super(sourceName, context, null);
+ boolean updatesAllowed,
+ RepositoryAccessData accessData ) {
+ super(sourceName, context);
+ assert defaultWorkspace != null;
+ assert availableWorkspaceNames != null;
this.defaultNamespaceUri = getExecutionContext().getNamespaceRegistry().getDefaultNamespaceUri();
this.updatesAllowed = updatesAllowed;
- this.repository = repository;
+ this.defaultWorkspace = defaultWorkspace;
this.logger = getExecutionContext().getLogger(getClass());
+ this.availableWorkspaceNames = availableWorkspaceNames;
+ this.creatingWorkspacesAllowed = creatingWorkspacesAllowed;
+ this.accessData = accessData;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.CopyBranchRequest)
+ * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.ReadAllChildrenRequest)
*/
@Override
- public void process( CopyBranchRequest request ) {
+ public void process( ReadAllChildrenRequest request ) {
logger.trace(request.toString());
- verifyUpdatesAllowed();
+ // Get the SVNRepository object that represents the workspace ...
+ SVNRepository workspaceRoot = getWorkspaceDirectory(request.inWorkspace());
+ if (workspaceRoot == null) {
+ request.setError(new InvalidWorkspaceException(
+ SVNRepositoryConnectorI18n.workspaceDoesNotExist.text(request.inWorkspace())));
+ return;
+ }
+ Location myLocation = request.of();
+ Path requestedPath = getPathFor(myLocation, request);
+ // svn connector does not support same name sibling
+ checkThePath(requestedPath, request);
+ // requested path is the root
+ if (requestedPath.isRoot()) {
+ // workspace root must be a directory
+ final Collection<SVNDirEntry> entries = SVNRepositoryUtil.getDir(workspaceRoot, "");
+ for (SVNDirEntry entry : entries) {
+ // Decide how to represent the children ...
+ if (entry.getKind() == SVNNodeKind.DIR) {
+ // Create a Location for each file and directory contained by the parent directory ...
+ String localName = entry.getName();
+ Name childName = nameFactory().create(defaultNamespaceUri, localName);
+ Path childPath = pathFactory().create(requestedPath, childName);
+ request.addChild(Location.create(childPath));
+ } else if (entry.getKind() == SVNNodeKind.FILE) {
+ // The parent is a file, and the path may refer to the node that is either the "nt:file" parent
+ // node, or the child "jcr:content" node...
+ String localName = entry.getName();
+ Path contentPath = pathFactory().create(BACK_SLASH + localName);
+ if (!contentPath.getLastSegment().getName().equals(JcrLexicon.CONTENT)) {
+ Location location = Location.create(pathFactory().create(contentPath, JcrLexicon.CONTENT));
+ request.addChild(location);
+ }
+ }
+ }
+ } else {
+ try {
+ SVNNodeKind kind = getNodeKind(workspaceRoot,
+ requestedPath,
+ accessData.getRepositoryRootUrl(),
+ request.inWorkspace());
+ if (kind == SVNNodeKind.DIR) {
+ String directoryPath = getPathAsString(requestedPath);
+ // Decide how to represent the children ...
+ if (!accessData.getRepositoryRootUrl().equals(request.inWorkspace())) {
+ directoryPath = directoryPath.substring(1);
+ }
+ Collection<SVNDirEntry> dirEntries = SVNRepositoryUtil.getDir(workspaceRoot, directoryPath);
+ for (SVNDirEntry entry : dirEntries) {
+ // Decide how to represent the children ...
+ if (entry.getKind() == SVNNodeKind.DIR) {
+ // Create a Location for each file and directory contained by the parent directory ...
+ String localName = entry.getName();
+ Name childName = nameFactory().create(defaultNamespaceUri, localName);
+ Path childPath = pathFactory().create(requestedPath, childName);
+ request.addChild(Location.create(childPath));
+ } else if (entry.getKind() == SVNNodeKind.FILE) {
+ // The parent is a file, and the path may refer to the node that is either the "nt:file" parent
+ // node, or the child "jcr:content" node...
+ String localName = entry.getName();
+ Path contentPath = pathFactory().create(getPathAsString(requestedPath) + BACK_SLASH + localName);
+ Location content = Location.create(pathFactory().create(contentPath, JcrLexicon.CONTENT));
+ request.addChild(content);
+ }
+ }
+ } else {
+ if (!requestedPath.getLastSegment().getName().equals(JcrLexicon.CONTENT)) {
+ // Use leading '/' on the requested path
+ // repository root URL is exactly the same as the workspace
+ // Get the parent path
+ String filePath = getPathAsString(requestedPath);
+ if (!accessData.getRepositoryRootUrl().equals(request.inWorkspace())) {
+ filePath = filePath.substring(1);
+ }
+ Path contentPath = pathFactory().create(requestedPath, JcrLexicon.CONTENT);
+ Location content = Location.create(contentPath);
+ request.addChild(content);
+ }
+ }
+ } catch (SVNException e) {
+ request.setError(e);
+ }
+ }
+ request.setActualLocationOfNode(myLocation);
+ setCacheableInfo(request);
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.CreateNodeRequest)
+ * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.ReadAllPropertiesRequest)
*/
@Override
- public void process( CreateNodeRequest request ) {
+ public void process( ReadAllPropertiesRequest request ) {
logger.trace(request.toString());
- verifyUpdatesAllowed();
- // get the parent location of the new node
- Location myLocation = request.under();
- Path parent = getPathFor(myLocation, request);
+
+ // Get the SVNRepository object that represents the workspace ...
+ SVNRepository workspaceRoot = getWorkspaceDirectory(request.inWorkspace());
+ if (workspaceRoot == null) {
+ request.setError(new InvalidWorkspaceException(
+ SVNRepositoryConnectorI18n.workspaceDoesNotExist.text(request.inWorkspace())));
+ return;
+ }
+
+ // Find the existing file for the parent ...
+ Location myLocation = request.at();
+ Path requestedPath = getPathFor(myLocation, request);
+ if (requestedPath.isRoot()) {
+ // There are no properties on the root ...
+ request.setActualLocationOfNode(myLocation);
+ setCacheableInfo(request);
+ return;
+ }
+
try {
- String root = parent.getString(getExecutionContext().getNamespaceRegistry());
- SVNNodeKind rootKind = repository.checkPath(root, -1);
- if (rootKind == SVNNodeKind.UNKNOWN) {
- SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
- "path with name '{0}' is unknown in the repository",
- root);
- SVNException ex = new SVNException(err);
- request.setError(ex);
- } else if (rootKind == SVNNodeKind.NONE) {
- SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
- "path with name '{0}' is missing in the repository",
- root);
- SVNException ex = new SVNException(err);
- request.setError(ex);
- } else if (rootKind == SVNNodeKind.FILE) {
- SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
- "pretended root item with name '{0}' is a file",
- root);
- SVNException ex = new SVNException(err);
- request.setError(ex);
- } else if (rootKind == SVNNodeKind.DIR) {
- Collection<Property> childNodeProperties = request.properties();
- Object[] objs = values(childNodeProperties);
- for (Object object : objs) {
- if (object instanceof Name && ((Name)object).compareTo(JcrNtLexicon.FOLDER) == 0) {
- // process folder creation
- // if the node is a directory
- String folderName = request.named().getString(getExecutionContext().getNamespaceRegistry());
- if (root.length() == 1 && root.charAt(0) == '/') {
- // test if so a directory does not exist.
- mkdir("", folderName, request.toString());
- } else {
- if (root.length() > 1 && root.charAt(0) == '/') {
- // test if so a directory does not exist.
- mkdir(root.substring(1), folderName, request.toString());
- }
- }
- } else if (object instanceof Name && ((Name)object).compareTo(JcrNtLexicon.FILE) == 0) {
- String fileName = request.named().getString(getExecutionContext().getNamespaceRegistry());
- byte[] content = getContent(objs);
- // TODO: what is with the created on
- // Date createdOn = getCreatedOn(objs);
- // commit in to the repository
- newFile(root, fileName, content, request.toString());
+
+ SVNNodeKind kind = getNodeKind(workspaceRoot, requestedPath, accessData.getRepositoryRootUrl(), request.inWorkspace());
+ // Generate the properties for this File object ...
+ PropertyFactory factory = getExecutionContext().getPropertyFactory();
+ DateTimeFactory dateFactory = getExecutionContext().getValueFactories().getDateFactory();
+ // Note that we don't have 'created' timestamps, just last modified, so we'll have to use them
+ if (kind == SVNNodeKind.DIR) {
+ String directoryPath = getPathAsString(requestedPath);
+ if (!accessData.getRepositoryRootUrl().equals(request.inWorkspace())) {
+ directoryPath = directoryPath.substring(1);
+ }
+ request.addProperty(factory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FOLDER));
+ SVNDirEntry entry = getEntryInfo(workspaceRoot, directoryPath);
+ request.addProperty(factory.create(JcrLexicon.LAST_MODIFIED, dateFactory.create(entry.getDate())));
+ } else {
+ if (requestedPath.getLastSegment().getName().equals(JcrLexicon.CONTENT)) {
+ String contentPath = getPathAsString(requestedPath.getParent());
+ if (!accessData.getRepositoryRootUrl().equals(request.inWorkspace())) {
+ contentPath = contentPath.substring(1);
}
+ SVNDirEntry entry = getEntryInfo(workspaceRoot, contentPath);
+ // The request is to get properties of the "jcr:content" child node ...
+ request.addProperty(factory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.RESOURCE));
+ request.addProperty(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;
+ request.addProperty(factory.create(JcrLexicon.MIMETYPE, mimeType));
+
+ if (os.toByteArray().length > 0) {
+ // Now put the file's content into the "jcr:data" property ...
+ BinaryFactory binaryFactory = getExecutionContext().getValueFactories().getBinaryFactory();
+ request.addProperty(factory.create(JcrLexicon.DATA, binaryFactory.create(os.toByteArray())));
+ }
+
+ } else {
+ String filePath = getPathAsString(requestedPath);
+ if (!accessData.getRepositoryRootUrl().equals(request.inWorkspace())) {
+ filePath = filePath.substring(1);
+ }
+ // The request is to get properties for the node representing the file
+ request.addProperty(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);
+ if (created != null) {
+ request.addProperty(factory.create(JcrLexicon.CREATED, dateFactory.create(created)));
+ }
}
}
+ request.setActualLocationOfNode(myLocation);
+ setCacheableInfo(request);
} catch (SVNException e) {
request.setError(e);
@@ -191,21 +315,20 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.DeleteBranchRequest)
+ * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.CreateNodeRequest)
*/
@Override
- public void process( DeleteBranchRequest request ) {
- logger.trace(request.toString());
- verifyUpdatesAllowed();
+ public void process( CreateNodeRequest request ) {
+ updatesAllowed(request);
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.MoveBranchRequest)
+ * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.UpdatePropertiesRequest)
*/
@Override
- public void process( MoveBranchRequest request ) {
+ public void process( UpdatePropertiesRequest request ) {
logger.trace(request.toString());
verifyUpdatesAllowed();
}
@@ -213,157 +336,41 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.ReadAllChildrenRequest)
+ * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.CopyBranchRequest)
*/
- @SuppressWarnings( "unchecked" )
@Override
- public void process( ReadAllChildrenRequest request ) {
- logger.trace(request.toString());
- Location myLocation = request.of();
- Path nodePath = getPathFor(myLocation, request);
- try {
- SVNNodeKind kind = validateNodeKind(nodePath);
- String requestedNodePath = nodePath.getString(getExecutionContext().getNamespaceRegistry());
- if (kind == SVNNodeKind.FILE) { // the requested node is a file.
- SVNDirEntry entry = getEntryInfo(requestedNodePath);
- if (!nodePath.getLastSegment().getName().equals(JcrLexicon.CONTENT)) {
- String localName = entry.getName();
- Name childName = nameFactory().create(defaultNamespaceUri, localName);
- String url = entry.getURL().toString();
- Property idProperty = propertyFactory().create(childName, url);
- request.addChild(Location.create(pathFactory().create(nodePath, JcrLexicon.CONTENT), idProperty));
- }
- } else if (kind == SVNNodeKind.DIR) { // the requested node is a directory.
- final Collection<SVNDirEntry> dirEntries = getRepository().getDir(requestedNodePath,
- -1,
- null,
- (Collection<SVNDirEntry>)null);
- for (SVNDirEntry dirEntry : dirEntries) {
- if (dirEntry.getKind() == SVNNodeKind.FILE) {
- String localName = dirEntry.getName();
- Path newPath = pathFactory().create(requestedNodePath + BACK_SLASH + localName);
- if (!newPath.getLastSegment().getName().equals(JcrLexicon.CONTENT)) {
- Name childName = nameFactory().create(defaultNamespaceUri, localName);
- String url = dirEntry.getURL().toString();
- Property idProperty = propertyFactory().create(childName, url);
- Location location = Location.create(pathFactory().create(newPath, JcrLexicon.CONTENT), idProperty);
- request.addChild(location);
- }
- } else if (dirEntry.getKind() == SVNNodeKind.DIR) {
- String localName = dirEntry.getName();
- Name childName = nameFactory().create(defaultNamespaceUri, localName);
- Path childPath = pathFactory().create(nodePath, childName);
- String url = dirEntry.getURL().toString();
- Property idProperty = propertyFactory().create(childName, url);
- request.addChild(childPath, idProperty);
- }
- }
- }
- request.setActualLocationOfNode(myLocation);
- } catch (SVNException e) {
- request.setError(e);
- }
-
+ public void process( CopyBranchRequest request ) {
+ updatesAllowed(request);
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.ReadAllPropertiesRequest)
+ * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.DeleteBranchRequest)
*/
@Override
- public void process( ReadAllPropertiesRequest request ) {
- logger.trace(request.toString());
- Location myLocation = request.at();
- Path nodePath = getPathFor(myLocation, request);
- if (nodePath.isRoot()) {
- // There are no properties on the root ...
- request.setActualLocationOfNode(myLocation);
- return;
- }
- try {
- // See if the path is a "jcr:content" node ...
- if (nodePath.getLastSegment().getName().equals(JcrLexicon.CONTENT)) {
- // //"jcr:primaryType" property value of "nt:resource",
- // "jcr:data" property whose value are the contents of the file
- // and a few other properties, like "jcr:encoding", "jcr:mimeType" and "jcr:lastModified" and
- // also "jcr:created" property
- Path parent = nodePath.getParent();
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- SVNProperties fileProperties = new SVNProperties();
- getData(parent.getString(getExecutionContext().getNamespaceRegistry()), fileProperties, os);
- Property ntResourceproperty = propertyFactory().create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.RESOURCE);
- request.addProperty(ntResourceproperty);
- String mimeType = fileProperties.getStringValue(SVNProperty.MIME_TYPE);
- if (mimeType != null) {
- Property jcrMimeTypeProperty = propertyFactory().create(JcrLexicon.MIMETYPE, mimeType);
- request.addProperty(jcrMimeTypeProperty);
- }
- SVNDirEntry entry = getEntryInfo(parent.getString(getExecutionContext().getNamespaceRegistry()));
- Date lastModified = entry.getDate();
- if (lastModified != null) {
- Property jcrLastModifiedProperty = propertyFactory().create(JcrLexicon.LAST_MODIFIED,
- dateFactory().create(lastModified));
- request.addProperty(jcrLastModifiedProperty);
- }
- if (os.toByteArray().length > 0) {
- Property jcrDataProperty = propertyFactory().create(JcrLexicon.DATA, binaryFactory().create(os.toByteArray()));
- request.addProperty(jcrDataProperty);
- }
- } else {
- SVNNodeKind kind = validateNodeKind(nodePath);
- if (kind == SVNNodeKind.FILE) {
- // "jcr:primaryType" property whose value is "nt:file".
- Property ntFileProperty = propertyFactory().create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FILE);
- request.addProperty(ntFileProperty);
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- SVNProperties fileProperties = new SVNProperties();
- getData(nodePath.getString(getExecutionContext().getNamespaceRegistry()), fileProperties, os);
- String created = fileProperties.getStringValue(SVNProperty.COMMITTED_DATE);
- if (created != null) {
- Property jcrCreatedProperty = propertyFactory().create(JcrLexicon.CREATED, created);
- request.addProperty(jcrCreatedProperty);
- }
-
- } else if (kind == SVNNodeKind.DIR) {
- // A directory maps to a single node with a name that represents the name of the directory and a
- // "jcr:primaryType" property whose value is "nt:folder"
- Property jcrPrimaryTypeProp = propertyFactory().create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FOLDER);
- request.addProperty(jcrPrimaryTypeProp);
- SVNDirEntry dirEntry = getEntryInfo(nodePath.getString(getExecutionContext().getNamespaceRegistry()));
- Property jcrCreatedProp = propertyFactory().create(JcrLexicon.CREATED,
- dateFactory().create(dirEntry.getDate()));
- request.addProperty(jcrCreatedProp);
- }
- }
- request.setActualLocationOfNode(myLocation);
-
- } catch (SVNException e) {
- request.setError(e);
- }
+ public void process( DeleteBranchRequest request ) {
+ updatesAllowed(request);
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.RenameNodeRequest)
+ * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.MoveBranchRequest)
*/
@Override
- public void process( RenameNodeRequest request ) {
- logger.trace(request.toString());
- verifyUpdatesAllowed();
- super.process(request);
+ public void process( MoveBranchRequest request ) {
+ updatesAllowed(request);
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.UpdatePropertiesRequest)
+ * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.RenameNodeRequest)
*/
@Override
- public void process( UpdatePropertiesRequest request ) {
- logger.trace(request.toString());
- verifyUpdatesAllowed();
+ public void process( RenameNodeRequest request ) {
+ if (updatesAllowed(request)) super.process(request);
}
/**
@@ -373,11 +380,42 @@
*/
@Override
public void process( VerifyWorkspaceRequest request ) {
- // This does the job of converting a null workspace name to a valid workspace
+ // If the request contains a null name, then we use the default ...
String workspaceName = request.workspaceName();
- if (workspaceName == null) workspaceName = "default";
- request.setActualRootLocation(Location.create(pathFactory().createRootPath()));
- request.setActualWorkspaceName(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.worspaceDoesNotExist.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)));
+ }
}
/**
@@ -387,29 +425,58 @@
*/
@Override
public void process( GetWorkspacesRequest request ) {
- request.setAvailableWorkspaceNames(Collections.singleton("default"));
+ // 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.CreateWorkspaceRequest)
+ * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.CloneWorkspaceRequest)
*/
@Override
- public void process( CreateWorkspaceRequest request ) {
- String msg = SVNRepositoryConnectorI18n.sourceDoesNotSupportCreatingWorkspaces.text(getSourceName());
- request.setError(new InvalidRequestException(msg));
+ 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.CloneWorkspaceRequest)
+ * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.CreateWorkspaceRequest)
*/
@Override
- public void process( CloneWorkspaceRequest request ) {
- String msg = SVNRepositoryConnectorI18n.sourceDoesNotSupportCloningWorkspaces.text(getSourceName());
- request.setError(new InvalidRequestException(msg));
+ 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)));
+ }
+
}
/**
@@ -419,8 +486,15 @@
*/
@Override
public void process( DestroyWorkspaceRequest request ) {
- String msg = SVNRepositoryConnectorI18n.sourceDoesNotSupportDeletingWorkspaces.text(getSourceName());
- request.setError(new InvalidRequestException(msg));
+ 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)));
+ }
}
/**
@@ -434,6 +508,13 @@
}
}
+ protected boolean updatesAllowed( Request request ) {
+ if (!updatesAllowed) {
+ request.setError(new InvalidRequestException(SVNRepositoryConnectorI18n.sourceIsReadOnly.text(getSourceName())));
+ }
+ return !request.hasError();
+ }
+
/**
* Factory for sample name.
*
@@ -508,7 +589,7 @@
protected void getData( String path,
SVNProperties properties,
OutputStream os ) throws SVNException {
- getRepository().getFile(path, -1, properties, os);
+ getDefaultWorkspace().getFile(path, -1, properties, os);
}
@@ -517,21 +598,33 @@
*
* @return repository
*/
- public SVNRepository getRepository() {
- return repository;
+ public SVNRepository getDefaultWorkspace() {
+ return defaultWorkspace;
}
/**
* Validate the kind of node and throws an exception if necessary.
*
+ * @param repos
* @param requestedPath
* @return the kind.
*/
- protected SVNNodeKind validateNodeKind( final Path requestedPath ) {
- String myPath = requestedPath.getString(getExecutionContext().getNamespaceRegistry());
- SVNNodeKind kind = null;
+ protected SVNNodeKind validateNodeKind( SVNRepository repos,
+ Path requestedPath ) {
+ SVNNodeKind kind;
+ String myPath;
+ if (getPathAsString(requestedPath).trim().equals("/")) {
+ myPath = getPathAsString(requestedPath);
+ } else if (requestedPath.getLastSegment().getName().equals(JcrLexicon.CONTENT)) {
+ myPath = getPathAsString(requestedPath.getParent());
+ } else {
+ // directory and file
+ myPath = getPathAsString(requestedPath);
+ }
+
try {
- kind = getRepository().checkPath(myPath, -1);
+
+ 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,
@@ -550,17 +643,23 @@
return kind;
}
+ private 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}.
*/
- protected SVNDirEntry getEntryInfo( String path ) {
+ protected SVNDirEntry getEntryInfo( SVNRepository repos,
+ String path ) {
assert path != null;
SVNDirEntry entry = null;
try {
- entry = getRepository().info(path, -1);
+ entry = repos.info(path, -1);
} catch (SVNException e) {
throw new RepositorySourceException(
getSourceName(),
@@ -610,12 +709,13 @@
/**
* Get the last revision.
*
+ * @param repos
* @return the last revision number.
* @throws Exception
*/
- public long getLatestRevision() throws Exception {
+ public long getLatestRevision( SVNRepository repos ) throws Exception {
try {
- return repository.getLatestRevision();
+ return repos.getLatestRevision();
} catch (SVNException e) {
e.printStackTrace();
// logger.error( "svn error: " );
@@ -656,21 +756,22 @@
} else if (rootKind == SVNNodeKind.DIR) {
ISVNEditor editor = repository.getCommitEditor(message, null, true, null);
if (root.length() == 1 && root.charAt(0) == '/') {
- addProcess(editor, root, "", child);
+ addProcess(repository, editor, root, "", child);
} else {
String rootPath = root.substring(1);
- addProcess(editor, rootPath, null, child);
+ addProcess(repository, editor, rootPath, null, child);
}
}
}
- private void addProcess( ISVNEditor editor,
+ private void addProcess( SVNRepository repos,
+ ISVNEditor editor,
String rootPath,
String editedRoot,
String childSegmentName ) throws SVNException {
openDirectories(editor, editedRoot);
// test if so a directory does not exist.
- SVNNodeKind childKind = repository.checkPath(childSegmentName, -1);
+ SVNNodeKind childKind = repos.checkPath(childSegmentName, -1);
if (childKind == SVNNodeKind.NONE) {
editor.addDir(childSegmentName, null, -1);
closeDirectories(editor, childSegmentName);
@@ -693,18 +794,21 @@
/**
* Create a directory .
*
+ * @param repos
* @param root - the root directory where the created directory will reside
* @param childName - the name of the created directory.
* @param message - comment for the creation.
* @throws SVNException - if during the creation, there is an error.
*/
- private void mkdir( String root,
+ @SuppressWarnings("unused")
+ private void mkdir( SVNRepository repos,
+ String root,
String childName,
String message ) throws SVNException {
- SVNNodeKind childKind = repository.checkPath(childName, -1);
+ SVNNodeKind childKind = repos.checkPath(childName, -1);
if (childKind == SVNNodeKind.NONE) {
ScmAction addNodeAction = addDirectory(root, childName);
- SVNActionExecutor executor = new SVNActionExecutor(repository);
+ SVNActionExecutor executor = new SVNActionExecutor(repos);
executor.execute(addNodeAction, message);
} else {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN, "Item with name '{0}' can't be created", childName);
@@ -721,14 +825,15 @@
* @param message
* @throws SVNException
*/
+ @SuppressWarnings("unused")
private void newFile( String path,
String file,
byte[] content,
String message ) throws SVNException {
- SVNNodeKind childKind = repository.checkPath(file, -1);
+ SVNNodeKind childKind = defaultWorkspace.checkPath(file, -1);
if (childKind == SVNNodeKind.NONE) {
ScmAction addFileNodeAction = addFile(path, file, content);
- SVNActionExecutor executor = new SVNActionExecutor(repository);
+ SVNActionExecutor executor = new SVNActionExecutor(defaultWorkspace);
executor.execute(addFileNodeAction, message);
} else {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
@@ -849,17 +954,7 @@
}
- // private Date getCreatedOn( Object[] objs ) {
- // Date createdOn = null;
- // for (Object object : objs) {
- // if (object instanceof Date) {
- // createdOn = (Date)object;
- //
- // }
- // }
- // return createdOn;
- // }
-
+ @SuppressWarnings("unused")
private byte[] getContent( Object[] objs ) {
byte[] content = null;
for (Object object : objs) {
@@ -871,6 +966,7 @@
return content;
}
+ @SuppressWarnings("unused")
private Object[] values( Collection<Property> childNodeProperties ) {
Set<Object> result = new HashSet<Object>();
for (Property property : childNodeProperties) {
@@ -878,4 +974,64 @@
}
return result.toArray();
}
+
+ private 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(getSourceName(), request));
+ }
+ // TODO
+// if (!segment.getName().getNamespaceUri().equals(defaultNamespaceUri)) {
+// I18n msg = SVNRepositoryConnectorI18n.onlyTheDefaultNamespaceIsAllowed;
+// throw new RepositorySourceException(getSourceName(), msg.text(getSourceName(), request));
+// }
+ }
+ }
+
+ 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.getLastSegment().getName().equals(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;
+ }
}
15 years, 1 month
DNA SVN: r927 - trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2009-05-22 09:19:37 -0400 (Fri, 22 May 2009)
New Revision: 927
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java
Log:
changes made to support workspace features
Modified: 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 2009-05-22 13:19:21 UTC (rev 926)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java 2009-05-22 13:19:37 UTC (rev 927)
@@ -1,69 +1,80 @@
-/*
- * 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;
-
-/**
- * @author Serge Pagop
- */
-public final class SVNRepositoryConnectorI18n {
-
- public static I18n connectorName;
- public static I18n nodeDoesNotExist;
- public static I18n nodeIsActuallyUnknow;
- public static I18n nodeTypeIsNotSupported;
- public static I18n propertyIsRequired;
- public static I18n errorSerializingCachePolicyInSource;
- public static I18n objectFoundInJndiWasNotCache;
- public static I18n objectFoundInJndiWasNotCacheFactory;
- public static I18n locationInRequestMustHavePath;
- public static I18n sourceIsReadOnly;
- public static I18n sourceDoesNotSupportCreatingWorkspaces;
- public static I18n sourceDoesNotSupportCloningWorkspaces;
- public static I18n sourceDoesNotSupportDeletingWorkspaces;
- public static I18n connectingFailureOrUserAuthenticationProblem;
-
- 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);
- }
-}
+/*
+ * 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;
+
+/**
+ * @author Serge Pagop
+ */
+public final class SVNRepositoryConnectorI18n {
+
+ public static I18n connectorName;
+ public static I18n nodeDoesNotExist;
+ public static I18n nodeIsActuallyUnknow;
+ public static I18n nodeTypeIsNotSupported;
+ public static I18n propertyIsRequired;
+ public static I18n errorSerializingCachePolicyInSource;
+ public static I18n objectFoundInJndiWasNotCache;
+ public static I18n objectFoundInJndiWasNotCacheFactory;
+ 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 worspaceDoesNotExist;
+ 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;
+
+ 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);
+ }
+}
15 years, 1 month
DNA SVN: r926 - trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2009-05-22 09:19:21 -0400 (Fri, 22 May 2009)
New Revision: 926
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnection.java
Log:
changes made to support workspace features
Modified: 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 2009-05-22 13:14:08 UTC (rev 925)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnection.java 2009-05-22 13:19:21 UTC (rev 926)
@@ -23,6 +23,7 @@
*/
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;
@@ -30,8 +31,6 @@
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.property.PathFactory;
-import org.jboss.dna.graph.property.PropertyFactory;
import org.jboss.dna.graph.request.Request;
import org.jboss.dna.graph.request.processor.RequestProcessor;
import org.tmatesoft.svn.core.SVNErrorCode;
@@ -41,7 +40,7 @@
import org.tmatesoft.svn.core.io.SVNRepository;
/**
- * The repository connection to a SVN Repository instance.
+ * The defaultRepository connection to a SVN Repository instance.
*
* @author Serge Pagop
*/
@@ -49,33 +48,54 @@
private final String sourceName;
private final CachePolicy cachePolicy;
- private final SVNRepository repository;
+ 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,
- SVNRepository repository ) {
- CheckArg.isNotNull(repository, "repository");
- CheckArg.isNotNull(sourceName, "sourceName");
+ 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 = repository.checkPath("", -1);
+ nodeKind = defaultWorkspace.checkPath("", -1);
if (nodeKind == SVNNodeKind.NONE) {
SVNErrorMessage error = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
"No entry at URL ''{0}''",
- repository.getLocation().getPath());
+ 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",
- repository.getLocation().getPath());
+ 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",
- repository.getLocation().getPath());
+ defaultWorkspace.getLocation().getPath());
throw new SVNException(error);
}
} catch (SVNException e) {
@@ -85,12 +105,15 @@
this.sourceName = sourceName;
this.cachePolicy = cachePolicy;
- this.repository = repository;
+ this.defaultWorkspace = defaultWorkspace;
this.updatesAllowed = updatesAllowed;
+ this.availableWorkspaceNames = availableWorkspaceNames;
+ this.creatingWorkspacesAllowed = creatingWorkspacesAllowed;
+ this.accessData = accessData;
}
- SVNRepository getRepository() {
- return repository;
+ SVNRepository getDefaultWorkspace() {
+ return defaultWorkspace;
}
/**
@@ -120,7 +143,7 @@
public boolean ping( long time,
TimeUnit unit ) {
try {
- this.repository.getRepositoryRoot(true);
+ this.defaultWorkspace.getRepositoryRoot(true);
} catch (SVNException e) {
return false;
}
@@ -142,18 +165,24 @@
* @see org.jboss.dna.graph.connector.RepositoryConnection#execute(org.jboss.dna.graph.ExecutionContext,
* org.jboss.dna.graph.request.Request)
*/
- @SuppressWarnings( "unused" )
public void execute( final ExecutionContext context,
final Request request ) throws RepositorySourceException {
- final PathFactory pathFactory = context.getValueFactories().getPathFactory();
- final PropertyFactory propertyFactory = context.getPropertyFactory();
- RequestProcessor processor = new SVNRepositoryRequestProcessor(getSourceName(), context, repository, updatesAllowed);
+ 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;
+ }
}
15 years, 1 month
DNA SVN: r925 - trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2009-05-22 09:14:08 -0400 (Fri, 22 May 2009)
New Revision: 925
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryUtil.java
Log:
svn repos connector util class
Added: 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 (rev 0)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryUtil.java 2009-05-22 13:14:08 UTC (rev 925)
@@ -0,0 +1,213 @@
+package org.jboss.dna.connector.svn;
+
+import java.util.Collection;
+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.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 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) {
+ throw new RepositorySourceException(sourceName, e.getMessage());
+ }
+ 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.
+ */
+ @SuppressWarnings( "unchecked" )
+ public static Collection<SVNDirEntry> getDir( SVNRepository repos,
+ String path ) {
+ Collection<SVNDirEntry> entries = null;
+ try {
+ return repos.getDir(path, -1, null, (Collection<SVNDirEntry>)null);
+ } catch (SVNException e) {
+ return entries;
+ }
+ }
+
+ /**
+ * 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 ) {
+ try {
+ if (repository.checkPath(path, -1) == SVNNodeKind.NONE) {
+ return false;
+ } else if (repository.checkPath(path, -1) == SVNNodeKind.UNKNOWN) {
+ return false;
+ }
+ } catch (SVNException e) {
+ return false;
+ }
+ return true;
+ }
+}
15 years, 1 month