👷 Import build scripts from rewrite branch

Signed-off-by: palexdev <alessandro.parisi406@gmail.com>
This commit is contained in:
palexdev 2023-10-17 10:50:32 +02:00
parent 156dc9713b
commit de25cb9180
5 changed files with 141 additions and 1 deletions

View File

@ -6,6 +6,10 @@ plugins {
group 'io.github.palexdev' group 'io.github.palexdev'
version "$materialfx" version "$materialfx"
ext {
scriptsDir = "$rootDir/scripts"
}
repositories { repositories {
mavenCentral() mavenCentral()
} }

View File

@ -7,6 +7,10 @@ plugins {
id 'com.github.johnrengelman.shadow' version "$shadowJarPlugin" id 'com.github.johnrengelman.shadow' version "$shadowJarPlugin"
} }
// Cross-platform scripts
apply from: "$scriptsDir/updateJFXRes.gradle"
apply from: "$scriptsDir/processCSS.gradle"
repositories { repositories {
mavenCentral() mavenCentral()
@ -104,4 +108,4 @@ build {
mavenPublish { mavenPublish {
sonatypeHost = "S01" sonatypeHost = "S01"
} }

View File

@ -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 # 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 # 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 BASE_DIR=$1
IMG_DIR="${BASE_DIR}/image" IMG_DIR="${BASE_DIR}/image"
OUT_DIR="${BASE_DIR}/distributions" OUT_DIR="${BASE_DIR}/distributions"

47
scripts/processCSS.gradle Normal file
View File

@ -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<File> 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
}

View File

@ -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()
}
}
}