Skip to content

Commit 002dea4

Browse files
authored
Bump to xamarin/xamarin-android-tools/main@d92fc3e3 (#823)
Context: https://developercommunity.visualstudio.com/t/illegal-character-exception-in-xamarinandroid-afte/1363149 Changes: dotnet/android-tools@554d45a...d92fc3e * dotnet/android-tools@d92fc3e: [Xamarin.Android.Tools.AndroidSdk] Probe for AdoptOpenJDK Locations (#115) * dotnet/android-tools@dca30d9: [Xamarin.Android.Tools.AndroidSdk] Probe for Zulu JDK (#114) * dotnet/android-tools@237642c: [Xamarin.Android.Tools.AndroidSdk] Probe for Microsoft OpenJDK dirs (#113) * dotnet/android-tools@e618e00: [Xamarin.Android.Tools.AndroidSdk] Fix quotes in %PATH% or %PATHEXT% (#112) Finally, *prefer* JDK 8, as hilarious as that is, for two reasons: 1. `gradlew` fails to execute when running under OpenJDK 14: [ERROR] [system.err] java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7 2. The unit tests added in 69e1b80 currently depend upon the XML formatting conventions of JDK 8, and the tests fail when running under JDK 11 because of whitespace changes in `javax.xml` output. For now, it's currently easier to just require JDK 8. The preferred JDK version is controlled by the new `$(MaxJdkVersion)` YAML variable, which in turn sets `$(JI_MAX_JDK)` (55c56f7) and/or the `$(MaxJdkVersion)` MSBuild property, which `dotnet build -t:Prepare` uses to generate `bin/Build*/JdkInfo.props`. Finally, *for consistency*, update `TestJVM` to look for the generated `JdkInfo.props`. If found, use the `$(JdkJvmPath)` value at `/Project/Chooose/When/PropertyGroup/JdkJvmPath` instead of using `JdkInfo.GetKnownSystemJdkInfos()`, so that the JVM that we built against is also used for unit test execution.
1 parent a3de91e commit 002dea4

File tree

5 files changed

+49
-10
lines changed

5 files changed

+49
-10
lines changed

build-tools/automation/azure-pipelines.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pr:
1818
variables:
1919
RunningOnCI: true
2020
Build.Configuration: Release
21+
MaxJdkVersion: 8
2122
DotNetCoreVersion: 5.0.103
2223
HostedMacImage: macOS-10.15
2324
HostedWinVS2019: Hosted Windows 2019 with VS2019
@@ -108,15 +109,15 @@ jobs:
108109

109110
- template: templates\install-dependencies.yaml
110111

111-
- script: make prepare CONFIGURATION=$(Build.Configuration)
112+
- script: make prepare CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion)
112113
displayName: make prepare
113114

114-
- script: make all CONFIGURATION=$(Build.Configuration)
115+
- script: make all CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion)
115116
displayName: make all
116117

117118
- script: |
118119
r=0
119-
make run-all-tests CONFIGURATION=$(Build.Configuration) || r=$?
120+
make run-all-tests CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion) || r=$?
120121
jar cf xatb.jar -C tests/Xamarin.Android.Tools.Bytecode-Tests/obj/*/classes .
121122
zip -r bin.zip bin
122123
exit $r
@@ -158,7 +159,7 @@ jobs:
158159

159160
- template: templates\install-dependencies.yaml
160161

161-
- script: make prepare-core CONFIGURATION=$(Build.Configuration)
162+
- script: make prepare-core CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion)
162163
displayName: make prepare-core
163164

164165
- template: templates\core-build.yaml

build-tools/automation/templates/core-build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ steps:
66
displayName: Prepare Solution
77
inputs:
88
projects: Java.Interop.sln
9-
arguments: '-c $(Build.Configuration) -target:Prepare'
9+
arguments: '-c $(Build.Configuration) -target:Prepare -p:MaxJdkVersion=$(MaxJdkVersion)'
1010

1111
- task: DotNetCoreCLI@2
1212
displayName: Build Solution

build-tools/scripts/Prepare.targets

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
<Target Name="Prepare">
88
<Exec Command="git submodule update --init --recursive" WorkingDirectory="$(_TopDir)" />
99
<MSBuild Projects="$(MSBuildThisFileDirectory)..\..\build-tools\Java.Interop.BootstrapTasks\Java.Interop.BootstrapTasks.csproj" />
10+
<PropertyGroup>
11+
<_MaxJdk>$(MaxJdkVersion)</_MaxJdk>
12+
<_MaxJdk Condition=" '$(_MaxJdk)' == '' ">$(JI_MAX_JDK)</_MaxJdk>
13+
</PropertyGroup>
1014
<JdkInfo
1115
JdksRoot="$(ProgramFiles)\Java"
1216
MakeFragmentFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\JdkInfo.mk"
13-
MaximumJdkVersion="$(JI_MAX_MDK)"
17+
MaximumJdkVersion="$(_MaxJdk)"
1418
PropertyFile="$(_TopDir)\bin\Build$(Configuration)\JdkInfo.props">
1519
<Output TaskParameter="JavaHomePath" PropertyName="_JavaSdkDirectory" />
1620
</JdkInfo>

tests/TestJVM/TestJVM.cs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Reflection;
77
using System.Threading;
88
using System.Text;
9+
using System.Xml.Linq;
910

1011
using Xamarin.Android.Tools;
1112

@@ -47,14 +48,47 @@ static TextWriter GetLogOutput (string envVar, string prefix, Assembly caller)
4748

4849
static string GetJvmLibraryPath ()
4950
{
50-
var env = Environment.GetEnvironmentVariable ("JI_JVM_PATH");
51-
if (!string.IsNullOrEmpty (env))
52-
return env;
51+
var jdkDir = ReadJavaSdkDirectoryFromJdkInfoProps ();
52+
if (jdkDir != null) {
53+
return jdkDir;
54+
}
5355
var jdk = JdkInfo.GetKnownSystemJdkInfos ()
5456
.FirstOrDefault ();
5557
return jdk?.JdkJvmPath;
5658
}
5759

60+
static string ReadJavaSdkDirectoryFromJdkInfoProps ()
61+
{
62+
var location = typeof (TestJVM).Assembly.Location;
63+
var binDir = Path.GetDirectoryName (Path.GetDirectoryName (location));
64+
var testDir = Path.GetFileName (Path.GetDirectoryName (location));
65+
if (!testDir.StartsWith ("Test", StringComparison.OrdinalIgnoreCase)) {
66+
return null;
67+
}
68+
var buildName = testDir.Replace ("Test", "Build");
69+
if (buildName.Contains ('-')) {
70+
buildName = buildName.Substring (0, buildName.IndexOf ('-'));
71+
}
72+
var jdkPropFile = Path.Combine (binDir, buildName, "JdkInfo.props");
73+
if (!File.Exists (jdkPropFile)) {
74+
return null;
75+
}
76+
77+
var msbuild = XNamespace.Get ("http://schemas.microsoft.com/developer/msbuild/2003");
78+
79+
var jdkProps = XDocument.Load (jdkPropFile);
80+
var jdkJvmPath = jdkProps.Elements ()
81+
.Elements (msbuild + "Choose")
82+
.Elements (msbuild + "When")
83+
.Elements (msbuild + "PropertyGroup")
84+
.Elements (msbuild + "JdkJvmPath")
85+
.FirstOrDefault ();
86+
if (jdkJvmPath == null) {
87+
return null;
88+
}
89+
return jdkJvmPath.Value;
90+
}
91+
5892
Dictionary<string, Type> typeMappings;
5993

6094
public TestJVM (string[] jars = null, Dictionary<string, Type> typeMappings = null)

0 commit comments

Comments
 (0)