1
0

Little Bit of Kotlin

Dieser Commit ist enthalten in:
Chaos 2022-01-11 20:28:54 +01:00
Ursprung f41673e69a
Commit 8098e2c339
6 geänderte Dateien mit 176 neuen und 85 gelöschten Zeilen

62
pom.xml
Datei anzeigen

@ -12,6 +12,7 @@
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<kotlin.version>1.6.10</kotlin.version>
</properties>
<build>
@ -38,6 +39,56 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals> <goal>compile</goal> </goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals> <goal>testCompile</goal> </goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
@ -103,5 +154,16 @@
<artifactId>mslinks</artifactId>
<version>1.0.6.2</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Datei anzeigen

@ -12,7 +12,6 @@ import java.util.Arrays;
public class Main {
@Getter
private static final Logger logger = LogManager.getLogger(Main.class);
@Getter
private static String[] allArgs;
@ -33,4 +32,8 @@ public class Main {
Router.printRoutes();
}
}
public static Logger getLogger() {
return logger;
}
}

Datei anzeigen

@ -1,49 +0,0 @@
package de.chaos.swlnmngr;
import de.chaos.swlnmngr.config.Config;
import lombok.experimental.UtilityClass;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
import java.io.IOException;
import java.net.URI;
@UtilityClass
public class UpdateChecker {
private static final URI repoUrl = URI.create("https://steamwar.de/devlabs/api/v1/repos/Chaoscaot/SteamwarLinkManager/releases?draft=false&pre-release=" + Config.PRE_RELEASES + "&page=1&limit=1");
public static final String CURRENT_VERSION;
static {
try {
CURRENT_VERSION = new String(UpdateChecker.class.getResourceAsStream("/jar.version").readAllBytes());
} catch (IOException e) {
Main.getLogger().error("Could not read Version", e);
System.exit(1);
throw new SecurityException(e);
}
}
public static void checkForUpdates() {
try (CloseableHttpClient client = HttpClients.createMinimal()) {
HttpGet get = new HttpGet(repoUrl);
try (CloseableHttpResponse response = client.execute(get)) {
JSONArray array = new JSONArray(new JSONTokener(response.getEntity().getContent()));
JSONObject latestObject = array.getJSONObject(0);
String latestVersion = latestObject.getString("tag_name");
if(!latestVersion.equals(CURRENT_VERSION)) {
Main.getLogger().info("The Running Jar is not the Latest release Version\n\tYour Version: {}\n\tLatest Release Version: {}", CURRENT_VERSION, latestVersion);
Main.getLogger().info("Download the Latest Jar here: https://steamwar.de/devlabs/Chaoscaot/SteamwarLinkManager/releases");
}
}
} catch (IOException e) {
Main.getLogger().error("Could not fetch Updates", e);
}
}
}

Datei anzeigen

@ -0,0 +1,75 @@
package de.chaos.swlnmngr
import de.chaos.swlnmngr.config.Config
import org.apache.http.client.methods.CloseableHttpResponse
import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.client.CloseableHttpClient
import org.apache.http.impl.client.HttpClients
import java.io.IOException
import java.net.URI
import kotlin.system.exitProcess
class UpdateChecker {
companion object {
@JvmStatic
val repoURL :URI = URI.create("https://steamwar.de/devlabs/repos/Chaoscaot/SteamwarLinkManager/releases")
@JvmStatic
public val CURRENT_VERSION :String;
init {
try {
CURRENT_VERSION = String(UpdateChecker::class.java.getResourceAsStream("/jar.version").readAllBytes());
} catch (e :IOException) {
Main.getLogger().error("Could not read Version", e)
exitProcess(1)
throw SecurityException(e)
}
}
@JvmStatic
fun checkForUpdates() {
val client :CloseableHttpClient = HttpClients.createMinimal()
client.use { client: CloseableHttpClient -> {
val get = HttpGet(repoURL);
val response :CloseableHttpResponse = client.execute(get)
response.use { response: CloseableHttpResponse -> {
}}
}}
}
}
}
/*
private static final URI repoUrl = URI.create("https://steamwar.de/devlabs/api/v1/repos/Chaoscaot/SteamwarLinkManager/releases?draft=false&pre-release=" + Config.PRE_RELEASES + "&page=1&limit=1");
public static final String CURRENT_VERSION;
static {
try {
CURRENT_VERSION = new String(UpdateChecker.class.getResourceAsStream("/jar.version").readAllBytes());
} catch (IOException e) {
Main.getLogger().error("Could not read Version", e);
System.exit(1);
throw new SecurityException(e);
}
}
public static void checkForUpdates() {
try (CloseableHttpClient client = HttpClients.createMinimal()) {
HttpGet get = new HttpGet(repoUrl);
try (CloseableHttpResponse response = client.execute(get)) {
JSONArray array = new JSONArray(new JSONTokener(response.getEntity().getContent()));
JSONObject latestObject = array.getJSONObject(0);
String latestVersion = latestObject.getString("tag_name");
if(!latestVersion.equals(CURRENT_VERSION)) {
Main.getLogger().info("The Running Jar is not the Latest release Version\n\tYour Version: {}\n\tLatest Release Version: {}", CURRENT_VERSION, latestVersion);
Main.getLogger().info("Download the Latest Jar here: https://steamwar.de/devlabs/Chaoscaot/SteamwarLinkManager/releases");
}
}
} catch (IOException e) {
Main.getLogger().error("Could not fetch Updates", e);
}
}
*/

Datei anzeigen

@ -1,35 +0,0 @@
package de.chaos.swlnmngr.route;
import de.chaos.swlnmngr.Main;
import de.chaos.swlnmngr.route.routes.*;
import java.util.*;
public class Router {
private static final List<Route> ROUTES;
static {
ROUTES = List.of(new InstallRoute(), new UpdateRoute(), new LinkRoute(), new NewRoute());
}
public static void route(String[] args) {
for (Route route : ROUTES) {
if(route.getName().equalsIgnoreCase(args[0])) {
String[] rArgs = new String[args.length - 1];
System.arraycopy(args, 1, rArgs, 0, args.length - 1);
Main.getLogger().info("Running: {}", route.getName());
if(route.route(rArgs)) {
System.exit(0);
} else {
System.exit(1);
}
}
}
}
public static void printRoutes() {
Main.getLogger().info("Available Routes: ");
Main.getLogger().info("\t{}", ROUTES.stream().map(Route::getName).reduce((s, s2) -> s + ", " + s2).get());
}
}

Datei anzeigen

@ -0,0 +1,35 @@
package de.chaos.swlnmngr.route
import de.chaos.swlnmngr.Main
import de.chaos.swlnmngr.route.routes.*
import org.apache.logging.log4j.Level
import kotlin.system.exitProcess
class Router {
companion object {
@JvmStatic
val ROUTES :List<Route> = listOf(InstallRoute(), UpdateRoute(), LinkRoute(), NewRoute())
@JvmStatic
fun route(args: Array<String>) {
for (route in ROUTES) {
if(route.name.lowercase() == args[0].lowercase()) {
val rArgs :Array<String> = Array(args.size - 1) { i: Int -> args[i + 1] }
Main.getLogger().info("Running: {}", route.name)
if(route.route(rArgs)) {
exitProcess(0)
} else {
exitProcess(1)
}
}
}
}
@JvmStatic
fun printRoutes() {
Main.getLogger().log(Level.INFO, "Available Routes: ")
Main.getLogger().log(Level.INFO, "\t{}", ROUTES.map { route -> route.name }.reduce { acc, s -> "$acc, $s" })
}
}
}