|
97 | 97 | <AutoInstalledJdkExists Condition="Exists('$(JdkInstallDir)\bin\java.exe') OR Exists('$(JdkInstallDir)/bin/java')">true</AutoInstalledJdkExists> |
98 | 98 | </PropertyGroup> |
99 | 99 |
|
100 | | - <!-- Download and install JDK 17 if no compatible Java found (Windows only) --> |
| 100 | + <!-- Download and install JDK 17 if no compatible Java found --> |
101 | 101 | <Message Text="(FlinkDotNet.JobGateway) No compatible Java found. Installing JDK $(JdkVersion) to $(JdkInstallDir)..." |
102 | 102 | Importance="High" |
103 | | - Condition="'$(IsWindows)' == 'true' AND '$(JavaHomeIsValid)' != 'true' AND '$(DetectedJavaHome)' == '' AND '$(AutoInstalledJdkExists)' != 'true'" /> |
| 103 | + Condition="('$(IsWindows)' == 'true' OR '$(IsLinux)' == 'true' OR '$(IsMacOS)' == 'true') AND '$(AutoInstalledJdkExists)' != 'true'" /> |
104 | 104 |
|
105 | 105 | <!-- Create tools directory if it doesn't exist --> |
106 | 106 | <MakeDir Directories="$(ToolsDir)" |
107 | | - Condition="'$(IsWindows)' == 'true' AND '$(JavaHomeIsValid)' != 'true' AND '$(DetectedJavaHome)' == '' AND '$(AutoInstalledJdkExists)' != 'true'" /> |
| 107 | + Condition="('$(IsWindows)' == 'true' OR '$(IsLinux)' == 'true' OR '$(IsMacOS)' == 'true') AND '$(AutoInstalledJdkExists)' != 'true'" /> |
108 | 108 |
|
109 | 109 | <!-- Download JDK ZIP (Windows only - use powershell for Windows PowerShell 5.1 compatibility) --> |
110 | 110 | <Exec Command="powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host 'Downloading JDK $(JdkVersion) from $(JdkDownloadUrl)...'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '$(JdkDownloadUrl)' -OutFile '$(JdkZipPath)' -UseBasicParsing"" |
111 | | - Condition="'$(IsWindows)' == 'true' AND '$(JavaHomeIsValid)' != 'true' AND '$(DetectedJavaHome)' == '' AND '$(AutoInstalledJdkExists)' != 'true' AND !Exists('$(JdkZipPath)')" |
| 111 | + Condition="'$(IsWindows)' == 'true' AND '$(AutoInstalledJdkExists)' != 'true' AND !Exists('$(JdkZipPath)')" |
112 | 112 | StandardOutputImportance="High" /> |
113 | 113 |
|
114 | 114 | <!-- Extract JDK ZIP (Windows only) --> |
115 | 115 | <Message Text="(FlinkDotNet.JobGateway) Extracting JDK to $(ToolsDir)..." |
116 | 116 | Importance="High" |
117 | | - Condition="'$(IsWindows)' == 'true' AND '$(JavaHomeIsValid)' != 'true' AND '$(DetectedJavaHome)' == '' AND '$(AutoInstalledJdkExists)' != 'true' AND Exists('$(JdkZipPath)')" /> |
| 117 | + Condition="'$(IsWindows)' == 'true' AND '$(AutoInstalledJdkExists)' != 'true' AND Exists('$(JdkZipPath)')" /> |
118 | 118 |
|
119 | 119 | <Exec Command="powershell -NoProfile -ExecutionPolicy Bypass -Command "Expand-Archive -Path '$(JdkZipPath)' -DestinationPath '$(ToolsDir)' -Force"" |
120 | | - Condition="'$(IsWindows)' == 'true' AND '$(JavaHomeIsValid)' != 'true' AND '$(DetectedJavaHome)' == '' AND '$(AutoInstalledJdkExists)' != 'true' AND Exists('$(JdkZipPath)')" |
| 120 | + Condition="'$(IsWindows)' == 'true' AND '$(AutoInstalledJdkExists)' != 'true' AND Exists('$(JdkZipPath)')" |
121 | 121 | StandardOutputImportance="High" /> |
122 | 122 |
|
123 | 123 | <!-- Verify JDK was extracted successfully (Windows) --> |
124 | | - <Error Condition="'$(IsWindows)' == 'true' AND '$(JavaHomeIsValid)' != 'true' AND '$(DetectedJavaHome)' == '' AND '$(AutoInstalledJdkExists)' != 'true' AND !Exists('$(JdkInstallDir)\bin\java.exe')" |
| 124 | + <Error Condition="'$(IsWindows)' == 'true' AND '$(AutoInstalledJdkExists)' != 'true' AND !Exists('$(JdkInstallDir)\bin\java.exe')" |
125 | 125 | Text="JDK installation failed. java.exe not found at $(JdkInstallDir)\bin\java.exe" /> |
126 | 126 |
|
127 | 127 | <Message Text="(FlinkDotNet.JobGateway) JDK $(JdkVersion) successfully installed to $(JdkInstallDir)" |
128 | 128 | Importance="High" |
129 | 129 | Condition="'$(IsWindows)' == 'true' AND Exists('$(JdkInstallDir)\bin\java.exe')" /> |
130 | 130 |
|
131 | | - <!-- Error if Java not found on Linux/macOS (should be pre-installed in CI) --> |
132 | | - <Error Condition="('$(IsLinux)' == 'true' OR '$(IsMacOS)' == 'true') AND '$(JavaHomeIsValid)' != 'true' AND '$(JAVA_HOME)' == ''" |
133 | | - Text="Java not found on Linux/macOS. Please install JDK 17+ or ensure JAVA_HOME is set. On GitHub Actions, Java is installed via actions/setup-java@v4." /> |
| 131 | + <!-- Download and extract JDK 17 (Linux/macOS) --> |
| 132 | + <Exec Command="/bin/bash -c "set -euo pipefail; echo 'Downloading JDK $(JdkVersion) from $(JdkDownloadUrl)...'; curl -fSL -o '$(JdkTarPath)' '$(JdkDownloadUrl)'"" |
| 133 | + Condition="('$(IsLinux)' == 'true' OR '$(IsMacOS)' == 'true') AND '$(AutoInstalledJdkExists)' != 'true' AND !Exists('$(JdkTarPath)')" |
| 134 | + StandardOutputImportance="High" |
| 135 | + StandardErrorImportance="High" /> |
| 136 | + |
| 137 | + <Message Text="(FlinkDotNet.JobGateway) Extracting JDK to $(ToolsDir)..." |
| 138 | + Importance="High" |
| 139 | + Condition="('$(IsLinux)' == 'true' OR '$(IsMacOS)' == 'true') AND '$(AutoInstalledJdkExists)' != 'true' AND Exists('$(JdkTarPath)')" /> |
| 140 | + |
| 141 | + <Exec Command="/bin/bash -c "set -euo pipefail; tar -xzf '$(JdkTarPath)' -C '$(ToolsDir)'"" |
| 142 | + Condition="('$(IsLinux)' == 'true' OR '$(IsMacOS)' == 'true') AND '$(AutoInstalledJdkExists)' != 'true' AND Exists('$(JdkTarPath)')" |
| 143 | + StandardOutputImportance="High" |
| 144 | + StandardErrorImportance="High" /> |
| 145 | + |
| 146 | + <!-- Verify JDK was extracted successfully (Linux/macOS) --> |
| 147 | + <Error Condition="('$(IsLinux)' == 'true' OR '$(IsMacOS)' == 'true') AND '$(AutoInstalledJdkExists)' != 'true' AND !Exists('$(JdkInstallDir)/bin/java')" |
| 148 | + Text="JDK installation failed. java binary not found at $(JdkInstallDir)/bin/java" /> |
| 149 | + |
| 150 | + <Message Text="(FlinkDotNet.JobGateway) JDK $(JdkVersion) successfully installed to $(JdkInstallDir)" |
| 151 | + Importance="High" |
| 152 | + Condition="('$(IsLinux)' == 'true' OR '$(IsMacOS)' == 'true') AND Exists('$(JdkInstallDir)/bin/java')" /> |
134 | 153 |
|
135 | 154 | <!-- Re-check if auto-installed JDK exists after installation attempt --> |
136 | 155 | <PropertyGroup> |
|
141 | 160 | <PropertyGroup> |
142 | 161 | <!-- Priority 1: Use valid existing JAVA_HOME --> |
143 | 162 | <EffectiveJavaHome Condition="'$(JavaHomeIsValid)' == 'true'">$(JAVA_HOME)</EffectiveJavaHome> |
144 | | - <!-- Priority 2: Use detected Java installation --> |
145 | | - <EffectiveJavaHome Condition="'$(EffectiveJavaHome)' == '' AND '$(DetectedJavaHome)' != ''">$(DetectedJavaHome)</EffectiveJavaHome> |
146 | | - <!-- Priority 3: Use auto-installed JDK (re-check after installation) --> |
| 163 | + <!-- Priority 2: Prefer managed JDK 17 installation --> |
147 | 164 | <EffectiveJavaHome Condition="'$(EffectiveJavaHome)' == '' AND '$(AutoInstalledJdkExists)' == 'true'">$(JdkInstallDir)</EffectiveJavaHome> |
| 165 | + <!-- Priority 3: Use other detected Java installations as fallback --> |
| 166 | + <EffectiveJavaHome Condition="'$(EffectiveJavaHome)' == '' AND '$(DetectedJavaHome)' != ''">$(DetectedJavaHome)</EffectiveJavaHome> |
148 | 167 | <!-- Priority 4: On Linux/macOS, use JAVA_HOME even if validation failed (GitHub Actions sets valid paths) --> |
149 | 168 | <EffectiveJavaHome Condition="'$(EffectiveJavaHome)' == '' AND ('$(IsLinux)' == 'true' OR '$(IsMacOS)' == 'true') AND '$(JAVA_HOME)' != ''">$(JAVA_HOME)</EffectiveJavaHome> |
150 | 169 | </PropertyGroup> |
|
0 commit comments