Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bee9d0286a0a
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 51aea619cd04
Choose a head ref
  • 4 commits
  • 18 files changed
  • 1 contributor

Commits on Dec 27, 2014

  1. Copy the full SHA
    462b83f View commit details
  2. Copy the full SHA
    3d56328 View commit details
  3. Copy the full SHA
    ef39dd5 View commit details
  4. adds test which assembles a runnable.jar and uses CWD inside the jar

    this example uses Gemfile for the gem dependencies, Jarfile for jar dependencies,
    a Rakefile setting up bundler, a rspec test verifying that all gems, jars and the
    CWD are all inside the jar
    mkristian committed Dec 27, 2014
    Copy the full SHA
    51aea61 View commit details
25 changes: 16 additions & 9 deletions core/src/main/java/org/jruby/RubyDir.java
Original file line number Diff line number Diff line change
@@ -188,6 +188,9 @@ private static IRubyObject asRubyStringList(Ruby runtime, List<ByteList> dirs) {
}

private static String getCWD(Ruby runtime) {
if (runtime.getCurrentDirectory().startsWith("uri:")) {
return runtime.getCurrentDirectory();
}
try {
return new org.jruby.util.NormalizedFile(runtime.getCurrentDirectory()).getCanonicalPath();
} catch (Exception e) {
@@ -310,17 +313,22 @@ public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyOb
RubyFile.get_path(context, args[0]) : getHomeDirectoryPath(context);
String adjustedPath = RubyFile.adjustRootPathOnWindows(runtime, path.asJavaString(), null);
checkDirIsTwoSlashesOnWindows(runtime, adjustedPath);
JRubyFile dir = getDir(runtime, adjustedPath, true);
String realPath = null;
String oldCwd = runtime.getCurrentDirectory();
if (adjustedPath.startsWith("uri:")){
realPath = adjustedPath;
}
else {
JRubyFile dir = getDir(runtime, adjustedPath, true);

// We get canonical path to try and flatten the path out.
// a dir '/subdir/..' should return as '/'
// cnutter: Do we want to flatten path out?
try {
realPath = dir.getCanonicalPath();
} catch (IOException e) {
realPath = dir.getAbsolutePath();
// We get canonical path to try and flatten the path out.
// a dir '/subdir/..' should return as '/'
// cnutter: Do we want to flatten path out?
try {
realPath = dir.getCanonicalPath();
} catch (IOException e) {
realPath = dir.getAbsolutePath();
}
}

IRubyObject result = null;
@@ -330,7 +338,6 @@ public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyOb
try {
result = block.yield(context, path);
} finally {
dir = getDir(runtime, oldCwd, true);
runtime.setCurrentDirectory(oldCwd);
}
} else {
11 changes: 8 additions & 3 deletions core/src/main/java/org/jruby/util/JRubyFile.java
Original file line number Diff line number Diff line change
@@ -93,8 +93,13 @@ public static FileResource createResource(POSIX posix, Ruby runtime, String cwd,
}
}

JRubyFile f = create(cwd, pathname);
if (cwd != null && cwd.startsWith("uri:")){
return createResource(posix, runtime, null, f.getPath());
}

// If any other special resource types fail, count it as a filesystem backed resource.
return new RegularFileResource(posix, create(cwd, pathname));
return new RegularFileResource(posix, f);
}

public static String normalizeSeps(String path) {
@@ -109,10 +114,10 @@ private static JRubyFile createNoUnicodeConversion(String cwd, String pathname)
if (pathname == null || pathname.equals("") || Ruby.isSecurityRestricted()) {
return JRubyNonExistentFile.NOT_EXIST;
}
if(cwd != null && cwd.startsWith("uri:") && !pathname.startsWith("uri:")) {
File internal = new JavaSecuredFile(pathname);
if(cwd != null && cwd.startsWith("uri:") && !pathname.startsWith("uri:") && !pathname.contains("!/") && !internal.isAbsolute()) {
return new JRubyFile(cwd + "/" + pathname);
}
File internal = new JavaSecuredFile(pathname);
if(!internal.isAbsolute()) {
internal = new JavaSecuredFile(cwd, pathname);
if(!internal.isAbsolute()) {
10 changes: 7 additions & 3 deletions core/src/main/java/org/jruby/util/URLResource.java
Original file line number Diff line number Diff line change
@@ -155,8 +155,11 @@ public static FileResource createClassloaderURI(Ruby runtime, String pathname) {
if (cl == null ) {
cl = Thread.currentThread().getContextClassLoader();
}
if (pathname.startsWith("/")) {
pathname = pathname.substring(1);
try
{
pathname = new NormalizedFile("/" + pathname).getCanonicalPath().substring(1);
} catch (IOException e) {
pathname = pathname.replaceAll("^[.]?/+", "");
}
URL url = cl.getResource(pathname);
String[] files = listClassLoaderFiles(cl, pathname);
@@ -256,7 +259,8 @@ private static String[] listClassLoaderFiles(ClassLoader classloader, String pat
}
try
{
Enumeration<URL> urls = classloader.getResources(pathname + "/.jrubydir");
pathname = pathname + (pathname.equals("") ? ".jrubydir" : "/.jrubydir");
Enumeration<URL> urls = classloader.getResources(pathname);
if (!urls.hasMoreElements()) {
return null;
}
2 changes: 1 addition & 1 deletion lib/ruby/shared/rubygems/defaults/jruby.rb
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ def self.win_platform?
# Allow specifying jar and classpath type gem path entries
def self.path_separator
return File::PATH_SEPARATOR unless File::PATH_SEPARATOR == ':'
/(?<!jar:file|jar|file|classpath):/
/(?<!jar:file|jar|file|classpath|uri:classloader|uri):/
end
end

1 change: 1 addition & 0 deletions maven/jruby/src/it/runnable/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*jar
12 changes: 12 additions & 0 deletions maven/jruby/src/it/runnable/.jbundler/classpath.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'jar_dependencies'
JBUNDLER_LOCAL_REPO = Jars.home
JBUNDLER_JRUBY_CLASSPATH = []
JBUNDLER_JRUBY_CLASSPATH.freeze
JBUNDLER_TEST_CLASSPATH = []
JBUNDLER_TEST_CLASSPATH.freeze
JBUNDLER_CLASSPATH = []
JBUNDLER_CLASSPATH << (JBUNDLER_LOCAL_REPO + '/org/bouncycastle/bcpkix-jdk15on/1.49/bcpkix-jdk15on-1.49.jar')
JBUNDLER_CLASSPATH << (JBUNDLER_LOCAL_REPO + '/org/slf4j/slf4j-simple/1.6.4/slf4j-simple-1.6.4.jar')
JBUNDLER_CLASSPATH << (JBUNDLER_LOCAL_REPO + '/org/bouncycastle/bcprov-jdk15on/1.49/bcprov-jdk15on-1.49.jar')
JBUNDLER_CLASSPATH << (JBUNDLER_LOCAL_REPO + '/org/slf4j/slf4j-api/1.6.4/slf4j-api-1.6.4.jar')
JBUNDLER_CLASSPATH.freeze
7 changes: 7 additions & 0 deletions maven/jruby/src/it/runnable/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source 'https://rubygems.org'

gem 'rspec', '~> 2.14'

gem 'rake', '~> 10.3'

gem 'jbundler', '0.7.1'
50 changes: 50 additions & 0 deletions maven/jruby/src/it/runnable/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
GEM
remote: https://rubygems.org/
specs:
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.2.5)
equalizer (0.0.9)
ice_nine (0.11.0)
jar-dependencies (0.1.7)
jbundler (0.7.1)
bundler (~> 1.5)
jar-dependencies (~> 0.1.7)
maven-tools (~> 1.0.6)
ruby-maven (>= 3.1.1.0.6, < 3.1.2)
maven-tools (1.0.7)
virtus (~> 1.0)
rake (10.3.2)
rspec (2.99.0)
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec-core (2.99.2)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.99.2)
ruby-maven (3.1.1.0.8)
maven-tools (~> 1.0.1)
ruby-maven-libs (= 3.1.1)
ruby-maven-libs (3.1.1)
thread_safe (0.3.4-java)
virtus (1.0.3)
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)

PLATFORMS
java
ruby

DEPENDENCIES
jbundler (= 0.7.1)
rake (~> 10.3)
rspec (~> 2.14)
1 change: 1 addition & 0 deletions maven/jruby/src/it/runnable/Jarfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jar 'org.slf4j:slf4j-simple', '1.6.4'
6 changes: 6 additions & 0 deletions maven/jruby/src/it/runnable/Jarfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
:runtime:
- org.bouncycastle:bcpkix-jdk15on:jar:1.49
- org.slf4j:slf4j-simple:jar:1.6.4
- org.bouncycastle:bcprov-jdk15on:jar:1.49
- org.slf4j:slf4j-api:jar:1.6.4
95 changes: 95 additions & 0 deletions maven/jruby/src/it/runnable/Mavenfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#-*- mode: ruby -*-

properties( 'tesla.dump.pom' => 'pom.xml',
'tesla.dump.readOnly' => true,
'jruby.version' => '@project.version@' )
gemfile

gem 'bundler', '1.7.7'

pom 'org.jruby:jruby', '${jruby.version}'

files = [ 'config.ru', '*file', '*file.lock', '.jbundler/classpath.rb',
'lib/**', 'app/**', 'config/**', 'vendor/**', 'spec/**' ]

resource :directory => '${basedir}' do
includes( files )
end

execute 'create jrubydir info', :phase => 'process-resources' do |ctx|
target = ctx.project.build.output_directory.to_pathname
entries = files.collect { |f| Dir[ f.sub( /\/.*$/, '') ] }.flatten.uniq
File.write( File.join( target, '.jrubydir' ),
(['.'] + entries + [ '' ]).join( "\n" ) )
require (ctx.basedir.to_pathname + '/../../../../../core/src/main/ruby/jruby/commands.rb')
files.select do |f|
f =~ /\//
end.collect do |f|
f.sub( /\/.*$/, '')
end.each do |f|
JRuby::Commands.generate_dir_info( File.join( target, f ), false )
end
end

resource :directory => '${project.build.directory}/rubygems/bin' do
includes '*'
target_path 'META-INF/jruby.home/bin'
end

build do
directory 'pkg'
end

jruby_plugin!( :gem, :includeRubygemsInResources => true )

if File.file?('Jarfile.lock')
phase :package do
plugin :dependency do
items = []
File.read( 'Jarfile.lock' ).each_line do |l|
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[:groupId].gsub(/[.]/, '/'),
data[:artifactId],
data[:version] )
items << data
end
end
execute_goal( :copy,
:id => 'copy jar dependencies',
:artifactItems => items )
end
end
end

plugin :shade do
execute_goals( 'shade',
:id => 'pack',
:artifactSet => { :excludes => ['rubygems:*'] },
:transformers => [ { :@implementation => 'org.apache.maven.plugins.shade.resource.ManifestResourceTransformer',
:mainClass => 'Main' } ] )
end

# test bits

phase :package do
plugin( 'org.codehaus.mojo:exec-maven-plugin:1.2',
:executable => 'java',
:environmentVariables => {
'PATH' => '${basedir}',
'HOME' => '${basedir}',
'GEM_PATH' => '${basedir}',
'GEM_HOME' => '${basedir}'
} ) do

execute_goal( :exec, :id => 'rake -T',
:arguments => [ '-jar', 'runnable.jar', '-S', 'rake', '-T' ] )

execute_goal( :exec, :id => 'rspec',
:arguments => [ '-jar', 'runnable.jar', '-S', 'rspec' ] )

end
end

15 changes: 15 additions & 0 deletions maven/jruby/src/it/runnable/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "bundler/setup"
begin
Bundler.setup
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'jbundler'

require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
334 changes: 334 additions & 0 deletions maven/jruby/src/it/runnable/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,334 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>no_group_id_given</groupId>
<artifactId>runnable</artifactId>
<version>0.0.0</version>
<name>runnable</name>
<properties>
<tesla.dump.readOnly>true</tesla.dump.readOnly>
<jruby.version>@project.version@</jruby.version>
<jruby.plugins.version>1.0.7</jruby.plugins.version>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
<tesla.dump.pom>pom.xml</tesla.dump.pom>
<tesla.version>0.1.1</tesla.version>
</properties>
<dependencies>
<dependency>
<groupId>rubygems</groupId>
<artifactId>bundler</artifactId>
<version>1.7.7</version>
<type>gem</type>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby</artifactId>
<version>${jruby.version}</version>
<type>pom</type>
</dependency>
</dependencies>
<repositories>
<repository>
<id>rubygems-releases</id>
<url>http://rubygems-proxy.torquebox.org/releases</url>
</repository>
</repositories>
<build>
<resources>
<resource>
<directory>${basedir}</directory>
<includes>
<include>config.ru</include>
<include>*file</include>
<include>*file.lock</include>
<include>.jbundler/classpath.rb</include>
<include>lib/**</include>
<include>app/**</include>
<include>config/**</include>
<include>vendor/**</include>
<include>spec/**</include>
</includes>
</resource>
<resource>
<targetPath>META-INF/jruby.home/bin</targetPath>
<directory>${project.build.directory}/rubygems/bin</directory>
<includes>
<include>*</include>
</includes>
</resource>
</resources>
<directory>pkg</directory>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>.</outputDirectory>
<finalName>runnable</finalName>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4</version>
<configuration>
<filesets>
<fileset>
<directory>.</directory>
<includes>
<include>runnable.jar</include>
<include>*/**/*.jar</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>de.saumya.mojo</groupId>
<artifactId>gem-maven-plugin</artifactId>
<version>${jruby.plugins.version}</version>
<executions>
<execution>
<id>install gems</id>
<goals>
<goal>initialize</goal>
</goals>
</execution>
</executions>
<configuration>
<includeRubygemsInResources>true</includeRubygemsInResources>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy jar dependencies</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<type>jar</type>
<version>1.49</version>
<classifier />
<outputDirectory>${project.build.outputDirectory}/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>
</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>
</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>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>pack</id>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>rubygems:*</exclude>
</excludes>
</artifactSet>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>rake -T</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-jar</argument>
<argument>runnable.jar</argument>
<argument>-S</argument>
<argument>rake</argument>
<argument>-T</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>rspec</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-jar</argument>
<argument>runnable.jar</argument>
<argument>-S</argument>
<argument>rspec</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<executable>java</executable>
<environmentVariables>
<PATH>${basedir}</PATH>
<HOME>${basedir}</HOME>
<GEM_PATH>${basedir}</GEM_PATH>
<GEM_HOME>${basedir}</GEM_HOME>
</environmentVariables>
</configuration>
</plugin>
<plugin>
<groupId>io.tesla.polyglot</groupId>
<artifactId>tesla-polyglot-maven-plugin</artifactId>
<version>${tesla.version}</version>
<executions>
<execution>
<id>create jrubydir info</id>
<phase>process-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<taskId>create jrubydir info</taskId>
<nativePom>Mavenfile</nativePom>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>io.tesla.polyglot</groupId>
<artifactId>tesla-polyglot-ruby</artifactId>
<version>${tesla.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>gemfile</id>
<activation>
<file>
<missing>Gemfile.lock</missing>
</file>
</activation>
<dependencies>
<dependency>
<groupId>rubygems</groupId>
<artifactId>rspec</artifactId>
<version>[2.14,2.99999]</version>
<type>gem</type>
</dependency>
<dependency>
<groupId>rubygems</groupId>
<artifactId>rake</artifactId>
<version>[10.3,10.99999]</version>
<type>gem</type>
</dependency>
<dependency>
<groupId>rubygems</groupId>
<artifactId>jbundler</artifactId>
<version>0.7.1</version>
<type>gem</type>
</dependency>
</dependencies>
</profile>
<profile>
<id>gemfile_lock</id>
<activation>
<file>
<exists>Gemfile.lock</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>de.saumya.mojo</groupId>
<artifactId>gem-maven-plugin</artifactId>
<version>${jruby.plugins.version}</version>
<executions>
<execution>
<id>install gem sets for compile</id>
<phase>initialize</phase>
<goals>
<goal>sets</goal>
</goals>
<configuration>
<scope>compile</scope>
<gems>
<rspec>2.99.0</rspec>
<rspec-core>2.99.2</rspec-core>
<rspec-expectations>2.99.2</rspec-expectations>
<diff-lcs>1.2.5</diff-lcs>
<rspec-mocks>2.99.2</rspec-mocks>
<rake>10.3.2</rake>
<jbundler>0.7.1</jbundler>
<jar-dependencies>0.1.7</jar-dependencies>
<maven-tools>1.0.7</maven-tools>
<virtus>1.0.3</virtus>
<axiom-types>0.1.1</axiom-types>
<descendants_tracker>0.0.4</descendants_tracker>
<thread_safe>0.3.4</thread_safe>
<ice_nine>0.11.0</ice_nine>
<coercible>1.0.0</coercible>
<equalizer>0.0.9</equalizer>
<ruby-maven>3.1.1.0.8</ruby-maven>
<ruby-maven-libs>3.1.1</ruby-maven-libs>
</gems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
12 changes: 12 additions & 0 deletions maven/jruby/src/it/runnable/spec/one_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'jbundler'

describe "something" do
it "does something" do
$CLASSPATH.size.should == 4
Jars.home.should == 'uri:classloader://'
Dir.pwd.should == 'uri:classloader://'
$LOAD_PATH.each do |lp|
lp.should =~ /^uri:classloader:|runnable.jar!\//
end
end
end
40 changes: 40 additions & 0 deletions maven/jruby/src/it/runnable/src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
public class Main extends org.jruby.Main {

public static void main(String[] args) {
Main main = new Main();

try {
org.jruby.Main.Status status = main.run(args);
if (status.isExit()) {
System.exit(status.getStatus());
}
} catch (org.jruby.exceptions.RaiseException rj) {
System.exit(-1);//TODO handleRaiseException(rj));
} catch (Throwable t) {
// print out as a nice Ruby backtrace
System.err.println(org.jruby.runtime.ThreadContext.createRawBacktraceStringFromThrowable(t));
while ((t = t.getCause()) != null) {
System.err.println("Caused by:");
System.err.println(org.jruby.runtime.ThreadContext.createRawBacktraceStringFromThrowable(t));
}
System.exit(1);
}
}

public Main() {
this(new org.jruby.RubyInstanceConfig());
}

private Main(org.jruby.RubyInstanceConfig config) {
super(config);
config.setHardExit(true);
config.setCurrentDirectory( "uri:classloader://" );
config.setJRubyHome( "uri:classloader://META-INF/jruby.home" );
config.setLoadPaths( java.util.Arrays.asList("uri:classloader://") );
java.util.Map env = new java.util.HashMap( System.getenv() );
env.put( "JARS_HOME", "uri:classloader://" );
// needed for jruby version before 1.7.19
env.put( "BUNDLE_DISABLE_SHARED_GEMS", "true" );
config.setEnvironment( env );
}
}
10 changes: 10 additions & 0 deletions maven/jruby/src/it/runnable/verify.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import java.io.*;
import org.codehaus.plexus.util.FileUtils;


String log = FileUtils.fileRead( new File( basedir, "build.log" ) );
String expected = "Run RSpec code examples";
if ( !log.contains( expected ) )
{
throw new RuntimeException( "log file does not contain '" + expected + "'" );
}
Binary file added test/test_uri_classloader.jar
Binary file not shown.
72 changes: 72 additions & 0 deletions test/test_uri_classloader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-
require 'test/unit'
require 'test/test_helper'

class TestFile < Test::Unit::TestCase
include TestHelper

def setup
$CLASSPATH << File.expand_path( '../test_uri_classloader.jar', __FILE__ )
end

def ensure_cwd
pwd = Dir.pwd
begin
yield
ensure
Dir.chdir pwd
end
end

def test_dir_glob_on_uri_classloader_path
assert_equal ['uri:classloader://Rakefile'], Dir[ 'uri:classloader://*' ]

ensure_cwd do
Dir.chdir( 'uri:classloader://' )
assert_equal ['Rakefile'], Dir[ '*' ]
end

ensure_cwd do
JRuby.runtime.current_directory = 'uri:classloader://'
assert_equal ['Rakefile'], Dir[ '*' ]
end
end

def test_dir_glob_on_uri_classloader_path_with_dot
assert_equal ['uri:classloader://./Rakefile'], Dir[ 'uri:classloader://./*' ]

ensure_cwd do
Dir.chdir( 'uri:classloader://.' )
assert_equal ['Rakefile'], Dir[ '*' ]
end

ensure_cwd do
JRuby.runtime.current_directory = 'uri:classloader://.'
assert_equal ['Rakefile'], Dir[ '*' ]
end
end

def test_dir_glob_on_uri_classloader_path_with_dot_dot
assert_equal ['uri:classloader://lib/../Rakefile'], Dir[ 'uri:classloader://lib/../*' ]

ensure_cwd do
JRuby.runtime.current_directory = 'uri:classloader://lib/..'
assert_equal ['Rakefile'], Dir[ '*' ]
end

ensure_cwd do
Dir.chdir 'uri:classloader://lib/..'
assert_equal ['Rakefile'], Dir[ '*' ]
end

ensure_cwd do
JRuby.runtime.current_directory = 'uri:classloader://'
assert_equal ['lib/../Rakefile'], Dir[ 'lib/../*' ]
end

ensure_cwd do
Dir.chdir 'uri:classloader://'
assert_equal ['lib/../Rakefile'], Dir[ 'lib/../*' ]
end
end
end