Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions core/src/main/java/org/jruby/RubyProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static RubyModule createProcessModule(Ruby runtime) {
public static final String CLOCK_UNIT_FLOAT_MILLISECOND = "float_millisecond";
public static final String CLOCK_UNIT_FLOAT_SECOND = "float_second";
public static final String CLOCK_UNIT_HERTZ = "hertz";

@JRubyClass(name="Process::Status")
public static class RubyStatus extends RubyObject {
private final long status;
Expand Down Expand Up @@ -573,16 +573,12 @@ public static IRubyObject exit_bang(IRubyObject recv, IRubyObject[] args) {

@JRubyMethod(name = "groups", module = true, visibility = PRIVATE)
public static IRubyObject groups(IRubyObject recv) {
if(Platform.IS_WINDOWS) {
throw recv.getRuntime().newNotImplementedError("groups() function is unimplemented on this machine");
} else {
long[] groups = (new com.sun.security.auth.module.UnixSystem()).getGroups();
RubyArray ary = RubyArray.newArray(recv.getRuntime(), groups.length);
for(int i = 0; i < groups.length; i++) {
ary.push(RubyFixnum.newFixnum(recv.getRuntime(), groups[i]));
}
return ary;
long[] groups = Platform.getPlatform().getGroups(recv);
RubyArray ary = RubyArray.newArray(recv.getRuntime(), groups.length);
for(int i = 0; i < groups.length; i++) {
ary.push(RubyFixnum.newFixnum(recv.getRuntime(), groups[i]));
}
return ary;
}

@JRubyMethod(name = "setrlimit", rest = true, module = true, visibility = PRIVATE)
Expand Down
57 changes: 57 additions & 0 deletions core/src/main/java/org/jruby/platform/NTPlatform.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/***** BEGIN LICENSE BLOCK *****
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2014 Timur Duehr <tduehr@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/

package org.jruby.platform;

import org.jruby.runtime.builtin.IRubyObject;

public class NTPlatform extends Platform {
private final Class systemClass;
private final Object system;

protected NTPlatform() {
Class sClass = null;
Object s = null;

try {
sClass = Class.forName("com.sun.security.auth.module.NTSystem");
s = sClass.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new UnsupportedOperationException(e.getMessage(), e);
}

systemClass = sClass;
system = s;
}


@Override
public long[] getGroups(IRubyObject recv) {
throw recv.getRuntime().newNotImplementedError("groups() function is unimplemented on Windows");
}
}
23 changes: 21 additions & 2 deletions core/src/main/java/org/jruby/platform/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
package org.jruby.platform;

import org.jruby.util.SafePropertyAccessor;
import org.jruby.runtime.builtin.IRubyObject;

import java.nio.ByteOrder;
import java.util.HashMap;
Expand All @@ -38,8 +39,8 @@
/**
* Platform specific constants.
*/
public class Platform {
private static final Platform INSTANCE = new Platform();
public abstract class Platform {
private static final Platform INSTANCE = initPlatform();
public static Platform getPlatform() {
return INSTANCE;
}
Expand Down Expand Up @@ -103,6 +104,7 @@ private static String initArchitecture() {
}
return arch;
}

public static final String ARCH = initArchitecture();
public static final String OS = initOperatingSystem();
public static final String JVM = getProperty("java.vm.name", "unknown");
Expand All @@ -124,6 +126,21 @@ private static String initArchitecture() {
public static final boolean IS_GCJ = JVM.equals(GCJ);
public static final boolean IS_IBM = JVM.equals(IBM);

private static Platform initPlatform(){
try {
if (IS_WINDOWS)
return new NTPlatform();

if (IS_SOLARIS)
return new SolarisPlatform();

// Punt
return new UnixPlatform();
} catch (UnsupportedOperationException e) {
return new UnsupportedPlatform();
}
}

/**
* An extension over <code>System.getProperty</code> method.
* Handles security restrictions, and returns the default
Expand All @@ -140,4 +157,6 @@ public static String getProperty(String property, String defValue) {
return defValue;
}
}

public abstract long[] getGroups(IRubyObject recv);
}
69 changes: 69 additions & 0 deletions core/src/main/java/org/jruby/platform/SolarisPlatform.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/***** BEGIN LICENSE BLOCK *****
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2014 Timur Duehr <tduehr@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/

package org.jruby.platform;

import org.jruby.runtime.builtin.IRubyObject;

import java.lang.Class;
import java.lang.reflect.Method;

public class SolarisPlatform extends Platform {
private final Class systemClass;
private final Object system;
private final Method groupsMethod;

protected SolarisPlatform() {
Class sClass = null;
Object s = null;
Method g = null;
try {
sClass = Class.forName("com.sun.security.auth.module.SolarisSystem");
s = sClass.getDeclaredConstructor().newInstance();
g = sClass.getDeclaredMethod("getGroups");
} catch (Exception e) {
throw new UnsupportedOperationException(e.getMessage(), e);
}

systemClass = sClass;
system = s;
groupsMethod = g;
}

@Override
public long[] getGroups(IRubyObject recv) {
if (groupsMethod == null)
throw recv.getRuntime().newNotImplementedError("groups() function is unimplemented on this platform");

try {
return (long[])groupsMethod.invoke(system);
} catch (Exception e) {
throw new UnsupportedOperationException("groups() function is unimplemented on this platform", e);
}
}
}
69 changes: 69 additions & 0 deletions core/src/main/java/org/jruby/platform/UnixPlatform.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/***** BEGIN LICENSE BLOCK *****
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2014 Timur Duehr <tduehr@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/

package org.jruby.platform;

import org.jruby.runtime.builtin.IRubyObject;

import java.lang.Class;
import java.lang.reflect.Method;

public class UnixPlatform extends Platform {
private final Class systemClass;
private final Object system;
private final Method groupsMethod;

protected UnixPlatform() {
Class sClass = null;
Object s = null;
Method g = null;
try {
sClass = Class.forName("com.sun.security.auth.module.UnixSystem");
s = sClass.getDeclaredConstructor().newInstance();
g = sClass.getDeclaredMethod("getGroups");
} catch (Exception e) {
throw new UnsupportedOperationException(e.getMessage(), e);
}

systemClass = sClass;
system = s;
groupsMethod = g;
}

@Override
public long[] getGroups(IRubyObject recv) {
if (groupsMethod == null)
throw recv.getRuntime().newNotImplementedError("groups() function is unimplemented on this platform");

try {
return (long[])groupsMethod.invoke(system);
} catch (Exception e) {
throw new UnsupportedOperationException("groups() function is unimplemented on this platform", e);
}
}
}
37 changes: 37 additions & 0 deletions core/src/main/java/org/jruby/platform/UnsupportedPlatform.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/***** BEGIN LICENSE BLOCK *****
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2014 Timur Duehr <tduehr@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/

package org.jruby.platform;

import org.jruby.runtime.builtin.IRubyObject;

public class UnsupportedPlatform extends Platform {
public long[] getGroups(IRubyObject recv) {
throw recv.getRuntime().newNotImplementedError("groups() function is unimplemented on this platform");
}
}