Skip to content

Commit

Permalink
give priority for jruby-home to embedded one from classpath
Browse files Browse the repository at this point in the history
jruby home will be found in the following order:
* system property jruby.home
* if there is META-INF/jruby.home on the classloader
* JRUBY_HOME environment
* fallback to systemp temp directory

fixes #3257
mkristian committed Sep 14, 2015
1 parent f053889 commit f25d0a8
Showing 11 changed files with 86 additions and 2 deletions.
5 changes: 4 additions & 1 deletion core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -305,12 +305,15 @@ private String calculateJRubyHome() {
newJRubyHome = SafePropertyAccessor.getProperty("jruby.home");
}

if (newJRubyHome == null && getLoader().getResource("META-INF/jruby.home/.jrubydir") != null) {
newJRubyHome = "uri:classloader://META-INF/jruby.home";
}
if (newJRubyHome != null) {
// verify it if it's there
newJRubyHome = verifyHome(newJRubyHome, error);
} else {
try {
newJRubyHome = SystemPropertyCatcher.findJRubyHome(this);
newJRubyHome = SafePropertyAccessor.getenv("JRUBY_HOME");
} catch (Exception e) {}

if (newJRubyHome != null) {
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/embed/ScriptingContainer.java
Original file line number Diff line number Diff line change
@@ -67,6 +67,7 @@
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.profile.builtin.ProfileOutput;
import org.jruby.util.KCode;
import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.cli.OutputStrings;
import org.jruby.util.cli.Options;

@@ -264,7 +265,7 @@ static LocalContextProvider getProviderInstance(LocalContextScope scope, LocalVa
}

private void initRubyInstanceConfig() throws RaiseException {
String home = SystemPropertyCatcher.findJRubyHome(this);
String home = SafePropertyAccessor.getenv("JRUBY_HOME");
if (home != null) {
provider.getRubyInstanceConfig().setJRubyHome(home);
}
Original file line number Diff line number Diff line change
@@ -180,6 +180,7 @@ public static void setJRubyHome(ScriptingContainer container) {
* @param instance any instance to get a resource
* @return JRuby home path if exists, null when failed to find it.
*/
@Deprecated
public static String findJRubyHome(Object instance) {
String jrubyhome;
if ((jrubyhome = SafePropertyAccessor.getenv("JRUBY_HOME")) != null) {
@@ -191,6 +192,7 @@ public static String findJRubyHome(Object instance) {
return "uri:classloader://META-INF/jruby.home";
}

@Deprecated
public static String findFromJar(Object instance) {
URL resource = instance.getClass().getResource("/META-INF/jruby.home");
if (resource == null) {
@@ -229,6 +231,7 @@ public static String findFromJar(Object instance) {
*
* @return a list of load paths.
*/
@Deprecated
public static List<String> findLoadPaths() {
String paths = SafePropertyAccessor.getProperty(PropertyName.CLASSPATH.toString());
List<String> loadPaths = new ArrayList<String>();
16 changes: 16 additions & 0 deletions maven/jruby-complete/src/it/integrity/pom.xml
Original file line number Diff line number Diff line change
@@ -79,6 +79,22 @@
</arguments>
</configuration>
</execution>
<execution>
<id>check jruby-home</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>org.jruby.Main</argument>
<argument>-e</argument>
<argument>p JRuby.runtime.jruby_home</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>count installed gems</id>
<phase>test</phase>
3 changes: 3 additions & 0 deletions maven/jruby-complete/src/it/integrity/verify.bsh
Original file line number Diff line number Diff line change
@@ -58,3 +58,6 @@ if ( !file.exists() )
{
throw new RuntimeException( "file '" + file + "' does not exists" );
}

expected = "uri:classloader://META-INF/jruby.home";
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );
16 changes: 16 additions & 0 deletions maven/jruby-dist/src/it/integrity/pom.xml
Original file line number Diff line number Diff line change
@@ -99,6 +99,22 @@
</arguments>
</configuration>
</execution>
<execution>
<id>check jruby-home</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-classpath</argument>
<argument>-Xbootclasspath/a:${jruby.home}/lib/jruby.jar</argument>
<argument>org.jruby.Main</argument>
<argument>-e</argument>
<argument>p JRuby.runtime.jruby_home</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>count installed gems</id>
<phase>test</phase>
3 changes: 3 additions & 0 deletions maven/jruby-dist/src/it/integrity/verify.bsh
Original file line number Diff line number Diff line change
@@ -48,3 +48,6 @@ if ( !log.contains( expected ) )
{
throw new RuntimeException( "log file does not contain '" + expected + "'" );
}

String unexpected = "uri:classloader://META-INF/jruby.home";
if ( log.contains( unexpected ) ) throw new RuntimeException( "log file does contain unexpected '" + unexpected + "'" );
16 changes: 16 additions & 0 deletions maven/jruby-jars/src/it/integrity/pom.xml
Original file line number Diff line number Diff line change
@@ -91,6 +91,22 @@
</arguments>
</configuration>
</execution>
<execution>
<id>check jruby-home</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-classpath</argument>
<argument>${gem.home}/gems/jruby-jars-${ruby.version}/lib/jruby-core-@project.version@-complete.jar${path.separator}${gem.home}/gems/jruby-jars-${ruby.version}/lib/jruby-stdlib-@project.version@.jar</argument>
<argument>org.jruby.Main</argument>
<argument>-e</argument>
<argument>p JRuby.runtime.jruby_home</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>count installed gems</id>
<phase>test</phase>
3 changes: 3 additions & 0 deletions maven/jruby-jars/src/it/integrity/verify.bsh
Original file line number Diff line number Diff line change
@@ -48,3 +48,6 @@ if ( !log.contains( expected ) )
{
throw new RuntimeException( "log file does not contain '" + expected + "'" );
}

expected = "uri:classloader://META-INF/jruby.home";
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );
17 changes: 17 additions & 0 deletions maven/jruby/src/it/integrity/pom.xml
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
<configuration>
<executable>java</executable>
<environmentVariables>
<JRUBY_HOME>${basedir}</JRUBY_HOME>
<PATH>${basedir}</PATH>
<HOME>${basedir}</HOME>
<GEM_PATH>${basedir}</GEM_PATH>
@@ -80,6 +81,22 @@
</arguments>
</configuration>
</execution>
<execution>
<id>check jruby-home</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>org.jruby.Main</argument>
<argument>-e</argument>
<argument>p JRuby.runtime.jruby_home</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>count installed gems</id>
<phase>test</phase>
3 changes: 3 additions & 0 deletions maven/jruby/src/it/integrity/verify.bsh
Original file line number Diff line number Diff line change
@@ -66,3 +66,6 @@ if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not

expected = "maven/jruby/target/it/integrity/target/classes/hello.rb";
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );

expected = "uri:classloader://META-INF/jruby.home";
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );

0 comments on commit f25d0a8

Please sign in to comment.