|
1 | 1 | import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform |
2 | 2 | import org.jetbrains.compose.desktop.application.dsl.TargetFormat |
| 3 | +import org.jetbrains.compose.desktop.application.tasks.AbstractJPackageTask |
3 | 4 | import org.jetbrains.compose.internal.de.undercouch.gradle.tasks.download.Download |
4 | 5 |
|
5 | 6 | plugins{ |
@@ -30,6 +31,11 @@ sourceSets{ |
30 | 31 | srcDirs("src") |
31 | 32 | } |
32 | 33 | } |
| 34 | + test{ |
| 35 | + kotlin{ |
| 36 | + srcDirs("test") |
| 37 | + } |
| 38 | + } |
33 | 39 | } |
34 | 40 |
|
35 | 41 | compose.desktop { |
@@ -99,12 +105,177 @@ dependencies { |
99 | 105 |
|
100 | 106 | implementation(libs.compottie) |
101 | 107 | implementation(libs.kaml) |
| 108 | + |
| 109 | + testImplementation(kotlin("test")) |
| 110 | + testImplementation(libs.mockitoKotlin) |
| 111 | + testImplementation(libs.junitJupiter) |
| 112 | + testImplementation(libs.junitJupiterParams) |
102 | 113 | } |
103 | 114 |
|
104 | 115 | tasks.compileJava{ |
105 | 116 | options.encoding = "UTF-8" |
106 | 117 | } |
107 | 118 |
|
| 119 | +tasks.test { |
| 120 | + useJUnitPlatform() |
| 121 | + workingDir = file("build/test") |
| 122 | + workingDir.mkdirs() |
| 123 | +} |
| 124 | + |
| 125 | +tasks.register<Exec>("installCreateDmg") { |
| 126 | + onlyIf { org.gradle.internal.os.OperatingSystem.current().isMacOsX } |
| 127 | + commandLine("arch", "-arm64", "brew", "install", "--quiet", "create-dmg") |
| 128 | +} |
| 129 | +tasks.register<Exec>("packageCustomDmg"){ |
| 130 | + onlyIf { org.gradle.internal.os.OperatingSystem.current().isMacOsX } |
| 131 | + group = "compose desktop" |
| 132 | + |
| 133 | + val distributable = tasks.named<AbstractJPackageTask>("createDistributable").get() |
| 134 | + dependsOn(distributable, "installCreateDmg") |
| 135 | + |
| 136 | + val packageName = distributable.packageName.get() |
| 137 | + val dir = distributable.destinationDir.get() |
| 138 | + val dmg = dir.file("../dmg/$packageName-$version.dmg").asFile |
| 139 | + val app = dir.file("$packageName.app").asFile |
| 140 | + |
| 141 | + dmg.parentFile.deleteRecursively() |
| 142 | + dmg.parentFile.mkdirs() |
| 143 | + |
| 144 | + val extra = mutableListOf<String>() |
| 145 | + val isSigned = compose.desktop.application.nativeDistributions.macOS.signing.sign.get() |
| 146 | + |
| 147 | + if(!isSigned) { |
| 148 | + val content = """ |
| 149 | + run 'xattr -d com.apple.quarantine Processing-${version}.dmg' to remove the quarantine flag |
| 150 | + """.trimIndent() |
| 151 | + val instructions = dmg.parentFile.resolve("INSTRUCTIONS.txt") |
| 152 | + instructions.writeText(content) |
| 153 | + extra.add("--add-file") |
| 154 | + extra.add("INSTRUCTIONS.txt") |
| 155 | + extra.add(instructions.path) |
| 156 | + extra.add("200") |
| 157 | + extra.add("25") |
| 158 | + } |
| 159 | + |
| 160 | + commandLine("brew", "install", "--quiet", "create-dmg") |
| 161 | + |
| 162 | + commandLine("create-dmg", |
| 163 | + "--volname", packageName, |
| 164 | + "--volicon", file("macos/volume.icns"), |
| 165 | + "--background", file("macos/background.png"), |
| 166 | + "--icon", "$packageName.app", "200", "200", |
| 167 | + "--window-pos", "200", "200", |
| 168 | + "--window-size", "775", "485", |
| 169 | + "--app-drop-link", "500", "200", |
| 170 | + "--hide-extension", "$packageName.app", |
| 171 | + *extra.toTypedArray(), |
| 172 | + dmg, |
| 173 | + app |
| 174 | + ) |
| 175 | +} |
| 176 | + |
| 177 | +tasks.register<Exec>("packageCustomMsi"){ |
| 178 | + onlyIf { org.gradle.internal.os.OperatingSystem.current().isWindows } |
| 179 | + dependsOn("createDistributable") |
| 180 | + workingDir = file("windows") |
| 181 | + group = "compose desktop" |
| 182 | + |
| 183 | + commandLine( |
| 184 | + "dotnet", |
| 185 | + "build", |
| 186 | + "/p:Platform=x64", |
| 187 | + "/p:Version=$version", |
| 188 | + "/p:DefineConstants=\"Version=$version;\"" |
| 189 | + ) |
| 190 | +} |
| 191 | + |
| 192 | +tasks.register("generateSnapConfiguration"){ |
| 193 | + onlyIf { org.gradle.internal.os.OperatingSystem.current().isLinux } |
| 194 | + val distributable = tasks.named<AbstractJPackageTask>("createDistributable").get() |
| 195 | + dependsOn(distributable) |
| 196 | + |
| 197 | + val arch = when (System.getProperty("os.arch")) { |
| 198 | + "amd64", "x86_64" -> "amd64" |
| 199 | + "aarch64" -> "arm64" |
| 200 | + else -> System.getProperty("os.arch") |
| 201 | + } |
| 202 | + |
| 203 | + val dir = distributable.destinationDir.get() |
| 204 | + val content = """ |
| 205 | + name: ${rootProject.name} |
| 206 | + version: ${rootProject.version} |
| 207 | + base: core22 |
| 208 | + summary: A creative coding editor |
| 209 | + description: | |
| 210 | + Processing is a flexible software sketchbook and a programming language designed for learning how to code. |
| 211 | + confinement: strict |
| 212 | + |
| 213 | + apps: |
| 214 | + processing: |
| 215 | + command: opt/processing/bin/Processing |
| 216 | + desktop: opt/processing/lib/processing-Processing.desktop |
| 217 | + plugs: |
| 218 | + - desktop |
| 219 | + - desktop-legacy |
| 220 | + - wayland |
| 221 | + - x11 |
| 222 | + |
| 223 | + parts: |
| 224 | + processing: |
| 225 | + plugin: dump |
| 226 | + source: deb/processing_$version-1_$arch.deb |
| 227 | + source-type: deb |
| 228 | + stage-packages: |
| 229 | + - openjdk-17-jdk |
| 230 | + override-prime: | |
| 231 | + snapcraftctl prime |
| 232 | + chmod -R +x opt/processing/lib/app/resources/jdk-* |
| 233 | + """.trimIndent() |
| 234 | + dir.file("../snapcraft.yaml").asFile.writeText(content) |
| 235 | +} |
| 236 | + |
| 237 | +tasks.register<Exec>("packageSnap"){ |
| 238 | + onlyIf { org.gradle.internal.os.OperatingSystem.current().isLinux } |
| 239 | + dependsOn("packageDeb", "generateSnapConfiguration") |
| 240 | + group = "compose desktop" |
| 241 | + |
| 242 | + val distributable = tasks.named<AbstractJPackageTask>("createDistributable").get() |
| 243 | + workingDir = distributable.destinationDir.dir("../").get().asFile |
| 244 | + |
| 245 | + commandLine("snapcraft") |
| 246 | +} |
| 247 | +tasks.register<Zip>("zipDistributable"){ |
| 248 | + dependsOn("createDistributable") |
| 249 | + group = "compose desktop" |
| 250 | + |
| 251 | + val distributable = tasks.named<AbstractJPackageTask>("createDistributable").get() |
| 252 | + val dir = distributable.destinationDir.get() |
| 253 | + val packageName = distributable.packageName.get() |
| 254 | + |
| 255 | + from(dir){ eachFile{ permissions{ unix("755") } } } |
| 256 | + archiveBaseName.set(packageName) |
| 257 | + destinationDirectory.set(dir.file("../").asFile) |
| 258 | +} |
| 259 | + |
| 260 | +afterEvaluate{ |
| 261 | + tasks.named("createDistributable").configure{ |
| 262 | + finalizedBy("zipDistributable") |
| 263 | + } |
| 264 | + tasks.named("packageDmg").configure{ |
| 265 | + dependsOn("packageCustomDmg") |
| 266 | + group = "compose desktop" |
| 267 | + actions = emptyList() |
| 268 | + } |
| 269 | + tasks.named("packageMsi").configure{ |
| 270 | + dependsOn("packageCustomMsi") |
| 271 | + group = "compose desktop" |
| 272 | + actions = emptyList() |
| 273 | + } |
| 274 | + tasks.named("packageDistributionForCurrentOS").configure { |
| 275 | + dependsOn("packageSnap") |
| 276 | + } |
| 277 | +} |
| 278 | + |
108 | 279 |
|
109 | 280 | // LEGACY TASKS |
110 | 281 | // Most of these are shims to be compatible with the old build system |
|
0 commit comments