Skip to content

Commit d85257d

Browse files
committed
Refactor Platform enum and replace tasks.create() with tasks.register()
1 parent 8911dfb commit d85257d

File tree

2 files changed

+33
-37
lines changed

2 files changed

+33
-37
lines changed

desktop/build.gradle.kts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ tasks.register<Jar>("dist") { // Compiles the jar file
7272
}
7373

7474

75-
enum class Platform(val desc: String) {
76-
Windows32("windows32"), Windows64("windows64"), Linux32("linux32"), Linux64("linux64"), MacOS("mac");
75+
enum class Platform() {
76+
Windows32, Windows64, Linux32, Linux64, MacOS;
7777
}
7878

7979
class PackrConfig(
@@ -93,10 +93,8 @@ class PackrConfig(
9393
var bundleIdentifier: String? = null
9494
)
9595

96-
for (platform in Platform.values()) {
97-
val platformName = platform.toString()
98-
99-
tasks.create("packr${platformName}") {
96+
for (platform in Platform.entries) {
97+
tasks.register("packr${platform.name}") {
10098
// This task assumes that 'dist' has already been called - does not 'gradle depend' on it
10199
// so we can run 'dist' from one job and then run the packr builds from a different job
102100

@@ -139,16 +137,16 @@ for (platform in Platform.values()) {
139137

140138
// Requires that both packr and the jre are downloaded, as per buildAndDeploy.yml, "Upload to itch.io"
141139

142-
val jdkFile =
143-
when (platform) {
144-
Platform.Linux64 -> "jre-linux-64.tar.gz"
145-
Platform.Windows64 -> "jdk-windows-64.zip"
146-
else -> "jre-macOS.tar.gz"
147-
}
140+
val jdkFile = when (platform) {
141+
Platform.Linux64 -> "jre-linux-64.tar.gz"
142+
Platform.Windows64 -> "jdk-windows-64.zip"
143+
else -> "jre-macOS.tar.gz"
144+
}
148145

149-
val platformNameForPackrCmd =
150-
if (platform == Platform.MacOS) "mac"
151-
else platform.name.lowercase()
146+
val platformNameForPackrCmd = when (platform) {
147+
Platform.MacOS -> "mac"
148+
else -> platform.name.lowercase()
149+
}
152150

153151
val command = "java -jar $rootDir/packr-all-4.0.0.jar" +
154152
" --platform $platformNameForPackrCmd" +
@@ -162,13 +160,13 @@ for (platform in Platform.values()) {
162160
Files.copy(File("$rootDir/extraImages/Icons/Unciv.ico"), File(config.outDir, "Unciv.ico"))
163161
}
164162

165-
tasks.register<Zip>("zip${platformName}") {
166-
archiveFileName.set("${BuildConfig.appName}-${platformName}.zip")
163+
tasks.register<Zip>("zip${platform.name}") {
164+
archiveFileName.set("${BuildConfig.appName}-${platform.name}.zip")
167165
from(config.outDir)
168166
destinationDirectory.set(deployFolder)
169167
}
170168

171-
finalizedBy("zip${platformName}")
169+
finalizedBy("zip${platform.name}")
172170
}
173171
}
174172

server/build.gradle.kts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ tasks.register<Jar>("dist") { // Compiles the jar file
6060
}
6161
}
6262

63-
enum class Platform(val desc: String) {
64-
Windows32("windows32"), Windows64("windows64"), Linux32("linux32"), Linux64("linux64"), MacOS("mac");
63+
enum class Platform() {
64+
Windows32, Windows64, Linux32, Linux64, MacOS;
6565
}
6666

6767
class PackrConfig(
@@ -81,10 +81,8 @@ class PackrConfig(
8181
var bundleIdentifier: String? = null
8282
)
8383

84-
for (platform in Platform.values()) {
85-
val platformName = platform.toString()
86-
87-
tasks.create("packr${platformName}") {
84+
for (platform in Platform.entries) {
85+
tasks.register("packr${platform.name}") {
8886
dependsOn(tasks.getByName("dist"))
8987

9088
// Needs to be here and not in doLast because the zip task depends on the outDir
@@ -127,16 +125,16 @@ for (platform in Platform.values()) {
127125

128126
// Requires that both packr and the jre are downloaded, as per buildAndDeploy.yml, "Upload to itch.io"
129127

130-
val jdkFile =
131-
when (platform) {
132-
Platform.Linux64 -> "jre-linux-64.tar.gz"
133-
Platform.Windows64 -> "jdk-windows-64.zip"
134-
else -> "jre-macOS.tar.gz"
135-
}
128+
val jdkFile = when (platform) {
129+
Platform.Linux64 -> "jre-linux-64.tar.gz"
130+
Platform.Windows64 -> "jdk-windows-64.zip"
131+
else -> "jre-macOS.tar.gz"
132+
}
136133

137-
val platformNameForPackrCmd =
138-
if (platform == Platform.MacOS) "mac"
139-
else platform.name.lowercase()
134+
val platformNameForPackrCmd = when (platform) {
135+
Platform.MacOS -> "mac"
136+
else -> platform.name.lowercase()
137+
}
140138

141139
val command = "java -jar $rootDir/packr-all-4.0.0.jar" +
142140
" --platform $platformNameForPackrCmd" +
@@ -150,17 +148,17 @@ for (platform in Platform.values()) {
150148
}
151149
else "") +
152150
" --output ${config.outDir}"
153-
command.runCommand(rootDir)
154151

152+
command.runCommand(rootDir)
155153
}
156154

157-
tasks.register<Zip>("zip${platformName}") {
158-
archiveFileName.set("UncivServer-${platformName}.zip")
155+
tasks.register<Zip>("zip${platform.name}") {
156+
archiveFileName.set("UncivServer-${platform.name}.zip")
159157
from(config.outDir)
160158
destinationDirectory.set(deployFolder)
161159
}
162160

163-
finalizedBy("zip${platformName}")
161+
finalizedBy("zip${platform.name}")
164162
}
165163
}
166164

0 commit comments

Comments
 (0)