Skip to content

Commit 2ecf249

Browse files
Support Windows ARM (#54)
In this changeset, we add a dependency to Windows ARM binaries since we recently [introduced](TeamDev-IP/JxBrowser#2990) the support of this architecture. As for now, this will only be supported in JxBrowser 8. Also, I added a check for some artifacts supported only in JxBrowser 8. From now on, if the user decides to use the `jxbrowser-kotlin` artifact with JxBrowser 7, for example, the build will fail.
1 parent af095f5 commit 2ecf249

4 files changed

Lines changed: 77 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ dependencies {
4848
implementation(jxbrowser.macArm)
4949
implementation(jxbrowser.win32)
5050
implementation(jxbrowser.win64)
51+
implementation(jxbrowser.win64Arm)
5152
implementation(jxbrowser.linux64)
5253
implementation(jxbrowser.linuxArm)
5354
}

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ repositories {
5656

5757
dependencies {
5858
implementation(kotlin("stdlib"))
59+
implementation("com.vdurmont:semver4j:3.1.0")
5960

6061
testImplementation(kotlin("test"))
6162
testImplementation(gradleTestKit())

src/main/kotlin/com/teamdev/jxbrowser/gradle/JxBrowserExtension.kt

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import com.teamdev.jxbrowser.gradle.Environment.isWindows
2828
import com.teamdev.jxbrowser.gradle.Environment.isX64Bit
2929
import com.teamdev.jxbrowser.gradle.Environment.jvmArch
3030
import com.teamdev.jxbrowser.gradle.Environment.osName
31+
import com.vdurmont.semver4j.Semver
3132
import org.gradle.api.Project
3233
import org.gradle.api.provider.Provider
3334

@@ -73,12 +74,16 @@ public open class JxBrowserExtension(private val project: Project) {
7374
/**
7475
* Returns a dependency notation for the `jxbrowser-kotlin`,
7576
* an artifact with the Kotlin API of the library.
77+
*
78+
* Kotlin API is only supported in JxBrowser 8.x.x.
7679
*/
7780
public val kotlin: Provider<String> = artifact("kotlin")
7881

7982
/**
8083
* Returns a dependency notation for the `jxbrowser-compose`,
8184
* an artifact with Compose integration.
85+
*
86+
* Compose is only supported in JxBrowser 8.x.x.
8287
*/
8388
public val compose: Provider<String> = artifact("compose")
8489

@@ -112,6 +117,14 @@ public open class JxBrowserExtension(private val project: Project) {
112117
*/
113118
public val win32: Provider<String> = artifact("win32")
114119

120+
/**
121+
* Returns a dependency notation for the `jxbrowser-win64-arm`,
122+
* an artifact with Chromium Windows ARM 64-bit binaries.
123+
*
124+
* Windows ARM is only supported in JxBrowser 8.x.x.
125+
*/
126+
public val win64Arm: Provider<String> = artifact("win64-arm")
127+
115128
/**
116129
* Returns a dependency notation for the `jxbrowser-linux64`,
117130
* an artifact with Chromium Linux 64-bit binaries.
@@ -151,12 +164,13 @@ public open class JxBrowserExtension(private val project: Project) {
151164
private fun currentPlatform(): Provider<String> {
152165
val platformMap =
153166
mapOf(
154-
Pair({ isX64Bit() && isWindows() }, win64),
155-
Pair({ isX64Bit() && isLinux() }, linux64),
156-
Pair({ isX64Bit() && isMac() }, mac),
157-
Pair({ is32Bit() && isWindows() }, win32),
158-
Pair({ isArm() && isLinux() }, linuxArm),
159-
Pair({ isArm() && isMac() }, macArm),
167+
{ isX64Bit() && isWindows() } to win64,
168+
{ is32Bit() && isWindows() } to win32,
169+
{ isArm() && isWindows() } to win64Arm,
170+
{ isX64Bit() && isLinux() } to linux64,
171+
{ isX64Bit() && isMac() } to mac,
172+
{ isArm() && isLinux() } to linuxArm,
173+
{ isArm() && isMac() } to macArm,
160174
)
161175
return platformMap.entries.firstOrNull { it.key() }?.value
162176
?: project.providers.provider {
@@ -169,13 +183,34 @@ public open class JxBrowserExtension(private val project: Project) {
169183
private fun artifact(shortName: String) =
170184
project.providers.provider {
171185
check(version.isNotBlank()) { "JxBrowser version is not specified." }
186+
checkArtifactSupported(shortName)
172187
if (shortName == "core") {
173188
"$GROUP:jxbrowser:$version"
174189
} else {
175190
"$GROUP:jxbrowser-$shortName:$version"
176191
}
177192
}
178193

194+
/**
195+
* Check if the artifact with `shortName` exists in JxBrowser `version`.
196+
*/
197+
private fun checkArtifactSupported(shortName: String) {
198+
val artifactNameToReleaseVersion =
199+
mapOf(
200+
"compose" to "8.0.0-eap.1",
201+
"kotlin" to "8.0.0-eap.1",
202+
"win64-arm" to "8.0.0",
203+
)
204+
val artifactReleaseVersion = artifactNameToReleaseVersion[shortName]
205+
if (artifactReleaseVersion != null) {
206+
val releaseVersion = Semver(artifactReleaseVersion)
207+
val actualVersion = Semver(version)
208+
check(actualVersion.isGreaterThanOrEqualTo(releaseVersion)) {
209+
"Artifact '$shortName' is not supported by JxBrowser $version. Use $artifactReleaseVersion or greater."
210+
}
211+
}
212+
}
213+
179214
private companion object {
180215
private const val GROUP = "com.teamdev.jxbrowser"
181216
}

src/test/kotlin/com/teamdev/jxbrowser/gradle/JxBrowserPluginFunctionalTest.kt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import org.junit.jupiter.api.io.TempDir
3030
import java.io.File
3131
import kotlin.test.BeforeTest
3232
import kotlin.test.Test
33+
import kotlin.test.assertFails
3334

3435
@DisplayName("JxBrowserPlugin should")
3536
internal class JxBrowserPluginFunctionalTest {
@@ -94,7 +95,6 @@ internal class JxBrowserPluginFunctionalTest {
9495
"jxbrowser-mac-$jxBrowserVersion.jar",
9596
"jxbrowser-mac-arm-$jxBrowserVersion.jar",
9697
)
97-
9898
buildFile.writeText(
9999
"""
100100
plugins {
@@ -194,6 +194,39 @@ internal class JxBrowserPluginFunctionalTest {
194194
libsFolder.files() shouldContainExactlyInAnyOrder filesToCheck
195195
}
196196

197+
@Test
198+
fun `fail to download unsupported artifacts`() {
199+
val jxBrowserVersion = "7.40.0" // This version doesn't contain artifacts bellow.
200+
val unsupportedArtifacts = listOf("kotlin", "compose", "win64-arm")
201+
202+
for (artifact in unsupportedArtifacts) {
203+
buildFile.writeText(
204+
"""
205+
plugins {
206+
java
207+
id("com.teamdev.jxbrowser")
208+
}
209+
210+
jxbrowser {
211+
version = "$jxBrowserVersion"
212+
}
213+
214+
dependencies {
215+
implementation(jxbrowser.$artifact)
216+
}
217+
""".trimIndent(),
218+
)
219+
220+
assertFails {
221+
GradleRunner.create()
222+
.withProjectDir(testProjectDir)
223+
.withPluginClasspath()
224+
.withArguments("build")
225+
.build()
226+
}
227+
}
228+
}
229+
197230
private fun BuildResult.outcome(taskName: String) = this.task(taskName)!!.outcome
198231

199232
private fun File.files() = this.listFiles()!!.map { it.name }

0 commit comments

Comments
 (0)