Skip to content

Commit

Permalink
Update to cloudnet v4
Browse files Browse the repository at this point in the history
  • Loading branch information
EinDev committed Jan 17, 2025
1 parent 27783da commit cbd368f
Show file tree
Hide file tree
Showing 20 changed files with 268 additions and 146 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up JDK 8
- name: Set up JDK 23
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
java-version: '23'
distribution: 'corretto'

- name: Set up Gradle
uses: gradle/gradle-build-action@v2
Expand Down
26 changes: 15 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ allprojects {

repositories {
mavenCentral()
maven { url = 'https://repo.cloudnetservice.eu/repository/releases/' }
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots/' }
}

project.ext {
dependencyVersionCloudNet = '3.4.5-RELEASE'
dependencyVersionLombok = '1.18.22'
dependencyVersionJunixSocket = '2.8.3'

cliFile = 'cloudnet-client.jar'
dependencyVersionCloudNet = ''
dependencyVersionLombok = '1.18.36'
dependencyVersionJunixSocket = '2.8.3'
dependencyVersionJline = '3.28.0'
cliFile = 'cloudnet-client.jar'
}
}

Expand All @@ -31,13 +30,18 @@ subprojects {
options.encoding = 'UTF-8'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = 1.23
targetCompatibility = 1.23

dependencies {
compileOnly group: 'org.projectlombok', name: 'lombok', version: dependencyVersionLombok
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: dependencyVersionLombok
implementation group: 'com.kohlschutter.junixsocket', name: 'junixsocket-core', version: dependencyVersionJunixSocket
implementation(platform('eu.cloudnetservice.cloudnet:bom:4.0.0-RC11.2'))
annotationProcessor(platform('eu.cloudnetservice.cloudnet:bom:4.0.0-RC11.2'))
compileOnly("""org.projectlombok:lombok:${dependencyVersionLombok}""")
annotationProcessor("""org.projectlombok:lombok:${dependencyVersionLombok}""")
implementation("""com.kohlschutter.junixsocket:junixsocket-core:${dependencyVersionJunixSocket}""")
compileOnly('org.slf4j:slf4j-api:2.0.16')
compileOnly('eu.cloudnetservice.cloudnet:platform-inject-api')
annotationProcessor('eu.cloudnetservice.cloudnet:platform-inject-processor')
}

license {
Expand Down
10 changes: 7 additions & 3 deletions cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ shadowJar {
dependencies {
implementation project(':shared')
implementation group: 'commons-cli', name: 'commons-cli', version: '1.3.1'
implementation group: 'org.jline', name: 'jline', version: '3.9.0'
implementation group: 'de.dytanic.cloudnet', name: 'cloudnet', version: dependencyVersionCloudNet
}
implementation('eu.cloudnetservice.cloudnet:node') {
exclude group: "com.github.CloudNetService.cloud-command-framework", module: "cloud-annotations"
exclude group: "com.github.CloudNetService.cloud-command-framework", module: "cloud-core"
exclude group: "dev.derklaro.gulf", module: "gulf"
}
implementation('org.jline:jline-reader:3.28.0')
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@

package dev.ein.cloudnet.managementsocket.cli;

import de.dytanic.cloudnet.console.IConsole;
import de.dytanic.cloudnet.console.JLine3Console;
import dev.ein.cloudnet.managementsocket.shared.command.Response;
import dev.ein.cloudnet.managementsocket.shared.command.Util;
import eu.cloudnetservice.node.console.JLine3Console;
import eu.cloudnetservice.node.console.handler.ConsoleInputHandler;
import eu.cloudnetservice.node.console.handler.ConsoleTabCompleteHandler;
import lombok.NonNull;
import org.apache.commons.cli.*;
import org.newsclub.net.unix.AFUNIXSocket;
import org.newsclub.net.unix.AFUNIXSocketAddress;

import java.io.File;
import java.io.ObjectOutputStream;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;

public class CommandLineInterface {
public static void main(String[] args) throws Exception {
IConsole console = new JLine3Console();
JLine3Console console = new JLine3Console();
CommandLineParser parser = new DefaultParser();
Options options = new Options();

Expand All @@ -48,15 +52,29 @@ public static void main(String[] args) throws Exception {
ExecutorService socketExec = Executors.newFixedThreadPool(1);
try {
CommandLine commandLine = parser.parse(options, args);
boolean interactive = commandLine.getArgs().length > 0;
File socketFile = new File(commandLine.getOptionValue("socket", "./control.socket"));
try (AFUNIXSocket socket = AFUNIXSocket.newInstance()) {
socket.connect(AFUNIXSocketAddress.of(socketFile), 5000);
ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
LinkedBlockingQueue<Response> responseQueue = new LinkedBlockingQueue<>();
ConsoleHandler consoleHandler = new ConsoleHandler(socketExec, out, responseQueue, console);
new ResponseConsoleWriterThread(socket, console, responseQueue, consoleHandler.getConsoleStopIssued()).start();
console.addCommandHandler(UUID.randomUUID(), consoleHandler::commandHandler);
console.addTabCompletionHandler(UUID.randomUUID(), consoleHandler::tabCompletionHandler);
console.addCommandHandler(UUID.randomUUID(), new ConsoleInputHandler() {
@Override
public void handleInput(@NonNull String s) {
consoleHandler.commandHandler(s);
}
});
console.addTabCompleteHandler(UUID.randomUUID(), new ConsoleTabCompleteHandler() {
@Override
public @NonNull Collection<String> completeInput(@NonNull String s) {
return consoleHandler.tabCompleteHandler(s);
}
});
if(interactive) {
consoleHandler.commandHandler(String.join(" ", commandLine.getArgs()));
}
consoleHandler.waitUntilStop();
console.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@

package dev.ein.cloudnet.managementsocket.cli;

import de.dytanic.cloudnet.common.Properties;
import de.dytanic.cloudnet.console.IConsole;
import dev.ein.cloudnet.managementsocket.shared.command.Response;
import dev.ein.cloudnet.managementsocket.shared.command.Util;
import dev.ein.cloudnet.managementsocket.shared.command.commands.CommandExecutedResponse;
import dev.ein.cloudnet.managementsocket.shared.command.commands.TabCompletionRequest;
import dev.ein.cloudnet.managementsocket.shared.command.commands.TabCompletionResponse;
import dev.ein.cloudnet.managementsocket.shared.command.commands.TextBasedRequest;
import eu.cloudnetservice.node.console.JLine3Console;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand All @@ -45,7 +44,7 @@ public class ConsoleHandler {
private final ExecutorService socketExec;
private final ObjectOutputStream out;
private final LinkedBlockingQueue<Response> responseQueue;
private final IConsole console;
private final JLine3Console console;

public void commandHandler(String commandLine) {
if (commandLine.equals("exit") || commandLine.equals("stop") || commandLine.equals("shutdown")) {
Expand Down Expand Up @@ -74,15 +73,15 @@ private void handleCommand(String s) throws InterruptedException {
}
} catch (IOException e) {
console.writeLine("[ERROR] An error occured sending the command");
console.write(Util.getStackTrace(e));
console.writeLine(Util.getStackTrace(e));
}
}

public Collection<String> tabCompletionHandler(String commandLine, String[] args, Properties properties) {
public Collection<String> tabCompleteHandler(String commandLine) {
try {
return socketExec.submit(() -> handleTabComplete(commandLine)).get();
} catch (InterruptedException | ExecutionException e) {
console.writeLine("[ERROR] Unable to get tab completions");
} catch (InterruptedException|ExecutionException e) {
console.writeLine(String.format("[ERROR] Caught exception while handling tab completion for '%s'", commandLine));
console.writeLine(Util.getStackTrace(e));
return Collections.emptyList();
}
Expand All @@ -101,7 +100,7 @@ private Collection<String> handleTabComplete(String s) throws InterruptedExcepti
}
} catch (IOException e) {
console.writeLine("[ERROR] An error occured sending the command");
console.write(Util.getStackTrace(e));
console.writeLine(Util.getStackTrace(e));
}
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2019-2024 CloudNetService team & contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.ein.cloudnet.managementsocket.cli;

public class NewInterface {
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package dev.ein.cloudnet.managementsocket.cli;

import de.dytanic.cloudnet.console.IConsole;
import dev.ein.cloudnet.managementsocket.shared.command.Response;
import dev.ein.cloudnet.managementsocket.shared.command.Util;
import dev.ein.cloudnet.managementsocket.shared.command.commands.DisconnectRequest;
import dev.ein.cloudnet.managementsocket.shared.command.commands.LogMessage;
import eu.cloudnetservice.node.console.JLine3Console;
import lombok.AllArgsConstructor;
import org.newsclub.net.unix.AFUNIXSocket;
import org.newsclub.net.unix.SocketClosedException;
Expand All @@ -34,7 +34,7 @@
@AllArgsConstructor
public class ResponseConsoleWriterThread extends Thread {
private final AFUNIXSocket socket;
private final IConsole console;
private final JLine3Console console;
private final LinkedBlockingQueue<Response> responseQueue;
private final Lock consoleStopIssued;

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Sun Jan 07 12:18:01 CET 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
44 changes: 31 additions & 13 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -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/HEAD/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/.
Expand All @@ -80,13 +82,12 @@ 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
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +134,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
Expand Down Expand Up @@ -193,18 +201,28 @@ 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, 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 \
"$@"

# 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.
Expand Down
Loading

0 comments on commit cbd368f

Please sign in to comment.