jvanzyl     01/08/26 09:21:41

  Modified:    jjar     build.xml
               jjar/src/java/org/apache/commons/jjar DependencyEngine.java
  Added:       jjar     build.properties.sample
               jjar/src/test/org/apache/commons/jjar
                        TestDependencyEngine.java
  Log:
  - added a reset to the dep engine so it can be reused
  - add sample build.properties file
  - added start of junit tests for the dep engine
  - udpated build file to run tests
  
  Revision  Changes    Path
  1.5       +28 -1     jakarta-commons-sandbox/jjar/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jjar/build.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- build.xml 2001/08/21 22:58:37     1.4
  +++ build.xml 2001/08/26 16:21:40     1.5
  @@ -1,7 +1,7 @@
   <project name="Jakarta Jar Archive Respository" default="jar" basedir=".">
   
   <!--
  -        $Id: build.xml,v 1.4 2001/08/21 22:58:37 jon Exp $
  +        $Id: build.xml,v 1.5 2001/08/26 16:21:40 jvanzyl Exp $
   -->
   
   <!-- ========== Initialize Properties ===================================== -->
  @@ -181,7 +181,34 @@
              manifest="${build.home}/conf/MANIFEST.MF"/>
     </target>
   
  +  <target name="compile.tests" depends="compile"
  +   description="Compile unit test cases">
  +    <javac  srcdir="${test.home}"
  +           destdir="${build.home}/tests"
  +             debug="${compile.debug}"
  +       deprecation="${compile.deprecation}"
  +          optimize="${compile.optimize}">
  +      <classpath refid="test.classpath"/>
  +    </javac>
  +    <copy    todir="${build.home}/tests" filtering="on">
  +      <fileset dir="${test.home}" excludes="**/*.java"/>
  +    </copy>
  +  </target>
   
  +
   <!-- ========== Unit Test Targets ========================================= --> 
  +
  +  <target name="test"  depends="compile.tests,test.depengine"
  +   description="Run all unit test cases">
  +  </target>
  +
  +  <target name="test.depengine">
  +    <echo message="Running DependencyEngine tests ..."/>
  +    <java classname="${test.runner}" fork="yes"
  +        failonerror="${test.failonerror}">
  +      <arg value="org.apache.commons.jjar.TestDependencyEngine"/>
  +      <classpath refid="test.classpath"/>
  +    </java>
  +  </target>
   
   </project>
  
  
  
  1.1                  jakarta-commons-sandbox/jjar/build.properties.sample
  
  Index: build.properties.sample
  ===================================================================
  junit.jar = /home/jvanzyl/js/jars/junit-3.7.jar
  
  
  
  1.4       +16 -112   
jakarta-commons-sandbox/jjar/src/java/org/apache/commons/jjar/DependencyEngine.java
  
  Index: DependencyEngine.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jjar/src/java/org/apache/commons/jjar/DependencyEngine.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DependencyEngine.java     2001/08/21 11:36:27     1.3
  +++ DependencyEngine.java     2001/08/26 16:21:40     1.4
  @@ -82,7 +82,7 @@
    *  </p>
    *
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Geir Magnusson Jr.</a>
  - *  @version $Id: DependencyEngine.java,v 1.3 2001/08/21 11:36:27 geirm Exp $ 
  + *  @version $Id: DependencyEngine.java,v 1.4 2001/08/26 16:21:40 jvanzyl Exp $ 
    */
   public class DependencyEngine
   {    
  @@ -104,6 +104,15 @@
       }
   
       /**
  +     * Reset the dependency engine, clear all entries
  +     * and start from scratch.
  +     */
  +    public void reset()
  +    {
  +        projects = new HashMap();
  +    }        
  +
  +    /**
        *  returns a list of dependencies for a given package
        */
       public List getDependencies( String pkg )
  @@ -378,6 +387,12 @@
           return; 
       }
   
  +    public void addProject(String project, List dependencies)
  +        throws Exception
  +    {
  +        addProject(project, dependencies, project);
  +    }
  +
       /**
        *  Adds a project and it's associated dependencies.  The dependencies
        *  currently do not have to be projects themselves.
  @@ -431,117 +446,6 @@
           projects.put( project, n );
   
           return;
  -    }
  -
  -    /**
  -     *  little demonstration test
  -     */
  -    public static void main(String arg[] )
  -    {
  -        /*
  -         *  tests the engine with
  -         *   A  B  C
  -         *   ^  ^  ^\ 
  -         *    \/ \/  |
  -         *    D <-E  |
  -         *    ^      /
  -         *     \    /
  -         *      F <-
  -         */
  -
  -        try
  -        {
  -            DependencyEngine d = new DependencyEngine();
  -           
  -            ArrayList deps = null;
  -        
  -            /*
  -             *  A : no dependencies 
  -             */
  -            deps = new ArrayList();
  -            d.addProject( "A", deps, "A" );
  -            
  -            /*
  -             *  B : no dependencies
  -             */
  -            deps = new ArrayList();
  -            d.addProject("B", deps, "B" );
  -            
  -            /*
  -             *   C -> F
  -             */
  -            deps = new ArrayList();
  -            deps.add("F");
  -            d.addProject("C", deps, "C");
  -            
  -            /*
  -             *  D -> A, B
  -             */
  -            deps = new ArrayList();
  -            deps.add("A");
  -            deps.add("B");
  -            d.addProject("D", deps, "D");
  -            
  -            /*
  -             *  E -> B, C, D
  -             */
  -            deps = new ArrayList();
  -            deps.add("B");
  -            deps.add("C");
  -            deps.add("D");
  -            d.addProject("E", deps, "E" );
  -
  -            /*
  -             *   F -> D
  -             */
  -            deps = new ArrayList();
  -            deps.add("D");
  -            d.addProject("F", deps, "F" );
  -
  -            /*
  -             *  generate the list of all
  -             */
  -            List l = d.generateCookielist();
  -
  -            /*
  -             *  show us
  -             */
  -            Iterator i = l.iterator();
  -
  -            while(i.hasNext())
  -            {
  -                String s = (String) i.next();
  -
  -                System.out.println("Building : " + s );
  -            }
  -
  -            /*
  -             *  now test the 'project set' dep gen, so
  -             *  give it two projects - you should get out
  -             *  the correctly ordered list so that all 
  -             *  can be correctly built
  -             */
  -
  -            System.out.println("Mix test :");
  -
  -            ArrayList foo = new ArrayList();
  -            foo.add("E");
  -            foo.add("D");
  -            List foofoo = d.getDependencies(foo);
  -
  -            i = foofoo.iterator();
  -
  -            while(i.hasNext())
  -            {
  -                String s = (String) i.next();
  -
  -                System.out.println("Building : " + s );
  -            }
  -        }
  -        catch( Exception e )
  -        {
  -            System.out.println("main : "  + e );
  -        }
       }
   }
   
  
  
  
  1.1                  
jakarta-commons-sandbox/jjar/src/test/org/apache/commons/jjar/TestDependencyEngine.java
  
  Index: TestDependencyEngine.java
  ===================================================================
  package org.apache.commons.jjar;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import java.util.StringTokenizer;
  
  /**
   * @author <a href="mailto:[EMAIL PROTECTED]";>Jason van Zyl</a>
   * @version $Id: TestDependencyEngine.java,v 1.1 2001/08/26 16:21:41 jvanzyl Exp $
   */
  public class TestDependencyEngine 
      extends TestCase
  {
      private DependencyEngine d;
  
      public TestDependencyEngine(String testName)
      {
          super(testName);
      }
  
      public static Test suite()
      {
          return new TestSuite(TestDependencyEngine.class);
      }
  
      public static void main(String args[])
      {
          String[] testCaseName = { TestDependencyEngine.class.getName() };
          junit.textui.TestRunner.main(testCaseName);
      }
  
      public void setUp()
      {
          d = new DependencyEngine();
      }
      
      public void testProjectDependencies()
      {
          String cookieList = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
          
          try
          {
              addAlphabetProjects(d);            
              assertEquals(getCookieListString(d), cookieList);
          }
          catch(Exception e)
          {
              fail();
          }
      }
  
      public void testReset()
      {
          String cookieList = "";
          
          try
          {
              addAlphabetProjects(d);
              d.reset();
              assertEquals(getCookieListString(d), cookieList);
          }
          catch(Exception e)
          {
              fail();
          }
      }
  
      private void addAlphabetProjects(DependencyEngine d)
          throws Exception
      {
          d.addProject( "Z", deps("Y"));
          d.addProject( "Y", deps("X"));
          d.addProject( "X", deps("W"));
          d.addProject( "W", deps("V"));
          d.addProject( "V", deps("U"));
          d.addProject( "U", deps("T"));
          d.addProject( "T", deps("S"));
          d.addProject( "S", deps("R"));
          d.addProject( "R", deps("Q"));
          d.addProject( "Q", deps("P"));
          d.addProject( "P", deps("O"));
          d.addProject( "O", deps("N"));
          d.addProject( "N", deps("M"));
          d.addProject( "M", deps("L"));
          d.addProject( "L", deps("K"));
          d.addProject( "K", deps("J"));
          d.addProject( "J", deps("I"));
          d.addProject( "I", deps("H"));
          d.addProject( "H", deps("G"));
          d.addProject( "G", deps("F"));
          d.addProject( "F", deps("E"));
          d.addProject( "E", deps("D"));
          d.addProject( "D", deps("C"));
          d.addProject( "C", deps("B"));
          d.addProject( "B", deps("A"));
          d.addProject( "A", deps(null));
      }
  
      private String getCookieListString(DependencyEngine d)
          throws Exception
      {
          StringBuffer sb = new StringBuffer();
          List depList = d.generateCookielist();
          Iterator i = depList.iterator();
  
          while(i.hasNext())
          {
              sb.append((String) i.next());
          }
          
          return sb.toString();
      }
  
      private List deps(String project)
      {
          ArrayList deps = new ArrayList();
          
          if (project != null)
          {
              StringTokenizer st = new StringTokenizer(project, ",");
              
              while(st.hasMoreTokens())
              {
                  deps.add(st.nextToken());
              }
          }
          
          return deps;
      }        
  
      public void testMultiProjectDependency()
      {
          try
          {
              d.addProject("1", deps("A"));
          }
          catch( Exception e )
          {
          }
      }
  }
  
  
  

Reply via email to