1
0

Commits vergleichen

...
Dieses Repository wurde am 2022-01-11 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.

4 Commits

Autor SHA1 Nachricht Datum
Chaos
6c29cf56a8 More KT 2022-01-11 22:25:31 +01:00
Chaos
5c2ffde227 Merge Master 2022-01-11 21:54:10 +01:00
Chaos
abafded876 Merge branch 'master' into kotlin_rewrite
# Conflicts:
#	src/main/java/de/chaos/swlnmngr/Main.java
#	src/main/java/de/chaos/swlnmngr/UpdateChecker.java
2022-01-11 21:51:04 +01:00
Chaos
8098e2c339 Little Bit of Kotlin 2022-01-11 20:28:54 +01:00
7 geänderte Dateien mit 195 neuen und 84 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>
@ -97,5 +148,16 @@
<artifactId>commons-io</artifactId>
<version>2.11.0</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

@ -1,49 +0,0 @@
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 org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
import java.io.IOException;
import java.net.URI;
public class UpdateChecker {
private 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,82 @@
package de.chaos.swlnmngr
import org.apache.http.client.methods.HttpGet
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/Chaoscaot/SteamwarLinkManager/releases/latest")
@JvmStatic
val download = URI.create("$repoURL/download/")
@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 = HttpClients.custom().disableRedirectHandling().build()
Main.getLogger().debug("Checking for Updates...")
val get = HttpGet(repoURL)
Main.getLogger().debug(get)
val response = client.execute(get)
Main.getLogger().debug(response.statusLine.toString())
val latest = response.getFirstHeader("Location").value.replaceFirst(".*/".toRegex(), "")
if (latest != CURRENT_VERSION) {
Main.getLogger().info("The Running Jar is not the Latest release Version\n\tYour Version: {}\n\tLatest Release Version: {}", CURRENT_VERSION, latest)
Main.getLogger().info("Download the Latest Jar here: https://steamwar.de/devlabs/Chaoscaot/SteamwarLinkManager/releases/latest")
}
response.close()
client.close()
}
}
}
/*
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,6 +1,7 @@
package de.chaos.swlnmngr.config;
import de.chaos.swlnmngr.Main;
import de.chaos.swlnmngr.route.Router;
import org.apache.commons.cli.*;
import java.io.File;
@ -23,6 +24,7 @@ public class CLIConfig {
options.addOption(new Option("c", "config", true, "Use another Config File"));
options.addOption(new Option("i", "installdir", true, "Use other Install Dir"));
options.addOption(new Option("u", "update-checker", false, "Enable the Auto-Update Checker"));
options.addOption(new Option(null, "update-the-fucking-jar-please", false, "Self Describing"));
CommandLine cli = null;
CommandLineParser parser = new DefaultParser();
@ -67,5 +69,8 @@ public class CLIConfig {
} else {
CONFIG = new File(INSTALL_DIR, "config.json");
}
if(cli.hasOption("update-the-fucking-jar-please")) {
Router.route(new String[] {"update-jar"});
}
}
}

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(), UpdateJarRoute())
@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" })
}
}
}

Datei anzeigen

@ -0,0 +1,11 @@
package de.chaos.swlnmngr.route.routes
class UpdateJarRoute :Route {
override fun getName(): String {
return "update-jar"
}
override fun route(args: Array<out String>?): Boolean {
TODO("Not yet implemented")
}
}