001: package org.drools.scm.svn;
002:
003: import java.io.File;
004: import java.io.FileInputStream;
005: import java.io.FileOutputStream;
006: import java.io.IOException;
007: import java.net.URL;
008: import java.util.ArrayList;
009: import java.util.Iterator;
010: import java.util.List;
011:
012: import junit.framework.TestCase;
013:
014: import org.drools.scm.CompositeScmAction;
015: import org.drools.scm.ScmAction;
016: import org.drools.scm.ScmEntry;
017: import org.drools.scm.svn.SvnActionFactory.AddDirectory;
018: import org.drools.scm.svn.SvnActionFactory.AddFile;
019:
020: public class SvnLogTest extends TestCase {
021: private static String svnUrl;
022:
023: public void setUp() throws IOException {
024: // First we need to find the absolute path
025: URL url = getClass().getResource("/svn_repo_empty");
026:
027: assertNotNull(url);
028: File src = new File(url.getFile());
029: File dst = new File(src.getParent(), "/copy_svn_repo_empty");
030:
031: // make sure the destination is empty before we copy
032: delete(dst);
033:
034: copy(src, dst);
035:
036: // Now set the two path roots
037: svnUrl = "file:///"
038: + dst.getAbsolutePath().replaceAll("\\\\", "/");
039: }
040:
041: public void tearDown() throws Exception {
042: URL url = getClass().getResource("/copy_svn_repo_empty");
043: delete(new File(url.getFile()));
044: }
045:
046: public void testHistory() throws Exception {
047: SvnActionFactory svn = new SvnActionFactory(svnUrl, "mrtrout",
048: "drools");
049:
050: CompositeScmAction actions = new CompositeScmAction();
051:
052: ScmAction addFolder = new AddDirectory("", "folder1");
053: actions.addScmAction(addFolder);
054: byte[] content = new byte[] { 1, 1, 1, 1 };
055: ScmAction addFile = new AddFile("folder1", "file1.dat", content);
056: actions.addScmAction(addFile);
057: svn.execute(actions, "test message");
058:
059: // actions = new CompositeSvnAction();
060: // MoveDirectory moveDirectory = new MoveDirectory( "folder1",
061: // "folder2",
062: // svn.getLatestRevision() );
063: // actions.addScmAction( moveDirectory );
064: // svn.execute( actions,
065: // "test message" );
066: //
067: // Collection collection = svn.log( new String[] { "" }, 0, -1 );
068: // for ( Iterator it = collection.iterator(); it.hasNext(); ) {
069: // SVNLogEntry logEntry = ( SVNLogEntry ) it.next();
070: // Map map = logEntry.getChangedPaths();
071: // Set changePathSet = map.keySet();
072: // for ( Iterator it2 = changePathSet.iterator(); it2.hasNext(); ) {
073: // SVNLogEntryPath entryPath = ( SVNLogEntryPath ) map.get( it2.next() );
074: // System.out.println( entryPath );
075: // }
076: // }
077:
078: }
079:
080: public static void copy(File src, File dest) throws IOException {
081: if (src.isDirectory()) {
082: dest.mkdirs();
083: String list[] = src.list();
084:
085: for (int i = 0; i < list.length; i++) {
086: String dest1 = dest.getPath() + File.separator
087: + list[i];
088: String src1 = src.getPath() + File.separator + list[i];
089: copy(new File(src1), new File(dest1));
090: }
091: } else {
092:
093: FileInputStream fin = new FileInputStream(src);
094: FileOutputStream fout = new FileOutputStream(dest);
095: int c;
096: while ((c = fin.read()) >= 0)
097: fout.write(c);
098: fin.close();
099: fout.close();
100: }
101: }
102:
103: public static void delete(File src) throws IOException {
104: if (src.isDirectory()) {
105: String list[] = src.list();
106:
107: for (int i = 0; i < list.length; i++) {
108: String src1 = src.getPath() + File.separator + list[i];
109: delete(new File(src1));
110: }
111: src.delete();
112: } else {
113: src.delete();
114: }
115: }
116:
117: public static List convertToStringList(List list) {
118: List files = new ArrayList(list.size());
119:
120: for (Iterator it = list.iterator(); it.hasNext();) {
121: ScmEntry entry = (ScmEntry) it.next();
122: files.add(entry.getPath().equals("") ? entry.getName()
123: : entry.getPath() + "/" + entry.getName());
124: }
125: return files;
126: }
127:
128: }
|