From d423203d960e6e2340798f00f907d2b1271c3d89 Mon Sep 17 00:00:00 2001 From: nea Date: Thu, 8 Jun 2023 03:47:38 +0200 Subject: Use kotlin buildscript --- build.gradle | 156 --------------------- build.gradle.kts | 77 ++++++++++ buildSrc/build.gradle.kts | 23 +++ gradle/wrapper/gradle-wrapper.properties | 2 +- nosession_libc/build.gradle.kts | 60 ++++++++ nosession_libc/src/main/cpp/libc.cpp | 31 ++++ nosession_libc/src/main/cpp/libc.h | 29 ++++ settings.gradle.kts | 1 + src/main/cpp/libc.cpp | 31 ---- src/main/cpp/libc.h | 29 ---- .../nosession/linux/bwrap/BubblewrapBuilder.java | 2 +- .../gq/malwarefight/nosession/linux/libc/Libc.java | 2 +- .../gq/malwarefight/nosession/utils/Utils.java | 2 +- 13 files changed, 225 insertions(+), 220 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts create mode 100644 buildSrc/build.gradle.kts create mode 100644 nosession_libc/build.gradle.kts create mode 100644 nosession_libc/src/main/cpp/libc.cpp create mode 100644 nosession_libc/src/main/cpp/libc.h create mode 100644 settings.gradle.kts delete mode 100644 src/main/cpp/libc.cpp delete mode 100644 src/main/cpp/libc.h diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 9d62ac3..0000000 --- a/build.gradle +++ /dev/null @@ -1,156 +0,0 @@ -import org.gradle.internal.jvm.Jvm - -buildscript { - ext.kotlin_version = '1.8.21' - repositories { - //new forge repository - maven { url "https://maven.minecraftforge.net" } - maven { url 'https://jitpack.io/' } - mavenCentral() - mavenLocal() - } - dependencies { - classpath 'com.github.thefightagainstmalware:ForgeGradle:5a1fcb9' - classpath 'com.github.thefightagainstmalware:MixinGradle:92e66fe' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - -plugins { - id "java" - id 'cpp' -} - -apply plugin: 'net.minecraftforge.gradle.forge' -apply plugin: 'kotlin' -apply plugin: 'org.spongepowered.mixin' - -project.version = "1.2.0" -group = "gq.malwarefight.nosession" -archivesBaseName = "nosession" - -compileJava.sourceCompatibility = compileJava.targetCompatibility = 1.8 -compileJava.options.encoding = "UTF-8" - -minecraft { - version = "1.8.9-11.15.1.2318-1.8.9" - runDir = "run" - mappings = "stable_22" //mappings for 1.8.9 - makeObfSourceJar = false //disable creation of sources jar -} - -configurations { - shade - compile.extendsFrom(shade) -} - -repositories { - maven { url 'https://repo.spongepowered.org/maven/' } - maven { url 'https://maven.minecraftforge.net/' } - mavenCentral() -} - -dependencies { - compileOnly "net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9:universal" - shade('org.spongepowered:mixin:0.7.11-SNAPSHOT') { - exclude module: 'launchwrapper' - exclude module: 'guava' - exclude module: 'gson' - exclude module: 'commons-io' - exclude module: 'log4j-core' - } - - compileOnly 'org.spongepowered:mixin:0.7.11-SNAPSHOT' // why gradle why why why - annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" -} - -processResources { - duplicatesStrategy = DuplicatesStrategy.WARN - //replace stuff in mcmod.info, nothing else - from(sourceSets.main.resources.srcDirs) { - include "mcmod.info" - - //replace version and mcversion - expand "version":project.version, "mcversion":project.minecraft.version - } - - //copy everything else, that"s not the mcmod.info - from(sourceSets.main.resources.srcDirs) { - exclude "mcmod.info" - } - - rename '(.+_at.cfg)', 'META-INF/$1' -} - - -sourceSets { - main { - ext.refMap = "mixins.nosession.refmap.json" - } -} - -model { - components { - linux(NativeLibrarySpec) { - sources { - cpp { - source { - srcDir 'src/main/cpp' - include "libc.cpp" - } - } - } - buildTypes { - release - } - - binaries.all { - def jvmHome = Jvm.current().javaHome - if (targetPlatform.operatingSystem.macOsX) { - cppCompiler.args '-I', "${jvmHome}/include" - cppCompiler.args '-I', "${jvmHome}/include/darwin" - cppCompiler.args '-mmacosx-version-min=10.4' - linker.args '-mmacosx-version-min=10.4' - } else if (targetPlatform.operatingSystem.linux) { - cppCompiler.args '-I', "${jvmHome}/include" - cppCompiler.args '-I', "${jvmHome}/include/linux" - cppCompiler.args '-D_FILE_OFFSET_BITS=64' - } else if (targetPlatform.operatingSystem.windows) { - cppCompiler.args "-I${jvmHome}/include" - cppCompiler.args "-I${jvmHome}/include/win32" - } else if (targetPlatform.operatingSystem.freeBSD) { - cppCompiler.args '-I', "${jvmHome}/include" - cppCompiler.args '-I', "${jvmHome}/include/freebsd" - } - } - } - } -} - - -jar { - dependsOn project.configurations.compile - inputs.files {linuxSharedLibrary} - from("build/libs/linux/shared/" + System.mapLibraryName("linux")) { - into("native/" + System.getProperty("os.arch") + "/" + System.getProperty("os.name")) - } - - from { - project.configurations.compile.collect { - it.isDirectory() ? it : zipTree(it) - } - } - exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA', 'dummyThing' - manifest { - attributes "ForceLoadAsMod": true, - "TweakOrder": 0, - "ModSide": "CLIENT", - 'FMLCorePluginContainsFMLMod': true, - 'MixinConfigs': 'mixins.nosession.json', - "FMLCorePlugin": "gq.malwarefight.nosession.NoSessionLoadingPlugin" - } -} -kotlin { - jvmToolchain(11) -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..43f60dc --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,77 @@ +plugins { + java + id("net.minecraftforge.gradle.forge") + id("org.spongepowered.mixin") + kotlin("jvm") +} + +version = "1.2.0" +group = "gq.malwarefight.nosession" + +val kotlinVersion = "1.8.21" +val shade: Configuration by configurations.creating +configurations { + val compile by creating { + extendsFrom(shade) + } + implementation.get().extendsFrom(compile) +} + +minecraft { + version = "1.8.9-11.15.1.2318-1.8.9" + runDir = "run" + mappings = "stable_22" //mappings for 1.8.9 + makeObfSourceJar = false //disable creation of sources jar +} + + +repositories { + maven("https://repo.spongepowered.org/maven/") + maven("https://maven.minecraftforge.net/") + mavenCentral() +} + +dependencies { + compileOnly("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9:universal") + shade("org.spongepowered:mixin:0.7.11-SNAPSHOT") { + exclude(module = "launchwrapper") + exclude(module = "guava") + exclude(module = "gson") + exclude(module = "commons-io") + exclude(module = "log4j-core") + } + shade(project(":nosession_libc", "lib")) + compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT") + annotationProcessor("org.spongepowered:mixin:0.8.5:processor") + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion") +} + +tasks.processResources { + inputs.property("version", project.version) + inputs.property("mcversion", project.minecraft.version) + filesMatching(listOf("mcmod.info")) { + expand(inputs.properties) + } +} + +sourceSets.main { + this.ext["refMap"] = "mixins.nosession.refmap.json" +} + +tasks.withType(Jar::class) { + from(shade.map { if(it.isDirectory) it else zipTree(it) }) + manifest { + attributes( + "ForceLoadAsMod" to true, + "ModSide" to "CLIENT", + "FMLCorePluginContainsFMLMod" to true, + "MixinConfigs" to "mixins.nosession.json", + "FMLCorePlugin" to "gq.malwarefight.nosession.NoSessionLoadingPlugin" + ) + } + exclude("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA", "dummyThing") + archiveBaseName.set("NoSession") + isPreserveFileTimestamps = false + isReproducibleFileOrder = true +} + diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..d3aea12 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,23 @@ +plugins { + `kotlin-dsl` + java +} + +repositories { + mavenCentral() + maven("https://maven.minecraftforge.net") + maven("https://jitpack.io") { + mavenContent { + includeGroupByRegex("(com|io)\\.github\\..+") + } + } + mavenLocal() +} + +val kotlin_version = "1.8.21" + +dependencies { + implementation("com.github.thefightagainstmalware:ForgeGradle:5a1fcb9") + implementation("com.github.thefightagainstmalware:MixinGradle:92e66fe") + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index da1db5f..fae0804 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/nosession_libc/build.gradle.kts b/nosession_libc/build.gradle.kts new file mode 100644 index 0000000..0f64343 --- /dev/null +++ b/nosession_libc/build.gradle.kts @@ -0,0 +1,60 @@ +import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.archivesName + +plugins { + `cpp-library` + `java-base` + +} +val lib by configurations.creating + +library { + linkage.set(listOf(Linkage.SHARED)) +} + +project.afterEvaluate { + tasks.withType(CppCompile::class) { + val javaHome = rootProject.the() + .compilerFor(rootProject.the().toolchain) + .map { it.metadata.installationPath.asFile } + val includeDir = javaHome.map { it.resolve("include") } + val os = targetPlatform.get().operatingSystem + compilerArgs.add("-I") + compilerArgs.add(includeDir.map { it.absolutePath }) + compilerArgs.add("-I") + compilerArgs.add(includeDir.map { + it.resolve( + when { + os.isMacOsX -> "darwin" + os.isLinux -> "linux" + os.isWindows -> "win32" + os.isFreeBSD -> "freebsd" + else -> TODO("Unsupported operating system") + } + ).absolutePath + }) + if (os.isLinux) { + compilerArgs.add("-D_FILE_OFFSET_BITS=64") + } + if (os.isMacOsX) { + compilerArgs.add("-mmacosx-version-min=10.4") + } + } + + tasks.withType(AbstractLinkTask::class) { + if (targetPlatform.get().operatingSystem.isMacOsX) + linkerArgs.add("-mmacosx-version-min=10.4") + } + val linkRelease: AbstractLinkTask by tasks + val archive by tasks.creating(Zip::class) { + archivesName.set("archive.jar") + destinationDirectory.set(layout.buildDirectory.dir("libs")) + from(linkRelease.linkedFile) { + val targetPlatform = linkRelease.targetPlatform.get() + into("native/" + when(val arch = targetPlatform.architecture.name) { + "x86-64" -> "amd64" + else -> arch + } + "/" +targetPlatform.operatingSystem.name) + } + } + artifacts.add(lib.name, archive) +} diff --git a/nosession_libc/src/main/cpp/libc.cpp b/nosession_libc/src/main/cpp/libc.cpp new file mode 100644 index 0000000..060e83e --- /dev/null +++ b/nosession_libc/src/main/cpp/libc.cpp @@ -0,0 +1,31 @@ +#include +#include "unistd.h" +#include +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: gq_malwarefight_nosession_linux_libc_Libc + * Method: geteuid + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_gq_malwarefight_nosession_linux_libc_Libc_geteuid + (JNIEnv *, jclass) { + return (int) geteuid(); +} + +/* + * Class: gq_malwarefight_nosession_linux_libc_Libc + * Method: unlink + * Signature: (Ljava/lang/String;)I + */ +JNIEXPORT void JNICALL Java_gq_malwarefight_nosession_linux_libc_Libc_unlink + (JNIEnv* env, jclass, jstring string) { + const char* path = env->GetStringUTFChars(string, NULL); + unlink(path); + env->ReleaseStringUTFChars(string, path); +} + +#ifdef __cplusplus +} +#endif diff --git a/nosession_libc/src/main/cpp/libc.h b/nosession_libc/src/main/cpp/libc.h new file mode 100644 index 0000000..6aaa1a6 --- /dev/null +++ b/nosession_libc/src/main/cpp/libc.h @@ -0,0 +1,29 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class gq_malwarefight_nosession_linux_libc_Libc */ + +#ifndef _Included_gq_malwarefight_nosession_linux_libc_Libc +#define _Included_gq_malwarefight_nosession_linux_libc_Libc // NOLINT(bugprone-reserved-identifier) +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: gq_malwarefight_nosession_linux_libc_Libc + * Method: geteuid + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_gq_malwarefight_nosession_linux_libc_Libc_geteuid + (JNIEnv *, jclass); + +/* + * Class: gq_malwarefight_nosession_linux_libc_Libc + * Method: unlink + * Signature: (Ljava/lang/String;) + */ +JNIEXPORT void JNICALL Java_gq_malwarefight_nosession_linux_libc_Libc_unlink + (JNIEnv *, jclass, jstring); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..e6fbf04 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +include("nosession_libc") diff --git a/src/main/cpp/libc.cpp b/src/main/cpp/libc.cpp deleted file mode 100644 index 060e83e..0000000 --- a/src/main/cpp/libc.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include "unistd.h" -#include -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: gq_malwarefight_nosession_linux_libc_Libc - * Method: geteuid - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_gq_malwarefight_nosession_linux_libc_Libc_geteuid - (JNIEnv *, jclass) { - return (int) geteuid(); -} - -/* - * Class: gq_malwarefight_nosession_linux_libc_Libc - * Method: unlink - * Signature: (Ljava/lang/String;)I - */ -JNIEXPORT void JNICALL Java_gq_malwarefight_nosession_linux_libc_Libc_unlink - (JNIEnv* env, jclass, jstring string) { - const char* path = env->GetStringUTFChars(string, NULL); - unlink(path); - env->ReleaseStringUTFChars(string, path); -} - -#ifdef __cplusplus -} -#endif diff --git a/src/main/cpp/libc.h b/src/main/cpp/libc.h deleted file mode 100644 index 6aaa1a6..0000000 --- a/src/main/cpp/libc.h +++ /dev/null @@ -1,29 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class gq_malwarefight_nosession_linux_libc_Libc */ - -#ifndef _Included_gq_malwarefight_nosession_linux_libc_Libc -#define _Included_gq_malwarefight_nosession_linux_libc_Libc // NOLINT(bugprone-reserved-identifier) -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: gq_malwarefight_nosession_linux_libc_Libc - * Method: geteuid - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_gq_malwarefight_nosession_linux_libc_Libc_geteuid - (JNIEnv *, jclass); - -/* - * Class: gq_malwarefight_nosession_linux_libc_Libc - * Method: unlink - * Signature: (Ljava/lang/String;) - */ -JNIEXPORT void JNICALL Java_gq_malwarefight_nosession_linux_libc_Libc_unlink - (JNIEnv *, jclass, jstring); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/main/java/gq/malwarefight/nosession/linux/bwrap/BubblewrapBuilder.java b/src/main/java/gq/malwarefight/nosession/linux/bwrap/BubblewrapBuilder.java index 34542cd..6a5b9a5 100644 --- a/src/main/java/gq/malwarefight/nosession/linux/bwrap/BubblewrapBuilder.java +++ b/src/main/java/gq/malwarefight/nosession/linux/bwrap/BubblewrapBuilder.java @@ -395,7 +395,7 @@ public class BubblewrapBuilder { finalArgs.addAll(bubblewrapArgs); finalArgs.add(command); finalArgs.addAll(programArgs); - pb.command(finalArgs).redirectOutput(new File("/home/pandaninjas/log")).redirectError(new File("/home/pandaninjas/log1")); + pb.command(finalArgs).redirectOutput(new File(System.getProperty("NOSESSION_STDOUT", System.getProperty("user.home") + "/nosession-stdout.log"))).redirectError(new File(System.getProperty("NOSESSION_STDERR", System.getProperty("user.home") + "/nosession-stderr.log"))); return pb; } } diff --git a/src/main/java/gq/malwarefight/nosession/linux/libc/Libc.java b/src/main/java/gq/malwarefight/nosession/linux/libc/Libc.java index 670f83d..3677537 100644 --- a/src/main/java/gq/malwarefight/nosession/linux/libc/Libc.java +++ b/src/main/java/gq/malwarefight/nosession/linux/libc/Libc.java @@ -16,7 +16,7 @@ public class Libc { static { try { File tempFile = Files.createTempFile("nosession_libc", ".so").toFile(); - try (InputStream is = Libc.class.getResourceAsStream("/native/" + System.getProperty("os.arch") + "/" + System.getProperty("os.name") + "/" + System.mapLibraryName("linux"))) { + try (InputStream is = Libc.class.getResourceAsStream("/native/" + System.getProperty("os.arch") + "/" + System.getProperty("os.name") + "/" + System.mapLibraryName("nosession_libc"))) { assert is != null: "Native library not compiled"; Utils.copy(is, Files.newOutputStream(tempFile.toPath())); } diff --git a/src/main/java/gq/malwarefight/nosession/utils/Utils.java b/src/main/java/gq/malwarefight/nosession/utils/Utils.java index 7f65b2a..ab10319 100644 --- a/src/main/java/gq/malwarefight/nosession/utils/Utils.java +++ b/src/main/java/gq/malwarefight/nosession/utils/Utils.java @@ -174,7 +174,7 @@ public class Utils { public static void setToken(String token) throws IOException, URISyntaxException { ProcessBuilder processBuilder = new ProcessBuilder( - getJavaExe(p), "-XX:+DisableAttachMechanism", "-cp", getClasspath(p), Main.class.getName() + getJavaExe(), "-XX:+DisableAttachMechanism", "-cp", getClasspath(), Main.class.getName() ); processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT).redirectError(ProcessBuilder.Redirect.INHERIT); Process c = processBuilder.start(); -- cgit