mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 06:32:10 +02:00
cleanup fragment supported IProcessList extension
This commit is contained in:
parent
4f7803089b
commit
f45c222418
7 changed files with 152 additions and 13 deletions
|
@ -1,15 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="/org.eclipse.core.resources"/>
|
||||
<classpathentry kind="src" path="/org.eclipse.ui"/>
|
||||
<classpathentry kind="src" path="/org.eclipse.cdt.core"/>
|
||||
<classpathentry kind="src" path="/org.eclipse.core.resources"/>
|
||||
<classpathentry kind="src" path="/org.eclipse.core.runtime"/>
|
||||
<classpathentry kind="src" path="/org.apache.xerces"/>
|
||||
<classpathentry kind="src" path="/org.eclipse.search"/>
|
||||
<classpathentry kind="src" path="/org.eclipse.compare"/>
|
||||
<classpathentry kind="src" path="/org.eclipse.debug.ui"/>
|
||||
<classpathentry kind="src" path="/org.eclipse.debug.core"/>
|
||||
<classpathentry kind="src" path="/org.eclipse.core.boot"/>
|
||||
<classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/>
|
||||
<classpathentry kind="output" path=""/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
1
core/org.eclipse.cdt.core.win32/.cvsignore
Normal file
1
core/org.eclipse.cdt.core.win32/.cvsignore
Normal file
|
@ -0,0 +1 @@
|
|||
bin
|
|
@ -10,9 +10,7 @@
|
|||
<project>org.eclipse.core.resources</project>
|
||||
<project>org.eclipse.core.runtime</project>
|
||||
<project>org.eclipse.debug.core</project>
|
||||
<project>org.eclipse.debug.ui</project>
|
||||
<project>org.eclipse.search</project>
|
||||
<project>org.eclipse.ui</project>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
bin.includes = fragment.xml,\
|
||||
os/
|
||||
os/,\
|
||||
*.jar
|
||||
source.cdt_win32.jar = src/
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<fragment
|
||||
id="org.eclipse.cdt.core.win32"
|
||||
name="Win32 Fragment"
|
||||
name="CDT Core Win32 Fragment"
|
||||
version="1.0.0"
|
||||
provider-name="Eclipse.org"
|
||||
plugin-id="org.eclipse.cdt.core"
|
||||
plugin-version="1.0.0">
|
||||
|
||||
<runtime>
|
||||
<library name="cdt_win32.jar"/>
|
||||
</runtime>
|
||||
|
||||
<requires>
|
||||
<import plugin="org.eclipse.core.resources"/>
|
||||
<import plugin="org.eclipse.ui"/>
|
||||
</requires>
|
||||
|
||||
|
||||
<extension
|
||||
point="org.eclipse.cdt.core.ProcessList">
|
||||
<processList
|
||||
class="org.eclipse.cdt.internal.core.win32.ProcessList">
|
||||
</processList>
|
||||
</extension>
|
||||
</fragment>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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()]);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue