Improved build script.

This commit is contained in:
Andrew Lalis 2022-06-03 10:46:26 +02:00
parent 99f438161f
commit ebad42cf99
4 changed files with 98 additions and 8 deletions

1
.gitignore vendored
View File

@ -37,3 +37,4 @@ build/
src/main/resources/app
/build_system
/log

View File

@ -1,6 +1,8 @@
#!/usr/bin/env dub
/+ dub.sdl:
dependency "dsh" version="~>1.6.1"
dependency "dxml" version="~>0.4.3"
dependency "requests" version="~>2.0.8"
+/
/**
@ -11,27 +13,107 @@
module build_system;
import dsh;
import dxml.dom;
import dxml.util;
import std.stdio;
import std.string;
import std.algorithm;
import std.uni;
const DIST = "./src/main/resources/app";
const DIST_ORIGIN = "./quasar-app/dist/spa";
const APP_DIR = "./quasar-app";
const APP_BUILD = "quasar build -m spa";
const API_BUILD = "mvn clean package spring-boot:repackage -DskipTests=true";
void main(string[] args) {
print("Building RailSignalAPI");
chdir("quasar-app");
const LOG_DIR = "./log";
const API_LOG = LOG_DIR ~ "/api_build.txt";
const APP_LOG = LOG_DIR ~ "/app_build.txt";
int main(string[] args) {
string ver = getVersion();
if (ver is null) {
error("Could not determine version.");
return 1;
}
removeIfExists(LOG_DIR);
mkdir(LOG_DIR);
print("Building Rail Signal v%s", ver);
if (args.length >= 2) {
string command = args[1].strip.toLower;
if (command == "app") {
buildApp();
} else if (command == "api") {
buildApi(ver);
} else if (command == "all") {
buildApp();
buildApi(ver);
if (args.length >= 3 && args[2].strip.toLower == "release") {
if (args.length >= 4) {
string token = args[3].strip();
print("Are you sure you want to create a GitHub release for version %s?", ver);
string response = readln().strip.toLower;
if (response == "yes" || response == "y") createRelease(token, ver);
} else {
error("Missing required personal access token to create a GitHub release.");
return 1;
}
}
}
} else {
buildApp();
buildApi(ver);
}
return 0;
}
/**
* Builds the production version of the frontend app and injects it into the
* API's resources to serve statically.
*/
void buildApp() {
chdir(APP_DIR);
print("Building app...");
runOrQuit(APP_BUILD);
runOrQuit(APP_BUILD, "." ~ APP_LOG); // Use an extra dot because we moved into app dir.
print("Copying dist from %s to %s", DIST_ORIGIN, DIST);
chdir("..");
removeIfExists(DIST);
mkdir(DIST);
copyDir(DIST_ORIGIN, DIST);
print("Building API...");
runOrQuit(API_BUILD);
print("Build complete!");
}
/**
* Builds the production version of the backend API.
*/
void buildApi(string ver) {
print("Building API...");
runOrQuit(API_BUILD, API_LOG);
string[] jars = findFilesByExtension("target", ".jar", false);
string jarFile = jars[0];
string finalJarFile = "./target/rail-signal-" ~ ver ~ ".jar";
// Clean up the jar file name.
copy(jarFile, finalJarFile);
print("Build complete. Created %s", finalJarFile);
}
/**
* Parses the version of the system from the pom file.
* Returns: The version string, or null if it couldn't be found.
*/
string getVersion() {
auto data = parseDOM!simpleXML(readText("pom.xml"));
auto root = data.children[0];
foreach (child; root.children) {
if (child.name == "version") {
return child.children[0].text;
}
}
return null;
}
void createRelease(string token, string ver) {
}

View File

@ -4,6 +4,11 @@ import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
* A switch has a set of possible configurations, each of which links two
* different nodes. Most conventional switches have two configurations, but for
* universal compatibility, as many as 10 may be allowed.
*/
public class SwitchPayload extends ComponentPayload {
@NotNull @Size(max = 10)
public SwitchConfigurationPayload[] possibleConfigurations;

View File

@ -173,9 +173,11 @@ public class ComponentService {
}
private void updateConnectedNodes(PathNode owner, Set<PathNode> newNodes) {
// The set of all path nodes that will be disconnected from the owner.
Set<PathNode> disconnected = new HashSet<>(owner.getConnectedNodes());
disconnected.removeAll(newNodes);
// The set of all path nodes that will be connected to the owner.
Set<PathNode> connected = new HashSet<>(newNodes);
connected.removeAll(owner.getConnectedNodes());