/bundles/plugins-trunk/JCompiler/jcompiler/JCompilerPlugin.java

# · Java · 144 lines · 76 code · 23 blank · 45 comment · 1 complexity · b46e3092eb451ef14f2576ad45c040d3 MD5 · raw file

  1. /*
  2. * JCompilerPlugin.java - JCompiler plugin
  3. * Copyright (c) 1999, 2000 Kevin A. Burton and Aziz Sharif
  4. *
  5. * :tabSize=4:indentSize=4:noTabs=false:maxLineLen=0:
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. package jcompiler;
  22. import java.io.File;
  23. import java.io.IOException;
  24. import java.util.Vector;
  25. import org.gjt.sp.jedit.jEdit;
  26. import org.gjt.sp.jedit.EditPlugin;
  27. import org.gjt.sp.jedit.GUIUtilities;
  28. import org.gjt.sp.jedit.JARClassLoader;
  29. import org.gjt.sp.jedit.MiscUtilities;
  30. import org.gjt.sp.jedit.OptionGroup;
  31. import org.gjt.sp.jedit.ServiceManager;
  32. import org.gjt.sp.jedit.View;
  33. import org.gjt.sp.jedit.gui.DockableWindowManager;
  34. import org.gjt.sp.jedit.gui.OptionsDialog;
  35. import org.gjt.sp.util.Log;
  36. import jcompiler.options.*;
  37. import console.Console;
  38. import console.Shell;
  39. public class JCompilerPlugin extends EditPlugin
  40. {
  41. /** holds a shared instance of the JCompiler shell. */
  42. private static final JCompilerShell shell =
  43. (JCompilerShell) ServiceManager.getService("console.Shell", "JCompiler");
  44. class ToolsJarNotFoundException extends RuntimeException
  45. {
  46. public ToolsJarNotFoundException(String message)
  47. {
  48. super(message);
  49. }
  50. }
  51. public void start()
  52. {
  53. if(!MiscUtilities.isToolsJarAvailable())
  54. {
  55. // I can't live without my tools.jar:
  56. throw new ToolsJarNotFoundException(
  57. "Could not find library tools.jar!\n"
  58. + "\n"
  59. + "This library is essential for the JCompiler plugin.\n"
  60. + "It is provided with a full Java Development Kit (JDK),\n"
  61. + "not a simple Java Runtime Environment (JRE).\n"
  62. + "You are probably running a JRE only.\n"
  63. + "\n"
  64. + "Further information:\n"
  65. + "tools.jar usually resides in {java.home}/../lib/.\n"
  66. + "Your java.home is " + System.getProperty("java.home") + "\n"
  67. + "\n"
  68. + "Please make sure that tools.jar is either in your\n"
  69. + "CLASSPATH or in the location mentioned above.\n"
  70. + "If that doesn't help, try adding it to jEdit's jars/ folder.");
  71. }
  72. }
  73. /**
  74. * Returns a shared JCompilerShell singleton instance.
  75. */
  76. public static JCompilerShell getShell()
  77. {
  78. return shell;
  79. }
  80. /**
  81. * Executes an arbitrary command in the JCompiler shell.
  82. * @see JCompilerShell for a list of supported commands.
  83. */
  84. public static void executeCommand(View view, String command)
  85. {
  86. // ensure Console window is visible:
  87. DockableWindowManager wm = view.getDockableWindowManager();
  88. wm.showDockableWindow("console");
  89. // set current Console shell to JCompilerShell:
  90. Console console = (Console) wm.getDockable("console");
  91. console.setShell(shell);
  92. // run the command:
  93. console.run(shell, command);
  94. // bugfix: textarea looses focus after compile:
  95. view.getTextArea().requestFocus();
  96. }
  97. /**
  98. * Invokes the command "compile" on the Shell instance,
  99. * compiling the current buffer.
  100. */
  101. public static void compileFile(View view)
  102. {
  103. executeCommand(view, "compile");
  104. }
  105. /**
  106. * Invokes the command "compilepkg" on the Shell instance,
  107. * compiling outdated files of the source tree containing current buffer.
  108. */
  109. public static void compilePackage(View view)
  110. {
  111. executeCommand(view, "compilepkg");
  112. }
  113. /**
  114. * Invokes the command "rebuildpkg" on the Shell instance,
  115. * recompiling all files of the source tree containing current buffer.
  116. */
  117. public static void rebuildPackage(View view)
  118. {
  119. executeCommand(view, "rebuildpkg");
  120. }
  121. }