Skip to content

Commit

Permalink
Launcher-Wrapper, Fixed InMemoryLauncher on most versions, compilatio…
Browse files Browse the repository at this point in the history
…n support for Java 21 and 17
  • Loading branch information
3arthqu4ke committed Aug 4, 2024
1 parent aed138f commit da16fae
Show file tree
Hide file tree
Showing 64 changed files with 1,125 additions and 241 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ run
/headlessmc-lwjgl/logs/
/logs/
/headlessmc-launcher-*.jar
/libs/
/headlessmc-launcher/libs/
/fabricloader.log
/.mixin.out/
153 changes: 78 additions & 75 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io.franzbecker.gradle.lombok.task.DelombokTask

plugins {
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'io.franzbecker.gradle-lombok' version '5.0.0'
}

Expand All @@ -15,11 +15,20 @@ allprojects {
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'io.franzbecker.gradle-lombok'

// no lombok for that project, cause its doing naughty things with stubing java.lang classes
if (project != project(':headlessmc-modlauncher')) {
// Consider switching to https://github.com/freefair/gradle-plugins/tree/main/lombok-plugin looks more maintained?
apply plugin: 'io.franzbecker.gradle-lombok'
lombok {
version '1.18.34'
}
}

group 'me.earth.headlessmc'
version rootProject.project_version


repositories {
mavenCentral()
maven {
Expand Down Expand Up @@ -52,14 +61,17 @@ allprojects {
dependencies {
compileOnly 'org.jetbrains:annotations:24.1.0'

compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
// no lombok for modlauncher cause we do bad hacks there in the java9 stub.
if (project != project(':headlessmc-modlauncher')) {
compileOnly 'org.projectlombok:lombok:1.18.34'
annotationProcessor 'org.projectlombok:lombok:1.18.34'

testCompileOnly 'org.projectlombok:lombok:1.18.30'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.30'
testCompileOnly 'org.projectlombok:lombok:1.18.34'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.34'
}

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.3'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.3'
}

test {
Expand All @@ -82,18 +94,14 @@ allprojects {
}

java {
// because we are using lomboks var
if (!JavaVersion.current().isJava9Compatible()) {
withSourcesJar()
withJavadocJar()
}
withSourcesJar()
withJavadocJar()
}

// TODO: even though we are doing all of this Intellij
// still complains about bytecode not matching the source...
if (sourceSets.main.java.srcDirs.stream().anyMatch { it.exists()}
// var keyword causes issues in DelombokTask with newer jdks
&& !JavaVersion.current().isJava9Compatible()) {
&& project != project(':headlessmc-modlauncher')) {
tasks.register('delombok', DelombokTask) {
dependsOn compileJava
ext.outputDir = file(buildDir.toPath().resolve('delombok'))
Expand All @@ -109,27 +117,30 @@ allprojects {
'-d', ext.outputDir)
}
}

javadoc {
dependsOn delombok
source = delombok.outputDir
}

sourcesJar {
dependsOn delombok
from delombok.outputDir
// I tried every single exclude/include pattern but I could not get any to work
exclude (fileTreeElement -> {
return !((FileTreeElement) fileTreeElement)
.getFile()
.toPath()
.toAbsolutePath()
.startsWith(delombok.outputDir.toPath().toAbsolutePath())
})
}
}

javadoc {
dependsOn delombok
source = delombok.outputDir
options.addStringOption('Xdoclint:none', '-quiet')
options.linkSource true
}

sourcesJar {
dependsOn delombok
from delombok.outputDir
// I tried every single exclude/include pattern but I could not get any to work
exclude (fileTreeElement -> {
return !((FileTreeElement) fileTreeElement)
.getFile()
.toPath()
.toAbsolutePath()
.startsWith(delombok.outputDir.toPath().toAbsolutePath())
})
}
}

jar {
Expand All @@ -139,65 +150,57 @@ allprojects {
shadowJar {
configurations = [project.configurations.jarLibs, project.configurations.jarLibsApi]
archiveClassifier.set('')

// when launching older versions in memory we get conflicts between asm versions,
// we prevent this by renaming our own asm.
relocate 'org.objectweb.asm', 'me.earth.headlessmc.asm'
}

jar.finalizedBy(shadowJar)

// since we are not creating javadoc and sources on java 9+ skip
if (!JavaVersion.current().isJava9Compatible()) {
def pubSuffix = System.getenv('IS_MAVEN_PUB') != null
? ''
: System.getenv('GITHUB_RUN_NUMBER') != null && System.getenv('GITHUB_SHA') != null
? "-${System.getenv('GITHUB_RUN_NUMBER')}-${System.getenv('GITHUB_SHA').substring(0, 7)}"
: '-local'

publishing {
publications {
"${project.name.toLowerCase(Locale.ENGLISH)}"(MavenPublication) {
((MavenPublication) it).groupId "${project.group}"
((MavenPublication) it).artifactId "${project.archivesBaseName.toLowerCase(Locale.ENGLISH)}"
((MavenPublication) it).version "${project.version}${pubSuffix}"
// TODO: testFixtures are part of commons artifact?
// Exclude shadowJars from publication
components.withType(AdhocComponentWithVariants).forEach { c ->
c.withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
skip()
}
def pubSuffix = System.getenv('IS_MAVEN_PUB') != null
? ''
: System.getenv('GITHUB_RUN_NUMBER') != null && System.getenv('GITHUB_SHA') != null
? "-${System.getenv('GITHUB_RUN_NUMBER')}-${System.getenv('GITHUB_SHA').substring(0, 7)}"
: '-local'

publishing {
publications {
"${project.name.toLowerCase(Locale.ENGLISH)}"(MavenPublication) {
((MavenPublication) it).groupId "${project.group}"
((MavenPublication) it).artifactId "${project.archivesBaseName.toLowerCase(Locale.ENGLISH)}"
((MavenPublication) it).version "${project.version}${pubSuffix}"
// TODO: testFixtures are part of commons artifact?
// Exclude shadowJars from publication
components.withType(AdhocComponentWithVariants).forEach { c ->
c.withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
skip()
}

from components.java
}

from components.java
}
}

repositories {
// mavenLocal()
if (System.getenv('DEPLOY_TO_GITHUB_PACKAGES_URL') != null) {
maven {
name = 'GithubPagesMaven'
url = System.getenv('DEPLOY_TO_GITHUB_PACKAGES_URL')
credentials {
username = System.getenv('GITHUB_USER')
password = System.getenv('GITHUB_TOKEN')
}
}
} else {
maven {
name = 'BuildDirMaven'
url = rootProject.layout.buildDirectory.dir('maven')
repositories {
// mavenLocal()
if (System.getenv('DEPLOY_TO_GITHUB_PACKAGES_URL') != null) {
maven {
name = 'GithubPagesMaven'
url = System.getenv('DEPLOY_TO_GITHUB_PACKAGES_URL')
credentials {
username = System.getenv('GITHUB_USER')
password = System.getenv('GITHUB_TOKEN')
}
}
} else {
maven {
name = 'BuildDirMaven'
url = rootProject.layout.buildDirectory.dir('maven')
}
}
}
}

publish {
dependsOn(build)
}
} else {
project.logger.warn('Cannot publish on Java 9+ as we are not generating JavaDocs!')
publish {
dependsOn(build)
}
}

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repositories {
}

dependencies {
implementation group: 'org.ow2.asm', name: 'asm', version: '9.6'
implementation group: 'org.ow2.asm', name: 'asm', version: '9.7'
}

gradlePlugin {
Expand Down
10 changes: 6 additions & 4 deletions headlessmc-commons/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ dependencies {
api project(':headlessmc-api')

testFixturesCompileOnly project(':headlessmc-api')
testFixturesCompileOnly 'org.projectlombok:lombok:1.18.30'
testFixturesAnnotationProcessor 'org.projectlombok:lombok:1.18.30'
testFixturesImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'
testFixturesRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1'

testFixturesCompileOnly 'org.projectlombok:lombok:1.18.34'
testFixturesAnnotationProcessor 'org.projectlombok:lombok:1.18.34'

testFixturesImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.3'
testFixturesRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.3'
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public void debug(String message) {
logger.fine(message);
}

public void debug(String message, Throwable throwable) {
logger.log(Level.FINE, message, throwable);
}

public void info(Throwable throwable) {
logger.log(Level.INFO, "", throwable);
}
Expand All @@ -30,6 +34,10 @@ public void error(Throwable throwable) {
logger.log(Level.SEVERE, "", throwable);
}

public void warn(String message) {
logger.warning(message);
}

public void warn(String message, Throwable throwable) {
logger.log(Level.WARNING, message, throwable);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package me.earth.headlessmc.command;

import lombok.RequiredArgsConstructor;
import lombok.val;
import me.earth.headlessmc.MockedHeadlessMc;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.security.Permission;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class QuitCommandTest {
private final QuitCommand command =
Expand All @@ -26,31 +23,6 @@ public void testMatches() {
assertFalse(command.matches());
}

@Test
@Disabled("Disabled for now until I can verify it works everywhere")
public void testExecute() {
try {
System.setSecurityManager(new SecurityManager() {
@Override
public void checkPermission(Permission perm) {
// NOP
}

@Override
public void checkExit(int status) {
super.checkExit(status);
throw new ExitException(status);
}
});

val ex = assertThrows(ExitException.class,
() -> command.execute("quit"));
assertEquals(0, ex.code);
} finally {
System.setSecurityManager(null);
}
}

@RequiredArgsConstructor
public static final class ExitException extends RuntimeException {
private final int code;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.earth.headlessmc.config;

import lombok.val;
import lombok.var;
import me.earth.headlessmc.api.config.Property;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -43,7 +43,7 @@ public void testBooleanProperty() {

@Test
public void testArrayProperty() {
var array = PropertyTypes.array("test", ";");
Property<String[]> array = PropertyTypes.array("test", ";");
Assertions.assertNull(array.parse(null));
Assertions.assertNull(array.parse(""));

Expand Down
8 changes: 6 additions & 2 deletions headlessmc-launcher-jfx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'headlessmc-modules'
}

def MAIN_CLASS = 'me.earth.headlessmc.launcher.Main'
def MAIN_CLASS = 'me.earth.headlessmc.wrapper.Main'
application {
mainClass = MAIN_CLASS
}
Expand All @@ -23,7 +23,7 @@ def javaFxVersion = '17.0.9'
version += '-' + javaFxVersion

dependencies {
jarLibsApi project(':headlessmc-launcher')
runtimeOnly project(':headlessmc-launcher-wrapper')
jarLibs group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
jarLibs group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac'
jarLibs group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux'
Expand All @@ -48,7 +48,11 @@ dependencies {
}

shadowJar {
dependsOn project(':headlessmc-launcher-wrapper')['shadowJar']
excludes.remove("module-info.class")

from project(':headlessmc-launcher-wrapper')['shadowJar']

exclude("META-INF/maven/com.google.code.gson/**")
exclude("LICENSE")
}
Loading

0 comments on commit da16fae

Please sign in to comment.