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.io.*;
import java.util.*;
import java.util.regex.*;

try
{   
    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 = reader.read( buf ) ) != -1 )
    {
        String readData = String.valueOf( buf, 0, numRead );
        data.append( readData );
        buf = new char[1024];
    }
    reader.close();
    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 )
{
    t.printStackTrace();
    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" )
            .text
            .contains(expected)

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

return found

Happy coding!

RT: History of Programming Languages

.

.

1996 – James Gosling invents Java. Java is a relatively verbose, garbage collected, class based, statically typed, single dispatch, object oriented language with single implementation inheritance and multiple interface inheritance. Sun loudly heralds Java’s novelty.

2001 – Anders Hejlsberg invents C#. C# is a relatively verbose, garbage collected, class based, statically typed, single dispatch, object oriented language with single implementation inheritance and multiple interface inheritance. Microsoft loudly heralds C#’s novelty.

.

.

From: One Div Zero: A Brief, Incomplete, and Mostly Wrong History of Programming Languages