本文整理匯總了Java中org.netbeans.modules.nativeexecution.api.NativeProcess類的典型用法代碼示例。如果您正苦於以下問題:Java NativeProcess類的具體用法?Java NativeProcess怎麽用?Java NativeProcess使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
NativeProcess類屬於org.netbeans.modules.nativeexecution.api包,在下文中一共展示了NativeProcess類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: propertyChange
import org.netbeans.modules.nativeexecution.api.NativeProcess; //導入依賴的package包/類
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (IOVisibility.PROP_VISIBILITY.equals(evt.getPropertyName()) && Boolean.FALSE.equals(evt.getNewValue())) {
if (destroyed.compareAndSet(false, true)) {
// term is closing => destroy process
final NativeProcess proc = processRef.get();
if (proc != null) {
RP.submit(new Runnable() {
@Override
public void run() {
try {
proc.destroy();
} catch (Throwable th) {
}
}
});
}
}
}
}
示例2: stateChanged
import org.netbeans.modules.nativeexecution.api.NativeProcess; //導入依賴的package包/類
@Override
public void stateChanged(ChangeEvent e) {
if (!(e instanceof NativeProcessChangeEvent)) {
return;
}
final NativeProcessChangeEvent event = (NativeProcessChangeEvent) e;
processRef.compareAndSet(null, (NativeProcess) event.getSource());
switch (event.state) {
case RUNNING:
case ERROR:
startTimeMillis = System.currentTimeMillis();
break;
}
}
示例3: getPostStatusString
import org.netbeans.modules.nativeexecution.api.NativeProcess; //導入依賴的package包/類
@Override
public String getPostStatusString(NativeProcess process) {
ProcessStatusEx exitStatusEx = process.getExitStatusEx();
if (exitStatusEx != null) {
return NbBundle.getMessage(PostMessageDisplayer.class, "MSG_FINISHED", actionName); // NOI18N
}
State state = process.getState();
switch (state) {
case ERROR:
return NbBundle.getMessage(PostMessageDisplayer.class, "MSG_FAILED", actionName); // NOI18N
case CANCELLED:
return NbBundle.getMessage(PostMessageDisplayer.class, "MSG_TERMINATED", actionName); // NOI18N
case FINISHED:
if (process.exitValue() == 0) {
return NbBundle.getMessage(PostMessageDisplayer.class, "MSG_SUCCESSFUL", actionName);
} else {
return NbBundle.getMessage(PostMessageDisplayer.class, "MSG_FAILED", actionName);
}
default:
// should not happen
return ""; // NOI18N
}
}
示例4: outPostMessage
import org.netbeans.modules.nativeexecution.api.NativeProcess; //導入依賴的package包/類
@Override
public void outPostMessage(InputOutput io, NativeProcess process, long time) {
Color color;
if (process.getState() == State.ERROR) {
color = Colors.getColorError(io);
} else {
color = process.exitValue() == 0
? Colors.getColorSuccess(io)
: Colors.getColorFailure(io);
}
try {
IOColorLines.println(io, "\r", Color.BLACK); // NOI18N
IOColorLines.println(io, getPostMessage(process, time) + "\r", color); // NOI18N
} catch (IOException ex) {
}
}
示例5: getPID
import org.netbeans.modules.nativeexecution.api.NativeProcess; //導入依賴的package包/類
private static int getPID(Process process) {
int pid = -1;
try {
if (process instanceof NativeProcess) {
pid = ((NativeProcess) process).getPID();
} else {
String className = process.getClass().getName();
// TODO: windows?...
if ("java.lang.UNIXProcess".equals(className)) { // NOI18N
Field f = process.getClass().getDeclaredField("pid"); // NOI18N
f.setAccessible(true);
pid = f.getInt(process);
}
}
} catch (Throwable e) {
org.netbeans.modules.nativeexecution.support.Logger.getInstance().log(Level.FINE, e.getMessage(), e);
}
return pid;
}
示例6: doTestDestroyInfiniteTasks
import org.netbeans.modules.nativeexecution.api.NativeProcess; //導入依賴的package包/類
public void doTestDestroyInfiniteTasks(final ExecutionEnvironment execEnv) throws Exception {
System.out.println("==== [email protected]" + execEnv.getDisplayName() + " STARTED ===="); // NOI18N
ConnectionManager.getInstance().connectTo(execEnv);
final BlockingQueue<NativeProcess> processQueue = new LinkedBlockingQueue<>();
final Counters counters = new Counters();
int count = 20;
final TaskFactory infiniteTaskFactory = new TaskFactory() {
@Override
public Runnable newTask() {
return new InfiniteTask(execEnv, counters, processQueue);
}
};
performDestroyTest(execEnv, count, infiniteTaskFactory, counters, processQueue);
System.out.println("==== [email protected]" + execEnv.getDisplayName() + " counters ===="); // NOI18N
counters.dump(System.out);
System.out.println("============"); // NOI18N
assertEquals(count, counters.getCounter("Started").get()); // NOI18N
assertEquals(count, counters.getCounter("Killed").get()); // NOI18N
assertEquals(count, counters.getCounter("Finished").get()); // NOI18N
assertEquals(count, counters.getCounter("State == " + State.CANCELLED.name()).get());
System.out.println("==== [email protected]" + execEnv.getDisplayName() + " DONE ===="); // NOI18N
}
示例7: _testShellCommandProcess
import org.netbeans.modules.nativeexecution.api.NativeProcess; //導入依賴的package包/類
public void _testShellCommandProcess() throws Exception {
NativeProcessBuilder npb = NativeProcessBuilder.newLocalProcessBuilder();
npb.setCommandLine("echo $$ && (echo \"TEST\" | sed 's/E/O/')");
NativeProcess process = npb.call();
int rc = process.waitFor();
String error = ProcessUtils.readProcessErrorLine(process);
System.out.println(error);
assertEquals("echo $$ exit status", 0, rc);
List<String> output = ProcessUtils.readProcessOutput(process);
int pid = Integer.parseInt(output.get(0));
assertEquals("shell pid", pid, process.getPID());
assertEquals("TOST", output.get(1));
}
示例8: propertyChange
import org.netbeans.modules.nativeexecution.api.NativeProcess; //導入依賴的package包/類
@Override
public void propertyChange(PropertyChangeEvent evt) {
if ("IOVisibility.PROP_VISIBILITY".equals(evt.getPropertyName()) && Boolean.FALSE.equals(evt.getNewValue())) {
if (destroyed.compareAndSet(false, true)) {
final NativeProcess proc = processRef.get();
if (proc != null) {
RP.submit(new Runnable() {
@Override
public void run() {
try {
proc.destroy();
} catch (Throwable th) {
}
}
});
}
}
}
}
示例9: run
import org.netbeans.modules.nativeexecution.api.NativeProcess; //導入依賴的package包/類
@Override
public void run() {
if (outputListener != null) {
try {
outputListener.flush();
outputListener.close();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
outputListener = null;
}
NativeProcess process = processRef.get();
if (process != null && listener != null) {
listener.executionFinished(process.exitValue());
}
}
示例10: stateChanged
import org.netbeans.modules.nativeexecution.api.NativeProcess; //導入依賴的package包/類
@Override
public void stateChanged(ChangeEvent e) {
NativeProcess process = processRef.get();
if (process == null && e.getSource() instanceof NativeProcess) {
processRef.compareAndSet(null, (NativeProcess) e.getSource());
}
}
示例11: getPostMessage
import org.netbeans.modules.nativeexecution.api.NativeProcess; //導入依賴的package包/類
@Override
public String getPostMessage(NativeProcess process, long time) {
State state = process.getState();
StringBuilder res = new StringBuilder();
ProcessStatusEx statusEx = process.getExitStatusEx();
int status = process.exitValue();
if (statusEx != null) {
if (state == State.ERROR) {
return NbBundle.getMessage(PostMessageDisplayer.class, "FAILED", actionName.toUpperCase()); // NOI18N
}
res.append(NbBundle.getMessage(PostMessageDisplayer.class, "FINISHED", actionName.toUpperCase())); // NOI18N
res.append("; "); // NOI18N
if (statusEx.ifExited()) {
res.append(NbBundle.getMessage(PostMessageDisplayer.class, "EXIT_VALUE", statusEx.getExitCode())); // NOI18N
} else {
res.append(statusEx.termSignal());
if (statusEx.ifCoreDump()) {
res.append("; "); // NOI18N
res.append(NbBundle.getMessage(PostMessageDisplayer.class, "COREDUMPED")); // NOI18N
}
}
res.append("; "); // NOI18N
res.append(NbBundle.getMessage(PostMessageDisplayer.class, "TOTAL_TIME_EX", // NOI18N
formatTime(statusEx.realTime(TimeUnit.MILLISECONDS)),
formatTime(statusEx.sysTime(TimeUnit.MILLISECONDS)),
formatTime(statusEx.usrTime(TimeUnit.MILLISECONDS))));
return res.toString();
}
return getPostMessage(state, status, time);
}
示例12: getCharset
import org.netbeans.modules.nativeexecution.api.NativeProcess; //導入依賴的package包/類
public static String getCharset(NativeProcess process) {
String res = null;
if (process instanceof AbstractNativeProcess) {
res = ((AbstractNativeProcess) process).getCharset();
}
return res == null ? DEFAULT_CHARSET : res;
}
示例13: createProcess
import org.netbeans.modules.nativeexecution.api.NativeProcess; //導入依賴的package包/類
@Override
public Process createProcess(String... arguments) throws IOException {
assertNotNull(remoteScriptPath);
final ExecutionEnvironment env = getTestExecutionEnvironment();
NativeProcessBuilder pb = NativeProcessBuilder.newProcessBuilder(env);
pb.setExecutable(remoteScriptPath);
pb.setArguments(arguments);
NativeProcess process = pb.call();
return process;
}
示例14: doTestExecAndWaitTasks
import org.netbeans.modules.nativeexecution.api.NativeProcess; //導入依賴的package包/類
public void doTestExecAndWaitTasks(final ExecutionEnvironment execEnv) throws Exception {
System.out.println("==== [email protected]" + execEnv.getDisplayName() + " STARTED ===="); // NOI18N
final BlockingQueue<NativeProcess> processQueue = new LinkedBlockingQueue<>();
final Counters counters = new Counters();
int count = 5;
final TaskFactory shortTasksFactory = new TaskFactory() {
@Override
public Runnable newTask() {
return new ShortTask(execEnv, counters, processQueue);
}
};
final TaskFactory longTasksFactory = new TaskFactory() {
@Override
public Runnable newTask() {
return new LongTask(execEnv, counters, processQueue);
}
};
ConcurrentTasksSupport startSupport = new ConcurrentTasksSupport(count);
startSupport.addFactory(shortTasksFactory);
startSupport.addFactory(longTasksFactory);
startSupport.init();
startSupport.start();
startSupport.waitCompletion();
System.out.println("==== [email protected]" + execEnv.getDisplayName() + " counters ===="); // NOI18N
counters.dump(System.out);
System.out.println("============"); // NOI18N
assertEquals(count, counters.getCounter("Started").get()); // NOI18N
assertEquals(count, counters.getCounter("Done").get()); // NOI18N
assertEquals(count, counters.getCounter("CorrectOutput").get()); // NOI18N
System.out.println("==== [email protected]" + execEnv.getDisplayName() + " DONE ===="); // NOI18N
}
示例15: testNonexistentProcess
import org.netbeans.modules.nativeexecution.api.NativeProcess; //導入依賴的package包/類
@org.junit.Test
public void testNonexistentProcess() throws Exception {
NativeProcessBuilder npb = NativeProcessBuilder.newLocalProcessBuilder();
npb.setExecutable("wrong-process");
NativeProcess process = npb.call();
int rc = process.waitFor();
assertTrue("wrong-process exit status != 0", rc != 0);
String error = ProcessUtils.readProcessErrorLine(process);
System.out.println(error);
}