Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Sync Java compilation scenarios

Merged Java compilation scenarios with minor adjustments
to exclude non-POSIX OS.
  • Loading branch information...
commit 3f2743234235279bf0ce7e3b6e5ac96603c94bcc 1 parent f729a4b
Alex Coles myabc authored luislavena committed
3  cucumber.yml
View
@@ -1 +1,4 @@
+default: --tags ~@java --format progress features
+java: --tags @java --format progress features
+all: --format progress features
autotest: --format progress features
22 features/java-compile.feature
View
@@ -0,0 +1,22 @@
+Feature: JCompile Java extensions
+
+ In order to avoid bitching from Enterprise users
+ As a Ruby developer
+ I want some rake tasks that take away the pain of compilation
+
+ @java
+ Scenario: Compile single Java extension (with default Rake)
+ Given that all my Java source files are in place
+ And I've installed the Java Development Kit
+ When rake task 'java compile' is invoked
+ Then rake task 'java compile' succeeded
+ And binaries for platform 'java' get generated
+
+ @java
+ Scenario: Compile single Java extension (with Rake on JRuby)
+ Given that all my Java source files are in place
+ And I've installed the Java Development Kit
+ When I've installed JRuby
+ When rake task 'java compile' is invoked on JRuby
+ Then rake task 'java compile' succeeded
+ And binaries for platform 'java' get generated
33 features/java-no-native-compile.feature
View
@@ -0,0 +1,33 @@
+Feature: No native or cross compilation on JRuby
+
+ In order to present a good user experience to users of rake-compiler
+ As a user of JRuby
+ I want to be warned that my platform does not provide any support for C Extensions
+ I want to be be informed of this without rake-compiler blowing up in my face
+
+ @java
+ Scenario: Attempting to do a cross compilation while on JRuby (without prerequisites)
+ Given that all my source files are in place
+ And I'm running a POSIX operating system
+ When rake task 'cross compile' is invoked on JRuby
+ Then rake task 'cross compile' should fail
+ And output of rake task 'cross compile' warns
+ """
+ WARNING: You're attempting to (cross-)compile C extensions from a platform
+ (jruby) that does not support native extensions or mkmf.rb.
+ """
+ And output of rake task 'cross compile' contains /Don't know how to build task 'cross'/
+
+ @java
+ Scenario: Attempting to do a cross compilation while on JRuby (even with prerequisites)
+ Given that all my source files are in place
+ And I'm running a POSIX operating system
+ And I've installed cross compile toolchain
+ When rake task 'cross compile' is invoked on JRuby
+ Then rake task 'cross compile' should fail
+ And output of rake task 'cross compile' warns
+ """
+ WARNING: You're attempting to (cross-)compile C extensions from a platform
+ (jruby) that does not support native extensions or mkmf.rb.
+ """
+ And output of rake task 'cross compile' contains /Don't know how to build task 'cross'/
24 features/java-package.feature
View
@@ -0,0 +1,24 @@
+Feature: Generate JRuby gems from JRuby or MRI
+
+ In order to keep sanity in the Ruby world
+ As a Gem developer who used to do J2EE development
+ I want more rake magic that turns monotony into joy.
+
+ @java
+ Scenario: package a gem for Java (with default Rake)
+ Given that my JRuby gem source is all in place
+ And I've installed the Java Development Kit
+ And I've already successfully executed rake task 'java compile'
+ When rake task 'java gem' is invoked
+ Then rake task 'java gem' succeeded
+ And gem for platform 'java' get generated
+
+ @java
+ Scenario: package a gem for Java (with Rake on JRuby)
+ Given that my JRuby gem source is all in place
+ And I've installed the Java Development Kit
+ And I've installed JRuby
+ And I've already successfully executed rake task 'java compile' on JRuby
+ When rake task 'java gem' is invoked
+ Then rake task 'java gem' succeeded
+ And gem for platform 'java' get generated
16 features/step_definitions/compilation.rb
View
@@ -8,6 +8,11 @@
generate_source_code_for extension_name
end
+Given /^a extension Java-compilable '(.*)'$/ do |extension_name|
+ generate_java_compile_extension_task_for extension_name
+ generate_java_source_code_for extension_name
+end
+
Given /^a extension '(.*)' multi cross\-compilable$/ do |extension_name|
generate_multi_cross_compile_extension_task_for extension_name
generate_source_code_for extension_name
@@ -23,12 +28,23 @@
Given "a extension cross-compilable 'extension_one'"
end
+Given /^that all my Java source files are in place$/ do
+ Given "a safe project directory"
+ Given "a extension Java-compilable 'extension_one'"
+end
+
Given /^that my gem source is all in place$/ do
Given "a safe project directory"
Given "a gem named 'gem_abc'"
Given "a extension cross-compilable 'extension_one'"
end
+Given /^that my JRuby gem source is all in place$/ do
+ Given "a safe project directory"
+ Given "a gem named 'gem_abc'"
+ Given "a extension Java-compilable 'extension_one'"
+end
+
Given /^that my gem source is all in place to target two platforms$/ do
Given "a safe project directory"
Given "a gem named 'gem_abc'"
9 features/step_definitions/cross_compilation.rb
View
@@ -6,14 +6,7 @@
end
Given %r{^I've installed cross compile toolchain$} do
- compilers = %w(i586-mingw32msvc-gcc i386-mingw32-gcc)
- paths = ENV['PATH'].split(File::PATH_SEPARATOR)
- compiler = compilers.find do |comp|
- paths.find do |path|
- File.exist? File.join(path, comp)
- end
- end
- pending "Cannot locate suitable compiler in the PATH." unless compiler
+ pending 'Cannot locate suitable compiler in the PATH.' unless search_path(%w(i586-mingw32msvc-gcc i386-mingw32-gcc))
end
Then /^binaries for platform '(.*)' get generated$/ do |platform|
33 features/step_definitions/execution.rb
View
@@ -1,15 +1,25 @@
-Given %r{^I've already successfully executed rake task '(.*)'$} do |task_name|
- emptyness = `rake #{task_name} 2>&1`
+# FIXME: Make the Transform work
+#
+# Transform /^| on JRuby$/ do |step_arg|
+# / on JRuby/.match(step_arg) != nil
+# end
+
+Given %r{^I've already successfully executed rake task '(.*)'(| on JRuby)$} do |task_name, on_jruby|
+ rake_cmd = "rake #{task_name}"
+ rake_cmd = 'jruby -S ' << rake_cmd if on_jruby == ' on JRuby'
+ emptyness = `#{rake_cmd} 2>&1`
unless $?.success?
warn emptyness
raise "rake failed with #{$?.exitstatus}"
end
end
-When /^rake task '(.*)' is invoked$/ do |task_name|
+When /^rake task '(.*)' is invoked(| on JRuby)$/ do |task_name, on_jruby|
@output ||= {}
@result ||= {}
- @output[task_name] = `rake #{task_name} 2>&1`
+ rake_cmd = "rake #{task_name}"
+ rake_cmd = 'jruby -S ' << rake_cmd if on_jruby == ' on JRuby'
+ @output[task_name] = `#{rake_cmd} 2>&1`
@result[task_name] = $?.success?
end
@@ -21,6 +31,14 @@
end
end
+Then /^rake task '(.*)' should fail$/ do |task_name|
+ if @result.nil? || !@result.include?(task_name) then
+ raise "The task #{task_name} should be invoked first."
+ else
+ @result[task_name].should be_false
+ end
+end
+
Then /^output of rake task '(.*)' (contains|do not contain) \/(.*)\/$/ do |task_name, condition, regex|
if condition == 'contains' then
@output[task_name].should match(%r(#{regex}))
@@ -28,3 +46,10 @@
@output[task_name].should_not match(%r(#{regex}))
end
end
+
+Then /^output of rake task '(.*)' warns$/ do |task_name, warning|
+ STDERR.puts task_name.inspect
+ STDERR.puts @output[task_name].inspect
+ STDERR.puts warning.inspect
+ @output[task_name].should include(warning)
+end
12 features/step_definitions/gem.rb
View
@@ -12,6 +12,12 @@
Then /^a gem for '(.*)' version '(.*)' platform '(.*)' do exist in '(.*)'$/ do |name, version, platform, folder|
File.exist?(gem_file_platform(folder, name, version, platform)).should be_true
+
+ # unpack the Gem and check what's inside!
+ `gem unpack #{gem_file_platform(folder, name, version, platform)} --target tmp`
+ unpacked_gem_dir = unpacked_gem_dir_platform('tmp', name, version, platform)
+ File.exist?(unpacked_gem_dir).should be_true
+ Dir.glob(unpacked_gem_dir << "/lib/*.#{binary_extension(platform)}").should_not be_empty
end
Then /^gem for platform '(.*)' get generated$/ do |platform|
@@ -28,3 +34,9 @@ def gem_file_platform(folder, name, version, platform = nil)
file << ".gem"
file
end
+
+def unpacked_gem_dir_platform(folder, name, version, platform = nil)
+ file = "#{folder}/#{name}-#{version}"
+ file << "-" << (platform || Gem::Platform.new(RUBY_PLATFORM).to_s)
+ file
+end
7 features/step_definitions/java_compilation.rb
View
@@ -0,0 +1,7 @@
+Given %r{^I've installed the Java Development Kit$} do
+ pending('Cannot locate suitable Java compiler (the Java Development Kit) in the PATH.') unless search_path(%w(javac javac.exe))
+end
+
+Given %r{^I've installed JRuby$} do
+ pending('Cannot locate a JRuby installation in the PATH.') unless search_path(%w(jruby jruby.exe jruby.bat))
+end
29 features/support/file_template_helpers.rb
View
@@ -75,6 +75,15 @@ def template_rake_extension_multi_cross_compile(extension_name)
EOF
end
+ def template_rake_extension_java_compile(extension_name, gem_spec = nil)
+ <<-EOF
+require 'rake/javaextensiontask'
+Rake::JavaExtensionTask.new("#{extension_name}"#{', SPEC' if gem_spec}) do |ext|
+ # nothing
+end
+EOF
+ end
+
def template_extconf(extension_name)
<<-EOF
require 'mkmf'
@@ -97,6 +106,26 @@ def template_source_h
#include "ruby.h"
EOF
end
+
+ def template_source_java(extension_name)
+ <<-EOF
+import org.jruby.Ruby;
+import org.jruby.runtime.load.BasicLibraryService;
+
+public class #{camelize(extension_name)}Service implements BasicLibraryService {
+ public boolean basicLoad(final Ruby runtime) throws java.io.IOException {
+ System.out.println("#{camelize(extension_name)}Service.java of extension #{extension_name}\\n");
+ return true;
+ }
+}
+
+EOF
+ end
+
+ def camelize(str)
+ str.gsub(/(^|_)(.)/) { $2.upcase }
+ end
+
end
World(FileTemplateHelpers)
29 features/support/generator_helpers.rb
View
@@ -4,7 +4,7 @@ def generate_scaffold_structure
FileUtils.mkdir_p "lib"
FileUtils.mkdir_p "tasks"
FileUtils.mkdir_p "tmp"
-
+
# create Rakefile loader
File.open("Rakefile", 'w') do |rakefile|
rakefile.puts template_rakefile.strip
@@ -60,6 +60,25 @@ def generate_cross_compile_extension_task_for(extension_name)
end
end
+ def generate_java_compile_extension_task_for(extension_name)
+ # create folder structure
+ FileUtils.mkdir_p "ext/#{extension_name}"
+
+ return if File.exist?("tasks/#{extension_name}.rake")
+
+ # create specific extension rakefile
+ # Building a gem?
+ if File.exist?("tasks/gem.rake") then
+ File.open("tasks/gem.rake", 'a+') do |ext_in_gem|
+ ext_in_gem.puts template_rake_extension_java_compile(extension_name, true)
+ end
+ else
+ File.open("tasks/#{extension_name}.rake", 'w') do |ext_rake|
+ ext_rake.puts template_rake_extension_java_compile(extension_name)
+ end
+ end
+ end
+
def generate_multi_cross_compile_extension_task_for(extension_name)
# create folder structure
FileUtils.mkdir_p "ext/#{extension_name}"
@@ -91,6 +110,14 @@ def generate_source_code_for(extension_name)
ext.puts template_extconf(extension_name)
end
end
+
+ def generate_java_source_code_for(extension_name)
+ # source .java file
+ File.open("ext/#{extension_name}/#{camelize(extension_name)}Service.java", 'w') do |c|
+ c.puts template_source_java(extension_name)
+ end
+ end
+
end
World(GeneratorHelpers)
13 features/support/platform_extension_helpers.rb
View
@@ -5,10 +5,23 @@ def binary_extension(platform = RUBY_PLATFORM)
'bundle'
when /mingw|mswin|linux/
'so'
+ when /java/
+ 'jar'
else
RbConfig::CONFIG['DLEXT']
end
end
+
+ def search_path(binaries)
+ paths = ENV['PATH'].split(File::PATH_SEPARATOR)
+ binary = binaries.find do |bin_file|
+ paths.find do |path|
+ bin = File.join(path, bin_file)
+ File.exist?(bin) && File.executable?(bin)
+ end
+ end
+ binary
+ end
end
World(PlatformExtensionHelpers)
Please sign in to comment.
Something went wrong with that request. Please try again.