juanco      02/03/03 13:57:20

  Modified:    src/java/org/apache/maven/jrcs/rcs Archive.java
                        ArchiveParser.java ArchiveParser.jj Node.java
                        Path.java
               src/test/org/apache/maven/jrcs/rcs ArchiveTest.java
  Log:
  added basic support for extracting change logs
  
  Revision  Changes    Path
  1.18      +76 -26    
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/rcs/Archive.java
  
  Index: Archive.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/rcs/Archive.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Archive.java      3 Mar 2002 18:38:41 -0000       1.17
  +++ Archive.java      3 Mar 2002 21:57:20 -0000       1.18
  @@ -64,12 +64,15 @@
   import java.io.IOException;
   import java.text.Format;
   import java.text.MessageFormat;
  +import java.util.Collections;
   import java.util.Collection;
   import java.util.Iterator;
   import java.util.Map;
   import java.util.Set;
   import java.util.TreeMap;
   import java.util.TreeSet;
  +import java.util.List;
  +import java.util.LinkedList;
   
   import org.apache.maven.jrcs.diff.Diff;
   import org.apache.maven.jrcs.diff.PatchFailedException;
  @@ -157,7 +160,7 @@
    * @see org.apache.maven.jrcs.diff
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Juanco Anez</a>
  - * @version $Id: Archive.java,v 1.17 2002/03/03 18:38:41 juanco Exp $
  + * @version $Id: Archive.java,v 1.18 2002/03/03 21:57:20 juanco Exp $
    */
   public class Archive
           extends ToString
  @@ -445,30 +448,6 @@
           phrases.put(key, values);
       }
   
  -    /**
  -     * Get the archive node associated with a version number.
  -     * @param vernum The version number.
  -     * @return The node, if found.
  -     */
  -    protected Node getNode(Version vernum)
  -            throws InvalidVersionNumberException,
  -            NodeNotFoundException
  -    {
  -        if (!vernum.even())
  -        {
  -            throw new InvalidVersionNumberException(vernum);
  -        }
  -        Node node = (Node) nodes.get(vernum);
  -        if (node == null)
  -        {
  -            throw new NodeNotFoundException();
  -        }
  -        else
  -        {
  -            return node;
  -        }
  -    }
  -
       protected Node newNode(Version vernum)
       {
           return newNode(vernum, null);
  @@ -513,7 +492,7 @@
           return (BranchNode) newNode(vernum);
       }
   
  -    protected Node findNode(Version vernum)
  +    protected Node getNode(Version vernum)
               throws InvalidVersionNumberException,
               NodeNotFoundException
       {
  @@ -531,6 +510,19 @@
   
   
       /**
  +     * Return the node with the version number that matches the one provided.
  +     * The given version number may be partial.
  +     * @param vernum the version number to match.
  +     * @return the node, or null if no match found.
  +     */
  +    public Node findNode(Version vernum)
  +    {
  +       Path path = getRevisionPath(vernum);
  +       return (path == null ? null : path.last());
  +    }
  +
  +
  +    /**
        * Place a string image of the archive in the given StringBuffer.
        * @param s Where the image shoul go.
        */
  @@ -1134,6 +1126,64 @@
           return result;
       }
   
  +    /**
  +     * Return the list of nodes between the head revision and 
  +     * the root revision.
  +     */
  +    public Node[] changeLog() 
  +    {
  +        return changeLog(head.version);
  +    }
  +
  +    /**
  +     * Return the list of nodes between the the given revision
  +     * and the root revision.
  +     * @param latest the version of the last revision in the log.
  +     */
  +    public Node[] changeLog(Version latest)
  +    {
  +        return changeLog(latest, head.root().version);
  +    }
  +
  +    /**
  +     * Return the list of nodes between the the given two revisions.
  +     * @param latest the version of the last revision in the log.
  +     * @param earliest the version of the first revision in the log.
  +     */
  +    public Node[] changeLog(Version latest, Version earliest)
  +    {
  +        Node last  = findNode(latest);
  +        if (last == null)
  +        {
  +           throw new NodeNotFoundException(latest.toString());
  +        }
  +
  +        Node first = findNode(earliest);
  +        if (first == null)
  +        {
  +           throw new NodeNotFoundException(earliest.toString());
  +        }
  +        
  +        List result = new LinkedList();
  +        
  +        Node node = last; 
  +        while (node != null)
  +        {
  +            result.add(0, node);
  +            if (node == first)
  +            {
  +                break;
  +            }
  +            node = node.parent;
  +        }
  +
  +        if (node == null)
  +        {
  +           throw new NodeNotFoundException(earliest.toString());
  +        }
  +
  +        return (Node[]) result.toArray(new Node[result.size()]);
  +    }
   }
   
   
  
  
  
  1.8       +2 -2      
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/rcs/ArchiveParser.java
  
  Index: ArchiveParser.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/rcs/ArchiveParser.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ArchiveParser.java        27 Feb 2002 20:58:58 -0000      1.7
  +++ ArchiveParser.java        3 Mar 2002 21:57:20 -0000       1.8
  @@ -65,7 +65,7 @@
    * This class is NOT thread safe.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Juanco Anez</a>
  - * @version $Id: ArchiveParser.java,v 1.7 2002/02/27 20:58:58 sbailliez Exp $
  + * @version $Id: ArchiveParser.java,v 1.8 2002/03/03 21:57:20 juanco Exp $
    * @see Archive
    */
   class ArchiveParser implements ArchiveParserConstants
  @@ -540,7 +540,7 @@
           String log;
           String txt;
           v = version();
  -        node = arc.findNode(v);
  +        node = arc.getNode(v);
           jj_consume_token(LOG);
           log = string();
           node.setLog(log);
  
  
  
  1.6       +2 -2      
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/rcs/ArchiveParser.jj
  
  Index: ArchiveParser.jj
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/rcs/ArchiveParser.jj,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ArchiveParser.jj  27 Feb 2002 16:49:48 -0000      1.5
  +++ ArchiveParser.jj  3 Mar 2002 21:57:20 -0000       1.6
  @@ -90,7 +90,7 @@
    * This class is NOT thread safe.
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>Juanco Anez</a>
  - * @version $Id: ArchiveParser.jj,v 1.5 2002/02/27 16:49:48 juanco Exp $
  + * @version $Id: ArchiveParser.jj,v 1.6 2002/03/03 21:57:20 juanco Exp $
    * @see Archive
    */
   class ArchiveParser {
  @@ -405,7 +405,7 @@
   {
       v = version()
       {
  -      node = arc.findNode(v);
  +      node = arc.getNode(v);
       }
   
       <LOG> log = string()
  
  
  
  1.10      +2 -2      
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/rcs/Node.java
  
  Index: Node.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/rcs/Node.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Node.java 3 Mar 2002 18:38:41 -0000       1.9
  +++ Node.java 3 Mar 2002 21:57:20 -0000       1.10
  @@ -88,9 +88,9 @@
    * @see Archive
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Juanco Anez</a>
  - * @version $Id: Node.java,v 1.9 2002/03/03 18:38:41 juanco Exp $
  + * @version $Id: Node.java,v 1.10 2002/03/03 21:57:20 juanco Exp $
    */
  -abstract class Node
  +public abstract class Node
           extends ToString
           implements Comparable
   {
  
  
  
  1.9       +3 -3      
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/rcs/Path.java
  
  Index: Path.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/rcs/Path.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Path.java 3 Mar 2002 18:38:41 -0000       1.8
  +++ Path.java 3 Mar 2002 21:57:20 -0000       1.9
  @@ -56,8 +56,9 @@
   
   
   import java.util.Iterator;
  -import java.util.LinkedList;
   import java.util.List;
  +import java.util.LinkedList;
  +import java.util.ArrayList;
   
   import org.apache.maven.jrcs.diff.PatchFailedException;
   
  @@ -72,7 +73,7 @@
    * @see Node
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Juanco Anez</a>
  - * @version $Id: Path.java,v 1.8 2002/03/03 18:38:41 juanco Exp $
  + * @version $Id: Path.java,v 1.9 2002/03/03 21:57:20 juanco Exp $
    */
   class Path
   {
  @@ -204,5 +205,4 @@
           }
           return lines;
       }
  -
   }
  
  
  
  1.9       +50 -0     
jakarta-turbine-maven/src/test/org/apache/maven/jrcs/rcs/ArchiveTest.java
  
  Index: ArchiveTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/test/org/apache/maven/jrcs/rcs/ArchiveTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ArchiveTest.java  3 Mar 2002 19:12:32 -0000       1.8
  +++ ArchiveTest.java  3 Mar 2002 21:57:20 -0000       1.9
  @@ -223,6 +223,11 @@
   
           assertNull(archive.getRevisionVersion("2"));
           assertNull(archive.getRevisionVersion("1.2.1"));
  +
  +        Node[] log = archive.changeLog();
  +        assertNotNull("log is null", log);
  +        assertEquals(    1, log.length);    
  +        assertEquals("1.1", log[0].version.toString());
       }
   
       public void testAdd1_2()
  @@ -241,6 +246,12 @@
   
           assertNull(archive.getRevisionVersion("2"));
           assertNull(archive.getRevisionVersion("1.2.1"));
  +
  +        Node[] log = archive.changeLog();
  +        assertNotNull("log is null", log);
  +        assertEquals(    2, log.length);    
  +        assertEquals("1.1", log[0].version.toString());
  +        assertEquals("1.2", log[1].version.toString());
       }
   
        public void testAdd1_2_with_keywords()
  @@ -278,6 +289,13 @@
   
           assertNull(archive.getRevisionVersion("2"));
           assertNull(archive.getRevisionVersion("1.2.1"));
  +
  +        Node[] log = archive.changeLog();
  +        assertNotNull("log is null", log);
  +        assertEquals(    3, log.length);    
  +        assertEquals("1.1", log[0].version.toString());
  +        assertEquals("1.2", log[1].version.toString());
  +        assertEquals("1.3", log[2].version.toString());
       }
   
       public void testAdd1_2_1()
  @@ -306,6 +324,19 @@
   
           assertNull(archive.getRevisionVersion("1.2.1.2"));
           assertNull(archive.getRevisionVersion("1.2.2"));
  +
  +        Node[] log = archive.changeLog(new Version("1.2.1"));
  +        assertNotNull("log is null", log);
  +        assertEquals(    3, log.length);    
  +        assertEquals("1.1",     log[0].version.toString());
  +        assertEquals("1.2",     log[1].version.toString());
  +        assertEquals("1.2.1.1", log[2].version.toString());
  +
  +        log = archive.changeLog(new Version("1.2.1"), new Version("1.2"));
  +        assertNotNull("log is null", log);
  +        assertEquals(    2, log.length);    
  +        assertEquals("1.2",     log[0].version.toString());
  +        assertEquals("1.2.1.1", log[1].version.toString());
       }
   
       public void testBranch()
  @@ -348,6 +379,25 @@
           assertNull(archive.getRevisionVersion("1.2.8.6"));
           assertNull(archive.getRevisionVersion("1.2.3"));
           assertNull(archive.getRevisionVersion("1.2.9"));
  +
  +        Node[] log = archive.changeLog(new Version("1.2.8"));
  +        assertNotNull("log is null", log);
  +        assertEquals(    5, log.length);    
  +        assertEquals("1.1",     log[0].version.toString());
  +        assertEquals("1.2"    , log[1].version.toString());
  +        assertEquals("1.2.8.2", log[2].version.toString());
  +        assertEquals("1.2.8.4", log[3].version.toString());
  +        assertEquals("1.2.8.5", log[4].version.toString());
  +
  +        try
  +        {
  +            log = archive.changeLog(new Version("1.2.8"), new Version("1.2.1"));
  +            fail("found change log between 1.2.8.5 and 1.2.1.2");
  +        }
  +        catch (NodeNotFoundException e)
  +        {
  +        }
  +
       }
   
       public void testInvalidBranch()
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to