diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 39e3006d74d..494e2c118cc 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -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 Attempt to fix PR 97554 * model/org/eclipse/cdt/internal/core/model/PathEntryManager.java diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/CygPath.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/CygPath.java index e1152235909..b6345fb666f 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/CygPath.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/CygPath.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.cdt.utils; - import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; @@ -18,18 +17,27 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import org.eclipse.cdt.utils.spawner.ProcessFactory; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; 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$ cygpath = ProcessFactory.getFactory().exec(args); - //cppfilt = new Spawner(args); stdin = new BufferedWriter(new OutputStreamWriter(cygpath.getOutputStream())); 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 { @@ -37,23 +45,64 @@ public class CygPath { } public String getFileName(String name) throws IOException { + if (useOldCygPath) { + return internalgetFileName(name); + } stdin.write(name + "\n"); //$NON-NLS-1$ stdin.flush(); String str = stdout.readLine(); - if ( str != null ) { + if (str != null) { return str.trim(); } throw new IOException(); } public void dispose() { - try { - stdout.close(); - stdin.close(); - cygpath.getErrorStream().close(); + if (!useOldCygPath) { + try { + stdout.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(); + } + } + } + }