[jboss-svn-commits] JBL Code SVN: r9277 - in labs/jbossrules/trunk/drools-repository/src: main/java/org/drools/scm and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Feb 1 20:21:21 EST 2007


Author: mark.proctor at jboss.com
Date: 2007-02-01 20:21:21 -0500 (Thu, 01 Feb 2007)
New Revision: 9277

Added:
   labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/
   labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/DefaultScmEntry.java
   labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmAction.java
   labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmActionFactory.java
   labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmActionTypeFactory.java
   labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmEntry.java
   labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/svn/
   labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/svn/CompositeSvnAction.java
   labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/svn/SvnActionFactory.java
   labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/scm/svn/
   labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/scm/svn/SvnActionFactoryTest.java
Log:
-JBRULES-640 SCM replication/Sync implementation

Added: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/DefaultScmEntry.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/DefaultScmEntry.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/DefaultScmEntry.java	2007-02-02 01:21:21 UTC (rev 9277)
@@ -0,0 +1,79 @@
+package org.drools.scm;
+
+import java.io.File;
+import java.util.Date;
+
+import org.tmatesoft.svn.core.SVNDirEntry;
+import org.tmatesoft.svn.core.SVNNodeKind;
+
+public class DefaultScmEntry
+    implements
+    ScmEntry {
+//    private SVNDirEntry entry;
+    
+    private String author;
+    private Date date;
+    private String name;
+    private String path;
+    private long revision;
+    private long size;
+    private int type;
+   
+    public DefaultScmEntry() {
+        
+    }       
+    
+    public int getType() {
+        return type;
+    }
+
+    public void setType(int type) {
+        this.type = type;
+    }
+
+    public String getAuthor() {
+        return author;
+    }
+    public void setAuthor(String author) {
+        this.author = author;
+    }
+    public Date getDate() {
+        return date;
+    }
+    public void setDate(Date date) {
+        this.date = date;
+    }
+    public String getName() {
+        return name;
+    }
+    public void setName(String name) {
+        this.name = name;
+    }
+    public String getPath() {
+        return path;
+    }
+    public void setPath(String path) {
+        this.path = path;
+    }
+    public long getRevision() {
+        return revision;
+    }
+    public void setRevision(long revision) {
+        this.revision = revision;
+    }
+    public long getSize() {
+        return size;
+    }
+    public void setSize(long size) {
+        this.size = size;
+    }
+      
+    public boolean isFile() {
+        return this.type == ScmEntry.FILE;
+    }
+    
+    public boolean isDirectory() {
+        return this.type == ScmEntry.DIRECTORY;
+    }
+    
+}

Added: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmAction.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmAction.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmAction.java	2007-02-02 01:21:21 UTC (rev 9277)
@@ -0,0 +1,11 @@
+/**
+ * 
+ */
+package org.drools.scm;
+
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.io.ISVNEditor;
+
+public interface ScmAction {
+    public void applyAction(ISVNEditor editor) throws SVNException;
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmActionFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmActionFactory.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmActionFactory.java	2007-02-02 01:21:21 UTC (rev 9277)
@@ -0,0 +1,60 @@
+package org.drools.scm;
+
+import java.io.OutputStream;
+import java.util.List;
+
+import org.tmatesoft.svn.core.SVNException;
+
+
+
+public interface ScmActionFactory {
+    public long getLatestRevision() throws Exception ;
+
+    public ScmAction addFile(String path,
+                             String file,
+                             byte[] content);
+
+    public ScmAction addDirectory(String root,
+                                  String path);
+
+    public ScmAction updateFile(String path,
+                                String file,
+                                byte[] oldContent,
+                                byte[] newContent);
+
+    public ScmAction copyFile(String path,
+                              String file,
+                              String newPath,
+                              String newFile,
+                              long revision);
+
+    public ScmAction copyDirectory(String path,
+                                   String newPath,
+                                   long revision);
+
+    public ScmAction moveFile(String path,
+                              String file,
+                              String newPath,
+                              String newFile,
+                              long revision);
+
+    public ScmAction moveDirectory(String path,
+                                   String newPath,
+                                   long revision);
+
+    public ScmAction deleteFile(String path,
+                                String file);
+
+    public ScmAction deleteDirectory(String path);
+    
+    public void execute(ScmAction action,
+                        String message) throws Exception;
+    
+    public void getContent(String path, String file, long revision, OutputStream os) throws Exception;    
+    
+    public List listEntries(String path) throws Exception;
+    
+    public void listEntries(String path,
+                            List list) throws Exception;
+    
+}

Added: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmActionTypeFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmActionTypeFactory.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmActionTypeFactory.java	2007-02-02 01:21:21 UTC (rev 9277)
@@ -0,0 +1,14 @@
+package org.drools.scm;
+
+import java.util.Map;
+
+public class ScmActionTypeFactory {
+    
+    public void registerScmActionFactory() {
+        
+    }
+    
+    public void unregisterAcmActionFactory() {
+        
+    }
+}

Added: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmEntry.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmEntry.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmEntry.java	2007-02-02 01:21:21 UTC (rev 9277)
@@ -0,0 +1,18 @@
+package org.drools.scm;
+
+import java.util.Date;
+
+public interface ScmEntry {
+    public static final int FILE = 0;
+    public static final int DIRECTORY = 0;
+    
+    
+    String  getAuthor();
+    Date    getDate(); 
+    String  getName(); 
+    String  getPath();
+    long    getRevision(); 
+    long    getSize(); 
+    public boolean isFile();    
+    public boolean isDirectory();   
+}

Added: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/svn/CompositeSvnAction.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/svn/CompositeSvnAction.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/svn/CompositeSvnAction.java	2007-02-02 01:21:21 UTC (rev 9277)
@@ -0,0 +1,37 @@
+/**
+ * 
+ */
+package org.drools.scm.svn;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.drools.scm.ScmAction;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.io.ISVNEditor;
+
+public class CompositeSvnAction
+    implements
+    ScmAction {
+    private List actions;
+
+    public CompositeSvnAction() {
+        this.actions = Collections.EMPTY_LIST;
+    }
+
+    public void addScmAction(ScmAction action) {
+        if ( actions == Collections.EMPTY_LIST ) {
+            this.actions = new ArrayList();
+        }
+        this.actions.add( action );
+    }
+
+    public void applyAction(ISVNEditor editor) throws SVNException {
+        for ( Iterator it = this.actions.iterator(); it.hasNext(); ) {
+            ScmAction action = (ScmAction) it.next();
+            action.applyAction( editor );
+        }
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/svn/SvnActionFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/svn/SvnActionFactory.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/svn/SvnActionFactory.java	2007-02-02 01:21:21 UTC (rev 9277)
@@ -0,0 +1,627 @@
+package org.drools.scm.svn;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.drools.resource.util.SvnUtil.CopyDirectory;
+import org.drools.resource.util.SvnUtil.CopyFile;
+import org.drools.resource.util.SvnUtil.DeleteDirectory;
+import org.drools.resource.util.SvnUtil.DeleteFile;
+import org.drools.scm.DefaultScmEntry;
+import org.drools.scm.ScmAction;
+import org.drools.scm.ScmActionFactory;
+import org.drools.scm.ScmEntry;
+import org.tmatesoft.svn.core.SVNCommitInfo;
+import org.tmatesoft.svn.core.SVNDirEntry;
+import org.tmatesoft.svn.core.SVNErrorCode;
+import org.tmatesoft.svn.core.SVNErrorMessage;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.SVNNodeKind;
+import org.tmatesoft.svn.core.SVNURL;
+import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
+import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
+import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
+import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
+import org.tmatesoft.svn.core.io.ISVNEditor;
+import org.tmatesoft.svn.core.io.ISVNWorkspaceMediator;
+import org.tmatesoft.svn.core.io.SVNRepository;
+import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
+import org.tmatesoft.svn.core.io.diff.SVNDeltaGenerator;
+import org.tmatesoft.svn.core.wc.SVNWCUtil;
+
+public class SvnActionFactory
+    implements
+    ScmActionFactory {
+
+    private static Logger logger = Logger.getLogger( SvnActionFactory.class );
+    private SVNRepository repository;
+
+    /*
+     * Initializes the library to work with a repository either via svn:// (and
+     * svn+ssh://) or via http:// (and https://)
+     */
+    static {
+        // for DAV (over http and https)
+        DAVRepositoryFactory.setup();
+
+        // for SVN (over svn and svn+ssh)
+        SVNRepositoryFactoryImpl.setup();
+
+        // For File        
+        FSRepositoryFactory.setup();
+    }
+
+    public SVNRepository getSVNRepository() {
+        return this.repository;
+    }
+
+    public ScmAction addDirectory(String root,
+                                  String path) {
+        return new AddDirectory( root,
+                                 path );
+    }
+
+    public ScmAction addFile(String path,
+                             String file,
+                             byte[] content) {
+        return new AddFile( path,
+                            file,
+                            content );
+    }
+
+    public ScmAction copyDirectory(String path,
+                                   String newPath,
+                                   long revision) {
+        return new CopyDirectory( path,
+                                  newPath,
+                                  revision );
+    }
+
+    public ScmAction copyFile(String path,
+                              String file,
+                              String newPath,
+                              String newFile,
+                              long revision) {
+        return new CopyFile( path,
+                             file,
+                             newPath,
+                             newFile,
+                             revision );
+    }
+
+    public ScmAction deleteDirectory(String path) {
+        return new DeleteDirectory( path );
+    }
+
+    public ScmAction deleteFile(String path,
+                                String file) {
+        return new DeleteFile( path,
+                               file );
+    }
+
+    public ScmAction moveDirectory(String path,
+                                   String newPath,
+                                   long revision) {
+        return new MoveDirectory( path,
+                                  newPath,
+                                  revision );
+    }
+
+    public ScmAction moveFile(String path,
+                              String file,
+                              String newPath,
+                              String newFile,
+                              long revision) {
+        return new MoveFile( path,
+                             file,
+                             newPath,
+                             newFile,
+                             revision );
+    }
+
+    public ScmAction updateFile(String path,
+                                String file,
+                                byte[] oldContent,
+                                byte[] newContent) {
+        return new UpdateFile( path,
+                               file,
+                               oldContent,
+                               newContent );
+    }
+
+    public SvnActionFactory(String url,
+                            String svnUsername,
+                            String svnPassword) throws Exception {
+        String username = svnUsername;
+        String password = svnPassword;
+        try {
+            this.repository = SVNRepositoryFactory.create( SVNURL.parseURIEncoded( url ) );
+            ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( username,
+                                                                                                  password );
+            repository.setAuthenticationManager( authManager );
+
+            SVNNodeKind nodeKind = repository.checkPath( "",
+                                                         -1 );
+            if ( nodeKind == SVNNodeKind.NONE ) {
+                SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.UNKNOWN,
+                                                              "No entry at URL ''{0}''",
+                                                              url );
+                throw new SVNException( err );
+            } else if ( nodeKind == SVNNodeKind.FILE ) {
+                SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.UNKNOWN,
+                                                              "Entry at URL ''{0}'' is a file while directory was expected",
+                                                              url );
+                throw new SVNException( err );
+            }
+        } catch ( SVNException e ) {
+            e.printStackTrace();
+            logger.error( "svn error: " );
+            throw e;
+        }
+    }
+    
+    public void getContent(String path, String file, long revision, OutputStream os) throws SVNException  {
+        this.repository.getFile( path + "/" + file, revision, null, os);
+    }
+
+    public long getLatestRevision() throws Exception {
+        try {
+            return repository.getLatestRevision();
+        } catch ( SVNException e ) {
+            e.printStackTrace();
+            logger.error( "svn error: " );
+            throw e;
+        }
+    }
+
+    public void execute(ScmAction action,
+                        String message) throws Exception {
+        try {
+            ISVNEditor editor = this.repository.getCommitEditor( message,
+                                                                 null );
+            editor.openRoot( -1 );
+            action.applyAction( editor );
+            editor.closeDir();
+
+            SVNCommitInfo info = editor.closeEdit();
+        } catch ( SVNException e ) {
+            e.printStackTrace();
+            logger.error( "svn error: " );
+            throw e;
+        }
+    }
+
+    public static class CompositeScmAction
+        implements
+        ScmAction {
+        private List actions;
+
+        public CompositeScmAction() {
+            this.actions = Collections.EMPTY_LIST;
+        }
+
+        public void addScmAction(ScmAction action) {
+            if ( actions == Collections.EMPTY_LIST ) {
+                this.actions = new ArrayList();
+            }
+            this.actions.add( action );
+        }
+
+        public void applyAction(ISVNEditor editor) throws SVNException {
+            for ( Iterator it = this.actions.iterator(); it.hasNext(); ) {
+                ScmAction action = (ScmAction) it.next();
+                action.applyAction( editor );
+            }
+        }
+    }
+
+    public static class AddFile
+        implements
+        ScmAction {
+        private String file;
+        private String path;
+        private byte[] content;
+
+        public AddFile(String path,
+                       String file,
+                       byte[] content) {
+            this.path = path;
+            this.file = file;
+            this.content = content;
+        }
+
+        public void applyAction(ISVNEditor editor) throws SVNException {
+            openDirectories( editor,
+                             path );
+
+            editor.addFile( path + "/" + file,
+                            null,
+                            -1 );
+            editor.applyTextDelta( path + "/" + file,
+                                   null );
+            SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
+            String checksum = deltaGenerator.sendDelta( path + "/" + file,
+                                                        new ByteArrayInputStream( this.content ),
+                                                        editor,
+                                                        true );
+            editor.closeFile( path + "/" + file,
+                              checksum );
+
+            closeDirectories( editor,
+                              path );
+        }
+    }
+
+    /**
+     * root should be the last, previously created, parent folder. Each directory in the path
+     * will be created.
+     *
+     */
+    public static class AddDirectory
+        implements
+        ScmAction {
+        private String root;
+        private String path;
+
+        public AddDirectory(String root,
+                            String path) {
+            this.root = root;
+            this.path = path;
+        }
+
+        public void applyAction(ISVNEditor editor) throws SVNException {
+            openDirectories( editor,
+                             this.root );
+            String[] paths = this.path.split( "/" );
+            String newPath = this.root;
+            for ( int i = 0, length = paths.length; i < length; i++ ) {
+                newPath = (newPath.length() != 0) ? newPath + "/" + paths[i] : paths[i];
+
+                editor.addDir( newPath,
+                               null,
+                               -1 );
+            }
+
+            closeDirectories( editor,
+                              path );
+            closeDirectories( editor,
+                              this.root );
+        }
+    }
+
+    public static class UpdateFile
+        implements
+        ScmAction {
+        private String file;
+        private String path;
+        private byte[] oldContent;
+        private byte[] newContent;
+
+        public UpdateFile(String path,
+                          String file,
+                          byte[] oldContent,
+                          byte[] newContent) {
+            this.path = path;
+            this.file = file;
+            this.oldContent = oldContent;
+            this.newContent = newContent;
+        }
+
+        public void applyAction(ISVNEditor editor) throws SVNException {
+            openDirectories( editor,
+                             path );
+            editor.openFile( path + "/" + file,
+                             -1 );
+
+            editor.applyTextDelta( path + "/" + file,
+                                   null );
+            SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
+            String checksum = deltaGenerator.sendDelta( path + "/" + file,
+                                                        new ByteArrayInputStream( this.oldContent ),
+                                                        0,
+                                                        new ByteArrayInputStream( this.newContent ),
+                                                        editor,
+                                                        true );
+            editor.closeFile( path + "/" + file,
+                              checksum );
+            closeDirectories( editor,
+                              path );
+        }
+    }
+
+    public static class CopyFile
+        implements
+        ScmAction {
+        private String file;
+        private String path;
+        private String newPath;
+        private String newFile;
+        private long   revision;
+
+        public CopyFile(String path,
+                        String file,
+                        String newPath,
+                        String newFile,
+                        long revision) {
+            this.path = path;
+            this.file = file;
+            this.newPath = newPath;
+            this.newFile = newFile;
+            this.revision = revision;
+        }
+
+        public void applyAction(ISVNEditor editor) throws SVNException {
+            editor.addFile( newPath + "/" + newFile,
+                            path + "/" + file,
+                            revision );
+        }
+    }
+
+    public static class CopyDirectory
+        implements
+        ScmAction {
+        private String path;
+        private String newPath;
+        private long   revision;
+
+        public CopyDirectory(String path,
+                             String newPath,
+                             long revision) {
+            this.path = path;
+            this.newPath = newPath;
+            this.revision = revision;
+        }
+
+        public void applyAction(ISVNEditor editor) throws SVNException {
+            editor.addDir( newPath,
+                           path,
+                           revision );
+            editor.closeDir();
+        }
+    }
+
+    public static class MoveFile
+        implements
+        ScmAction {
+        private String file;
+        private String path;
+        private String newPath;
+        private String newFile;
+        private long   revision;
+
+        public MoveFile(String path,
+                        String file,
+                        String newPath,
+                        String newFile,
+                        long revision) {
+            this.path = path;
+            this.file = file;
+            this.newPath = newPath;
+            this.newFile = newFile;
+            this.revision = revision;
+        }
+
+        public void applyAction(ISVNEditor editor) throws SVNException {
+            CopyFile copyFile = new CopyFile( path,
+                                              file,
+                                              newPath,
+                                              newFile,
+                                              revision );
+            DeleteFile deleteFile = new DeleteFile( path,
+                                                    file );
+
+            copyFile.applyAction( editor );
+            deleteFile.applyAction( editor );
+
+        }
+    }
+
+    public static class MoveDirectory
+        implements
+        ScmAction {
+        private String path;
+        private String newPath;
+        private long   revision;
+
+        public MoveDirectory(String path,
+                             String newPath,
+                             long revision) {
+            this.path = path;
+            this.newPath = newPath;
+            this.revision = revision;
+        }
+
+        public void applyAction(ISVNEditor editor) throws SVNException {
+            CopyDirectory copyDirectory = new CopyDirectory( path,
+                                                             newPath,
+                                                             revision );
+            DeleteDirectory deleteDirectory = new DeleteDirectory( path );
+
+            copyDirectory.applyAction( editor );
+            deleteDirectory.applyAction( editor );
+
+        }
+    }
+
+    public static class DeleteFile
+        implements
+        ScmAction {
+        private String path;
+        private String file;
+
+        public DeleteFile(String path,
+                          String file) {
+            this.path = path;
+            this.file = file;
+        }
+
+        public void applyAction(ISVNEditor editor) throws SVNException {
+            openDirectories( editor,
+                             path );
+            editor.deleteEntry( path + "/" + file,
+                                -1 );
+            closeDirectories( editor,
+                              path );
+        }
+    }
+
+    public static class DeleteDirectory
+        implements
+        ScmAction {
+        private String path;
+
+        public DeleteDirectory(String path) {
+            this.path = path;
+        }
+
+        public void applyAction(ISVNEditor editor) throws SVNException {
+            openDirectories( editor,
+                             path );
+            editor.deleteEntry( path,
+                                -1 );
+            closeDirectories( editor,
+                              path );
+        }
+    }
+
+    public static class CommitMediator
+        implements
+        ISVNWorkspaceMediator {
+        private Map myTmpStorages = new HashMap();
+
+        /*
+         * This may be implemented to get properties from 
+         * '.svn/wcprops'
+         */
+        public String getWorkspaceProperty(String path,
+                                           String name) throws SVNException {
+            return null;
+        }
+
+        /*
+         * This may be implemented to set properties in 
+         * '.svn/wcprops'
+         */
+        public void setWorkspaceProperty(String path,
+                                         String name,
+                                         String value) throws SVNException {
+        }
+
+        /*
+         * Creates a temporary file delta  storage. id  will be  
+         * used as the temporary storage identifier. Returns an  
+         * OutputStream to write the delta data into the temporary 
+         * storage.
+         */
+        public OutputStream createTemporaryLocation(String path,
+                                                    Object id) throws IOException {
+            ByteArrayOutputStream tempStorageOS = new ByteArrayOutputStream();
+            myTmpStorages.put( id,
+                               tempStorageOS );
+            return tempStorageOS;
+        }
+
+        /*
+         * Returns an InputStream of the temporary file delta 
+         * storage identified by id to read the delta.
+         */
+        public InputStream getTemporaryLocation(Object id) throws IOException {
+            return new ByteArrayInputStream( ((ByteArrayOutputStream) myTmpStorages.get( id )).toByteArray() );
+        }
+
+        /*
+         * Gets the length of the delta that was written  
+         * to the temporary storage identified by id.
+         */
+        public long getLength(Object id) throws IOException {
+            ByteArrayOutputStream tempStorageOS = (ByteArrayOutputStream) myTmpStorages.get( id );
+            if ( tempStorageOS != null ) {
+                return tempStorageOS.size();
+            }
+            return 0;
+        }
+
+        /*
+         * Deletes the temporary file delta storage identified 
+         * by id.
+         */
+        public void deleteTemporaryLocation(Object id) {
+            myTmpStorages.remove( id );
+        }
+    }
+
+    public static void openDirectories(ISVNEditor editor,
+                                       String path) throws SVNException {
+        int pos = path.indexOf( '/',
+                                0 );
+        while ( pos != -1 ) {
+            editor.openDir( path.substring( 0,
+                                            pos ),
+                            -1 );
+            pos = path.indexOf( '/',
+                                pos + 1 );
+        }
+        editor.openDir( path.substring( 0,
+                                        path.length() ),
+                        -1 );
+    }
+
+    public static void closeDirectories(ISVNEditor editor,
+                                        String path) throws SVNException {
+        int length = path.length() - 1;
+        int pos = path.lastIndexOf( '/',
+                                    length );
+        editor.closeDir();
+        while ( pos != -1 ) {
+            editor.closeDir();
+            pos = path.lastIndexOf( '/',
+                                    pos - 1 );
+        }
+    }
+
+    public List listEntries(String path) throws SVNException {
+        List entries = new ArrayList();
+        listEntries( path,
+                     entries );
+        return entries;
+    }
+
+    public void listEntries(String path,
+                            List list) throws SVNException {
+        Collection entries = this.repository.getDir( path,
+                                                     -1,
+                                                     null,
+                                                     (Collection) null );
+        Iterator iterator = entries.iterator();
+        while ( iterator.hasNext() ) {
+            SVNDirEntry svnEntry = (SVNDirEntry) iterator.next();
+
+            DefaultScmEntry scmEntry = new DefaultScmEntry();
+            scmEntry.setPath( path.equals( "" ) ? path : path.substring( 1 ) );
+            scmEntry.setName( svnEntry.getName() );
+            scmEntry.setAuthor( svnEntry.getAuthor() );
+            scmEntry.setDate( svnEntry.getDate() );
+            scmEntry.setRevision( svnEntry.getRevision() );
+            scmEntry.setSize( svnEntry.getSize() );
+            scmEntry.setType( (svnEntry.getKind() == SVNNodeKind.DIR) ? ScmEntry.DIRECTORY : ScmEntry.FILE );
+            list.add( scmEntry );
+
+            if ( svnEntry.getKind() == SVNNodeKind.DIR ) {
+                listEntries( path + "/" + svnEntry.getName(),
+                             list );
+            }
+        }
+    }
+
+}

Added: labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/scm/svn/SvnActionFactoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/scm/svn/SvnActionFactoryTest.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/scm/svn/SvnActionFactoryTest.java	2007-02-02 01:21:21 UTC (rev 9277)
@@ -0,0 +1,620 @@
+package org.drools.scm.svn;
+
+import java.io.ByteArrayInputStream;
+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.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+import org.drools.scm.DefaultScmEntry;
+import org.drools.scm.ScmAction;
+import org.drools.scm.ScmActionFactory;
+import org.drools.scm.ScmEntry;
+import org.drools.scm.svn.SvnActionFactory.AddDirectory;
+import org.drools.scm.svn.SvnActionFactory.AddFile;
+import org.drools.scm.svn.SvnActionFactory.CopyDirectory;
+import org.drools.scm.svn.SvnActionFactory.CopyFile;
+import org.drools.scm.svn.SvnActionFactory.DeleteDirectory;
+import org.drools.scm.svn.SvnActionFactory.DeleteFile;
+import org.drools.scm.svn.SvnActionFactory.MoveDirectory;
+import org.drools.scm.svn.SvnActionFactory.MoveFile;
+import org.drools.scm.svn.SvnActionFactory.UpdateFile;
+import org.tmatesoft.svn.core.SVNDirEntry;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.SVNNodeKind;
+import org.tmatesoft.svn.core.io.SVNRepository;
+
+public class SvnActionFactoryTest extends TestCase {
+
+    private static Logger logger = Logger.getLogger( SvnActionFactoryTest.class );
+
+    private static String svnUrl;
+
+    public void setUp() throws IOException {
+        // First we need to find the absolute path
+        URL url = getClass().getResource( "/svn_repo_empty" );
+
+        assertNotNull( url );
+        File src = new File( url.getFile() );
+        File dst = new File( src.getParent(),
+                             "/copy_svn_repo_empty" );
+
+        // make sure the destination is empty before we copy
+        delete( dst );
+
+        copy( src,
+              dst );
+
+        // Now set the two path roots
+        svnUrl = "file:///" + dst.getAbsolutePath().replaceAll( "\\\\",
+                                                                "/" );
+    }
+
+    public void tearDown() throws Exception {
+        URL url = getClass().getResource( "/copy_svn_repo_empty" );
+        delete( new File( url.getFile() ) );
+    }
+
+    public void testCannotAddFolderWithNoParent() throws Exception {
+        ScmActionFactory svn = new SvnActionFactory( svnUrl,
+                                                     "mrtrout",
+                                                     "drools" );
+
+        CompositeSvnAction actions = new CompositeSvnAction();
+
+        try {
+            ScmAction addFolder = new AddDirectory( "folder1",
+                                                    "folder1_1" );
+            actions.addScmAction( addFolder );
+            svn.execute( actions,
+                         "test message" );
+            fail( "This should fail as 'folder1' has not yet been created" );
+        } catch ( Exception e ) {
+
+        }
+    }
+
+    public void testCannotAddDuplicateDirectories() throws Exception {
+        ScmActionFactory svn = new SvnActionFactory( svnUrl,
+                                                     "mrtrout",
+                                                     "drools" );
+
+        CompositeSvnAction actions = new CompositeSvnAction();
+
+        // Correctly add a new directory at root
+        actions = new CompositeSvnAction();
+        ScmAction addFolder = new AddDirectory( "",
+                                                "folder1" );
+        actions.addScmAction( addFolder );
+
+        svn.execute( actions,
+                     "test message" );
+
+        // Check we can't add duplicate folders
+        try {
+            actions = new CompositeSvnAction();
+            addFolder = new AddDirectory( "",
+                                          "folder1" );
+            actions.addScmAction( addFolder );
+            svn.execute( actions,
+                         "test message" );
+            fail( "This should fail as 'folder1' already exists" );
+        } catch ( Exception e ) {
+
+        }
+    }
+
+    public void testAddFolders() throws Exception {
+        ScmActionFactory svn = new SvnActionFactory( svnUrl,
+                                                     "mrtrout",
+                                                     "drools" );
+
+        CompositeSvnAction actions = new CompositeSvnAction();
+
+        // Correctly add a new folder at root
+        actions = new CompositeSvnAction();
+        ScmAction addFolder = new AddDirectory( "",
+                                                "folder1" );
+        actions.addScmAction( addFolder );
+
+        svn.execute( actions,
+                     "test message" );
+
+        // Now check various flat and deep folder creations
+        actions = new CompositeSvnAction();
+
+        addFolder = new AddDirectory( "folder1",
+                                      "folder1_1" );
+        actions.addScmAction( addFolder );
+
+        addFolder = new AddDirectory( "folder1/folder1_1",
+                                      "folder1_1_1" );
+        actions.addScmAction( addFolder );
+
+        addFolder = new AddDirectory( "folder1",
+                                      "folder1_2" );
+        actions.addScmAction( addFolder );
+
+        addFolder = new AddDirectory( "",
+                                      "folder2/folder2_1" );
+        actions.addScmAction( addFolder );
+
+        addFolder = new AddDirectory( "",
+                                      "folder3/folder3_1/folder3_1_1/folder3_1_1_1" );
+        actions.addScmAction( addFolder );
+
+        svn.execute( actions,
+                     "test message" );
+        //------
+        // Now test results
+        //-------                
+        List list = convertToStringList( svn.listEntries( "" ) );
+
+        assertTrue( list.contains( "folder1" ) );
+        assertTrue( list.contains( "folder1/folder1_1" ) );
+        assertTrue( list.contains( "folder1/folder1_2" ) );
+        assertTrue( list.contains( "folder2/folder2_1" ) );
+        assertTrue( list.contains( "folder3/folder3_1/folder3_1_1/folder3_1_1_1" ) );
+
+    }
+
+    public void testAddFiles() throws Exception {
+        ScmActionFactory svn = new SvnActionFactory( svnUrl,
+                                                     "mrtrout",
+                                                     "drools" );
+
+        CompositeSvnAction actions = new CompositeSvnAction();
+
+        ScmAction addFolder = new AddDirectory( "",
+                                                "folder1" );
+        actions.addScmAction( addFolder );
+
+        ScmAction addFile = new AddFile( "folder1",
+                                         "file1.dat",
+                                         new byte[]{1, 1, 1, 1} );
+        actions.addScmAction( addFile );
+
+        addFolder = new AddDirectory( "folder1",
+                                      "folder1_1" );
+        actions.addScmAction( addFolder );
+
+        addFile = new AddFile( "folder1/folder1_1",
+                               "file1_1.dat",
+                               new byte[]{0, 0, 0, 0} );
+        actions.addScmAction( addFile );
+
+        svn.execute( actions,
+                     "test message" );
+        
+        // Check the contents are correct
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        svn.getContent( "folder1", "file1.dat", -1, baos );
+        assertTrue( Arrays.equals( new byte[]{1, 1, 1, 1}, baos.toByteArray() ) );
+        
+        baos = new ByteArrayOutputStream();
+        svn.getContent( "folder1/folder1_1", "file1_1.dat", -1, baos );
+        assertTrue( Arrays.equals( new byte[]{0, 0, 0, 0}, baos.toByteArray() ) );
+              
+        // Check the directories are correctly created
+        List list = convertToStringList( svn.listEntries( "" ) );
+        assertTrue( list.contains( "folder1" ) );
+        assertTrue( list.contains( "folder1/file1.dat" ) );
+        assertTrue( list.contains( "folder1/folder1_1" ) );
+        assertTrue( list.contains( "folder1/folder1_1/file1_1.dat" ) );
+    }
+
+    public void testUpdateFile() throws Exception {
+        ScmActionFactory svn = new SvnActionFactory( svnUrl,
+                                                     "mrtrout",
+                                                     "drools" );
+
+        CompositeSvnAction actions = new CompositeSvnAction();
+
+        ScmAction addFolder = new AddDirectory( "",
+                                                "folder1" );
+        actions.addScmAction( addFolder );
+
+        byte[] oldContent = new byte[]{1, 1, 1, 1};
+        byte[] newContent = new byte[]{1, 0, 1, 0};
+        
+        // Add the initial file
+        ScmAction addFile = new AddFile( "folder1",
+                                         "file1.dat",
+                                         oldContent );                
+        actions.addScmAction( addFile );
+        svn.execute( actions,
+                     "test message" );
+        
+        // Check the contents are correct
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        svn.getContent( "folder1", "file1.dat", -1, baos );
+        assertTrue( Arrays.equals( oldContent, baos.toByteArray() ) );
+
+        // Update the existing file
+        actions = new CompositeSvnAction();
+        ScmAction updateFile = new UpdateFile( "folder1",
+                                               "file1.dat",
+                                               oldContent,
+                                               newContent );
+        actions.addScmAction( updateFile );
+        svn.execute( actions,
+                     "test message" );
+        
+        // Check the contents are correct
+        baos = new ByteArrayOutputStream();
+        svn.getContent( "folder1", "file1.dat", -1, baos );
+        assertTrue( Arrays.equals( newContent, baos.toByteArray() ) );
+
+        // Check the correct directory structue was created
+        List list = convertToStringList( svn.listEntries( "" ) );
+        assertTrue( list.contains( "folder1" ) );
+        assertTrue( list.contains( "folder1/file1.dat" ) );
+    }
+
+    public void testCopyFile() throws Exception {
+        ScmActionFactory svn = new SvnActionFactory( svnUrl,
+                                                     "mrtrout",
+                                                     "drools" );
+
+        CompositeSvnAction actions = new CompositeSvnAction();
+
+        ScmAction addFolder = new AddDirectory( "",
+                                                "folder1" );
+        actions.addScmAction( addFolder );
+        byte[] content = new byte[]{1, 1, 1, 1};
+        ScmAction addFile = new AddFile( "folder1",
+                                         "file1.dat",
+                                         content );
+        actions.addScmAction( addFile );
+        svn.execute( actions,
+                     "test message" );
+        
+        // Check the contents are correct
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        svn.getContent( "folder1", "file1.dat", -1, baos );
+        assertTrue( Arrays.equals( content, baos.toByteArray() ) );
+        
+        List list = convertToStringList( svn.listEntries( "" ) );
+        assertTrue( list.contains( "folder1" ) );
+        assertTrue( list.contains( "folder1/file1.dat" ) );
+        assertFalse( list.contains( "folder2/file2.dat" ) );
+        
+        // Now copy the file
+        actions = new CompositeSvnAction();
+        addFolder = new AddDirectory( "",
+                                      "folder2" );
+        actions.addScmAction( addFolder );
+        ScmAction copyFile = new CopyFile( "folder1",
+                                           "file1.dat",
+                                           "folder2",
+                                           "file2.dat",
+                                           svn.getLatestRevision() );
+        actions.addScmAction( copyFile );
+        svn.execute( actions,
+                     "test message" );             
+        
+        baos = new ByteArrayOutputStream();
+        svn.getContent( "folder2", "file2.dat", -1, baos );
+        assertTrue( Arrays.equals( content, baos.toByteArray() ) );
+        
+        list = convertToStringList( svn.listEntries( "" ) );
+        assertTrue( list.contains( "folder1" ) );
+        assertTrue( list.contains( "folder1/file1.dat" ) );
+        assertTrue( list.contains( "folder2/file2.dat" ) );
+    }
+
+    public void testCopyDirectory() throws Exception {
+        ScmActionFactory svn = new SvnActionFactory( svnUrl,
+                                                     "mrtrout",
+                                                     "drools" );
+
+        CompositeSvnAction actions = new CompositeSvnAction();
+
+        ScmAction addFolder = new AddDirectory( "",
+                                                "folder1" );
+        actions.addScmAction( addFolder );
+        byte[] content1 = new byte[]{1, 1, 1, 1};
+        ScmAction addFile = new AddFile( "folder1",
+                                         "file1.dat",
+                                         content1 );
+        actions.addScmAction( addFile );
+
+        addFolder = new AddDirectory( "folder1",
+                                      "folder1_1" );
+        actions.addScmAction( addFolder );
+        byte[] content2 = new byte[]{1, 0, 0, 1};
+        addFile = new AddFile( "folder1/folder1_1",
+                               "file1.dat",
+                               content2 );
+        actions.addScmAction( addFile );
+        svn.execute( actions,
+                     "test message" );
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        svn.getContent( "folder1", "file1.dat", -1, baos );
+        assertTrue( Arrays.equals( content1, baos.toByteArray() ) );
+        baos = new ByteArrayOutputStream();
+        svn.getContent( "folder1/folder1_1", "file1.dat", -1, baos );
+        assertTrue( Arrays.equals( content2, baos.toByteArray() ) );        
+        
+        List list = convertToStringList( svn.listEntries( "" ) );
+        assertTrue( list.contains( "folder1" ) );
+        assertTrue( list.contains( "folder1/folder1_1/file1.dat" ) );
+        assertFalse( list.contains( "folder2/folder1/file1.dat" ) );        
+
+        // Now copy the directory
+        actions = new CompositeSvnAction();
+        addFolder = new AddDirectory( "",
+                                      "folder2" );
+        actions.addScmAction( addFolder );
+        ScmAction copyDirectory = new CopyDirectory( "folder1",
+                                                     "folder2/folder1",
+                                                     svn.getLatestRevision() );
+        actions.addScmAction( copyDirectory );
+        svn.execute( actions,
+                     "test message" );
+        
+        baos = new ByteArrayOutputStream();
+        svn.getContent( "folder1", "file1.dat", -1, baos );
+        assertTrue( Arrays.equals( content1, baos.toByteArray() ) );
+        baos = new ByteArrayOutputStream();
+        svn.getContent( "folder1/folder1_1", "file1.dat", -1, baos );
+        assertTrue( Arrays.equals( content2, baos.toByteArray() ) );        
+        baos = new ByteArrayOutputStream();
+        svn.getContent( "folder2/folder1", "file1.dat", -1, baos );
+        assertTrue( Arrays.equals( content1, baos.toByteArray() ) );
+        baos = new ByteArrayOutputStream();
+        svn.getContent( "folder2/folder1/folder1_1", "file1.dat", -1, baos );
+        assertTrue( Arrays.equals( content2, baos.toByteArray() ) ); 
+        
+        list = convertToStringList( svn.listEntries( "" ) );
+        assertTrue( list.contains( "folder1" ) );
+        assertTrue( list.contains( "folder1/folder1_1/file1.dat" ) );
+        assertTrue( list.contains( "folder2/folder1/file1.dat" ) );
+    }
+
+    public void testMoveFile() throws Exception {
+        ScmActionFactory svn = new SvnActionFactory( svnUrl,
+                                                     "mrtrout",
+                                                     "drools" );
+
+        CompositeSvnAction actions = new CompositeSvnAction();
+
+        ScmAction addFolder = new AddDirectory( "",
+                                                "folder1" );
+        actions.addScmAction( addFolder );
+        byte[] content = new byte[]{1, 1, 1, 1};
+        ScmAction addFile = new AddFile( "folder1",
+                                         "file1.dat",
+                                         content );
+        actions.addScmAction( addFile );
+        svn.execute( actions,
+                     "test message" );
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        svn.getContent( "folder1", "file1.dat", -1, baos );
+        assertTrue( Arrays.equals( content, baos.toByteArray() ) );    
+        
+        List list = convertToStringList( svn.listEntries( "" ) );
+        assertTrue( list.contains( "folder1" ) );
+        assertTrue( list.contains( "folder1/file1.dat" ) );
+        assertFalse( list.contains( "folder2/file2.dat" ) );
+        
+        // No do the file move
+        actions = new CompositeSvnAction();
+        addFolder = new AddDirectory( "",
+                                      "folder2" );
+        actions.addScmAction( addFolder );
+        MoveFile moveFile = new MoveFile( "folder1",
+                                          "file1.dat",
+                                          "folder2",
+                                          "file2.dat",
+                                          svn.getLatestRevision() );
+        actions.addScmAction( moveFile );
+        svn.execute( actions,
+                     "test message" );
+        
+        baos = new ByteArrayOutputStream();
+        svn.getContent( "folder2", "file2.dat", -1, baos );
+        assertTrue( Arrays.equals( content, baos.toByteArray() ) );          
+        
+        list = convertToStringList( svn.listEntries( "" ) );
+        assertTrue( list.contains( "folder1" ) );
+        assertFalse( list.contains( "folder1/file1.dat" ) );
+        assertTrue( list.contains( "folder2/file2.dat" ) );
+    }   
+
+    public void testMoveDirectory() throws Exception {
+        ScmActionFactory svn = new SvnActionFactory( svnUrl,
+                                                     "mrtrout",
+                                                     "drools" );
+
+        CompositeSvnAction actions = new CompositeSvnAction();
+
+        ScmAction addFolder = new AddDirectory( "",
+                                                "folder1" );
+        actions.addScmAction( addFolder );
+        byte[] content = new byte[]{1, 1, 1, 1};
+        ScmAction addFile = new AddFile( "folder1",
+                                         "file1.dat",
+                                         content );
+        actions.addScmAction( addFile );
+        svn.execute( actions,
+                     "test message" );
+
+        // check the intial content and dir structure
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        svn.getContent( "folder1", "file1.dat", -1, baos );
+        assertTrue( Arrays.equals( content, baos.toByteArray() ) );       
+        
+        actions = new CompositeSvnAction();
+        MoveDirectory moveDirectory = new MoveDirectory( "folder1",
+                                                         "folder2",
+                                                         svn.getLatestRevision() );
+        actions.addScmAction( moveDirectory );
+        svn.execute( actions,
+                     "test message" );
+        
+        // Check the moved content and dir structure
+        baos = new ByteArrayOutputStream();
+        svn.getContent( "folder2", "file1.dat", -1, baos );
+        assertTrue( Arrays.equals( content, baos.toByteArray() ) ); 
+                
+        List list = convertToStringList( svn.listEntries( "" ) );
+
+        assertFalse( list.contains( "folder1" ) );
+        assertFalse( list.contains( "folder1/file1.dat" ) );
+        assertTrue( list.contains( "folder2/file1.dat" ) );
+    }
+
+    public void testDeleteFile() throws Exception {
+        ScmActionFactory svn = new SvnActionFactory( svnUrl,
+                                                     "mrtrout",
+                                                     "drools" );
+
+        CompositeSvnAction actions = new CompositeSvnAction();
+
+        ScmAction addFolder = new AddDirectory( "",
+                                                "folder1" );
+        actions.addScmAction( addFolder );
+        byte[] content = new byte[]{1, 1, 1, 1};
+        ScmAction addFile = new AddFile( "folder1",
+                                         "file1.dat",
+                                         content );
+        actions.addScmAction( addFile );
+        svn.execute( actions,
+                     "test message" );       
+        List list = convertToStringList( svn.listEntries( "" ) );
+        assertTrue( list.contains( "folder1" ) );
+        assertTrue( list.contains( "folder1/file1.dat" ) );        
+
+        // Now do the file delete
+        actions = new CompositeSvnAction();
+        ScmAction deleteFile = new DeleteFile( "folder1",
+                                               "file1.dat" );
+        actions.addScmAction( deleteFile );
+        svn.execute( actions,
+                     "test message" );            
+        list = convertToStringList( svn.listEntries( "" ) );
+        assertTrue( list.contains( "folder1" ) );
+        assertFalse( list.contains( "folder1/file1.dat" ) );
+    }
+
+    public void testDeleteDirectory() throws Exception {
+        ScmActionFactory svn = new SvnActionFactory( svnUrl,
+                                                     "mrtrout",
+                                                     "drools" );
+
+        CompositeSvnAction actions = new CompositeSvnAction();
+
+        ScmAction addFolder = new AddDirectory( "",
+                                                "folder1" );
+        actions.addScmAction( addFolder );
+        byte[] content = new byte[]{1, 1, 1, 1};
+        ScmAction addFile = new AddFile( "folder1",
+                                         "file1.dat",
+                                         content );
+        actions.addScmAction( addFile );        
+        addFolder = new AddDirectory( "",
+                                      "folder2" );
+        actions.addScmAction( addFolder );
+        svn.execute( actions,
+                     "test message" );
+        List list = convertToStringList( svn.listEntries( "" ) );
+        assertTrue( list.contains( "folder1" ) );
+        assertTrue( list.contains( "folder1/file1.dat" ) );
+        assertTrue( list.contains( "folder2" ) );
+        
+        // now do the directory delete        
+        actions = new CompositeSvnAction();
+        ScmAction deleteDirectory = new DeleteDirectory( "folder1" );
+        actions.addScmAction( deleteDirectory );
+        svn.execute( actions,
+                     "test message" );
+        list = convertToStringList( svn.listEntries( "" ) );        
+        assertFalse( list.contains( "folder1" ) );
+        assertFalse( list.contains( "folder1/file1.dat" ) );
+        assertTrue( list.contains( "folder2" ) );
+    }
+
+    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() + "\\" + list[i];
+                String src1 = src.getPath() + "\\" + 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() + "\\" + list[i];
+                delete( new File( src1 ) );
+            }
+            src.delete();
+        } else {
+            src.delete();
+        }
+    }
+
+    public static List convertToStringList(List list) {
+        List files = new ArrayList( list.size() );
+
+        for ( Iterator it = list.iterator(); it.hasNext(); ) {
+            ScmEntry entry = (ScmEntry) it.next();
+            files.add( entry.getPath().equals( "" ) ? entry.getName() : entry.getPath() + "/" + entry.getName() );
+        }
+        return files;
+    }
+
+    public static Map convertToMap(List list) {
+        Map map = new HashMap( list.size() );
+
+        for ( Iterator it = list.iterator(); it.hasNext(); ) {
+            ScmEntry entry = (ScmEntry) it.next();
+            if ( entry.isDirectory() ) {
+                map.put( entry.getPath().equals( "" ) ? entry.getName() : entry.getPath() + "/" + entry.getName(),
+                         entry );
+            } else {
+                List files = (List) map.get( entry.getPath() );
+                if ( files == null ) {
+                    files = new ArrayList();
+                    map.put( entry.getPath(),
+                             files );
+                }
+
+                files.add( entry );
+            }
+        }
+        return map;
+    }
+}




More information about the jboss-svn-commits mailing list