From 4adb11dada29ac6ca2d12270fd7e617007ff9bf3 Mon Sep 17 00:00:00 2001 From: AsamK Date: Sat, 23 Jan 2021 15:55:41 +0100 Subject: [PATCH] Convert gradle scripts to kotlin --- build.gradle | 113 ---------------------- build.gradle.kts | 129 +++++++++++++++++++++++++ settings.gradle => settings.gradle.kts | 0 3 files changed, 129 insertions(+), 113 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts rename settings.gradle => settings.gradle.kts (100%) diff --git a/build.gradle b/build.gradle deleted file mode 100644 index f3475343..00000000 --- a/build.gradle +++ /dev/null @@ -1,113 +0,0 @@ -plugins { - id "java" - id "application" - id "eclipse" -} - -sourceCompatibility = JavaVersion.VERSION_11 -targetCompatibility = JavaVersion.VERSION_11 - -mainClassName = "org.asamk.signal.Main" - -version = "0.7.4" - -compileJava.options.encoding = "UTF-8" - -repositories { - mavenLocal() - mavenCentral() -} - -dependencies { - implementation("com.google.protobuf:protobuf-javalite:3.10.0") - implementation("com.github.turasa:signal-service-java:2.15.3_unofficial_18") - implementation("org.bouncycastle:bcprov-jdk15on:1.68") - implementation("net.sourceforge.argparse4j:argparse4j:0.8.1") - implementation("com.github.hypfvieh:dbus-java:3.2.4") - implementation("org.slf4j:slf4j-simple:1.7.30") -} - -jar { - manifest { - attributes( - "Implementation-Title": project.name, - "Implementation-Version": project.version, - "Main-Class": project.mainClassName, - ) - } -} - -run { - if (project.hasProperty("appArgs")) { - // allow passing command-line arguments to the main application e.g.: - // $ gradle run -PappArgs="['-u', '+...', 'daemon', '--json']" - args(Eval.me(appArgs)) - } -} - -// Find any 3rd party libraries which have released new versions -// to the central Maven repo since we last upgraded. -task checkLibVersions { - doLast { - def checked = [:] - allprojects { - configurations.each { configuration -> - configuration.allDependencies.each { dependency -> - def version = dependency.version - if (!checked[dependency]) { - def group = dependency.group - def path = group.replace(".", "/") - def name = dependency.name - def url = "https://repo1.maven.org/maven2/$path/$name/maven-metadata.xml" - try { - def metadata = new XmlSlurper().parseText(url.toURL().text) - def newest = metadata.versioning.latest; - if ("$version" != "$newest") { - println("UPGRADE {\"group\": \"$group\", \"name\": \"$name\", \"current\": \"$version\", \"latest\": \"$newest\"}") - } - } catch (FileNotFoundException e) { - logger.debug("Unable to download $url: $e.message") - } catch (org.xml.sax.SAXParseException e) { - logger.debug("Unable to parse $url: $e.message") - } - checked[dependency] = true - } - } - } - } - } -} - -task assembleNativeImage { - dependsOn("assemble") - doLast { - def graalVMHome = System.getenv("GRAALVM_HOME") - if (!graalVMHome) { - throw new GradleException("Required GRAALVM_HOME environment variable not set.") - } - def nativeBinaryOutputPath = "$buildDir/native-image" - def nativeBinaryName = "signal-cli" - - mkdir(nativeBinaryOutputPath) - - exec { - workingDir = "." - commandLine("$graalVMHome/bin/native-image", - "-H:Path=$nativeBinaryOutputPath", - "-H:Name=$nativeBinaryName", - "-H:JNIConfigurationFiles=graalvm-config-dir/jni-config.json", - "-H:DynamicProxyConfigurationFiles=graalvm-config-dir/proxy-config.json", - "-H:ResourceConfigurationFiles=graalvm-config-dir/resource-config.json", - "-H:ReflectionConfigurationFiles=graalvm-config-dir/reflect-config.json", - "--no-fallback", - "--allow-incomplete-classpath", - "--report-unsupported-elements-at-runtime", - "--enable-url-protocols=http,https", - "--enable-https", - "--enable-all-security-services", - "-cp", - sourceSets.main.runtimeClasspath.asPath, - project.mainClassName) - } - } -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..b2bd53e4 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,129 @@ +plugins { + java + application + eclipse +} + +version = "0.7.4" + +java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 +} + +application { + mainClass.set("org.asamk.signal.Main") +} + +repositories { + mavenLocal() + mavenCentral() +} + +dependencies { + implementation("com.google.protobuf:protobuf-javalite:3.10.0") + implementation("com.github.turasa:signal-service-java:2.15.3_unofficial_18") + implementation("org.bouncycastle:bcprov-jdk15on:1.68") + implementation("net.sourceforge.argparse4j:argparse4j:0.8.1") + implementation("com.github.hypfvieh:dbus-java:3.2.4") + implementation("org.slf4j:slf4j-simple:1.7.30") +} + +configurations { + implementation { + resolutionStrategy.failOnVersionConflict() + } +} + +tasks.withType { + options.encoding = "UTF-8" +} + +tasks.withType { + manifest { + attributes( + "Implementation-Title" to project.name, + "Implementation-Version" to project.version, + "Main-Class" to application.mainClass.get() + ) + } +} + +tasks.withType { + val appArgs: String? by project + if (appArgs != null) { + // allow passing command-line arguments to the main application e.g.: + // $ gradle run -PappArgs="['-u', '+...', 'daemon', '--json']" + args = groovy.util.Eval.me(appArgs) as MutableList + } +} + +// Find any 3rd party libraries which have released new versions +// to the central Maven repo since we last upgraded. +val checkLibVersions by tasks.registering { + doLast { + val checked = kotlin.collections.HashSet() + allprojects { + configurations.forEach { configuration -> + configuration.allDependencies.forEach { dependency -> + val version = dependency.version + if (!checked.contains(dependency)) { + val group = dependency.group + val path = group?.replace(".", "/") ?: "" + val name = dependency.name + val metaDataUrl = "https://repo1.maven.org/maven2/$path/$name/maven-metadata.xml" + try { + val url = org.codehaus.groovy.runtime.ResourceGroovyMethods.toURL(metaDataUrl) + val metaDataText = org.codehaus.groovy.runtime.ResourceGroovyMethods.getText(url) + val metadata = groovy.util.XmlSlurper().parseText(metaDataText) + val newest = (metadata.getProperty("versioning") as groovy.util.slurpersupport.GPathResult).getProperty("latest") + if (version != newest.toString()) { + println("UPGRADE {\"group\": \"$group\", \"name\": \"$name\", \"current\": \"$version\", \"latest\": \"$newest\"}") + } + } catch (e: Throwable) { + logger.debug("Unable to download or parse $metaDataUrl: $e.message") + } + checked.add(dependency) + } + } + } + } + } +} + +val assembleNativeImage by tasks.registering { + dependsOn("assemble") + + var graalVMHome = "" + doFirst { + graalVMHome = System.getenv("GRAALVM_HOME") + ?: throw GradleException("Required GRAALVM_HOME environment variable not set.") + } + + doLast { + val nativeBinaryOutputPath = "$buildDir/native-image" + val nativeBinaryName = "signal-cli" + + mkdir(nativeBinaryOutputPath) + + exec { + workingDir = File(".") + commandLine("$graalVMHome/bin/native-image", + "-H:Path=$nativeBinaryOutputPath", + "-H:Name=$nativeBinaryName", + "-H:JNIConfigurationFiles=graalvm-config-dir/jni-config.json", + "-H:DynamicProxyConfigurationFiles=graalvm-config-dir/proxy-config.json", + "-H:ResourceConfigurationFiles=graalvm-config-dir/resource-config.json", + "-H:ReflectionConfigurationFiles=graalvm-config-dir/reflect-config.json", + "--no-fallback", + "--allow-incomplete-classpath", + "--report-unsupported-elements-at-runtime", + "--enable-url-protocols=http,https", + "--enable-https", + "--enable-all-security-services", + "-cp", + sourceSets.main.get().runtimeClasspath.asPath, + application.mainClass.get()) + } + } +} diff --git a/settings.gradle b/settings.gradle.kts similarity index 100% rename from settings.gradle rename to settings.gradle.kts -- 2.50.1