Skip to content

Commit 80b391d

Browse files
committed
Support testing with JDK 17
Context: dotnet/android#8029 Update `<JdkInfo/>` task to emit a new `$(Java*MajorVersion)` MSBuild property. This is used by `src/Java.Base` so that it knows which JDK version it's binding. Begin explicitly qualifying all `$(Jdk*)` and `$(Java*)` MSBuild properties to explicitly disambiguate between JDK 1.8 and JDK-11 contexts. Eventually we may "swap" things so that properties without a version are for e.g. JDK 11 (17, etc.) and `$(Jdk8*)` is for JDK 1.8-requiring contexts. Note: to get this to *build* we had to update `src/Java.Base` to support binding against JDK-17, which was an expected diversion. This "JDK-17 Java.Base binding" was a "time limited" effort.
1 parent 6aedf1c commit 80b391d

File tree

23 files changed

+155
-27
lines changed

23 files changed

+155
-27
lines changed

Configuration.Override.props.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<JdkJvmPath>/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre/jli/libjli.dylib</JdkJvmPath>
4+
<JdkJvm11Path>/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre/jli/libjli.dylib</JdkJvmPath>
55
<MonoFrameworkPath>/Library/Frameworks/Mono.framework/Libraries/libmonosgen-2.0.1.dylib</MonoFrameworkPath>
66
<UtilityOutputFullPath>$(MSBuildThisFileDirectory)bin\$(Configuration)\</UtilityOutputFullPath>
77
</PropertyGroup>
88
<ItemGroup>
99
<!-- JDK C `include` directories -->
10-
<JdkIncludePath Include="/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/include" />
11-
<JdkIncludePath Include="/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/include/darwin" />
10+
<Jdk11IncludePath Include="/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/include" />
11+
<Jdk11IncludePath Include="/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/include/darwin" />
1212
</ItemGroup>
1313
<ItemGroup>
1414
<!-- Mono C `include` directories -->

Directory.Build.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
Condition=" Exists('$(MSBuildThisFileDirectory)bin\Build$(Configuration)\Version.props') "
3434
/>
3535
<Import
36-
Project="$(_OutputPath)JdkInfo.props"
37-
Condition="Exists('$(_OutputPath)JdkInfo.props')"
36+
Project="$(_OutputPath)JdkInfo-8.props"
37+
Condition="Exists('$(_OutputPath)JdkInfo-8.props')"
3838
/>
3939
<Import
4040
Project="$(_OutputPath)JdkInfo-11.props"
@@ -69,7 +69,7 @@
6969
<JavacSourceVersion Condition=" '$(JavacSourceVersion)' == '' ">1.8</JavacSourceVersion>
7070
<JavacTargetVersion Condition=" '$(JavacTargetVersion)' == '' ">1.8</JavacTargetVersion>
7171
<_BootClassPath Condition=" '$(JreRtJarPath)' != '' ">-bootclasspath "$(JreRtJarPath)"</_BootClassPath>
72-
<_JavacSourceOptions>-source $(JavacSourceVersion) -target $(JavacTargetVersion) $(_BootClassPath)</_JavacSourceOptions>
72+
<_Javac8SourceOptions>-source $(JavacSourceVersion) -target $(JavacTargetVersion) $(_BootClassPath)</_Javac8SourceOptions>
7373
</PropertyGroup>
7474
<PropertyGroup>
7575
<XamarinAndroidToolsFullPath>$([System.IO.Path]::GetFullPath ('$(XamarinAndroidToolsDirectory)'))</XamarinAndroidToolsFullPath>

Documentation/BuildConfiguration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Overridable MSBuild properties include:
2121
[`java-interop`](src/java-interop) against. By default this is
2222
probed for from numerous locations within
2323
[`build-tools/scripts/jdk.mk`](build-tools/scripts/jdk.mk).
24-
* `$(JavaCPath)`: Path to the `javac` command-line tool, by default set to `javac`.
25-
* `$(JarPath)`: Path to the `jar` command-line tool, by default set to `jar`.
24+
* `$(JavaC8Path)`: Path to the `javac` command-line tool, by default set to `javac`.
25+
* `$(Jar8Path)`: Path to the `jar` command-line tool, by default set to `jar`.
2626
* It may be desirable to override these on Windows, depending on your `PATH`.
2727
* `$(UtilityOutputFullPath)`: Directory to place various utilities such as
2828
[`class-parse`](tools/class-parse), [`generator`](tools/generator),

build-tools/Java.Interop.BootstrapTasks/Java.Interop.BootstrapTasks/JdkInfo.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public override bool Execute ()
6161
JavaHomePath = jdk.HomePath;
6262

6363
Directory.CreateDirectory (Path.GetDirectoryName (PropertyFile.ItemSpec));
64-
WritePropertyFile (jdk.JavaPath, jdk.JarPath, jdk.JavacPath, jdk.JdkJvmPath, rtJarPath, jdk.IncludePath);
64+
WritePropertyFile (jdk, rtJarPath);
6565

6666
if (MakeFragmentFile != null) {
6767
Directory.CreateDirectory (Path.GetDirectoryName (MakeFragmentFile.ItemSpec));
@@ -117,8 +117,14 @@ Action<TraceLevel, string> CreateLogger ()
117117
return logger;
118118
}
119119

120-
void WritePropertyFile (string javaPath, string jarPath, string javacPath, string jdkJvmPath, string rtJarPath, IEnumerable<string> includes)
120+
void WritePropertyFile (XATInfo jdk, string rtJarPath)
121121
{
122+
var jarPath = jdk.JarPath;
123+
var javacPath = jdk.JavacPath;
124+
var javaPath = jdk.JavaPath;
125+
var jdkJvmPath = jdk.JdkJvmPath;
126+
var includes = jdk.IncludePath;
127+
122128
var msbuild = XNamespace.Get ("http://schemas.microsoft.com/developer/msbuild/2003");
123129
var jdkJvmP = $"JdkJvm{PropertyNameModifier}Path";
124130
var project = new XElement (msbuild + "Project",
@@ -129,6 +135,7 @@ void WritePropertyFile (string javaPath, string jarPath, string javacPath, strin
129135
new XElement (msbuild + "ItemGroup",
130136
includes.Select (i => new XElement (msbuild + $"Jdk{PropertyNameModifier}IncludePath", new XAttribute ("Include", i)))))),
131137
new XElement (msbuild + "PropertyGroup",
138+
CreateProperty (msbuild, $"Java{PropertyNameModifier}MajorVersion", jdk.Version.Major.ToString ()),
132139
CreateProperty (msbuild, $"Java{PropertyNameModifier}SdkDirectory", JavaHomePath),
133140
CreateProperty (msbuild, $"Java{PropertyNameModifier}Path", javaPath),
134141
CreateProperty (msbuild, $"JavaC{PropertyNameModifier}Path", javacPath),

build-tools/scripts/Prepare.targets

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,22 @@
1919
</PropertyGroup>
2020
<JdkInfo
2121
JdksRoot="$(Jdks8Root)"
22+
PropertyNameModifier="8"
2223
MakeFragmentFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\JdkInfo.mk"
2324
MaximumJdkVersion="$(_MaxJdk)"
2425
DotnetToolPath="$(DotnetToolPath)"
25-
PropertyFile="$(_TopDir)\bin\Build$(Configuration)\JdkInfo.props">
26+
PropertyFile="$(_TopDir)\bin\Build$(Configuration)\JdkInfo-8.props">
2627
<Output TaskParameter="JavaHomePath" PropertyName="_JavaSdkDirectory" />
2728
</JdkInfo>
2829
<PropertyGroup>
2930
<Jdks11Root Condition=" '$(Jdks11Root)' == '' And '$(JAVA_HOME_11_X64)' != '' And Exists($(JAVA_HOME_11_X64)) ">$(JAVA_HOME_11_X64)</Jdks11Root>
31+
<Jdks11MaxVersion Condition=" '$(Jdks11MaxVersion)' == '' ">11.99.0</Jdks11MaxVersion>
3032
</PropertyGroup>
3133
<JdkInfo
3234
JdksRoot="$(Jdks11Root)"
3335
PropertyNameModifier="11"
3436
MinimumJdkVersion="11.0"
35-
MaximumJdkVersion="11.99.0"
37+
MaximumJdkVersion="$(Jdks11MaxVersion)"
3638
PropertyFile="$(_TopDir)\bin\Build$(Configuration)\JdkInfo-11.props">
3739
<Output TaskParameter="JavaHomePath" PropertyName="Java11SdkDirectory"/>
3840
</JdkInfo>

src/Java.Base/Java.Base.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
66
<Nullable>enable</Nullable>
77
<NoWarn>$(NoWarn);8764</NoWarn>
8+
<LangVersion>9.0</LangVersion>
89
</PropertyGroup>
910

1011
<Import Project="..\..\TargetFrameworkDependentValues.props" />

src/Java.Base/Java.Base.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<GeneratorPath>$(UtilityOutputFullPath)generator.dll</GeneratorPath>
5+
<DefineConstants>$(DefineConstants);JAVA_$(Java11MajorVersion)</DefineConstants>
56
</PropertyGroup>
67

78
<ItemGroup>

src/Java.Base/Java.Lang/Class.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using Java.Interop;
3+
4+
#if JAVA_17
5+
using Java.Lang.Invoke;
6+
using Java.Lang.Constants;
7+
8+
namespace Java.Lang {
9+
public partial class Class {
10+
11+
}
12+
}
13+
14+
#endif // JAVA_17

src/Java.Base/Java.Lang/Double.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using Java.Interop;
3+
4+
#if JAVA_17
5+
using Java.Lang.Invoke;
6+
using Java.Lang.Constants;
7+
8+
namespace Java.Lang {
9+
public partial class Double {
10+
11+
Java.Lang.Object? IConstantDesc.ResolveConstantDesc (MethodHandles.Lookup? lookup) =>
12+
ResolveConstantDesc (lookup);
13+
}
14+
}
15+
16+
#endif // JAVA_17

src/Java.Base/Java.Lang/Float.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using Java.Interop;
3+
4+
#if JAVA_17
5+
using Java.Lang.Invoke;
6+
using Java.Lang.Constants;
7+
8+
namespace Java.Lang {
9+
public partial class Float {
10+
11+
Java.Lang.Object? IConstantDesc.ResolveConstantDesc (MethodHandles.Lookup? lookup) =>
12+
ResolveConstantDesc (lookup);
13+
}
14+
}
15+
16+
#endif // JAVA_17

0 commit comments

Comments
 (0)