-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
delegate script source argument to the new load service FileResource factory and allow all uri like paths which the regular JRuby code uses as well. fixes #2948 Sponsored by Lookout Inc.
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
- 9.1.17.0
- 9.1.16.0
- 9.1.15.0
- 9.1.14.0
- 9.1.13.0
- 9.1.12.0
- 9.1.11.0
- 9.1.10.0
- 9.1.9.0
- 9.1.8.0
- 9.1.7.0
- 9.1.6.0
- 9.1.5.0
- 9.1.4.0
- 9.1.3.0
- 9.1.2.0
- 9.1.1.0
- 9.1.0.0
- 9.0.5.0
- 9.0.4.0
- 9.0.3.0
- 9.0.1.0
- 9.0.0.0
- 9.0.0.0.rc2
- 1.7.27
- 1.7.26
- 1.7.25
- 1.7.24
- 1.7.23
- 1.7.22
- 1.7.21
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,22 +29,25 @@ | |
package org.jruby; | ||
|
||
import jnr.posix.util.Platform; | ||
|
||
import org.jruby.ast.executable.Script; | ||
import org.jruby.compiler.ASTCompiler; | ||
import org.jruby.compiler.ASTCompiler19; | ||
import org.jruby.exceptions.MainExitException; | ||
import org.jruby.embed.util.SystemPropertyCatcher; | ||
import org.jruby.exceptions.MainExitException; | ||
import org.jruby.runtime.Constants; | ||
import org.jruby.runtime.backtrace.TraceType; | ||
import org.jruby.runtime.load.LoadService; | ||
import org.jruby.runtime.load.LoadService19; | ||
import org.jruby.runtime.profile.builtin.ProfileOutput; | ||
import org.jruby.util.ClassCache; | ||
import org.jruby.util.FileResource; | ||
import org.jruby.util.InputStreamMarkCursor; | ||
import org.jruby.util.JRubyFile; | ||
import org.jruby.util.KCode; | ||
import org.jruby.util.NormalizedFile; | ||
import org.jruby.util.SafePropertyAccessor; | ||
import org.jruby.util.URLResource; | ||
import org.jruby.util.cli.ArgumentProcessor; | ||
import org.jruby.util.cli.Options; | ||
import org.jruby.util.cli.OutputStrings; | ||
|
@@ -55,6 +58,7 @@ | |
import java.io.ByteArrayInputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
@@ -408,37 +412,32 @@ public InputStream getScriptSource() { | |
return getInput(); | ||
} else { | ||
final String script = getScriptFileName(); | ||
final InputStream stream; | ||
if (script.startsWith("file:") && script.indexOf(".jar!/") != -1) { | ||
stream = new URL("jar:" + script).openStream(); | ||
} else if (script.startsWith("classpath:")) { | ||
stream = Ruby.getClassLoader().getResourceAsStream(script.substring("classpath:".length())); | ||
} else { | ||
File file = JRubyFile.create(getCurrentDirectory(), getScriptFileName()); | ||
if (isXFlag()) { | ||
// search for a shebang line and | ||
// return the script between shebang and __END__ or CTRL-Z (0x1A) | ||
return findScript(file); | ||
FileResource resource =JRubyFile.createResource(null, getCurrentDirectory(), getScriptFileName()); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mkristian
Author
Member
|
||
if (resource != null && resource.exists()) { | ||
if (resource.isFile() || resource.isSymLink()) { | ||
if (isXFlag()) { | ||
// search for a shebang line and | ||
// return the script between shebang and __END__ or CTRL-Z (0x1A) | ||
return findScript(resource.inputStream()); | ||
} | ||
return new BufferedInputStream(resource.inputStream(), 8192); | ||
} | ||
else { | ||
throw new FileNotFoundException(script + " (Not a file)"); | ||
} | ||
stream = new FileInputStream(file); | ||
} | ||
|
||
return new BufferedInputStream(stream, 8192); | ||
else { | ||
throw new FileNotFoundException(script + " (No such file or directory)"); | ||
} | ||
} | ||
} catch (IOException e) { | ||
// We haven't found any file directly on the file system, | ||
// now check for files inside the JARs. | ||
InputStream is = getJarScriptSource(scriptFileName); | ||
if (is != null) { | ||
return new BufferedInputStream(is, 8129); | ||
} | ||
throw new MainExitException(1, "Error opening script file: " + e.getMessage()); | ||
} | ||
} | ||
|
||
private static InputStream findScript(File file) throws IOException { | ||
private static InputStream findScript(InputStream is) throws IOException { | ||
StringBuilder buf = new StringBuilder(); | ||
BufferedReader br = new BufferedReader(new FileReader(file)); | ||
BufferedReader br = new BufferedReader(new InputStreamReader(is)); | ||
String currentLine = br.readLine(); | ||
while (currentLine != null && !isRubyShebangLine(currentLine)) { | ||
currentLine = br.readLine(); | ||
|
@@ -457,27 +456,6 @@ private static InputStream findScript(File file) throws IOException { | |
return new BufferedInputStream(new ByteArrayInputStream(buf.toString().getBytes()), 8192); | ||
} | ||
|
||
private static InputStream getJarScriptSource(String scriptFileName) { | ||
boolean looksLikeJarURL = scriptFileName.startsWith("file:") && scriptFileName.indexOf("!/") != -1; | ||
if (!looksLikeJarURL) { | ||
return null; | ||
} | ||
|
||
String before = scriptFileName.substring("file:".length(), scriptFileName.indexOf("!/")); | ||
String after = scriptFileName.substring(scriptFileName.indexOf("!/") + 2); | ||
|
||
try { | ||
JarFile jFile = new JarFile(before); | ||
JarEntry entry = jFile.getJarEntry(after); | ||
|
||
if (entry != null && !entry.isDirectory()) { | ||
return jFile.getInputStream(entry); | ||
} | ||
} catch (IOException ignored) { | ||
} | ||
return null; | ||
} | ||
|
||
public String displayedFileName() { | ||
if (hasInlineScript) { | ||
if (scriptFileName != null) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
puts "hello #{__FILE__}" |
unable to merge this part (to master) ... just so much divergence between these APIs at least if they were "somehow" compatible with each other but they're quite different ... under master
createResource
assumes a non null runtime :