From e6632c0a00fb7a43d9b8754573cb98102365cc12 Mon Sep 17 00:00:00 2001 From: Christian Meier Date: Fri, 24 Jul 2015 09:59:45 +0200 Subject: [PATCH] added nested IsolatedScriptingContainer via jruby-mains test execute code inside a jar via jruby-mains, create an IsolatedSCriptingContainer which should inherit the environment from the jruby-mains, i.e. GEM_PATH, GEM_HOME, JARS_HOME, current working directory should all point inside the jars Sponsored by Lookout Inc. --- maven/jruby/src/it/runnable/Mavenfile | 11 +++++--- maven/jruby/src/it/runnable/nested.rb | 14 ++++++++++ maven/jruby/src/it/runnable/pom.xml | 27 ++++++++++++++---- maven/jruby/src/it/runnable/spec/one_spec.rb | 2 +- maven/jruby/src/it/runnable/test.rb | 25 +++++++++++++++++ maven/jruby/src/it/runnable/test_other.rb | 29 ++++++++++++++++++++ maven/jruby/src/it/runnable/verify.bsh | 14 +++++++++- 7 files changed, 110 insertions(+), 12 deletions(-) create mode 100644 maven/jruby/src/it/runnable/nested.rb create mode 100644 maven/jruby/src/it/runnable/test.rb create mode 100644 maven/jruby/src/it/runnable/test_other.rb diff --git a/maven/jruby/src/it/runnable/Mavenfile b/maven/jruby/src/it/runnable/Mavenfile index dcd50f61321..6d23634287b 100644 --- a/maven/jruby/src/it/runnable/Mavenfile +++ b/maven/jruby/src/it/runnable/Mavenfile @@ -3,7 +3,7 @@ properties( 'tesla.dump.pom' => 'pom.xml', 'tesla.dump.readOnly' => true, 'jruby.version' => '@project.version@', - 'jruby.plugins.version' => '1.0.8' ) + 'jruby.plugins.version' => '1.0.10' ) gemfile @@ -11,13 +11,13 @@ gem 'bundler', '1.7.7' pom 'org.jruby:jruby', '${jruby.version}' -jar 'de.saumya.mojo:jruby-mains', '0.2.0' +jar 'de.saumya.mojo:jruby-mains', '0.3.1' build do directory 'pkg' end -files = [ '.rspec', 'config.ru', '*file', '*file.lock', '.jbundler/classpath.rb', +files = [ '.rspec', '*.rb', 'config.ru', '*file', '*file.lock', '.jbundler/classpath.rb', 'lib/**', 'app/**', 'config/**', 'vendor/**', 'spec/**' ] jruby_plugin!( :gem, # need a jruby-complete from maven central here @@ -40,7 +40,7 @@ if File.file?('Jarfile.lock') data = l.sub(/-\ /, '').strip.split(':') if data.size > 3 data = Hash[ [:groupId, :artifactId, :type, :version, :classifier].zip( data ) ] - data[ :outputDirectory ] = File.join( '${project.build.outputDirectory}', + data[ :outputDirectory ] = File.join( '${project.build.outputDirectory}/jars', data[:groupId].gsub(/[.]/, '/'), data[:artifactId], data[:version] ) @@ -81,6 +81,9 @@ phase :package do execute_goal( :exec, :id => 'rspec', :arguments => [ '-jar', 'runnable.jar', '-S', 'rspec' ] ) + + execute_goal( :exec, :id => 'nested IsolatedScriptingContainer', + :arguments => [ '-jar', 'runnable.jar', 'nested.rb' ] ) end end diff --git a/maven/jruby/src/it/runnable/nested.rb b/maven/jruby/src/it/runnable/nested.rb new file mode 100644 index 00000000000..18ca7a5f18e --- /dev/null +++ b/maven/jruby/src/it/runnable/nested.rb @@ -0,0 +1,14 @@ +# TODO needs fix in jruby +#require_relative 'test' +require 'uri:classloader:/test' + +# not use Singleton scope since in this case it would use the on global runtime +other = org.jruby.embed.IsolatedScriptingContainer.new(org.jruby.embed.LocalContextScope::THREADSAFE) + +other.runScriptlet("$other = #{JRuby.runtime.object_id}") + +# TODO needs fix in jruby +#other.runScriptlet( "require_relative 'test_other'" ) +other.runScriptlet( "require 'uri:classloader:/test_other'" ) + +other.terminate diff --git a/maven/jruby/src/it/runnable/pom.xml b/maven/jruby/src/it/runnable/pom.xml index 75f70dce359..8dbcc2f7d18 100644 --- a/maven/jruby/src/it/runnable/pom.xml +++ b/maven/jruby/src/it/runnable/pom.xml @@ -9,7 +9,7 @@ true @project.version@ - 1.0.8 + 1.0.10 utf-8 pom.xml @@ -29,7 +29,7 @@ de.saumya.mojo jruby-mains - 0.2.0 + 0.3.1 @@ -92,6 +92,7 @@ true .rspec + *.rb config.ru *file *file.lock @@ -127,7 +128,7 @@ jar 1.49 - ${project.build.outputDirectory}/org/bouncycastle/bcpkix-jdk15on/1.49 + ${project.build.outputDirectory}/jars/org/bouncycastle/bcpkix-jdk15on/1.49 org.slf4j @@ -135,7 +136,7 @@ jar 1.6.4 - ${project.build.outputDirectory}/org/slf4j/slf4j-simple/1.6.4 + ${project.build.outputDirectory}/jars/org/slf4j/slf4j-simple/1.6.4 org.bouncycastle @@ -143,7 +144,7 @@ jar 1.49 - ${project.build.outputDirectory}/org/bouncycastle/bcprov-jdk15on/1.49 + ${project.build.outputDirectory}/jars/org/bouncycastle/bcprov-jdk15on/1.49 org.slf4j @@ -151,7 +152,7 @@ jar 1.6.4 - ${project.build.outputDirectory}/org/slf4j/slf4j-api/1.6.4 + ${project.build.outputDirectory}/jars/org/slf4j/slf4j-api/1.6.4 @@ -233,6 +234,20 @@ + + nested IsolatedScriptingContainer + package + + exec + + + + -jar + runnable.jar + nested.rb + + + java diff --git a/maven/jruby/src/it/runnable/spec/one_spec.rb b/maven/jruby/src/it/runnable/spec/one_spec.rb index c13eb65b385..9e7ea564828 100644 --- a/maven/jruby/src/it/runnable/spec/one_spec.rb +++ b/maven/jruby/src/it/runnable/spec/one_spec.rb @@ -4,7 +4,7 @@ it "does something" do expect(__FILE__).to eq 'uri:classloader:/spec/one_spec.rb' expect($CLASSPATH.size).to eq 4 - expect(Jars.home).to eq 'uri:classloader://' + expect(Jars.home).to eq 'uri:classloader://jars' expect(Dir.pwd).to eq 'uri:classloader://' $LOAD_PATH.each do |lp| # bundler or someone else messes up the $LOAD_PATH diff --git a/maven/jruby/src/it/runnable/test.rb b/maven/jruby/src/it/runnable/test.rb new file mode 100644 index 00000000000..fd1dae143a1 --- /dev/null +++ b/maven/jruby/src/it/runnable/test.rb @@ -0,0 +1,25 @@ +require 'minitest/autorun' + +describe 'ENV' do + + it 'has current directory inside classloader' do + Dir.pwd.must_equal 'uri:classloader://' + end + + it 'has first entry LOAD_PATH' do + $LOAD_PATH.first.must_equal 'uri:classloader://' + end + + it 'has GEM_HOME set' do + ENV['GEM_HOME'].must_equal 'uri:classloader://META-INF/jruby.home/lib/ruby/gems/shared' + end + + it 'has GEM_PATH set' do + ENV['GEM_PATH'].must_equal 'uri:classloader://' + end + + it 'has JARS_HOME set' do + ENV['JARS_HOME'].must_equal 'uri:classloader://jars' + end + +end diff --git a/maven/jruby/src/it/runnable/test_other.rb b/maven/jruby/src/it/runnable/test_other.rb new file mode 100644 index 00000000000..e1af6c02988 --- /dev/null +++ b/maven/jruby/src/it/runnable/test_other.rb @@ -0,0 +1,29 @@ +require 'minitest/autorun' + +describe 'ENV' do + + it 'has $other' do + $other.wont_equal JRuby.runtime.object_id + end + + it 'has first entry LOAD_PATH' do + $LOAD_PATH.first.must_equal 'uri:classloader:/' + end + + it 'has current directory inside classloader' do + Dir.pwd.must_equal 'uri:classloader:/' + end + + it 'has GEM_HOME set' do + ENV['GEM_HOME'].must_equal 'uri:classloader:/' + end + + it 'has GEM_PATH set' do + ENV['GEM_PATH'].must_equal 'uri:classloader:/' + end + + it 'has JARS_HOME set' do + ENV['JARS_HOME'].must_equal 'uri:classloader:/jars' + end + +end diff --git a/maven/jruby/src/it/runnable/verify.bsh b/maven/jruby/src/it/runnable/verify.bsh index 988b42f9a2b..c217b1316e1 100644 --- a/maven/jruby/src/it/runnable/verify.bsh +++ b/maven/jruby/src/it/runnable/verify.bsh @@ -10,4 +10,16 @@ expected = "uri:classloader:/Rakefile []"; if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" ); expected = "uri:classloader:/Rakefile [\"spec\"]"; -if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" ); \ No newline at end of file +if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" ); + +expected = "5 tests, 5 assertions, 0 failures, 0 errors, 0 skips"; +if ( !log.contains( expected ) ) +{ + throw new RuntimeException( "log file does not contain '" + expected + "'" ); +} + +expected = "6 tests, 6 assertions, 0 failures, 0 errors, 0 skips"; +if ( !log.contains( expected ) ) +{ + throw new RuntimeException( "log file does not contain '" + expected + "'" ); +} \ No newline at end of file