From de25cb91804e36a31d3df0ecb6a5ead70e3fdb43 Mon Sep 17 00:00:00 2001 From: palexdev Date: Tue, 17 Oct 2023 10:50:32 +0200 Subject: [PATCH] :construction_worker: Import build scripts from `rewrite` branch Signed-off-by: palexdev --- build.gradle | 4 ++ materialfx/build.gradle | 6 +- {demo/scripts => scripts}/JLinkPackage.sh | 2 + scripts/processCSS.gradle | 47 +++++++++++++ scripts/updateJFXRes.gradle | 83 +++++++++++++++++++++++ 5 files changed, 141 insertions(+), 1 deletion(-) rename {demo/scripts => scripts}/JLinkPackage.sh (97%) mode change 100755 => 100644 create mode 100644 scripts/processCSS.gradle create mode 100644 scripts/updateJFXRes.gradle diff --git a/build.gradle b/build.gradle index 73949b1c..971672d7 100755 --- a/build.gradle +++ b/build.gradle @@ -6,6 +6,10 @@ plugins { group 'io.github.palexdev' version "$materialfx" +ext { + scriptsDir = "$rootDir/scripts" +} + repositories { mavenCentral() } diff --git a/materialfx/build.gradle b/materialfx/build.gradle index c12e73d4..333d8f69 100755 --- a/materialfx/build.gradle +++ b/materialfx/build.gradle @@ -7,6 +7,10 @@ plugins { id 'com.github.johnrengelman.shadow' version "$shadowJarPlugin" } +// Cross-platform scripts +apply from: "$scriptsDir/updateJFXRes.gradle" +apply from: "$scriptsDir/processCSS.gradle" + repositories { mavenCentral() @@ -104,4 +108,4 @@ build { mavenPublish { sonatypeHost = "S01" -} +} \ No newline at end of file diff --git a/demo/scripts/JLinkPackage.sh b/scripts/JLinkPackage.sh old mode 100755 new mode 100644 similarity index 97% rename from demo/scripts/JLinkPackage.sh rename to scripts/JLinkPackage.sh index 2243157b..59ff0794 --- a/demo/scripts/JLinkPackage.sh +++ b/scripts/JLinkPackage.sh @@ -23,6 +23,8 @@ # I was tired of Gradle shit and also tired of learning about boring Linux commands stuff (the tar command is quantum physic # and the zip command on the other hand is very limited) so this is the quickest solution I came up with +# TODO make this cross platform too + BASE_DIR=$1 IMG_DIR="${BASE_DIR}/image" OUT_DIR="${BASE_DIR}/distributions" diff --git a/scripts/processCSS.gradle b/scripts/processCSS.gradle new file mode 100644 index 00000000..e45365f8 --- /dev/null +++ b/scripts/processCSS.gradle @@ -0,0 +1,47 @@ +import groovy.transform.Field +import org.apache.tools.ant.taskdefs.condition.Os + +// Special handling for Windows. Fuck. This. Shit. +@Field var isWindows = (Os.isFamily(Os.FAMILY_WINDOWS)) + +tasks.register("processCSS") { + doLast { + def rootDir = rootProject.projectDir.absolutePath + def resDir = "$rootDir/materialfx/src/main/resources/io/github/palexdev/materialfx" + List themesDirs = new ArrayList<>() + new File(resDir).eachFile { + if (it.isDirectory() && it.name != "jfx") themesDirs += it + } + + // Check if npm and cssbeautify-cli are installed on the host + if (!execute("npm -v")) throw new GradleException("npm command could not be found") + if (!execute("cssbeautify-cli -v")) throw new GradleException("cssbeautify-cli command could not be found") + logger.warn("All dependencies have been found") + + themesDirs.each { dir -> + dir.eachFileRecurse { + def name = it.name + def path = it.absolutePath + def parent = it.parent + if (name.endsWith(".css")) { // Unfortunately, doesn't run very well o SCSS files + logger.warn("Beautifying: $name") + def tmp = new File("${path}.tmp") + it.renameTo(tmp) + def beautifyCommand = "cssbeautify-cli -a -i2 -f ${path}.tmp -w $parent/$name" + execute(beautifyCommand) + delete(tmp) + } + } + } + } +} + +boolean execute(String str) { + if (isWindows) str = "cmd /c " + str // Prepend call to cmd + Process proc = new ProcessBuilder().with { + command str.split(" ") + redirectOutput(ProcessBuilder.Redirect.DISCARD) + }.start() + proc.waitForOrKill(10_000) + return proc.exitValue() == 0 +} \ No newline at end of file diff --git a/scripts/updateJFXRes.gradle b/scripts/updateJFXRes.gradle new file mode 100644 index 00000000..b5b7c76d --- /dev/null +++ b/scripts/updateJFXRes.gradle @@ -0,0 +1,83 @@ +import groovy.transform.Field +import org.apache.tools.ant.taskdefs.condition.Os + +import java.nio.file.Files +import java.nio.file.StandardCopyOption + +// Special handling for Windows. Fuck. This. Shit. +@Field var isWindows = (Os.isFamily(Os.FAMILY_WINDOWS)) + +tasks.register("updateJFXRes") { + doLast { + def rootDir = rootProject.projectDir.absolutePath + def resDir = "$rootDir/materialfx/src/main/resources/io/github/palexdev/materialfx/css/jfx" + def caspianDir = "$resDir/caspian" + def modenaDir = "$resDir/modena" + + // Check if svn, npm, csso and cssbeautify-cli are installed on the host + if (!execute("svn help")) throw new GradleException("svn command could not be found") + if (!execute("npm -v")) throw new GradleException("npm command could not be found") + if (!execute("csso -v")) throw new GradleException("csso command could not be found") + if (!execute("cssbeautify-cli -v")) throw new GradleException("cssbeautify-cli command could not be found") + logger.warn("All dependencies have been found") + + // Download the whole repository to a temp dir + def tmpDir = Files.createTempDirectory("gradle.tmp").toString() + def svnCommand = "svn export --force https://github.com/openjdk/jfx.git/trunk/modules/javafx.controls/src/main/resources/com/sun/javafx/scene/control/skin $tmpDir" + logger.warn("Executing svn command") + execute(svnCommand) + + // Move the required files to their respective directories + logger.warn("Processing Caspian resources") + processCssFiles(new File(tmpDir, "caspian"), new File(caspianDir)) + logger.warn("Zipping Caspian resources") + ant.zip(destfile: new File(caspianDir, "assets.zip")) { + fileset(dir: new File(caspianDir, "assets/")) + } + delete(new File(caspianDir, "assets")) + + logger.warn("Processing Modena resources") + processCssFiles(new File(tmpDir, "modena"), new File(modenaDir)) + logger.warn("Zipping Modena resources") + ant.zip(destfile: new File(modenaDir, "assets.zip")) { + fileset(dir: new File(modenaDir, "assets/")) + } + delete(new File(modenaDir, "assets")) + + delete(tmpDir) + logger.warn("JavaFX resources have been updated successfully") + } +} + +boolean execute(String str) { + if (isWindows) str = "cmd /c " + str // Prepend call to cmd + Process proc = new ProcessBuilder().with { + command str.split(" ") + redirectOutput(ProcessBuilder.Redirect.DISCARD) + }.start() + proc.waitForOrKill(10_000) + return proc.exitValue() == 0 +} + +void processCssFiles(File source, File dest) { + source.eachFile { + if (it.name.endsWith(".css")) { + // Optimize + def cssoCommand = "csso $it.absolutePath -o $it.absolutePath --no-restructure" + logger.debug(cssoCommand) + execute(cssoCommand) + + // Beautify + def beautifyCommand = "cssbeautify-cli -a -i2 -f $it.absolutePath -w ${new File(dest, it.name)}" + logger.debug(beautifyCommand) + execute(beautifyCommand) + + it.delete() + } else { + def assetsDir = new File(dest, "assets") + assetsDir.mkdirs() + Files.copy(it.toPath(), new File(dest, "assets/$it.name").toPath(), StandardCopyOption.REPLACE_EXISTING) + it.delete() + } + } +} \ No newline at end of file