package org.apache.maven.it;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStream;
import java.net.URL;

/**
 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
 * @version $Id$
 */
public class Verifier
{
    private String basedir;

    public Verifier( String basedir )
    {
        this.basedir = basedir;
    }

    // ----------------------------------------------------------------------
    //
    // ----------------------------------------------------------------------

    public void verify()
        throws VerificationException
    {
        try
        {
            BufferedReader reader = new BufferedReader( new FileReader( new File( basedir, "expected-results.txt" ) ) );

            String line = "";

            while ( ( line = reader.readLine() ) != null )
            {
                verifyExpectedResult( line );
            }
        }
        catch ( Exception e )
        {
            throw new VerificationException( e );
        }
        
        System.out.println( "-------------------------------------" );
        
        System.out.println( "OK" );
        
        System.out.println( "-------------------------------------" );
    }

    private void verifyExpectedResult( String line )
        throws VerificationException
    {
        if ( line.indexOf( "!/" ) > 0 )
        {
            String urlString = "jar:file:" + line;

            try
            {
                URL url = new URL( urlString );

                InputStream is = url.openStream();

                if ( is == null )
                {
                    throw new VerificationException( "Expected JAR resource was not found: " + line );
                }
            }
            catch ( Exception e )
            {
                throw new VerificationException( "Expected JAR resource was not found: " + line );
            }
        }
        else
        {
            File expectedFile = new File( basedir, line );

            if ( !expectedFile.exists() )
            {
                throw new VerificationException( "Expected file was not found: " + line );
            }
        }
    }

    // ----------------------------------------------------------------------
    //
    // ----------------------------------------------------------------------

    public static void main( String args[] )
        throws VerificationException
    {
        Verifier verifier = new Verifier( args[0] );

        verifier.verify();
    }
}

@@ -1016,32 +1016,69 @@
 ( e );%0A        %7D
+%0A%0A        System.out.println( %22%5Cn%22 );
 %0A        %0A      
@@ -1180,16 +1180,33 @@
 intln( %22
+Integration test 
 OK%22 );%0A 

make it clear it is the integration test that passed and not just the tests