| 1 |
= Jerbil -- Java build extensions for Rake |
|---|
| 2 |
|
|---|
| 3 |
"If I knew then what I know now, I would have tried using a real |
|---|
| 4 |
scripting language, such as JavaScript via the Rhino component or |
|---|
| 5 |
Python via JPython, with bindings to Java objects which implemented |
|---|
| 6 |
the functionality expressed in todays tasks. Then, there would be a |
|---|
| 7 |
first class way to express logic and we wouldn't be stuck with XML as |
|---|
| 8 |
a format that is too bulky for the way that people really want to use |
|---|
| 9 |
the tool." |
|---|
| 10 |
|
|---|
| 11 |
-- James Duncan Davidson, creator of Apache Ant |
|---|
| 12 |
|
|---|
| 13 |
This package contains several tasklibs for Rake[http://rake.rubyforge.org] which can be |
|---|
| 14 |
used to build Java projects. |
|---|
| 15 |
|
|---|
| 16 |
Jerbil uses Rjb[http://rjb.rubyforge.org/] |
|---|
| 17 |
(Ruby-Java-Bridge) to load a Java virtual machine into the Ruby process running Rake. |
|---|
| 18 |
|
|---|
| 19 |
The JVM is then used to compile Java source files, create javadocs etc. |
|---|
| 20 |
It is not a complete replacement for ant (yet), but has several advantages such as |
|---|
| 21 |
extremly compact build files and easy scriptability. |
|---|
| 22 |
|
|---|
| 23 |
The main focus at the moment are small to medium-sized projects using |
|---|
| 24 |
testng[http://testng.org] and hibernate[http://hibernate.org]. |
|---|
| 25 |
|
|---|
| 26 |
== Requirements |
|---|
| 27 |
|
|---|
| 28 |
Jerbil requires rubygems[http://rubygems.org], Rake, Rjb[http://rjb.rubyforge.org/], |
|---|
| 29 |
builder[http://builder.rubyforge.org/] and JDK 1.5. |
|---|
| 30 |
|
|---|
| 31 |
== Installation |
|---|
| 32 |
|
|---|
| 33 |
You need to have Ruby and rubygems installed. The Windows version of Ruby already ships with rubygems |
|---|
| 34 |
preinstalled. On Debian systems (testing) you can install it using apt-get: |
|---|
| 35 |
|
|---|
| 36 |
% apt-get install rubygems |
|---|
| 37 |
|
|---|
| 38 |
Rake, Rjb and builder are best installed using gem: |
|---|
| 39 |
|
|---|
| 40 |
% gem install rake |
|---|
| 41 |
% gem install builder |
|---|
| 42 |
% gem install rjb |
|---|
| 43 |
|
|---|
| 44 |
The installation of Rjb can be a bit tricky for non-Windows users because |
|---|
| 45 |
JAVA_HOME needs to be set up correctly. Also, a C compiler is required in order to |
|---|
| 46 |
build the JNI extension for Ruby. |
|---|
| 47 |
|
|---|
| 48 |
Finally jerbil needs to be installed: |
|---|
| 49 |
|
|---|
| 50 |
% gem install jerbil --source http://code.trampolinesystems.com |
|---|
| 51 |
|
|---|
| 52 |
Jerbil might become an 'official' rubygem at some later point. Note that some tasks require additional |
|---|
| 53 |
jar files, for example Jerbil::TestNG::TestNGTask. |
|---|
| 54 |
|
|---|
| 55 |
The source code is available via subversion: http://svn.trampolinesystems.com/jerbil/trunk |
|---|
| 56 |
|
|---|
| 57 |
== Usage |
|---|
| 58 |
|
|---|
| 59 |
A minimal Rakefile to compile Java files could look like this: |
|---|
| 60 |
|
|---|
| 61 |
require 'jerbil' |
|---|
| 62 |
|
|---|
| 63 |
CLASSPATH = FileList[ "./lib/*.jar" ] |
|---|
| 64 |
BUILD_DIR = "build" |
|---|
| 65 |
FILES = JavaFileList.new("src", BUILD_DIR) |
|---|
| 66 |
|
|---|
| 67 |
load_jvm(CLASSPATH, BUILD_DIR) |
|---|
| 68 |
|
|---|
| 69 |
Jerbil::JavacTask.new(:compile, FILES) |
|---|
| 70 |
|
|---|
| 71 |
The JVM gets loaded once via the Jerbil::JavaHelper load_jvm method. This initialization step is |
|---|
| 72 |
required, otherwise the task will fail. <tt>Jerbil::JavacTask.new(:compile, FILES)</tt> |
|---|
| 73 |
defines a new task (<tt>:compile</tt>) which will compile all Java files found in directory |
|---|
| 74 |
+src+ to +build+. |
|---|
| 75 |
|
|---|
| 76 |
=== Debugging |
|---|
| 77 |
|
|---|
| 78 |
As all the code runs in a single JVM, debugging can only be enabled on a global level. |
|---|
| 79 |
Just add the environment variable +JAVA_DEBUG+. |
|---|
| 80 |
|
|---|
| 81 |
% JAVA_DEBUG='1' rake test |
|---|
| 82 |
|
|---|
| 83 |
This will load the JVM in debug mode, listening on port 8000. To specify a different port, |
|---|
| 84 |
use JAVA_DEBUG='port=33333'. Adding +suspend+ to the +JAVA_DEBUG+ environment will suspend execution |
|---|
| 85 |
until the debugging client connects. |
|---|
| 86 |
|
|---|
| 87 |
=== Specifiying additional jvm options |
|---|
| 88 |
|
|---|
| 89 |
% JAVA_OPTS = '-Xmx=256M' rake test |
|---|
| 90 |
or |
|---|
| 91 |
load_jvm(CLASSPATH, BUILD, :java_opts=>"-Xmx=256M") |
|---|
| 92 |
|
|---|
| 93 |
== Example |
|---|
| 94 |
|
|---|
| 95 |
See the example/[http://svn.trampolinesystems.com/jerbil/trunk/example] subdirectory |
|---|
| 96 |
in the repository. |
|---|
| 97 |
|
|---|
| 98 |
% svn co http://svn.trampolinesystems.com/jerbil/trunk/example |
|---|
| 99 |
|
|---|
| 100 |
== Advantages over Ant |
|---|
| 101 |
|
|---|
| 102 |
See Martin Fowler's article[http://www.martinfowler.com/articles/rake.html] for a detailed |
|---|
| 103 |
discussion on Rake vs. Ant. Besides the more compact build scripts you also get ability to |
|---|
| 104 |
implement arbitrary Java interfaces in Ruby (see Jerbil::TestNG::DefaultTestListener for an example). |
|---|
| 105 |
Another possibility is build script metaprogramming, i.e. creating your tasks programmatically: |
|---|
| 106 |
|
|---|
| 107 |
MODULES = [ "common", "core", "server" ] |
|---|
| 108 |
MODULES.each_with_index do |m,i| |
|---|
| 109 |
Jerbil::JavacTask.new("compile_#{m}") do |t| |
|---|
| 110 |
t.java_files = JavaFileList.new(File.join(m,SRC_DIR), DST_DIR) |
|---|
| 111 |
MODULES[0..i-1].each { |
|---|
| 112 |
|prev| t.depends_on "compile_#{prev}" |
|---|
| 113 |
} if i>0 |
|---|
| 114 |
end |
|---|
| 115 |
end |
|---|
| 116 |
|
|---|
| 117 |
This snippet creates several build targets (+:compile_common+, +:compile_core+, |
|---|
| 118 |
+:compile_server+) including correct dependency setup. |
|---|
| 119 |
|
|---|
| 120 |
Lastly, all the tasks run in one single JVM, speeding up the build significantly. |
|---|
| 121 |
However this is actually a trade-off as state isolation is not guaranteed between |
|---|
| 122 |
subsequently run tasks. This shouldn't be a problem in most cases though. |
|---|
| 123 |
|
|---|
| 124 |
== Related projects |
|---|
| 125 |
|
|---|
| 126 |
* Raven[http://raven.rubyforge.org/]: similar to Jerbil in scope, but different approach (invokes |
|---|
| 127 |
javac externally, no Java-Ruby integration). |
|---|
| 128 |
|
|---|
| 129 |
== FAQ |
|---|
| 130 |
|
|---|
| 131 |
See FAQ[http://code.trampolinesystems.com/jerbil/wiki/FAQ]. |
|---|
| 132 |
|
|---|
| 133 |
== Project homepage |
|---|
| 134 |
|
|---|
| 135 |
http://code.trampolinesystems.com/jerbil |
|---|
| 136 |
|
|---|
| 137 |
== Contact |
|---|
| 138 |
|
|---|
| 139 |
mailto:jan@trampolinesystems.com |
|---|
| 140 |
|
|---|
| 141 |
== License |
|---|
| 142 |
|
|---|
| 143 |
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
|---|
| 144 |
in compliance with the License. You may obtain a copy of the License at |
|---|
| 145 |
|
|---|
| 146 |
http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 147 |
|
|---|
| 148 |
Unless required by applicable law or agreed to in writing, software distributed under the License |
|---|
| 149 |
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
|---|
| 150 |
or implied. See the License for the specific language governing permissions and limitations under |
|---|
| 151 |
the License. |
|---|
| 152 |
|
|---|
| 153 |
== 3dparty code / MIT License |
|---|
| 154 |
|
|---|
| 155 |
This product contains portions of Rails (activesupport/inflector.rb, |
|---|
| 156 |
activesupport/inflections.rb) which are licensed as follows: |
|---|
| 157 |
|
|---|
| 158 |
Copyright (c) 2004-2006 David Heinemeier Hansson |
|---|
| 159 |
|
|---|
| 160 |
Permission is hereby granted, free of charge, to any person obtaining |
|---|
| 161 |
a copy of this software and associated documentation files (the |
|---|
| 162 |
"Software"), to deal in the Software without restriction, including |
|---|
| 163 |
without limitation the rights to use, copy, modify, merge, publish, |
|---|
| 164 |
distribute, sublicense, and/or sell copies of the Software, and to |
|---|
| 165 |
permit persons to whom the Software is furnished to do so, subject to |
|---|
| 166 |
the following conditions: |
|---|
| 167 |
|
|---|
| 168 |
The above copyright notice and this permission notice shall be |
|---|
| 169 |
included in all copies or substantial portions of the Software. |
|---|
| 170 |
|
|---|
| 171 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|---|
| 172 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|---|
| 173 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|---|
| 174 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
|---|
| 175 |
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
|---|
| 176 |
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|---|
| 177 |
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Copyright (c) 2004-2006 David Heinemeier Hansson |
|---|
| 178 |
|
|---|