-
-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
138 lines (113 loc) · 3.57 KB
/
build.gradle.kts
File metadata and controls
138 lines (113 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import java.net.URI
plugins {
id("java-library")
}
repositories {
mavenCentral()
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
val coreJar = file("../../../core/library/core.jar")
val batikVersion = "1.19"
// The .zip file to be downloaded
val batikZip = "batik-bin-$batikVersion.zip"
// The .jar that we need from the download
val batikJar = file("library/batik.jar")
// URL for the version of Batik currently supported by this library
val batikUrl = "https://dlcdn.apache.org//xmlgraphics/batik/binaries/$batikZip"
// Storing a "local" copy in case the original link goes dead. When updating
// releases, please upload the new version to download.processing.org.
val batikBackupUrl = "https://download.processing.org/batik/$batikZip"
// Download Batik dependency if not present
// OK to ignore failed downloads if we at least have a version that's local
val downloadBatik by tasks.registering {
outputs.file(batikJar)
doLast {
if (batikJar.exists()) {
logger.lifecycle("Batik JAR already exists, skipping download.")
return@doLast
}
batikJar.parentFile.mkdirs()
val zipFile = file(batikZip)
val urlsToTry = listOf(batikUrl, batikBackupUrl)
val success = urlsToTry.any { url ->
try {
logger.lifecycle("Downloading Batik from $url")
URI(url).toURL().openStream().use { input ->
zipFile.outputStream().use { output ->
input.copyTo(output)
}
}
copy {
from(zipTree(zipFile)) {
include("batik-$batikVersion/lib/batik-all-$batikVersion.jar")
}
into(batikJar.parentFile)
eachFile {
path = batikJar.name
}
includeEmptyDirs = false
}
zipFile.delete()
if (batikJar.exists()) {
logger.lifecycle("Successfully extracted Batik JAR to ${batikJar.absolutePath}")
true
} else {
logger.error("Extraction failed")
false
}
} catch (e: Exception) {
logger.warn("Failed to download from $url: ${e.message}")
false
}
}
if (!success) {
throw GradleException("Failed to download Batik from all sources and no local copy found.")
}
}
}
tasks.register("checkCore") {
doFirst {
if (!coreJar.exists()) {
throw GradleException("Missing core.jar at $coreJar. Please build the core module first.")
}
}
}
sourceSets {
main {
java {
srcDirs("src")
}
}
}
dependencies {
implementation(project(":core"))
implementation(files(batikJar))
}
// Compile sources
tasks.named<JavaCompile>("compileJava") {
dependsOn(downloadBatik, "checkCore")
options.encoding = "UTF-8"
}
tasks.named<Jar>("jar") {
dependsOn("checkCore")
archiveBaseName.set("svg")
destinationDirectory.set(file("library"))
from(sourceSets.main.get().output)
}
tasks.register<Jar>("svgJar") {
dependsOn("checkCore", "classes")
archiveBaseName.set("svg")
destinationDirectory.set(file("library"))
from(sourceSets.main.get().output)
}
// Clean the build directories
tasks.named<Delete>("clean") {
delete("bin", "library/svg.jar")
}
tasks.register<Delete>("cleanLibs") {
delete(batikJar)
}