forked from jruby/jruby
/
JRubyPOSIXHandler.java
88 lines (71 loc) · 2.35 KB
/
JRubyPOSIXHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package org.jruby.ext;
import java.io.File;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.jruby.Ruby;
import org.jruby.RubyHash;
import org.jruby.common.IRubyWarnings.ID;
import org.jruby.ext.posix.POSIXHandler;
import org.jruby.ext.posix.POSIX.ERRORS;
public class JRubyPOSIXHandler implements POSIXHandler {
Ruby runtime;
private boolean isVerbose;
public JRubyPOSIXHandler(Ruby runtime) {
this.runtime = runtime;
isVerbose = false;
try {
isVerbose = Boolean.getBoolean("jruby.native.verbose");
} catch (SecurityException e) {
}
}
public void error(ERRORS error, String extraData) {
switch (error) {
case ENOENT:
throw runtime.newErrnoENOENTError("No such file or directory - " + extraData);
}
}
public void unimplementedError(String method) {
throw runtime.newNotImplementedError(method + " unsupported on this platform");
}
public void warn(WARNING_ID id, String message, Object... data) {
ID ourID;
if (id == WARNING_ID.DUMMY_VALUE_USED) {
ourID = ID.DUMMY_VALUE_USED;
} else {
ourID = ID.MISCELLANEOUS;
}
runtime.getWarnings().warn(ourID, message, data);
}
public boolean isVerbose() {
return isVerbose;
}
public File getCurrentWorkingDirectory() {
return new File(runtime.getCurrentDirectory());
}
@SuppressWarnings("unchecked")
public String[] getEnv() {
RubyHash hash = (RubyHash) runtime.getObject().fastGetConstant("ENV");
int i=0;
String[] env = new String[hash.size()];
for (Iterator<Entry<Object, Object>> iter = hash.directEntrySet().iterator(); iter.hasNext(); i++) {
Map.Entry<Object, Object> entry = iter.next();
env[i] = entry.getKey().toString() + "=" + entry.getValue().toString();
}
return env;
}
public PrintStream getErrorStream() {
return runtime.getErrorStream();
}
public InputStream getInputStream() {
return runtime.getInputStream();
}
public int getPID() {
return runtime.hashCode();
}
public PrintStream getOutputStream() {
return runtime.getOutputStream();
}
}