/** * Executes the command utilizing the P4API. This method will be used only if the supporting Java * Native Interface library could be loaded. */ private synchronized void native_exec(String[] cmd) throws IOException { jni_proc = new P4JNI(); // P4JNI tmp = new P4JNI(); jni_proc.runCommand(jni_proc, cmd, environ); in = jni_proc.getReader(); err = in; out = jni_proc.getWriter(); }
/** Returns the next line from the process, or null if the command has completed its execution. */ public synchronized String readLine() { if (using_native && null != jni_proc && jni_proc.isPiped()) { return native_readLine(); } else { return pure_readLine(); } }
/** * Waits for the process to exit and closes out the process. This method should be called after * the {@link #exec(java.lang.String[]) exec} method in order to close things down properly. * * @param out The stream to which any errors should be sent. * @return The exit value of the underlying process. */ public synchronized int close(PrintStream out) throws IOException { if (using_native && null != jni_proc && jni_proc.isPiped()) { native_close(out); } else { pure_close(out); } /* * if (0 != exit_code) { throw new IOException("P4Process ERROR: p4 sync * exited with error ("+ exit_code+")"); } */ if (null != P4_ERROR) { throw new IOException(P4_ERROR); } return exit_code; }
/** * Executes a p4 command. This uses the class environment information to execute the p4 command * specified in the String array. This array contains all the command line arguments that will be * specified for execution, including "p4" in the first position. * * @param cmd Array of command line arguments ("p4" must be first). */ public synchronized void exec(String[] cmd) throws IOException { String[] pre_cmds = new String[12]; int i = 0; pre_cmds[i++] = cmd[0]; pre_cmds[i++] = "-s"; // Forces all commands to use stdout for message // reporting, no longer read stderr if (!getEnv().getPort().trim().equals("")) { pre_cmds[i++] = "-p"; pre_cmds[i++] = getEnv().getPort(); } if (!getEnv().getUser().trim().equals("")) { pre_cmds[i++] = "-u"; pre_cmds[i++] = getEnv().getUser(); } if (!getEnv().getClient().trim().equals("")) { pre_cmds[i++] = "-c"; pre_cmds[i++] = getEnv().getClient(); } if (!getEnv().getPassword().trim().equals("")) { pre_cmds[i++] = "-P"; pre_cmds[i++] = getEnv().getPassword(); } if (cmd[1].equals("-x")) { pre_cmds[i++] = "-x"; pre_cmds[i++] = cmd[2]; } new_cmd = new String[(i + cmd.length) - 1]; for (int j = 0; j < (i + cmd.length) - 1; j++) { if (j < i) { new_cmd[j] = pre_cmds[j]; } else { new_cmd[j] = cmd[(j - i) + 1]; } } Debug.verbose("P4Process.exec: ", new_cmd); if (P4JNI.isValid()) { native_exec(new_cmd); using_native = true; } else { pure_exec(new_cmd); using_native = false; } }