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: 908ecddb4696
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0a2af70d2663
Choose a head ref
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Jun 5, 2015

  1. use new JRuby.create to load script from command line script source

    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.
    
    Conflicts:
    	core/src/main/java/org/jruby/RubyInstanceConfig.java
    	core/src/main/java/org/jruby/util/ClasspathResource.java
    	core/src/main/java/org/jruby/util/URLResource.java
    	core/src/test/java/org/jruby/util/URLResourceTest.java
    mkristian committed Jun 5, 2015
    Copy the full SHA
    d76a33b View commit details
  2. Copy the full SHA
    5b46184 View commit details
  3. Copy the full SHA
    0a2af70 View commit details
69 changes: 18 additions & 51 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -35,13 +35,13 @@
import org.jruby.runtime.backtrace.TraceType;
import org.jruby.runtime.load.LoadService;
import org.jruby.runtime.profile.builtin.ProfileOutput;
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.FileResource;
import org.jruby.util.cli.ArgumentProcessor;
import org.jruby.util.cli.Options;
import org.jruby.util.cli.OutputStrings;
@@ -389,44 +389,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 = getScriptSourceFromJar(script);
} else if (script.startsWith("uri:classloader:")) {
FileResource urlResource = URLResource.create(loader, script, true);
stream = urlResource.inputStream();
} 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());
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 InputStream getScriptSourceFromJar(String script) {
return Ruby.getClassLoader().getResourceAsStream(script.substring("classpath:".length()));
}

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();
@@ -445,27 +433,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) {
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/JRubyFile.java
Original file line number Diff line number Diff line change
@@ -110,7 +110,7 @@ private static FileResource createResource(Ruby runtime, String cwd, String path
}

// If any other special resource types fail, count it as a filesystem backed resource.
return new RegularFileResource(runtime.getPosix(), f);
return new RegularFileResource(runtime == null ? null : runtime.getPosix(), f);
}

public static String normalizeSeps(String path) {
7 changes: 0 additions & 7 deletions core/src/main/java/org/jruby/util/URLResource.java
Original file line number Diff line number Diff line change
@@ -179,13 +179,6 @@ public static FileResource createClassloaderURI(Ruby runtime, String pathname, b
return create(cl, pathname, isFile);
}

// public static FileResource createClassloaderURI(Ruby runtime, String pathname) {
// // retrieve the classloader from the runtime if available otherwise mimic how the runtime got its classloader and
// // take this
// ClassLoader cl = runtime != null ? runtime.getJRubyClassLoader() : URLResource.class.getClassLoader();
// return create(cl, pathname);
// }

public static FileResource create(Ruby runtime, String pathname, boolean isFile)
{
if (!pathname.startsWith(URI)) {
6 changes: 1 addition & 5 deletions core/src/test/java/org/jruby/util/URLResourceTest.java
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ public void testNoneDirectory(){
FileResource resource = URLResource.create((Ruby) null, "uri:" + uri, false);

assertNotNull(resource );
// you can open streams on file-system directories
assertTrue(resource.isFile());
assertTrue(resource.exists());
assertFalse(resource.isDirectory());
@@ -37,7 +36,6 @@ public void testFile(){
FileResource resource = URLResource.create((Ruby) null, "uri:" + uri, false);

assertNotNull(resource );
// you can open streams on file-system directories
assertTrue(resource.isFile());
assertTrue(resource.exists());
assertFalse(resource.isDirectory());
@@ -75,7 +73,6 @@ public void testNoneDirectoryClassloader()
"uri:classloader:/somedir/dir_without_listing", false);

assertNotNull( resource );
// you can open streams on file-system directories
assertTrue( resource.isFile() );
assertTrue( resource.exists() );
assertFalse( resource.isDirectory() );
@@ -88,7 +85,6 @@ public void testFileClassloader()
"uri:classloader:/somedir/.jrubydir", false );

assertNotNull( resource );
// you can open streams on file-system directories
assertTrue( resource.isFile() );
assertTrue( resource.exists() );
assertFalse( resource.isDirectory() );
@@ -106,4 +102,4 @@ public void testNonExistingFileClassloader()
assertFalse( resource.isDirectory() );
assertNull( resource.list() );
}
}
}
1 change: 0 additions & 1 deletion maven/jruby-complete/src/it/extended/Mavenfile
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@

properties( 'polyglot.dump.pom' => 'pom.xml',
'jruby.version' => '@project.version@',
'jruby.version' => '1.7.21-SNAPSHOT',
'jruby.plugins.version' => '1.0.8',
'jruby.home' => '${basedir}/../../../../..' )

2 changes: 1 addition & 1 deletion maven/jruby-complete/src/it/extended/pom.xml
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
<name>extended</name>
<properties>
<jruby.home>${basedir}/../../../../..</jruby.home>
<jruby.version>1.7.21-SNAPSHOT</jruby.version>
<jruby.version>@project.version@</jruby.version>
<jruby.plugins.version>1.0.8</jruby.plugins.version>
<polyglot.dump.pom>pom.xml</polyglot.dump.pom>
</properties>