Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Improve javac -version parsing (#1292)
Browse files Browse the repository at this point in the history
The [Ubuntu build][0] is [failing][1]:

	warning : Failed to get the Java SDK version as it does not appear to contain a valid version number.
	`javac -version` returned:
	```openjdk version "1.8.0_03-Ubuntu"
	OpenJDK Runtime Environment (build 1.8.0_03-Ubuntu-8u77-b03-3ubuntu3-b03)
	OpenJDK 64-Bit Server VM (build 25.03-b03, mixed mode)
	```
	...
	Task "AdjustJavacVersionArguments"
	  …/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/Xamarin.Android.Common.targets:
	  error : Error executing task AdjustJavacVersionArguments: Required property 'JdkVersion' not set.

[0]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android-linux/779/
[1]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android-linux/779/consoleText

This was introduced/broken by commit 0e1d1c8, which turned
`AdjustJavacVersionArguments.JdkVersion` into a `[Required]`
parameter. The value for `AdjustJavacVersionArguments.JdkVersion`
comes from the `<ResolveSdks/>` task `JdkVersion` output parameter,
which itself comes from parsing `javac -version` output.

The problem is that the regex we used to parse the output of
`javac -version` wasn't properly parsing the output on Ubuntu:

	openjdk version "1.8.0_03-Ubuntu"

Specifically, the `-Ubuntu` text was causing the regex to not match.

Update the regex to be a bit more lenient, enabling it to work with
the Ubuntu `javac -version` output, which *should* allow the build to
progress further.
  • Loading branch information
jonpryor authored Feb 12, 2018
1 parent 0114586 commit 0d822e2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public bool RunTask ()
// `java -version` will produce values such as:
// java version "9.0.4"
// java version "1.8.0_77"
static readonly Regex javaVersionRegex = new Regex (@"version ""(?<version>[\d\.]+)(_\d+)?""");
static readonly Regex javaVersionRegex = new Regex (@"version ""(?<version>[\d\.]+)(_d+)?[^""]*""");

Version GetJavaVersionForFramework (string targetFrameworkVersion)
{
Expand Down

0 comments on commit 0d822e2

Please sign in to comment.