vert-x/vert.x — pull request #479 by darylteo (2012-12-29 16:30:10+00:00)
Title: Improvements to require() for Vertx 2.0 

Changelog:

[Fix] #450 Script loading using require() not load.
- [Fix] vertx.js no longer pollutes global namespace. See Test: [JavaScriptScriptLoadingTest](https://github.com/darylteo/vert.x/blob/b6e0bf12cbbc5ffe1849c76b3438e806fec1ff91/vertx-testsuite/src/test/java/org/vertx/java/tests/core/scriptloading/JavaScriptScriptLoadingTest.java)
- [Enhancement] Console is now injected from RhinoVerticle, and not vertx.js

[Fix] Tests all use require instead of load.
[Fix] require looks for [index.json](https://github.com/vert-x/vert.x/blob/vertx20/vertx-lang/vertx-lang-rhino/src/main/java/org/vertx/java/deploy/impl/rhino/RhinoVerticle.java#L104), not index.js when loading CommonJS packages.

[Enhancement] Refactoring
[Enhancement] Cleanup

[New] Require also looks for index.coffee as a failsafe when searching for main js file

**All tests should pass.**

./mk -Dtest.single=JavaScript* :vertx-testsuite:test

Notes while I was coding:
- this pull request is for **vertx20**, not vertx master.
- generating of CoffeeScript into Javascript. Generated file is saved [in the same directory](https://github.com/vert-x/vert.x/blob/vertx20/vertx-lang/vertx-lang-rhino/src/main/java/org/vertx/java/deploy/impl/rhino/CoffeeScriptCompiler.java#L66) as the original file... perhaps these should be saved in a "tmp" directory?
- while on the topic of "tmp" directory, there could perhaps be a "createTempFile" available through vertx FileSystem? I'm not sure how safe system's /tmp directory is, but there is already an [convenient way](http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#createTempDirectory\(java.nio.file.Path, java.lang.String, java.nio.file.attribute.FileAttribute...\)) to achieve this.
- documentation needs to be done for require. #157 If this gets merged into 2.0 I'll gladly update the docs.
- while attempting on a solution for #465, I discovered that I could not use the classloader to load resources/classes from the mod directory. I suspect I will need to write a package loading classloader to support that... but I will continue on it until this gets merged in hopefully.
- tbh with the release of V2.0, I don't believe we should support "load". Previously load was left in by nelsonsilva to support older verticles. With V2.0, I believe we should at least deprecate it, if not remove it completely.
- we may need to revise the nomenclature with regards to modules. There're vertx modules, non-runnable vertx modules, then CommonJS packages and modules.
- sorry I'm still quite a git noob, so I didn't know how to squash commits, thus the barrage of commits.

Kind Regards,
Daryl