// Copyright 2002 by Basil Vandegriend.  All rights reserved.

package com.basilv.core;

import java.io.PrintWriter;
import java.text.DateFormat;
import java.util.Date;

/**
 * Utility class for application main functionality.
 */
public class AppUtilities
{

	/**
	 * Log application information to system out.
	 * 
	 * @param applicationName The name of the application to display. Cannot be
	 *        null or empty.
	 */
	public static void logApplicationInfoToSystemOut(String applicationName) {
		Assert.notNullOrEmpty("applicationName", applicationName);

		PrintWriter writer = new PrintWriter(System.out);

		writer.println();
		writer.println(applicationName);
		writer.println("Copyright 2008 by Basil Vandegriend.  All rights reserved.");
		writer.println();

		logExecutionInformation(writer);
	}

	/**
	 * Log execution information to the specified writer. Information logged
	 * includes the current date and time, and the working directory.
	 * 
	 * @param writer Cannot be null.
	 */
	public static void logExecutionInformation(PrintWriter writer) {
		Assert.notNull("writer", writer);

		Date curDate = new Date();
		DateFormat dateFormatter = DateFormat.getDateTimeInstance();
		String curDateAndTimeString = dateFormatter.format(curDate);

		writer.println("Executed on: " + curDateAndTimeString);
		writer.println("Working directory: " + System.getProperty("user.dir"));
		writer.println();

		writer.flush();
	}

}
