2 * Copyright (C) 2008 Shawn Pearce <spearce@spearce.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License, version 2, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17 package org
.spearce
.jgit
.util
;
19 import java
.io
.BufferedReader
;
21 import java
.io
.IOException
;
22 import java
.io
.InputStreamReader
;
23 import java
.security
.AccessController
;
24 import java
.security
.PrivilegedAction
;
26 class FS_Win32_Cygwin
extends FS_Win32
{
27 private static String cygpath
;
29 static boolean detect() {
30 final String path
= AccessController
31 .doPrivileged(new PrivilegedAction
<String
>() {
33 return System
.getProperty("java.library.path");
38 for (final String p
: path
.split(";")) {
39 final File e
= new File(p
, "cygpath.exe");
41 cygpath
= e
.getAbsolutePath();
48 protected File
resolveImpl(final File dir
, final String pn
) {
52 p
= Runtime
.getRuntime().exec(
53 new String
[] { cygpath
, "--windows", "--absolute", pn
},
55 p
.getOutputStream().close();
57 final BufferedReader lineRead
= new BufferedReader(
58 new InputStreamReader(p
.getInputStream(), "UTF-8"));
61 r
= lineRead
.readLine();
68 if (p
.waitFor() == 0 && r
!= null && r
.length() > 0)
71 } catch (InterruptedException ie
) {
72 // Stop bothering me, I have a zombie to reap.
75 } catch (IOException ioe
) {
76 // Fall through and use the default return.
79 return super.resolveImpl(dir
, pn
);
83 protected File
userHomeImpl() {
84 final String home
= AccessController
85 .doPrivileged(new PrivilegedAction
<String
>() {
87 return System
.getenv("HOME");
90 if (home
== null || home
.length() == 0)
91 return super.userHomeImpl();
92 return resolveImpl(new File("."), home
);