Java? Come on! :)

I’m working on a patch for Maven Release. Now Brett asked me to write an integration test, to prove I’m actually fixing something.

The project uses Maven Verifier, which runs a pom and then lets you test whether it did the right thing or not by checking the build log.

Check, if a file has a string in it

I copied this java-code (verify.bsh) from a similar integration test. It reads the build.log and checks if it contains some string.

import java.util.*;
import java.util.regex.*;

    File buildLog = new File( basedir, "build.log" );
    System.out.println( "Checking logs.." );
    StringBuffer data = new StringBuffer( 1024 );
    BufferedReader reader = new BufferedReader( new FileReader( buildLog ) );
    char[] buf = new char[1024];
    int numRead = 0;
    while ( ( numRead = buf ) ) != -1 )
        String readData = String.valueOf( buf, 0, numRead );
        data.append( readData );
        buf = new char[1024];
    String contents = data.toString();

    String expected = "Executing goals 'clean verify' with arguments '-P profile-in-parent,it-repo'";
    if( contents.indexOf( expected ) != -1 )
        return true;
catch( Throwable t )
    return false;

System.out.println( "FAILED!" );
return false;

I now replaced this with following groovy code (verify.groovy):

expected = "[INFO] Executing goals 'clean verify' with arguments '-P it-repo,profile-in-parent'"

println "Expects \"$expected\" in build.log"
println "Checking logs..."

found = new File(basedir, "build.log" )

println found ? "GOOD!" : "FAILED!"

return found

Happy coding!