Skip to content

Commit

Permalink
Showing 278 changed files with 8,206 additions and 2,535 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -85,8 +85,9 @@ branches:
- /^test-.*$/
- /^ha-feature/

script: if [[ -v COMMAND ]]; then $COMMAND; else travis_retry ./mvnw -Pbootstrap clean install -Dinvoker.skip=false $PHASE | egrep -v 'Download|\\[exec\\] [[:digit:]]+/[[:digit:]]+|^[[:space:]]*\\[exec\\][[:space:]]*$' ; [ ${PIPESTATUS[0]} == 0 ]; fi
install: /bin/true
script: if [[ -v COMMAND ]]; then $COMMAND; else ./mvnw install -Dinvoker.skip=false $PHASE | egrep -v 'Download|\\[exec\\] [[:digit:]]+/[[:digit:]]+|^[[:space:]]*\\[exec\\][[:space:]]*$' ; [ ${PIPESTATUS[0]} == 0 ]; fi
install: travis_retry ./mvnw -Pbootstrap clean install -Dinvoker.skip -Dmaven.test.skip

notifications:
irc:
channels:
2 changes: 1 addition & 1 deletion core/pom.rb
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@
jar 'com.github.jnr:jnr-enxio:0.9'
jar 'com.github.jnr:jnr-x86asm:1.0.2'
jar 'com.github.jnr:jnr-unixsocket:0.8'
jar 'com.github.jnr:jnr-posix:3.0.14'
jar 'com.github.jnr:jnr-posix:3.0.15-SNAPSHOT'
jar 'com.github.jnr:jnr-constants:0.8.8'
jar 'com.github.jnr:jnr-ffi:2.0.3'
jar 'com.github.jnr:jffi:${jffi.version}'
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-posix</artifactId>
<version>3.0.14</version>
<version>3.0.15-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.jnr</groupId>
12 changes: 5 additions & 7 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -528,16 +528,14 @@ public void runFromMain(InputStream inputStream, String filename) {
getGlobalVariables().define("$PROGRAM_NAME", d, GLOBAL);
getGlobalVariables().define("$0", d, GLOBAL);

for (Iterator i = config.getOptionGlobals().entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
Object value = entry.getValue();
IRubyObject varvalue;
if (value != null) {
varvalue = newString(value.toString());
for (Map.Entry<String, String> entry : config.getOptionGlobals().entrySet()) {
final IRubyObject varvalue;
if (entry.getValue() != null) {
varvalue = newString(entry.getValue());
} else {
varvalue = getTrue();
}
getGlobalVariables().set("$" + entry.getKey().toString(), varvalue);
getGlobalVariables().set("$" + entry.getKey(), varvalue);
}

if (filename.endsWith(".class")) {
16 changes: 16 additions & 0 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -628,6 +628,7 @@ public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRuby
return runtime.newString(dirname(context, jfilename)).infectBy(filename);
}

private static Pattern PROTOCOL_PATTERN = Pattern.compile("^([a-z]+:)?[a-z]+:/.*");
public static String dirname(ThreadContext context, String jfilename) {
String name = jfilename.replace('\\', '/');
int minPathLength = 1;
@@ -639,6 +640,21 @@ public static String dirname(ThreadContext context, String jfilename) {
minPathLength = 3;
}

// jar like paths
if (name.contains("!/")) {
int start = name.indexOf("!/") + 1;
String path = dirname(context, name.substring(start));
if (path.equals(".") || path.equals("/")) path = "";
return name.substring(0, start) + path;
}
// address all the url like paths first
if (PROTOCOL_PATTERN.matcher(name).matches()) {
int start = name.indexOf(":/") + 2;
String path = dirname(context, name.substring(start));
if (path.equals(".")) path = "";
return name.substring(0, start) + path;
}

while (name.length() > minPathLength && name.charAt(name.length() - 1) == '/') {
trimmedSlashes = true;
name = name.substring(0, name.length() - 1);
29 changes: 9 additions & 20 deletions core/src/main/java/org/jruby/RubyGlobal.java
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@

import jnr.enxio.channels.NativeDeviceChannel;
import jnr.posix.POSIX;

import org.jcodings.Encoding;
import org.jruby.anno.JRubyMethod;
import org.jruby.common.IRubyWarnings.ID;
@@ -56,21 +57,16 @@
import org.jruby.util.KCode;
import org.jruby.util.OSEnvironment;
import org.jruby.util.RegexpOptions;
import org.jruby.util.ShellLauncher;
import org.jruby.util.cli.OutputStrings;
import org.jruby.util.io.BadDescriptorException;
import org.jruby.util.io.OpenFile;
import org.jruby.util.io.STDIO;

import static org.jruby.internal.runtime.GlobalVariable.Scope.*;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.Channel;
import java.nio.channels.Channels;
import java.util.HashMap;
import java.util.Map;

/** This class initializes global variables and constants.
@@ -296,14 +292,8 @@ private static Channel prepareStdioChannel(Ruby runtime, STDIO stdio, Object str
}

private static void defineGlobalEnvConstants(Ruby runtime) {
Map environmentVariableMap = null;
OSEnvironment environment = new OSEnvironment();
environmentVariableMap = environment.getEnvironmentVariableMap(runtime);

if (environmentVariableMap == null) {
// if the environment variables can't be obtained, define an empty ENV
environmentVariableMap = new HashMap();
}
Map<RubyString, RubyString> environmentVariableMap = environment.getEnvironmentVariableMap(runtime);

CaseInsensitiveStringOnlyRubyHash env = new CaseInsensitiveStringOnlyRubyHash(runtime,
environmentVariableMap,
@@ -315,9 +305,8 @@ private static void defineGlobalEnvConstants(Ruby runtime) {
runtime.setENV(env);

// Define System.getProperties() in ENV_JAVA
Map systemProps = environment.getSystemPropertiesMap(runtime);
RubyHash systemPropsHash = new ReadOnlySystemPropertiesHash(
runtime, systemProps, runtime.getNil());
Map<RubyString, RubyString> systemProps = environment.getSystemPropertiesMap(runtime);
RubyHash systemPropsHash = new ReadOnlySystemPropertiesHash(runtime, systemProps, runtime.getNil());
systemPropsHash.setFrozen(true);
runtime.defineGlobalConstant("ENV_JAVA", systemPropsHash);
}
@@ -329,7 +318,7 @@ private static void defineGlobalEnvConstants(Ruby runtime) {
*/
public static class CaseInsensitiveStringOnlyRubyHash extends StringOnlyRubyHash {

public CaseInsensitiveStringOnlyRubyHash(Ruby runtime, Map valueMap, IRubyObject defaultValue, boolean updateRealENV) {
public CaseInsensitiveStringOnlyRubyHash(Ruby runtime, Map<RubyString, RubyString> valueMap, IRubyObject defaultValue, boolean updateRealENV) {
super(runtime, valueMap, defaultValue, updateRealENV);
}

@@ -363,12 +352,12 @@ public static class StringOnlyRubyHash extends RubyHash {
// the op_aset to also update the real ENV map via setenv/unsetenv.
private boolean updateRealENV;

public StringOnlyRubyHash(Ruby runtime, Map valueMap, IRubyObject defaultValue, boolean updateRealENV) {
public StringOnlyRubyHash(Ruby runtime, Map<RubyString, RubyString> valueMap, IRubyObject defaultValue, boolean updateRealENV) {
super(runtime, valueMap, defaultValue);
this.updateRealENV = updateRealENV;
}

public StringOnlyRubyHash(Ruby runtime, Map valueMap, IRubyObject defaultValue) {
public StringOnlyRubyHash(Ruby runtime, Map<RubyString, RubyString> valueMap, IRubyObject defaultValue) {
this(runtime, valueMap, defaultValue, false);
}

@@ -470,11 +459,11 @@ private IRubyObject normalizeEnvString(IRubyObject str) {
}

private static class ReadOnlySystemPropertiesHash extends StringOnlyRubyHash {
public ReadOnlySystemPropertiesHash(Ruby runtime, Map valueMap, IRubyObject defaultValue, boolean updateRealENV) {
public ReadOnlySystemPropertiesHash(Ruby runtime, Map<RubyString, RubyString> valueMap, IRubyObject defaultValue, boolean updateRealENV) {
super(runtime, valueMap, defaultValue, updateRealENV);
}

public ReadOnlySystemPropertiesHash(Ruby runtime, Map valueMap, IRubyObject defaultValue) {
public ReadOnlySystemPropertiesHash(Ruby runtime, Map<RubyString, RubyString> valueMap, IRubyObject defaultValue) {
this(runtime, valueMap, defaultValue, false);
}

13 changes: 7 additions & 6 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
package org.jruby;

import jnr.posix.util.Platform;

import org.jruby.embed.util.SystemPropertyCatcher;
import org.jruby.exceptions.MainExitException;
import org.jruby.runtime.Constants;
@@ -391,7 +392,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()) {
@@ -661,7 +662,7 @@ public boolean isSiphashEnabled() {
return siphashEnabled;
}

public void setEnvironment(Map newEnvironment) {
public void setEnvironment(Map<String, String> newEnvironment) {
environment = new HashMap<String, String>();
if (newEnvironment != null) {
environment.putAll(newEnvironment);
@@ -677,7 +678,7 @@ private void setupEnvironment(String jrubyHome) {
}
}

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

@@ -1055,15 +1056,15 @@ public String getInPlaceBackupExtension() {
return inPlaceBackupExtension;
}

public Map getOptionGlobals() {
public Map<String, String> getOptionGlobals() {
return optionGlobals;
}

public boolean isManagementEnabled() {
return managementEnabled;
}

public Set getExcludedMethods() {
public Set<String> getExcludedMethods() {
return excludedMethods;
}

@@ -1465,7 +1466,7 @@ public ClassLoader getCurrentThreadClassLoader() {
private boolean argvGlobalsOn = false;
private boolean assumeLoop = Options.CLI_ASSUME_LOOP.load();
private boolean assumePrinting = Options.CLI_ASSUME_PRINT.load();
private Map optionGlobals = new HashMap();
private Map<String, String> optionGlobals = new HashMap<String, String>();
private boolean processLineEnds = Options.CLI_PROCESS_LINE_ENDS.load();
private boolean split = Options.CLI_AUTOSPLIT.load();
private Verbosity verbosity = Options.CLI_WARNING_LEVEL.load();
20 changes: 7 additions & 13 deletions core/src/main/java/org/jruby/embed/IsolatedScriptingContainer.java
Original file line number Diff line number Diff line change
@@ -5,11 +5,6 @@
import java.util.HashMap;
import java.util.Map;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.wiring.BundleWiring;

/**
* the IsolatedScriptingContainer does set GEM_HOME and GEM_PATH and JARS_HOME
* in such a way that it uses only resources which can be reached with classloader.
@@ -75,10 +70,10 @@ public void setEnvironment(Map environment) {
}
}

private Bundle toBundle(String symbolicName) {
BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
Bundle bundle = null;
for (Bundle b : context.getBundles()) {
private org.osgi.framework.Bundle toBundle(String symbolicName) {
org.osgi.framework.BundleContext context = org.osgi.framework.FrameworkUtil.getBundle(getClass()).getBundleContext();
org.osgi.framework.Bundle bundle = null;
for (org.osgi.framework.Bundle b : context.getBundles()) {
if (b.getSymbolicName().equals(symbolicName)) {
bundle = b;
break;
@@ -90,22 +85,21 @@ private Bundle toBundle(String symbolicName) {
return bundle;
}

private String createUri(Bundle cl, String ref) {
private String createUri(org.osgi.framework.Bundle cl, String ref) {
URL url = cl.getResource( ref );
if ( url == null && ref.startsWith( "/" ) ) {
url = cl.getResource( ref.substring( 1 ) );
}
if ( url == null ) {
throw new RuntimeException( "reference " + ref + " not found on classloader " + cl );
}
System.err.println("=---" + url.toString().replaceFirst( ref + "$", "" ));
return "uri:" + url.toString().replaceFirst( ref + "$", "" );
}
/**
* add the classloader from the given bundle to the LOAD_PATH
* @param bundle
*/
public void addBundleToLoadPath(Bundle bundle) {
public void addBundleToLoadPath(org.osgi.framework.Bundle bundle) {
addLoadPath(createUri(bundle, "/.jrubydir"));
}

@@ -123,7 +117,7 @@ public void addBundleToLoadPath(String symbolicName) {
* add the classloader from the given bundle to the GEM_PATH
* @param bundle
*/
public void addBundleToGemPath(Bundle bundle) {
public void addBundleToGemPath(org.osgi.framework.Bundle bundle) {
addGemPath(createUri(bundle, "/specifications/.jrubydir"));
}

Loading

0 comments on commit b2bfc48

Please sign in to comment.