Skip to content

Commit 3b9c3b5

Browse files
author
TechsCode
committed
Slightly adjusted config format making it easier to use
1 parent ccfa7a3 commit 3b9c3b5

3 files changed

Lines changed: 12 additions & 15 deletions

File tree

src/main/java/me/TechsCode/ReleaseServer/Config.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package me.TechsCode.ReleaseServer;
22

3-
import com.google.gson.Gson;
4-
import com.google.gson.JsonObject;
5-
import com.google.gson.JsonParser;
3+
import com.google.gson.*;
64
import me.TechsCode.ReleaseServer.objects.Deployment;
75
import me.TechsCode.ReleaseServer.objects.Project;
86
import me.TechsCode.ReleaseServer.objects.Remote;
@@ -18,6 +16,7 @@
1816
import java.util.List;
1917
import java.util.Map;
2018
import java.util.stream.Collectors;
19+
import java.util.stream.StreamSupport;
2120

2221
public class Config {
2322

@@ -52,6 +51,12 @@ public int getPort(){
5251
return root.get("port").getAsInt();
5352
}
5453

54+
public List<String> getTokens(){
55+
return StreamSupport.stream(root.getAsJsonArray("apiTokens").spliterator(), false)
56+
.map(JsonElement::getAsString)
57+
.collect(Collectors.toList());
58+
}
59+
5560
private Map<String, Remote> getRemotes(){
5661
JsonObject jsonObject = root.getAsJsonObject("remotes");
5762

@@ -71,13 +76,12 @@ private List<Deployment> getDeploymentsList(JsonObject jsonObject, Map<String, R
7176
return jsonObject.entrySet().stream()
7277
.map(deployment -> {
7378
JsonObject data_ = (JsonObject) deployment.getValue();
74-
String name_ = deployment.getKey();
7579
boolean enabled_ = data_.get("enabled").getAsBoolean();
76-
Remote remote_ = remoteMap.getOrDefault(data_.get("remote").getAsString(), null);
80+
Remote remote_ = remoteMap.getOrDefault(deployment.getKey(), null);
7781
String path_ = data_.get("path").getAsString();
7882
String[] commands = gson.fromJson(data_.getAsJsonArray("commands"), String[].class);
7983

80-
return new Deployment(name_, enabled_, remote_, path_, commands);
84+
return new Deployment(enabled_, remote_, path_, commands);
8185
}).collect(Collectors.toList());
8286
}
8387

src/main/java/me/TechsCode/ReleaseServer/objects/Deployment.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,18 @@
22

33
public class Deployment {
44

5-
private String name;
65
private boolean enabled;
76
private Remote remote;
87
private String path;
98
private String[] commands;
109

11-
public Deployment(String name, boolean enabled, Remote remote, String path, String[] commands) {
12-
this.name = name;
10+
public Deployment(boolean enabled, Remote remote, String path, String[] commands) {
1311
this.enabled = enabled;
1412
this.remote = remote;
1513
this.path = path;
1614
this.commands = commands;
1715
}
1816

19-
public String getName() {
20-
return name;
21-
}
22-
2317
public boolean isEnabled() {
2418
return enabled;
2519
}

src/main/resources/config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
"githubToken": null,
2121

2222
"deployments": {
23-
"ExampleDeployment": {
23+
"exampleRemote": {
2424
"enabled": false,
25-
"remote": "exampleRemote",
2625
"path": "/home/server",
2726
"commands": []
2827
}

0 commit comments

Comments
 (0)