From ea204277b2c22c54b6d3c989dd5872d6d8cd30b8 Mon Sep 17 00:00:00 2001 From: jishnunambiarr Date: Thu, 22 May 2025 18:39:31 +0200 Subject: [PATCH 1/8] Use Maven dependency for Batik in build.gradle.kts --- java/libraries/svg/build.gradle.kts | 33 ++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/java/libraries/svg/build.gradle.kts b/java/libraries/svg/build.gradle.kts index a176f03df..540e0ddab 100644 --- a/java/libraries/svg/build.gradle.kts +++ b/java/libraries/svg/build.gradle.kts @@ -1 +1,32 @@ -ant.importBuild("build.xml") \ No newline at end of file +plugins { + id("java") +} + +repositories { + mavenCentral() +} + +dependencies { + implementation(project(":core")) + implementation("org.apache.xmlgraphics:batik-all:1.19") +} + +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } +} +sourceSets { + main { + java.srcDirs("src") + } +} + +tasks.jar { + archiveBaseName.set("svg") + destinationDirectory.set(file("library")) +} + +tasks.clean { + delete("bin", "library/svg.jar") +} \ No newline at end of file From 2b146384618202397de63300dcc19d7902b6ab9c Mon Sep 17 00:00:00 2001 From: jishnunambiarr Date: Thu, 22 May 2025 22:48:09 +0200 Subject: [PATCH 2/8] Updated build.gradle.kts with manual Batik download. --- java/libraries/svg/build.gradle.kts | 92 +++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 11 deletions(-) diff --git a/java/libraries/svg/build.gradle.kts b/java/libraries/svg/build.gradle.kts index 540e0ddab..9403d5844 100644 --- a/java/libraries/svg/build.gradle.kts +++ b/java/libraries/svg/build.gradle.kts @@ -1,32 +1,102 @@ +import java.net.URI + +// Batik configuration +val batikVersion = "1.19" +val batikZip = "batik-bin-$batikVersion.zip" +val batikJarName = "batik-all-$batikVersion.jar" +val batikJar = file("library/batik.jar") + +// URLs +val batikUrl = "https://dlcdn.apache.org/xmlgraphics/batik/binaries/$batikZip" +val batikBackupUrl = "https://download.processing.org/batik/$batikZip" + plugins { - id("java") + id("java-library") } -repositories { - mavenCentral() + +val downloadBatik by tasks.registering { + outputs.file(batikJar) + + doLast { + if (!batikJar.exists()) { + batikJar.parentFile.mkdirs() // Ensures 'library' directory exists + project.logger.lifecycle("Batik JAR not found at ${batikJar.absolutePath}. Downloading...") + + val urlsToTry = listOf(batikUrl, batikBackupUrl) + var downloaded = false + + for (currentUrl in urlsToTry) { + try { + project.logger.info("Attempting to download Batik from: $currentUrl") + // Create temp file in the build directory for easier cleanup if something goes wrong + val tempZipFile = project.layout.buildDirectory.file("tmp/${batikZip}").get().asFile + tempZipFile.parentFile.mkdirs() + tempZipFile.deleteOnExit() // In case of abnormal termination + + URI(currentUrl).toURL().openStream().use { input -> + tempZipFile.outputStream().use { output -> + input.copyTo(output) + } + } + project.logger.info("Downloaded $batikZip to ${tempZipFile.absolutePath}") + + project.copy { + from(project.zipTree(tempZipFile)) + include("**/lib/$batikJarName") // e.g. batik-1.19/lib/batik-all-1.19.jar + into(batikJar.parentFile) // Extract to 'library' directory + rename { _ -> batikJar.name } // Rename the single matched file to 'batik.jar' + } + + project.logger.lifecycle("Extracted $batikJarName to ${batikJar.absolutePath}") + tempZipFile.delete() // Clean up the downloaded zip + downloaded = true + break // Success + } catch (e: Exception) { + project.logger.warn("Failed to download/extract Batik from $currentUrl: ${e.message} (${e.javaClass.simpleName})") + } + } + + if (!downloaded) { + if (batikJar.exists()){ + project.logger.warn("Batik download failed from all sources, but a previous version exists at ${batikJar.absolutePath}. Using existing.") + } else { + throw GradleException("Failed to download Batik from all sources and no local copy found at ${batikJar.path}.") + } + } + } else { + project.logger.info("Batik JAR already exists at ${batikJar.absolutePath}. Skipping download.") + } + } + } + + dependencies { implementation(project(":core")) - implementation("org.apache.xmlgraphics:batik-all:1.19") + implementation(files(batikJar)) + } java { toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) + languageVersion.set(JavaLanguageVersion.of(21)) } } -sourceSets { - main { - java.srcDirs("src") - } + +tasks.named("compileJava") { + dependsOn(downloadBatik) + options.encoding = "UTF-8" } -tasks.jar { + + +tasks.named("jar") { archiveBaseName.set("svg") destinationDirectory.set(file("library")) } -tasks.clean { +tasks.named("clean") { delete("bin", "library/svg.jar") } \ No newline at end of file From 76f1403c704d607de17782fd3fb6a54b7db749ef Mon Sep 17 00:00:00 2001 From: jishnunambiarr Date: Thu, 22 May 2025 23:15:19 +0200 Subject: [PATCH 3/8] Updated build.gradle.kts with manual Batik download. --- java/libraries/svg/build.gradle.kts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/java/libraries/svg/build.gradle.kts b/java/libraries/svg/build.gradle.kts index 9403d5844..11007d74e 100644 --- a/java/libraries/svg/build.gradle.kts +++ b/java/libraries/svg/build.gradle.kts @@ -71,17 +71,28 @@ val downloadBatik by tasks.registering { } +val coreJar = file("../../../core/library/core.jar") + +tasks.register("checkCore") { + doFirst { + + if (!coreJar.exists()) { + throw GradleException("Missing core.jar at $coreJar. Please build the core module first.") + } + } +} + dependencies { - implementation(project(":core")) + implementation(files(coreJar)) implementation(files(batikJar)) } java { toolchain { - languageVersion.set(JavaLanguageVersion.of(21)) + languageVersion.set(JavaLanguageVersion.of(17)) } } From 43695756274888717a96651b2f0e4da49ff568a0 Mon Sep 17 00:00:00 2001 From: jishnunambiarr Date: Fri, 23 May 2025 22:49:05 +0200 Subject: [PATCH 4/8] Updated build.gradle.kts: Sourcesets block added to fix library not found error. --- java/libraries/svg/build.gradle.kts | 162 ++++++++++++++++------------ 1 file changed, 92 insertions(+), 70 deletions(-) diff --git a/java/libraries/svg/build.gradle.kts b/java/libraries/svg/build.gradle.kts index 11007d74e..cb68a712c 100644 --- a/java/libraries/svg/build.gradle.kts +++ b/java/libraries/svg/build.gradle.kts @@ -1,104 +1,106 @@ import java.net.URI -// Batik configuration -val batikVersion = "1.19" -val batikZip = "batik-bin-$batikVersion.zip" -val batikJarName = "batik-all-$batikVersion.jar" -val batikJar = file("library/batik.jar") - -// URLs -val batikUrl = "https://dlcdn.apache.org/xmlgraphics/batik/binaries/$batikZip" -val batikBackupUrl = "https://download.processing.org/batik/$batikZip" - plugins { id("java-library") } -val downloadBatik by tasks.registering { - outputs.file(batikJar) - - doLast { - if (!batikJar.exists()) { - batikJar.parentFile.mkdirs() // Ensures 'library' directory exists - project.logger.lifecycle("Batik JAR not found at ${batikJar.absolutePath}. Downloading...") - - val urlsToTry = listOf(batikUrl, batikBackupUrl) - var downloaded = false - - for (currentUrl in urlsToTry) { - try { - project.logger.info("Attempting to download Batik from: $currentUrl") - // Create temp file in the build directory for easier cleanup if something goes wrong - val tempZipFile = project.layout.buildDirectory.file("tmp/${batikZip}").get().asFile - tempZipFile.parentFile.mkdirs() - tempZipFile.deleteOnExit() // In case of abnormal termination - - URI(currentUrl).toURL().openStream().use { input -> - tempZipFile.outputStream().use { output -> - input.copyTo(output) - } - } - project.logger.info("Downloaded $batikZip to ${tempZipFile.absolutePath}") +repositories { + mavenCentral() + google() +} - project.copy { - from(project.zipTree(tempZipFile)) - include("**/lib/$batikJarName") // e.g. batik-1.19/lib/batik-all-1.19.jar - into(batikJar.parentFile) // Extract to 'library' directory - rename { _ -> batikJar.name } // Rename the single matched file to 'batik.jar' - } - project.logger.lifecycle("Extracted $batikJarName to ${batikJar.absolutePath}") - tempZipFile.delete() // Clean up the downloaded zip - downloaded = true - break // Success - } catch (e: Exception) { - project.logger.warn("Failed to download/extract Batik from $currentUrl: ${e.message} (${e.javaClass.simpleName})") - } - } - - if (!downloaded) { - if (batikJar.exists()){ - project.logger.warn("Batik download failed from all sources, but a previous version exists at ${batikJar.absolutePath}. Using existing.") - } else { - throw GradleException("Failed to download Batik from all sources and no local copy found at ${batikJar.path}.") - } - } - } else { - project.logger.info("Batik JAR already exists at ${batikJar.absolutePath}. Skipping download.") - } +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) } - } val coreJar = file("../../../core/library/core.jar") + +dependencies { + implementation(project(":core")) + implementation(files(batikJar)) +} + tasks.register("checkCore") { doFirst { - if (!coreJar.exists()) { throw GradleException("Missing core.jar at $coreJar. Please build the core module first.") } } } +tasks.register("svgJar") { + dependsOn("checkCore", "classes") + archiveBaseName.set("svg") + destinationDirectory.set(file("library")) + from(sourceSets.main.get().output) +} +// Batik configuration +val batikVersion = "1.19" +val batikZip = "batik-bin-$batikVersion.zip" +val batikJarName = "batik-all-$batikVersion.jar" +val batikJar = file("library/batik.jar") -dependencies { - implementation(files(coreJar)) - implementation(files(batikJar)) +// URLs +val batikUrl = "https://dlcdn.apache.org/xmlgraphics/batik/binaries/$batikZip" +val batikBackupUrl = "https://download.processing.org/batik/$batikZip" -} +val downloadBatik by tasks.registering { + outputs.file(batikJar) -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) + doLast { + if (batikJar.exists()) { + logger.lifecycle("Batik JAR already exists at ${batikJar.absolutePath}, skipping download.") + return@doLast + } + + val urlsToTry = listOf(batikUrl, batikBackupUrl) + val zipFile = layout.buildDirectory.file(batikZip).get().asFile + + zipFile.parentFile.mkdirs() + + val success = urlsToTry.any { url -> + try { + logger.lifecycle("Trying to download Batik from $url") + URI(url).toURL().openStream().use { input -> + zipFile.outputStream().use { output -> + input.copyTo(output) + } + } + logger.lifecycle("Downloaded Batik zip to ${zipFile.absolutePath}") + + copy { + from(zipTree(zipFile)) + include("**/lib/$batikJarName") + into(batikJar.parentFile) + rename { batikJar.name } + } + + logger.lifecycle("Extracted $batikJarName to ${batikJar.absolutePath}") + zipFile.delete() // Optional cleanup + true + } 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.named("compileJava") { - dependsOn(downloadBatik) + dependsOn(downloadBatik, "checkCore") options.encoding = "UTF-8" + classpath += files(batikJar) } @@ -106,6 +108,26 @@ tasks.named("compileJava") { tasks.named("jar") { archiveBaseName.set("svg") destinationDirectory.set(file("library")) + from(sourceSets.main.get().output) + manifest { + attributes( + "Implementation-Title" to "Processing SVG Library", + "Implementation-Version" to project.version + ) + } +} + +sourceSets { + main { + java { + srcDirs("src") + include("**/*.java") // Explicitly include all Java files + } + resources { + srcDirs("src") + include("**/*.properties") // Include any properties files if needed + } + } } tasks.named("clean") { From fa366cedd9321483bf80b1fedadf8d982b93bb49 Mon Sep 17 00:00:00 2001 From: jishnunambiarr Date: Sun, 25 May 2025 01:05:38 +0200 Subject: [PATCH 5/8] Updated build.gradle.kts: Batik jar added to classpath. Reduced redundancy --- java/libraries/svg/build.gradle.kts | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/java/libraries/svg/build.gradle.kts b/java/libraries/svg/build.gradle.kts index cb68a712c..83b232aeb 100644 --- a/java/libraries/svg/build.gradle.kts +++ b/java/libraries/svg/build.gradle.kts @@ -7,10 +7,8 @@ plugins { repositories { mavenCentral() - google() } - java { toolchain { languageVersion.set(JavaLanguageVersion.of(17)) @@ -50,6 +48,7 @@ val batikJar = file("library/batik.jar") val batikUrl = "https://dlcdn.apache.org/xmlgraphics/batik/binaries/$batikZip" val batikBackupUrl = "https://download.processing.org/batik/$batikZip" +// Storing a copy locally in case the main URL goes dead val downloadBatik by tasks.registering { outputs.file(batikJar) @@ -82,7 +81,7 @@ val downloadBatik by tasks.registering { } logger.lifecycle("Extracted $batikJarName to ${batikJar.absolutePath}") - zipFile.delete() // Optional cleanup + zipFile.delete() true } catch (e: Exception) { logger.warn("Failed to download from $url: ${e.message}") @@ -101,35 +100,24 @@ tasks.named("compileJava") { dependsOn(downloadBatik, "checkCore") options.encoding = "UTF-8" classpath += files(batikJar) -} - +} tasks.named("jar") { archiveBaseName.set("svg") destinationDirectory.set(file("library")) from(sourceSets.main.get().output) - manifest { - attributes( - "Implementation-Title" to "Processing SVG Library", - "Implementation-Version" to project.version - ) - } } sourceSets { main { java { srcDirs("src") - include("**/*.java") // Explicitly include all Java files - } - resources { - srcDirs("src") - include("**/*.properties") // Include any properties files if needed } } } +// Cleanup tasks.named("clean") { delete("bin", "library/svg.jar") } \ No newline at end of file From 573569fd991932ff9093389c2580d0cd07feb7b6 Mon Sep 17 00:00:00 2001 From: jishnunambiarr Date: Sun, 25 May 2025 01:09:37 +0200 Subject: [PATCH 6/8] Removed old build file --- java/libraries/svg/build.xml | 83 ------------------------------------ 1 file changed, 83 deletions(-) delete mode 100644 java/libraries/svg/build.xml diff --git a/java/libraries/svg/build.xml b/java/libraries/svg/build.xml deleted file mode 100644 index cb674f9e5..000000000 --- a/java/libraries/svg/build.xml +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 0662e31fec9404c981a0909ae79f581a357bf129 Mon Sep 17 00:00:00 2001 From: jishnunambiarr Date: Sun, 25 May 2025 02:20:55 +0200 Subject: [PATCH 7/8] Updated build.gradle.kts --- java/libraries/svg/build.gradle.kts | 99 +++++++++++++++-------------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/java/libraries/svg/build.gradle.kts b/java/libraries/svg/build.gradle.kts index 83b232aeb..c77479d1b 100644 --- a/java/libraries/svg/build.gradle.kts +++ b/java/libraries/svg/build.gradle.kts @@ -4,7 +4,6 @@ plugins { id("java-library") } - repositories { mavenCentral() } @@ -16,73 +15,54 @@ java { } val coreJar = file("../../../core/library/core.jar") - - -dependencies { - implementation(project(":core")) - implementation(files(batikJar)) -} - -tasks.register("checkCore") { - doFirst { - if (!coreJar.exists()) { - throw GradleException("Missing core.jar at $coreJar. Please build the core module first.") - } - } -} - -tasks.register("svgJar") { - dependsOn("checkCore", "classes") - archiveBaseName.set("svg") - destinationDirectory.set(file("library")) - from(sourceSets.main.get().output) -} - -// Batik configuration val batikVersion = "1.19" val batikZip = "batik-bin-$batikVersion.zip" -val batikJarName = "batik-all-$batikVersion.jar" val batikJar = file("library/batik.jar") -// URLs -val batikUrl = "https://dlcdn.apache.org/xmlgraphics/batik/binaries/$batikZip" +val batikUrl = "https://dlcdn.apache.org//xmlgraphics/batik/binaries/$batikZip" val batikBackupUrl = "https://download.processing.org/batik/$batikZip" -// Storing a copy locally in case the main URL goes dead val downloadBatik by tasks.registering { outputs.file(batikJar) doLast { if (batikJar.exists()) { - logger.lifecycle("Batik JAR already exists at ${batikJar.absolutePath}, skipping download.") + logger.lifecycle("Batik JAR already exists, skipping download.") return@doLast } + batikJar.parentFile.mkdirs() + val zipFile = file(batikZip) val urlsToTry = listOf(batikUrl, batikBackupUrl) - val zipFile = layout.buildDirectory.file(batikZip).get().asFile - - zipFile.parentFile.mkdirs() val success = urlsToTry.any { url -> try { - logger.lifecycle("Trying to download Batik from $url") + logger.lifecycle("Downloading Batik from $url") URI(url).toURL().openStream().use { input -> zipFile.outputStream().use { output -> input.copyTo(output) } } - logger.lifecycle("Downloaded Batik zip to ${zipFile.absolutePath}") - copy { - from(zipTree(zipFile)) - include("**/lib/$batikJarName") + from(zipTree(zipFile)) { + include("batik-$batikVersion/lib/batik-all-$batikVersion.jar") + } into(batikJar.parentFile) - rename { batikJar.name } + eachFile { + path = batikJar.name + } + includeEmptyDirs = false } - logger.lifecycle("Extracted $batikJarName to ${batikJar.absolutePath}") zipFile.delete() - true + + 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 @@ -95,29 +75,50 @@ val downloadBatik by tasks.registering { } } +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)) +} tasks.named("compileJava") { dependsOn(downloadBatik, "checkCore") options.encoding = "UTF-8" - classpath += files(batikJar) - } tasks.named("jar") { + dependsOn("checkCore") archiveBaseName.set("svg") destinationDirectory.set(file("library")) from(sourceSets.main.get().output) } -sourceSets { - main { - java { - srcDirs("src") - } - } +tasks.register("svgJar") { + dependsOn("checkCore", "classes") + archiveBaseName.set("svg") + destinationDirectory.set(file("library")) + from(sourceSets.main.get().output) } -// Cleanup tasks.named("clean") { delete("bin", "library/svg.jar") +} + +tasks.register("cleanLibs") { + delete(batikJar) } \ No newline at end of file From 9c5b56fd3f4258138329670b606041f86b9d0291 Mon Sep 17 00:00:00 2001 From: jishnunambiarr Date: Sun, 25 May 2025 09:55:58 +0200 Subject: [PATCH 8/8] Updated build.gradle.kts --- java/libraries/svg/build.gradle.kts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/java/libraries/svg/build.gradle.kts b/java/libraries/svg/build.gradle.kts index c77479d1b..e8d6a8378 100644 --- a/java/libraries/svg/build.gradle.kts +++ b/java/libraries/svg/build.gradle.kts @@ -16,12 +16,23 @@ java { 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) @@ -96,6 +107,7 @@ dependencies { implementation(files(batikJar)) } +// Compile sources tasks.named("compileJava") { dependsOn(downloadBatik, "checkCore") options.encoding = "UTF-8" @@ -115,10 +127,12 @@ tasks.register("svgJar") { from(sourceSets.main.get().output) } +// Clean the build directories tasks.named("clean") { delete("bin", "library/svg.jar") } + tasks.register("cleanLibs") { delete(batikJar) } \ No newline at end of file