-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Java.Interop.BootstrapTasks] Use JdkInfo
Context: xamarin/xamarin-android-tools#29 (comment) Bumps to xamarin/xamarin-android-tools:master@75530565 The `<JdkInfo/>` task within `Java.Interop.BootstrapTasks.dll` isn't the *only* thing that needs to determine the path of an installed JDK. The IDEs could also use such functionality, as could xamarin-android. Add a submodule reference to xamarin-android-tools, and use `Xamarin.Android.Tools.JdkInfo` to find the preferred JDK, instead of having lots of custom probing with the `<JdkInfo/>` task. Finally, for consistency, move `src/Java.Interop.BootstrapTasks` to `build-tools/Java.Interop.BootstrapTasks`, as the `Java.Interop.BootstrapTasks.dll` assembly is only intended for in building Java.Interop *itself*, and not for "downlevel" distribution.
- Loading branch information
Showing
13 changed files
with
159 additions
and
627 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
122 changes: 122 additions & 0 deletions
122
build-tools/Java.Interop.BootstrapTasks/Java.Interop.BootstrapTasks/JdkInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Xml.Linq; | ||
|
||
using Xamarin.Android.Tools; | ||
|
||
using XATInfo = Xamarin.Android.Tools.JdkInfo; | ||
|
||
namespace Java.Interop.BootstrapTasks | ||
{ | ||
public class JdkInfo : Task | ||
{ | ||
const string JARSIGNER = "jarsigner.exe"; | ||
const string MDREG_KEY = @"SOFTWARE\Novell\Mono for Android"; | ||
const string MDREG_JAVA_SDK = "JavaSdkDirectory"; | ||
|
||
public string JdksRoot { get; set; } | ||
|
||
public string MaximumJdkVersion { get; set; } | ||
|
||
static Regex VersionExtractor = new Regex (@"(?<version>[\d]+(\.\d+)+)", RegexOptions.Compiled); | ||
|
||
[Required] | ||
public ITaskItem PropertyFile { get; set; } | ||
|
||
[Required] | ||
public ITaskItem MakeFragmentFile { get; set; } | ||
|
||
[Output] | ||
public string JavaHomePath { get; set; } | ||
|
||
public override bool Execute () | ||
{ | ||
var maxVersion = GetVersion (MaximumJdkVersion); | ||
|
||
XATInfo jdk = XATInfo.GetKnownSystemJdkInfos (CreateLogger ()) | ||
.Where (j => maxVersion != null ? j.Version <= maxVersion : true) | ||
.FirstOrDefault (); | ||
|
||
if (jdk == null) { | ||
Log.LogError ("Could not determine JAVA_HOME location. Please set JdksRoot or export the JAVA_HOME environment variable."); | ||
return false; | ||
} | ||
|
||
JavaHomePath = jdk.HomePath; | ||
|
||
Directory.CreateDirectory (Path.GetDirectoryName (PropertyFile.ItemSpec)); | ||
Directory.CreateDirectory (Path.GetDirectoryName (MakeFragmentFile.ItemSpec)); | ||
|
||
WritePropertyFile (jdk.JarPath, jdk.JavacPath, jdk.JdkJvmPath, jdk.IncludePath); | ||
WriteMakeFragmentFile (jdk.JarPath, jdk.JavacPath, jdk.JdkJvmPath, jdk.IncludePath); | ||
|
||
return !Log.HasLoggedErrors; | ||
} | ||
|
||
Version GetVersion (string value) | ||
{ | ||
if (string.IsNullOrEmpty (value)) | ||
return null; | ||
if (!value.Contains (".")) { | ||
value += ".0"; | ||
} | ||
Version v; | ||
if (Version.TryParse (value, out v)) | ||
return v; | ||
return null; | ||
} | ||
|
||
Action<TraceLevel, string> CreateLogger () | ||
{ | ||
Action<TraceLevel, string> logger = (level, value) => { | ||
switch (level) { | ||
case TraceLevel.Error: | ||
Log.LogError ("{0}", value); | ||
break; | ||
case TraceLevel.Warning: | ||
Log.LogWarning ("{0}", value); | ||
break; | ||
default: | ||
Log.LogMessage (MessageImportance.Low, "{0}", value); | ||
break; | ||
} | ||
}; | ||
return logger; | ||
} | ||
|
||
void WritePropertyFile (string jarPath, string javacPath, string jdkJvmPath, IEnumerable<string> includes) | ||
{ | ||
var msbuild = XNamespace.Get ("http://schemas.microsoft.com/developer/msbuild/2003"); | ||
var project = new XElement (msbuild + "Project", | ||
new XElement (msbuild + "Choose", | ||
new XElement (msbuild + "When", new XAttribute ("Condition", " '$(JdkJvmPath)' == '' "), | ||
new XElement (msbuild + "PropertyGroup", | ||
new XElement (msbuild + "JdkJvmPath", jdkJvmPath)), | ||
new XElement (msbuild + "ItemGroup", | ||
includes.Select (i => new XElement (msbuild + "JdkIncludePath", new XAttribute ("Include", i)))))), | ||
new XElement (msbuild + "PropertyGroup", | ||
new XElement (msbuild + "JavaCPath", new XAttribute ("Condition", " '$(JavaCPath)' == '' "), | ||
javacPath), | ||
new XElement (msbuild + "JarPath", new XAttribute ("Condition", " '$(JarPath)' == '' "), | ||
jarPath))); | ||
project.Save (PropertyFile.ItemSpec); | ||
} | ||
|
||
void WriteMakeFragmentFile (string jarPath, string javacPath, string jdkJvmPath, IEnumerable<string> includes) | ||
{ | ||
using (var o = new StreamWriter (MakeFragmentFile.ItemSpec)) { | ||
o.WriteLine ($"export JI_JAR_PATH := {jarPath}"); | ||
o.WriteLine ($"export JI_JAVAC_PATH := {javacPath}"); | ||
o.WriteLine ($"export JI_JDK_INCLUDE_PATHS := {string.Join (" ", includes)}"); | ||
o.WriteLine ($"export JI_JVM_PATH := {jdkJvmPath}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Submodule xamarin-android-tools
added at
755305
Oops, something went wrong.