Skip to content

Commit

Permalink
Update Guice to 7.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Mar 7, 2024
1 parent 6e2a9a7 commit 790ef49
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ dependencies {
}
runtimeDownload(libs.rabbitmq)
runtimeDownload(libs.nats)
runtimeDownload(libs.guice) {
exclude("com.google.guava")
}
runtimeDownload(libs.assistedInject) {
isTransitive = false
}
Expand Down
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fun Task.relocateCloud() {
fun Task.relocateGuice() {
relocateDependency("com.google.inject")
relocateDependency("org.aopalliance")
relocateDependency("javax.inject")
relocateDependency("jakarta.inject")
}

fun ShadowJar.configureShadowJar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public FactoryProvider3(
Key<?> paramKey = Annotations.getKey(param, method, paramAnnotations[p++], errors);
Class<?> underlylingType = paramKey.getTypeLiteral().getRawType();
if (underlylingType.equals(Provider.class)
|| underlylingType.equals(javax.inject.Provider.class)) {
|| underlylingType.equals(jakarta.inject.Provider.class)) {
errors.addMessage(
"A Provider may not be a type in a factory method of an AssistedInject."
+ "\n Offending instance is parameter [%s] with key [%s] on method [%s]",
Expand Down
3 changes: 0 additions & 3 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ dependencies {
runtimeOnly(libs.jarRelocator) {
isTransitive = false
}
runtimeDownload(libs.guice) {
exclude("com.google.guava")
}
runtimeDownload(libs.checkerQual)
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ foliaApi = "1.19.4-R0.1-SNAPSHOT"
event = "1.0.0-SNAPSHOT"
registry = "1.0.0-SNAPSHOT"
kyoriMoonshine = "2.0.4"
guice = "5.1.0"
guice = "7.0.0"
velocityApi = "3.3.0-SNAPSHOT"
minecraft = "1.20.4"
fabricLoader = "0.15.4"
Expand Down
6 changes: 1 addition & 5 deletions paper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ dependencies {
isTransitive = false
}
compileOnly(libs.factionsUuid)

runtimeDownload(libs.guice) {
exclude("com.google.guava")
}
}

configurablePlugins {
Expand All @@ -57,7 +53,7 @@ tasks {
withType(RunServer::class).configureEach {
version.set(libs.versions.minecraft)
downloadPlugins {
url("https://download.luckperms.net/1521/bukkit/loader/LuckPerms-Bukkit-5.4.108.jar")
url("https://download.luckperms.net/1533/bukkit/loader/LuckPerms-Bukkit-5.4.120.jar")
github("MiniPlaceholders", "MiniPlaceholders", libs.versions.miniplaceholders.get(), "MiniPlaceholders-Paper-${libs.versions.miniplaceholders.get()}.jar")
github("MiniPlaceholders", "PlaceholderAPI-Expansion", "1.2.0", "PlaceholderAPI-Expansion-1.2.0.jar")
hangar("PlaceholderAPI", libs.versions.placeholderapi.get())
Expand Down
35 changes: 31 additions & 4 deletions velocity/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,40 +1,67 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id("carbon.shadow-platform")
id("xyz.jpenilla.run-velocity")
}

val bstats: Configuration by configurations.creating
configurations.compileOnly {
extendsFrom(bstats)
}

dependencies {
implementation(projects.carbonchatCommon)
implementation(libs.bstatsVelocity)
bstats(libs.bstatsVelocity)

compileOnly(libs.velocityApi)

implementation(libs.cloudVelocity)
compileOnly(libs.miniplaceholders)

runtimeDownload(libs.mysql)

compileOnly("javax.inject:javax.inject:1")
}

gremlin {
defaultJarRelocatorDependencies.set(true)
}

runVelocityExtension.detectPluginJar = false

tasks {
val bStatsJar = register<ShadowJar>("bStatsShadowJar") {
archiveClassifier = "bStats"
configurations = listOf(bstats)
relocateDependency("org.bstats")
}
shadowJar {
archiveClassifier = "shadowJar"
relocateCloud()
standardRuntimeRelocations()
relocateDependency("com.google.inject.assistedinject")
relocateDependency("io.leangen.geantyref")
relocateGuice()
}
val prod = register<Zip>("productionJar") {
destinationDirectory.set(layout.buildDirectory.dir("libs"))
archiveFileName.set("carbonchat-velocity-${project.version}.jar")
from(zipTree(shadowJar.flatMap { it.archiveFile }))
from(zipTree(bStatsJar.flatMap { it.archiveFile })) {
exclude("META-INF/**")
}
}
carbonPlatform.productionJar = prod.flatMap { it.archiveFile }
writeDependencies {
standardRuntimeRelocations()
relocateDependency("com.google.inject.assistedinject")
relocateDependency("io.leangen.geantyref")
relocateGuice()
}
runVelocity {
velocityVersion(libs.versions.velocityApi.get())
pluginJars.from(prod)
downloadPlugins {
url("https://download.luckperms.net/1521/velocity/LuckPerms-Velocity-5.4.108.jar")
url("https://download.luckperms.net/1533/velocity/LuckPerms-Velocity-5.4.120.jar")
github("MiniPlaceholders", "MiniPlaceholders", libs.versions.miniplaceholders.get(), "MiniPlaceholders-Velocity-${libs.versions.miniplaceholders.get()}.jar")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.Multibinder;
import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.plugin.PluginManager;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import java.nio.file.Path;
Expand Down Expand Up @@ -60,15 +61,18 @@
public final class CarbonChatVelocityModule extends CarbonPlatformModule {

private final Logger logger = LogManager.getLogger("carbonchat");
private final CarbonVelocityBootstrap bootstrap;
private final PluginContainer pluginContainer;
private final ProxyServer proxyServer;
private final Path dataDirectory;

CarbonChatVelocityModule(
final CarbonVelocityBootstrap bootstrap,
final PluginContainer pluginContainer,
final ProxyServer proxyServer,
final Path dataDirectory
) {
this.bootstrap = bootstrap;
this.pluginContainer = pluginContainer;
this.proxyServer = proxyServer;
this.dataDirectory = dataDirectory;
Expand Down Expand Up @@ -106,6 +110,11 @@ public CommandManager<Commander> createCommandManager(
protected void configurePlatform() {
this.install(new CarbonCommonModule());

this.bind(CarbonVelocityBootstrap.class).toInstance(this.bootstrap);
this.bind(PluginContainer.class).toInstance(this.pluginContainer);
this.bind(ProxyServer.class).toInstance(this.proxyServer);
this.bind(PluginManager.class).toInstance(this.proxyServer.getPluginManager());

this.bind(CarbonChat.class).to(CarbonChatVelocity.class);
this.bind(CarbonServer.class).to(CarbonServerVelocity.class);
this.bind(ProfileResolver.class).to(VelocityProfileResolver.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package net.draycia.carbon.velocity;

import com.google.inject.Inject;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
Expand All @@ -28,6 +28,7 @@
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import java.nio.file.Path;
import javax.inject.Inject;
import net.draycia.carbon.common.config.ConfigManager;
import net.draycia.carbon.common.config.MessagingSettings;
import net.draycia.carbon.common.util.CarbonDependencies;
Expand All @@ -40,52 +41,71 @@ public final class CarbonVelocityBootstrap {

private static final int BSTATS_PLUGIN_ID = 19505;

private final Injector parentInjector;
private final PluginContainer pluginContainer;
private final ProxyServer proxy;
private final Path dataDirectory;
private final Metrics.Factory metricsFactory;
private @MonotonicNonNull Injector injector;
private final Inner inner;

@Inject
@Inject // use javax.inject, so it doesn't get relocated - we use Guice 7 and Velocity uses Guice 6.
public CarbonVelocityBootstrap(
final Injector injector,
final ProxyServer proxyServer,
final PluginContainer pluginContainer,
@DataDirectory final Path dataDirectory,
final Metrics.Factory metricsFactory
) {
this.proxy = proxyServer;
this.parentInjector = injector;
this.pluginContainer = pluginContainer;
this.dataDirectory = dataDirectory;
this.metricsFactory = metricsFactory;

this.inner = new Inner();
}

@Subscribe
public void onProxyInitialize(final ProxyInitializeEvent event) {
new VelocityClasspathAppender(this.proxy, this).append(
CarbonDependencies.resolve(this.dataDirectory.resolve("libraries"))
);

this.injector = this.parentInjector.createChildInjector(
new CarbonChatVelocityModule(this.pluginContainer, this.proxy, this.dataDirectory));
this.injector.getInstance(CarbonChatVelocity.class).onInitialization(this);

final Metrics metrics = this.metricsFactory.make(this, BSTATS_PLUGIN_ID);
metrics.addCustomChart(new SimplePie("user_manager_type", () -> this.injector.getInstance(ConfigManager.class).primaryConfig().storageType().name()));
metrics.addCustomChart(new SimplePie("messaging", () -> {
final MessagingSettings settings = this.injector.getInstance(ConfigManager.class).primaryConfig().messagingSettings();
if (!settings.enabled()) {
return "disabled";
}
return settings.brokerType().name();
}));
this.inner.onProxyInitialize(event);
}

@Subscribe
public void onProxyShutdown(final ProxyShutdownEvent event) {
this.injector.getInstance(CarbonChatVelocity.class).onShutdown();
this.inner.onProxyShutdown(event);
}

// Inner class to avoid classloading issues with guice
private final class Inner {
private @MonotonicNonNull Injector injector;

void onProxyInitialize(final ProxyInitializeEvent event) {
new VelocityClasspathAppender(CarbonVelocityBootstrap.this.proxy, CarbonVelocityBootstrap.this).append(
CarbonDependencies.resolve(CarbonVelocityBootstrap.this.dataDirectory.resolve("libraries"))
);

this.injector = Guice.createInjector(
new CarbonChatVelocityModule(
CarbonVelocityBootstrap.this,
CarbonVelocityBootstrap.this.pluginContainer,
CarbonVelocityBootstrap.this.proxy,
CarbonVelocityBootstrap.this.dataDirectory
)
);
final Injector injector = this.injector;
injector.getInstance(CarbonChatVelocity.class).onInitialization(CarbonVelocityBootstrap.this);

final Metrics metrics = CarbonVelocityBootstrap.this.metricsFactory.make(CarbonVelocityBootstrap.this, BSTATS_PLUGIN_ID);
metrics.addCustomChart(new SimplePie("user_manager_type", () -> injector.getInstance(ConfigManager.class).primaryConfig().storageType().name()));
metrics.addCustomChart(new SimplePie("messaging", () -> {
final MessagingSettings settings = injector.getInstance(ConfigManager.class).primaryConfig().messagingSettings();
if (!settings.enabled()) {
return "disabled";
}
return settings.brokerType().name();
}));
}

void onProxyShutdown(final ProxyShutdownEvent event) {
this.injector.getInstance(CarbonChatVelocity.class).onShutdown();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
import net.draycia.carbon.common.messages.CarbonMessages;
import net.draycia.carbon.velocity.CarbonVelocityBootstrap;
import net.kyori.adventure.audience.Audience;
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
import org.slf4j.Logger;

@DefaultQualifier(NonNull.class)
public final class VelocityChatListener extends ChatListenerInternal implements VelocityListener<PlayerChatEvent> {
Expand Down

0 comments on commit 790ef49

Please sign in to comment.