File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\os\PosixAPI.java.html

1 package hudson.os;
2
3 import org.jruby.ext.posix.JavaPOSIX;
4 import org.jruby.ext.posix.POSIX;
5 import org.jruby.ext.posix.POSIXFactory;
6 import org.jruby.ext.posix.POSIXHandler;
7 import org.jruby.ext.posix.POSIX.ERRORS;
8
9 import java.io.File;
10 import java.io.InputStream;
11 import java.io.PrintStream;
12 import java.util.Map;
13 import java.util.logging.Logger;
14
15 /**
16 * POSIX API wrapper.
17 *
18 * @author Kohsuke Kawaguchi
19 */
20 public class PosixAPI {
21 public static POSIX get() {
22 return posix;
23 }
24
25 /**
26 * @deprecated as of 1.448
27 * Use {@link #supportsNative()}.
28 */
29 public boolean isNative() {
30 return supportsNative();
31 }
32
33 /**
34 * Determine if the jna-posix library could not provide native support, and
35 * used a fallback java implementation which does not support many operations.
36 */
37 public static boolean supportsNative() {
38 return !(posix instanceof JavaPOSIX);
39 }
40
41 private static final POSIX posix = POSIXFactory.getPOSIX(new POSIXHandler() {
42 public void error(ERRORS errors, String s) {
43 throw new PosixException(s,errors);
44 }
45
46 public void unimplementedError(String s) {
47 throw new UnsupportedOperationException(s);
48 }
49
50 public void warn(WARNING_ID warning_id, String s, Object... objects) {
51 LOGGER.fine(s);
52 }
53
54 public boolean isVerbose() {
55 return true;
56 }
57
58 public File getCurrentWorkingDirectory() {
59 return new File(".").getAbsoluteFile();
60 }
61
62 public String[] getEnv() {
63 Map<String,String> envs = System.getenv();
64 String[] envp = new String[envs.size()];
65
66 int i = 0;
67 for (Map.Entry<String,String> e : envs.entrySet()) {
68 envp[i++] = e.getKey()+'+'+e.getValue();
69 }
70 return envp;
71 }
72
73 public InputStream getInputStream() {
74 return System.in;
75 }
76
77 public PrintStream getOutputStream() {
78 return System.out;
79 }
80
81 public int getPID() {
82 // TODO
83 return 0;
84 }
85
86 public PrintStream getErrorStream() {
87 return System.err;
88 }
89 }, true);
90
91 private static final Logger LOGGER = Logger.getLogger(PosixAPI.class.getName());
92 }
93