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

Commits on Dec 28, 2015

  1. remove runtime.is2_0 checking

    kares committed Dec 28, 2015
    Copy the full SHA
    c5a5204 View commit details
  2. Copy the full SHA
    fcbdb5b View commit details
  3. Copy the full SHA
    988bde4 View commit details
  4. Copy the full SHA
    a3a7b91 View commit details
54 changes: 29 additions & 25 deletions core/src/main/java/org/jruby/RubyDir.java
Original file line number Diff line number Diff line change
@@ -37,15 +37,11 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;

import jnr.posix.FileStat;
import jnr.posix.POSIX;

import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyClass;
@@ -61,7 +57,6 @@
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.Visibility;
import org.jruby.util.Dir;
import org.jruby.util.FileResource;
import org.jruby.util.JRubyFile;
@@ -118,15 +113,11 @@ private final void checkDir() {

private final void checkDirIgnoreClosed() {
testFrozen("Dir");
update();
}

private void update() {
// update snapshot (if changed) :
if (snapshot == null || dir.exists() && dir.lastModified() > lastModified) {
lastModified = dir.lastModified();
List<String> snapshotList = new ArrayList<String>();
snapshotList.addAll(getContents(dir));
snapshot = snapshotList.toArray(new String[snapshotList.size()]);
final List<String> contents = getContents(dir);
snapshot = contents.toArray(new String[contents.size()]);
}
}

@@ -190,8 +181,9 @@ private static String getCWD(Ruby runtime) {
return runtime.getCurrentDirectory();
}
try {
return new org.jruby.util.NormalizedFile(runtime.getCurrentDirectory()).getCanonicalPath();
} catch (Exception e) {
return new JRubyFile(runtime.getCurrentDirectory()).getCanonicalPath();
}
catch (Exception e) {
return runtime.getCurrentDirectory();
}
}
@@ -312,8 +304,8 @@ public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyOb
getHomeDirectoryPath(context);
String adjustedPath = RubyFile.adjustRootPathOnWindows(runtime, path.asJavaString(), null);
checkDirIsTwoSlashesOnWindows(runtime, adjustedPath);
String realPath = null;
String oldCwd = runtime.getCurrentDirectory();
final String realPath;
final String oldCwd = runtime.getCurrentDirectory();
if (PROTOCOL_PATTERN.matcher(adjustedPath).matches()) {
realPath = adjustedPath;
}
@@ -738,13 +730,18 @@ private static String dirFromPath(final String path, final Ruby runtime) throws
* <code>ArrayList</code> containing the names of the files as Java Strings.
*/
protected static List<String> getContents(FileResource directory) {
String[] contents = directory.list();
List<String> result = new ArrayList<String>();
final String[] contents = directory.list();

final List<String> result;
// If an IO exception occurs (something odd, but possible)
// A directory may return null.
if (contents != null) result.addAll(Arrays.asList(contents));

if (contents != null) {
result = new ArrayList<String>(contents.length);
Collections.addAll(result, contents);
}
else {
result = Collections.emptyList();
}
return result;
}

@@ -753,12 +750,19 @@ protected static List<String> getContents(FileResource directory) {
* <code>ArrayList</code> containing the names of the files as Ruby Strings.
*/
protected static List<RubyString> getContents(FileResource directory, Ruby runtime) {
List<RubyString> result = new ArrayList<RubyString>();
String[] contents = directory.list();
final String[] contents = directory.list();

for (int i = 0; i < contents.length; i++) {
result.add(runtime.newString(contents[i]));
final List<RubyString> result;
if (contents != null) {
result = new ArrayList<RubyString>(contents.length);
for (int i = 0; i < contents.length; i++) {
result.add( runtime.newString(contents[i]) );
}
}
else {
result = Collections.emptyList();
}

return result;
}

118 changes: 64 additions & 54 deletions core/src/main/java/org/jruby/ext/rbconfig/RbConfigLibrary.java
Original file line number Diff line number Diff line change
@@ -30,7 +30,16 @@
***** END LICENSE BLOCK *****/
package org.jruby.ext.rbconfig;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import jnr.posix.util.Platform;

import org.jruby.Ruby;
import org.jruby.RubyHash;
import org.jruby.RubyKernel;
@@ -42,16 +51,8 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.load.Library;
import org.jruby.util.NormalizedFile;
import org.jruby.util.SafePropertyAccessor;

import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.jruby.platform.Platform.IS_WINDOWS;

@JRubyModule(name="Config")
@@ -63,9 +64,9 @@ public class RbConfigLibrary implements Library {
private static final String RUBY_SOLARIS = "solaris";
private static final String RUBY_FREEBSD = "freebsd";
private static final String RUBY_AIX = "aix";

private static String normalizedHome;

/** This is a map from Java's "friendly" OS names to those used by Ruby */
public static final Map<String, String> RUBY_OS_NAMES = new HashMap<String, String>();
static {
@@ -89,23 +90,23 @@ public class RbConfigLibrary implements Library {
RUBY_OS_NAMES.put("FreeBSD", RUBY_FREEBSD);
RUBY_OS_NAMES.put("AIX", RUBY_AIX);
}

public static String getOSName() {
if (Platform.IS_WINDOWS) {
return RUBY_WIN32;
}

String OSName = Platform.getOSName();
String theOSName = RUBY_OS_NAMES.get(OSName);

return theOSName == null ? OSName : theOSName;
}

public static String getArchitecture() {
String architecture = Platform.ARCH;
if (architecture == null) architecture = "unknown";
if (architecture.equals("amd64")) architecture = "x86_64";

return architecture;
}

@@ -129,16 +130,17 @@ public static String getLibDir(Ruby runtime) {
libdir = home + "/lib";
}
else {
libdir = new NormalizedFile(home, "lib").getPath();
libdir = newFile(home, "lib").getPath();
}
} else {
try {
// Our shell scripts pass in non-canonicalized paths, but even if we didn't
// anyone who did would become unhappy because Ruby apps expect no relative
// operators in the pathname (rubygems, for example).
libdir = new NormalizedFile(libdir).getCanonicalPath();
} catch (IOException e) {
libdir = new NormalizedFile(libdir).getAbsolutePath();
libdir = newFile(libdir).getCanonicalPath();
}
catch (IOException e) {
libdir = newFile(libdir).getAbsolutePath();
}
}

@@ -147,12 +149,12 @@ public static String getLibDir(Ruby runtime) {

public static String getVendorDirGeneral(Ruby runtime) {
// vendorDirGeneral example: /usr/share/jruby/lib/ - commonly the same as libdir
return new NormalizedFile(SafePropertyAccessor.getProperty("vendor.dir.general", getLibDir(runtime))).getPath();
return newFile(SafePropertyAccessor.getProperty("vendor.dir.general", getLibDir(runtime))).getPath();
}

public static String getSiteDirGeneral(Ruby runtime) {
// siteDirGeneral example: /usr/local/share/jruby/lib/
return new NormalizedFile(SafePropertyAccessor.getProperty("site.dir.general", getLibDir(runtime))).getPath();
return newFile(SafePropertyAccessor.getProperty("site.dir.general", getLibDir(runtime))).getPath();
}

public static Boolean isSiteVendorSame(Ruby runtime) {
@@ -165,23 +167,23 @@ public static String getRubygemsDir(Ruby runtime) {
}

public static String getRubySharedLibDir(Ruby runtime) {
return new NormalizedFile(getVendorDirGeneral(runtime), "ruby/shared").getPath();
return newFile(getVendorDirGeneral(runtime), "ruby/shared").getPath();
}

public static String getRubyLibDir(Ruby runtime) {
return getRubyLibDirFor(runtime, "stdlib");
}

public static String getRubyLibDirFor(Ruby runtime, String runtimeVerStr) {
return new NormalizedFile(getVendorDirGeneral(runtime), String.format("ruby/%s", runtimeVerStr)).getPath();
return newFile(getVendorDirGeneral(runtime), String.format("ruby/%s", runtimeVerStr)).getPath();
}

public static String getArchDir(Ruby runtime) {
return getRubyLibDir(runtime);
}

public static String getVendorDir(Ruby runtime) {
return new NormalizedFile(getRubyLibDir(runtime), "vendor_ruby").getPath();
return newFile(getRubyLibDir(runtime), "vendor_ruby").getPath();
}

public static String getVendorLibDir(Ruby runtime) {
@@ -193,7 +195,7 @@ public static String getVendorArchDir(Ruby runtime) {
}

public static String getSiteDir(Ruby runtime) {
return new NormalizedFile(getSiteDirGeneral(runtime), String.format("ruby/%s/site_ruby", getRuntimeVerStr(runtime))).getPath();
return newFile(getSiteDirGeneral(runtime), String.format("ruby/%s/site_ruby", getRuntimeVerStr(runtime))).getPath();
}

public static String getSiteLibDir(Ruby runtime) {
@@ -203,9 +205,9 @@ public static String getSiteLibDir(Ruby runtime) {
public static String getSiteArchDir(Ruby runtime) {
return getSiteDir(runtime);
}

public static String getSysConfDir(Ruby runtime) {
return new NormalizedFile(getNormalizedHome(runtime), "etc").getPath();
return newFile(getNormalizedHome(runtime), "etc").getPath();
}

/**
@@ -218,15 +220,15 @@ public void load(Ruby runtime, boolean wrap) {

configModule = runtime.defineModule("RbConfig");
RubyKernel.autoload(runtime.getObject(), runtime.newSymbol("Config"), runtime.newString("rbconfig/obsolete.rb"));

configModule.defineAnnotatedMethods(RbConfigLibrary.class);

RubyHash configHash = RubyHash.newHash(runtime);
configModule.defineConstant("CONFIG", configHash);

String[] versionParts;
versionParts = Constants.RUBY_VERSION.split("\\.");

setConfig(configHash, "MAJOR", versionParts[0]);
setConfig(configHash, "MINOR", versionParts[1]);
setConfig(configHash, "TEENY", versionParts[2]);
@@ -240,7 +242,7 @@ public void load(Ruby runtime, boolean wrap) {
// Use property for binDir if available, otherwise fall back to common bin default
String binDir = SafePropertyAccessor.getProperty("jruby.bindir");
if (binDir == null) {
binDir = new NormalizedFile(normalizedHome, "bin").getPath();
binDir = newFile(normalizedHome, "bin").getPath();
}
setConfig(configHash, "bindir", binDir);

@@ -255,11 +257,11 @@ public void load(Ruby runtime, boolean wrap) {
setConfig(configHash, "host_os", getOSName());
setConfig(configHash, "host_vendor", System.getProperty("java.vendor"));
setConfig(configHash, "host_cpu", getArchitecture());

setConfig(configHash, "target_os", getOSName());

setConfig(configHash, "target_cpu", getArchitecture());

String jrubyJarFile = "jruby.jar";
URL jrubyPropertiesUrl = Ruby.getClassLoader().getResource("/org/jruby/Ruby.class");
if (jrubyPropertiesUrl != null) {
@@ -274,13 +276,13 @@ public void load(Ruby runtime, boolean wrap) {
setConfig(configHash, "LIBRUBY_SO", jrubyJarFile);
setConfig(configHash, "LIBRUBY_SO", jrubyJarFile);
setConfig(configHash, "LIBRUBY_ALIASES", jrubyJarFile);

setConfig(configHash, "build", Constants.BUILD);
setConfig(configHash, "target", Constants.TARGET);


String shareDir = new NormalizedFile(normalizedHome, "share").getPath();
String includeDir = new NormalizedFile(normalizedHome, "lib/native/" + getOSName()).getPath();
String shareDir = newFile(normalizedHome, "share").getPath();
String includeDir = newFile(normalizedHome, "lib/native/" + getOSName()).getPath();

String vendorDirGeneral = getVendorDirGeneral(runtime);
String siteDirGeneral = getSiteDirGeneral(runtime);
@@ -313,12 +315,12 @@ public void load(Ruby runtime, boolean wrap) {
setConfig(configHash, "includedir", includeDir);
setConfig(configHash, "configure_args", "");
setConfig(configHash, "datadir", shareDir);
setConfig(configHash, "mandir", new NormalizedFile(normalizedHome, "man").getPath());
setConfig(configHash, "mandir", newFile(normalizedHome, "man").getPath());
setConfig(configHash, "sysconfdir", sysConfDir);
setConfig(configHash, "localstatedir", new NormalizedFile(normalizedHome, "var").getPath());
setConfig(configHash, "localstatedir", newFile(normalizedHome, "var").getPath());
setConfig(configHash, "DLEXT", "jar");
if (getRubygemsDir(runtime) != null) {
setConfig(configHash, "rubygemsdir", new NormalizedFile(getRubygemsDir(runtime)).getPath());
setConfig(configHash, "rubygemsdir", newFile(getRubygemsDir(runtime)).getPath());
}

if (Platform.IS_WINDOWS) {
@@ -327,19 +329,19 @@ public void load(Ruby runtime, boolean wrap) {
setConfig(configHash, "EXEEXT", "");
}

setConfig(configHash, "ridir", new NormalizedFile(shareDir, "ri").getPath());
setConfig(configHash, "ridir", newFile(shareDir, "ri").getPath());

// These will be used as jruby defaults for rubygems if found
String gemhome = SafePropertyAccessor.getProperty("jruby.gem.home");
String gempath = SafePropertyAccessor.getProperty("jruby.gem.path");
if (gemhome != null) setConfig(configHash, "default_gem_home", gemhome);
if (gempath != null) setConfig(configHash, "default_gem_path", gempath);

setConfig(configHash, "joda-time.version", Constants.JODA_TIME_VERSION);
setConfig(configHash, "tzdata.version", Constants.TZDATA_VERSION);

RubyHash mkmfHash = RubyHash.newHash(runtime);


setConfig(mkmfHash, "libdir", vendorDirGeneral);
setConfig(mkmfHash, "arch", "java");
@@ -357,19 +359,19 @@ public void load(Ruby runtime, boolean wrap) {
setConfig(mkmfHash, "archdir", archDir);
setConfig(mkmfHash, "topdir", archDir);
setConfig(mkmfHash, "configure_args", "");
setConfig(mkmfHash, "datadir", new NormalizedFile(normalizedHome, "share").getPath());
setConfig(mkmfHash, "mandir", new NormalizedFile(normalizedHome, "man").getPath());
setConfig(mkmfHash, "datadir", newFile(normalizedHome, "share").getPath());
setConfig(mkmfHash, "mandir", newFile(normalizedHome, "man").getPath());
setConfig(mkmfHash, "sysconfdir", sysConfDir);
setConfig(mkmfHash, "localstatedir", new NormalizedFile(normalizedHome, "var").getPath());
setConfig(mkmfHash, "localstatedir", newFile(normalizedHome, "var").getPath());
if (getRubygemsDir(runtime) != null) {
setConfig(mkmfHash, "rubygemsdir", new NormalizedFile(getRubygemsDir(runtime)).getPath());
setConfig(mkmfHash, "rubygemsdir", newFile(getRubygemsDir(runtime)).getPath());
}

setupMakefileConfig(configModule, mkmfHash);

runtime.getLoadService().load("jruby/kernel/rbconfig.rb", false);
}

private static void setupMakefileConfig(RubyModule configModule, RubyHash mkmfHash) {
Ruby ruby = configModule.getRuntime();

@@ -394,11 +396,11 @@ private static void setupMakefileConfig(RubyModule configModule, RubyHash mkmfHa

String archflags = " -m" + (Platform.IS_64_BIT ? "64" : "32");

String hdr_dir = new NormalizedFile(normalizedHome, "lib/native/include/").getPath();
String hdr_dir = newFile(normalizedHome, "lib/native/include/").getPath();

// A few platform specific values
if (Platform.IS_WINDOWS) {
ldflags += " -L" + new NormalizedFile(normalizedHome, "lib/native/" + (Platform.IS_64_BIT ? "x86_64" : "i386") + "-Windows").getPath();
ldflags += " -L" + newFile(normalizedHome, "lib/native/" + (Platform.IS_64_BIT ? "x86_64" : "i386") + "-Windows").getPath();
ldflags += " -ljruby-cext";
ldsharedflags += " $(if $(filter-out -g -g0,$(debugflags)),,-s)";
dldflags = "-Wl,--enable-auto-image-base,--enable-auto-import $(DEFFILE)";
@@ -417,7 +419,7 @@ private static void setupMakefileConfig(RubyModule configModule, RubyHash mkmfHa

String libext = "a";
String objext = "o";

setConfig(mkmfHash, "configure_args", "");
setConfig(mkmfHash, "CFLAGS", cflags);
setConfig(mkmfHash, "CPPFLAGS", cppflags);
@@ -454,9 +456,9 @@ private static void setupMakefileConfig(RubyModule configModule, RubyHash mkmfHa
setConfig(mkmfHash, "includedir", hdr_dir);
setConfig(mkmfHash, "rubyhdrdir", hdr_dir);
setConfig(mkmfHash, "archdir", hdr_dir);

ruby.getObject().defineConstant("CROSS_COMPILING", ruby.getNil());

configModule.defineConstant("MAKEFILE_CONFIG", mkmfHash);
}

@@ -490,4 +492,12 @@ private static String getRubyEnv(RubyHash envHash, String var, String default_va
var = (String) envHash.get(var);
return var == null ? default_value : var;
}

private static File newFile(final String path) {
return new org.jruby.util.NormalizedFile(path);
}
private static File newFile(final String parent, final String child) {
return new org.jruby.util.NormalizedFile(parent, child);
}

}
11 changes: 4 additions & 7 deletions core/src/main/java/org/jruby/ext/stringio/StringIO.java
Original file line number Diff line number Diff line change
@@ -575,13 +575,10 @@ private IRubyObject getline(ThreadContext context, IRubyObject[] args) {
break;

case 2:
if (!args[0].isNil()) str = args[0].convertToString();
// 2.0 ignores double nil, 1.9 raises
if (runtime.is2_0()) {
if (!args[1].isNil()) {
limit = RubyNumeric.num2int(args[1]);
}
} else {
if ( ! args[0].isNil() ) {
str = args[0].convertToString();
}
if ( ! args[1].isNil() ) {
limit = RubyNumeric.num2int(args[1]);
}
break;
18 changes: 11 additions & 7 deletions core/src/main/java/org/jruby/util/JRubyFile.java
Original file line number Diff line number Diff line change
@@ -36,16 +36,16 @@
import java.io.IOException;

import jnr.posix.JavaSecuredFile;
import jnr.posix.POSIX;

import org.jruby.Ruby;
import org.jruby.platform.Platform;
import org.jruby.runtime.ThreadContext;

/**
* <p>This file acts as an alternative to NormalizedFile, due to the problems with current working
* directory.</p>
*
* <p>
* This file acts as an alternative to NormalizedFile, due to the problems with
* current working directory.
* </p>
*/
public class JRubyFile extends JavaSecuredFile {
private static final long serialVersionUID = 435364547567567L;
@@ -124,7 +124,7 @@ private static JRubyFile createNoUnicodeConversion(String cwd, String pathname)
if (pathname == null || pathname.length() == 0 || Ruby.isSecurityRestricted()) {
return JRubyNonExistentFile.NOT_EXIST;
}
if(pathname.startsWith("file:")) {
if (pathname.startsWith("file:")) {
pathname = pathname.substring(5);
}
File internal = new JavaSecuredFile(pathname);
@@ -149,10 +149,14 @@ private JRubyFile(File file) {
this(file.getAbsolutePath());
}

protected JRubyFile(String filename) {
public JRubyFile(String filename) {
super(filename);
}

public JRubyFile(String parent, String child) {
super(parent, child);
}

@Override
public String getAbsolutePath() {
final String path = super.getPath();
@@ -177,7 +181,7 @@ public String getCanonicalPath() throws IOException {

@Override
public String getPath() {
return normalizeSeps(super.getPath());
return normalizeSeps(super.getPath());
}

@Override