Update 2026.11.06-01
This commit is contained in:
parent
7ee35194be
commit
ba557628e3
1
.gitignore
vendored
1
.gitignore
vendored
@ -44,5 +44,4 @@ bin/
|
||||
|
||||
### Weapie ###
|
||||
/**/config
|
||||
/**/src/test
|
||||
/**/tmp
|
||||
|
||||
@ -3,44 +3,57 @@ import org.gradle.api.credentials.PasswordCredentials
|
||||
plugins {
|
||||
id("java-library")
|
||||
id("maven-publish")
|
||||
id("com.github.johnrengelman.shadow") version("8.1.1")
|
||||
alias(libs.plugins.shadow)
|
||||
}
|
||||
|
||||
allprojects {
|
||||
apply(plugin = "java-library")
|
||||
apply(plugin = "maven-publish")
|
||||
apply(plugin = "com.github.johnrengelman.shadow")
|
||||
apply(plugin = "com.gradleup.shadow")
|
||||
|
||||
group = "de.weapie"
|
||||
version = "2024.07.12-01"
|
||||
version = "2026.11.06-01"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(rootProject.libs.lombok)
|
||||
compileOnly(rootProject.libs.lombok)
|
||||
annotationProcessor(rootProject.libs.lombok)
|
||||
|
||||
implementation(rootProject.libs.annotations)
|
||||
annotationProcessor(rootProject.libs.annotations)
|
||||
compileOnlyApi(rootProject.libs.annotations)
|
||||
|
||||
testAnnotationProcessor(rootProject.libs.lombok)
|
||||
testImplementation(rootProject.libs.lombok)
|
||||
testCompileOnly(rootProject.libs.lombok)
|
||||
testImplementation(platform(rootProject.libs.junit.bom))
|
||||
testImplementation(rootProject.libs.junit.jupiter)
|
||||
testRuntimeOnly(rootProject.libs.junit.launcher)
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
sourceCompatibility = JavaVersion.VERSION_17.toString()
|
||||
targetCompatibility = JavaVersion.VERSION_17.toString()
|
||||
// options
|
||||
options.release.set(17)
|
||||
options.encoding = "UTF-8"
|
||||
options.isIncremental = true
|
||||
}
|
||||
|
||||
tasks.withType<Test>().configureEach {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
events("passed", "skipped", "failed")
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
repositories {
|
||||
maven {
|
||||
name = "jfHomeRepoPrivate"
|
||||
name = "repo"
|
||||
url = uri("https://repo.jf.home/private")
|
||||
credentials(PasswordCredentials::class)
|
||||
authentication {
|
||||
@ -59,8 +72,11 @@ allprojects {
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
archiveBaseName.set("${project.name}")
|
||||
archiveVersion.set("${project.version}")
|
||||
archiveFileName.set("${archiveBaseName.get()}-${archiveVersion.get()}.jar")
|
||||
archiveClassifier.set("all")
|
||||
filesMatching("META-INF/services/**") {
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
}
|
||||
mergeServiceFiles()
|
||||
exclude("META-INF/*.SF", "META-INF/*.RSA", "META-INF/*.DSA")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,27 +1,13 @@
|
||||
dependencies {
|
||||
implementation(libs.mongodb)
|
||||
api(libs.mongodb)
|
||||
implementation(libs.mysql)
|
||||
implementation(libs.postgres)
|
||||
implementation(libs.sqlite)
|
||||
|
||||
compileOnly(libs.gson)
|
||||
api(project(":devlok-utils"))
|
||||
api(project(":devlok-files"))
|
||||
|
||||
testImplementation(libs.gson)
|
||||
testImplementation(platform("org.junit:junit-bom:5.10.2"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
dependsOn(":devlok-utils:shadowJar")
|
||||
dependsOn(":devlok-files:shadowJar")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
events("passed", "skipped", "failed")
|
||||
}
|
||||
}
|
||||
dependsOn(tasks.shadowJar)
|
||||
systemProperty("devlok.shadowJar", tasks.shadowJar.get().archiveFile.get().asFile.absolutePath)
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package de.weapie.devlok.database.mongodb;
|
||||
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoClients;
|
||||
import com.mongodb.MongoClientSettings;
|
||||
import com.mongodb.MongoCredential;
|
||||
import com.mongodb.ServerAddress;
|
||||
@ -44,12 +45,11 @@ public class MongoDBDatabase extends BasicDatabase {
|
||||
this.password.toCharArray()
|
||||
);
|
||||
|
||||
this.mongoClient = new MongoClient(
|
||||
new ServerAddress(
|
||||
this.host,
|
||||
this.port
|
||||
), List.of(mongoCredential)
|
||||
);
|
||||
this.mongoClient = MongoClients.create(MongoClientSettings.builder()
|
||||
.applyToClusterSettings(settings -> settings.hosts(List.of(new ServerAddress(this.host, this.port))))
|
||||
.credential(mongoCredential)
|
||||
.uuidRepresentation(org.bson.UuidRepresentation.JAVA_LEGACY)
|
||||
.build());
|
||||
|
||||
CodecRegistry pojoCodecRegistry = CodecRegistries.fromRegistries(
|
||||
MongoClientSettings.getDefaultCodecRegistry(),
|
||||
@ -71,6 +71,8 @@ public class MongoDBDatabase extends BasicDatabase {
|
||||
public void disconnect() {
|
||||
if (!this.isConnected()) return;
|
||||
this.mongoClient.close();
|
||||
this.mongoClient = null;
|
||||
this.mongoDatabase = null;
|
||||
System.out.println("Successfully disconnected to MongoDB database");
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ package de.weapie.devlok.database.mongodb;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoCursor;
|
||||
import com.mongodb.client.model.Sorts;
|
||||
import com.mongodb.client.model.UpdateOptions;
|
||||
import com.mongodb.client.model.ReplaceOptions;
|
||||
import de.weapie.devlok.database.Database;
|
||||
import de.weapie.devlok.database.utils.BasicService;
|
||||
import de.weapie.devlok.utils.data.Pair;
|
||||
@ -44,7 +44,7 @@ public class MongoDBService implements BasicService {
|
||||
@Override
|
||||
public long count(String collection) {
|
||||
if(!this.database().isConnected()) return 0;
|
||||
return this.collection(collection).count();
|
||||
return this.collection(collection).countDocuments();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -110,7 +110,7 @@ public class MongoDBService implements BasicService {
|
||||
@Override
|
||||
public void replace(String collection, Document filter, Document replace) {
|
||||
if(!this.database().isConnected()) return;
|
||||
this.collection(collection).replaceOne(filter, replace, new UpdateOptions().upsert(true));
|
||||
this.collection(collection).replaceOne(filter, replace, new ReplaceOptions().upsert(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -31,7 +31,7 @@ public class MySQLDatabase extends BasicDatabase {
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
try {
|
||||
return this.connection != null || this.connection.isValid(1);
|
||||
return this.connection != null && !this.connection.isClosed() && this.connection.isValid(1);
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
@ -40,7 +40,7 @@ public class MySQLDatabase extends BasicDatabase {
|
||||
@Override
|
||||
public void connect() {
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
|
||||
String dataSourceName = this.getDataSourceName();
|
||||
this.connection = DriverManager.getConnection(dataSourceName, this.user, this.password);
|
||||
@ -56,7 +56,7 @@ public class MySQLDatabase extends BasicDatabase {
|
||||
|
||||
@Override
|
||||
public void disconnect() {
|
||||
this.autoReconnect.interrupt();
|
||||
if (this.autoReconnect != null) this.autoReconnect.interrupt();
|
||||
|
||||
try {
|
||||
if (this.connection != null) {
|
||||
|
||||
@ -24,7 +24,7 @@ public class PostgresDatabase extends BasicDatabase {
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
try {
|
||||
return this.connection != null || this.connection.isValid(1);
|
||||
return this.connection != null && !this.connection.isClosed() && this.connection.isValid(1);
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ public class SQLiteDatabase extends BasicDatabase {
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
try {
|
||||
return this.connection != null || this.connection.isValid(1);
|
||||
return this.connection != null && !this.connection.isClosed() && this.connection.isValid(1);
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1,20 +1,4 @@
|
||||
dependencies {
|
||||
implementation(libs.gson)
|
||||
api(libs.gson)
|
||||
api(project(":devlok-utils"))
|
||||
|
||||
testImplementation(libs.gson)
|
||||
testImplementation(platform("org.junit:junit-bom:5.10.2"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
dependsOn(":devlok-utils:shadowJar")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
events("passed", "skipped", "failed")
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class JsonUtils {
|
||||
|
||||
@ -35,10 +36,9 @@ public class JsonUtils {
|
||||
}
|
||||
|
||||
public static void writeJson(Object object, File file) {
|
||||
try(FileWriter fileWriter = new FileWriter(file)) {
|
||||
try(FileWriter fileWriter = new FileWriter(file, StandardCharsets.UTF_8)) {
|
||||
String jsonString = JSON.toJson(object);
|
||||
fileWriter.write(jsonString);
|
||||
fileWriter.close();
|
||||
} catch (IOException ex) {
|
||||
System.out.println("Exception thrown while writing the file " + file.getPath());
|
||||
ex.printStackTrace();
|
||||
@ -46,10 +46,9 @@ public class JsonUtils {
|
||||
}
|
||||
|
||||
public static void writePrettyJson(Object object, File file) {
|
||||
try(FileWriter fileWriter = new FileWriter(file)) {
|
||||
try(FileWriter fileWriter = new FileWriter(file, StandardCharsets.UTF_8)) {
|
||||
String prettyJsonString = PRETTY_JSON.toJson(object);
|
||||
fileWriter.write(prettyJsonString);
|
||||
fileWriter.close();
|
||||
} catch (IOException ex) {
|
||||
System.out.println("Exception thrown while writing the file " + file.getPath());
|
||||
ex.printStackTrace();
|
||||
@ -61,11 +60,8 @@ public class JsonUtils {
|
||||
}
|
||||
|
||||
public static <T> T fromJson(File file, Class<T> tClass) {
|
||||
try {
|
||||
FileReader fileReader = new FileReader(file);
|
||||
T config = JSON.fromJson(fileReader, tClass);
|
||||
fileReader.close();
|
||||
return config;
|
||||
try (FileReader fileReader = new FileReader(file, StandardCharsets.UTF_8)) {
|
||||
return JSON.fromJson(fileReader, tClass);
|
||||
} catch (IOException ex) {
|
||||
System.out.println("Exception thrown while reading the file " + file.getPath());
|
||||
ex.printStackTrace();
|
||||
|
||||
@ -1,20 +1,4 @@
|
||||
dependencies {
|
||||
api(project(":devlok-utils"))
|
||||
api(project(":devlok-files"))
|
||||
|
||||
testImplementation(platform("org.junit:junit-bom:5.10.2"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
dependsOn(":devlok-utils:shadowJar")
|
||||
dependsOn(":devlok-files:shadowJar")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
events("passed", "skipped", "failed")
|
||||
}
|
||||
}
|
||||
@ -1,25 +1,9 @@
|
||||
dependencies {
|
||||
implementation(libs.netty5)
|
||||
compileOnly(libs.gson)
|
||||
api(platform(libs.netty.bom))
|
||||
api(libs.bundles.netty)
|
||||
runtimeOnly("io.netty:netty-transport-native-epoll:${libs.versions.netty.get()}:linux-x86_64")
|
||||
runtimeOnly("io.netty:netty-transport-native-epoll:${libs.versions.netty.get()}:linux-aarch_64")
|
||||
api(project(":devlok-utils"))
|
||||
api(project(":devlok-files"))
|
||||
api(project(":devlok-reflections"))
|
||||
|
||||
testImplementation(libs.gson)
|
||||
testImplementation(platform("org.junit:junit-bom:5.10.2"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
dependsOn(":devlok-reflections:shadowJar")
|
||||
dependsOn(":devlok-utils:shadowJar")
|
||||
dependsOn(":devlok-files:shadowJar")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
events("passed", "skipped", "failed")
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
package de.weapie.devlok.networking;
|
||||
|
||||
import de.weapie.devlok.utils.executers.FutureResult;
|
||||
import io.netty5.channel.Channel;
|
||||
import io.netty5.channel.EventLoopGroup;
|
||||
import io.netty5.util.concurrent.FutureListener;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@ -15,6 +15,7 @@ public abstract class CommunicationComponent extends CommunicationListener {
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
@Setter(AccessLevel.PROTECTED)
|
||||
private FutureResult<Void> connectionFuture = new FutureResult<>();
|
||||
private volatile Channel connectionChannel;
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final EventLoopGroup bossGroup;
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
@ -30,11 +31,11 @@ public abstract class CommunicationComponent extends CommunicationListener {
|
||||
|
||||
public abstract void initialize();
|
||||
|
||||
public FutureListener<? super Channel> handleConnectionRelease() {
|
||||
public ChannelFutureListener handleConnectionRelease() {
|
||||
return it -> {
|
||||
if (it.isSuccess()) {
|
||||
connectionChannel = it.channel();
|
||||
connectionFuture.complete(null);
|
||||
it.getNow().closeFuture();
|
||||
} else {
|
||||
connectionFuture.completeExceptionally(it.cause());
|
||||
}
|
||||
@ -42,7 +43,7 @@ public abstract class CommunicationComponent extends CommunicationListener {
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return connectionFuture.isDone();
|
||||
return connectionChannel != null && connectionChannel.isActive();
|
||||
}
|
||||
|
||||
public boolean isAlive() {
|
||||
@ -50,7 +51,8 @@ public abstract class CommunicationComponent extends CommunicationListener {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (connectionChannel != null) connectionChannel.close();
|
||||
bossGroup.shutdownGracefully();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
package de.weapie.devlok.networking;
|
||||
|
||||
import io.netty5.channel.EventLoop;
|
||||
import io.netty5.channel.MultithreadEventLoopGroup;
|
||||
import io.netty5.channel.ServerChannel;
|
||||
import io.netty5.channel.ServerChannelFactory;
|
||||
import io.netty5.channel.epoll.Epoll;
|
||||
import io.netty5.channel.epoll.EpollHandler;
|
||||
import io.netty5.channel.epoll.EpollServerSocketChannel;
|
||||
import io.netty5.channel.epoll.EpollSocketChannel;
|
||||
import io.netty5.channel.nio.NioHandler;
|
||||
import io.netty5.channel.socket.SocketChannel;
|
||||
import io.netty5.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty5.channel.socket.nio.NioSocketChannel;
|
||||
import io.netty.channel.EventLoop;
|
||||
import io.netty.channel.MultiThreadIoEventLoopGroup;
|
||||
import io.netty.channel.ServerChannel;
|
||||
import io.netty.channel.ChannelFactory;
|
||||
import io.netty.channel.epoll.Epoll;
|
||||
import io.netty.channel.epoll.EpollIoHandler;
|
||||
import io.netty.channel.epoll.EpollServerSocketChannel;
|
||||
import io.netty.channel.epoll.EpollSocketChannel;
|
||||
import io.netty.channel.nio.NioIoHandler;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -20,15 +20,19 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class CommunicationNetworkUtils {
|
||||
|
||||
@Contract("_ -> new")
|
||||
public static @NotNull MultithreadEventLoopGroup createEventLoopGroup(int threads) {
|
||||
return new MultithreadEventLoopGroup(threads, Epoll.isAvailable() ? EpollHandler.newFactory() : NioHandler.newFactory());
|
||||
public static @NotNull MultiThreadIoEventLoopGroup createEventLoopGroup(int threads) {
|
||||
return new MultiThreadIoEventLoopGroup(threads, Epoll.isAvailable() ? EpollIoHandler.newFactory() : NioIoHandler.newFactory());
|
||||
}
|
||||
|
||||
public static @NotNull SocketChannel createChannelFactory(EventLoop loop) {
|
||||
return Epoll.isAvailable() ? new EpollSocketChannel(loop) : new NioSocketChannel(loop);
|
||||
return createChannelFactory();
|
||||
}
|
||||
|
||||
public static ServerChannelFactory<? extends ServerChannel> generateChannelFactory() {
|
||||
public static @NotNull SocketChannel createChannelFactory() {
|
||||
return Epoll.isAvailable() ? new EpollSocketChannel() : new NioSocketChannel();
|
||||
}
|
||||
|
||||
public static ChannelFactory<? extends ServerChannel> generateChannelFactory() {
|
||||
return Epoll.isAvailable() ? EpollServerSocketChannel::new : NioServerSocketChannel::new;
|
||||
}
|
||||
|
||||
|
||||
@ -2,9 +2,10 @@ package de.weapie.devlok.networking;
|
||||
|
||||
import de.weapie.devlok.networking.channel.ChannelTransmit;
|
||||
import de.weapie.devlok.networking.packet.Packet;
|
||||
import io.netty5.channel.Channel;
|
||||
import io.netty5.channel.ChannelHandlerContext;
|
||||
import io.netty5.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -14,6 +15,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@AllArgsConstructor
|
||||
@ChannelHandler.Sharable
|
||||
public final class CommunicationTransmitHandler extends SimpleChannelInboundHandler<Packet> {
|
||||
|
||||
private final Function<Channel, List<ChannelTransmit>> findTransmitFunction;
|
||||
@ -21,7 +23,7 @@ public final class CommunicationTransmitHandler extends SimpleChannelInboundHand
|
||||
private final Consumer<ChannelTransmit> channelTransmitConsumer;
|
||||
|
||||
@Override
|
||||
protected void messageReceived(ChannelHandlerContext channelHandlerContext, Packet packet) {
|
||||
protected void channelRead0(ChannelHandlerContext channelHandlerContext, Packet packet) {
|
||||
channelTransmitPacketConsumer.accept(packet, findTransmitFunction.apply(channelHandlerContext.channel()).stream().filter(it -> it.channel().equals(channelHandlerContext.channel())).findFirst().orElseThrow());
|
||||
}
|
||||
|
||||
@ -36,7 +38,7 @@ public final class CommunicationTransmitHandler extends SimpleChannelInboundHand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelExceptionCaught(ChannelHandlerContext ctx, @NotNull Throwable cause) {
|
||||
if (!cause.getMessage().equals("Connection reset")) cause.printStackTrace();
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, @NotNull Throwable cause) {
|
||||
if (!"Connection reset".equals(cause.getMessage())) cause.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,9 +3,9 @@ package de.weapie.devlok.networking.channel;
|
||||
import de.weapie.devlok.networking.codec.PacketDecoder;
|
||||
import de.weapie.devlok.networking.codec.PacketEncoder;
|
||||
import de.weapie.devlok.networking.CommunicationTransmitHandler;
|
||||
import io.netty5.channel.Channel;
|
||||
import io.netty5.handler.codec.LengthFieldBasedFrameDecoder;
|
||||
import io.netty5.handler.codec.LengthFieldPrepender;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
||||
import io.netty.handler.codec.LengthFieldPrepender;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
@ -14,7 +14,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
@Setter
|
||||
@Accessors(fluent = true)
|
||||
@AllArgsConstructor
|
||||
public final class ChannelInitializer extends io.netty5.channel.ChannelInitializer<Channel> {
|
||||
public final class ChannelInitializer extends io.netty.channel.ChannelInitializer<Channel> {
|
||||
|
||||
private final CommunicationTransmitHandler transmitHandler;
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ package de.weapie.devlok.networking.channel;
|
||||
|
||||
import de.weapie.devlok.networking.CommunicationListener;
|
||||
import de.weapie.devlok.networking.packet.Packet;
|
||||
import io.netty5.channel.Channel;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@ -6,9 +6,9 @@ import de.weapie.devlok.networking.packet.Packet;
|
||||
import de.weapie.devlok.networking.CommunicationComponent;
|
||||
import de.weapie.devlok.networking.CommunicationNetworkUtils;
|
||||
import de.weapie.devlok.networking.CommunicationTransmitHandler;
|
||||
import io.netty5.bootstrap.Bootstrap;
|
||||
import io.netty5.channel.ChannelOption;
|
||||
import io.netty5.channel.epoll.Epoll;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.epoll.Epoll;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
@ -43,18 +43,11 @@ public final class CommunicationClient extends CommunicationComponent {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
this.bootstrap.connect(hostname(), port()).addListener(future -> {
|
||||
if (future.isSuccess()) {
|
||||
this.connectionFuture().complete(null);
|
||||
return;
|
||||
}
|
||||
this.connectionFuture().completeExceptionally(future.cause());
|
||||
this.connectionFuture(null);
|
||||
});
|
||||
this.bootstrap.connect(hostname(), port()).addListener(handleConnectionRelease());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(Packet packet) {
|
||||
this.channelTransmit.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ package de.weapie.devlok.networking.client;
|
||||
import de.weapie.devlok.networking.channel.ChannelTransmit;
|
||||
import de.weapie.devlok.networking.packet.Packet;
|
||||
import de.weapie.devlok.networking.CommunicationComponent;
|
||||
import io.netty5.channel.Channel;
|
||||
import io.netty.channel.Channel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@ -3,31 +3,31 @@ package de.weapie.devlok.networking.codec;
|
||||
import de.weapie.devlok.networking.packet.Packet;
|
||||
import de.weapie.devlok.networking.packet.PacketBuffer;
|
||||
import de.weapie.devlok.reflections.common.Allocator;
|
||||
import io.netty5.buffer.Buffer;
|
||||
import io.netty5.channel.ChannelHandlerContext;
|
||||
import io.netty5.handler.codec.ByteToMessageDecoder;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.CorruptedFrameException;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
|
||||
public class PacketDecoder extends ByteToMessageDecoder {
|
||||
import java.util.List;
|
||||
|
||||
// The preceding LengthFieldBasedFrameDecoder supplies one complete frame.
|
||||
public class PacketDecoder extends MessageToMessageDecoder<ByteBuf> {
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, Buffer in) {
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
var buffer = new PacketBuffer(in);
|
||||
|
||||
var className = buffer.readString();
|
||||
|
||||
try {
|
||||
var readableBytes = buffer.readInt();
|
||||
var content = new PacketBuffer(in.copy(in.readerOffset(), readableBytes, true));
|
||||
in.skipReadableBytes(readableBytes);
|
||||
|
||||
var packet = (Packet) Allocator.allocate(Class.forName(className));
|
||||
|
||||
packet.read(content);
|
||||
|
||||
buffer.resetBuffer();
|
||||
ctx.fireChannelRead(packet);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while decoding packet " + className);
|
||||
e.printStackTrace();
|
||||
var readableBytes = buffer.readInt();
|
||||
if (readableBytes < 0 || readableBytes != in.readableBytes()) {
|
||||
throw new CorruptedFrameException("Invalid packet payload length: " + readableBytes);
|
||||
}
|
||||
|
||||
var packetType = Class.forName(className, false, getClass().getClassLoader()).asSubclass(Packet.class);
|
||||
var packet = Allocator.allocate(packetType);
|
||||
if (packet == null) {
|
||||
throw new CorruptedFrameException("Cannot allocate packet: " + className);
|
||||
}
|
||||
// The slice is borrowed from the frame and released by MessageToMessageDecoder.
|
||||
packet.read(new PacketBuffer(in.readSlice(readableBytes)));
|
||||
out.add(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,60 +2,20 @@ package de.weapie.devlok.networking.codec;
|
||||
|
||||
import de.weapie.devlok.networking.packet.Packet;
|
||||
import de.weapie.devlok.networking.packet.PacketBuffer;
|
||||
import io.netty5.buffer.Buffer;
|
||||
import io.netty5.channel.ChannelHandlerContext;
|
||||
import io.netty5.handler.codec.MessageToByteEncoder;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
|
||||
public class PacketEncoder extends MessageToByteEncoder<Packet> {
|
||||
|
||||
private static final HashMap<Packet, PacketBuffer> tempPacketEncoderList = new HashMap<>();
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
protected Buffer allocateBuffer(ChannelHandlerContext ctx, Packet packet) {
|
||||
try {
|
||||
var buffer = PacketBuffer.allocate();
|
||||
|
||||
packet.write(buffer);
|
||||
|
||||
tempPacketEncoderList.put(packet, buffer);
|
||||
|
||||
// amount of chars in class name
|
||||
var bytes = Integer.BYTES +
|
||||
// class name
|
||||
packet.getClass().getName().getBytes(StandardCharsets.UTF_8).length +
|
||||
// amount of bytes in buffer
|
||||
Integer.BYTES +
|
||||
// buffer content
|
||||
buffer.getOrigin().readableBytes();
|
||||
|
||||
return ctx.bufferAllocator().allocate(bytes);
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, Packet msg, Buffer out) {
|
||||
try {
|
||||
var origin = tempPacketEncoderList.get(msg).getOrigin();
|
||||
protected void encode(ChannelHandlerContext ctx, Packet packet, ByteBuf out) {
|
||||
try (var content = PacketBuffer.allocate()) {
|
||||
packet.write(content);
|
||||
var buffer = new PacketBuffer(out);
|
||||
var readableBytes = origin.readableBytes();
|
||||
|
||||
buffer.writeString(msg.getClass().getName());
|
||||
buffer.writeInt(readableBytes);
|
||||
|
||||
origin.copyInto(0, out, out.writerOffset(), readableBytes);
|
||||
out.skipWritableBytes(readableBytes);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while encoding packet " + msg.getClass().getName());
|
||||
e.printStackTrace();
|
||||
buffer.writeString(packet.getClass().getName());
|
||||
buffer.writeInt(content.getOrigin().readableBytes());
|
||||
out.writeBytes(content.getOrigin());
|
||||
}
|
||||
tempPacketEncoderList.remove(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
package de.weapie.devlok.networking.packet;
|
||||
|
||||
import io.netty5.buffer.Buffer;
|
||||
import io.netty5.buffer.BufferAllocator;
|
||||
import io.netty5.buffer.DefaultBufferAllocators;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -13,20 +12,25 @@ import java.util.function.BiConsumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@AllArgsConstructor
|
||||
public final class PacketBuffer {
|
||||
private static final BufferAllocator BUFFER_ALLOCATOR = DefaultBufferAllocators.offHeapAllocator();
|
||||
public final class PacketBuffer implements AutoCloseable {
|
||||
private static final ByteBufAllocator BUFFER_ALLOCATOR = ByteBufAllocator.DEFAULT;
|
||||
|
||||
@Getter
|
||||
private final Buffer origin;
|
||||
private final ByteBuf origin;
|
||||
|
||||
public static PacketBuffer allocate() {
|
||||
return new PacketBuffer(BUFFER_ALLOCATOR.allocate(0));
|
||||
return new PacketBuffer(BUFFER_ALLOCATOR.buffer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
origin.release();
|
||||
}
|
||||
|
||||
public void resetBuffer() {
|
||||
if (origin.readableBytes() > 0) {
|
||||
System.err.println("Buffer not empty! Skipping remaining bytes: " + origin.readableBytes());
|
||||
origin.skipReadableBytes(origin.readableBytes());
|
||||
origin.skipBytes(origin.readableBytes());
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,7 +149,7 @@ public final class PacketBuffer {
|
||||
return this.origin.readByte();
|
||||
}
|
||||
|
||||
public PacketBuffer writeBytes(Buffer bytes) {
|
||||
public PacketBuffer writeBytes(ByteBuf bytes) {
|
||||
this.origin.writeBytes(bytes);
|
||||
return this;
|
||||
}
|
||||
@ -168,4 +172,4 @@ public final class PacketBuffer {
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,20 +6,20 @@ import de.weapie.devlok.networking.CommunicationTransmitHandler;
|
||||
import de.weapie.devlok.networking.channel.ChannelInitializer;
|
||||
import de.weapie.devlok.networking.channel.ChannelTransmit;
|
||||
import de.weapie.devlok.networking.packet.Packet;
|
||||
import io.netty5.bootstrap.ServerBootstrap;
|
||||
import io.netty5.channel.ChannelOption;
|
||||
import io.netty5.channel.EventLoopGroup;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Accessors(fluent = true)
|
||||
public final class CommunicationServer extends CommunicationComponent {
|
||||
|
||||
@Getter
|
||||
private final List<ChannelTransmit> channels = new ArrayList<>();
|
||||
private final List<ChannelTransmit> channels = new CopyOnWriteArrayList<>();
|
||||
private final EventLoopGroup workerGroup = CommunicationNetworkUtils.createEventLoopGroup(0);
|
||||
|
||||
public CommunicationServer(String hostname, int port) {
|
||||
@ -50,4 +50,12 @@ public final class CommunicationServer extends CommunicationComponent {
|
||||
public void sendPacket(Packet packet) {
|
||||
this.channels.forEach(channelTransmit -> channelTransmit.sendPacket(packet));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
channels.forEach(channelTransmit -> channelTransmit.channel().close());
|
||||
channels.clear();
|
||||
workerGroup.shutdownGracefully();
|
||||
super.close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import de.weapie.devlok.networking.CommunicationComponent;
|
||||
import de.weapie.devlok.networking.channel.ChannelTransmit;
|
||||
import de.weapie.devlok.networking.packet.Packet;
|
||||
import de.weapie.devlok.networking.packet.RequestPacket;
|
||||
import io.netty5.channel.Channel;
|
||||
import io.netty.channel.Channel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CommunicationServerTransmit extends ChannelTransmit {
|
||||
|
||||
@ -1,19 +1,4 @@
|
||||
dependencies {
|
||||
api(project(":devlok-utils"))
|
||||
|
||||
testImplementation(project(":devlok-logger"))
|
||||
testImplementation(platform("org.junit:junit-bom:5.10.2"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
dependsOn(":devlok-utils:shadowJar")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
events("passed", "skipped", "failed")
|
||||
}
|
||||
}
|
||||
@ -1,22 +1,5 @@
|
||||
dependencies {
|
||||
implementation(libs.redis)
|
||||
api(libs.redis)
|
||||
api(project(":devlok-utils"))
|
||||
api(project(":devlok-files"))
|
||||
|
||||
testImplementation(libs.gson)
|
||||
testImplementation(platform("org.junit:junit-bom:5.10.2"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
dependsOn(":devlok-utils:shadowJar")
|
||||
dependsOn(":devlok-files:shadowJar")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
events("passed", "skipped", "failed")
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
dependencies {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
dependencies {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,23 +1,36 @@
|
||||
[versions]
|
||||
annotations = "24.1.0"
|
||||
lombok = "1.18.32"
|
||||
gson = "2.11.0"
|
||||
netty5 = "5.0.0.Alpha5"
|
||||
mongodb = "3.12.14"
|
||||
mysql = "5.1.36"
|
||||
postgres = "42.7.4"
|
||||
sqlite = "3.46.0.0"
|
||||
redis = "4.2.0"
|
||||
annotations = "26.1.0"
|
||||
lombok = "1.18.48"
|
||||
gson = "2.15.0"
|
||||
netty = "4.2.20.Final"
|
||||
mongodb = "5.14.0"
|
||||
mysql = "26.10.0"
|
||||
postgres = "42.7.14"
|
||||
sqlite = "3.54.1.0"
|
||||
redis = "8.0.2"
|
||||
junit = "6.1.3"
|
||||
shadow = "9.6.1"
|
||||
|
||||
[libraries]
|
||||
lombok = { group = "org.projectlombok", name="lombok", version.ref = "lombok" }
|
||||
annotations = { group = "org.jetbrains", name="annotations", version.ref = "annotations" }
|
||||
gson = { group = "com.google.code.gson", name="gson", version.ref = "gson" }
|
||||
netty5 = { group = "io.netty", name = "netty5-all", version.ref = "netty5" }
|
||||
mongodb = { group = "org.mongodb", name = "mongodb-driver", version.ref = "mongodb" }
|
||||
mysql = { group = "mysql", name = "mysql-connector-java", version.ref = "mysql" }
|
||||
netty-bom = { group = "io.netty", name = "netty-bom", version.ref = "netty" }
|
||||
netty-buffer = { group = "io.netty", name = "netty-buffer" }
|
||||
netty-transport = { group = "io.netty", name = "netty-transport" }
|
||||
netty-codec = { group = "io.netty", name = "netty-codec-base" }
|
||||
netty-epoll = { group = "io.netty", name = "netty-transport-classes-epoll" }
|
||||
mongodb = { group = "org.mongodb", name = "mongodb-driver-sync", version.ref = "mongodb" }
|
||||
mysql = { group = "com.mysql", name = "mysql-connector-j", version.ref = "mysql" }
|
||||
postgres = { group = "org.postgresql", name = "postgresql", version.ref = "postgres" }
|
||||
sqlite = { group = "org.xerial", name = "sqlite-jdbc", version.ref = "sqlite" }
|
||||
redis = { group = "redis.clients", name = "jedis", version.ref = "redis" }
|
||||
junit-bom = { group = "org.junit", name = "junit-bom", version.ref = "junit" }
|
||||
junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter" }
|
||||
junit-launcher = { group = "org.junit.platform", name = "junit-platform-launcher" }
|
||||
|
||||
[plugins]
|
||||
[bundles]
|
||||
netty = ["netty-buffer", "netty-transport", "netty-codec", "netty-epoll"]
|
||||
|
||||
[plugins]
|
||||
shadow = { id = "com.gradleup.shadow", version.ref = "shadow" }
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
8
gradle/wrapper/gradle-wrapper.properties
vendored
8
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,10 @@
|
||||
#Tue Jan 23 09:21:27 CET 2024
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||
distributionSha256Sum=0b00b0ffe07c4d4789c12d4935a44a7057d55774b7540bd4a3f76f336deb177a
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.0-bin.zip
|
||||
networkTimeout=10000
|
||||
retries=0
|
||||
retryBackOffMs=500
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
54
gradlew
vendored
54
gradlew
vendored
@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
# Copyright © 2015 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -15,10 +15,12 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
# gradlew start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
@ -27,7 +29,7 @@
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
# ksh gradlew
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
@ -55,7 +57,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@ -80,13 +82,11 @@ do
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@ -114,7 +114,6 @@ case "$( uname )" in #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
@ -133,22 +132,29 @@ location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
@ -165,7 +171,6 @@ fi
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
@ -193,18 +198,27 @@ if "$cygwin" || "$msys" ; then
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
|
||||
93
gradlew.bat
vendored
93
gradlew.bat
vendored
@ -13,19 +13,49 @@
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem gradlew startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
@rem Set local scope for the variables, and ensure extensions are enabled
|
||||
setlocal EnableExtensions
|
||||
|
||||
@rem Catch executions from older scripts and ensure they exit cleanly.
|
||||
@rem This can be removed once we can be reasonably confident that few people
|
||||
@rem will be migrating directly to this new wrapper.
|
||||
goto afterSafetyNet
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
goto exitWithErrorLevel
|
||||
:afterSafetyNet
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@ -40,15 +70,16 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
1>&2 echo.
|
||||
1>&2 echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
1>&2 echo.
|
||||
1>&2 echo Please set the JAVA_HOME variable in your environment to match the
|
||||
1>&2 echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
"%COMSPEC%" /c exit 1
|
||||
goto exitWithErrorLevel
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
@ -56,34 +87,26 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
1>&2 echo.
|
||||
1>&2 echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
1>&2 echo.
|
||||
1>&2 echo Please set the JAVA_HOME variable in your environment to match the
|
||||
1>&2 echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
"%COMSPEC%" /c exit 1
|
||||
goto exitWithErrorLevel
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
@rem Execute gradlew
|
||||
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
|
||||
@rem which allows us to clear the local environment before executing the java command
|
||||
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel & goto exitWithErrorLevel
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@rem This label must not be changed. We rely on old scripts being able to jump to this point.
|
||||
:exitWithErrorLevel
|
||||
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
|
||||
"%COMSPEC%" /c exit %ERRORLEVEL%
|
||||
|
||||
Loading…
Reference in New Issue
Block a user