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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Feb 12 19:36:11 EST 2007


Author: michael.neale at jboss.com
Date: 2007-02-12 19:36:11 -0500 (Mon, 12 Feb 2007)
New Revision: 9462

Added:
   labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/scm/jcr/
   labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/scm/jcr/JcrActionFactoryTest.java
Modified:
   labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/jcr/JcrActionFactory.java
Log:
JBRULES-670

Modified: 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	2007-02-12 23:43:47 UTC (rev 9461)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/scm/jcr/JcrActionFactory.java	2007-02-13 00:36:11 UTC (rev 9462)
@@ -4,6 +4,7 @@
 import java.io.OutputStream;
 import java.util.Iterator;
 import java.util.List;
+import java.util.StringTokenizer;
 
 import org.drools.repository.RulesRepository;
 import org.drools.scm.ScmAction;
@@ -18,7 +19,7 @@
 public class JcrActionFactory
     implements
     ScmActionFactory {
-    
+
     private RulesRepository repository;
 
     public ScmAction addDirectory(String root,
@@ -97,268 +98,321 @@
                                 byte[] newContent) {
         return null;
     }
-    
-    public void syncToScmLog(List list, ScmActionFactory factory) throws Exception { 
+
+    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;                
+                ScmAction action;
                 switch ( item.getActionType() ) {
-                    case 'A': {
+                    case 'A' : {
                         Add add = (Add) item;
-                        if ( add.getPathType() == 'D'  ) {
-                            addDirectory( "", add.getPath() );
+                        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 );
-                            
+                            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() );
+                            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() );
+                    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 );
-                            
+                            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() );
+                            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; 
+
+                        break;
                     }
-                    case 'D': {
-                        Delete delete = (Delete) item;                        
-                        if ( delete.getPathType() == 'D'  ) {
+                    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 );
-                        }                        
+                            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':
+                    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 );
+                        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 );
-                        
+                        getContent( path,
+                                    file,
+                                    -1,
+                                    bosOriginal );
+
                         ByteArrayOutputStream bosNew = new ByteArrayOutputStream();
-                        factory.getContent( path, file, update.getRevision(), bosNew );
-                        
-                        action = updateFile( path, file, bosOriginal.toByteArray(), bosNew.toByteArray() );
-                        
+                        factory.getContent( path,
+                                            file,
+                                            update.getRevision(),
+                                            bosNew );
+
+                        action = updateFile( path,
+                                             file,
+                                             bosOriginal.toByteArray(),
+                                             bosNew.toByteArray() );
+
                         break;
-                    case 'R':
+                    case 'R' :
                         // @TODO this is a delete and add
-                        break;                        
+                        break;
                 }
-                
-                
-            }            
+
+            }
         }
     }
-    
+
     public static class AddFile
-    implements
-    ScmAction {
-    private String file;
-    private String path;
-    private byte[] content;
+        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 AddFile(String path,
+                       String file,
+                       byte[] content) {
+            this.path = path;
+            this.file = file;
+            this.content = content;
+        }
+
+        public void applyAction(Object context) throws Exception {
+
+        }
     }
 
-    public void applyAction(Object context) throws Exception {
-        
+    private String convertPath(String path, String token, String replace) {
+        if (path.indexOf( token ) == -1) return path;
+        StringTokenizer tk = new StringTokenizer(path, token);
+        StringBuffer buf = new StringBuffer();
+        while ( tk.hasMoreTokens() ) {
+            String el = tk.nextToken();
+            buf.append( el );
+            if (tk.hasMoreTokens()) buf.append( replace );            
+        }
+        return buf.toString();
     }
-}
+    
+    public String toDirectoryName(String packageName) {
+        return convertPath( packageName, ".", "/" );
+    }
+    
+    public String toPackageName(String directory) {
+        return convertPath( directory, "/", "." );
+    }
 
-/**
- * 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;
+    /**
+     * 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 AddDirectory(String root,
+                            String path) {
+            this.root = root;
+            this.path = path;
+        }
 
-    public void applyAction(Object context) throws Exception {
-        
+        public void applyAction(Object context) throws Exception {
+
+        }
     }
-}
 
-public static class UpdateFile
-    implements
-    ScmAction {
-    private String file;
-    private String path;
-    private byte[] oldContent;
-    private byte[] newContent;
+    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 UpdateFile(String path,
+                          String file,
+                          byte[] oldContent,
+                          byte[] newContent) {
+            this.path = path;
+            this.file = file;
+            this.oldContent = oldContent;
+            this.newContent = newContent;
+        }
 
-    public void applyAction(Object context) throws Exception {
-        
+        public void applyAction(Object context) throws Exception {
+
+        }
     }
-}
 
-public static class CopyFile
-    implements
-    ScmAction {
-    private String file;
-    private String path;
-    private String newPath;
-    private String newFile;
-    private long   revision;
+    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 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(Object context) throws Exception {
+        public void applyAction(Object context) throws Exception {
 
+        }
     }
-}
 
-public static class CopyDirectory
-    implements
-    ScmAction {
-    private String path;
-    private String newPath;
-    private long   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 CopyDirectory(String path,
+                             String newPath,
+                             long revision) {
+            this.path = path;
+            this.newPath = newPath;
+            this.revision = revision;
+        }
 
-    public void applyAction(Object context) throws Exception {
+        public void applyAction(Object context) throws Exception {
+        }
     }
-}
 
-public static class MoveFile
-    implements
-    ScmAction {
-    private String file;
-    private String path;
-    private String newPath;
-    private String newFile;
-    private long   revision;
+    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 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(Object context) throws Exception {
+        public void applyAction(Object context) throws Exception {
+        }
     }
-}
 
-public static class MoveDirectory
-    implements
-    ScmAction {
-    private String path;
-    private String newPath;
-    private long   revision;
+    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 MoveDirectory(String path,
+                             String newPath,
+                             long revision) {
+            this.path = path;
+            this.newPath = newPath;
+            this.revision = revision;
+        }
 
-    public void applyAction(Object context) throws Exception {
+        public void applyAction(Object context) throws Exception {
 
+        }
     }
-}
 
-public static class DeleteFile
-    implements
-    ScmAction {
-    private String path;
-    private String file;
+    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 DeleteFile(String path,
+                          String file) {
+            this.path = path;
+            this.file = file;
+        }
 
-    public void applyAction(Object context) throws Exception {
+        public void applyAction(Object context) throws Exception {
+        }
     }
-}
 
-public static class DeleteDirectory
-    implements
-    ScmAction {
-    private String path;
+    public static class DeleteDirectory
+        implements
+        ScmAction {
+        private String path;
 
-    public DeleteDirectory(String path) {
-        this.path = path;
-    }
+        public DeleteDirectory(String path) {
+            this.path = path;
+        }
 
-    public void applyAction(Object context) throws Exception {
+        public void applyAction(Object context) throws Exception {
+        }
     }
-}
-    
 
+
+
 }

Added: labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/scm/jcr/JcrActionFactoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/scm/jcr/JcrActionFactoryTest.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/scm/jcr/JcrActionFactoryTest.java	2007-02-13 00:36:11 UTC (rev 9462)
@@ -0,0 +1,20 @@
+package org.drools.scm.jcr;
+
+import junit.framework.TestCase;
+
+public class JcrActionFactoryTest extends TestCase {
+
+    public void testMapPathNameToPackage() {
+        JcrActionFactory fact = new JcrActionFactory();
+        assertEquals("org.foo.bar", fact.toPackageName("org/foo/bar"));
+        assertEquals("foo", fact.toPackageName("foo"));
+        assertEquals("FooBar", fact.toPackageName("FooBar"));
+        
+    
+        assertEquals("org/foo/bar", fact.toDirectoryName("org.foo.bar"));
+        assertEquals("foo", fact.toDirectoryName("foo"));
+    }
+    
+    
+    
+}


Property changes on: labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/scm/jcr/JcrActionFactoryTest.java
___________________________________________________________________
Name: svn:eol-style
   + native




More information about the jboss-svn-commits mailing list