Lines 42-47
Link Here
|
42 |
|
42 |
|
43 |
package org.netbeans.modules.cnd.remote.support; |
43 |
package org.netbeans.modules.cnd.remote.support; |
44 |
|
44 |
|
|
|
45 |
import java.io.IOException; |
45 |
import java.util.LinkedHashMap; |
46 |
import java.util.LinkedHashMap; |
46 |
import java.util.Map; |
47 |
import java.util.Map; |
47 |
import java.util.logging.Level; |
48 |
import java.util.logging.Level; |
Lines 55-62
Link Here
|
55 |
import org.netbeans.modules.cnd.utils.CndUtils; |
56 |
import org.netbeans.modules.cnd.utils.CndUtils; |
56 |
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment; |
57 |
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment; |
57 |
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory; |
58 |
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory; |
|
|
59 |
import org.netbeans.modules.nativeexecution.api.HostInfo; |
60 |
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager.CancellationException; |
61 |
import org.netbeans.modules.nativeexecution.api.util.HostInfoUtils; |
58 |
import org.netbeans.modules.nativeexecution.api.util.ProcessUtils; |
62 |
import org.netbeans.modules.nativeexecution.api.util.ProcessUtils; |
59 |
import org.netbeans.modules.nativeexecution.api.util.ProcessUtils.ExitStatus; |
63 |
import org.netbeans.modules.nativeexecution.api.util.ProcessUtils.ExitStatus; |
|
|
64 |
import org.openide.util.Exceptions; |
60 |
|
65 |
|
61 |
/** |
66 |
/** |
62 |
* Misc. utiliy finctions |
67 |
* Misc. utiliy finctions |
Lines 98-133
Link Here
|
98 |
* NB: this is a LONG RUNNING method - never call from UI thread |
103 |
* NB: this is a LONG RUNNING method - never call from UI thread |
99 |
*/ |
104 |
*/ |
100 |
public static String getHomeDirectory(ExecutionEnvironment execEnv) { |
105 |
public static String getHomeDirectory(ExecutionEnvironment execEnv) { |
101 |
CndUtils.assertNonUiThread(); |
106 |
HostInfo hostInfo = null; |
102 |
String dir = null; |
107 |
|
103 |
// it isn't worth doing smart synchronization here |
108 |
try { |
104 |
synchronized(homeDirs) { |
109 |
hostInfo = HostInfoUtils.getHostInfo(execEnv); |
105 |
// we cache nulls as well |
110 |
} catch (IOException ex) { |
106 |
if (homeDirs.containsKey(execEnv)) { |
111 |
} catch (CancellationException ex) { |
107 |
return homeDirs.get(execEnv); |
|
|
108 |
} |
109 |
} |
112 |
} |
110 |
try { // FIXUP: remove this try/catch as soon as in NPE in execution is fixed |
113 |
|
111 |
if (Boolean.getBoolean("cnd.emulate.null.home.dir")) { // to emulate returning null //NOI18N |
114 |
return hostInfo == null ? null : hostInfo.getUserDir(); |
112 |
return null; |
|
|
113 |
} |
114 |
// NB: it's important that /bin/pwd is called since it always reports resolved path |
115 |
// while shell's pwd result depend on shell |
116 |
ExitStatus res = ProcessUtils.execute(execEnv, "sh", "-c", "cd; /bin/pwd"); // NOI18N |
117 |
if (res.isOK()) { |
118 |
String s = res.output; |
119 |
if (HostInfoProvider.fileExists(execEnv, s)) { |
120 |
dir = s; |
121 |
} |
122 |
} |
123 |
} catch (Exception e) { |
124 |
e.printStackTrace(); |
125 |
} |
126 |
synchronized(homeDirs) { |
127 |
// we cache nulls as well |
128 |
homeDirs.put(execEnv, dir); |
129 |
} |
130 |
return dir; |
131 |
} |
115 |
} |
132 |
|
116 |
|
133 |
/** |
117 |
/** |