Logo Search packages:      
Sourcecode: gant version File versions

void org::codehaus::gant::ant::tests::Gant_Test::testRunningAntFromShell (  )  [inline]

Test stemming from GANT-19 and relating to ensuring the right classpath when loading the Groovyc Ant task.

Definition at line 92 of file Gant_Test.java.

                                          {
    //
    //  This Ant task actually fails always and so the return code is 1.  If the Groovyc class cannot be
    //  loaded then the result is a message:
    //
    //    : taskdef class org.codehaus.groovy.ant.Groovyc cannot be found
    //
    //  whereas if it succeeds the message is more like:
    //
    //    [gant] Error evaluating Gantfile: startup failed, build_gant: 15: unable to resolve class org.codehaus.gant.ant.tests.Gant_Test
    //    [gant]  @ line 15, column 1.
    //    [gant] 1 error
    //    [gant] 
    //
    //  If Gant is compiled against Groovy 1.6-beta-1 then there is an infinite recursion in the metaclass
    //  system emanating from InvokerHelper as the Gant Ant task is started leading to a StackOverflowError,
    //  and so the correct output is not received.
    //
    final ProcessBuilder pb = new ProcessBuilder ( "ant" , "-f" , "src/test/groovy/org/codehaus/gant/ant/tests/gantTest.xml" ) ;
    try {
      final StringBuilder sb = new StringBuilder ( ) ;
      final Process p = pb.start ( ) ;  //  Could throw an IOException hence the try block.
      final BufferedReader br = new BufferedReader ( new InputStreamReader ( p.getInputStream ( ) ) ) ;
      final Thread readThread = new Thread ( ) {
          public void run ( ) {
            try {
              while ( true ) {
                final String line = br.readLine ( ) ;  //  Could throw an IOException hence the try block.
                if ( line == null ) { break ; }
                sb.append ( line ) ;
                sb.append ( System.getProperty ( "line.separator" ) ) ;
              }
            }
            catch ( final IOException ioe ) { fail ( "Got an IOException reading a line in the read thread." ) ; }
          }
        } ;
      readThread.start ( ) ;
      try { assertEquals ( 1 , p.waitFor ( ) ) ; }
      catch ( final InterruptedException ie ) { fail ( "Got an InterruptedException waiting for the Ant process to finish." ) ; }
      try { readThread.join ( ) ;}
      catch ( final InterruptedException ie ) { fail ( "Got an InterruptedException waiting for the read thread to terminate." ) ; }
      /*
       *  If the spawned Ant runs using Groovy 1.6-beta-2 then the full and complete error message is
       *  output.  If the spawned Ant user any previous version of Groovy then it fails to print things out.
       */
      assertEquals ( "Buildfile: src/test/groovy/org/codehaus/gant/ant/tests/gantTest.xml\n\n-initializeWithGroovyHome:\n\n-initializeNoGroovyHome:\n\ngantTestDefaultTarget:\n     [gant] Error evaluating Gantfile: startup failed, build_gant: 15: unable to resolve class org.codehaus.gant.ant.tests.Gant_Test\n     [gant]  @ line 15, column 1.\n     [gant] 1 error\n     [gant] \n", sb.toString ( ) ) ;
      /**/
    }
    catch ( final IOException ioe ) { fail ( "Got an IOException from starting the process." ) ; }
  }


Generated by  Doxygen 1.6.0   Back to index