-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[build] java is no longer required in PATH
Windows machines do not include Java in their path by default, so it is a better experience to not require it for the build. Changes to make this happen: - A new `JavaPaths` MSBuild task that sets `JAVA_HOME`, and can return the path to `javac` or `jar` - The `JdkInfo` task has been changed to inherit from `JavaPaths` - Usage of java command line tools througout the build are making use of `JavaPaths` now
- Loading branch information
1 parent
bb808ad
commit 215d396
Showing
8 changed files
with
142 additions
and
65 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
84 changes: 84 additions & 0 deletions
84
build-tools/xa-prep-tasks/Xamarin.Android.BuildTools.PrepTasks/JavaPaths.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,84 @@ | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
using System; | ||
using System.IO; | ||
using Xamarin.Android.Build.Utilities; | ||
|
||
namespace Xamarin.Android.BuildTools.PrepTasks | ||
{ | ||
public class JavaPaths : Task | ||
{ | ||
public string AndroidNdkPath { get; set; } | ||
|
||
public string AndroidSdkPath { get; set; } | ||
|
||
public string JavaSdkPath { get; set; } | ||
|
||
[Output] | ||
public string JavaC { get; set; } | ||
|
||
[Output] | ||
public string Jar { get; set; } | ||
|
||
public override bool Execute () | ||
{ | ||
LogMessages (); | ||
|
||
AndroidLogger.Error += ErrorHandler; | ||
AndroidLogger.Warning += WarningHandler; | ||
AndroidLogger.Info += InfoHandler; | ||
try { | ||
AndroidSdk.Refresh (AndroidSdkPath, AndroidNdkPath, JavaSdkPath); | ||
|
||
var javaSdkPath = AndroidSdk.JavaSdkPath; | ||
if (string.IsNullOrEmpty (javaSdkPath)) { | ||
Log.LogError ("JavaSdkPath is blank"); | ||
return false; | ||
} | ||
|
||
Log.LogMessage (MessageImportance.Low, $" {nameof (AndroidSdk.JavaSdkPath)}: {javaSdkPath}"); | ||
|
||
return SetOutput (javaSdkPath); | ||
} finally { | ||
AndroidLogger.Error -= ErrorHandler; | ||
AndroidLogger.Warning -= WarningHandler; | ||
AndroidLogger.Info -= InfoHandler; | ||
} | ||
} | ||
|
||
protected virtual void LogMessages() | ||
{ | ||
Log.LogMessage (MessageImportance.Low, $"Task {nameof (JavaPaths)}"); | ||
Log.LogMessage (MessageImportance.Low, $" {nameof (AndroidNdkPath)}: {AndroidNdkPath}"); | ||
Log.LogMessage (MessageImportance.Low, $" {nameof (AndroidSdkPath)}: {AndroidSdkPath}"); | ||
Log.LogMessage (MessageImportance.Low, $" {nameof (JavaSdkPath)}: {JavaSdkPath}"); | ||
} | ||
|
||
protected virtual bool SetOutput(string javaSdkPath) | ||
{ | ||
Environment.SetEnvironmentVariable ("JAVA_HOME", javaSdkPath); | ||
|
||
var directories = new string [] { Path.Combine (javaSdkPath, "bin") }; | ||
string _; | ||
JavaC = Which.GetProgramLocation ("javac", out _, directories); | ||
Jar = Which.GetProgramLocation ("jar", out _, directories); | ||
|
||
return !Log.HasLoggedErrors; | ||
} | ||
|
||
private void ErrorHandler (string task, string message) | ||
{ | ||
Log.LogError ($"{task}: {message}"); | ||
} | ||
|
||
private void WarningHandler (string task, string message) | ||
{ | ||
Log.LogWarning ($"{task}: {message}"); | ||
} | ||
|
||
private void InfoHandler (string task, string message) | ||
{ | ||
Log.LogMessage (MessageImportance.Low, $"{task}: {message}"); | ||
} | ||
} | ||
} |
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