BaseExtensionTask
(Not documented)
# File lib/rake/javaextensiontask.rb, line 38
38: def define
39: super
40:
41: define_java_platform_tasks
42: end
(Not documented)
# File lib/rake/javaextensiontask.rb, line 28
28: def init(name = nil, gem_spec = nil)
29: super
30: @source_pattern = '**/*.java'
31: @classpath = nil
32: @java_compiling = nil
33: @debug = false
34: @source_version = '1.5'
35: @target_version = '1.5'
36: end
(Not documented)
# File lib/rake/javaextensiontask.rb, line 45
45: def define_compile_tasks(for_platform = nil, ruby_ver = RUBY_VERSION)
46: # platform usage
47: platf = for_platform || platform
48:
49: # lib_path
50: lib_path = lib_dir
51:
52: # tmp_path
53: tmp_path = "#{@tmp_dir}/#{platf}/#{@name}"
54:
55: # cleanup and clobbering
56: CLEAN.include(tmp_path)
57: CLOBBER.include("#{lib_path}/#{binary(platf)}")
58: CLOBBER.include("#{@tmp_dir}")
59:
60: # directories we need
61: directory tmp_path
62: directory lib_dir
63:
64: # copy binary from temporary location to final lib
65: # tmp/extension_name/extension_name.{so,bundle} => lib/
66: task "copy:#{@name}:#{platf}" => [lib_path, "#{tmp_path}/#{binary(platf)}"] do
67: cp "#{tmp_path}/#{binary(platf)}", "#{lib_path}/#{binary(platf)}"
68: end
69:
70: not_jruby_compile_msg = "WARNING: You're cross-compiling a binary extension for JRuby, but are using\nanother interpreter. If your Java classpath or extension dir settings are not\ncorrectly detected, then either check the appropriate environment variables or\nexecute the Rake compilation task using the JRuby interpreter.\n(e.g. `jruby -S rake compile:java`)\n"
71: warn_once(not_jruby_compile_msg) unless defined?(JRUBY_VERSION)
72:
73: file "#{tmp_path}/#{binary(platf)}" => "#{tmp_path}/.build" do
74:
75: class_files = FileList["#{tmp_path}/**/*.class"].
76: gsub("#{tmp_path}/", '')
77:
78: # avoid environment variable expansion using backslash
79: class_files.gsub!('$', '\$') unless windows?
80:
81: args = class_files.map { |path|
82: ["-C #{tmp_path}", path]
83: }.flatten
84:
85: sh "jar cf #{tmp_path}/#{binary(platf)} #{args.join(' ')}"
86: end
87:
88: file "#{tmp_path}/.build" => [tmp_path] + source_files do
89: classpath_arg = java_classpath_arg(@classpath)
90: debug_arg = @debug ? '-g' : ''
91:
92: sh "javac #{java_extdirs_arg} -target #{@target_version} -source #{@source_version} -Xlint:unchecked #{debug_arg} #{classpath_arg} -d #{tmp_path} #{source_files.join(' ')}"
93:
94: # Checkpoint file
95: touch "#{tmp_path}/.build"
96: end
97:
98: # compile tasks
99: unless Rake::Task.task_defined?('compile') then
100: desc "Compile all the extensions"
101: task "compile"
102: end
103:
104: # compile:name
105: unless Rake::Task.task_defined?("compile:#{@name}") then
106: desc "Compile #{@name}"
107: task "compile:#{@name}"
108: end
109:
110: # Allow segmented compilation by platform (open door for 'cross compile')
111: task "compile:#{@name}:#{platf}" => ["copy:#{@name}:#{platf}"]
112: task "compile:#{platf}" => ["compile:#{@name}:#{platf}"]
113:
114: # Only add this extension to the compile chain if current
115: # platform matches the indicated one.
116: if platf == RUBY_PLATFORM then
117: # ensure file is always copied
118: file "#{lib_path}/#{binary(platf)}" => ["copy:#{name}:#{platf}"]
119:
120: task "compile:#{@name}" => ["compile:#{@name}:#{platf}"]
121: task "compile" => ["compile:#{platf}"]
122: end
123: end
(Not documented)
# File lib/rake/javaextensiontask.rb, line 132
132: def define_java_platform_tasks
133: # lib_path
134: lib_path = lib_dir
135:
136: if @gem_spec && !Rake::Task.task_defined?("java:#{@gem_spec.name}")
137: task "java:#{@gem_spec.name}" do |t|
138:
139: # FIXME: truly duplicate the Gem::Specification
140: spec = gem_spec.dup
141:
142: # adjust to specified platform
143: spec.platform = Gem::Platform.new('java')
144:
145: # clear the extensions defined in the specs
146: spec.extensions.clear
147:
148: # add the binaries that this task depends on
149: ext_files = []
150:
151: # go through native prerequisites and grab the real extension files from there
152: t.prerequisites.each do |ext|
153: ext_files << ext
154: end
155:
156: # include the files in the gem specification
157: spec.files += ext_files
158:
159: # expose gem specification for customization
160: if @java_compiling
161: @java_compiling.call(spec)
162: end
163:
164: # Generate a package for this gem
165: gem_package = Rake::GemPackageTask.new(spec) do |pkg|
166: pkg.need_zip = false
167: pkg.need_tar = false
168: end
169: end
170:
171: # add binaries to the dependency chain
172: task "java:#{@gem_spec.name}" => ["#{lib_path}/#{binary(platform)}"]
173:
174: # ensure the extension get copied
175: unless Rake::Task.task_defined?("#{lib_path}/#{binary(platform)}") then
176: file "#{lib_path}/#{binary(platform)}" => ["copy:#{name}:#{platform}"]
177: end
178:
179: task 'java' => ["java:#{@gem_spec.name}"]
180: end
181:
182: task 'java' do
183: task 'compile' => 'compile:java'
184: end
185: end
Discover the Java/JRuby classpath and build a classpath argument
@params
*args:: Additional classpath arguments to append
Copied verbatim from the ActiveRecord-JDBC project. There are a small myriad of ways to discover the Java classpath correctly.
# File lib/rake/javaextensiontask.rb, line 205
205: def java_classpath_arg(*args)
206: jruby_cpath = nil
207: if RUBY_PLATFORM =~ /java/
208: begin
209: cpath = Java::java.lang.System.getProperty('java.class.path').split(File::PATH_SEPARATOR)
210: cpath += Java::java.lang.System.getProperty('sun.boot.class.path').split(File::PATH_SEPARATOR)
211: jruby_cpath = cpath.compact.join(File::PATH_SEPARATOR)
212: rescue => e
213: end
214: end
215: unless jruby_cpath
216: jruby_cpath = ENV['JRUBY_PARENT_CLASSPATH'] || ENV['JRUBY_HOME'] &&
217: Dir.glob("#{File.expand_path(ENV['JRUBY_HOME'])}/lib/*.jar").
218: join(File::PATH_SEPARATOR)
219: end
220: raise "JRUBY_HOME or JRUBY_PARENT_CLASSPATH are not set" unless jruby_cpath
221: jruby_cpath += File::PATH_SEPARATOR + args.join(File::PATH_SEPARATOR) unless args.empty?
222: jruby_cpath ? "-cp \"#{jruby_cpath}\"" : ""
223: end
Discover Java Extension Directories and build an extdirs argument
# File lib/rake/javaextensiontask.rb, line 190
190: def java_extdirs_arg
191: extdirs = Java::java.lang.System.getProperty('java.ext.dirs') rescue nil
192: extdirs = ENV['JAVA_EXT_DIR'] unless extdirs
193: java_extdir = extdirs.nil? ? "" : "-extdirs \"#{extdirs}\""
194: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.