1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

fixed bug#94702

This commit is contained in:
David Inglis 2005-06-14 14:39:43 +00:00
parent d8a971aedb
commit 2dc9421f24
2 changed files with 69 additions and 14 deletions

View file

@ -1,3 +1,9 @@
2005-06-14 David Inglis
Support for older cygpaths - bug # 94702
* utils/org/eclipse/cdt/utils/CygPath.java
2005-06-08 Alain Magloire 2005-06-08 Alain Magloire
Attempt to fix PR 97554 Attempt to fix PR 97554
* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java * model/org/eclipse/cdt/internal/core/model/PathEntryManager.java

View file

@ -10,7 +10,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.utils; package org.eclipse.cdt.utils;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.IOException; import java.io.IOException;
@ -18,18 +17,27 @@ import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import org.eclipse.cdt.utils.spawner.ProcessFactory; import org.eclipse.cdt.utils.spawner.ProcessFactory;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
public class CygPath { public class CygPath {
private Process cygpath;
private BufferedReader stdout;
private BufferedWriter stdin;
public CygPath(String command) throws IOException { boolean useOldCygPath = false;
private final Process cygpath;
private final BufferedReader stdout;
private final BufferedWriter stdin;
public CygPath(String command) throws IOException {
String[] args = {command, "--windows", "--file", "-"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ String[] args = {command, "--windows", "--file", "-"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
cygpath = ProcessFactory.getFactory().exec(args); cygpath = ProcessFactory.getFactory().exec(args);
//cppfilt = new Spawner(args);
stdin = new BufferedWriter(new OutputStreamWriter(cygpath.getOutputStream())); stdin = new BufferedWriter(new OutputStreamWriter(cygpath.getOutputStream()));
stdout = new BufferedReader(new InputStreamReader(cygpath.getInputStream())); stdout = new BufferedReader(new InputStreamReader(cygpath.getInputStream()));
try {
getFileName("test"); //$NON-NLS-1$ // test for older cygpath
} catch (IOException e) {
dispose();
useOldCygPath = true;
}
} }
public CygPath() throws IOException { public CygPath() throws IOException {
@ -37,23 +45,64 @@ public class CygPath {
} }
public String getFileName(String name) throws IOException { public String getFileName(String name) throws IOException {
if (useOldCygPath) {
return internalgetFileName(name);
}
stdin.write(name + "\n"); //$NON-NLS-1$ stdin.write(name + "\n"); //$NON-NLS-1$
stdin.flush(); stdin.flush();
String str = stdout.readLine(); String str = stdout.readLine();
if ( str != null ) { if (str != null) {
return str.trim(); return str.trim();
} }
throw new IOException(); throw new IOException();
} }
public void dispose() { public void dispose() {
try { if (!useOldCygPath) {
stdout.close(); try {
stdin.close(); stdout.close();
cygpath.getErrorStream().close(); stdin.close();
cygpath.getErrorStream().close();
} catch (IOException e) {
}
cygpath.destroy();
} }
catch (IOException e) {
}
cygpath.destroy();
} }
/**
* @param path
* @return
*/
private String internalgetFileName(String path) throws IOException {
Process cygPath = null;
BufferedReader reader = null;
try {
cygPath = ProcessFactory.getFactory().exec(new String[]{"cygpath", "-w", path}); //$NON-NLS-1$ //$NON-NLS-2$
reader = new BufferedReader(new InputStreamReader(cygPath.getInputStream()));
String newPath = reader.readLine();
IPath ipath;
if (path != null && !path.equals("")) { //$NON-NLS-1$
ipath = new Path(newPath);
} else {
ipath = new Path(path);
}
if (ipath.isAbsolute() && !ipath.toFile().exists() && ipath.segment(0).length() == 1) {
// look like it could be /c/... path
StringBuffer drive = new StringBuffer(ipath.segment(0));
drive.append(':');
ipath = ipath.removeFirstSegments(1);
ipath = ipath.makeAbsolute();
ipath = ipath.setDevice(drive.toString());
}
return ipath.toOSString();
} finally {
if (reader != null) {
reader.close();
}
if (cygPath != null) {
cygPath.destroy();
}
}
}
} }