Author: rhauch
Date: 2008-12-08 13:06:24 -0500 (Mon, 08 Dec 2008)
New Revision: 670
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/util/FileUtil.java
trunk/extensions/dna-connector-svn/.classpath
trunk/extensions/dna-connector-svn/.project
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnection.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java
Log:
DNA-36 Changed the way the local repository is created to better match how Hudson works
(hopefully). Also changed to use the FileUtil.deletemethod, and moved the copy
functionality into FileUtil. Finally, changed the asserts in the SVNRepositoryConnection
constructor to be arg checks; this is more testable (as unit tests should not be expecting
AssertionError, as then it is not possible to run the unit tests against the code with
asserts removed.
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/util/FileUtil.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/util/FileUtil.java 2008-12-08
17:01:20 UTC (rev 669)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/FileUtil.java 2008-12-08
18:06:24 UTC (rev 670)
@@ -23,6 +23,9 @@
package org.jboss.dna.common.util;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
@@ -63,6 +66,49 @@
}
/**
+ * Copy the source file system structure into the supplied target location. If the
source is a file, the destiniation will be
+ * created as a file; if the source is a directory, the destination will be created
as a directory.
+ *
+ * @param sourceFileOrDirectory the file or directory whose contents are to be copied
into the target location
+ * @param destinationFileOrDirectory the location where the copy is to be placed;
does not need to exist, but if it does its
+ * type must match that of <code>src</code>
+ * @return the number of files (not directories) that were copied
+ * @throws IllegalArgumentException if the <code>src</code> or
<code>dest</code> references are null
+ * @throws IOException
+ */
+ public static int copy( File sourceFileOrDirectory,
+ File destinationFileOrDirectory ) throws IOException {
+ int numberOfFilesCopied = 0;
+ if (sourceFileOrDirectory.isDirectory()) {
+ destinationFileOrDirectory.mkdirs();
+ String list[] = sourceFileOrDirectory.list();
+
+ for (int i = 0; i < list.length; i++) {
+ String dest1 = destinationFileOrDirectory.getPath() + File.separator +
list[i];
+ String src1 = sourceFileOrDirectory.getPath() + File.separator +
list[i];
+ numberOfFilesCopied += copy(new File(src1), new File(dest1));
+ }
+ } else {
+ FileInputStream fin = new FileInputStream(sourceFileOrDirectory);
+ try {
+ FileOutputStream fout = new
FileOutputStream(destinationFileOrDirectory);
+ try {
+ int c;
+ while ((c = fin.read()) >= 0) {
+ fout.write(c);
+ }
+ } finally {
+ fout.close();
+ }
+ } finally {
+ fin.close();
+ }
+ numberOfFilesCopied++;
+ }
+ return numberOfFilesCopied;
+ }
+
+ /**
* Utility to convert {@link File} to {@link URL}.
*
* @param filePath the path of the file
Modified: trunk/extensions/dna-connector-svn/.classpath
===================================================================
--- trunk/extensions/dna-connector-svn/.classpath 2008-12-08 17:01:20 UTC (rev 669)
+++ trunk/extensions/dna-connector-svn/.classpath 2008-12-08 18:06:24 UTC (rev 670)
@@ -1,18 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" path="src/main/resources"
excluding="**/*.java"/>
- <classpathentry kind="src" path="src/test/java"
output="target/test-classes"/>
- <classpathentry kind="src" path="src/test/resources"
output="target/test-classes" excluding="**/*.java"/>
- <classpathentry kind="output" path="target/classes"/>
- <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="src" path="/dna-common"/>
- <classpathentry kind="src" path="/dna-graph"/>
- <classpathentry kind="var"
path="M2_REPO/net/jcip/jcip-annotations/1.0/jcip-annotations-1.0.jar"/>
- <classpathentry kind="var"
path="M2_REPO/joda-time/joda-time/1.4/joda-time-1.4.jar"/>
- <classpathentry kind="var"
path="M2_REPO/junit/junit/4.4/junit-4.4.jar"/>
- <classpathentry kind="var"
path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar"/>
- <classpathentry kind="var"
path="M2_REPO/org/mockito/mockito-all/1.5/mockito-all-1.5.jar"/>
- <classpathentry kind="var"
path="M2_REPO/org/slf4j/slf4j-api/1.4.3/slf4j-api-1.4.3.jar"/>
- <classpathentry kind="var"
path="M2_REPO/org/slf4j/slf4j-log4j12/1.4.3/slf4j-log4j12-1.4.3.jar"/>
- <classpathentry kind="var"
path="M2_REPO/org/tmatesoft/svnkit/svnkit/1.2.0.4949/svnkit-1.2.0.4949.jar"/>
-</classpath>
\ No newline at end of file
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/test-classes"
path="src/test/java"/>
+ <classpathentry kind="src" output="target/test-classes"
path="src/test/resources"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con"
path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Modified: trunk/extensions/dna-connector-svn/.project
===================================================================
--- trunk/extensions/dna-connector-svn/.project 2008-12-08 17:01:20 UTC (rev 669)
+++ trunk/extensions/dna-connector-svn/.project 2008-12-08 18:06:24 UTC (rev 670)
@@ -1,16 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>dna-connector-svn</name>
- <comment>JBoss DNA Connector that accesses an in-process SVN
instance.</comment>
- <projects>
- <project>dna-common</project>
- <project>dna-graph</project>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
\ No newline at end of file
+ <name>dna-connector-svn</name>
+ <comment>JBoss DNA Connector that accesses an in-process SVN
instance.</comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
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 2008-12-08
17:01:20 UTC (rev 669)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnection.java 2008-12-08
18:06:24 UTC (rev 670)
@@ -24,6 +24,7 @@
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import javax.transaction.xa.XAResource;
+import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.cache.CachePolicy;
import org.jboss.dna.graph.connectors.RepositoryConnection;
@@ -68,8 +69,8 @@
CachePolicy cachePolicy,
boolean updatesAllowed,
SVNRepository repository ) {
- assert (sourceName != null);
- assert (repository != null);
+ CheckArg.isNotNull(repository, "repository");
+ CheckArg.isNotNull(sourceName, "sourceName");
SVNNodeKind nodeKind = null;
try {
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 2008-12-08
17:01:20 UTC (rev 669)
+++
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java 2008-12-08
18:06:24 UTC (rev 670)
@@ -1,24 +1,24 @@
- /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * 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.
- *
- * This software 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.
- */
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* 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.
+*
+* This software 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 static org.hamcrest.core.Is.is;
@@ -26,23 +26,12 @@
import static org.hamcrest.core.IsSame.sameInstance;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.stub;
-import static org.mockito.Mockito.verify;
-import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
import org.jboss.dna.common.text.UrlEncoder;
+import org.jboss.dna.common.util.FileUtil;
import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.ExecutionContext;
@@ -50,28 +39,18 @@
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.connectors.RepositorySourceListener;
-import org.jboss.dna.graph.properties.Name;
import org.jboss.dna.graph.properties.NameFactory;
-import org.jboss.dna.graph.properties.Path;
import org.jboss.dna.graph.properties.PathFactory;
import org.jboss.dna.graph.properties.PathNotFoundException;
import org.jboss.dna.graph.properties.PropertyFactory;
-import org.jboss.dna.graph.properties.Path.Segment;
import org.jboss.dna.graph.requests.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.SVNDirEntry;
-import org.tmatesoft.svn.core.SVNException;
-import org.tmatesoft.svn.core.SVNNodeKind;
-import org.tmatesoft.svn.core.SVNProperties;
-import org.tmatesoft.svn.core.internal.io.dav.DAVRepository;
-import org.tmatesoft.svn.core.internal.util.SVNEncodingUtil;
import org.tmatesoft.svn.core.io.SVNRepository;
/**
@@ -106,20 +85,18 @@
propertyFactory = context.getPropertyFactory();
nameFactory = context.getValueFactories().getNameFactory();
- // First we need to find the absolute path
- URL url = getClass().getResource("/dummy_svn_repos");
+ // 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 src = new File("src/test/resources/dummy_svn_repos");
+ File dst = new File("target/copy_dummy_svn_repos");
- assertThat(url, is(notNullValue()));
- File src = new File(url.getFile());
- File dst = new File(src.getParent(), "/copy_dummy_svn_repo");
-
// make sure the destination is empty before we copy
- delete(dst);
+ FileUtil.delete(dst);
+ FileUtil.copy(src, dst);
- copy(src, dst);
-
// Now set the two path roots
- String svnUrl = "file:///" +
dst.getAbsolutePath().replaceAll("\\\\", "/");
+ String svnUrl = dst.getCanonicalFile().toURL().toString();
+ svnUrl = svnUrl.replaceFirst("file:/", "file://localhost/");
// add the 'localhost'
String username = "sp";
String password = "";
// Create a Repository instance from the http-protocol, that use a anonymous
credential.
@@ -142,13 +119,13 @@
}
}
- @Test( expected = AssertionError.class )
+ @Test( expected = IllegalArgumentException.class )
public void shouldFailToInstantiateIfSourceNameIsNull() {
sourceName = null;
connection = new SVNRepositoryConnection(sourceName, policy, Boolean.FALSE,
repository);
}
- @Test( expected = AssertionError.class )
+ @Test( expected = IllegalArgumentException.class )
public void shouldFailToInstantiateIfRepositoryIsNull() {
repository = null;
connection = new SVNRepositoryConnection(sourceName, policy, Boolean.FALSE,
repository);
@@ -169,15 +146,15 @@
assertThat(connection.getDefaultCachePolicy(), is(sameInstance(policy)));
}
-// @Test
-// public void shouldGetTheSVNRepositoryRootFromTheSVNRepositoryWhenPinged() throws
Exception {
-// CachePolicy policy = mock(CachePolicy.class);
-// repository = mock(SVNRepository.class);
-// connection = new SVNRepositoryConnection("the source name", policy,
false, repository);
-// stub(repository.getRepositoryRoot(true)).toReturn(null);
-// assertThat(connection.ping(1, TimeUnit.SECONDS), is(true));
-// verify(repository).getRepositoryRoot(true);
-// }
+ // @Test
+ // public void shouldGetTheSVNRepositoryRootFromTheSVNRepositoryWhenPinged() throws
Exception {
+ // CachePolicy policy = mock(CachePolicy.class);
+ // repository = mock(SVNRepository.class);
+ // connection = new SVNRepositoryConnection("the source name", policy,
false, repository);
+ // stub(repository.getRepositoryRoot(true)).toReturn(null);
+ // assertThat(connection.ping(1, TimeUnit.SECONDS), is(true));
+ // verify(repository).getRepositoryRoot(true);
+ // }
@Test
public void shouldHaveNoOpListenerWhenCreated() {
@@ -212,7 +189,7 @@
}
- @Test
+ @Test
public void shouldListLocationForChildrenOfAParentPath() {
// read children from the root node.
@@ -239,40 +216,4 @@
return paths;
}
- public static void copy( File src,
- File dest ) throws IOException {
- if (src.isDirectory()) {
- dest.mkdirs();
- String list[] = src.list();
-
- for (int i = 0; i < list.length; i++) {
- String dest1 = dest.getPath() + File.separator + list[i];
- String src1 = src.getPath() + File.separator + list[i];
- copy(new File(src1), new File(dest1));
- }
- } else {
-
- FileInputStream fin = new FileInputStream(src);
- FileOutputStream fout = new FileOutputStream(dest);
- int c;
- while ((c = fin.read()) >= 0)
- fout.write(c);
- fin.close();
- fout.close();
- }
- }
-
- public static void delete( File src ) throws IOException {
- if (src.isDirectory()) {
- String list[] = src.list();
-
- for (int i = 0; i < list.length; i++) {
- String src1 = src.getPath() + File.separator + list[i];
- delete(new File(src1));
- }
- src.delete();
- } else {
- src.delete();
- }
- }
-}
\ No newline at end of file
+}