/plugins/ClearCasePlugin/trunk/src/clearcase/ClearCasePlugin.java

# · Java · 291 lines · 194 code · 74 blank · 23 comment · 8 complexity · 5a94748af7f92196983deda88f855dad MD5 · raw file

  1. package clearcase;
  2. import java.io.IOException;
  3. import java.io.OutputStream;
  4. import org.gjt.sp.jedit.EditPlugin;
  5. import org.gjt.sp.jedit.MiscUtilities;
  6. import org.gjt.sp.jedit.jEdit;
  7. import org.gjt.sp.jedit.View;
  8. import org.gjt.sp.jedit.gui.DockableWindowManager;
  9. import org.gjt.sp.util.Log;
  10. import console.Console;
  11. import console.Shell;
  12. public class ClearCasePlugin extends EditPlugin implements ClearCaseConstants
  13. {
  14. public static ConsoleOutputStream output;
  15. private static int reloadDelay = FILE_RELOAD_DELAY;
  16. // private static final ClearCaseShell shell = new ClearCaseShell();
  17. public void start()
  18. {
  19. Log.log(Log.DEBUG, this, "ClearCase plugin started");
  20. }
  21. public void stop()
  22. {
  23. Log.log(Log.DEBUG, this, "ClearCase plugin stopped");
  24. }
  25. // ================================================
  26. // ClearTool Plugin methods
  27. // ================================================
  28. public static void checkOut(View view)
  29. {
  30. String file = view.getBuffer().getPath();
  31. CheckOutDialog dialog = new CheckOutDialog(view);
  32. Console console = showConsole(view, true);
  33. if(dialog.getExitValue().equals("Ok"))
  34. {
  35. CheckOut command = new CheckOut(file, dialog.getReserved(), dialog.getComment());
  36. executeClearToolCommand(view, command);
  37. // sleep for a few seconds to allow previous cleartool command to execute
  38. try { Thread.sleep(getFileReloadDelay()*1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
  39. view.getBuffer().reload(view);
  40. }
  41. }
  42. public static void checkIn(View view)
  43. {
  44. String file = view.getBuffer().getPath();
  45. CheckInDialog dialog = new CheckInDialog(view);
  46. if(dialog.getExitValue().equals("Ok"))
  47. {
  48. CheckIn command = new CheckIn(file, dialog.getComment());
  49. executeClearToolCommand(view, command);
  50. // sleep for a few seconds to allow previous cleartool command to execute
  51. try { Thread.sleep(getFileReloadDelay()*1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
  52. view.getBuffer().reload(view);
  53. }
  54. }
  55. public static void addToSourceControl(View view)
  56. {
  57. String file = view.getBuffer().getPath();
  58. AddToSourceControlDialog dialog = new AddToSourceControlDialog(view);
  59. if(dialog.getExitValue().equals("Ok"))
  60. {
  61. AddToSourceControl command = new AddToSourceControl(
  62. file,
  63. dialog.getKeepCheckedOut(),
  64. dialog.getCheckOutInParentDirectory(),
  65. dialog.getComment());
  66. if (dialog.getCheckOutInParentDirectory())
  67. {
  68. String parentOfPath = MiscUtilities.getParentOfPath(view.getBuffer().getPath());
  69. CheckOut parentDirCommand = new CheckOut(parentOfPath, true, "");
  70. executeClearToolCommand(view, parentDirCommand);
  71. // sleep for a few seconds to allow previous cleartool command to execute
  72. try { Thread.sleep(getFileReloadDelay()*1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
  73. }
  74. executeClearToolCommand(view, command);
  75. if (dialog.getCheckOutInParentDirectory())
  76. { // sleep for a few seconds to allow previous cleartool command to execute
  77. try { Thread.sleep(getFileReloadDelay()*1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
  78. String parentOfPath = MiscUtilities.getParentOfPath(view.getBuffer().getPath());
  79. CheckIn parentDirCommand = new CheckIn(parentOfPath, "");
  80. executeClearToolCommand(view, parentDirCommand);
  81. }
  82. // sleep for a few seconds to allow previous cleartool command to execute
  83. try { Thread.sleep(getFileReloadDelay()*1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
  84. view.getBuffer().reload(view);
  85. }
  86. }
  87. public static void unCheckOut(View view)
  88. {
  89. String file = view.getBuffer().getPath();
  90. UnCheckOutDialog dialog = new UnCheckOutDialog(view);
  91. if(dialog.getExitValue().equals("Ok"))
  92. {
  93. UnCheckOut command = new UnCheckOut(file, dialog.getKeepFile());
  94. executeClearToolCommand(view, command);
  95. // sleep for a few seconds to allow previous cleartool command to execute
  96. try { Thread.sleep(getFileReloadDelay()*1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
  97. view.getBuffer().reload(view);
  98. }
  99. }
  100. public static void updateBuffer(View view)
  101. {
  102. String file = view.getBuffer().getPath();
  103. Update command = new Update(file);
  104. executeClearToolCommand(view, new Update(file));
  105. }
  106. public static void showHistory(View view)
  107. {
  108. String file = view.getBuffer().getPath();
  109. ShowHistory command = new ShowHistory(file);
  110. command.setGraphical(true);
  111. executeClearToolCommand(view, command);
  112. }
  113. public static void compareToPreviousVersion(View view)
  114. {
  115. String file = view.getBuffer().getPath();
  116. ComparePreviousVersion command = new ComparePreviousVersion(file);
  117. command.setGraphical(true);
  118. executeClearToolCommand(view, command);
  119. }
  120. public static void showVersionTree(View view)
  121. {
  122. String file = view.getBuffer().getPath();
  123. ShowVersionTree command = new ShowVersionTree(file);
  124. command.setGraphical(true);
  125. executeClearToolCommand(view, command);
  126. }
  127. // ================================================
  128. // ClearCase Plugin methods
  129. // ================================================
  130. public static void findCheckouts(View view)
  131. {
  132. executeCommand(view, new FindCheckouts());
  133. }
  134. public static void showDetails(View view)
  135. {
  136. executeCommand(view, new ShowDetails());
  137. }
  138. public static void merge(View view)
  139. {
  140. executeCommand(view, new Merge());
  141. }
  142. // ================================================
  143. // Utility methods
  144. // ================================================
  145. public static void executeCommand(View view, Command command)
  146. {
  147. Log.log(Log.DEBUG, view, "Trying to execute command " + command);
  148. Console console = showConsole(view, true);
  149. // Run command send output to shell.
  150. try
  151. {
  152. OutputStream input = new ConsoleOutputStream( console.getInfoColor(), console );
  153. OutputStream error = new ConsoleOutputStream( console.getErrorColor(), console );
  154. // Exec command
  155. CommandExec exec = new CommandExec(command.getCommandLine(), input, error);
  156. exec.execute();
  157. }
  158. catch(IOException ex)
  159. {
  160. console.print(console.getErrorColor(), ex.getMessage());
  161. ex.printStackTrace();
  162. }
  163. catch(InterruptedException ex)
  164. {
  165. console.print(console.getErrorColor(), ex.getMessage());
  166. ex.printStackTrace();
  167. }
  168. finally
  169. {
  170. console.commandDone();
  171. }
  172. }
  173. public static void executeClearToolCommand(View view, ClearToolCommand command)
  174. {
  175. Log.log(Log.DEBUG, view, "Trying to execute command " + command);
  176. Console console = showConsole(view, true);
  177. Shell shell = console.setShell("ClearCase");
  178. // Run command send output to shell.
  179. try
  180. {
  181. // Exec command
  182. shell.execute(console, command.getCommandLine(), console.getOutput());
  183. }
  184. finally
  185. {
  186. }
  187. }
  188. /**
  189. * Shows console.
  190. */
  191. public static Console showConsole(View view, boolean focus)
  192. {
  193. DockableWindowManager wm = view.getDockableWindowManager();
  194. wm.showDockableWindow("console");
  195. Console console = (Console) wm.getDockable("console");
  196. console.setShell("ClearCase");
  197. // Set focus back to text area. Should maybe set to last view.
  198. if(focus == false)
  199. {
  200. view.getTextArea().requestFocus();
  201. }
  202. return console;
  203. }
  204. public static int getFileReloadDelay ()
  205. {
  206. try
  207. {
  208. reloadDelay = Integer.parseInt(jEdit.getProperty("clearcase.reloadDelay"));
  209. }
  210. catch (Exception ex)
  211. {
  212. jEdit.setProperty("clearcase.reloadDelay", "" + reloadDelay); // Slimy way to convert int value to string
  213. System.out.println("Problem loading clearcase.reloadDelay. Using default value = " + reloadDelay + " Exception: " + ex);
  214. }
  215. return reloadDelay;
  216. }
  217. }