/plugins/JCompiler/tags/init/src/java/net/sourceforge/jedit/jcompiler/BuildMessage.java

# · Java · 205 lines · 110 code · 65 blank · 30 comment · 12 complexity · 22cdbc9259ede2429f7b7d2ae0fe88ef MD5 · raw file

  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License
  4. * as published by the Free Software Foundation; either version 2
  5. * of the License, or any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. package net.sourceforge.jedit.jcompiler;
  17. import net.sourceforge.jedit.buildtools.StaticLogger;
  18. import java.util.StringTokenizer;
  19. import java.io.File;
  20. public class BuildMessage {
  21. public final static int TYPE_UNKNOWN = -1;
  22. public final static int TYPE_EXCEPTION = 1;
  23. public final static int TYPE_BUILD = 2;
  24. private String message = "";
  25. private String target = "";
  26. private int type = 0;
  27. private int lineNumber = 0;
  28. private BuildMessage( String message,
  29. int type ) {
  30. this.message = message;
  31. this.type = type;
  32. }
  33. public BuildMessage( String message,
  34. String target,
  35. int type,
  36. int lineNumber ) {
  37. this.message = message;
  38. this.target = target;
  39. this.type = type;
  40. this.lineNumber = lineNumber;
  41. }
  42. public int getLineNumber() {
  43. return this.lineNumber;
  44. }
  45. public String getTarget() {
  46. return this.target;
  47. }
  48. public String getMessage() {
  49. return this.message;
  50. }
  51. public int getType() {
  52. return this.type;
  53. }
  54. /**
  55. Given a string... try to determine a build message and then return it.
  56. */
  57. public static BuildMessage getBuildMessage(String message) {
  58. BuildMessage buildMessage = null;
  59. switch (getMessageType(message) ) {
  60. case TYPE_EXCEPTION:
  61. buildMessage = getTypeExceptionMessage(message);
  62. break;
  63. case TYPE_BUILD:
  64. buildMessage = getTypeBuildMessage(message);
  65. break;
  66. case TYPE_UNKNOWN:
  67. buildMessage = new BuildMessage( message, TYPE_UNKNOWN );
  68. break;
  69. }
  70. return buildMessage;
  71. }
  72. private static BuildMessage getTypeExceptionMessage(String message) {
  73. /*
  74. StringTokenizer tokens = new StringTokenizer( message, ":" );
  75. if ( tokens.hasMoreElements()
  76. tokens.nextToken();
  77. String lineNumber = tokens.nextToken();
  78. */
  79. int lineNumber = 0;
  80. int lineStart = message.lastIndexOf(":");
  81. int lineEnd = message.lastIndexOf(")");
  82. if ( lineStart > -1 && lineEnd > -1 ) {
  83. lineNumber = Integer.parseInt( message.substring( lineStart + 1, lineEnd ) );
  84. }
  85. String trimmed = message.trim();
  86. int start = trimmed.indexOf(" ") + 1;
  87. int end = trimmed.indexOf("(");
  88. String classname = trimmed.substring( start, end );
  89. classname = classname.substring( 0, classname.lastIndexOf(".") );
  90. //remove any reference to an inner class
  91. if (classname.indexOf("$") > -1) {
  92. classname = classname.substring( 0, classname.indexOf("$") );
  93. }
  94. //ok... now use EditBus to request that a file get decompiled.
  95. String target = classname;
  96. return new BuildMessage( message,
  97. target,
  98. TYPE_EXCEPTION,
  99. lineNumber );
  100. }
  101. private static BuildMessage getTypeBuildMessage(String message) {
  102. int start = message.indexOf(".java:");
  103. if (start > 0) {
  104. start = start + 5;
  105. }
  106. int end = message.indexOf(':', start + 1);
  107. if (start < 0 || end < 0 || end - start <= 0) {
  108. return null;
  109. }
  110. String lineNumStr = message.substring(start+1, end);
  111. int lineNum = Integer.parseInt(lineNumStr);
  112. String errFile = message.substring(0, start);
  113. return new BuildMessage( message,
  114. errFile,
  115. TYPE_BUILD,
  116. lineNum );
  117. }
  118. private static int getMessageType( String message ) {
  119. //if the string begins with "at" return
  120. if ( message.trim().length() >= 2 && message.trim().substring(0, 2).equals("at") ) {
  121. return TYPE_EXCEPTION;
  122. }
  123. //exceptions begin with a file separated by a ":" so if this file exists
  124. //it is a build type
  125. StringTokenizer tokens = new StringTokenizer( message, ":" ) ;
  126. if ( tokens.hasMoreTokens() ) {
  127. if ( new File( tokens.nextToken() ).exists() ) {
  128. return TYPE_BUILD;
  129. }
  130. }
  131. return TYPE_UNKNOWN;
  132. }
  133. public void dump() {
  134. StaticLogger.log( "Message: " + this.getMessage() );
  135. StaticLogger.log( "Target: " + this.getTarget());
  136. StaticLogger.log( "Type: " + this.getType());
  137. StaticLogger.log( "LineNumber: " + this.getLineNumber());
  138. }
  139. }