Skip to content

Commit

Permalink
Merge pull request #45 from avaerian/java-21
Browse files Browse the repository at this point in the history
Update codebase to Java 21 + refactor build system
  • Loading branch information
avaerian authored Sep 24, 2024
2 parents d481d23 + a884a73 commit 946bb85
Show file tree
Hide file tree
Showing 268 changed files with 2,381 additions and 476 deletions.
35 changes: 35 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
plugins {
`kotlin-dsl`
}

repositories {
gradlePluginPortal()
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
}

dependencies {

implementation(libs.paperweight)
implementation(libs.shadow)

/*
compileOnly(libs.paperApi)
/*project.project(":nms").subprojects.forEach {
implementation(project(it.path))
}*/
constraints {
val asmVersion = "[${libs.versions.minAsm.get()},)"
implementation("org.ow2.asm:asm:$asmVersion") {
because("Java 21 support")
}
implementation("org.ow2.asm:asm-commons:$asmVersion") {
because("Java 21 support")
}
}
*/

}

9 changes: 9 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}

rootProject.name = "build-logic"
17 changes: 17 additions & 0 deletions build-logic/src/main/kotlin/buildlogic.common.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
id("com.gradleup.shadow")
}

/*tasks.named<ShadowJar>("shadowJar") {
archiveClassifier.set("")
configurations = [project.configurations.compileClasspath]
exclude("module-info.class")
exclude("*.properties")
dependencies {
include(project(":core"))
include(project(":nms:v1_19_R3"))
include(dependency("xyz.jpenilla:reflection-remapper"))
}
}*/
50 changes: 50 additions & 0 deletions build-logic/src/main/kotlin/buildlogic.nms.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import buildlogic.getLibrary
import buildlogic.getVersion
import buildlogic.libsCatalog
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
`java-library`
id("io.papermc.paperweight.userdev")
}

repositories {
gradlePluginPortal()
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
}

configurations.all {
resolutionStrategy.force("net.fabricmc:tiny-remapper:${libsCatalog.getVersion("minTinyRemapper")}")
}

tasks.withType<ShadowJar> {
dependencies {
exclude("org.ow2.asm:asm")
//exclude("org.ow2.asm:asm-commons")
}
}

dependencies {
implementation(project(":core"))
implementation(libsCatalog.getLibrary("reflectionRemapper"))

constraints {
val asmVersion = "[${libsCatalog.getVersion("minAsm")},)"
implementation("org.ow2.asm:asm:$asmVersion") {
because("Java 21 support")
}
implementation("org.ow2.asm:asm-commons:$asmVersion") {
because("Java 21 support")
}

remapper("net.fabricmc:tiny-remapper:[${libsCatalog.getVersion("minTinyRemapper")},)") {
because("Java 21 support")
}
}
}

/*tasks.named("assemble") {
dependsOn("reobfJar")
}*/

20 changes: 20 additions & 0 deletions build-logic/src/main/kotlin/buildlogic/GradleUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package buildlogic

import org.gradle.api.Project
import org.gradle.api.artifacts.MinimalExternalModuleDependency
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.artifacts.VersionConstraint
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.getByType

val Project.libsCatalog: VersionCatalog
get() = extensions.getByType<VersionCatalogsExtension>().named("libs")

fun VersionCatalog.getLibrary(name: String): Provider<MinimalExternalModuleDependency> = findLibrary(name).orElseThrow {
error("Library $name not found in libs catalog")
}

fun VersionCatalog.getVersion(name: String): VersionConstraint = findVersion(name).orElseThrow {
error("Library $name not found in libs catalog")
}
98 changes: 31 additions & 67 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,89 +1,53 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id("com.github.johnrengelman.shadow") version("7.1.2") apply(false)
`kotlin-dsl`
`java-library`
id("java")
id("io.papermc.paperweight.userdev") version("1.5.4") apply(false)
id("com.gradleup.shadow") version("8.3.1")
}

dependencies {

implementation(project(":main"))
implementation(project(":v1_19_R1", "reobf"))
group = rootProject.group
version = rootProject.version

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}

allprojects {

apply(plugin = "java")
apply(plugin = "com.github.johnrengelman.shadow")

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}

repositories {
mavenCentral()
}

group = "org.minerift.ether"
version = "1.0-SNAPSHOT"

tasks.withType<ShadowJar> {
archiveClassifier.set("") // SUPER IMPORTANT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
dependencies {
include(project(":main"))
include(project(":v1_19_R1"))
include(dependency("xyz.jpenilla:reflection-remapper"))
}
}
repositories {
gradlePluginPortal()
mavenCentral()
}

// Paper-API dependency for submodules
subprojects {
repositories {
mavenCentral()
maven { url = uri("https://repo.papermc.io/repository/maven-public/") }
}
// TODO: create a SourceSet "shade" for shadowJar to clarify shading?

dependencies {
compileOnly("io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT")
}
dependencies {
implementation(project(":core"))
implementation(project(":nms:v1_20_R2", "reobf"))

// shade in these dependencies as well
implementation(libs.reflectionRemapper)
}

// Once more versions are implemented, this list will grow
configure(subprojects.filter { listOf("v1_19_R1").contains(it.name) }) {
apply(plugin = "io.papermc.paperweight.userdev")
tasks.named<ShadowJar>("shadowJar") {
//archiveClassifier.set("implementation")

repositories {
mavenCentral()
}
//exclude("module-info.class")
exclude("*.properties") // TODO: review
archiveFileName.set("${project.name}-${project.version}.jar")

dependencies {
implementation(project(":main"))
implementation("xyz.jpenilla:reflection-remapper:0.1.1")
include(project(":core"))
include(project(":nms:v1_20_R2"))
include(dependency("xyz.jpenilla:reflection-remapper"))
}
}

/*
compileJava.options.encoding = 'UTF-8'
tasks.withType<Test> {
//systemProperties = System.getProperties()
systemProperties.remove("java.endorsed.dirs")
tasks.withType<JavaCompile> {
options.release.set(21)
options.encoding = Charsets.UTF_8.name()
}

tasks.create("runBinaryTests", Test::class) {
dependsOn("shadowJar")
val FAT_JAR_FILEPATH = "$projectDir/build/libs/${project.name}-$version-all.jar"
testClassesDirs += zipTree(FAT_JAR_FILEPATH)
classpath = project.files(FAT_JAR_FILEPATH, configurations.runtimeClasspath)
outputs.upToDateWhen { false }
}
task runBinaryTests(type: Test) {
testClassesDirs += zipTree($projectDir/fatjar.jar)
classpath = project.files( "$projectDir/fatjar.jar", configurations.runtime )
outputs.upToDateWhen { false }
}
*/
tasks.withType<Javadoc> {
options.encoding = Charsets.UTF_8.name()
}
50 changes: 50 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
plugins {
id("com.gradleup.shadow")
id("me.champeau.jmh") version("0.7.2")
}

//sourceSets["jmh"].compileClasspath += sourceSets["main"].runtimeClasspath
//sourceSets["jmh"].runtimeClasspath += sourceSets["main"].runtimeClasspath

repositories {
mavenCentral()
maven ("https://maven.enginehub.org/repo/")
}



dependencies {

//implementation("org.jooq:joor-java-8:0.9.15")
compileOnly(libs.paperApi)

// TODO: move these to :build-logic build.gradle.kts with version constraints for better Mojang lib conflict handling
// General libraries
implementation(libs.guava)
implementation(libs.gson)
implementation(libs.fastutil)

// SQL libraries
implementation(libs.jooq)
implementation(libs.hikariCP)

implementation(libs.sql.driver.sqlite)
implementation(libs.sql.driver.postgresql)
implementation(libs.sql.driver.h2)
implementation(libs.sql.driver.mysql)

compileOnly(libs.worldeditBukkit)

// Benchmarking
jmhImplementation(libs.jmh.core)
jmhAnnotationProcessor(libs.jmh.annprocessor)

// Unit tests
testImplementation(libs.junit.jupiter.api)
testImplementation(libs.junit.jupiter.params)
testRuntimeOnly(libs.junit.jupiter.engine)
}

tasks.withType<Test> {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@

public class UserModel extends Model<EtherUser, UUID> {

public final Field<EtherUser, UUID, ?> USER_ID = createField("user_id", SQLDataType.UUID.notNull(), EtherUser::getUUID);
public final Field<EtherUser, Integer, ?> ISLAND_ID = createField("island_id", SQLDataType.INTEGER.nullable(true), (user) -> {

// NOTE: fields are not associated with the Model
public final Field<EtherUser, UUID, ?> USER_ID
= createField("user_id", SQLDataType.UUID.notNull(), EtherUser::getUUID);
public final Field<EtherUser, Integer, ?> ISLAND_ID
= createField("island_id", SQLDataType.INTEGER.nullable(true), (user) -> {
// read island id if present, else null
Optional<Island> optIsland = user.getIsland();
return optIsland.isPresent() ? optIsland.get().getId() : null;
});

public final Field<EtherUser, String, ?> ISLAND_ROLE = createField("island_role", SQLDataType.VARCHAR, (user) -> user.getIslandRole().name());
public final Field<EtherUser, String, ?> ISLAND_ROLE
= createField("island_role", SQLDataType.VARCHAR, (user) -> user.getIslandRole().name());

public UserModel(SQLDatabase db) {
super("users", db);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public abstract class Model<M, K> {

private Fields<M, ?> fields;

private final List<Field<M, ?, ?>> prepFields = new ArrayList<>();
// TODO: use Builder pattern for creating fields to clean up this mess

@Deprecated
private final List<Field<M, ?, ?>> prepFields = new ArrayList<>(); // this is stupid

public Model(String tableName, SQLDatabase db) {
this.db = db;
Expand Down Expand Up @@ -108,7 +111,9 @@ public SQLDatabase getDb() {
// NOTE: Ignores name case when finding field
public Field<M, ?, ?> getField(String name) {
// assumes all fields in model belong to model (no weird shit)
Field<M, ?, ?>[] fields = Reflect.of(this).getFields().filter(field -> field.isType(Field.class)).readAllTyped(this, Field.class);
Field<M, ?, ?>[] fields = Reflect.of(this).getFields()
.filter(field -> field.isType(Field.class)).readAllTyped(this, Field.class);

for(Field<M, ?, ?> field : fields) {
if(field.getName().equalsIgnoreCase(name)) {
return field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public Vec2i getNextTileAlternate() {
return !tiles.isEmpty() ? tiles.get(0) : getNextTileFromGridBounds();
}

// TODO: create immutable copy if possible (?)
public IndexedList<Island> getData() {
return islands;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,17 @@ protected Table<UUID, UUID, IslandInvite> getUnderlyingTable() {

// Returns number of purged invites
public int purgeExpiredInvites() {

if(inviteTable.isEmpty()) {
return 0;
}

int originalSize = inviteTable.size();
inviteTable.values().removeIf(IslandInvite::isExpired);
System.out.println(inviteTable.values());
return originalSize - inviteTable.size();

int purgedInvites = originalSize - inviteTable.size();
System.out.println("Purged " + inviteTable.size() + " invites");
return purgedInvites;
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;
import java.util.Map;

@Deprecated
public class BinaryFormat {

public static class Section {
Expand Down
Loading

0 comments on commit 946bb85

Please sign in to comment.