Skip to content

Commit

Permalink
added nested IsolatedScriptingContainer via jruby-mains test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mkristian committed Jul 24, 2015
1 parent 6ceb537 commit e6632c0
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 12 deletions.
11 changes: 7 additions & 4 deletions maven/jruby/src/it/runnable/Mavenfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
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

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
Expand All @@ -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] )
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions maven/jruby/src/it/runnable/nested.rb
Original file line number Diff line number Diff line change
@@ -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
27 changes: 21 additions & 6 deletions maven/jruby/src/it/runnable/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<properties>
<tesla.dump.readOnly>true</tesla.dump.readOnly>
<jruby.version>@project.version@</jruby.version>
<jruby.plugins.version>1.0.8</jruby.plugins.version>
<jruby.plugins.version>1.0.10</jruby.plugins.version>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
<tesla.dump.pom>pom.xml</tesla.dump.pom>
</properties>
Expand All @@ -29,7 +29,7 @@
<dependency>
<groupId>de.saumya.mojo</groupId>
<artifactId>jruby-mains</artifactId>
<version>0.2.0</version>
<version>0.3.1</version>
</dependency>
</dependencies>
<repositories>
Expand Down Expand Up @@ -92,6 +92,7 @@
<includeBinStubs>true</includeBinStubs>
<includeRubyResources>
<includeRubyResource>.rspec</includeRubyResource>
<includeRubyResource>*.rb</includeRubyResource>
<includeRubyResource>config.ru</includeRubyResource>
<includeRubyResource>*file</includeRubyResource>
<includeRubyResource>*file.lock</includeRubyResource>
Expand Down Expand Up @@ -127,31 +128,31 @@
<type>jar</type>
<version>1.49</version>
<classifier />
<outputDirectory>${project.build.outputDirectory}/org/bouncycastle/bcpkix-jdk15on/1.49</outputDirectory>
<outputDirectory>${project.build.outputDirectory}/jars/org/bouncycastle/bcpkix-jdk15on/1.49</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<type>jar</type>
<version>1.6.4</version>
<classifier />
<outputDirectory>${project.build.outputDirectory}/org/slf4j/slf4j-simple/1.6.4</outputDirectory>
<outputDirectory>${project.build.outputDirectory}/jars/org/slf4j/slf4j-simple/1.6.4</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<type>jar</type>
<version>1.49</version>
<classifier />
<outputDirectory>${project.build.outputDirectory}/org/bouncycastle/bcprov-jdk15on/1.49</outputDirectory>
<outputDirectory>${project.build.outputDirectory}/jars/org/bouncycastle/bcprov-jdk15on/1.49</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<type>jar</type>
<version>1.6.4</version>
<classifier />
<outputDirectory>${project.build.outputDirectory}/org/slf4j/slf4j-api/1.6.4</outputDirectory>
<outputDirectory>${project.build.outputDirectory}/jars/org/slf4j/slf4j-api/1.6.4</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
Expand Down Expand Up @@ -233,6 +234,20 @@
</arguments>
</configuration>
</execution>
<execution>
<id>nested IsolatedScriptingContainer</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-jar</argument>
<argument>runnable.jar</argument>
<argument>nested.rb</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<executable>java</executable>
Expand Down
2 changes: 1 addition & 1 deletion maven/jruby/src/it/runnable/spec/one_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions maven/jruby/src/it/runnable/test.rb
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions maven/jruby/src/it/runnable/test_other.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 13 additions & 1 deletion maven/jruby/src/it/runnable/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "'" );
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 + "'" );
}

0 comments on commit e6632c0

Please sign in to comment.