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

Commits on Dec 10, 2016

  1. Copy the full SHA
    c6176a5 View commit details
  2. Copy the full SHA
    2a7c4dd View commit details
6 changes: 3 additions & 3 deletions truffle/src/main/java/org/jruby/truffle/Main.java
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ public static void main(String[] args) {
final int exitCode;

if (config.getShouldRunInterpreter()) {
final InputStream in = config.getScriptSource();
final boolean in = config.canGetScriptSource();
final String filename = config.displayedFileName();

final RubyEngine rubyEngine = new RubyEngine(
@@ -101,15 +101,15 @@ public static void main(String[] args) {

printTruffleTimeMetric("before-run");
try {
if (in == null) {
if (in == false) {
exitCode = 1;
} else if (config.isXFlag()) {
// no shebang was found and x option is set
config.getError().println("jruby: no Ruby script found in input (LoadError)");
exitCode = 1;
} else if (config.getShouldCheckSyntax()) {
// check syntax only and exit
exitCode = rubyEngine.doCheckSyntax(in, filename);
exitCode = rubyEngine.doCheckSyntax(config.getScriptSource(), filename);
} else {
exitCode = rubyEngine.execute(filename);
}
Original file line number Diff line number Diff line change
@@ -40,6 +40,8 @@ public SourceLoader(RubyContext context) {
public Source loadMain(String path) throws IOException {
if (path.equals("-e")) {
return loadFragment(new String(context.getOptions().INLINE_SCRIPT, StandardCharsets.UTF_8), "-e");
} else if (path.equals("-")) {
return Source.newBuilder(new InputStreamReader(System.in)).name(path).mimeType(RubyLanguage.MIME_TYPE).build();
} else {
final File file = new File(path).getCanonicalFile();
ensureReadable(path, file);
Original file line number Diff line number Diff line change
@@ -206,67 +206,33 @@ public byte[] inlineScript() {
return inlineScript.toString().getBytes();
}

public boolean canGetScriptSource() {
if (hasInlineScript) {
return true;
} else if (isForceStdin() || getScriptFileName() == null) {
return false;
} else {
return true;
}
}

public InputStream getScriptSource() {
try {
// KCode.NONE is used because KCODE does not affect parse in Ruby 1.8
// if Ruby 2.0 encoding pragmas are implemented, this will need to change
if (hasInlineScript) {
return new ByteArrayInputStream(inlineScript());
} else if (isForceStdin() || getScriptFileName() == null) {
// can't use -v and stdin
if (isShowVersion()) {
return null;
}
return getInput();
return null;
} else {
final String script = getScriptFileName();

return new FileInputStream(script);

/*FileResource resource = JRubyFile.createRestrictedResource(getCurrentDirectory(), getScriptFileName());
if (resource != null && resource.exists()) {
if (resource.canRead() && !resource.isDirectory()) {
if (isXFlag()) {
// search for a shebang line and
// return the script between shebang and __END__ or CTRL-Z (0x1A)
return findScript(resource.inputStream());
}
return resource.inputStream();
}
else {
throw new FileNotFoundException(script + " (Not a file)");
}
}
else {*/
//throw new FileNotFoundException(script + " (No such file or directory)");
//}
}
} catch (IOException e) {
throw new JavaException(e);
}
}

private static InputStream findScript(InputStream is) throws IOException {
StringBuilder buf = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String currentLine = br.readLine();
while (currentLine != null && !isRubyShebangLine(currentLine)) {
currentLine = br.readLine();
}

buf.append(currentLine);
buf.append("\n");

do {
currentLine = br.readLine();
if (currentLine != null) {
buf.append(currentLine);
buf.append("\n");
}
} while (!(currentLine == null || currentLine.contains("__END__") || currentLine.contains("\026")));
return new BufferedInputStream(new ByteArrayInputStream(buf.toString().getBytes()), 8192);
}

public String displayedFileName() {
if (hasInlineScript) {
if (scriptFileName != null) {
@@ -292,14 +258,6 @@ public String getJRubyHome() {
return jrubyHome;
}

public void setInput(InputStream newInput) {
input = newInput;
}

public InputStream getInput() {
return input;
}

public void setOutput(PrintStream newOutput) {
output = newOutput;
}