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/28 03:23:37 UTC
svn commit: r615715 - in /incubator/buildr/trunk: lib/buildr/antlr.rb
lib/buildr/javacc.rb lib/core/compile.rb lib/core/test.rb
lib/java/compilers.rb lib/java/java.rb lib/java/jruby.rb
spec/java_compilers.rb
Author: assaf
Date: Sun Jan 27 18:23:36 2008
New Revision: 615715
URL: http://svn.apache.org/viewvc?rev=615715&view=rev
Log:
More fixes for JRuby, and exposing project on compile and test tasks
Modified:
incubator/buildr/trunk/lib/buildr/antlr.rb
incubator/buildr/trunk/lib/buildr/javacc.rb
incubator/buildr/trunk/lib/core/compile.rb
incubator/buildr/trunk/lib/core/test.rb
incubator/buildr/trunk/lib/java/compilers.rb
incubator/buildr/trunk/lib/java/java.rb
incubator/buildr/trunk/lib/java/jruby.rb
incubator/buildr/trunk/spec/java_compilers.rb
Modified: incubator/buildr/trunk/lib/buildr/antlr.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/antlr.rb?rev=615715&r1=615714&r2=615715&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/antlr.rb (original)
+++ incubator/buildr/trunk/lib/buildr/antlr.rb Sun Jan 27 18:23:36 2008
@@ -21,7 +21,7 @@
end
Java.load
#Java.org.antlr.Tool.new_with_sig("[Ljava.lang.String;", args).process
- Java.org.antlr.Tool.new(args.map(&:to_s)).process
+ Java.org.antlr.Tool.new(args.to_java(Java.java.lang.String)).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=615715&r1=615714&r2=615715&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/javacc.rb (original)
+++ incubator/buildr/trunk/lib/buildr/javacc.rb Sun Jan 27 18:23:36 2008
@@ -17,7 +17,7 @@
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.load
- Java.org.javacc.parser.Main.mainProgram(args) == 0 or
+ Java.org.javacc.parser.Main.mainProgram(args.to_java(Java.java.lang.String)) == 0 or
fail "Failed to run JavaCC, see errors above."
end
@@ -29,7 +29,7 @@
args.unshift "-OUTPUT_DIRECTORY=#{options[:output]}" if options[:output]
args.unshift "-BUILD_NODE_FILES=#{options[:build_node_files] || false}"
Java.load
- Java.org.javacc.jjtree.JJTree.new.main(args) == 0 or
+ Java.org.javacc.jjtree.JJTree.new.main(args.to_java(Java.java.lang.String)) == 0 or
fail "Failed to run JJTree, see errors above."
end
Modified: incubator/buildr/trunk/lib/core/compile.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/compile.rb?rev=615715&r1=615714&r2=615715&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/compile.rb (original)
+++ incubator/buildr/trunk/lib/core/compile.rb Sun Jan 27 18:23:36 2008
@@ -306,9 +306,10 @@
target ? target.timestamp : Rake::EARLY
end
- protected
-
+ # The project this task belongs to.
attr_reader :project
+
+ protected
# Selects which compiler to use.
def compiler=(name) #:nodoc:
Modified: incubator/buildr/trunk/lib/core/test.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/test.rb?rev=615715&r1=615714&r2=615715&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/test.rb (original)
+++ incubator/buildr/trunk/lib/core/test.rb Sun Jan 27 18:23:36 2008
@@ -369,9 +369,10 @@
@report_to ||= file(@project.path_to(:reports, framework)=>self)
end
- protected
-
+ # The project this task belongs to.
attr_reader :project
+
+ protected
def associate_with(project)
@project = project
Modified: incubator/buildr/trunk/lib/java/compilers.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/compilers.rb?rev=615715&r1=615714&r2=615715&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/compilers.rb (original)
+++ incubator/buildr/trunk/lib/java/compilers.rb Sun Jan 27 18:23:36 2008
@@ -38,6 +38,8 @@
def compile(sources, target, dependencies) #:nodoc:
check_options options, OPTIONS
cmd_args = []
+ tools = File.expand_path('lib/tools.jar', ENV['JAVA_HOME']) if ENV['JAVA_HOME']
+ dependencies << tools if tools && File.exist?(tools)
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?
Modified: incubator/buildr/trunk/lib/java/java.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/java.rb?rev=615715&r1=615714&r2=615715&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/java.rb (original)
+++ incubator/buildr/trunk/lib/java/java.rb Sun Jan 27 18:23:36 2008
@@ -76,11 +76,14 @@
end
cmd_args << '-source' << options[:source] if options[:source]
classpath = classpath_from(options)
+ tools = File.expand_path('lib/tools.jar', ENV['JAVA_HOME']) if ENV['JAVA_HOME']
+ classpath << tools if tools && File.exist?(tools)
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
+ Java.load
Java.com.sun.tools.apt.Main.process(cmd_args.to_java(Java.java.lang.String)) == 0 or
fail 'Failed to process annotations, see errors above'
end
@@ -116,6 +119,7 @@
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
+ Java.load
Java.com.sun.tools.javac.Main.compile(cmd_args.to_java(Java.java.lang.String)) == 0 or
fail 'Failed to compile, see errors above'
end
@@ -213,7 +217,7 @@
# *Deprecated:* Append to Java.classpath directly.
def classpath
warn_deprecated 'Append to Java.classpath instead.'
- Java.classpath
+ ::Java.classpath
end
def classpath=(paths)
@@ -229,7 +233,7 @@
# *Deprecated:* Use Java.load instead.
def load
warn_deprecated 'Use Java.load instead.'
- Java.load
+ ::Java.load
end
alias :onload :setup
@@ -237,7 +241,7 @@
# *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)
+ ::Java.instance_eval(class_name)
end
end
Modified: incubator/buildr/trunk/lib/java/jruby.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/jruby.rb?rev=615715&r1=615714&r2=615715&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/jruby.rb (original)
+++ incubator/buildr/trunk/lib/java/jruby.rb Sun Jan 27 18:23:36 2008
@@ -1,4 +1,5 @@
require 'java'
+require 'jruby'
# Buildr runs along side a JVM, using either RJB or JRuby. The Java module allows
@@ -48,7 +49,7 @@
# 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
+ @classpath ||= []
end
# Loads the JVM and all the libraries listed on the classpath. Call this
@@ -58,30 +59,34 @@
def load
return self if @loaded
cp = Buildr.artifacts(classpath).map(&:to_s).each { |path| file(path).invoke }
- cp.each do |lib|
- if File.file?(lib)
- require lib # JRuby can load jars in runtime
- else
- $CLASSPATH << lib
- end
+ #cp ||= java.lang.System.getProperty('java.class.path').split(':').compact
+ # Use system ClassLoader to add classpath.
+ sysloader = java.lang.ClassLoader.getSystemClassLoader
+ add_url_method = java.lang.Class.forName('java.net.URLClassLoader').
+ getDeclaredMethod('addURL', [java.net.URL].to_java(java.lang.Class))
+ add_url_method.setAccessible(true)
+ add_path = lambda { |path| add_url_method.invoke(sysloader, [java.io.File.new(path).toURL].to_java(java.net.URL)) }
+ # Include tools (compiler, Javadoc, etc) for all platforms except OS/X.
+ unless Config::CONFIG['host_os'] =~ /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 "Missing #{tools}, perhaps your JAVA_HOME is not correclty set" unless File.file?(tools)
+ add_path[tools]
end
- load_java_tools unless Config::CONFIG['host_os'] =~ /darwin/i
+ cp.each { |path| add_path[path] }
@loaded = true
self
end
+=begin
def load_java_tools
home = ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not set.'
tools = File.expand_path('lib/tools.jar', home)
raise "Missing #{tools}, perhaps your JAVA_HOME is not correclty set" unless File.file?(tools)
- sysloader = java.lang.ClassLoader.getSystemClassLoader
- add_url_method = java.lang.Class.forName('java.net.URLClassLoader').
- getDeclaredMethod('addURL', [java.net.URL].to_java(java.lang.Class))
- add_url_method.setAccessible(true)
- list = java.util.ArrayList.new
- list.add(java.io.File.new(tools).toURL)
- add_url_method.invoke(sysloader, list.toArray)
+ loader = JRuby.runtime.get_jruby_class_loader
+ loader.add_url(java.io.File.new(tools).toURL)
end
+=end
end
Modified: incubator/buildr/trunk/spec/java_compilers.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/java_compilers.rb?rev=615715&r1=615714&r2=615715&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/java_compilers.rb (original)
+++ incubator/buildr/trunk/spec/java_compilers.rb Sun Jan 27 18:23:36 2008
@@ -31,7 +31,7 @@
end
end
- it 'should include as classpath dependency' do
+ it 'should include classpath dependencies' do
write 'src/dependency/Dependency.java', 'class Dependency {}'
define 'dependency', :version=>'1.0' do
compile.from('src/dependency').into('target/dependency')