From 54d97c51f18caea98666f238bc815a3f4c27e572 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 26 May 2021 21:58:32 +0100 Subject: [PATCH 1/5] Initial attempt --- buildSrc/src/main/groovy/DownloadTask.groovy | 17 ++++++++++++++++ common/build.gradle | 20 ++++++++++++++----- .../stickyapi/common/util/TextUtil.java | 2 +- 3 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 buildSrc/src/main/groovy/DownloadTask.groovy diff --git a/buildSrc/src/main/groovy/DownloadTask.groovy b/buildSrc/src/main/groovy/DownloadTask.groovy new file mode 100644 index 00000000..80dada03 --- /dev/null +++ b/buildSrc/src/main/groovy/DownloadTask.groovy @@ -0,0 +1,17 @@ +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction + +class DownloadTask extends DefaultTask { + @Input + String from + + @OutputFile + File destination + + @TaskAction + void download() { + ant.get(src: from, dest: destination) + } +} \ No newline at end of file diff --git a/common/build.gradle b/common/build.gradle index 6a5d3468..9d33b548 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -15,9 +15,6 @@ dependencies { // testRuntimeOnly = only accessible during the test job testRuntimeOnly "org.yaml:snakeyaml:1.27" - // Font width data (see above) - dddResource "dumbdogdiner:mc-font-extractor:main:mojangles_width_data@json" - implementation "com.google.code.gson:gson:2.8.7" // Dependencies available in both bukkit and bungee @@ -88,7 +85,7 @@ compileJava.source = processSourceTokens.outputs This task serves to copy width data from the default Minecraft font into the final jar. This data is generated by . */ - +/* // Font Width Info task copyMCFontExtractor(type: Copy) { def path = project.configurations.dddResource.find {it.name.startsWith("mc-font-extractor") } @@ -100,9 +97,22 @@ task copyMCFontExtractor(type: Copy) { destinationDir file("src/main/resources/generated/") rename "mc-font-extractor-main-mojangles_width_data.json", "mojangles_width_data.json" } +*/ +task downloadWidthData(type: DownloadTask) { + from "https://dumbdogdiner.github.io/mc-font-extractor/main/mojangles_width_data.json" + destination file("build/gen-src/generated/mojangles_width_data.json") +} + +processResources { + from("build/gen-src") +} + +processTestResources { + from("build/gen-src") +} // Run the font data copier -tasks.processResources.dependsOn copyMCFontExtractor +tasks.processResources.dependsOn downloadWidthData // Common build: create a jar from the :common & :common:serverversion projects diff --git a/common/src/main/java/com/dumbdogdiner/stickyapi/common/util/TextUtil.java b/common/src/main/java/com/dumbdogdiner/stickyapi/common/util/TextUtil.java index 1ca0d78a..8d314082 100644 --- a/common/src/main/java/com/dumbdogdiner/stickyapi/common/util/TextUtil.java +++ b/common/src/main/java/com/dumbdogdiner/stickyapi/common/util/TextUtil.java @@ -64,7 +64,7 @@ private static class WidthEntry { static { Gson gson = new Gson(); - try (InputStream input = ClassLoader.getSystemResource("generated/mojangles_width_data.json").openStream()) { + try (InputStream input = TextUtil.class.getResourceAsStream("generated/mojangles_width_data.json")) { WidthEntry[] entries = gson.fromJson(new InputStreamReader(input), WidthEntry[].class); for (WidthEntry entry : entries) { if (entry.getId() == null) entry.setId(0); From 650ce0d0ed57bb8cda9611c0c67606e4c261d6d4 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 26 May 2021 22:06:39 +0100 Subject: [PATCH 2/5] Add a leading / --- .../java/com/dumbdogdiner/stickyapi/common/util/TextUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/com/dumbdogdiner/stickyapi/common/util/TextUtil.java b/common/src/main/java/com/dumbdogdiner/stickyapi/common/util/TextUtil.java index 8d314082..4101d314 100644 --- a/common/src/main/java/com/dumbdogdiner/stickyapi/common/util/TextUtil.java +++ b/common/src/main/java/com/dumbdogdiner/stickyapi/common/util/TextUtil.java @@ -64,7 +64,7 @@ private static class WidthEntry { static { Gson gson = new Gson(); - try (InputStream input = TextUtil.class.getResourceAsStream("generated/mojangles_width_data.json")) { + try (InputStream input = TextUtil.class.getResourceAsStream("/generated/mojangles_width_data.json")) { WidthEntry[] entries = gson.fromJson(new InputStreamReader(input), WidthEntry[].class); for (WidthEntry entry : entries) { if (entry.getId() == null) entry.setId(0); From 0b42752585362448dcc17b0c019b4f7bb982010d Mon Sep 17 00:00:00 2001 From: James Date: Wed, 26 May 2021 22:10:31 +0100 Subject: [PATCH 3/5] Remove processTestResources (not needed); old code --- common/build.gradle | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/common/build.gradle b/common/build.gradle index 9d33b548..8d83aa3c 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -85,32 +85,16 @@ compileJava.source = processSourceTokens.outputs This task serves to copy width data from the default Minecraft font into the final jar. This data is generated by . */ -/* -// Font Width Info -task copyMCFontExtractor(type: Copy) { - def path = project.configurations.dddResource.find {it.name.startsWith("mc-font-extractor") } - println("common: Found font data at: " + path) - from file(path) - // into file("src/main/resources") - // - Please keep this comment for future reference. - // - This is how we would do this if we weren't also adding build info (see processSourceTokens, above comments) - destinationDir file("src/main/resources/generated/") - rename "mc-font-extractor-main-mojangles_width_data.json", "mojangles_width_data.json" -} -*/ task downloadWidthData(type: DownloadTask) { from "https://dumbdogdiner.github.io/mc-font-extractor/main/mojangles_width_data.json" destination file("build/gen-src/generated/mojangles_width_data.json") } +// Font Width Info: Switch resources folder processResources { from("build/gen-src") } -processTestResources { - from("build/gen-src") -} - // Run the font data copier tasks.processResources.dependsOn downloadWidthData From f63810dfeee7bab1e7730839538872711756a353 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 26 May 2021 22:15:40 +0100 Subject: [PATCH 4/5] Update dependsOn to reference new task --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index d492510c..f97598ed 100644 --- a/build.gradle +++ b/build.gradle @@ -271,7 +271,7 @@ dependencies { // Root build: create uber sources from subproject sources task rootSources(type: Jar, dependsOn: subprojects.classes) { // Gradle 7 implicit dependency fix: depend on special common tasks - dependsOn(":common:copyMCFontExtractor") + dependsOn(":common:downloadWidthData") dependsOn(":common:commonSources") archiveClassifier.set("sources") @@ -291,7 +291,7 @@ task rootTestReport(type: TestReport) { // Create a libs/modules folder with submodule jars task copySubprojectJars(type: Copy, dependsOn: subprojects.jar) { // Gradle 7 implicit dependency fix: depend on special common tasks - dependsOn(":common:copyMCFontExtractor") + dependsOn(":common:downloadWidthData") dependsOn(":common:commonSources") // Copy subproject jar and sources From 74fb4b3344b10600f85036634f97b59fa28457e2 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 26 May 2021 22:19:19 +0100 Subject: [PATCH 5/5] Remove old ivy repo, filter & configuration --- build.gradle | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/build.gradle b/build.gradle index f97598ed..5638c284 100644 --- a/build.gradle +++ b/build.gradle @@ -163,28 +163,12 @@ subprojects { jaxDoclet // give test dependencies access to compileOnly dependencies to emulate providedCompile testImplementation.extendsFrom compileOnly - - dddResource // custom configuration for our ivy resources (eg. font info) - dddResource.description = "Resources (eg. yml or json data) to be included in jar builds" } repositories { // Maven Central is defined in allprojects (for JaCoCo) maven { url "https://oss.sonatype.org/content/repositories/snapshots" } maven { url "https://papermc.io/repo/repository/maven-public/" } - - // Note: Subprojects can't have repo overrides to we have to put it here - // Define a Ivy repo for the font width data (that way we don't need another plugin!) - def dddResources = ivy { - url "https://dumbdogdiner.github.io/" - patternLayout { artifact "/[module]/[revision]/[classifier].[ext]"} - metadataSources { artifact() } - } - // Only use the Ivy repo for font width data - speeds up dependency resolution - exclusiveContent { - forRepositories(dddResources) - filter { includeGroup("dumbdogdiner") } - } } dependencies {