You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by as...@apache.org on 2008/01/16 10:11:43 UTC

svn commit: r612391 [1/2] - in /incubator/buildr/trunk: ./ doc/ doc/css/ doc/pages/ lib/ lib/buildr/ lib/buildr/jetty/ lib/core/ lib/java/ lib/java/org/apache/buildr/ lib/tasks/ spec/

Author: assaf
Date: Wed Jan 16 01:11:40 2008
New Revision: 612391

URL: http://svn.apache.org/viewvc?rev=612391&view=rev
Log:
Added profiles(.yaml) based on code provided by Yanko Ivanov\nConsolidated API for RJB and JRuby, replacing the now deprecated JavaWrapper.\nUpgraded to OpenJPA 1.0.1

Added:
    incubator/buildr/trunk/doc/pages/whats_new.textile
    incubator/buildr/trunk/lib/java/jruby.rb
    incubator/buildr/trunk/lib/java/rjb.rb
Modified:
    incubator/buildr/trunk/CHANGELOG
    incubator/buildr/trunk/Rakefile
    incubator/buildr/trunk/doc/css/default.css
    incubator/buildr/trunk/doc/css/eiffel.css
    incubator/buildr/trunk/doc/pages/extending.textile
    incubator/buildr/trunk/doc/pages/getting_started.textile
    incubator/buildr/trunk/doc/pages/more_stuff.textile
    incubator/buildr/trunk/doc/pages/recipes.textile
    incubator/buildr/trunk/doc/pages/troubleshooting.textile
    incubator/buildr/trunk/doc/print.toc.yaml
    incubator/buildr/trunk/doc/web.toc.yaml
    incubator/buildr/trunk/lib/buildr.rb
    incubator/buildr/trunk/lib/buildr/antlr.rb
    incubator/buildr/trunk/lib/buildr/javacc.rb
    incubator/buildr/trunk/lib/buildr/jetty.rb
    incubator/buildr/trunk/lib/buildr/jetty/JettyWrapper$BuildrHandler.class
    incubator/buildr/trunk/lib/buildr/jetty/JettyWrapper.java
    incubator/buildr/trunk/lib/buildr/openjpa.rb
    incubator/buildr/trunk/lib/core/environment.rb
    incubator/buildr/trunk/lib/core/package.rb
    incubator/buildr/trunk/lib/java/ant.rb
    incubator/buildr/trunk/lib/java/compilers.rb
    incubator/buildr/trunk/lib/java/java.rb
    incubator/buildr/trunk/lib/java/org/apache/buildr/JUnitTestFilter.java
    incubator/buildr/trunk/lib/java/packaging.rb
    incubator/buildr/trunk/lib/java/test_frameworks.rb
    incubator/buildr/trunk/lib/tasks/zip.rb
    incubator/buildr/trunk/spec/common_spec.rb
    incubator/buildr/trunk/spec/compile_spec.rb
    incubator/buildr/trunk/spec/java_packaging_spec.rb
    incubator/buildr/trunk/spec/spec_helpers.rb

Modified: incubator/buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/CHANGELOG?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/CHANGELOG (original)
+++ incubator/buildr/trunk/CHANGELOG Wed Jan 16 01:11:40 2008
@@ -4,7 +4,9 @@
 * Added: Layout class for controlling the project layout.  Also cleaned up places where paths were used instead of path names.
 * Added: HTTP Basic authentication support (Yuen-Chi Lian).
 * Added: EAR packaging (Victor Hugo Borja).
-* Changed: Upgraded to Rake 0.8, RSpec 1.1, RJB 1.1 and Facets 2.2.
+* Added: Profiles(.yaml), based on the code provided by Yanko Ivanov.
+* Added: Consolidated API for RJB and JRuby, replacing the now deprecated JavaWrapper.
+* Changed: Upgraded to Rake 0.8, RSpec 1.1, RJB 1.1, Facets 2.2, OpenJPA 1.0.1.
 * Changed: Resources are now copied to target/resources instead of target/classes, and target/test/resources instead of target/test-resources.
 * Changed: Test cases are not compiled into target/test/classes instead of target/test-classes.
 * Changed: Compile extension and CompileTask are now separate from the Java module.  Multiple compilers can be used, either guessed from the project layout, or specified with compile.using(:name).

Modified: incubator/buildr/trunk/Rakefile
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/Rakefile?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/Rakefile (original)
+++ incubator/buildr/trunk/Rakefile Wed Jan 16 01:11:40 2008
@@ -247,18 +247,17 @@
   end
 end
 
-namespace :setup do
-  task :jetty do
-    cp = ['jetty-6.1.1.jar', 'jetty-util-6.1.1.jar', 'servlet-api-2.5-6.1.1'].
-      map { |jar| `locate #{jar}`.split.first }.join(File::PATH_SEPARATOR)
-    Dir.chdir 'lib/buildr/jetty' do
-      `javac -cp #{cp} JettyWrapper.java`
-    end
+
+task 'compile' do
+  # RJB, JUnit and friends.
+  Dir.chdir 'lib/java' do
+    `javac -Xlint:all org/apache/buildr/*.java`
   end
 
-  task :junit do
-    Dir.chdir 'lib/java' do
-      `javac org/apache/buildr/JUnitTestFilter.java`
-    end
+  # Jetty server.
+  cp = ['jetty-6.1.1.jar', 'jetty-util-6.1.1.jar', 'servlet-api-2.5-6.1.1'].
+    map { |jar| `locate #{jar}`.split.first }.join(File::PATH_SEPARATOR)
+  Dir.chdir 'lib/buildr/jetty' do
+    `javac -Xlint:all -cp #{cp} JettyWrapper.java`
   end
 end

Modified: incubator/buildr/trunk/doc/css/default.css
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/doc/css/default.css?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/doc/css/default.css (original)
+++ incubator/buildr/trunk/doc/css/default.css Wed Jan 16 01:11:40 2008
@@ -1,9 +1,81 @@
 body {
-  color: #333;
   background-color: #fff;
-  font-family: Tahoma, Arial, Helvetica, sans-serif;
+  color: #000;
+  font-family: Verdana, Arial, Helvetica, sans-serif;
   text-align: center;
-	line-height: 140%;
+	line-height: 1.5em;
+}
+
+a:link, a:visited{
+  color: #0044b3;
+  text-decoration: none;
+}
+
+a:hover{
+  text-decoration: underline;
+}
+
+img {
+  border: none;
+}
+
+pre {
+	font-family: "Courier New";
+  padding: 1em;
+}
+pre.wrapped {
+  white-space: pre-wrap;       /* css-3 */
+  white-space: -moz-pre-wrap !important;  /* Mozilla, since 1999 */
+  white-space: -pre-wrap;      /* Opera 4-6 */
+  white-space: -o-pre-wrap;    /* Opera 7 */
+  word-wrap: break-word;
+}
+
+h1, h2, h3 {
+  padding: 0.3em;
+  margin: 2.5em 0 0.5em -0.3em;
+  line-height: 1.25em;
+  letter-spacing: 0.03em;
+}
+
+h1 {
+  border-bottom: 1px solid #808080;
+  font-size: 2em;
+  margin-top: 0;
+}
+
+h2 {
+  border-bottom: 1px solid #a0a0a0;
+  font-size: 1.3em;
+}
+
+h3 {
+  border-bottom: 1px solid #c0c0c0;
+  font-size: 1.1em;
+}
+
+blockquote {
+	padding-left: 2em;
+	padding-right: 2em;
+	margin-left: 0.3em;
+  margin-right: 0;
+	border-left: 1px solid #3c78b5;
+}
+
+table {
+  border: none;
+  margin: auto;
+}
+
+th, td {
+  padding: 1em;
+  border: 1px solid #C0C0C0;
+  vertical-align: top;
+  background-color: #FFFFFF;
+}
+
+th {
+  background-color: #F5F5F5;
 }
 
 
@@ -26,7 +98,6 @@
   float: right;
   font-size: 1.5em;
   font-weight: bold;
-  color: #0066b3;
   position: relative;
   bottom: 4.5em;
 }
@@ -52,19 +123,15 @@
 }
 
 #pages ol li a:link,  #pages ol li a:visited  {
-  color: #808080;
+  color: #606060;
   text-decoration: none;
 }
 
 #pages ol li a:hover {
-  color: #454545;
+  color: #222;
   text-decoration: none;
 }
 
-#pages ol li a.current {
-  color: #B8B8B8;
-}
-
 #pages form {
   margin-top: 2em;
   padding: 0.3em 0 0.5em 0.5em;
@@ -132,6 +199,7 @@
   float: right;
 }
 
+
 #footer {
   border-top: 1px solid #ccc;
   font-size: 0.9em;
@@ -139,65 +207,3 @@
   clear: both;
   margin: 0 0 3em 0em;
 }
-
-
-a:link, a:visited{
-  color: #0066b3;
-  text-decoration: none;
-}
-
-a:hover{
-  text-decoration: underline;
-}
-
-img {
-  border: none;
-}
-
-pre {
-	font-family: "Courier New";
-  padding: 1em;
-}
-pre.wrapped {
-  white-space: pre-wrap;       /* css-3 */
-  white-space: -moz-pre-wrap !important;  /* Mozilla, since 1999 */
-  white-space: -pre-wrap;      /* Opera 4-6 */
-  white-space: -o-pre-wrap;    /* Opera 7 */
-  word-wrap: break-word;
-}
-
-h1 a:link, h1 a:visited {
-  color: #080808;
-}
-
-h1, h2, h3 {
-  padding: 0.3em;
-  margin: 2.5em 0 0.5em -0.3em;
-  line-height: 1.1em;
-  letter-spacing: 1px;
-}
-
-h1 {
-  border-bottom: 1px solid #808080;
-  font-size: 2em;
-  margin-top: 0;
-}
-
-h2 {
-  border-bottom: 1px solid #a0a0a0;
-  font-size: 1.3em;
-}
-
-h3 {
-  border-bottom: 1px solid #c0c0c0;
-  font-size: 1.1em;
-}
-
-blockquote {
-	padding-left: 2em;
-	padding-right: 2em;
-	margin-left: 0.3em;
-  margin-right: 0;
-	border-left: 1px solid #3c78b5;
-}
-

Modified: incubator/buildr/trunk/doc/css/eiffel.css
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/doc/css/eiffel.css?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/doc/css/eiffel.css (original)
+++ incubator/buildr/trunk/doc/css/eiffel.css Wed Jan 16 01:11:40 2008
@@ -1,5 +1,4 @@
 pre.eiffel .EmbeddedSource {
-   background-color: #6597F6;
 }
 pre.eiffel .LibraryObject {
    font-weight: bold;
@@ -36,7 +35,6 @@
    font-style: italic;
 }
 pre.eiffel .MarkupTag {
-   color: #1C02FF;
 }
 pre.eiffel {
    background-color: #FFFFFF;
@@ -60,7 +58,7 @@
    font-style: italic;
 }
 pre.eiffel .MarkupNameOfTag {
-   font-weight: bold;
+   color: #1C02FF;
 }
 pre.eiffel .InvalidTrailingWhitespace {
    background-color: #FFD0D0;

Modified: incubator/buildr/trunk/doc/pages/extending.textile
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/doc/pages/extending.textile?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/doc/pages/extending.textile (original)
+++ incubator/buildr/trunk/doc/pages/extending.textile Wed Jan 16 01:11:40 2008
@@ -151,6 +151,53 @@
 }}}
 
 
+h2.  Using Java Libraries
+
+Buildr runs along side a JVM, using either RJB or JRuby.  The Java module
+allows you to access Java classes and create Java objects.
+
+Java classes are accessed as static methods on the @Java@ module, for example:
+
+{{{!ruby
+str = Java.java.lang.String.new('hai!')
+str.toUpperCase
+=> 'HAI!'
+Java.java.lang.String.isInstance(str)
+=> true
+Java.com.sun.tools.javac.Main.compile(args)
+}}}
+
+The @classpath@ attribute allows Buildr to add JARs and directories to the
+classpath, for example, we use it to load Ant and various Ant tasks, code
+generators, test frameworks, and so forth.
+
+When using an artifact specification, Buildr will automatically download and
+install the artifact before adding it to the classpath.
+
+For example, Ant is loaded as follows:
+
+{{{!ruby
+Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
+}}}
+
+Artifacts can only be downloaded after the Buildfile has loaded, giving it a
+chance to specify which remote repositories to use, so adding to classpath does
+not by itself load any libraries.  You must call @Java.load@ before accessing any
+Java classes to give Buildr a chance to load the libraries specified in the
+classpath.
+
+When building an extension, make sure to follow these rules:
+
+# Add to the @classpath@ when the extension is loaded (i.e. in module or class
+definition), so the first call to @Java.load@ anywhere in the code will include
+the libraries you specify.
+# Call @Java.load@ once before accessing any Java classes, allowing Buildr to
+set up the classpath.
+# Only call @Java.load@ when invoked, otherwise you may end up loading the JVM
+with a partial classpath, or before all remote repositories are listed.
+# Check on a clean build with empty local repository.
+
+
 h2.  Using Alternative Layouts
 
 Buildr follows a common convention for project layouts: Java source files

Modified: incubator/buildr/trunk/doc/pages/getting_started.textile
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/doc/pages/getting_started.textile?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/doc/pages/getting_started.textile (original)
+++ incubator/buildr/trunk/doc/pages/getting_started.textile Wed Jan 16 01:11:40 2008
@@ -68,5 +68,8 @@
 
 *AntWrap* Buildr uses AntWrap, for configuring and running Ant tasks.  You can learn more from the "Antwrap documentation":http://antwrap.rubyforge.org/.
 
+*YAML* Buildr uses YAML for its profiles.  You can "learn more about YAML here":http://www.yaml.org, and use this handy
+"YAML quick reference":http://www.yaml.org/refcard.html.
+
 
 fn1. You'll notice that Buildr creates a file called @buildfile@.  It's case sensitive, but Buildr will look for either @buildfile@ or @Buildfile@.  You can also use @Rakefile@ or @rakefile@ for compatibility with previous versions of Buildr.

Modified: incubator/buildr/trunk/doc/pages/more_stuff.textile
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/doc/pages/more_stuff.textile?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/doc/pages/more_stuff.textile (original)
+++ incubator/buildr/trunk/doc/pages/more_stuff.textile Wed Jan 16 01:11:40 2008
@@ -1,5 +1,6 @@
 h1. More Stuff
 
+
 h2. Help Tasks
 
 Buildr includes a number of informative tasks.  Currently that number stands
@@ -27,21 +28,106 @@
 method before the project or task definition.
 
 
-h2. Personal Settings and Environment Variables
+h2. Environment and Personal Settings
+
+In many cases you will want to customize your build to deal with different
+environments and configurations, customize how it runs on your machine, and
+even control the build each time you run the @buildr@ command.  The following
+sections will show you how to do that.
+
+
+h4. Environments
+
+One common use case is adapting the build to different environments.  For
+example, to compile code with debugging information during development and
+testing, but strip it for production.  Another example is using different
+databases for development, testing and production, or using services at
+different URLs.
+
+So let's start by talking about the build environment.  Buildr has a global
+attributes that indicates which environment it's running in, accessible from the
+@environment@ method.  You can set the current build environment in one of two
+ways.  Using the @-e@ command line option:
+
+{{{!sh
+$ buildr -e test
+(in /home/john/project, test)
+}}}
+
+Or by setting the environment variable @BUILDR_ENV@:
+
+{{{!
+$ export BUILDR_ENV=production
+$ buildr
+(in /home/john/project, production)
+}}}
+
+The default environment is "development".
+
+Here's a simple example for handling different environments within the
+Buildfile:
+
+{{{!ruby
+project 'db-module' do
+  db = (environment == 'production' ? 'oracle' : 'hsql')
+  resources.from(_(:source, :main, db))
+end
+}}}
+
+
+h4.  Profiles
+
+Different environments may require different configurations, and you can handle
+a lot of that by using the profile file.  The profile file is a YAML file
+called @profile.yaml@ that you place in the same directory as the Buildfile.
+We selected YAML because it's easier to read and edit than XML.
+
+For example, to support three different database configurations, we could write:
+
+{{{!yaml
+development:
+  db: hsql
+test:
+  db: oracle
+production:
+  db: oracle
+}}}
+
+And change the Buildfile to use the profile:
+
+{{{!ruby
+project 'db-module' do
+  db = profile['db']
+  resources.from(_(:source, :main, db))
+end
+}}}
+
+The @profile@ method returns a profile that matches the current environment.
+For the development environment, it returns a hash with the name/value pair
+@'db'=>'hsql'@.
+
+You can "learn more about YAML here":http://www.yaml.org, and use this handy
+"YAML quick reference":http://www.yaml.org/refcard.html.
+
+
+h4. Personal Settings
 
 Some things clearly do not belong in the Buildfile.  For example, the
 username/password you use to upload releases.  If you're working in a team or
-making the source code available, you'd want to keep these in a separate
-place.  You may want to pick a different location for the local repository, or
-use a different remote repository than everyone else, etc.
-
-Besides loading the Buildfile, Buildr will also attempt to load two
-@buildr.rb@ files.  It looks for the first @buildr.rb@ file in your home
-directory.  That's the file you would use to define personal settings.  It
-then looks for the second @buildr.rb@ file in the project directory.  You can
-use that one to over-ride settings specific to that project.
+on an open source project, you'd want to keep these in a separate place.
 
-Here's an example @buildr.rb@, not one I actually use, but close enough:
+You may want to use personal settings for picking up a different location for
+the local repository, or use a different set of preferred remote repositories,
+and so forth.
+
+Before loading the Buildfile, Buildr will attempt to load two @buildr.rb@
+files.  First, the @buildr.rb@ file it finds in your home directory, and then
+the @buildr.rb@ file it finds in the build directory.  That order is important,
+it allows you to place global settings that affect all your builds in your home
+directory's @buildr.rb@, but also over-ride those with settings for a given
+project.
+
+Here's an example @buildr.rb@:
 
 {{{!ruby
 # Only I should know that
@@ -51,67 +137,78 @@
 repositories.remote << 'http://inside-the-firewall'
 }}} 
 
-Environment variables are another way to set personal settings.  Here's an
-example for a Buildfile that will read the username/password from environment
-variables:
+
+h4.  Environment Variables
+
+Buildr uses several environment variables that help you control how it works.
+Environment variables are used in addition to profiles and personal settings in
+two cases:
+
+* When you need to control the build from the command line, for example,
+specifying the build environment using @BUILDR_ENV@, or skipping tests using
+@test=no@.
+
+* For commonly used environment variables, such as @JAVA_HOME@, @JAVA_OPTS@ and
+@HTTP_PROXY@.
+
+Some environment variables you will only set once or change infrequently.
+Other environment variables may change more often, for example, running a build
+with different versions of the JDK, or disabling tests.  You can change these
+variables when running Buildr by adding @name=value@ as a command line argument.
+
+For example:
+
+{{{!sh
+$ buildr test=no
+}}}
+
+You can also change environment variables from within the Buildfile.  For
+example, if your build needs more JVM heap space than the default, you can add
+a line like this to your Buildfile:
 
 {{{!ruby
-repositories.upload_to[:username] = ENV['USERNAME']
-repositories.upload_to[:password] = ENV['PASSWORD']
+# This project builds a lot of code.
+ENV['JAVA_OPTS'] = '-Xms1g -Xmx1g'
 }}}
 
-Build itself uses several environment variables, some more common, some
-specific to Buildr:
+Make sure to set environment variables at the very top of the Buildfile, above
+any @requires@ or other Ruby statements.
 
-*JAVA_HOME* -- Points to your JDK, required for running Buildr.
+Buildr uses the following environment variables.
 
-*JAVA_OPTS/JAVA_OPTIONS* -- Command line options to pass to the JDK (e.g.
-@'-Xms1g'@)[1].
+*BUILDR_ENV* -- Environment name that you can also set using the @-e@ command
+line option.
+
+*DEBUG* -- Set to @off@ if you want Buildr to compile without debugging
+information (default when running @release@, see
+"Compiling":building.html#compiling).
 
 *HTTP_PROXY* -- URL for HTTP proxy server (see "Specifying
 Repositories":artifacts.html#specifying_repositories).
 
+*JAVA_HOME* -- Points to your JDK, required for running Buildr.
+
+*JAVA_OPTS/JAVA_OPTIONS* -- Command line options to pass to the JDK (e.g.
+@'-Xms1g'@)[1].
+
 *NO_PROXY* -- Comma separated list of hosts and domain that should not be
 proxied (see "Specifying
 Repositories":artifacts.html#specifying_repositories).
 
-*DEBUG* -- Set to @off@ if you want Buildr to compile without debugging
-information (default when running @release@, see
-"Compiling":building.html#compiling).
-
 *TEST* -- Set to @off@ to tell Buildr to skip tests, or @all@ to tell Buildr
 to run all tests and ignore failures (see "Running
 Tests":testing.html#running_tests).
 
-*BUILDR_ENV* -- Environment name that you can also set using the @-e@ command
-line option.
-
-Some Buildfiles depend on the environment in which they are running, and may
-work differently in development, QA, production, etc.  Setting the environment
-name is a simple mechanism to control the Buildfile behavior.
+*USER* -- Tasks that need your user name, for example to log to remote serers,
+will use this environment variable.
 
-You set the environment name either using the @BUILDR_ENV@ environment
-variable, or the @-e@ command line option.  For example:
-
-{{{!sh
-$ export BUILDR_ENV=development
-$ buildr
-(in /home/john/project, development)
-. . .
-$ buildr -e production
-(in /home/john/project, production)
-. . .
-}}}
-
-From the Buildfile, you can access the environment name using
-@Buildr.environment@, and in some contexts, simply by calling @environment@.
-For example:
+If you need to, you can always use more environment variables.  This example
+uses two environment variables for specifying the username and password for
+uploading artifacts:
 
 {{{!ruby
-project 'db-module' do
-  db = (environment == 'production' ? 'oracle' : 'hsql')
-  resources.filter.using :database=>db
-end
+repositories.upload_to[:username] = ENV['USERNAME']
+repositories.upload_to[:password] = ENV['PASSWORD']
 }}}
 
 

Modified: incubator/buildr/trunk/doc/pages/recipes.textile
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/doc/pages/recipes.textile?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/doc/pages/recipes.textile (original)
+++ incubator/buildr/trunk/doc/pages/recipes.textile Wed Jan 16 01:11:40 2008
@@ -1,3 +1,34 @@
 h1. Recipes
 
 Commond recipes for Buildr, collected from the mailing list.
+
+
+h2.  Configuration
+
+h4.  Keeping your Profiles.yaml file DRY
+
+YAML allows you to write an object (map, array, etc) once and reference it in
+several places using anchors and aliases (@&@ and @*@).  For example, if you
+have several profiles, all with the same information, you can write this:
+
+{{{!yaml
+development: &common
+  db: oracle
+  port: 8080
+test: *common
+production: *common
+}}}
+
+You can use the merge key (@<<@) to create a name/value map that merges default
+values from another name/value map, for example:
+
+{{{!yaml
+common: &common
+  db: oracle
+  port: 8080
+development:
+  <<: *common
+  db: hsql
+test: *common
+production: *common
+}}}

Modified: incubator/buildr/trunk/doc/pages/troubleshooting.textile
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/doc/pages/troubleshooting.textile?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/doc/pages/troubleshooting.textile (original)
+++ incubator/buildr/trunk/doc/pages/troubleshooting.textile Wed Jan 16 01:11:40 2008
@@ -2,6 +2,30 @@
 
 Common troubleshooting tips collected from the mailing list.
 
+h2.  Building
+
+h3.  Running out of heap space
+
+You can give the JVM more heap space by setting the @JAVA_OPTS@ environment
+variables.  This environment variable provides arguments for staring the JVM.
+For example, to set the heap space to 1GB:
+
+{{{!sh
+$ export "JAVA_OPTS=-Xms1g -Xmx1g"
+$ buildr compile
+}}}
+
+If you're sharing the build with other developers, you'll want to specify these
+options in the Buildfile itself.  You can set the environment variable within
+the Buildfile, but make sure to do so at the very top of the Buildfile.
+
+For example:
+
+{{{!ruby
+ENV['JAVA_OPTS'] = '-Xms1g -Xmx1g'
+}}}
+
+
 h2.  Buildfiles
 
 h3.  Bugs resulting from a dangling comma or period

Added: incubator/buildr/trunk/doc/pages/whats_new.textile
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/doc/pages/whats_new.textile?rev=612391&view=auto
==============================================================================
--- incubator/buildr/trunk/doc/pages/whats_new.textile (added)
+++ incubator/buildr/trunk/doc/pages/whats_new.textile Wed Jan 16 01:11:40 2008
@@ -0,0 +1,191 @@
+h1.  What's New
+
+h2.  Buildr 1.3
+
+
+h4.  Multiple Languages
+
+The main focus of this release is supporting multiple languages for compiling
+and testing.
+
+For each project, Buildr will attempt to infer which compiler to use based on
+the source files it finds, for example, if it finds @.java@ files in the
+@src/main/java@ directory, it will switch to the javac compiler, if it finds
+@.scala@ files in the @src/main/scala@ directory, to the scalac compiler and so
+forth.
+
+Different compilers may use different target directory, @target/classes@ is
+picked for JVM compilers (Java, Scala, etc), so resources are not copied to
+their own directory, @target/resources@.  The prepare task has been removed.
+
+Not all languages have classpaths, so @compile.classpath@ is now known as
+@compile.dependencies@, but the old attribute still exists for backward
+compatibility.
+
+Also, for consistency, the test target directories have changed to
+@target/test/classes@ and @target/test/resources@, respectively.
+
+Speaking of tests, you can compile code in one language and use a different
+language to test it, say, if you're interested in compiling Java code and
+testing it with Ruby, or compiling Flash and running a Java test suite.
+
+As before, you can pick the test framework by calling
+@test.using(<framework>)@.  Buildr will attempt to pick one by default, for
+example, if the tests are written in Java, it will default to JUnit.
+
+And, since not all languages package to JARs, the default packaging is either
+inferred from the compiler (so @:jar@ when compiling Java code), otherwise to
+@:zip@.  All this defaulting means that @package()@ with no arguments does the
+right thing in more cases, and most probably won't break anyone's buildfiles.
+
+I've tried to keep the compiler API as simple as possible, making it easy to
+add new compilers; however, I had to change the test framework API to
+accommodate the new features, so old test frameworks will not work on 1.3.
+
+
+h4.  Packaging EARs
+
+EAR packages support four component types:
+
+* @:war@ -- J2EE Web Application (WAR).
+* @:ejb@ -- Enterprise Java Bean (JAR).
+* @:jar@ -- J2EE Application Client (JAR).
+* @:lib@ -- Shared library (JAR).
+
+This example shows two ways for adding components built by other projects:
+
+{{{!ruby
+package(:ear) << project('coolWebService').package(:war)
+package(:ear).add project('commonLib') # By default, the JAR package
+}}}
+
+EAR packages include an @application.xml@ file in the @META-INF@ directory that
+describes the application and its component.  This file is created for you
+during packaging, by referencing all the components added to the EAR.  There
+are a couple of things you will typically want to change.
+
+* *display-name* -- The application's display name defaults to the project's
+identifier.  You can change that by setting the @display_name@ attribute.
+
+* *context-root* -- WAR components specify a context root, based on the package
+identifier, for example, "cool-web-1.0.war" will have the context root
+"cool-web".  To specify a different context root, add the WAR package with the
+@context_root@ option.
+
+"Read more ...":packaging.html#packaging_ears
+
+
+h4.  New API for accessing Java libraries
+
+Java classes are accessed as static methods on the @Java@ module, for example:
+
+{{{!ruby
+str = Java.java.lang.String.new('hai!')
+str.toUpperCase
+=> 'HAI!'
+Java.java.lang.String.isInstance(str)
+=> true
+Java.com.sun.tools.javac.Main.compile(args)
+}}}
+
+The @classpath@ attribute allows Buildr to add JARs and directories to the
+classpath, for example, we use it to load Ant and various Ant tasks, code
+generators, test frameworks, and so forth.
+
+For example, Ant is loaded as follows:
+
+{{{!ruby
+Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
+}}}
+
+Artifacts can only be downloaded after the Buildfile has loaded, giving it a
+chance to specify which remote repositories to use, so adding to classpath does
+not by itself load any libraries.  You must call @Java.load@ before accessing any
+Java classes to give Buildr a chance to load the libraries specified in the
+classpath.
+
+"Read more ...":extending.html#using_java_libraries
+
+
+h4.  Creating Extensions
+
+A module defines instance methods that are then mixed into the project and
+become instance methods of the project.  There are two general ways for
+extending projects.  You can extend all projects by including the module in
+Project:
+
+{{{!ruby
+class Project
+  include MyExtension
+end
+}}}
+
+You can also extend a given project instance and only that instance by
+extending it with the module:
+
+{{{!ruby
+define 'foo' do
+  extend MyExtension
+end
+}}}
+
+Some extensions require tighter integration with the project, specifically for
+setting up tasks and properties, or for configuring tasks based on the project
+definition.  You can do that by adding callbacks to the process.
+
+"Read more ...":extending.html#creating_extensions
+
+
+h4.  Using Alternative Layouts
+
+Buildr follows a common convention for project layouts: Java source files
+appear in @src/main/java@ and compile to @target/classes@, resources are
+copied over from @src/main/resources@ and so forth.  Not all projects follow
+this convention, so it's now possible to specify an alternative project
+layout.
+
+A layout is an object that implements the @expand@ method.  The easiest way to
+define a custom layout is to create a new @Layout@ object and specify mapping
+between names used by Buildr and actual paths within the project.
+
+"Read more ...":extending.html#using_alternative_layouts
+
+
+h4.  Other
+
+* Buildr 1.3 upgrades to Rake 0.8, RSpec 1.1, RJB 1.1, Facets 2.2 and OpenJPA
+1.0.1.
+
+* JUnit tests now operate on all compiled test classes that extend
+junit.framework.TestCase and match the include/exclude patterns.  Test cases no
+longer have to end or start with Test, and including non-test classes simply
+ignores them.
+
+* Remote repositories now support HTTP Basic Authentication.
+
+* The prepare task has been removed, if you need to, simply add a prerequisite
+to the compile task.
+
+
+h4.  Documentation
+
+* The "What's new?":whats_new.html page (this one, actually), summarizes all
+the important new features and changes in each release.
+
+* The "Recipes":recipes.html page (also available in the PDF) lists recipes for
+using Buildr, collected from the mailing list.  Feel free to contribute tips,
+tricks and techniques.
+
+* The "Troubleshooting":troubleshooting.html page (also available in the PDF)
+collects troubleshooting ideas from the mailing list.
+
+* The "Download and installation":download.html has been rewritten to cover all
+you need to know about downloading and installing Buildr for various operating
+systems and configurations.
+
+* A new "Contributing":contributing.html page has more details on how to file
+bugs, policy for submitting patches, running Buildr test cases, and helping
+with the documentation.
+
+* The site also includes "RSpec test report":report.html and "Test coverage
+report":coverage/index.html.

Modified: incubator/buildr/trunk/doc/print.toc.yaml
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/doc/print.toc.yaml?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/doc/print.toc.yaml (original)
+++ incubator/buildr/trunk/doc/print.toc.yaml Wed Jan 16 01:11:40 2008
@@ -8,5 +8,6 @@
 - More Stuff: more_stuff.html
 - Extending: extending.html
 - Recipes: recipes.html
+- Troubleshooting: troubleshooting.html
 - Contributing: contributing.html
 - License: license.html

Modified: incubator/buildr/trunk/doc/web.toc.yaml
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/doc/web.toc.yaml?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/doc/web.toc.yaml (original)
+++ incubator/buildr/trunk/doc/web.toc.yaml Wed Jan 16 01:11:40 2008
@@ -2,6 +2,7 @@
   - Welcome: index.html
   - Download and Installation: download.html
   - Printable PDF: buildr.pdf
+  - New: whats_new.html
 - Using Buildr:
   - Getting Started: getting_started.html
   - Projects: projects.html

Modified: incubator/buildr/trunk/lib/buildr.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr.rb?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr.rb (original)
+++ incubator/buildr/trunk/lib/buildr.rb Wed Jan 16 01:11:40 2008
@@ -21,7 +21,6 @@
 
 module Buildr
   VERSION = '1.3.0'.freeze # unless const_defined?(:VERSION)
-
 end
 
 require 'core'
@@ -38,3 +37,7 @@
 class Object #:nodoc:
   Buildr.constants.each { |c| const_set c, Buildr.const_get(c) unless const_defined?(c) }
 end
+
+# Prevent RSpec runner from running at_exit.
+require 'spec'
+Spec.run = true

Modified: incubator/buildr/trunk/lib/buildr/antlr.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/antlr.rb?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/antlr.rb (original)
+++ incubator/buildr/trunk/lib/buildr/antlr.rb Wed Jan 16 01:11:40 2008
@@ -19,11 +19,9 @@
           mkdir_p options[:token] 
           args = ["-lib",  options[:token]] + args 
         end
-        antlr_class = Java.import("org.antlr.Tool")
-        antlr_tool = antlr_class.new_with_sig("[Ljava.lang.String;", args)
-        antlr_tool.process
-        #wrapper.import("org.antlr.Tool").main(args) == 0 or
-        #  fail "Failed to run ANTLR, see errors above."
+        Java.load
+        #Java.org.antlr.Tool.new_with_sig("[Ljava.lang.String;", args).process
+        Java.org.antlr.Tool.new(args.map(&:to_s)).process
       end
     end
 

Modified: incubator/buildr/trunk/lib/buildr/javacc.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/javacc.rb?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/javacc.rb (original)
+++ incubator/buildr/trunk/lib/buildr/javacc.rb Wed Jan 16 01:11:40 2008
@@ -16,7 +16,8 @@
 
         args = args.flatten.map(&:to_s).collect { |f| File.directory?(f) ? FileList[f + "/**/*.jj"] : f }.flatten
         args.unshift "-OUTPUT_DIRECTORY=#{options[:output]}" if options[:output]
-        Java.import("org.javacc.parser.Main").mainProgram(args) == 0 or
+        Java.load
+        Java.org.javacc.parser.Main.mainProgram(args) == 0 or
           fail "Failed to run JavaCC, see errors above."
       end
 
@@ -27,7 +28,8 @@
         args = args.flatten.map(&:to_s).collect { |f| File.directory?(f) ? FileList[f + "**/*.jjt"] : f }.flatten
         args.unshift "-OUTPUT_DIRECTORY=#{options[:output]}" if options[:output]
         args.unshift "-BUILD_NODE_FILES=#{options[:build_node_files] || false}"
-        Java.import("org.javacc.jjtree.JJTree").new.main(args) == 0 or
+        Java.load
+        Java.org.javacc.jjtree.JJTree.new.main(args) == 0 or
           fail "Failed to run JJTree, see errors above."
       end
 

Modified: incubator/buildr/trunk/lib/buildr/jetty.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/jetty.rb?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/jetty.rb (original)
+++ incubator/buildr/trunk/lib/buildr/jetty.rb Wed Jan 16 01:11:40 2008
@@ -36,7 +36,8 @@
       "org.mortbay.jetty:servlet-api-2.5:jar:#{VERSION}", "org.slf4j:slf4j-api:jar:#{SLF4J_VERSION}", 
       "org.slf4j:slf4j-simple:jar:#{SLF4J_VERSION}", "org.slf4j:jcl104-over-slf4j:jar:#{SLF4J_VERSION}" ]
      
-    Java.classpath <<  REQUIRES << File.join(__DIR__, "jetty")
+    Java.classpath <<  REQUIRES
+    Java.classpath << File.join(__DIR__, "jetty")
     
     # Default URL for Jetty (change with options.jetty.url).
     URL = "http://localhost:8080"
@@ -77,7 +78,8 @@
         puts "classpath #{Java.classpath.inspect}"
         port = URI.parse(url).port
         puts "Starting Jetty at http://localhost:#{port}" if verbose
-        jetty = Java.import("JettyWrapper").new(port)
+        Java.load
+        jetty = Java.JettyWrapper.new(port)
         sync << "Started" if sync
         sleep # Forever
       rescue Interrupt # Stopped from console

Modified: incubator/buildr/trunk/lib/buildr/jetty/JettyWrapper$BuildrHandler.class
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/jetty/JettyWrapper%24BuildrHandler.class?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/buildr/trunk/lib/buildr/jetty/JettyWrapper.java
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/jetty/JettyWrapper.java?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/jetty/JettyWrapper.java (original)
+++ incubator/buildr/trunk/lib/buildr/jetty/JettyWrapper.java Wed Jan 16 01:11:40 2008
@@ -48,7 +48,7 @@
 
     private class BuildrHandler extends AbstractHandler {
 
-        private HashMap _apps = new HashMap();
+        private HashMap<String,WebAppContext> _apps = new HashMap<String,WebAppContext>();
 
         public void handle(String string, HttpServletRequest request,
                            HttpServletResponse response, int i) throws IOException, ServletException {

Modified: incubator/buildr/trunk/lib/buildr/openjpa.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/openjpa.rb?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/openjpa.rb (original)
+++ incubator/buildr/trunk/lib/buildr/openjpa.rb Wed Jan 16 01:11:40 2008
@@ -5,7 +5,7 @@
   # Provides OpenJPA bytecode enhancement and Mapping tool task. Require explicitly using <code>require "buildr/openjpa"</code>.
   module OpenJPA
 
-    VERSION = "0.9.7-incubating"
+    VERSION = "1.0.1"
 
     REQUIRES = [ "org.apache.openjpa:openjpa-all:jar:#{VERSION}",
       "commons-collections:commons-collections:jar:3.1",

Modified: incubator/buildr/trunk/lib/core/environment.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/environment.rb?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/environment.rb (original)
+++ incubator/buildr/trunk/lib/core/environment.rb Wed Jan 16 01:11:40 2008
@@ -3,11 +3,7 @@
 
 module Buildr
 
-  # Collection of options for controlling Buildr. For example for running builds without running
-  # test cases, using a proxy server, JVM arguments, etc. You access this object by calling options,
-  # for example:
-  #   options.proxy.http = 'http://proxy.acme.com:8080'
-  #   options.java_args = '-Xmx512M'
+  # Collection of options for controlling Buildr.
   class Options
 
     # We use this to present environment variable as arrays.
@@ -38,7 +34,7 @@
     class Proxies
 
       # Returns the HTTP_PROXY URL.
-      def http()
+      def http
         ENV['HTTP_PROXY'] || ENV['http_proxy']
       end
 
@@ -49,7 +45,7 @@
       end
    
       # Returns list of hosts to exclude from proxying (NO_PROXY). 
-      def exclude()
+      def exclude
         @exclude ||= EnvArray.new('NO_PROXY')
       end
 
@@ -64,14 +60,14 @@
     end
 
     # :call-seq:
-    #   proxy() => options
+    #   proxy => options
     #
     # Returns the proxy options. Currently supported options are:
     # * :http -- HTTP proxy for use when downloading.
     # * :exclude -- Do not use proxy for these hosts/domains.
     #
     # For example:
-    #   options.proxy.http = "http://proxy.acme.com:8080"
+    #   options.proxy.http = 'http://proxy.acme.com:8080'
     # You can also set it using the environment variable HTTP_PROXY.
     #
     # You can exclude individual hosts from being proxied, or entire domains, for example:
@@ -88,7 +84,7 @@
   class << self
 
     # :call-seq:
-    #   options() => Options
+    #   options => Options
     #
     # Returns the Buildr options. See Options.
     def options
@@ -98,7 +94,7 @@
   end
 
   # :call-seq:
-  #   options() => Options
+  #   options => Options
   #
   # Returns the Buildr options. See Options.
   def options
@@ -106,15 +102,16 @@
   end
 
   # :call-seq:
-  #   environment() => string or nil
+  #   environment => string or nil
   #
   # Returns the environment name.  Use this when your build depends on the environment,
-  # for example, development, production, etc.  The value comes from the BUILDR_ENV environment variable.
+  # for example, development, production, etc.  The value comes from the BUILDR_ENV
+  # environment variable, and defaults to 'development'.
   # 
   # For example:
   #   buildr -e production
   def environment
-    ENV['BUILDR_ENV']
+    ENV['BUILDR_ENV'] ||= 'development'
   end
 
   # :call-seq:
@@ -139,8 +136,9 @@
   # Returns all the profiles loaded from the profiles.yaml file.
   def profiles
     unless @profiles
-      filename = File.expand_path('profiles.yaml', File.dirname(Rake.application.rakefile))
-      @profiles = File.exist?(filename) ? YAML::load(File.read(filename)) : {}
+      filename = ['Profiles.yaml', 'profiles.yaml'].map { |fn| File.expand_path(fn, File.dirname(Rake.application.rakefile)) }.
+        detect { |filename| File.exist?(filename) }
+      @profiles = filename ? YAML::load(File.read(filename)) : {}
     end
     @profiles
   end

Modified: incubator/buildr/trunk/lib/core/package.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/package.rb?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/package.rb (original)
+++ incubator/buildr/trunk/lib/core/package.rb Wed Jan 16 01:11:40 2008
@@ -164,7 +164,10 @@
             [ installed, pom ].map(&:to_s).each { |file| rm file if File.exist?(file) } 
           end
         end
-        task('upload') { package.pom.invoke ; package.pom.upload ; package.upload }
+        task 'upload'=>[package.pom] do
+          package.pom.upload
+          package.upload
+        end
 
         # Add the package to the list of packages created by this project, and
         # register it as an artifact. The later is required so if we look up the spec

Modified: incubator/buildr/trunk/lib/java/ant.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/ant.rb?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/ant.rb (original)
+++ incubator/buildr/trunk/lib/java/ant.rb Wed Jan 16 01:11:40 2008
@@ -1,17 +1,17 @@
-require "core/project"
-require "java/java"
-require "antwrap"
-require "core/help"
+require 'core/project'
+require 'java/java'
+require 'antwrap'
+require 'core/help'
 
 
 module Buildr
   module Ant
 
     # Which version of Ant we're using by default.
-    VERSION = "1.7.0" unless const_defined?('VERSION')
+    VERSION = '1.7.0' unless const_defined?('VERSION')
 
     # Libraries used by Ant.
-    REQUIRES = [ "org.apache.ant:ant:jar:#{VERSION}", "org.apache.ant:ant-launcher:jar:#{VERSION}", "xerces:xercesImpl:jar:2.6.2" ]
+    REQUIRES = [ "org.apache.ant:ant:jar:#{VERSION}", "org.apache.ant:ant-launcher:jar:#{VERSION}", 'xerces:xercesImpl:jar:2.6.2' ]
     Java.classpath << REQUIRES
 
     # :call-seq:
@@ -21,12 +21,12 @@
     # Ant tasks, and executes each task as it's defined.
     #
     # For example:
-    #   ant("hibernatedoclet") do |doclet|
-    #     doclet.taskdef :name=>"hibernatedoclet",
-    #       :classname=>"xdoclet.modules.hibernate.HibernateDocletTask", :classpath=>DOCLET
-    #     doclet.hibernatedoclet :destdir=>dest_dir, :force=>"true" do
-    #       hibernate :version=>"3.0"
-    #       fileset :dir=>source, :includes=>"**/*.java"
+    #   ant("hibernatedoclet') do |doclet|
+    #     doclet.taskdef :name=>'hibernatedoclet',
+    #       :classname=>'xdoclet.modules.hibernate.HibernateDocletTask', :classpath=>DOCLET
+    #     doclet.hibernatedoclet :destdir=>dest_dir, :force=>'true' do
+    #       hibernate :version=>'3.0'
+    #       fileset :dir=>source, :includes=>'**/*.java'
     #     end
     #   end
     def ant(name, &block)
@@ -45,7 +45,7 @@
 
   include Ant
 
-  task("help") do
+  task('help') do
     puts
     puts "Using Java #{Java.version}, Ant #{Ant::VERSION}."
   end

Modified: incubator/buildr/trunk/lib/java/compilers.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/compilers.rb?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/compilers.rb (original)
+++ incubator/buildr/trunk/lib/java/compilers.rb Wed Jan 16 01:11:40 2008
@@ -1,8 +1,8 @@
-require "core/project"
-require "core/common"
-require "core/compile"
-require "java/artifact"
-require "java/java"
+require 'core/project'
+require 'core/common'
+require 'core/compile'
+require 'java/artifact'
+require 'java/java'
 
 module Buildr
   module Compiler
@@ -38,16 +38,17 @@
       def compile(sources, target, dependencies) #:nodoc:
         check_options options, OPTIONS
         cmd_args = []
-        cmd_args << "-cp" << dependencies.join(File::PATH_SEPARATOR) unless dependencies.empty?
+        cmd_args << '-cp' << dependencies.join(File::PATH_SEPARATOR) unless dependencies.empty?
         source_paths = sources.select { |source| File.directory?(source) }
-        cmd_args << "-sourcepath" << source_paths.join(File::PATH_SEPARATOR) unless source_paths.empty?
-        cmd_args << "-d" << target
+        cmd_args << '-sourcepath' << source_paths.join(File::PATH_SEPARATOR) unless source_paths.empty?
+        cmd_args << '-d' << target
         cmd_args += javac_args
         cmd_args += files_from_sources(sources)
         unless Rake.application.options.dryrun
-          puts (["javac"] + cmd_args).join(" ") if Rake.application.options.trace
-          cmd_args = cmd_args.to_java_array(::Java.java.lang.String) if Java.jruby?
-          Java.import('com.sun.tools.javac.Main').compile(cmd_args) == 0 or fail "Failed to compile, see errors above"
+          puts (['javac'] + cmd_args).join(' ') if Rake.application.options.trace
+          #cmd_args = cmd_args.to_java_array(::Java.java.lang.String) if Java.jruby?
+          Java.load
+          Java.com.sun.tools.javac.Main.compile(cmd_args.map(&:to_s)) == 0 or fail 'Failed to compile, see errors above'
         end
       end
 
@@ -95,12 +96,12 @@
     # the hard work to calling #from and #using.
     #
     # For example:
-    #   javadoc.from(projects("myapp:foo", "myapp:bar")).using(:windowtitle=>"My App")
+    #   javadoc.from(projects('myapp:foo', 'myapp:bar')).using(:windowtitle=>'My App')
     # Or, short and sweet:
-    #   desc "My App"
-    #   define "myapp" do
+    #   desc 'My App'
+    #   define 'myapp' do
     #     . . .
-    #     javadoc projects("myapp:foo", "myapp:bar")
+    #     javadoc projects('myapp:foo', 'myapp:bar')
     #   end
     class JavadocTask < Rake::Task
 
@@ -112,8 +113,7 @@
         @files = FileList[]
         enhance do |task|
           rm_rf target.to_s, :verbose=>false
-          Java.javadoc source_files, options.merge(:classpath=>classpath, :sourcepath=>sourcepath,
-            :name=>name, :output=>File.expand_path(target.to_s))
+          generate source_files, File.expand_path(target.to_s), options.merge(:classpath=>classpath, :sourcepath=>sourcepath)
           touch target.to_s, :verbose=>false
         end
       end
@@ -128,7 +128,7 @@
       # as a prerequisite to a file task on the target directory.
       #
       # For example:
-      #   package :zip, :classifier=>"docs", :include=>javadoc.target
+      #   package :zip, :classifier=>'docs', :include=>javadoc.target
       def into(path)
         @target = file(path.to_s).enhance([self]) unless @target && @target.to_s == path.to_s
         self
@@ -177,7 +177,7 @@
       # Sets the Javadoc options from a hash and returns self.
       #
       # For example:
-      #   javadoc.using :windowtitle=>"My application"
+      #   javadoc.using :windowtitle=>'My application'
       def using(*args)
         args.pop.each { |key, value| @options[key.to_sym] = value } if Hash === args.last
         args.each { |key| @options[key.to_sym] = true }
@@ -195,7 +195,7 @@
       # by that project and classpath dependencies used when compiling.
       #
       # For example:
-      #   javadoc.from projects("myapp:foo", "myapp:bar")
+      #   javadoc.from projects('myapp:foo', 'myapp:bar')
       def from(*sources)
         sources.flatten.each do |source|
           case source
@@ -228,6 +228,40 @@
         source_files.map { |src| File.stat(src.to_s).mtime }.max > File.stat(target.to_s).mtime
       end
 
+    private
+
+      def generate(sources, target, options = {})
+        cmd_args = [ '-d', target, Rake.application.options.trace ? '-verbose' : '-quiet' ]
+        options.reject { |key, value| [:sourcepath, :classpath].include?(key) }.
+          each { |key, value| value.invoke if value.respond_to?(:invoke) }.
+          each do |key, value|
+            case value
+            when true, nil
+              cmd_args << "-#{key}"
+            when false
+              cmd_args << "-no#{key}"
+            when Hash
+              value.each { |k,v| cmd_args << "-#{key}" << k.to_s << v.to_s }
+            else
+              cmd_args += Array(value).map { |item| ["-#{key}", item.to_s] }.flatten
+            end
+          end
+        [:sourcepath, :classpath].each do |option|
+          Array(options[option]).flatten.tap do |paths|
+            cmd_args << "-#{option}" << paths.flatten.map(&:to_s).join(File::PATH_SEPARATOR) unless paths.empty?
+          end
+        end
+        cmd_args += sources.flatten.uniq
+        unless Rake.application.options.dryrun
+          puts "Generating Javadoc for #{name}" if verbose
+          puts (['javadoc'] + cmd_args).join(' ') if Rake.application.options.trace
+          Java.load
+          #cmd_args = cmd_args.to_java_array(::Java.java.lang.String) if Java.jruby?
+          Java.com.sun.tools.javadoc.Main.execute(cmd_args.map(&:to_s)) == 0 or
+            fail 'Failed to generate Javadocs, see errors above'
+        end
+      end
+
     end
 
 
@@ -283,9 +317,21 @@
     #
     def apt(*sources)
       sources = compile.sources if sources.empty?
-      file(path_to(:target, "generated/apt")=>sources) do |task|
-        Java.apt(sources.map(&:to_s) - [task.name], :output=>task.name,
-          :classpath=>compile.dependencies, :source=>compile.options.source)
+      file(path_to(:target, 'generated/apt')=>sources) do |task|
+        cmd_args = [ Rake.application.options.trace ? '-verbose' : '-nowarn' ]
+        cmd_args << '-nocompile' << '-s' << task.name
+        cmd_args << '-source' << compile.options.source if compile.options.source
+        classpath = Buildr.artifacts(compile.dependencies).map(&:to_s).each { |t| task(t).invoke }
+        cmd_args << '-cp' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
+        cmd_args += (sources.map(&:to_s) - [task.name]).
+          map { |arg| File.directory?(file) ? FileList["#{file}/**/*.java"] : file }.flatten
+        unless Rake.application.options.dryrun
+          puts 'Running apt' if verbose
+          puts (['apt'] + cmd_args).join(' ') if Rake.application.options.trace
+          #cmd_args = cmd_args.to_java_array(Java.java.lang.String) if Java.jruby?
+          Java.com.sun.tools.apt.Main.process(cmd_args.map(&:to_s)) == 0 or
+            fail 'Failed to process annotations, see errors above'
+        end
       end
     end
 

Modified: incubator/buildr/trunk/lib/java/java.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/java.rb?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/java.rb (original)
+++ incubator/buildr/trunk/lib/java/java.rb Wed Jan 16 01:11:40 2008
@@ -1,119 +1,21 @@
-require "rjb" if RUBY_PLATFORM != 'java'
-require "java" if RUBY_PLATFORM == 'java'
-require "core/project"
-
-module Buildr
-
-  # Base module for all things Java.
-  module Java
-
-    # Options accepted by #java and other methods here.
-    JAVA_OPTIONS = [ :verbose, :classpath, :name, :java_args, :properties ]
-
-    # Returned by Java#wrapper, you can use this object to set the classpath, specify blocks to be invoked
-    # after loading RJB, and load RJB itself.
-    #
-    # RJB can be loaded exactly once, and once loaded, you cannot change its classpath. Of course you can
-    # call libraries that manage their own classpath, but the lazy way is to just tell RJB of all the
-    # classpath dependencies you need in advance, before loading it.
-    #
-    # For that reason, you should not load RJB until the moment you need it. You can call #load or call
-    # Java#wrapper with a block. For the same reason, you may need to specify code to execute when loading
-    # (see #setup).
-    #
-    # JRuby doesn't have the above limitation, but uses the same API regardless.
-    class JavaWrapper #:nodoc:
-
-      include Singleton
-
-      def initialize() #:nodoc:
-        @classpath = [Java.tools_jar].compact
-        if Java.jruby?
-          # in order to get a complete picture, we need to add a few jars to the list.
-          @classpath += java.lang.System.getProperty('java.class.path').split(':').compact
-        end
-        @setup = []
-
-        setup do
-          setup do
-            cp = Buildr.artifacts(@classpath).map(&:to_s)
-            cp.each { |path| file(path).invoke }
-
-            if Java.jruby?
-              cp.each do |jlib|
-                require jlib
-              end
-            else
-              ::Rjb.load cp.join(File::PATH_SEPARATOR), Buildr.options.java_args.flatten
-            end
-          end
-        end
-      end
+require 'core/project'
+#ENV['JAVA_HOME'] = '...' if RUBY_PLATFORM =~ /darwin/i
+if PLATFORM == 'java'
+  require File.join(File.dirname(__FILE__), 'jruby')
+else
+  require File.join(File.dirname(__FILE__), 'rjb')
+end
 
-      attr_accessor :classpath
 
-      def setup(&block)
-        @setup << block
-        self
-      end
-      
-      def load(&block)
-        @setup.each { |block| block.call self }
-        @setup.clear
-      end
+# Base module for all things Java.
+module Java
 
-      def import(jlib)
-        if Java.jruby?
-          ::Java.instance_eval(jlib)
-        else
-          ::Rjb.import jlib
-        end
-      end
+  # JDK commands: java, javac, javadoc, etc.
+  module Commands
 
-      def method_missing(sym, *args, &block) #:nodoc:
-        # these aren't the same, but depending on method_missing while
-        # supporting two unrelated systems is asking for trouble anyways.
-        if Java.jruby?
-          ::Java.send sym, *args, &block
-        else
-          ::Rjb.send sym, *args, &block
-        end
-      end
-    end
-    
     class << self
 
       # :call-seq:
-      #   version() => string
-      #
-      # Returns the version number of the JVM.
-      #
-      # For example:
-      #   puts Java.version
-      #   => 1.5.0_10
-      def version()
-        @version ||= Java.wrapper { |jw| jw.import("java.lang.System").getProperty("java.version") }
-      end
-
-      # :call-seq:
-      #   tools_jar() => path
-      #
-      # Returns a path to tools.jar. On OS/X which has not tools.jar, returns an empty array,
-      # on all other platforms, fails if it doesn't find tools.jar.
-      def tools_jar()
-        return [] if darwin?
-        @tools ||= [File.join(home, "lib/tools.jar")] or raise "I need tools.jar to compile, can't find it in #{home}/lib"
-      end
-
-      # :call-seq:
-      #   home() => path
-      #
-      # Returns JAVA_HOME, fails if JAVA_HOME not set.
-      def home()
-        @home ||= ENV["JAVA_HOME"] or fail "Are we forgetting something? JAVA_HOME not set."
-      end
-
-      # :call-seq:
       #   java(class, *args, options?)
       #
       # Runs Java with the specified arguments.
@@ -122,31 +24,31 @@
       # * :classpath -- One or more file names, tasks or artifact specifications.
       #   These are all expanded into artifacts, and all tasks are invoked.
       # * :java_args -- Any additional arguments to pass (e.g. -hotspot, -xms)
-      # * :properties -- Hash of system properties (e.g. "path"=>base_dir).
+      # * :properties -- Hash of system properties (e.g. 'path'=>base_dir).
       # * :name -- Shows this name, otherwise shows the first argument (the class name).
       # * :verbose -- If true, prints the command and all its argument.
       def java(*args, &block)
         options = Hash === args.last ? args.pop : {}
         options[:verbose] ||= Rake.application.options.trace || false
-        rake_check_options options, *JAVA_OPTIONS
+        rake_check_options options, :classpath, :java_args, :properties, :name, :verbose
 
         name = options[:name] || "java #{args.first}"
-        cmd_args = [path_to_bin("java")]
+        cmd_args = [path_to_bin('java')]
         classpath = classpath_from(options)
-        cmd_args << "-cp" << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
+        cmd_args << '-cp' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
         options[:properties].each { |k, v| cmd_args << "-D#{k}=#{v}" } if options[:properties]
-        cmd_args += (options[:java_args] || Buildr.options.java_args).flatten
+        cmd_args += (options[:java_args] || (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split).flatten
         cmd_args += args.flatten.compact
         unless Rake.application.options.dryrun
           puts "Running #{name}" if verbose
           block = lambda { |ok, res| fail "Failed to execute #{name}, see errors above" unless ok } unless block
-          puts cmd_args.join(" ") if Rake.application.options.trace
-          system(cmd_args.map { |arg| %Q{"#{arg}"} }.join(" ")).tap do |ok|
+          puts cmd_args.join(' ') if Rake.application.options.trace
+          system(cmd_args.map { |arg| %Q{"#{arg}"} }.join(' ')).tap do |ok|
             block.call ok, $?
           end
         end
       end
-
+  
       # :call-seq:
       #   apt(*files, options)
       #
@@ -165,22 +67,22 @@
 
         files = args.flatten.map(&:to_s).
           collect { |arg| File.directory?(arg) ? FileList["#{arg}/**/*.java"] : arg }.flatten
-        cmd_args = [ Rake.application.options.trace ? "-verbose" : "-nowarn" ]
+        cmd_args = [ Rake.application.options.trace ? '-verbose' : '-nowarn' ]
         if options[:compile]
-          cmd_args << "-d" << options[:output].to_s
+          cmd_args << '-d' << options[:output].to_s
         else
-          cmd_args << "-nocompile" << "-s" << options[:output].to_s
+          cmd_args << '-nocompile' << '-s' << options[:output].to_s
         end
-        cmd_args << "-source" << options[:source] if options[:source]
+        cmd_args << '-source' << options[:source] if options[:source]
         classpath = classpath_from(options)
-        cmd_args << "-cp" << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
+        cmd_args << '-cp' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
         cmd_args += files
         unless Rake.application.options.dryrun
-          puts "Running apt" if verbose
-          puts (["apt"] + cmd_args).join(" ") if Rake.application.options.trace
-          cmd_args = cmd_args.to_java_array(::Java.java.lang.String) if Java.jruby?
-          Java.com.sun.tools.apt.Main.process(cmd_args) == 0 or
-            fail "Failed to process annotations, see errors above"
+          puts 'Running apt' if verbose
+          puts (['apt'] + cmd_args).join(' ') if Rake.application.options.trace
+          #cmd_args = cmd_args.to_java_array(Java.java.lang.String) if Java.jruby?
+          Java.com.sun.tools.apt.Main.process(cmd_args.map(&:to_s)) == 0 or
+            fail 'Failed to process annotations, see errors above'
         end
       end
 
@@ -206,17 +108,17 @@
 
         cmd_args = []
         classpath = classpath_from(options)
-        cmd_args << "-cp" << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
-        cmd_args << "-sourcepath" << options[:sourcepath].join(File::PATH_SEPARATOR) if options[:sourcepath]
-        cmd_args << "-d" << options[:output].to_s if options[:output]
+        cmd_args << '-cp' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
+        cmd_args << '-sourcepath' << options[:sourcepath].join(File::PATH_SEPARATOR) if options[:sourcepath]
+        cmd_args << '-d' << options[:output].to_s if options[:output]
         cmd_args += options[:javac_args].flatten if options[:javac_args]
         cmd_args += files
         unless Rake.application.options.dryrun
           puts "Compiling #{files.size} source files in #{name}" if verbose
-          puts (["javac"] + cmd_args).join(" ") if Rake.application.options.trace
-          cmd_args = cmd_args.to_java_array(::Java.java.lang.String) if Java.jruby?
-          Java.com.sun.tools.javac.Main.compile(cmd_args) == 0 or 
-            fail "Failed to compile, see errors above"
+          puts (['javac'] + cmd_args).join(' ') if Rake.application.options.trace
+          #cmd_args = cmd_args.to_java_array(Java.java.lang.String) if Java.jruby?
+          Java.com.sun.tools.javac.Main.compile(cmd_args.map(&:to_s)) == 0 or 
+            fail 'Failed to compile, see errors above'
         end
       end
 
@@ -234,12 +136,12 @@
       # All other options are passed to Javadoc as following:
       # * true -- As is, for example, :author=>true becomes -author
       # * false -- Prefixed, for example, :index=>false becomes -noindex
-      # * string -- Option with value, for example, :windowtitle=>"My project" becomes -windowtitle "My project"
+      # * string -- Option with value, for example, :windowtitle=>'My project' becomes -windowtitle "My project"
       # * array -- Option with set of values separated by spaces.
       def javadoc(*args)
         options = Hash === args.last ? args.pop : {}
 
-        cmd_args = [ "-d", options[:output], Rake.application.options.trace ? "-verbose" : "-quiet" ]
+        cmd_args = [ '-d', options[:output], Rake.application.options.trace ? '-verbose' : '-quiet' ]
         options.reject { |key, value| [:output, :name, :sourcepath, :classpath].include?(key) }.
           each { |key, value| value.invoke if value.respond_to?(:invoke) }.
           each do |key, value|
@@ -263,58 +165,25 @@
         name = options[:name] || Dir.pwd
         unless Rake.application.options.dryrun
           puts "Generating Javadoc for #{name}" if verbose
-          puts (["javadoc"] + cmd_args).join(" ") if Rake.application.options.trace
+          puts (['javadoc'] + cmd_args).join(' ') if Rake.application.options.trace
           Java.load
-          cmd_args = cmd_args.to_java_array(::Java.java.lang.String) if Java.jruby?
-          Java.import("com.sun.tools.javadoc.Main").execute(cmd_args) == 0 or
-            fail "Failed to generate Javadocs, see errors above"
+          cmd_args = cmd_args.to_java_array(Java.java.lang.String) if Java.jruby?
+          Java.com.sun.tools.javadoc.Main.execute(cmd_args.map(&:to_s)) == 0 or
+            fail 'Failed to generate Javadocs, see errors above'
         end
       end
 
-      # :call-seq:
-      #   wrapper() => JavaWrapper
-      #   wrapper() { ... }
-      #
-      # This method can be used in two ways. Without a block, returns the
-      # JavaWrapper object which you can use to configure the classpath or call
-      # other methods. With a block, loads RJB or sets up JRuby and yields to
-      # the block, returning its result.
-      #
-      # For example:
-      #   # Add class path dependency.
-      #   Java.wrapper.classpath << REQUIRES
-      #   # Require AntWrap when loading RJB/JRuby.
-      #   Java.wrapper.setup { require "antwrap" }
-      #
-      #  def execute(name, options)
-      #    options = options.merge(:name=>name, :base_dir=>Dir.pwd, :declarative=>true)
-      #    # Load RJB/JRuby and run AntWrap.
-      #    Java.wrapper { AntProject.new(options) }
-      #  end
-      def wrapper()
-        if block_given?
-          JavaWrapper.instance.load
-          yield JavaWrapper.instance
-        else
-          JavaWrapper.instance
-        end
-      end
+    protected
 
       # :call-seq:
       #   path_to_bin(cmd?) => path
       #
       # Returns the path to the specified Java command (with no argument to java itself).
-      def path_to_bin(name = "java")
-        File.join(home, "bin", name)
+      def path_to_bin(name = nil)
+        home = ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not set.'
+        File.join(home, 'bin', name.to_s)
       end
 
-      # return true if we a running on c-ruby and must use rjb
-      def rjb?; RUBY_PLATFORM != "java"; end
-      # return true if we are running on jruby
-      def jruby?; RUBY_PLATFORM == "java"; end
-
-  protected
-
       # :call-seq:
       #    classpath_from(options) => files
       #
@@ -324,105 +193,125 @@
         Buildr.artifacts(options[:classpath] || []).map(&:to_s).each { |t| task(t).invoke }
       end
 
-      def darwin?() #:nodoc:
-        RUBY_PLATFORM =~ /darwin/i
-      end
+    end
+
+  end
+
+end
+
+
+module Java
+
+  # *Deprecated:* In earlier versions, Java.wrapper served as a wrapper around RJB/JRuby.
+  # From this version forward, we apply with JRuby style for importing Java classes:
+  #   Java.java.lang.String.new('hai!')
+  # You still need to call Java.load before using any Java code: it resolves, downloads
+  # and installs various dependencies that are required on the classpath before calling
+  # any Java code (e.g. Ant and its tasks).
+  class Wrapper
+
+    include Singleton
 
+    # *Deprecated:* Append to Java.classpath directly.
+    def classpath
+      warn_deprecated 'Append to Java.classpath directly.'
+      Java.classpath
     end
 
-    # See Java#java.
-    def java(*args)
-      Java.java(*args)
+    def classpath=(paths)
+      fail 'Deprecated: Append to Java.classpath, you cannot replace the classpath.'
     end
 
-    def self.classpath
-      wrapper.classpath
+    # *Deprecated:* No longer necessary.
+    def setup
+      fail 'Deprecated: This method does not work with the new API'
+    end
+    
+    # *Deprecated:* Use Java.load instead.
+    def load
+      warn_deprecated 'Use Java.load instead.'
+      Java.load
     end
 
-    def self.load
-      wrapper.load
+    # *Deprecated:* Use Java.pkg.pkg.ClassName to import a Java class.
+    def import(class_name)
+      warn_deprecated 'Use Java.pkg.pkg.ClassName to import a Java class.'
+      Java.instance_eval(class_name)
     end
+  end
 
 
-    class Package #:nodoc:
+  class << self
 
-      def initialize(name)
-        @name = name
-      end
+    # *Deprecated*: Use Java::Commands.java instead.
+    def java(*args, &block)
+      warn_deprecated 'Use Java::Commands.java instead'
+      Commands.java(*args, &block)
+    end
 
-      attr_reader :name
+    # *Deprecated*: Use Java::Commands.apt instead.
+    def apt(*args)
+      warn_deprecated 'Use Java::Commands.apt instead'
+      Commands.apt(*args)
+    end
 
-      def method_missing(sym, *args, &block)
-        return super unless args.empty? && !block_given?
-        return ::Rjb.import("#{name}.#{sym}") if sym.to_s =~ /^[[:upper:]]/
-        @packages ||= {}
-        @packages[sym] ||= Package.new("#{name}.#{sym}")
-      end
+    # *Deprecated*: Use Java::Commands.javac instead.
+    def javac(*args)
+      warn_deprecated 'Use Java::Commands.javac instead'
+      Commands.javac(*args)
+    end
 
-      def to_s
-        name
-      end
-  
+    # *Deprecated*: Use Java::Commands.javadoc instead.
+    def javadoc(*args)
+      warn_deprecated 'Use Java::Commands.javadoc instead'
+      Commands.javadoc(*args)
+    end
+
+    # *Deprecated:* Use ENV_JAVA['java.version'] instead.
+    def version
+      warn_deprecated "Use ENV_JAVA['java.version'] instead"
+      Java.load
+      ENV_JAVA['java.version']
     end
 
-    def self.method_missing(sym, *args, &block)
-      return super unless args.empty? && !block_given?
-      return ::Rjb.import(sym.to_s) if sym.to_s =~ /^[[:upper:]]/
-      @packages ||= {}
-      @packages[sym] ||= Package.new(sym.to_s)
+    # *Deprecated:* Use ENV['JAVA_HOME'] instead
+    def home
+      warn_deprecated "Use ENV['JAVA_HOME'] instead"
+      ENV['JAVA_HOME']
     end
 
-    def self.import(cls)
-      wrapper.load
-      Rjb.import(cls)
-      #cls.split('.').inject(wrapper) { |wrapper, name| wrapper.send(name) }
+    # *Deprecated:* In earlier versions, Java.wrapper served as a wrapper around RJB/JRuby.
+    # From this version forward, we apply with JRuby style for importing Java classes:
+    #   Java.java.lang.String.new('hai!')
+    # You still need to call Java.load before using any Java code: it resolves, downloads
+    # and installs various dependencies that are required on the classpath before calling
+    # any Java code (e.g. Ant and its tasks).
+    def wrapper
+      if block_given?
+        Java.load
+        yield JavaWrapper.instance
+      else
+        JavaWrapper.instance
+      end
     end
 
   end
 
-  include Java
 
   class Options
 
-    # :call-seq:
-    #   java_args => array
-    #
-    # Returns the Java arguments.
-    def java_args()
-      @java_args ||= (ENV["JAVA_OPTS"] || ENV["JAVA_OPTIONS"] || "").split(" ")
-    end
-
-    # :call-seq:
-    #   java_args = array|string|nil
-    #
-    # Sets the Java arguments. These arguments are used when creating a JVM, including for use with RJB
-    # for most tasks (e.g. Ant, compile) and when forking a separate JVM (e.g. JUnit tests). You can also
-    # use the JAVA_OPTS environment variable.
-    #
-    # For example:
-    #   options.java_args = "-verbose"
-    # Or:
-    #   $ set JAVA_OPTS = "-Xms1g"
-    #   $ buildr
-    def java_args=(args)
-      args = args.split if String === args
-      @java_args = args.to_a
+    # *Deprecated:* Use ENV['JAVA_OPTS'] instead.
+    def java_args
+      warn_deprecated "Use ENV['JAVA_OPTS'] instead"
+      (ENV["JAVA_OPTS"] || ENV["JAVA_OPTIONS"]).to_s.split
     end
 
-  end
-
-end
-
-
-if Buildr::Java.jruby?
-  
-  # Convert a RubyArray to a Java Object[] array of the specified element_type
-  class Array #:nodoc:
-    def to_java_array(element_type)
-      java_array = ::Java.java.lang.reflect.Array.newInstance(element_type, self.size)
-      self.each_index { |i| java_array[i] = self[i] }
-      return java_array
+    # *Deprecated:* Use ENV['JAVA_OPTS'] instead.
+    def java_args=(args)
+      warn_deprecated "Use ENV['JAVA_OPTS'] instead"
+      ENV['JAVA_OPTS'] = Array(args).join(' ')
     end
+
   end
 
 end

Added: incubator/buildr/trunk/lib/java/jruby.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/jruby.rb?rev=612391&view=auto
==============================================================================
--- incubator/buildr/trunk/lib/java/jruby.rb (added)
+++ incubator/buildr/trunk/lib/java/jruby.rb Wed Jan 16 01:11:40 2008
@@ -0,0 +1,76 @@
+require 'java'
+
+
+# Buildr runs along side a JVM, using either RJB or JRuby.  The Java module allows
+# you to access Java classes and create Java objects.
+#
+# Java classes are accessed as static methods on the Java module, for example:
+#   str = Java.java.lang.String.new('hai!')
+#   str.toUpperCase
+#   => 'HAI!'
+#   Java.java.lang.String.isInstance(str)
+#   => true
+#   Java.com.sun.tools.javac.Main.compile(args)
+#
+# The classpath attribute allows Buildr to add JARs and directories to the classpath,
+# for example, we use it to load Ant and various Ant tasks, code generators, test
+# frameworks, and so forth.
+#
+# When using an artifact specification, Buildr will automatically download and
+# install the artifact before adding it to the classpath.
+#
+# For example, Ant is loaded as follows:
+#   Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
+#
+# Artifacts can only be downloaded after the Buildfile has loaded, giving it
+# a chance to specify which remote repositories to use, so adding to classpath
+# does not by itself load any libraries.  You must call Java.load before accessing
+# any Java classes to give Buildr a chance to load the libraries specified in the
+# classpath.
+#
+# When building an extension, make sure to follow these rules:
+# 1. Add to the classpath when the extension is loaded (i.e. in module or class
+#    definition), so the first call to Java.load anywhere in the code will include
+#    the libraries you specify.
+# 2. Call Java.load once before accessing any Java classes, allowing Buildr to
+#    set up the classpath.
+# 3. Only call Java.load when invoked, otherwise you may end up loading the JVM
+#    with a partial classpath, or before all remote repositories are listed.
+# 4. Check on a clean build with empty local repository.
+module Java
+
+  class << self
+
+    # Returns the classpath, an array listing directories, JAR files and
+    # artifacts.  Use when loading the extension to add any additional
+    # libraries used by that extension.
+    #
+    # For example, Ant is loaded as follows:
+    #   Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
+    def classpath
+      @classpath ||= java.lang.System.getProperty('java.class.path').split(':').compact
+    end
+
+    # Loads the JVM and all the libraries listed on the classpath.  Call this
+    # method before accessing any Java class, but only call it from methods
+    # used in the build, giving the Buildfile a chance to load all extensions
+    # that append to the classpath and specify which remote repositories to use.
+    def load
+      return self unless @loaded
+      cp = Buildr.artifacts(classpath).map(&:to_s).each { |path| file(path).invoke }
+      $LOAD_PATH.concat cp
+      self
+    end
+
+  end
+
+end
+
+# Convert a RubyArray to a Java Object[] array of the specified element_type
+class Array #:nodoc:
+  def to_java_array(element_type)
+    java_array = ::Java.java.lang.reflect.Array.newInstance(element_type, self.size)
+    self.each_index { |i| java_array[i] = self[i] }
+    return java_array
+  end
+end

Modified: incubator/buildr/trunk/lib/java/org/apache/buildr/JUnitTestFilter.java
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/org/apache/buildr/JUnitTestFilter.java?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/org/apache/buildr/JUnitTestFilter.java (original)
+++ incubator/buildr/trunk/lib/java/org/apache/buildr/JUnitTestFilter.java Wed Jan 16 01:11:40 2008
@@ -17,8 +17,8 @@
   }
 
   public String[] filter(String[] names) throws ClassNotFoundException {
-    Vector testCases = new Vector();
-    Class testCase = _loader.loadClass("junit.framework.TestCase");
+    Vector<String> testCases = new Vector<String>();
+    Class<?> testCase = _loader.loadClass("junit.framework.TestCase");
     for (int i = 0 ; i < names.length ; ++i) {
       Class cls = _loader.loadClass(names[i]);
       if (testCase.isAssignableFrom(cls))

Modified: incubator/buildr/trunk/lib/java/packaging.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/packaging.rb?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/packaging.rb (original)
+++ incubator/buildr/trunk/lib/java/packaging.rb Wed Jan 16 01:11:40 2008
@@ -5,10 +5,10 @@
 
 
 module Buildr
-  module Java
+  module Packaging
 
     # Adds packaging for Java projects: JAR, WAR, AAR, EAR, Javadoc.
-    module Packaging
+    module Java
 
       # Adds support for MANIFEST.MF and other META-INF files.
       module WithManifest #:nodoc:
@@ -400,8 +400,9 @@
       include Extension
 
       before_define do |project|
+        ::Java.load
         project.manifest ||= project.parent && project.parent.manifest ||
-          { 'Build-By'=>ENV['USER'], 'Build-Jdk'=>Java.version,
+          { 'Build-By'=>ENV['USER'], 'Build-Jdk'=>ENV_JAVA['java.version'],
             'Implementation-Title'=>project.comment || project.name,
             'Implementation-Version'=>project.version }
         project.meta_inf ||= project.parent && project.parent.meta_inf ||
@@ -477,7 +478,7 @@
     protected
 
       def package_as_jar(file_name) #:nodoc:
-        Java::Packaging::JarTask.define_task(file_name).tap do |jar|
+        Java::JarTask.define_task(file_name).tap do |jar|
           jar.with :manifest=>manifest, :meta_inf=>meta_inf
           jar.with compile.target unless compile.sources.empty?
           jar.with resources.target unless resources.sources.empty?
@@ -485,7 +486,7 @@
       end
 
       def package_as_war(file_name) #:nodoc:
-        Java::Packaging::WarTask.define_task(file_name).tap do |war|
+        Java::WarTask.define_task(file_name).tap do |war|
           war.with :manifest=>manifest, :meta_inf=>meta_inf
           # Add libraries in WEB-INF lib, and classes in WEB-INF classes
           classes = []
@@ -500,7 +501,7 @@
       end
 
       def package_as_aar(file_name) #:nodoc:
-        Java::Packaging::AarTask.define_task(file_name).tap do |aar|
+        Java::AarTask.define_task(file_name).tap do |aar|
           aar.with :manifest=>manifest, :meta_inf=>meta_inf
           aar.with :wsdls=>path_to(:source, :main, :axis2, '*.wsdl')
           aar.with :services_xml=>path_to(:source, :main, :axis2, 'services.xml') 
@@ -511,7 +512,7 @@
       end
 
       def package_as_ear(file_name) #:nodoc:
-        Java::Packaging::EarTask.define_task(file_name).tap do |ear|
+        Java::EarTask.define_task(file_name).tap do |ear|
           ear.send :associate, self
           ear.with :display_name=>id, :manifest=>manifest, :meta_inf=>meta_inf
         end
@@ -535,5 +536,5 @@
 
 
 class Buildr::Project
-  include Buildr::Java::Packaging
+  include Buildr::Packaging::Java
 end

Added: incubator/buildr/trunk/lib/java/rjb.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/rjb.rb?rev=612391&view=auto
==============================================================================
--- incubator/buildr/trunk/lib/java/rjb.rb (added)
+++ incubator/buildr/trunk/lib/java/rjb.rb Wed Jan 16 01:11:40 2008
@@ -0,0 +1,116 @@
+require 'rjb'
+
+# Equivalent to Java system properties.  For example:
+#   ENV_JAVA['java.version']
+#   ENV_JAVA['java.class.version']
+ENV_JAVA = {}
+
+
+# Buildr runs along side a JVM, using either RJB or JRuby.  The Java module allows
+# you to access Java classes and create Java objects.
+#
+# Java classes are accessed as static methods on the Java module, for example:
+#   str = Java.java.lang.String.new('hai!')
+#   str.toUpperCase
+#   => 'HAI!'
+#   Java.java.lang.String.isInstance(str)
+#   => true
+#   Java.com.sun.tools.javac.Main.compile(args)
+#
+# The classpath attribute allows Buildr to add JARs and directories to the classpath,
+# for example, we use it to load Ant and various Ant tasks, code generators, test
+# frameworks, and so forth.
+#
+# When using an artifact specification, Buildr will automatically download and
+# install the artifact before adding it to the classpath.
+#
+# For example, Ant is loaded as follows:
+#   Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
+#
+# Artifacts can only be downloaded after the Buildfile has loaded, giving it
+# a chance to specify which remote repositories to use, so adding to classpath
+# does not by itself load any libraries.  You must call Java.load before accessing
+# any Java classes to give Buildr a chance to load the libraries specified in the
+# classpath.
+#
+# When building an extension, make sure to follow these rules:
+# 1. Add to the classpath when the extension is loaded (i.e. in module or class
+#    definition), so the first call to Java.load anywhere in the code will include
+#    the libraries you specify.
+# 2. Call Java.load once before accessing any Java classes, allowing Buildr to
+#    set up the classpath.
+# 3. Only call Java.load when invoked, otherwise you may end up loading the JVM
+#    with a partial classpath, or before all remote repositories are listed.
+# 4. Check on a clean build with empty local repository.
+module Java
+
+  module Package #:nodoc:
+
+    def method_missing(sym, *args, &block)
+      raise ArgumentError, 'No arguments expected' unless args.empty?
+      name = "#{@name}.#{sym}"
+      return ::Rjb.import(name) if sym.to_s =~ /^[[:upper:]]/
+      Java.send :__package__, name
+    end
+
+  end
+
+  class << self
+
+    # Returns the classpath, an array listing directories, JAR files and
+    # artifacts.  Use when loading the extension to add any additional
+    # libraries used by that extension.
+    #
+    # For example, Ant is loaded as follows:
+    #   Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
+    def classpath
+      @classpath ||= []
+    end
+
+    # Loads the JVM and all the libraries listed on the classpath.  Call this
+    # method before accessing any Java class, but only call it from methods
+    # used in the build, giving the Buildfile a chance to load all extensions
+    # that append to the classpath and specify which remote repositories to use.
+    def load
+      return self unless @loaded
+      unless RUBY_PLATFORM =~ /darwin/i
+        home = ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not set.'
+        tools = File.expand_path('lib/tools.jar', home)
+        raise "I need tools.jar to compile, can't find it in #{home}/lib" unless File.exist?(tools)
+        classpath << tools
+      end
+      cp = Buildr.artifacts(classpath).map(&:to_s).each { |path| file(path).invoke }
+      java_opts = (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split
+      ::Rjb.load cp.join(File::PATH_SEPARATOR), java_opts
+
+      props = ::Rjb.import('java.lang.System').getProperties
+      enum = props.propertyNames 
+      while enum.hasMoreElements
+        name = enum.nextElement.toString
+        ENV_JAVA[name] = props.getProperty(name)
+      end
+      @loaded = true
+      self
+    end
+
+    def method_missing(sym, *args, &block) #:nodoc:
+      raise ArgumentError, 'No arguments expected' unless args.empty?
+      name = sym.to_s
+      return ::Rjb.import(name) if name =~ /^[[:upper:]]/
+      __package__ name
+    end
+
+  private
+
+    def __package__(name) #:nodoc:
+      const = name.split('.').map { |part| part.gsub(/^./) { |char| char.upcase } }.join
+      return Java.const_get(const) if Java.const_defined?(const)
+      package = Module.new
+      package.extend Package
+      package.instance_variable_set :@name, name
+      Java.const_set(const, package)
+    end
+
+  end
+
+end

Modified: incubator/buildr/trunk/lib/java/test_frameworks.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/test_frameworks.rb?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/test_frameworks.rb (original)
+++ incubator/buildr/trunk/lib/java/test_frameworks.rb Wed Jan 16 01:11:40 2008
@@ -92,7 +92,8 @@
 
 
     # Ant-JUnit requires for JUnit and JUnit reports tasks.  Also requires JUnitTestFilter.
-    Java.classpath << "org.apache.ant:ant-junit:jar:#{Ant::VERSION}" << File.join(File.dirname(__FILE__))
+    Java.classpath << "org.apache.ant:ant-junit:jar:#{Ant::VERSION}"
+    Java.classpath << File.join(File.dirname(__FILE__))
 
     # JUnit version number.
     VERSION = '4.3.1' unless const_defined?('VERSION')
@@ -114,6 +115,7 @@
         map { |file| Pathname.new(file).relative_path_from(target).to_s.ext('').gsub(File::SEPARATOR, '.') }.
         reject { |name| name =~ /\$/ }
       classpath = [target.to_s + '/'] + Buildr.artifacts(dependencies).map(&:to_s)
+      Java.load
       Java.org.apache.buildr.JUnitTestFilter.new(classpath).filter(candidates)
     end
 
@@ -135,9 +137,6 @@
           ant.classpath :path=>dependencies.each { |path| file(path).invoke }.join(File::PATH_SEPARATOR)
           (options[:properties] || []).each { |key, value| ant.sysproperty :key=>key, :value=>value }
           (options[:environment] || []).each { |key, value| ant.env :key=>key, :value=>value }
-          java_args = options[:java_args] || Buildr.options.java_args
-          java_args = java_args.split(/\s+/) if String === java_args
-          java_args.each { |value| ant.jvmarg :value=>value } if java_args
           ant.formatter :type=>'plain'
           ant.formatter :type=>'plain', :usefile=>false # log test
           ant.formatter :type=>'xml'
@@ -216,7 +215,7 @@
                       :classpath=>dependencies }
       tests.inject([]) do |passed, test|
         begin
-          Buildr.java cmd_args, '-testclass', test, cmd_options.merge(:name=>test)
+          Java::Commands.java cmd_args, '-testclass', test, cmd_options.merge(:name=>test)
           passed << test
         rescue
           passed

Modified: incubator/buildr/trunk/lib/tasks/zip.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/tasks/zip.rb?rev=612391&r1=612390&r2=612391&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/tasks/zip.rb (original)
+++ incubator/buildr/trunk/lib/tasks/zip.rb Wed Jan 16 01:11:40 2008
@@ -336,13 +336,8 @@
       options.each do |key, value|
         begin
           send "#{key}=", value
-        rescue NameError
-          if respond_to?(:[]=) # Backward compatible with Buildr 1.1.
-            warn_deprecated "The []= method is deprecated, please use attribute accessors instead."
-            self[key] = value
-          else
-            raise ArgumentError, "This task does not support the option #{key}."
-          end
+        rescue NoMethodError
+          raise ArgumentError, "#{self.class.name} does not support the option #{key}"
         end
       end
       self