Skip to content

Commit 7553056

Browse files
bratschejonpryor
authored andcommitted
[unix] Use JdkInfo to fetch the JDK path (#33)
Fixes: http://work.devdiv.io/646086 Fixes: http://work.devdiv.io/652760 Context: https://paper.dropbox.com/doc/OpenJDK-and-You--AH1yWKdVXgno~uXYfmcUAZTwAg-NoECAe2XkBQeoxFfGL6ea Update `AndroidSdkInfo.JavaSdkPath` so that it now uses `JdkInfo.GetKnownSystemJdkInfos()` to determine the JDK path to use, instead of separately reading from `monodroid-config.xml` or probing `$PATH` for `jarsigner`.
1 parent cb461cb commit 7553056

File tree

1 file changed

+4
-34
lines changed

1 file changed

+4
-34
lines changed

src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkUnix.cs

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Collections.Generic;
34
using System.Diagnostics;
45
using System.IO;
@@ -108,46 +109,15 @@ protected override IEnumerable<string> GetAllAvailableAndroidSdks ()
108109

109110
protected override string GetJavaSdkPath ()
110111
{
111-
var preferedJavaSdkPath = PreferedJavaSdkPath;
112-
if (!string.IsNullOrEmpty (preferedJavaSdkPath))
113-
return preferedJavaSdkPath;
114-
115-
// Look in PATH
116-
foreach (var path in ProcessUtils.FindExecutablesInPath (JarSigner)) {
117-
// Strip off "bin"
118-
var dir = Path.GetDirectoryName (path);
119-
120-
if (ValidateJavaSdkLocation (dir))
121-
return dir;
122-
}
123-
124-
return null;
112+
return JdkInfo.GetKnownSystemJdkInfos (Logger).FirstOrDefault ()?.HomePath;
125113
}
126114

127-
public override bool ValidateJavaSdkLocation (string loc)
115+
public override bool ValidateJavaSdkLocation (string loc)
128116
{
129117
var result = base.ValidateJavaSdkLocation (loc);
130118

131119
if (result) {
132-
// handle apple's java stub
133-
const string javaHomeExe = "/usr/libexec/java_home";
134-
135-
if (File.Exists (javaHomeExe)) {
136-
// returns true if there is a java installed
137-
var javaHomeTask = ProcessUtils.ExecuteToolAsync<bool> (javaHomeExe,
138-
(output) => {
139-
if (output.Contains ("(null)")) {
140-
return false;
141-
}
142-
143-
return true;
144-
}, System.Threading.CancellationToken.None
145-
);
146-
147-
if (!javaHomeTask.Result) {
148-
return false;
149-
}
150-
}
120+
return File.Exists (Path.Combine (loc, "bin", "javac"));
151121
}
152122

153123
return result;

0 commit comments

Comments
 (0)