//  Gant -- A Groovy build framework based on scripting Ant tasks.
//
//  Copyright © 2006-8 Russel Winder
//
//  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
//  compliance with the License. You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software distributed under the License is
//  distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
//  implied. See the License for the specific language governing permissions and limitations under the
//  License.

package org.codehaus.gant.tests ;

import java.util.List ;

import java.io.ByteArrayInputStream ;
import java.io.ByteArrayOutputStream ;
import java.io.PrintStream ;

import groovy.util.GroovyTestCase ;

import gant.Gant ;

import org.codehaus.groovy.runtime.InvokerHelper ;

/**
 *  A Gant test case: Adds the required input stream manipulation features to avoid replication of code.
 *  Also prepare a new instance of Gant for each test.
 *
 *  @author Russel Winder <russel.winder@concertant.com>
 */
public abstract class GantTestCase extends GroovyTestCase {
  public static final int groovyMajorVersion ;
  public static final int groovyMinorVersion ;
  static {
    final String[] version =  InvokerHelper.getVersion ( ).split ( "[.-]" , 3 ) ;
    groovyMajorVersion = Integer.parseInt ( version[0] ) ;
    groovyMinorVersion = Integer.parseInt ( version[1] ) ;
  }
  public static final boolean isWindows ;
  static {
    final String osName = System.getProperty ( "os.name" ) ;
    isWindows = ( osName.length ( ) > 6 ) ? osName.substring ( 0 , 7 ).equals ( "Windows" ) : false ;
  }
  private ByteArrayOutputStream output ;
  private PrintStream savedOut ;
  protected Gant gant ;
  protected String script ;
  protected void setUp ( ) {
    savedOut = System.out ;
    output = new ByteArrayOutputStream ( ) ;
    System.setOut ( new PrintStream ( output ) ) ;
    gant = new Gant ( "-" ) ;
    script = "" ;
  }
  protected void tearDown ( ) { System.setOut ( savedOut ) ; }
  protected void setScript ( final String script ) { System.setIn ( new ByteArrayInputStream ( script.getBytes ( ) ) ) ; }
  protected int processTargets ( ) { return gant.processTargets ( ) ; }
  protected int processTargets ( final String s ) { return gant.processTargets ( s ) ; }
  protected int processTargets ( final List<String> l ) { return gant.processTargets ( l ) ; }  
  protected String getOutput ( ) { return output.toString ( ).replace ( "\r" , "" ) ; }

  //  For some reason, some tests, but not all tests, output the results of various tasks run by Gant before
  //  the script is excuted.

  protected static final String prefixMaterial = "  [taskdef] classname : 'org.codehaus.groovy.ant.Groovyc' , name : 'groovyc'\n [property] environment : 'environment'\n" ;
  
}

@@ -2625,23 +2625,33 @@
 //  
-For some reason
+When run with Ant or Gant
 , so
@@ -2721,16 +2721,22 @@
 s run by
+%0A  // 
  Gant be
@@ -2739,22 +2739,16 @@
 t before
-%0A  // 
  the scr
@@ -2762,16 +2762,218 @@
 excuted.
+  When run with Maven this message is output in far more situations.%0A  //  It is not entirely clear why this is happening.  For now Ant and Gant runthe tests correctly and Maven%0A  //  has many failures.
 %0A%0A  prot

Add a few more words of comment about the different behaviours of Ant and Gant on the one hand and Maven on the other. The tests are set upto work fine with Ant and Gant, which means they fail with Maven.