/plugins/AntFarm/tags/antfarm-0_4/AntFarmPlugin.java

# · Java · 222 lines · 73 code · 22 blank · 127 comment · 7 complexity · 6a50a52edb1144df01c1f7975596b8bf MD5 · raw file

  1. /*
  2. * AntFarmPlugin.java - Ant build utility plugin for jEdit
  3. * Copyright (C) 2000 Chris Scott
  4. * Other contributors: Rick Gibbs
  5. *
  6. * The Apache Software License, Version 1.1
  7. *
  8. * Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
  9. * reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. *
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in
  20. * the documentation and/or other materials provided with the
  21. * distribution.
  22. *
  23. * 3. The end-user documentation included with the redistribution, if
  24. * any, must include the following acknowlegement:
  25. * "This product includes software developed by the
  26. * Apache Software Foundation (http://www.apache.org/)."
  27. * Alternately, this acknowlegement may appear in the software itself,
  28. * if and wherever such third-party acknowlegements normally appear.
  29. *
  30. * 4. The names "The Jakarta Project", "Ant", and "Apache Software
  31. * Foundation" must not be used to endorse or promote products derived
  32. * from this software without prior written permission. For written
  33. * permission, please contact apache@apache.org.
  34. *
  35. * 5. Products derived from this software may not be called "Apache"
  36. * nor may "Apache" appear in their names without prior written
  37. * permission of the Apache Group.
  38. *
  39. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  40. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  41. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  42. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  43. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  44. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  45. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  46. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  47. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  48. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  49. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  50. * SUCH DAMAGE.
  51. * ====================================================================
  52. *
  53. * This software consists of voluntary contributions made by many
  54. * individuals on behalf of the Apache Software Foundation. For more
  55. * information on the Apache Software Foundation, please see
  56. * <http://www.apache.org/>.
  57. */
  58. /**
  59. @author Chris Scott, Rick Gibbs
  60. */
  61. import org.gjt.sp.jedit.*;
  62. import org.gjt.sp.jedit.gui.*;
  63. import org.gjt.sp.jedit.msg.*;
  64. import java.awt.Color;
  65. import java.awt.event.ActionEvent;
  66. import java.awt.Component;
  67. import java.util.Vector;
  68. import java.io.*;
  69. /**
  70. * The 'Plugin' class is the interface between jEdit and the plugin.
  71. * Plugins can either extend EditPlugin or EBPlugin. EBPlugins have
  72. * the additional property that they receive EditBus messages.
  73. */
  74. public class AntFarmPlugin extends EBPlugin
  75. {
  76. /**
  77. * The 'name' of our dockable window.
  78. */
  79. public static final String NAME = "antfarm";
  80. private static DefaultErrorSource errorSource;
  81. static PrintStream out = System.out;
  82. static PrintStream err = System.err;
  83. private View theView;
  84. /**
  85. * Method called by jEdit to initialize the plugin.
  86. */
  87. public void start()
  88. {
  89. errorSource = new DefaultErrorSource("antfarm");
  90. EditBus.addToNamedList(ErrorSource.ERROR_SOURCES_LIST,errorSource);
  91. EditBus.addToBus(errorSource);
  92. // add our dockable to the dockables 'named list'
  93. EditBus.addToNamedList(DockableWindow.DOCKABLE_WINDOW_LIST,NAME);
  94. // save System.out and err in case we need them
  95. //out = System.out;
  96. //err = System.err;
  97. }
  98. /**
  99. * Method called by jEdit before exiting. Usually, nothing
  100. * needs to be done here.
  101. */
  102. //public void stop() {}
  103. /**
  104. * Method called every time a view is created to set up the
  105. * Plugins menu. Menus and menu items should be loaded using the
  106. * methods in the GUIUtilities class, and added to the list.
  107. * @param menuItems Add the menu item here
  108. */
  109. public void createMenuItems(Vector menuItems)
  110. {
  111. menuItems.addElement(GUIUtilities.loadMenuItem("antfarm"));
  112. }
  113. /**
  114. * Method called every time the plugin options dialog box is
  115. * displayed. Any option panes created by the plugin should be
  116. * added here.
  117. * @param optionsDialog The plugin options dialog box
  118. *
  119. * @see OptionPane
  120. * @see OptionsDialog#addOptionPane(OptionPane)
  121. */
  122. //public void createOptionPanes(OptionsDialog optionsDialog) {}
  123. /**
  124. * Handles a message sent on the EditBus. The default
  125. * implementation ignores the message.
  126. */
  127. public void handleMessage(EBMessage message)
  128. {
  129. /* upon receiving a CreateDockableWindow, we check if
  130. * the name of the requested window is 'hello-dockable',
  131. * and create it if it is so.
  132. */
  133. if(message instanceof CreateDockableWindow)
  134. {
  135. CreateDockableWindow cmsg = (CreateDockableWindow)message;
  136. theView = cmsg.getView();
  137. if(cmsg.getDockableWindowName().equals(NAME))
  138. //cmsg.setDockableWindow(new AntFarm(this, cmsg.getView()));
  139. cmsg.setDockableWindow(AntFarm.setAntFarm(this, theView));
  140. }
  141. }
  142. /**
  143. * Handle all of ANT's build messages including System.out and System.err
  144. *
  145. * Each build message filename, line no, column, of the error that it is
  146. * reporting if it in fact is an Error. You can use this info some how
  147. * to publish an event to the Error List
  148. *
  149. * TODO: handle System.err messages with a different color.
  150. */
  151. void handleBuildMessage( BuildMessage message )
  152. {
  153. handleBuildMessage( message, null);
  154. }
  155. void handleBuildMessage( BuildMessage message, Color lineColor )
  156. {
  157. if( message.isError() )
  158. {
  159. // publish this message to the ErrorList
  160. addError( ErrorSource.ERROR, message.getAbsoluteFilename(),
  161. message.getLine(), message.getColumn(),
  162. message.toString() ); //message.getMessage() );
  163. // "error-list" should be ErrorListPlugin.NAME but the
  164. // jar could be in a couple of different places...
  165. theView.getDockableWindowManager().addDockableWindow("error-list");
  166. }
  167. else if( message.isWarning() )
  168. {
  169. // publish this message to the ErrorList
  170. addError( ErrorSource.WARNING, message.getAbsoluteFilename(),
  171. message.getLine(), message.getColumn(),
  172. message.toString() ); //message.getMessage() );
  173. // "error-list" should be ErrorListPlugin.NAME but the
  174. // jar could be in a couple of different places...
  175. theView.getDockableWindowManager().addDockableWindow("error-list");
  176. }
  177. else
  178. {
  179. // publish this message to the buildResults text area
  180. //out.println("[MESSAGE]: " + message.toString() );
  181. if (lineColor != null)
  182. AntFarm.getAntFarm().appendToTextArea(message.toString(), lineColor);
  183. else
  184. AntFarm.getAntFarm().appendToTextArea(message.toString());
  185. }
  186. }
  187. void addError(int type, String file, int line, int column, String message)
  188. {
  189. /** this method call is a hack.. the signature of the method call is:
  190. * addError(int type, String path, int lineIndex, int start, int end, String error)
  191. * I don't know what 'start' and 'end' do
  192. * The -1 is a hack to make the error point to the correct place
  193. */
  194. errorSource.addError(type,file,line - 1,0,0,message);
  195. }
  196. void clearErrors()
  197. {
  198. errorSource.clear();
  199. }
  200. }