[jboss-svn-commits] JBL Code SVN: r9439 - in labs/jbossrules/trunk/drools-repository/src: main/java/org/drools/scm/jcr and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Feb 11 19:35:41 EST 2007
Author: mark.proctor at jboss.com
Date: 2007-02-11 19:35:41 -0500 (Sun, 11 Feb 2007)
New Revision: 9439
Added:
labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/jcr/
labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/jcr/CompositeJcrAction.java
labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/jcr/JcrActionFactory.java
labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/log/
labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/log/ScmLogEntry.java
labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/log/ScmLogEntryItem.java
labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/scm/svn/SvnLogTest.java
Modified:
labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmAction.java
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/SvnActionFactoryTest.java
Log:
-more svn/jcr sync work
Modified: 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 2007-02-11 19:46:00 UTC (rev 9438)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/ScmAction.java 2007-02-12 00:35:41 UTC (rev 9439)
@@ -7,5 +7,5 @@
import org.tmatesoft.svn.core.io.ISVNEditor;
public interface ScmAction {
- public void applyAction(ISVNEditor editor) throws SVNException;
+ public void applyAction(Object context) throws SVNException;
}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/jcr/CompositeJcrAction.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/jcr/CompositeJcrAction.java (rev 0)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/jcr/CompositeJcrAction.java 2007-02-12 00:35:41 UTC (rev 9439)
@@ -0,0 +1,38 @@
+/**
+ *
+ */
+package org.drools.scm.jcr;
+
+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 CompositeJcrAction
+ implements
+ ScmAction {
+ private List actions;
+
+ public CompositeJcrAction() {
+ 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(Object context) throws SVNException {
+// ISVNEditor editor = ( ISVNEditor ) context;
+ 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/jcr/JcrActionFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/jcr/JcrActionFactory.java (rev 0)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/jcr/JcrActionFactory.java 2007-02-12 00:35:41 UTC (rev 9439)
@@ -0,0 +1,176 @@
+package org.drools.scm.jcr;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.util.Iterator;
+import java.util.List;
+
+import org.drools.scm.ScmAction;
+import org.drools.scm.ScmActionFactory;
+import org.drools.scm.log.ScmLogEntry;
+import org.drools.scm.log.ScmLogEntryItem;
+import org.drools.scm.log.ScmLogEntry.Add;
+import org.drools.scm.log.ScmLogEntry.Copy;
+import org.drools.scm.log.ScmLogEntry.Delete;
+import org.drools.scm.log.ScmLogEntry.Update;
+
+public class JcrActionFactory
+ implements
+ ScmActionFactory {
+
+ public ScmAction addDirectory(String root,
+ String path) {
+ return null;
+ }
+
+ public ScmAction addFile(String path,
+ String file,
+ byte[] content) {
+ return null;
+ }
+
+ public ScmAction copyDirectory(String path,
+ String newPath,
+ long revision) {
+ return null;
+ }
+
+ public ScmAction copyFile(String path,
+ String file,
+ String newPath,
+ String newFile,
+ long revision) {
+ return null;
+ }
+
+ public ScmAction deleteDirectory(String path) {
+ return null;
+ }
+
+ public ScmAction deleteFile(String path,
+ String file) {
+ return null;
+ }
+
+ public void execute(ScmAction action,
+ String message) throws Exception {
+ }
+
+ public void getContent(String path,
+ String file,
+ long revision,
+ OutputStream os) throws Exception {
+ }
+
+ public long getLatestRevision() throws Exception {
+ return 0;
+ }
+
+ public List listEntries(String path) throws Exception {
+ return null;
+ }
+
+ public void listEntries(String path,
+ List list) throws Exception {
+ }
+
+ public ScmAction moveDirectory(String path,
+ String newPath,
+ long revision) {
+ return null;
+ }
+
+ public ScmAction moveFile(String path,
+ String file,
+ String newPath,
+ String newFile,
+ long revision) {
+ return null;
+ }
+
+ public ScmAction updateFile(String path,
+ String file,
+ byte[] oldContent,
+ byte[] newContent) {
+ return null;
+ }
+
+ public void syncToScmLog(List list, ScmActionFactory factory) throws Exception {
+ for ( Iterator it = list.iterator(); it.hasNext(); ) {
+ ScmLogEntry entry = (ScmLogEntry) it.next();
+ for ( Iterator it2 = entry.getAction().iterator(); it.hasNext(); ) {
+ ScmLogEntryItem item = (ScmLogEntryItem) it2.next();
+ ScmAction action;
+ switch ( item.getActionType() ) {
+ case 'A': {
+ Add add = (Add) item;
+ if ( add.getPathType() == 'D' ) {
+ addDirectory( "", add.getPath() );
+ } else {
+ int lastSlash = add.getPath().lastIndexOf( '/' );
+ String path = add.getPath().substring( 0, lastSlash - 1 );
+ String file = add.getPath().substring( lastSlash + 1, add.getPath().length() -1 );
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ factory.getContent( path, file, -1, bos );
+ action = addFile(path, file, bos.toByteArray() );
+ }
+ break;
+ }
+ case 'C': {
+ Copy copy = (Copy) item;
+ if ( copy.getPathType() == 'D' ) {
+ action =copyDirectory( copy.getFromPath(), copy.getToPath(), copy.getFromRevision() );
+ } else {
+ int lastSlash = copy.getFromPath().lastIndexOf( '/' );
+ String fromPath = copy.getFromPath().substring( 0, lastSlash - 1 );
+ String fromFile = copy.getFromPath().substring( lastSlash + 1, copy.getFromPath().length() -1 );
+
+ lastSlash = copy.getToPath().lastIndexOf( '/' );
+ String toPath = copy.getToPath().substring( 0, lastSlash - 1 );
+ String toFile = copy.getToPath().substring( lastSlash + 1, copy.getToPath().length() -1 );
+ action = copyFile( fromPath, fromFile, toPath, toFile, copy.getFromRevision() );
+ }
+
+ break;
+ }
+ case 'D': {
+ Delete delete = (Delete) item;
+ if ( delete.getPathType() == 'D' ) {
+ action = deleteDirectory( delete.getPath() );
+ } else {
+ int lastSlash = delete.getPath().lastIndexOf( '/' );
+ String path = delete.getPath().substring( 0, lastSlash - 1 );
+ String file = delete.getPath().substring( lastSlash + 1, delete.getPath().length() -1 );
+
+ action = deleteFile( path, file );
+ }
+ break;
+ }
+ case 'U':
+ // Can only be a file
+ Update update = (Update) item;
+ int lastSlash = update.getPath().lastIndexOf( '/' );
+ String path = update.getPath().substring( 0, lastSlash - 1 );
+ String file = update.getPath().substring( lastSlash + 1, update.getPath().length() -1 );
+
+ ByteArrayOutputStream bosOriginal = new ByteArrayOutputStream();
+ getContent( path, file, -1, bosOriginal );
+
+ ByteArrayOutputStream bosNew = new ByteArrayOutputStream();
+ factory.getContent( path, file, update.getRevision(), bosNew );
+
+ action = updateFile( path, file, bosOriginal.toByteArray(), bosNew.toByteArray() );
+
+ break;
+ case 'R':
+ // @TODO this is a delete and add
+ break;
+ }
+
+
+ }
+ }
+ }
+
+}
Added: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/log/ScmLogEntry.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/log/ScmLogEntry.java (rev 0)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/log/ScmLogEntry.java 2007-02-12 00:35:41 UTC (rev 9439)
@@ -0,0 +1,230 @@
+package org.drools.scm.log;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+public class ScmLogEntry {
+ private String author;
+ private Date date;
+ private String message;
+ private List list;
+
+ public ScmLogEntry(String author,
+ Date date,
+ String message) {
+ super();
+ this.author = author;
+ this.date = date;
+ this.message = message;
+ this.list = new ArrayList();
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void addAction(ScmLogEntryItem item) {
+ this.list.add( item );
+ }
+
+ public List getAction() {
+ return this.list;
+ }
+
+
+
+ public static class Add implements ScmLogEntryItem {
+ private char actionType = 'A';
+ private char pathType;
+ private String path;
+ private long revision;
+
+ public Add(char type,
+ String path,
+ long revision) {
+ super();
+ this.pathType = type;
+ this.path = path;
+ this.revision = revision;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public long getRevision() {
+ return revision;
+ }
+
+ public char getPathType() {
+ return pathType;
+ }
+
+ public char getActionType() {
+ return this.actionType;
+ }
+ }
+
+ public static class Delete implements ScmLogEntryItem {
+ private char actionType = 'D';
+ private char pathType;
+ private String path;
+ private long revision;
+
+ public Delete(char type,
+ String path,
+ long revision) {
+ super();
+ this.pathType = type;
+ this.path = path;
+ this.revision = revision;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public long getRevision() {
+ return revision;
+ }
+
+ public char getPathType() {
+ return pathType;
+ }
+
+ public char getActionType() {
+ return this.actionType;
+ }
+ }
+
+ public static class Copy implements ScmLogEntryItem {
+ private char actionType = 'C';
+ private char pathType;
+ private String fromPath;
+ private long fromRevision;
+ private String toPath;
+ private long toRevision;
+
+ public Copy(char type,
+ String fromPath,
+ long fromRevision,
+ String toPath,
+ long toRevision) {
+ super();
+ this.pathType = type;
+ this.fromPath = fromPath;
+ this.fromRevision = fromRevision;
+ this.toPath = toPath;
+ this.toRevision = toRevision;
+ }
+
+ public String getFromPath() {
+ return fromPath;
+ }
+
+ public long getFromRevision() {
+ return fromRevision;
+ }
+
+ public String getToPath() {
+ return toPath;
+ }
+
+ public long gettoRevision() {
+ return toRevision;
+ }
+
+ public char getPathType() {
+ return pathType;
+ }
+
+ public char getActionType() {
+ return this.actionType;
+ }
+
+ }
+
+ /**
+ *
+ * @author mproctor
+ *
+ */
+ public static class Update implements ScmLogEntryItem {
+ private char actionType = 'U';
+ private char pathType;
+ private String path;
+ private long revision;
+
+ public Update(char type,
+ String path,
+ long revision) {
+ super();
+ this.pathType = type;
+ this.path = path;
+ this.revision = revision;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public long getRevision() {
+ return revision;
+ }
+
+ public char getPathType() {
+ return pathType;
+ }
+
+ public char getActionType() {
+ return this.actionType;
+ }
+ }
+
+ /**
+ * The Entry has been deleted and another of the same path added in the same transaction.
+ * @author mproctor
+ *
+ */
+ public static class Replaced implements ScmLogEntryItem {
+ private char actionType = 'R';
+ private char pathType;
+ private String path;
+ private long revision;
+
+ public Replaced(char type,
+ String path,
+ long revision) {
+ super();
+ this.pathType = type;
+ this.path = path;
+ this.revision = revision;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public long getRevision() {
+ return revision;
+ }
+
+ public char getPathType() {
+ return pathType;
+ }
+
+ public char getActionType() {
+ return this.actionType;
+ }
+ }
+
+}
Added: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/log/ScmLogEntryItem.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/log/ScmLogEntryItem.java (rev 0)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/log/ScmLogEntryItem.java 2007-02-12 00:35:41 UTC (rev 9439)
@@ -0,0 +1,9 @@
+/**
+ *
+ */
+package org.drools.scm.log;
+
+public interface ScmLogEntryItem {
+ public char getPathType();
+ public char getActionType();
+}
\ No newline at end of file
Modified: 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 2007-02-11 19:46:00 UTC (rev 9438)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/svn/CompositeSvnAction.java 2007-02-12 00:35:41 UTC (rev 9439)
@@ -28,7 +28,8 @@
this.actions.add( action );
}
- public void applyAction(ISVNEditor editor) throws SVNException {
+ public void applyAction(Object context) throws SVNException {
+ ISVNEditor editor = ( ISVNEditor ) context;
for ( Iterator it = this.actions.iterator(); it.hasNext(); ) {
ScmAction action = (ScmAction) it.next();
action.applyAction( editor );
Modified: 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 2007-02-11 19:46:00 UTC (rev 9438)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/svn/SvnActionFactory.java 2007-02-12 00:35:41 UTC (rev 9439)
@@ -12,17 +12,29 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
-import org.apache.log4j.Logger;
+//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.log.ScmLogEntry;
+import org.drools.scm.log.ScmLogEntry.Add;
+import org.drools.scm.log.ScmLogEntry.Copy;
+import org.drools.scm.log.ScmLogEntry.Delete;
+import org.drools.scm.log.ScmLogEntry.Replaced;
+import org.drools.scm.log.ScmLogEntry.Update;
+
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.SVNLogEntry;
+import org.tmatesoft.svn.core.SVNLogEntryPath;
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
@@ -40,7 +52,7 @@
implements
ScmActionFactory {
- private static Logger logger = Logger.getLogger( SvnActionFactory.class );
+// private static Logger logger = Logger.getLogger( SvnActionFactory.class );
private SVNRepository repository;
/*
@@ -162,7 +174,7 @@
}
} catch ( SVNException e ) {
e.printStackTrace();
- logger.error( "svn error: " );
+ //logger.error( "svn error: " );
throw e;
}
}
@@ -170,13 +182,76 @@
public void getContent(String path, String file, long revision, OutputStream os) throws SVNException {
this.repository.getFile( path + "/" + file, revision, null, os);
}
+
+ public List log(String[] paths, long startRevision, long endRevision) throws SVNException {
+ return toScm( this.repository.log( paths, null, startRevision, endRevision, true, false ) );
+ }
+
+ private List toScm(Collection collection) throws SVNException {
+ List list = new ArrayList();
+ for ( Iterator it = collection.iterator(); it.hasNext(); ) {
+ SVNLogEntry logEntry = ( SVNLogEntry ) it.next();
+ Map map = logEntry.getChangedPaths();
+ Set changePathSet = map.keySet();
+
+ ScmLogEntry scmLogEntry = new ScmLogEntry(logEntry.getAuthor(),logEntry.getDate(), logEntry.getMessage() );
+ for ( Iterator it2 = changePathSet.iterator(); it2.hasNext(); ) {
+ SVNLogEntryPath entryPath = ( SVNLogEntryPath ) map.get( it2.next() );
+
+ switch (entryPath.getType()) {
+
+ case SVNLogEntryPath.TYPE_ADDED: {
+ SVNDirEntry dirEntry = this.repository.info( entryPath.getPath(), -1 );
+ char type = ( dirEntry.getKind() == SVNNodeKind.DIR ) ? 'D' : 'F';
+ if ( entryPath.getCopyPath() == null ) {
+ // this entry was added
+ Add add = new Add( type, entryPath.getPath(), logEntry.getRevision());
+ scmLogEntry.addAction( add );
+ break;
+ } else {
+ // this entry was copied
+ Copy copy = new Copy( type, entryPath.getCopyPath(), entryPath.getCopyRevision(), entryPath.getPath(), logEntry.getRevision() );
+ scmLogEntry.addAction( copy );
+ break;
+ }
+ }
+
+ case SVNLogEntryPath.TYPE_DELETED: {
+ SVNDirEntry dirEntry = this.repository.info( entryPath.getPath(), -1 );
+ char type = ( dirEntry.getKind() == SVNNodeKind.DIR ) ? 'D' : 'F';
+ Delete delete = new Delete( type, entryPath.getPath(), logEntry.getRevision());
+ scmLogEntry.addAction( delete );
+ break;
+ }
+
+ case SVNLogEntryPath.TYPE_MODIFIED: {
+ SVNDirEntry dirEntry = this.repository.info( entryPath.getPath(), -1 );
+ char type = ( dirEntry.getKind() == SVNNodeKind.DIR ) ? 'D' : 'F';
+ Update update = new Update( type, entryPath.getPath(), logEntry.getRevision());
+ scmLogEntry.addAction( update );
+ break;
+ }
+
+ case SVNLogEntryPath.TYPE_REPLACED: {
+ SVNDirEntry dirEntry = this.repository.info( entryPath.getPath(), -1 );
+ char type = ( dirEntry.getKind() == SVNNodeKind.DIR ) ? 'D' : 'F';
+ Replaced replaced = new Replaced( type, entryPath.getPath(), logEntry.getRevision());
+ scmLogEntry.addAction( replaced );
+ break;
+ }
+ }
+ }
+ list.add( scmLogEntry );
+ }
+ return list;
+ }
public long getLatestRevision() throws Exception {
try {
return repository.getLatestRevision();
} catch ( SVNException e ) {
e.printStackTrace();
- logger.error( "svn error: " );
+ //logger.error( "svn error: " );
throw e;
}
}
@@ -193,7 +268,7 @@
SVNCommitInfo info = editor.closeEdit();
} catch ( SVNException e ) {
e.printStackTrace();
- logger.error( "svn error: " );
+ //logger.error( "svn error: " );
throw e;
}
}
@@ -214,7 +289,8 @@
this.actions.add( action );
}
- public void applyAction(ISVNEditor editor) throws SVNException {
+ public void applyAction(Object context) throws SVNException {
+ ISVNEditor editor = ( ISVNEditor ) context;
for ( Iterator it = this.actions.iterator(); it.hasNext(); ) {
ScmAction action = (ScmAction) it.next();
action.applyAction( editor );
@@ -237,7 +313,8 @@
this.content = content;
}
- public void applyAction(ISVNEditor editor) throws SVNException {
+ public void applyAction(Object context) throws SVNException {
+ ISVNEditor editor = ( ISVNEditor ) context;
openDirectories( editor,
path );
@@ -276,7 +353,8 @@
this.path = path;
}
- public void applyAction(ISVNEditor editor) throws SVNException {
+ public void applyAction(Object context) throws SVNException {
+ ISVNEditor editor = ( ISVNEditor ) context;
openDirectories( editor,
this.root );
String[] paths = this.path.split( "/" );
@@ -314,7 +392,8 @@
this.newContent = newContent;
}
- public void applyAction(ISVNEditor editor) throws SVNException {
+ public void applyAction(Object context) throws SVNException {
+ ISVNEditor editor = ( ISVNEditor ) context;
openDirectories( editor,
path );
editor.openFile( path + "/" + file,
@@ -357,7 +436,8 @@
this.revision = revision;
}
- public void applyAction(ISVNEditor editor) throws SVNException {
+ public void applyAction(Object context) throws SVNException {
+ ISVNEditor editor = ( ISVNEditor ) context;
editor.addFile( newPath + "/" + newFile,
path + "/" + file,
revision );
@@ -379,7 +459,8 @@
this.revision = revision;
}
- public void applyAction(ISVNEditor editor) throws SVNException {
+ public void applyAction(Object context) throws SVNException {
+ ISVNEditor editor = ( ISVNEditor ) context;
editor.addDir( newPath,
path,
revision );
@@ -408,7 +489,8 @@
this.revision = revision;
}
- public void applyAction(ISVNEditor editor) throws SVNException {
+ public void applyAction(Object context) throws SVNException {
+ ISVNEditor editor = ( ISVNEditor ) context;
CopyFile copyFile = new CopyFile( path,
file,
newPath,
@@ -438,7 +520,8 @@
this.revision = revision;
}
- public void applyAction(ISVNEditor editor) throws SVNException {
+ public void applyAction(Object context) throws SVNException {
+ ISVNEditor editor = ( ISVNEditor ) context;
CopyDirectory copyDirectory = new CopyDirectory( path,
newPath,
revision );
@@ -462,7 +545,8 @@
this.file = file;
}
- public void applyAction(ISVNEditor editor) throws SVNException {
+ public void applyAction(Object context) throws SVNException {
+ ISVNEditor editor = ( ISVNEditor ) context;
openDirectories( editor,
path );
editor.deleteEntry( path + "/" + file,
@@ -481,7 +565,8 @@
this.path = path;
}
- public void applyAction(ISVNEditor editor) throws SVNException {
+ public void applyAction(Object context) throws SVNException {
+ ISVNEditor editor = ( ISVNEditor ) context;
openDirectories( editor,
path );
editor.deleteEntry( path,
Modified: 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 2007-02-11 19:46:00 UTC (rev 9438)
+++ labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/scm/svn/SvnActionFactoryTest.java 2007-02-12 00:35:41 UTC (rev 9439)
@@ -14,10 +14,11 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import junit.framework.TestCase;
-import org.apache.log4j.Logger;
+//import org.apache.log4j.Logger;
import org.drools.scm.DefaultScmEntry;
import org.drools.scm.ScmAction;
import org.drools.scm.ScmActionFactory;
@@ -33,12 +34,14 @@
import org.drools.scm.svn.SvnActionFactory.UpdateFile;
import org.tmatesoft.svn.core.SVNDirEntry;
import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.SVNLogEntry;
+import org.tmatesoft.svn.core.SVNLogEntryPath;
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 Logger logger = Logger.getLogger( SvnActionFactoryTest.class );
private static String svnUrl;
@@ -197,16 +200,24 @@
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() ) );
-
+ 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() ) );
-
+ 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" ) );
@@ -228,19 +239,23 @@
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 );
+ 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() ) );
+ svn.getContent( "folder1",
+ "file1.dat",
+ -1,
+ baos );
+ assertTrue( Arrays.equals( oldContent,
+ baos.toByteArray() ) );
// Update the existing file
actions = new CompositeSvnAction();
@@ -251,11 +266,15 @@
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() ) );
+ 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( "" ) );
@@ -280,17 +299,21 @@
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() ) );
-
+ 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( "",
@@ -303,12 +326,16 @@
svn.getLatestRevision() );
actions.addScmAction( copyFile );
svn.execute( actions,
- "test message" );
-
+ "test message" );
+
baos = new ByteArrayOutputStream();
- svn.getContent( "folder2", "file2.dat", -1, baos );
- assertTrue( Arrays.equals( content, baos.toByteArray() ) );
-
+ 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" ) );
@@ -341,18 +368,26 @@
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() ) );
+ 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() ) );
-
+ 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" ) );
+ assertFalse( list.contains( "folder2/folder1/file1.dat" ) );
// Now copy the directory
actions = new CompositeSvnAction();
@@ -365,20 +400,36 @@
actions.addScmAction( copyDirectory );
svn.execute( actions,
"test message" );
-
+
baos = new ByteArrayOutputStream();
- svn.getContent( "folder1", "file1.dat", -1, baos );
- assertTrue( Arrays.equals( content1, baos.toByteArray() ) );
+ 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() ) );
+ 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() ) );
+ 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() ) );
-
+ 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" ) );
@@ -402,16 +453,20 @@
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() ) );
-
+ 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( "",
@@ -425,16 +480,20 @@
actions.addScmAction( moveFile );
svn.execute( actions,
"test message" );
-
+
baos = new ByteArrayOutputStream();
- svn.getContent( "folder2", "file2.dat", -1, baos );
- assertTrue( Arrays.equals( content, baos.toByteArray() ) );
-
+ 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,
@@ -456,9 +515,13 @@
// check the intial content and dir structure
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- svn.getContent( "folder1", "file1.dat", -1, baos );
- assertTrue( Arrays.equals( content, baos.toByteArray() ) );
-
+ svn.getContent( "folder1",
+ "file1.dat",
+ -1,
+ baos );
+ assertTrue( Arrays.equals( content,
+ baos.toByteArray() ) );
+
actions = new CompositeSvnAction();
MoveDirectory moveDirectory = new MoveDirectory( "folder1",
"folder2",
@@ -466,12 +529,16 @@
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() ) );
-
+ svn.getContent( "folder2",
+ "file1.dat",
+ -1,
+ baos );
+ assertTrue( Arrays.equals( content,
+ baos.toByteArray() ) );
+
List list = convertToStringList( svn.listEntries( "" ) );
assertFalse( list.contains( "folder1" ) );
@@ -495,10 +562,10 @@
content );
actions.addScmAction( addFile );
svn.execute( actions,
- "test message" );
+ "test message" );
List list = convertToStringList( svn.listEntries( "" ) );
assertTrue( list.contains( "folder1" ) );
- assertTrue( list.contains( "folder1/file1.dat" ) );
+ assertTrue( list.contains( "folder1/file1.dat" ) );
// Now do the file delete
actions = new CompositeSvnAction();
@@ -506,7 +573,7 @@
"file1.dat" );
actions.addScmAction( deleteFile );
svn.execute( actions,
- "test message" );
+ "test message" );
list = convertToStringList( svn.listEntries( "" ) );
assertTrue( list.contains( "folder1" ) );
assertFalse( list.contains( "folder1/file1.dat" ) );
@@ -526,7 +593,7 @@
ScmAction addFile = new AddFile( "folder1",
"file1.dat",
content );
- actions.addScmAction( addFile );
+ actions.addScmAction( addFile );
addFolder = new AddDirectory( "",
"folder2" );
actions.addScmAction( addFolder );
@@ -536,19 +603,58 @@
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( "" ) );
+ list = convertToStringList( svn.listEntries( "" ) );
assertFalse( list.contains( "folder1" ) );
assertFalse( list.contains( "folder1/file1.dat" ) );
assertTrue( list.contains( "folder2" ) );
}
+
+ public void testHistory() throws Exception {
+ SvnActionFactory 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" );
+
+ actions = new CompositeSvnAction();
+ MoveDirectory moveDirectory = new MoveDirectory( "folder1",
+ "folder2",
+ svn.getLatestRevision() );
+ actions.addScmAction( moveDirectory );
+ svn.execute( actions,
+ "test message" );
+
+ Collection collection = svn.log( new String[] { "" }, 0, -1 );
+ for ( Iterator it = collection.iterator(); it.hasNext(); ) {
+ SVNLogEntry logEntry = ( SVNLogEntry ) it.next();
+ Map map = logEntry.getChangedPaths();
+ Set changePathSet = map.keySet();
+ for ( Iterator it2 = changePathSet.iterator(); it2.hasNext(); ) {
+ SVNLogEntryPath entryPath = ( SVNLogEntryPath ) map.get( it2.next() );
+ System.out.println( entryPath );
+ }
+ }
+
+ }
+
public static void copy(File src,
File dest) throws IOException {
if ( src.isDirectory() ) {
Added: labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/scm/svn/SvnLogTest.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/scm/svn/SvnLogTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/scm/svn/SvnLogTest.java 2007-02-12 00:35:41 UTC (rev 9439)
@@ -0,0 +1,145 @@
+package org.drools.scm.svn;
+
+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.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+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.MoveDirectory;
+import org.tmatesoft.svn.core.SVNLogEntry;
+import org.tmatesoft.svn.core.SVNLogEntryPath;
+
+import junit.framework.TestCase;
+
+public class SvnLogTest extends TestCase {
+ 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 testHistory() throws Exception {
+ SvnActionFactory 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" );
+
+
+
+// actions = new CompositeSvnAction();
+// MoveDirectory moveDirectory = new MoveDirectory( "folder1",
+// "folder2",
+// svn.getLatestRevision() );
+// actions.addScmAction( moveDirectory );
+// svn.execute( actions,
+// "test message" );
+//
+// Collection collection = svn.log( new String[] { "" }, 0, -1 );
+// for ( Iterator it = collection.iterator(); it.hasNext(); ) {
+// SVNLogEntry logEntry = ( SVNLogEntry ) it.next();
+// Map map = logEntry.getChangedPaths();
+// Set changePathSet = map.keySet();
+// for ( Iterator it2 = changePathSet.iterator(); it2.hasNext(); ) {
+// SVNLogEntryPath entryPath = ( SVNLogEntryPath ) map.get( it2.next() );
+// System.out.println( entryPath );
+// }
+// }
+
+ }
+
+ 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();
+ }
+ }
+
+ 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;
+ }
+
+}
More information about the jboss-svn-commits
mailing list