Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Inglis2002-09-18 09:49:43 -0400
committerDavid Inglis2002-09-18 09:49:43 -0400
commitf45c2224185cc9cf83e8e2f47cb1607f98918fb4 (patch)
tree966bba485f9208a44c5cce6da1c1b58444337cb7 /core/org.eclipse.cdt.core.win32/src
parent4f7803089b34208738f6684deab3f2738a18b554 (diff)
downloadorg.eclipse.cdt-f45c2224185cc9cf83e8e2f47cb1607f98918fb4.tar.gz
org.eclipse.cdt-f45c2224185cc9cf83e8e2f47cb1607f98918fb4.tar.xz
org.eclipse.cdt-f45c2224185cc9cf83e8e2f47cb1607f98918fb4.zip
cleanup fragment supported IProcessList extension
Diffstat (limited to 'core/org.eclipse.cdt.core.win32/src')
-rw-r--r--core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/ProcessInfo.java45
-rw-r--r--core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/ProcessList.java92
2 files changed, 137 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/ProcessInfo.java b/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/ProcessInfo.java
new file mode 100644
index 0000000000..13c88e07aa
--- /dev/null
+++ b/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/ProcessInfo.java
@@ -0,0 +1,45 @@
+package org.eclipse.cdt.internal.core.win32;
+
+import org.eclipse.cdt.core.IProcessInfo;
+
+/**
+ * @author alain
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class ProcessInfo implements IProcessInfo {
+
+ int pid;
+ String name;
+
+ public ProcessInfo(String pidString, String name) {
+ try {
+ pid = Integer.parseInt(pidString);
+ } catch (NumberFormatException e) {
+ }
+ this.name = name;
+ }
+
+ public ProcessInfo(int pid, String name) {
+ this.pid = pid;
+ this.name = name;
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.IProcessInfo#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.IProcessInfo#getPid()
+ */
+ public int getPid() {
+ return pid;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/ProcessList.java b/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/ProcessList.java
new file mode 100644
index 0000000000..eadeddc03e
--- /dev/null
+++ b/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/ProcessList.java
@@ -0,0 +1,92 @@
+package org.eclipse.cdt.internal.core.win32;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StreamTokenizer;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import org.eclipse.cdt.core.IProcessInfo;
+import org.eclipse.cdt.core.IProcessList;
+import org.eclipse.cdt.utils.spawner.ProcessFactory;
+
+/*
+ * Currently this will only work for Windows XP since tasklist
+ * is only shipped on XP. This could change to some JNI
+ * call out to get the list since the source to 'tlist' is
+ * on the msdn web site but that can be done later.
+ */
+
+public class ProcessList implements IProcessList {
+
+ private final int NAME = 1;
+ private final int PID = 2;
+ private final int OTHER = 3;
+
+ public IProcessInfo[] getProcessList() {
+ String OS = System.getProperty("os.name").toLowerCase();
+ Process p = null;
+ String command = null;
+ InputStream in = null;
+ if ((OS.indexOf("windows xp") > -1)) {
+ command = "tasklist /fo csv /nh /svc";
+ } else {
+ return new IProcessInfo[0];
+ }
+ try {
+ p = ProcessFactory.getFactory().exec(command);
+ }
+ catch (IOException e) {
+ return null;
+ }
+ in = p .getInputStream();
+ InputStreamReader reader = new InputStreamReader(in);
+ String line;
+ StreamTokenizer tokenizer = new StreamTokenizer(reader);
+ tokenizer.eolIsSignificant(true);
+ tokenizer.parseNumbers();
+ boolean done = false;
+ ArrayList processList = new ArrayList();
+ String name = null;
+ int pid = 0, token_state = NAME;
+ while( !done ) {
+ try {
+ switch ( tokenizer.nextToken() ) {
+ case StreamTokenizer.TT_EOL:
+ if ( name != null ) {
+ processList.add(new ProcessInfo(pid, name));
+ name = null;
+ }
+ break;
+ case StreamTokenizer.TT_EOF:
+ done = true;
+ break;
+ case '"':
+ switch ( token_state ) {
+ case NAME:
+ name = tokenizer.sval;
+ token_state = PID;
+ break;
+ case PID:
+ try {
+ pid = Integer.parseInt(tokenizer.sval);
+ } catch (NumberFormatException e ) {
+ name = null;
+ }
+ token_state = OTHER;
+ break;
+ case OTHER:
+ token_state = NAME;
+ break;
+ }
+ break;
+ }
+ }
+ catch (IOException e) {
+ }
+ }
+ return (IProcessInfo[]) processList.toArray(new IProcessInfo[processList.size()]);
+ }
+}

Back to the top