1
0

Doing First Release

Dieser Commit ist enthalten in:
Chaoscaot 2022-01-02 15:15:55 +01:00
Ursprung b636a81ec5
Commit 3d04a8183d
12 geänderte Dateien mit 231 neuen und 24 gelöschten Zeilen

23
pom.xml
Datei anzeigen

@ -6,7 +6,7 @@
<groupId>de.chaos</groupId> <groupId>de.chaos</groupId>
<artifactId>swlnmngr</artifactId> <artifactId>swlnmngr</artifactId>
<version>1.0-SNAPSHOT</version> <version>0.1</version>
<name>SteamWarLinkManager</name> <name>SteamWarLinkManager</name>
<properties> <properties>
@ -40,11 +40,21 @@
</plugin> </plugin>
</plugins> </plugins>
<resources> <resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>*.version</include>
</includes>
<filtering>true</filtering>
</resource>
<resource> <resource>
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
<includes> <includes>
<include>*.*</include> <include>*.*</include>
</includes> </includes>
<excludes>
<exclude>*.version</exclude>
</excludes>
<filtering>false</filtering> <filtering>false</filtering>
</resource> </resource>
</resources> </resources>
@ -57,12 +67,6 @@
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20211205</version> <version>20211205</version>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
@ -88,5 +92,10 @@
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>4.5.13</version> <version>4.5.13</version>
</dependency> </dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

Datei anzeigen

@ -23,11 +23,14 @@ public class Main {
if(CLIConfig.IS_DEBUG) { if(CLIConfig.IS_DEBUG) {
Configurator.setRootLevel(Level.DEBUG); Configurator.setRootLevel(Level.DEBUG);
} }
if(!CLIConfig.NO_UPDATE) {
UpdateChecker.checkForUpdates();
}
logger.debug("Arguments: {}", Arrays.toString(allArgs)); logger.debug("Arguments: {}", Arrays.toString(allArgs));
if(CLIConfig.ARGS.length > 0) { if(CLIConfig.ARGS.length > 0) {
Router.route(CLIConfig.ARGS); Router.route(CLIConfig.ARGS);
} else { } else {
Router.printRoutes();
} }
} }
} }

Datei anzeigen

@ -0,0 +1,51 @@
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 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("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);
}
}
public static void update() {
}
}

Datei anzeigen

@ -8,17 +8,18 @@ import java.io.File;
public class CLIConfig { public class CLIConfig {
public static final boolean IS_DEBUG; public static final boolean IS_DEBUG;
public static final boolean UPDATE; public static final boolean NO_UPDATE;
public static final File CONFIG; public static final File CONFIG;
public static final File INSTALL_DIR; public static final File INSTALL_DIR;
public static final String[] ARGS; public static final String[] ARGS;
static { static {
Options options = new Options(); Options options = new Options();
options.addOption(new Option("h", "help", false, "Display this Message"));
options.addOption(new Option("d", "debug", false, "Set the Log Level to Debug")); options.addOption(new Option("d", "debug", false, "Set the Log Level to Debug"));
options.addOption(new Option("u", "update", false, "Update the Default libs"));
options.addOption(new Option("c", "config", true, "Use another Config File")); 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("i", "installdir", true, "Use other Install Dir"));
options.addOption(new Option("u", "no-update", false, "Disable the Auto-Update Checker"));
CommandLine cli = null; CommandLine cli = null;
CommandLineParser parser = new DefaultParser(); CommandLineParser parser = new DefaultParser();
@ -32,9 +33,14 @@ public class CLIConfig {
System.exit(1); System.exit(1);
} }
if(cli.hasOption("h")) {
formatter.printHelp("swlnmngr", options, true);
System.exit(0);
}
ARGS = cli.getArgs(); ARGS = cli.getArgs();
IS_DEBUG = cli.hasOption("d"); IS_DEBUG = cli.hasOption("d");
UPDATE = cli.hasOption("u"); NO_UPDATE = cli.hasOption("u");
if(cli.hasOption("i")) { if(cli.hasOption("i")) {
INSTALL_DIR = new File(cli.getOptionValue("i")); INSTALL_DIR = new File(cli.getOptionValue("i"));
} else { } else {

Datei anzeigen

@ -16,10 +16,11 @@ public class Config {
private static final File CONFIG_FILE = new File(CLIConfig.INSTALL_DIR, "config.json"); private static final File CONFIG_FILE = new File(CLIConfig.INSTALL_DIR, "config.json");
public static final String PROJECT_PATH; public static final File PROJECT_PATH;
public static final File LIB_PATH; public static final File LIB_PATH;
public static final String DEFAULTS; public static final String DEFAULTS;
public static final URI LIB_URL; public static final URI LIB_URL;
public static final boolean PRE_RELEASES;
public static final String USERNAME; public static final String USERNAME;
public static final String PASSWORD; public static final String PASSWORD;
@ -40,9 +41,10 @@ public class Config {
System.exit(1); System.exit(1);
} }
PROJECT_PATH = config.getString("projectPath"); PROJECT_PATH = new File(config.getString("projectPath"));
LIB_PATH = new File(config.getString("libPath")); LIB_PATH = new File(config.getString("libPath"));
DEFAULTS = config.getString("defaultName"); DEFAULTS = config.getString("defaultName");
PRE_RELEASES = config.getBoolean("preReleases");
try { try {
LIB_URL = new URI(config.getString("libUrl")); LIB_URL = new URI(config.getString("libUrl"));
} catch (URISyntaxException e) { } catch (URISyntaxException e) {

Datei anzeigen

@ -1,9 +1,7 @@
package de.chaos.swlnmngr.route; package de.chaos.swlnmngr.route;
import de.chaos.swlnmngr.Main; import de.chaos.swlnmngr.Main;
import de.chaos.swlnmngr.route.routes.InstallRoute; import de.chaos.swlnmngr.route.routes.*;
import de.chaos.swlnmngr.route.routes.Route;
import de.chaos.swlnmngr.route.routes.UpdateRoute;
import java.util.*; import java.util.*;
@ -12,7 +10,7 @@ public class Router {
private static final List<Route> ROUTES; private static final List<Route> ROUTES;
static { static {
ROUTES = List.of(new InstallRoute(), new UpdateRoute()); ROUTES = List.of(new InstallRoute(), new UpdateRoute(), new LinkRoute(), new NewRoute());
} }
public static void route(String[] args) { public static void route(String[] args) {
@ -29,4 +27,9 @@ public class Router {
} }
} }
} }
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

@ -1,19 +1,22 @@
package de.chaos.swlnmngr.route.routes; package de.chaos.swlnmngr.route.routes;
import com.sun.nio.file.ExtendedCopyOption;
import de.chaos.swlnmngr.Main; import de.chaos.swlnmngr.Main;
import de.chaos.swlnmngr.config.CLIConfig; import de.chaos.swlnmngr.config.CLIConfig;
import org.apache.commons.lang.SystemUtils;
import org.json.JSONObject;
import org.json.JSONTokener;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.util.Objects; import java.util.Objects;
public class InstallRoute implements Route { public class InstallRoute implements Route {
private static final String[] defaultFiles = new String[] {"default_config.json", "default_swlnmngr.bat", "default_swlnmngr.sh"}; private static final String[] defaultFiles = new String[] {"default_swlnmngr.bat", "default_swlnmngr.sh"};
@Override @Override
public String getName() { public String getName() {
@ -37,6 +40,43 @@ public class InstallRoute implements Route {
} }
} }
if(SystemUtils.IS_OS_UNIX) {
try {
Files.deleteIfExists(new File(CLIConfig.INSTALL_DIR, "swlnmngr").toPath());
Files.createSymbolicLink(new File(CLIConfig.INSTALL_DIR, "swlnmngr").toPath(), new File(CLIConfig.INSTALL_DIR, "swlnmngr.sh").toPath());
} catch (IOException e) {
Main.getLogger().error("Could not create SymLink", e);
return false;
}
}
File configFile = new File(installDir, "config.json");
if(!configFile.exists()) {
try {
Files.copy(Objects.requireNonNull(InstallRoute.class.getResourceAsStream("/default_config.json")), configFile.toPath());
} catch (IOException e) {
Main.getLogger().error("Could not copy Config File", e);
return false;
}
} else {
try {
JSONObject defaultConfig = new JSONObject(new JSONTokener(Objects.requireNonNull(InstallRoute.class.getResourceAsStream("/default_config.json"))));
Main.getLogger().info(defaultConfig);
JSONObject currentConfig = new JSONObject(Files.readString(configFile.toPath()));
Main.getLogger().info(currentConfig);
for (String s : defaultConfig.keySet()) {
if(currentConfig.has(s)) continue;
currentConfig.put(s, defaultConfig.get(s));
}
Files.writeString(configFile.toPath(),
currentConfig.toString(2),
StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException e) {
Main.getLogger().error("Could write Config File", e);
return false;
}
}
try { try {
File jar = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI()); File jar = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI());
Main.getLogger().debug(jar); Main.getLogger().debug(jar);

Datei anzeigen

@ -0,0 +1,50 @@
package de.chaos.swlnmngr.route.routes;
import de.chaos.swlnmngr.Main;
import de.chaos.swlnmngr.config.Config;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class LinkRoute implements Route {
@Override
public String getName() {
return "link";
}
@Override
public boolean route(String[] args) {
if(args.length < 1) {
Main.getLogger().error("Usage: swlnmngr [Project] {Libs}");
return false;
}
String libs = args.length>1?args[1]:Config.DEFAULTS;
File libsFile = new File(Config.LIB_PATH, libs);
if(!libsFile.exists()) {
Main.getLogger().error("No Libs with name: {}", libs);
if(libs.equals(Config.DEFAULTS)) {
Main.getLogger().info("To Create the {} Folder run 'swlnmngr update'", Config.DEFAULTS);
}
return false;
}
File projectDir = new File(Config.PROJECT_PATH, args[0]);
if(!projectDir.exists()) {
Main.getLogger().error("No Project with name: {}", args[0]);
return false;
}
File link = new File(projectDir, "libs");
try {
Files.deleteIfExists(link.toPath());
Main.getLogger().debug(libsFile);
Main.getLogger().debug(link);
Path linkPath = Files.createSymbolicLink(link.toPath(), libsFile.toPath());
Main.getLogger().debug(linkPath);
} catch (IOException e) {
Main.getLogger().error("Could not Create SymLink", e);
return false;
}
return true;
}
}

Datei anzeigen

@ -0,0 +1,43 @@
package de.chaos.swlnmngr.route.routes;
import de.chaos.swlnmngr.Main;
import de.chaos.swlnmngr.config.Config;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
public class NewRoute implements Route {
@Override
public String getName() {
return "new";
}
@Override
public boolean route(String[] args) {
if(args.length < 1) {
Main.getLogger().error("Usage: swlnmngr [Name]");
return false;
}
String name = args[0];
File newFile = new File(Config.LIB_PATH, name);
Main.getLogger().debug(newFile);
if(newFile.exists()) {
Main.getLogger().error("Directory {} already exists", name);
return false;
}
newFile.mkdir();
File defaultFile = new File(Config.LIB_PATH, Config.DEFAULTS);
Main.getLogger().debug(defaultFile);
try {
for (File file : defaultFile.listFiles()) {
Main.getLogger().debug(file);
Files.createSymbolicLink(new File(newFile, file.getName()).toPath(), file.toPath());
}
} catch (IOException e) {
Main.getLogger().error("Could not create SymLink", e);
return false;
}
return true;
}
}

Datei anzeigen

@ -3,8 +3,7 @@
"libPath": "~/libs/", "libPath": "~/libs/",
"defaultName": "default", "defaultName": "default",
"libUrl": "https://steamwar.de/lib.php", "libUrl": "https://steamwar.de/lib.php",
"credentials": { "preReleases": false,
"username": "[EnterName]", "username": "[EnterName]",
"password": "[EnterPW]" "password": "[EnterPW]"
}
} }

Datei anzeigen

@ -0,0 +1 @@
${version}

Datei anzeigen

@ -1 +1 @@
java -jar target/SteamWarLinkManager.jar -i /home/chaos/IdeaProjects/swlnmngr/test/ install java -jar target/SteamWarLinkManager.jar -i ~/IdeaProjects/swlnmngr/test -du install