Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,75 @@ public void apply(Project project) {
task.exclude("mcp/**");
});

// Magma launcher jar = contains the Magma launcher code. from the magma-launcher project.
var magmaLauncherJar = tasks.register("magmaLauncherJar", Jar.class, task -> {
task.setGroup(INTERNAL_GROUP);
task.dependsOn(":magma-launcher:jar");
task.getArchiveClassifier().set("launcher");

task.from(project.zipTree(project.getRootProject().file(String.format("magma-launcher/build/libs/magma-launcher-%s.jar", project.getVersion()))));

task.getDestinationDirectory().convention(project.getExtensions().getByType(BasePluginExtension.class).getLibsDirectory());

task.from(createUnixServerArgsFile.flatMap(CreateArgsFile::getArgsFile), spec -> {
spec.into("data");
spec.rename(s -> "unix_args.txt");
});
task.from(createWindowsServerArgsFile.flatMap(CreateArgsFile::getArgsFile), spec -> {
spec.into("data");
spec.rename(s -> "win_args.txt");
});
task.from(binaryPatchOutputs.binaryPatchesForClient(), spec -> {
spec.into("data");
spec.rename(s -> "client.lzma");
});
task.from(binaryPatchOutputs.binaryPatchesForServer(), spec -> {
spec.into("data");
spec.rename(s -> "server.lzma");
});
var mavenPath = neoForgeVersion.map(v -> "net/neoforged/neoforge/" + v);
task.getInputs().property("mavenPath", mavenPath);
task.from(project.getRootProject().files("server_files"), spec -> {
spec.into("data");
spec.exclude("args.txt");
spec.filter(s -> {
return s.replaceAll("@MAVEN_PATH@", mavenPath.get());
});
});

// This is true by default (see gradle.properties), and needs to be disabled explicitly when building (see release.yml).
String installerDebugProperty = "neogradle.runtime.platform.installer.debug";
if (project.getProperties().containsKey(installerDebugProperty) && Boolean.parseBoolean(project.getProperties().get(installerDebugProperty).toString())) {
task.from(universalJar.flatMap(AbstractArchiveTask::getArchiveFile), spec -> {
spec.into(String.format("/maven/net/neoforged/neoforge/%s/", neoForgeVersion.get()));
spec.rename(name -> String.format("neoforge-%s-universal.jar", neoForgeVersion.get()));
});
}

task.manifest(manifest -> {
manifest.attributes(Map.of("Main-Class", "org.magmafoundation.magma.launcher.MagmaLauncherKt"));
manifest.attributes(
Map.of(
"Specification-Title", "Magma",
"Specification-Vendor", "Magma Development Limited",
"Specification-Version", project.getVersion().toString().substring(0, project.getVersion().toString().lastIndexOf(".")),
"Implementation-Title", "Magma",
"Implementation-Version", project.getVersion(),
"Implementation-Vendor", "Magma Development Limited"),
"org/magmafoundation/magma/launcher/");
manifest.attributes(Map.of("NeoForge-Version", project.getProperties().get("neoforgeVersion")));
});

task.dependsOn("generateMagmaLibs");
task.from(project.getTasks().named("generateMagmaLibs"));
});

tasks.named("assemble", task -> {
task.dependsOn(installerJar);
task.dependsOn(universalJar);
task.dependsOn(userdevJar);
task.dependsOn(sourcesJarProvider);
task.dependsOn(magmaLauncherJar);
});

// Set up E2E testing of the produced installer
Expand All @@ -444,6 +508,7 @@ public void apply(Project project) {
* Get the list of Maven repositories that may contain artifacts for the installer.
*/
private static Provider<List<URI>> getInstallerRepositoryUrls(Project project) {

return project.provider(() -> {
List<URI> repos = new ArrayList<>();
var projectRepos = project.getRepositories();
Expand Down
15 changes: 15 additions & 0 deletions codeformat/MAGMA-HEADER.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Magma Server
Copyright (C) 2019-${year}.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
43 changes: 43 additions & 0 deletions magma-launcher/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.util.Calendar

plugins {
id("java-library")
id("net.neoforged.licenser")
id("neoforge.formatting-conventions")
kotlin("jvm")
}

dependencies {
testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
compileOnly(platform("net.neoforged:minecraft-dependencies:${project.property("minecraft_version")}"))
compileOnly("org.slf4j:slf4j-api")
implementation(kotlin("stdlib-jdk8"))
implementation("dev.vankka:dependencydownload-runtime:1.3.1")
implementation("me.tongfei:progressbar:0.10.1")
implementation("cpw.mods:bootstraplauncher:2.0.2")
}

tasks.test {
useJUnitPlatform()
}

kotlin {
jvmToolchain(21)
}

license {
header(rootProject.file("codeformat/MAGMA-HEADER.txt"))
properties {
this["year"] = Calendar.getInstance().get(Calendar.YEAR).toString()
}
include("**/*.java", "**/*.kt")
}

tasks.jar.configure {
configurations["compileClasspath"].forEach { file: File ->
from(zipTree(file.absoluteFile))
}
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Magma Server
* Copyright (C) 2019-2025.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.magmafoundation.magma.launcher

import cpw.mods.bootstraplauncher.BootstrapLauncher
import org.magmafoundation.magma.launcher.dep.DependenciesDownloader
import org.magmafoundation.magma.launcher.installer.MagmaInstaller
import org.magmafoundation.magma.launcher.utils.JarTool
import org.magmafoundation.magma.launcher.utils.ServerInitHelper
import org.magmafoundation.magma.launcher.utils.SystemType
import java.nio.file.spi.FileSystemProvider
import java.util.function.Consumer
import java.util.jar.Manifest


var ui: UI? = null

fun main(args: Array<String>) {

ui = UI(!isArgumentPresent(args, "--no-ui"))

ui?.display(version = getVersion(), neoForgeVersion = getNeoForgeVersion())

var dependenciesDownloader: DependenciesDownloader = DependenciesDownloader()
var libsToLoad = dependenciesDownloader.start()

val magmaInstaller = MagmaInstaller(version = getVersion(), neoForgeVersion = getNeoForgeVersion())


val launchArgs: MutableList<String?> = JarTool.readFileLinesFromJar(
"data/" + (if (SystemType.getOS() == SystemType.OS.WINDOWS) "win" else "unix") + "_args.txt"
)
val forgeArgs: MutableList<String?> = ArrayList()
launchArgs.stream().filter { s: String? ->
s!!.startsWith("--launchTarget") || s.startsWith("--fml.neoForgeVersion") || s.startsWith("--fml.mcVersion") || s.startsWith("--fml.fmlVersion") || s.startsWith("--fml.neoFormVersion")
}.toList().forEach(
Consumer { arg: String? ->
forgeArgs.add(arg?.split(" ")[0])
forgeArgs.add(arg?.split(" ")[1])
})

ServerInitHelper.applyLaunchArgs(launchArgs as List<String>)

BootstrapLauncher.main(*forgeArgs.filterNotNull().toTypedArray())

}

private fun isArgumentPresent(args: Array<String>, argument: String): Boolean {
return args.any { it.equals(argument, ignoreCase = true) }
}

fun getVersion(): String {
val version = object {}.javaClass.`package`?.implementationVersion
return version ?: "dev-env"
}

fun getNeoForgeVersion(): String {
val neoForgeVersion = object {}.javaClass.classLoader.getResourceAsStream("META-INF/MANIFEST.MF")?.use { inputStream ->
val manifest = Manifest(inputStream)
manifest.mainAttributes.getValue("NeoForge-Version")
}
return neoForgeVersion ?: "dev-env"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Magma Server
* Copyright (C) 2019-2025.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.magmafoundation.magma.launcher

import java.text.SimpleDateFormat
import java.util.Date

class UI(enabled: Boolean) {

private val enabled: Boolean = enabled

var title: String = "______ ___ _____ __ \n" +
"___ |/ /_____ _______ _______ _________ _ ___ | / /__________ \n" +
"__ /|_/ /_ __ `/_ __ `/_ __ `__ \\ __ `/ __ |/ /_ _ \\ __ \\\n" +
"_ / / / / /_/ /_ /_/ /_ / / / / / /_/ / _ /| / / __/ /_/ /\n" +
"/_/ /_/ \\__,_/ _\\__, / /_/ /_/ /_/\\__,_/ /_/ |_/ \\___/\\____/ \n" +
" /____/ \n"

fun display(version: String, neoForgeVersion: String) {
if (!enabled) {
return
}

println(title)
println("Copyright (C) 2019-" + SimpleDateFormat("yyyy").format(Date()) + " Magma Foundation")
println("-----------------------------------------")
println("Running on Java " + System.getProperty("java.version") + " (" + System.getProperty("java.vendor") + ")")
println("Magma version $version")
println("NeoForge version $neoForgeVersion")
println("-----------------------------------------")
}
}
Loading