Skip to content

Commit

Permalink
Showing 3 changed files with 5 additions and 281 deletions.
2 changes: 1 addition & 1 deletion truffle/src/main/java/org/jruby/truffle/Main.java
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ public class Main {
public static void main(String[] args) {
printTruffleTimeMetric("before-main");

final RubyInstanceConfig config = new RubyInstanceConfig(false);
final RubyInstanceConfig config = new RubyInstanceConfig();

try {
config.processArguments(args);
Original file line number Diff line number Diff line change
@@ -450,18 +450,11 @@ private void processArgument() {
config.setShouldPrintUsage(true);
config.setShouldRunInterpreter(false);
break;
} else if (argument.equals("--properties")) {
config.setShouldPrintProperties(true);
config.setShouldRunInterpreter(false);
break;
} else if (argument.equals("--version")) {
disallowedInRubyOpts(argument);
config.setShowVersion(true);
config.setShouldRunInterpreter(false);
break FOR;
} else if (argument.equals("--bytecode")) {
config.setShowBytecode(true);
break FOR;
} else if (argument.equals("--fast")) {
throw new UnsupportedOperationException();
} else if (argument.startsWith("--profile")) {
@@ -513,8 +506,6 @@ private void processArgument() {
break FOR;
} else if (dumpArg.equals("syntax")) {
config.setShouldCheckSyntax(true);
} else if (dumpArg.equals("insns")) {
config.setShowBytecode(true);
} else {
MainExitException mee = new MainExitException(1, error);
mee.setUsageError(true);
@@ -612,24 +603,6 @@ private void runBinScript() {
endOfArguments = true;
}

private String resolve(String path, String scriptName) {
if (RubyInstanceConfig.DEBUG_SCRIPT_RESOLUTION) {
config.getError().println("Trying path: " + path);
}
try {
File fullName = new File(path, scriptName);
if (fullName.exists() && fullName.isFile()) {
if (RubyInstanceConfig.DEBUG_SCRIPT_RESOLUTION) {
config.getError().println("Found: " + fullName.getAbsolutePath());
}
return fullName.getAbsolutePath();
}
} catch (Exception e) {
// keep going
}
return null;
}

public String resolveScript(String scriptName) {
// TODO CS 4-Jan-17 this never worked properly - it needs home before we've set up a context to determine it properly
throw new UnsupportedOperationException();
@@ -664,14 +637,6 @@ public String resolveScript(String scriptName) {
return null;*/
}

@Deprecated
public String resolveScriptUsingClassLoader(String scriptName) {
if (RubyInstanceConfig.defaultClassLoader().getResourceAsStream("bin/" + scriptName) != null){
return "classpath:/bin/" + scriptName;
}
return null;
}

private String grabValue(String errorMessage) {
return grabValue(errorMessage, true);
}
Original file line number Diff line number Diff line change
@@ -29,13 +29,10 @@
package org.jruby.truffle.options;

import com.oracle.truffle.api.TruffleOptions;
import jnr.posix.util.Platform;
import org.jruby.truffle.core.string.KCode;
import org.jruby.truffle.core.string.StringSupport;
import org.jruby.truffle.language.control.JavaException;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -59,56 +56,21 @@
@SuppressWarnings("unused")
public class RubyInstanceConfig {

public RubyInstanceConfig(boolean isSecurityRestricted) {
this.isSecurityRestricted = isSecurityRestricted;
currentDirectory = isSecurityRestricted ? "/" : getFileProperty("user.dir");

if (isSecurityRestricted) {
//
} else {
if (COMPILE_EXCLUDE != null) {
excludedMethods.addAll(StringSupport.split(COMPILE_EXCLUDE, ','));
}
}
initEnvironment();
}

public static String getFileProperty(String property) {
return normalizeSeps(System.getProperty(property, "/"));
}

public static String normalizeSeps(String path) {
if (Platform.IS_WINDOWS) {
return path.replace(File.separatorChar, '/');
}
return path;
}

private void initEnvironment() {
public RubyInstanceConfig() {
currentDirectory = System.getProperty("user.dir", "/");
environment = new HashMap<>();
try {
environment.putAll(System.getenv());
}
catch (SecurityException se) { /* ignore missing getenv permission */ }
environment.putAll(System.getenv());
}

public void processArguments(String[] arguments) {
final ArgumentProcessor processor = new ArgumentProcessor(arguments, this);
processor.processArguments();
tryProcessArgumentsWithRubyopts();
processArgumentsWithRubyopts();
if (!TruffleOptions.AOT && !hasScriptArgv && System.console() != null) {
setScriptFileName(processor.resolveScript("irb"));
}
}

public void tryProcessArgumentsWithRubyopts() {
try {
processArgumentsWithRubyopts();
} catch (SecurityException se) {
// ignore and do nothing
}
}

public void processArgumentsWithRubyopts() {
// environment defaults to System.getenv normally
Object rubyoptObj = environment.get("RUBYOPT");
@@ -122,15 +84,6 @@ public void processArgumentsWithRubyopts() {
}
}

private static final Pattern RUBY_SHEBANG = Pattern.compile("#!.*ruby.*");

protected static boolean isRubyShebangLine(String line) {
return RUBY_SHEBANG.matcher(line).matches();
}

private static final String URI_PREFIX_STRING = "^(uri|jar|file|classpath):([^:/]{2,}:([^:/]{2,}:)?)?";
public static Pattern PROTOCOL_PATTERN = Pattern.compile(URI_PREFIX_STRING + ".*");

public byte[] inlineScript() {
return inlineScript.toString().getBytes();
}
@@ -166,22 +119,10 @@ public String displayedFileName() {
}
}

////////////////////////////////////////////////////////////////////////////
// Getters and setters for config settings.
////////////////////////////////////////////////////////////////////////////

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

public PrintStream getOutput() {
return output;
}

public void setError(PrintStream newError) {
error = newError;
}

public PrintStream getError() {
return error;
}
@@ -194,26 +135,6 @@ public String getCurrentDirectory() {
return currentDirectory;
}

public void setEnvironment(Map<String, String> newEnvironment) {
environment = new HashMap<>();
if (newEnvironment != null) {
environment.putAll(newEnvironment);
}
}

public Map<String, String> getEnvironment() {
return environment;
}

public ClassLoader getLoader() {
return loader;
}

public void setLoader(ClassLoader loader) {
this.loader = loader;
}


public String[] getArgv() {
return argv;
}
@@ -247,14 +168,6 @@ public boolean getShouldPrintUsage() {
return shouldPrintUsage;
}

public void setShouldPrintProperties(boolean shouldPrintProperties) {
this.shouldPrintProperties = shouldPrintProperties;
}

public boolean getShouldPrintProperties() {
return shouldPrintProperties;
}

public boolean isInlineScript() {
return hasInlineScript;
}
@@ -326,10 +239,6 @@ public boolean isShowVersion() {
return showVersion;
}

public void setShowBytecode(boolean showBytecode) {
this.showBytecode = showBytecode;
}

public void setShowCopyright(boolean showCopyright) {
this.showCopyright = showCopyright;
}
@@ -418,29 +327,6 @@ public void setFrozenStringLiteral(boolean frozenStringLiteral) {
this.frozenStringLiteral = frozenStringLiteral;
}


public static ClassLoader defaultClassLoader() {
if (TruffleOptions.AOT) {
return null;
}

ClassLoader loader = RubyInstanceConfig.class.getClassLoader();

// loader can be null for example when jruby comes from the boot-classLoader

if (loader == null) {
loader = Thread.currentThread().getContextClassLoader();
}

return loader;
}

////////////////////////////////////////////////////////////////////////////
// Configuration fields.
////////////////////////////////////////////////////////////////////////////

private final boolean isSecurityRestricted;

/**
* Indicates whether the script must be extracted from script source
*/
@@ -462,8 +348,6 @@ public static ClassLoader defaultClassLoader() {
private String internalEncoding = null;
private String externalEncoding = null;

private ClassLoader loader = defaultClassLoader();

// from CommandlineParser
private List<String> loadPaths = new ArrayList<>();
private Set<String> excludedMethods = new HashSet<>();
@@ -497,135 +381,10 @@ public static ClassLoader defaultClassLoader() {

private boolean forceStdin = false;

////////////////////////////////////////////////////////////////////////////
// Static configuration fields, used as defaults for new JRuby instances.
////////////////////////////////////////////////////////////////////////////

/**
* Comma-separated list of methods to exclude from JIT compilation.
* Specify as "Module", "Module#method" or "method".
*
* Set with the <tt>jruby.jit.exclude</tt> system property.
*/
public static final String COMPILE_EXCLUDE = "";

/**
* Indicates the global default for whether native code is enabled. Default
* is true. This value is used to default new runtime configurations.
*
* Set with the <tt>jruby.native.enabled</tt> system property.
*/
public static final boolean NATIVE_ENABLED = false;

@Deprecated
public final static boolean CEXT_ENABLED = false;

/**
* Turn on debugging of script resolution with "-S".
*
* Set with the <tt>jruby.debug.scriptResolution</tt> system property.
*/
public static final boolean DEBUG_SCRIPT_RESOLUTION = false;

@Deprecated
public static final boolean JIT_CACHE_ENABLED = false;

@Deprecated
public void setSafeLevel(int safeLevel) {
}

@Deprecated
public String getInPlaceBackupExtention() {
return inPlaceBackupExtension;
}

@Deprecated
public String getBasicUsageHelp() {
return OutputStrings.getBasicUsageHelp();
}

@Deprecated
public String getVersionString() {
return OutputStrings.getVersionString();
}

@Deprecated
public String getCopyrightString() {
return OutputStrings.getCopyrightString();
}

@Deprecated
public Collection<String> requiredLibraries() {
return requiredLibraries;
}

@Deprecated
public List<String> loadPaths() {
return loadPaths;
}

@Deprecated
public boolean shouldPrintUsage() {
return shouldPrintUsage;
}

@Deprecated
public boolean shouldPrintProperties() {
return shouldPrintProperties;
}

@Deprecated
public Boolean getVerbose() {
return isVerbose();
}

public Verbosity getVerbosity() {
return verbosity;
}

@Deprecated
public boolean shouldRunInterpreter() {
return isShouldRunInterpreter();
}

@Deprecated
public boolean isShouldRunInterpreter() {
return shouldRunInterpreter;
}

@Deprecated
public boolean isxFlag() {
return xFlag;
}

@Deprecated
public static final boolean nativeEnabled = NATIVE_ENABLED;

@Deprecated
public boolean isSamplingEnabled() {
return false;
}

@Deprecated
public void setBenchmarking(boolean benchmarking) {
}

@Deprecated
public boolean isBenchmarking() {
return false;
}

@Deprecated
public void setCextEnabled(boolean b) {
}

@Deprecated
public boolean isCextEnabled() {
return false;
}

@Deprecated public static final String JIT_CODE_CACHE = "";

public void setKCode(KCode kcode) {
this.kcode = kcode;
}

0 comments on commit 2443df5

Please sign in to comment.