ImportAll.hx 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C)2005-2015 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. import haxe.macro.Context;
  23. class ImportAll {
  24. public static function run( ?pack ) {
  25. if( pack == null ) {
  26. pack = "";
  27. haxe.macro.Compiler.define("doc_gen");
  28. }
  29. switch( pack ) {
  30. case "php":
  31. if( !Context.defined("php") ) return;
  32. case "neko":
  33. if( !Context.defined("neko") ) return;
  34. case "js":
  35. if( !Context.defined("js") ) return;
  36. case "cpp":
  37. if( !Context.defined("cpp") ) return;
  38. case "flash":
  39. if( !Context.defined("flash9") ) return;
  40. case "sys":
  41. if( !Context.defined("neko") && !Context.defined("php") && !Context.defined("cpp") ) return;
  42. case "java":
  43. if( !Context.defined("java") ) return;
  44. case "cs":
  45. if( !Context.defined("cs") ) return;
  46. case "python":
  47. if( !Context.defined("python") ) return;
  48. case "tools":
  49. return;
  50. case "build-tool":
  51. return;
  52. }
  53. for( p in Context.getClassPath() ) {
  54. if( p == "/" )
  55. continue;
  56. // skip if we have a classpath to haxe
  57. if( pack.length == 0 && sys.FileSystem.exists(p+"std") )
  58. continue;
  59. var p = p + pack.split(".").join("/");
  60. if( StringTools.endsWith(p,"/") )
  61. p = p.substr(0,-1);
  62. if( !sys.FileSystem.exists(p) || !sys.FileSystem.isDirectory(p) )
  63. continue;
  64. for( file in sys.FileSystem.readDirectory(p) ) {
  65. if( file == ".svn" || file == "_std" )
  66. continue;
  67. var full = (pack == "") ? file : pack + "." + file;
  68. if( StringTools.endsWith(file, ".hx") ) {
  69. var cl = full.substr(0, full.length - 3);
  70. switch( cl ) {
  71. case "ImportAll", "neko.db.MacroManager": continue;
  72. case "haxe.TimerQueue": if( Context.defined("neko") || Context.defined("php") || Context.defined("cpp") ) continue;
  73. case "Sys": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("cpp")) ) continue;
  74. case "haxe.web.Request": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("js")) ) continue;
  75. case "haxe.macro.ExampleJSGenerator","haxe.macro.Context", "haxe.macro.Compiler": if( !Context.defined("neko") ) continue;
  76. case "haxe.remoting.SocketWrapper": if( !Context.defined("flash") ) continue;
  77. case "haxe.remoting.SyncSocketConnection": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("cpp")) ) continue;
  78. case "sys.db.Sqlite" | "sys.db.Mysql" | "cs.db.AdoNet": continue;
  79. }
  80. Context.getModule(cl);
  81. } else if( sys.FileSystem.isDirectory(p + "/" + file) )
  82. run(full);
  83. }
  84. }
  85. }
  86. }