Skip to content

Commit 02da072

Browse files
authored
Merge pull request #191 from rheimus/master
Add support for JSON based config
2 parents efafbc0 + 95bfbd0 commit 02da072

File tree

8 files changed

+488
-2
lines changed

8 files changed

+488
-2
lines changed

build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ configurations {
2424

2525
dependencies {
2626
// Use JUnit Jupiter API for testing.
27-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2'
27+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2', 'org.junit.jupiter:junit-jupiter-params:5.4.2'
2828
// Use JUnit Jupiter Engine for testing.
2929
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.2'
3030

@@ -103,7 +103,10 @@ publishing {
103103
}
104104

105105
clean {
106-
def cleanupFiles = ["publish", "config", "logs", "mods"]
106+
}
107+
108+
task cleanProject {
109+
def cleanupFiles = ["publish", "config", "logs", "mods", "clientmods"]
107110

108111
for (name in cleanupFiles) {
109112
def f = file("$rootDir/$name")

config-client-schema.json

Whitespace-only changes.

config-server-schema.json

Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema",
3+
"$id": "https://github.com/superzanti/ServerSync/server-config.json",
4+
"type": "object",
5+
"title": "The server configuration schema",
6+
"description": "The root schema comprises the entire JSON document.",
7+
"default": {},
8+
"required": [
9+
"general",
10+
"connection",
11+
"rules",
12+
"misc"
13+
],
14+
"additionalProperties": true,
15+
"properties": {
16+
"general": {
17+
"$id": "#/properties/general",
18+
"type": "object",
19+
"title": "The general schema",
20+
"description": "General configuration of the servers behavior",
21+
"default": {},
22+
"examples": [
23+
{
24+
"sync_mode": 2,
25+
"push_client_mods": false
26+
}
27+
],
28+
"required": [
29+
"push_client_mods",
30+
"sync_mode"
31+
],
32+
"additionalProperties": true,
33+
"properties": {
34+
"push_client_mods": {
35+
"$id": "#/properties/general/properties/push_client_mods",
36+
"type": "boolean",
37+
"title": "The push_client_mods schema",
38+
"description": "Should clientmods be used for suggesting client side only mods",
39+
"default": false,
40+
"examples": [
41+
false
42+
]
43+
},
44+
"sync_mode": {
45+
"$id": "#/properties/general/properties/sync_mode",
46+
"type": "integer",
47+
"minimum": 1,
48+
"maximum": 2,
49+
"title": "The sync_mode schema",
50+
"description": "The type of file transfer that the server uses",
51+
"default": 2,
52+
"examples": [
53+
2
54+
]
55+
}
56+
}
57+
},
58+
"connection": {
59+
"$id": "#/properties/connection",
60+
"type": "object",
61+
"title": "The connection schema",
62+
"description": "Details about where your server communicates from",
63+
"default": {},
64+
"examples": [
65+
{
66+
"port": 38067
67+
}
68+
],
69+
"required": [
70+
"port"
71+
],
72+
"additionalProperties": true,
73+
"properties": {
74+
"port": {
75+
"$id": "#/properties/connection/properties/port",
76+
"type": "integer",
77+
"title": "The port schema",
78+
"description": "The port the server is serving on",
79+
"default": 38067,
80+
"examples": [
81+
38067
82+
]
83+
}
84+
}
85+
},
86+
"rules": {
87+
"$id": "#/properties/rules",
88+
"type": "object",
89+
"title": "The rules schema",
90+
"description": "Rules about what files to transfer and how",
91+
"default": {},
92+
"examples": [
93+
{
94+
"file_ignore_list": [
95+
{
96+
"pattern": "**/*.jar"
97+
}
98+
],
99+
"directory_include_list": [
100+
{
101+
"name": "test-mirror",
102+
"mode": "mirror"
103+
},
104+
{
105+
"name": "test-push",
106+
"mode": "push"
107+
}
108+
]
109+
}
110+
],
111+
"required": [
112+
"directory_include_list",
113+
"file_ignore_list"
114+
],
115+
"additionalProperties": true,
116+
"properties": {
117+
"directory_include_list": {
118+
"$id": "#/properties/rules/properties/directory_include_list",
119+
"type": "array",
120+
"title": "The directory_include_list schema",
121+
"description": "The directories that will be scanned for files to sync",
122+
"default": [],
123+
"examples": [
124+
[
125+
{
126+
"name": "test-mirror",
127+
"mode": "mirror"
128+
},
129+
{
130+
"name": "test-push",
131+
"mode": "push"
132+
}
133+
]
134+
],
135+
"additionalItems": true,
136+
"items": {
137+
"$id": "#/properties/rules/properties/directory_include_list/items",
138+
"anyOf": [
139+
{
140+
"$id": "#/properties/rules/properties/directory_include_list/items/anyOf/0",
141+
"type": "object",
142+
"title": "Object style included directory",
143+
"description": "Sync directory with details about how",
144+
"default": {},
145+
"examples": [
146+
{
147+
"mode": "mirror",
148+
"name": "test-mirror"
149+
}
150+
],
151+
"required": [
152+
"name"
153+
],
154+
"additionalProperties": true,
155+
"properties": {
156+
"name": {
157+
"$id": "#/properties/rules/properties/directory_include_list/items/anyOf/0/properties/name",
158+
"type": "string",
159+
"title": "The name schema",
160+
"description": "The name of the directory",
161+
"default": "",
162+
"examples": [
163+
"test-mirror"
164+
]
165+
},
166+
"mode": {
167+
"$id": "#/properties/rules/properties/directory_include_list/items/anyOf/0/properties/mode",
168+
"type": "string",
169+
"pattern": "push|mirror",
170+
"title": "The mode schema",
171+
"description": "What style of sync is being used, mostly affects file deletion client side",
172+
"default": "",
173+
"examples": [
174+
"mirror"
175+
]
176+
}
177+
}
178+
},
179+
{
180+
"$id": "#/properties/rules/properties/directory_include_list/items/anyOf/1",
181+
"type": "string",
182+
"title": "Named default mode",
183+
"description": "Default sync mode for named directory",
184+
"default": "",
185+
"examples": [
186+
"test-directory"
187+
]
188+
}
189+
]
190+
}
191+
},
192+
"file_ignore_list": {
193+
"$id": "#/properties/rules/properties/file_ignore_list",
194+
"type": "array",
195+
"title": "The file_ignore_list schema",
196+
"description": "A list of file patterns to ignore from sync",
197+
"default": [],
198+
"examples": [
199+
[
200+
{
201+
"pattern": "**/*.jar",
202+
"description": "No JARs"
203+
}
204+
]
205+
],
206+
"additionalItems": true,
207+
"items": {
208+
"$id": "#/properties/rules/properties/file_ignore_list/items",
209+
"anyOf": [
210+
{
211+
"$id": "#/properties/rules/properties/file_ignore_list/items/anyOf/0",
212+
"type": "object",
213+
"title": "Detailed configuration",
214+
"description": "Used to specify extra information about a pattern",
215+
"default": {},
216+
"examples": [
217+
{
218+
"pattern": "**/*.jar",
219+
"description": "No JARs"
220+
}
221+
],
222+
"required": [
223+
"pattern"
224+
],
225+
"additionalProperties": true,
226+
"properties": {
227+
"description": {
228+
"$id": "#/properties/rules/properties/file_ignore_list/items/anyOf/0/properties/description",
229+
"type": "string",
230+
"title": "A description about the purpose of this pattern",
231+
"description": "Use this to remind yourself why you are ignoring this pattern",
232+
"default": "",
233+
"examples": [
234+
"No JARs"
235+
]
236+
},
237+
"pattern": {
238+
"$id": "#/properties/rules/properties/file_ignore_list/items/anyOf/0/properties/pattern",
239+
"type": "string",
240+
"title": "The pattern to match against",
241+
"description": "Matches using GLOB patterns",
242+
"default": "",
243+
"examples": [
244+
"**/*.jar"
245+
]
246+
}
247+
}
248+
},
249+
{
250+
"$id": "#/properties/rules/properties/file_ignore_list/items/anyOf/1",
251+
"type": "string",
252+
"title": "Basic configuration",
253+
"description": "A pattern to match without extra details",
254+
"default": "",
255+
"examples": [
256+
"**/*.jar",
257+
"example.jar",
258+
"partial*.jar"
259+
]
260+
}
261+
]
262+
}
263+
}
264+
}
265+
},
266+
"misc": {
267+
"$id": "#/properties/misc",
268+
"type": "object",
269+
"title": "The misc schema",
270+
"description": "Unspecified other settings",
271+
"default": {},
272+
"examples": [
273+
{
274+
"locale": "en_NZ"
275+
}
276+
],
277+
"required": [
278+
"locale"
279+
],
280+
"additionalProperties": true,
281+
"properties": {
282+
"locale": {
283+
"$id": "#/properties/misc/properties/locale",
284+
"type": "string",
285+
"title": "The locale",
286+
"description": "What language should serversync load in",
287+
"default": "",
288+
"examples": [
289+
"en_NZ"
290+
]
291+
}
292+
}
293+
}
294+
}
295+
}

src/main/java/com/superzanti/serversync/SyncConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public class SyncConfig {
6161
private static SyncConfig singleton;
6262
private boolean isUsingIncompatableConfig = false;
6363

64+
public SyncConfig() {
65+
this.configType = EConfigType.COMMON;
66+
}
67+
6468
public SyncConfig(EConfigType type) {
6569
configType = type;
6670
config = new FriendlyConfig();

0 commit comments

Comments
 (0)