PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/bsh/commands/run.bsh

#
Unknown | 61 lines | 51 code | 10 blank | 0 comment | 0 complexity | 02057685cef6ea8713b94358f411731e MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /**
  2. Run a command in its own in its own private global namespace, with its
  3. own class manager and interpeter context. (kind of like unix "chroot" for
  4. a namespace).
  5. The root bsh system object is extended (with the extend() command) and
  6. made visible here, so that general system info (e.g. current working
  7. directory) is effectively inherited. Because the root bsh object is
  8. extended it is effectively read only / copy on write...
  9. e.g. you can change directories in the child context, do imports, change
  10. the classpath, etc. and it will not affect the calling context.
  11. <p>
  12. run() is like source() except that it runs the command in a new,
  13. subordinate and prune()'d namespace. So it's like "running" a command
  14. instead of "sourcing" it. run() teturns the object context in which the
  15. command was run.
  16. <p>
  17. Returns the object context so that you can gather results.
  18. <p>
  19. Parameter runArgument an argument passed to the child context under the
  20. name runArgument. e.g. you might pass in the calling This context
  21. from which to draw variables, etc.
  22. <p>
  23. @return Returns the object context so that you can gather results.
  24. @param runArgument an argument passed to the child context under the
  25. name runArgument. e.g. you might pass in the calling This context
  26. from which to draw variables, etc.
  27. */
  28. bsh.help.run= "usage: Thread run( filename )";
  29. run( String filename, Object runArgument )
  30. {
  31. // Our local namespace is going to be the new root (global)
  32. // make local copies of the system stuff.
  33. //
  34. // Extend the root system object
  35. // this is problematic... probably need more here...
  36. this.bsh=extend(global.bsh);
  37. this.bsh.help=extend(bsh.help);
  38. // save the classpath before pruning
  39. this.cp = this.caller.namespace.getClassManager()
  40. .getClassPath().getUserClassPathComponents();
  41. // Cut us off... make us the root (global) namespace for this command
  42. // Prune() will also create a new class manager for us.
  43. this.namespace.prune();
  44. // Inherit user classpath
  45. this.namespace.getClassManager().setClassPath( cp );
  46. this.interpreter.source( filename, this.namespace );
  47. return this;
  48. }
  49. run( String filename ) {
  50. run( filename, null );
  51. }