HMCL/build.gradle

221 lines
6.1 KiB
Groovy
Raw Normal View History

2018-12-08 21:00:23 +08:00
buildscript {
repositories {
2021-08-20 15:58:44 +08:00
mavenCentral()
2018-12-08 21:00:23 +08:00
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath group: 'com.google.code.gson', name: 'gson', version: '2.8.1'
}
2018-12-08 21:00:23 +08:00
}
2021-05-30 03:34:44 +08:00
plugins {
id 'checkstyle'
}
2018-12-08 21:00:23 +08:00
group 'org.jackhuang'
version '3.0'
subprojects {
apply plugin: 'java'
apply plugin: 'idea'
2020-08-11 11:25:23 +08:00
apply plugin: 'maven-publish'
2021-05-30 03:34:44 +08:00
apply plugin: 'checkstyle'
2018-12-08 21:00:23 +08:00
repositories {
flatDir name: 'libs', dirs: rootProject.file('lib')
2018-12-08 21:00:23 +08:00
mavenCentral()
maven { url 'https://jitpack.io' }
}
checkstyle {
sourceSets = []
}
2021-09-06 00:45:25 +08:00
tasks.withType(Checkstyle) {
exclude 'de/javawi/jstun'
}
2018-12-08 21:00:23 +08:00
sourceCompatibility = 1.8
compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'
2018-12-08 21:00:23 +08:00
}
2020-08-11 11:25:23 +08:00
publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
repositories {
mavenLocal()
}
}
2018-12-08 21:00:23 +08:00
}
2019-01-05 18:49:28 +08:00
defaultTasks 'clean', 'build'
2021-09-08 09:13:33 +08:00
var jfxModules = ['base', 'graphics', 'controls', 'fxml', 'media', 'web']
2021-09-07 20:07:11 +08:00
var jfxArches = ['linux', 'linux-arm32-monocle', 'linux-aarch64', 'mac', 'mac-aarch64', 'win', 'win-x86']
2021-09-08 09:13:33 +08:00
var jfxVersion = "17"
2021-09-07 21:35:35 +08:00
var jfxRepos = ['https://repo1.maven.org/maven2', 'https://maven.aliyun.com/repository/central']
var jfxDependenciesFile = file('HMCL/src/main/resources/assets/openjfx-dependencies.json')
2021-09-08 09:53:26 +08:00
var jfxUnsupported = [
'linux-arm32-monocle': ['media', 'web']
]
2021-09-07 21:35:35 +08:00
var jfxInClasspath = false
try {
Class.forName("javafx.application.Application", false, this.getClass().getClassLoader())
jfxInClasspath = true
} catch (Throwable ignored) {
}
if (!jfxInClasspath && JavaVersion.current() >= JavaVersion.VERSION_11) {
String os = null
String arch = null
String osName = System.getProperty("os.name").toLowerCase(Locale.US)
if (osName.contains("win"))
os = 'win'
else if (osName.contains("mac"))
os = 'mac'
else if (osName.contains("solaris") || osName.contains("linux") || osName.contains("unix") || osName.contains("sunos"))
os = 'linux'
else
os = null
String archName = System.getProperty("os.arch").toLowerCase(Locale.US)
switch (archName) {
case "x86_64":
case "x86-64":
case "amd64":
arch = ''
break
case "x86":
case "x86_32":
case "x86-32":
case "i386":
case "i486":
case "i586":
case "i686":
case "i86pc":
arch = '-x86'
break
case "aarch64":
arch = '-aarch64';
break
}
String platform = "$os$arch"
if (os != null && arch != null && jfxArches.contains(platform)) {
var jfxDependencies = jfxModules.collect { module -> "org.openjfx:javafx-$module:$jfxVersion:$platform" }
subprojects {
repositories {
mavenCentral()
}
dependencies {
jfxDependencies.forEach {
compileOnly it
}
}
}
}
}
2021-09-07 21:35:35 +08:00
import com.google.gson.*
task 'generateOpenJFXDependencies' {
doLast {
var jfxDependencies = new JsonArray()
jfxModules.forEach { module ->
JsonObject m = new JsonObject()
m.addProperty("module", "javafx.$module")
m.addProperty("groupId", "org.openjfx")
m.addProperty("artifactId", "javafx-$module")
m.addProperty("version", jfxVersion)
var sha1 = new JsonObject()
jfxArches.forEach { arch ->
2021-09-08 09:53:26 +08:00
if (jfxUnsupported.getOrDefault(arch, []).contains(module)) {
2021-09-07 21:35:35 +08:00
return
}
2021-09-08 09:53:26 +08:00
2021-09-07 21:35:35 +08:00
sha1.addProperty(
arch,
2021-09-08 09:38:45 +08:00
new URL("${jfxRepos.head()}/org/openjfx/javafx-$module/$jfxVersion/javafx-$module-$jfxVersion-${arch}.jar.sha1").getText("UTF-8")
2021-09-07 21:35:35 +08:00
)
}
m.add("sha1", sha1)
jfxDependencies.add(m)
}
2021-09-07 21:35:35 +08:00
jfxDependenciesFile.text = new GsonBuilder().setPrettyPrinting().create().toJson(jfxDependencies)
}
}
// Ensure that the mirror repository caches files
task 'preTouchOpenJFXDependencies' {
doLast {
2021-09-08 09:38:45 +08:00
jfxRepos.tail().forEach { repo ->
2021-09-07 21:35:35 +08:00
jfxModules.forEach { module ->
jfxArches.forEach { arch ->
2021-09-08 09:53:26 +08:00
if (jfxUnsupported.getOrDefault(arch, []).contains(module)) {
2021-09-07 21:35:35 +08:00
return
}
var jarUrl = "$repo/org/openjfx/javafx-$module/$jfxVersion/javafx-$module-$jfxVersion-${arch}.jar"
[jarUrl, jarUrl + ".sha1"].forEach { url ->
try {
new URL(url).getBytes()
System.out.println(url)
} catch (Throwable ignored) {
ignored.printStackTrace()
}
}
}
}
}
}
}
task 'checkTranslations' {
group 'verification'
doLast {
var en = new Properties()
var zh = new Properties()
var zh_CN = new Properties()
file("HMCL/src/main/resources/assets/lang/I18N.properties").withInputStream { en.load(it) }
file("HMCL/src/main/resources/assets/lang/I18N_zh.properties").withInputStream { zh.load(it) }
file("HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties").withInputStream { zh_CN.load(it) }
boolean success = true
zh_CN.forEach { k, v ->
if (!en.containsKey(k)) {
project.logger.log(LogLevel.WARN, "I18N.properties missing key '$k'")
success = false
}
}
zh_CN.forEach { k, v ->
if (!zh.containsKey(k)) {
project.logger.log(LogLevel.WARN, "I18N_zh.properties missing key '$k'")
success = false
}
}
if (!success) {
throw new GradleException("Part of the translation is missing")
}
}
}