/jEdit/trunk/macros/Misc/Make_Bug_Report.bsh

# · Unknown · 129 lines · 118 code · 11 blank · 0 comment · 0 complexity · efb311284d86cc460835af02a3b7575e MD5 · raw file

  1. /*
  2. * Make_Bug_Report.bsh - a BeanShell macro script for the
  3. * jEdit text editor - creates a new buffer with installation and
  4. * error information extracted from jEdit's Activity Log.
  5. * Copyright (C) 2001 John Gellene
  6. * jgellene@nyc.rr.com
  7. * http://community.jedit.org
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. * $Id: Make_Bug_Report.bsh 21353 2012-03-14 09:46:51Z jojaba_67 $
  24. *
  25. * Checked for jEdit 4.0 API
  26. *
  27. */
  28. // Localization
  29. final static String OpeningActivityLogError = jEdit.getProperty("macro.rs.MakeBugReport.OpeningActivityLog.error", "Error opening Activity Log.");
  30. final static String UsefulEntriesForReportLabel = jEdit.getProperty("macro.rs.MakeBugReport.UsefulEntriesForReport.label", "Activity log entries that might be useful in a bug report:\n\n.");
  31. final static String MessagejEditLabel = jEdit.getProperty("macro.rs.MakeBugReport.MessagejEdit.label", "[message] jEdit:");
  32. final static String NoticejEditLabel = jEdit.getProperty("macro.rs.MakeBugReport.NoticejEdit.label", "[notice] jEdit:");
  33. final static String NoticeJarClassLoaderLabel = jEdit.getProperty("macro.rs.MakeBugReport.NoticeJarClassLoader.label", "[notice] JARClassLoader:");
  34. final static String MessagejEditStartupCompleteLabel = jEdit.getProperty("macro.rs.MakeBugReport.MessagejEditStartupComplete.label", "[message] jEdit: Startup complete");
  35. final static String ErrorLabel = jEdit.getProperty("macro.rs.MakeBugReport.Error.label", "[error]");
  36. final static String ReadingActivityLogError = jEdit.getProperty("macro.rs.MakeBugReport.ReadingActivityLog.error", "Error reading Activity Log");
  37. // Process
  38. makeBugReport()
  39. {
  40. Log.flushStream();
  41. path = jEdit.getSettingsDirectory() + File.separator
  42. + "activity.log";
  43. try
  44. {
  45. file = new FileInputStream(path);
  46. reader = new BufferedReader(new InputStreamReader(file));
  47. }
  48. catch(IOException e)
  49. {
  50. Macros.error(view, OpeningActivityLogError);
  51. return;
  52. }
  53. report = new StringBuffer();
  54. report.append(UsefulEntriesForReportLabel);
  55. lastError = new StringBuffer();
  56. insideError = false;
  57. startupDone = false;
  58. activityLogHeaderLines = 250;
  59. try
  60. {
  61. for(i = 0; i < activityLogHeaderLines; ++i)
  62. {
  63. report.append(reader.readLine()).append('\n');
  64. }
  65. while((line = reader.readLine()) != null)
  66. {
  67. if(!startupDone &&
  68. (line.startsWith(MessagejEditLabel)
  69. || line.startsWith(NoticejEditLabel)
  70. || line.startsWith(NoticeJarClassLoaderLabel)))
  71. {
  72. report.append(line).append('\n');
  73. if(line.equals(MessagejEditStartupCompleteLabel))
  74. {
  75. startupDone = true;
  76. }
  77. }
  78. else if(line.startsWith(ErrorLabel))
  79. {
  80. if(!insideError)
  81. {
  82. lastError.setLength(0);
  83. insideError = true;
  84. }
  85. lastError.append(line).append('\n');
  86. }
  87. else
  88. insideError = false;
  89. }
  90. reader.close();
  91. }
  92. catch(IOException e)
  93. {
  94. Macros.error(view, ReadingActivityLogError);
  95. }
  96. report.append(lastError.toString());
  97. newBuffer = jEdit.newFile(view);
  98. newBuffer.insert(0, report.toString());
  99. }
  100. makeBugReport();
  101. /*
  102. jEdit macro index data (DocBook format)
  103. <listitem>
  104. <para><filename>Make_Bug_Report.bsh</filename></para>
  105. <abstract><para>
  106. Creates a new buffer with installation and error information
  107. extracted from the Activity Log.
  108. </para></abstract>
  109. <para>
  110. The macro extracts initial messages written to the Activity Log
  111. describing the user's operating system, JDK, jEdit version and
  112. installed plugins. It then appends the last set of error messages
  113. written to the Activity Log. The new text buffer can be saved and
  114. attached to an email message or a bug report made on SourceForge.
  115. </para>
  116. </listitem>
  117. */
  118. // end Make_Bug_Report.bsh