Skip to content

Commit 2eb540c

Browse files
committed
Require JDK 8 on CI?
XML output changed between JDK 8 and JDK 11, breaking some unit tests. Constrain CI to using JDK 8, so that tests pass. Additionally, *for consistency*, update `TestJVM` to look for `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 80f2c9c commit 2eb540c

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
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) JI_MAX_JDK=11
112+
- script: make prepare CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion)
112113
displayName: make prepare
113114

114-
- script: make all CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=11
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)