mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
task list fix
This commit is contained in:
parent
b9a6688e4a
commit
040970ff11
1 changed files with 4 additions and 65 deletions
|
@ -5,7 +5,6 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.StreamTokenizer;
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -14,6 +13,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.IProcessInfo;
|
import org.eclipse.cdt.core.IProcessInfo;
|
||||||
import org.eclipse.cdt.core.IProcessList;
|
import org.eclipse.cdt.core.IProcessList;
|
||||||
import org.eclipse.cdt.utils.spawner.ProcessFactory;
|
import org.eclipse.cdt.utils.spawner.ProcessFactory;
|
||||||
|
import org.eclipse.core.boot.BootLoader;
|
||||||
import org.eclipse.core.runtime.IPluginDescriptor;
|
import org.eclipse.core.runtime.IPluginDescriptor;
|
||||||
import org.eclipse.core.runtime.model.PluginDescriptorModel;
|
import org.eclipse.core.runtime.model.PluginDescriptorModel;
|
||||||
import org.eclipse.core.runtime.model.PluginFragmentModel;
|
import org.eclipse.core.runtime.model.PluginFragmentModel;
|
||||||
|
@ -28,25 +28,11 @@ import org.eclipse.core.runtime.model.PluginFragmentModel;
|
||||||
public class ProcessList implements IProcessList {
|
public class ProcessList implements IProcessList {
|
||||||
|
|
||||||
private IProcessInfo[] NOPROCESS = new IProcessInfo[0];
|
private IProcessInfo[] NOPROCESS = new IProcessInfo[0];
|
||||||
private final int NAME = 1;
|
|
||||||
private final int PID = 2;
|
|
||||||
private final int OTHER = 3;
|
|
||||||
|
|
||||||
public IProcessInfo[] getProcessList() {
|
public IProcessInfo[] getProcessList() {
|
||||||
String OS = System.getProperty("os.name").toLowerCase();
|
|
||||||
Process p = null;
|
Process p = null;
|
||||||
String command = null;
|
String command = null;
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
if ((OS.indexOf("windows xp") > -1)) {
|
|
||||||
command = "tasklist /fo csv /nh /svc";
|
|
||||||
try {
|
|
||||||
p = ProcessFactory.getFactory().exec(command);
|
|
||||||
in = p.getInputStream();
|
|
||||||
InputStreamReader reader = new InputStreamReader(in);
|
|
||||||
return parseTaskList(reader);
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
IPluginDescriptor desc = CCorePlugin.getDefault().getDescriptor();
|
IPluginDescriptor desc = CCorePlugin.getDefault().getDescriptor();
|
||||||
if (desc instanceof PluginDescriptorModel) {
|
if (desc instanceof PluginDescriptorModel) {
|
||||||
PluginDescriptorModel model = (PluginDescriptorModel) desc;
|
PluginDescriptorModel model = (PluginDescriptorModel) desc;
|
||||||
|
@ -54,8 +40,8 @@ public class ProcessList implements IProcessList {
|
||||||
for (int i = 0; i < fragments.length; i++) {
|
for (int i = 0; i < fragments.length; i++) {
|
||||||
String location = fragments[i].getLocation();
|
String location = fragments[i].getLocation();
|
||||||
try {
|
try {
|
||||||
URL url = new URL(location);
|
URL url = new URL(location + "/os/" + BootLoader.getOS() + "/" + BootLoader.getOSArch());
|
||||||
File path = new File(url.getFile(), "listtasks");
|
File path = new File(url.getFile(), "listtasks.exe");
|
||||||
if (path.exists()) {
|
if (path.exists()) {
|
||||||
command = path.getCanonicalPath();
|
command = path.getCanonicalPath();
|
||||||
break;
|
break;
|
||||||
|
@ -74,56 +60,9 @@ public class ProcessList implements IProcessList {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return NOPROCESS;
|
return NOPROCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IProcessInfo[] parseTaskList(InputStreamReader reader) {
|
|
||||||
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()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IProcessInfo[] parseListTasks(InputStreamReader reader) {
|
public IProcessInfo[] parseListTasks(InputStreamReader reader) {
|
||||||
BufferedReader br = new BufferedReader(reader);
|
BufferedReader br = new BufferedReader(reader);
|
||||||
ArrayList processList = new ArrayList();
|
ArrayList processList = new ArrayList();
|
||||||
|
|
Loading…
Add table
Reference in a new issue