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: 074543369e79
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a50803b8bf88
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Jun 16, 2015

  1. refactored runBinScript to use JRubyFile.createResource

    this treats the jruby-complete the same way as a filesystem
    installation of jruby. the implementation uses the new LoadService.
    
    Sponsored by Lookout Inc.
    mkristian committed Jun 16, 2015
    Copy the full SHA
    fcec818 View commit details
  2. make the JRubyFile api more descriptive

    without the POSIX instance from the runtime the created RegularFileResource
    can not perform any poix related operations. adds integration test with
    jruby-complete
    
    Sponsored by Lookout Inc.
    mkristian committed Jun 16, 2015
    Copy the full SHA
    a50803b View commit details
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -414,7 +414,7 @@ public InputStream getScriptSource() {
return getInput();
} else {
final String script = getScriptFileName();
FileResource resource =JRubyFile.createResource(null, getCurrentDirectory(), getScriptFileName());
FileResource resource = JRubyFile.createRestrictedResource(getCurrentDirectory(), getScriptFileName());
if (resource != null && resource.exists()) {
if (resource.isFile() || resource.isSymLink()) {
if (isXFlag()) {
13 changes: 7 additions & 6 deletions core/src/main/java/org/jruby/util/JRubyFile.java
Original file line number Diff line number Diff line change
@@ -63,6 +63,10 @@ public static FileResource createResource(ThreadContext context, String pathname
return createResource(context.runtime, pathname);
}

public static FileResource createRestrictedResource(String cwd, String pathname) {
return createResource(null, null, cwd, pathname);
}

public static FileResource createResource(Ruby runtime, String pathname) {
return createResource(runtime.getPosix(), runtime, runtime.getCurrentDirectory(), pathname);
}
@@ -93,12 +97,12 @@ 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 (cwd != null && (cwd.startsWith("uri:") || cwd.startsWith("file:"))) {
return createResource(posix, runtime, null, cwd + "/" + pathname);
}

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

@@ -117,9 +121,6 @@ private static JRubyFile createNoUnicodeConversion(String cwd, String pathname)
if(pathname.startsWith("file:")) {
pathname = pathname.substring(5);
}
if(pathname.startsWith("uri:")) {
return new JRubyFile(pathname);
}
File internal = new JavaSecuredFile(pathname);
if(cwd != null && cwd.startsWith("uri:") && !pathname.startsWith("uri:") && !pathname.contains("!/") && !internal.isAbsolute()) {
return new JRubyFile(cwd + "/" + pathname);
72 changes: 31 additions & 41 deletions core/src/main/java/org/jruby/util/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@
import org.jruby.exceptions.MainExitException;
import org.jruby.runtime.profile.builtin.ProfileOutput;
import org.jruby.util.JRubyFile;
import org.jruby.util.FileResource;
import org.jruby.util.KCode;
import org.jruby.util.SafePropertyAccessor;

@@ -531,59 +532,48 @@ private void runBinScript() {
endOfArguments = true;
}

private String resolveScript(String scriptName) {
// These try/catches are to allow failing over to the "commands" logic
// when running from within a jruby-complete jar file, which has
// jruby.home = a jar file URL that does not resolve correctly with
// JRubyFile.create.
File fullName = null;
try {
// try cwd first
fullName = JRubyFile.create(config.getCurrentDirectory(), scriptName);
if (fullName.exists() && fullName.isFile()) {
if (RubyInstanceConfig.DEBUG_SCRIPT_RESOLUTION) {
config.getError().println("Found: " + fullName.getAbsolutePath());
}
return scriptName;
}
} catch (Exception e) {
// keep going, try bin/#{scriptName}
private String resolve(String path, String scriptName) {
if (RubyInstanceConfig.DEBUG_SCRIPT_RESOLUTION) {
config.getError().println("Trying path: " + path);
}
try {
fullName = JRubyFile.create(config.getJRubyHome(), "bin/" + scriptName);
FileResource fullName = JRubyFile.createRestrictedResource(path, scriptName);
if (fullName.exists() && fullName.isFile()) {
if (RubyInstanceConfig.DEBUG_SCRIPT_RESOLUTION) {
config.getError().println("Found: " + fullName.getAbsolutePath());
config.getError().println("Found: " + fullName.absolutePath());
}
return fullName.getAbsolutePath();
return fullName.absolutePath();
}
} catch (Exception e) {
// keep going, try PATH
}
if(Ruby.getClassLoader().getResourceAsStream("bin/" + scriptName) != null){
return "classpath:bin/" + scriptName;
// keep going
}
try {
Object pathObj = config.getEnvironment().get("PATH");
String path = pathObj.toString();
if (path != null) {
String[] paths = path.split(System.getProperty("path.separator"));
for (int i = 0; i < paths.length; i++) {
fullName = JRubyFile.create(new File(paths[i]).getAbsolutePath(), scriptName);
if (fullName.exists() && fullName.isFile()) {
if (RubyInstanceConfig.DEBUG_SCRIPT_RESOLUTION) {
config.getError().println("Found: " + fullName.getAbsolutePath());
}
return fullName.getAbsolutePath();
}
}
return null;
}

private String resolveScript(String scriptName) {
// These try/catches are to allow failing over to the "commands" logic
// when running from within a jruby-complete jar file, which has
// jruby.home = a jar file URL that does not resolve correctly with
// JRubyFile.create.
String result = resolve(config.getCurrentDirectory(), scriptName);
if (result != null) return result;
result = resolve(config.getJRubyHome() + "/bin", scriptName);
if (result != null) return result;
result = resolve("uri:classloader:/bin", scriptName);
if (result != null) return result;

String path = config.getEnvironment().get("PATH").toString();
if (path != null) {
String[] paths = path.split(System.getProperty("path.separator"));
for (int i = 0; i < paths.length; i++) {
result = resolve(paths[i], scriptName);
if (result != null) return result;
}
} catch (Exception e) {
// will fall back to JRuby::Commands
}
if (config.isDebug()) {
config.getError().println("warning: could not resolve -S script on filesystem: " + scriptName);
config.getError().println("warning: could not resolve -S script: " + scriptName);
}
// fall back to JRuby::Commands
return null;
}

9 changes: 7 additions & 2 deletions maven/jruby-complete/src/it/extended/Mavenfile
Original file line number Diff line number Diff line change
@@ -18,17 +18,22 @@ phase :package do
plugin( 'org.codehaus.mojo:exec-maven-plugin:1.2',
:executable => 'java',
:environmentVariables => {
'PATH' => '${project.basedir}/bin${path.separator}${env.PATH}',
'GEM_PATH' => '${jruby.home}/lib/ruby/gems/shared',
'GEM_HOME' => '${jruby.home}/lib/ruby/gems/shared'
},
:basedir => '${jruby.home}' ) do


# see if gem gets found inside the jar though it is on $PATH
execute_goal( :exec, :id => 'gem help',
:arguments => [ '-Djruby.debug.scriptResolution=true', '-jar', '${project.build.directory}/dependency/jruby-complete-${jruby.version}.jar', '-S', 'gem', 'help' ] )

execute_goal( :exec, :id => 'rake -T',
:arguments => [ '-jar', '${project.build.directory}/dependency/jruby-complete-${jruby.version}.jar', '-S', 'rake', '-T' ] )

execute_goal( :exec, :id => 'rake test:mri',
:arguments => [ '-jar', '${project.build.directory}/dependency/jruby-complete-${jruby.version}.jar', '-S', 'rake', 'test:mri' ] )

end
end

18 changes: 18 additions & 0 deletions maven/jruby-complete/src/it/extended/pom.xml
Original file line number Diff line number Diff line change
@@ -39,6 +39,23 @@
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>gem help</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-Djruby.debug.scriptResolution=true</argument>
<argument>-jar</argument>
<argument>${project.build.directory}/dependency/jruby-complete-${jruby.version}.jar</argument>
<argument>-S</argument>
<argument>gem</argument>
<argument>help</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>rake -T</id>
<phase>package</phase>
@@ -75,6 +92,7 @@
<configuration>
<executable>java</executable>
<environmentVariables>
<PATH>${project.basedir}/bin${path.separator}${env.PATH}</PATH>
<GEM_PATH>${jruby.home}/lib/ruby/gems/shared</GEM_PATH>
<GEM_HOME>${jruby.home}/lib/ruby/gems/shared</GEM_HOME>
</environmentVariables>