/*
 * Make_Bug_Report.bsh - a BeanShell macro script for the
 * jEdit text editor -  creates a new buffer with installation and
 * error information extracted from jEdit's Activity Log.
 * Copyright (C) 2001 John Gellene
 * jgellene@nyc.rr.com
 * http://community.jedit.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: Make_Bug_Report.bsh 3873 2001-11-06 17:57:35Z jgellene $
 *
 * Checked for jEdit 4.0 API
 *
 */

makeBugReport()
{
	Log.flushStream();
	path = jEdit.getSettingsDirectory() + File.separator
		+ "activity.log";
	try
	{
		file = new FileInputStream(path);
		reader = new BufferedReader(new InputStreamReader(file));
	}
	catch(IOException e)
	{
		Macros.error(view, "Error opening Activity Log.");
		return;
	}
	report = new StringBuffer();

	report.append("Activity log entries that might be useful in a bug report:\n\n");

	lastError = new StringBuffer();
	insideError = false;
	startupDone = false;
	activityLogHeaderLines = 9;
	try
	{
		for(i = 0; i < activityLogHeaderLines; ++i)
		{
			report.append(reader.readLine()).append('\n');
		}
		while((line = reader.readLine()) != null)
		{
			if(!startupDone &&
				(line.startsWith("[message] jEdit:")
					|| line.startsWith("[notice] jEdit:")
					|| line.startsWith("[notice] JARClassLoader:")))
			{
				report.append(line).append('\n');
				if(line.equals("[message] jEdit: Startup complete"))
				{
					startupDone = true;
				}
			}
			else if(line.startsWith("[error]"))
			{
				if(!insideError)
				{
					lastError.setLength(0);
					insideError = true;
				}
				lastError.append(line).append('\n');
			}
			else
				insideError = false;
		}
		reader.close();
	}
	catch(IOException e)
	{
		Macros.error(view, "Error reading Activity Log");
	}

	report.append(lastError.toString());
	newBuffer = jEdit.newFile(view);
	newBuffer.insert(0, report.toString());
}

makeBugReport();

/*
jEdit macro index data (DocBook format)

  <listitem>
    <para><filename>Make_Bug_Report.bsh</filename></para>
    <abstract><para>
      Creates a new buffer with installation and error information
	  extracted from the Activity Log.
    </para></abstract>
	<para>
	  The macro extracts initial messages written to the Activity Log
	  describing the user's operating system, JDK, jEdit version and
	  installed plugins. It then appends the last set of error messages
	  written to the Activity Log.  The new text buffer can be saved and
	  attached to an email message or a bug report made on SourceForge.
	</para>
  </listitem>

*/

// end Make_Bug_Report.bsh

