Skip to content

Commit 1ffc720

Browse files
committed
Fix config serialization
1 parent e296660 commit 1ffc720

File tree

8 files changed

+100
-13
lines changed

8 files changed

+100
-13
lines changed

.github/workflows/release.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ jobs:
1616
java-version: 17
1717
distribution: 'zulu'
1818
check-latest: true
19-
# - name: Build Changelog
20-
# id: build_changelog
21-
# uses: mikepenz/release-changelog-builder-action@v1
22-
# with:
23-
# commitMode: true
24-
# token: ${{ github.token }}
2519
- name: Setup ENV
2620
run: echo "TAG=${GITHUB_REF:10}" >> $GITHUB_ENV
2721
- name: Grant execute permission for gradlew
@@ -31,14 +25,20 @@ jobs:
3125
run: ./gradlew buildAll -Pversion=${{ env.TAG }}
3226
env:
3327
BUILD_NUMBER: ${{ github.run_number }}
28+
- name: Make Changelog
29+
uses: FabricMC/fabric-action-scripts@v1
30+
id: changelog
31+
with:
32+
context: changelog
33+
workflow_id: release.yml
3434
- name: Create release
3535
id: create_release
3636
uses: ncipollo/release-action@v1
3737
with:
3838
token: ${{ github.token }}
3939
tag: ${{ github.ref }}
4040
name: Release ${{ env.TAG }}
41-
# body: ${{steps.build_changelog.outputs.changelog}}
41+
body: ${{ steps.changelog.outputs.changelog }}
4242
artifactErrorsFailBuild: true
4343
artifacts: 'build/libs/**.jar'
4444
generateReleaseNotes: true

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
name = "ReLauncher"
2-
version = 1.1.0-dirty
2+
version = 2.0.0-dirty

src/api/java/com/mcmoddev/relauncher/api/BaseProcessManager.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
/*
2+
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
3+
* Copyright (C) 2016-2022 <MMD - MinecraftModDevelopment>
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation;
8+
* Specifically version 2.1 of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18+
* USA
19+
* https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
20+
*/
121
package com.mcmoddev.relauncher.api;
222

323
import org.jetbrains.annotations.NotNull;

src/api/java/com/mcmoddev/relauncher/api/CustomScriptManager.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
/*
2+
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
3+
* Copyright (C) 2016-2022 <MMD - MinecraftModDevelopment>
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation;
8+
* Specifically version 2.1 of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18+
* USA
19+
* https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
20+
*/
121
package com.mcmoddev.relauncher.api;
222

323
import java.util.List;

src/api/java/com/mcmoddev/relauncher/api/LauncherFactory.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,22 @@ default Path getConfigPath(Path launcherDirectory) {
6464
@NotNull
6565
JarUpdater createUpdater(T config);
6666

67+
/**
68+
* Creates a {@link CustomScriptManager}.
69+
*
70+
* @param config the launcher config
71+
* @return the script manager
72+
*/
6773
default CustomScriptManager createScriptManager(T config) {
68-
throw new UnsupportedOperationException();
74+
throw new UnsupportedOperationException("Custom Script Managers are unsupported by this factory.");
6975
}
7076

7177
/**
7278
* Creates a {@link DiscordIntegration}. <br>
7379
* The launcher only calls this method if Discord Integration is enabled in the config.
7480
*
7581
* @param config the launcher config
76-
* @param updater the {@link BaseProcessManager process manager}
82+
* @param manager the {@link BaseProcessManager process manager}
7783
* @return the integration instance. Can be {@code null}.
7884
*/
7985
@Nullable
@@ -96,5 +102,6 @@ default RepoInfo getLauncherRepo() {
96102
@Nullable
97103
String getSelfUpdateUrl(String tagName) throws IOException, InterruptedException;
98104

99-
record RepoInfo(String owner, String repo) {}
105+
record RepoInfo(String owner, String repo) {
106+
}
100107
}

src/launcher/java/com/mcmoddev/relauncher/Config.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@
2121
package com.mcmoddev.relauncher;
2222

2323
import com.mcmoddev.relauncher.api.LauncherConfig;
24+
import io.leangen.geantyref.TypeToken;
25+
import org.checkerframework.checker.nullness.qual.Nullable;
2426
import org.spongepowered.configurate.CommentedConfigurationNode;
2527
import org.spongepowered.configurate.ConfigurateException;
28+
import org.spongepowered.configurate.ConfigurationNode;
2629
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
2730
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
2831
import org.spongepowered.configurate.objectmapping.meta.Comment;
2932
import org.spongepowered.configurate.objectmapping.meta.Required;
3033
import org.spongepowered.configurate.objectmapping.meta.Setting;
34+
import org.spongepowered.configurate.serialize.SerializationException;
35+
import org.spongepowered.configurate.serialize.TypeSerializer;
3136

37+
import java.lang.reflect.Type;
3238
import java.nio.file.Files;
3339
import java.nio.file.Path;
3440
import java.util.ArrayList;
@@ -48,6 +54,11 @@ public class Config implements LauncherConfig {
4854
- CUSTOM_SCRIPT => manages a custom java launch script, does NOT support updating""")
4955
public LauncherMode mode = LauncherMode.JAR;
5056

57+
@Override
58+
public LauncherMode getLauncherMode() {
59+
return mode;
60+
}
61+
5162
@Setting("jar_path")
5263
@Comment("Only if the mode is JAR, the path of the jar to launch.")
5364
public String jarPath = "file.jar";
@@ -164,6 +175,7 @@ public static <T> T load(final Path path, final Class<T> cfgType, final T defaul
164175
.emitComments(true)
165176
.prettyPrinting(true)
166177
.path(path)
178+
.defaultOptions(opt -> opt.serializers(builder -> builder.register(TypeToken.get(LauncherMode.class), new ModeSerializer())))
167179
.build();
168180
final var configSerializer = Objects.requireNonNull(loader.defaultOptions().serializers().get(cfgType));
169181
final var type = io.leangen.geantyref.TypeToken.get(cfgType).getType();
@@ -185,12 +197,35 @@ public static <T> T load(final Path path, final Class<T> cfgType, final T defaul
185197
final var configRef = loader.loadToReference();
186198

187199
{ // Add new values to the config
188-
final var inMemoryNode = CommentedConfigurationNode.factory().createNode();
200+
final var inMemoryNode = CommentedConfigurationNode
201+
.root(loader.defaultOptions());
189202
configSerializer.serialize(type, defaultValue, inMemoryNode);
190203
configRef.node().mergeFrom(inMemoryNode);
191204
configRef.save();
192205
}
193206

194207
return configRef.referenceTo(cfgType).get();
195208
}
209+
210+
private static final class ModeSerializer implements TypeSerializer<LauncherMode> {
211+
212+
@Override
213+
public LauncherMode deserialize(final Type type, final ConfigurationNode node) throws SerializationException {
214+
final var str = node.getString();
215+
if (str == null)
216+
return null;
217+
for (final var val : LauncherMode.class.getEnumConstants())
218+
if (str.equalsIgnoreCase(val.toString()))
219+
return val;
220+
return null;
221+
}
222+
223+
@Override
224+
public void serialize(final Type type, @Nullable final LauncherMode obj, final ConfigurationNode node) throws SerializationException {
225+
if (obj == null)
226+
node.raw(null);
227+
else
228+
node.set(obj.toString());
229+
}
230+
}
196231
}

src/launcher/java/com/mcmoddev/relauncher/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public final class Main {
8888
public static final ScheduledThreadPoolExecutor SERVICE;
8989

9090
static {
91-
final var service = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1, r -> new Thread(THREAD_GROUP, r, "UpdatingLauncher"));
91+
final var service = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1, r -> new Thread(THREAD_GROUP, r, "ReLauncher"));
9292
service.setKeepAliveTime(1, TimeUnit.HOURS);
9393
SERVICE = service;
9494
}

src/launcher/java/com/mcmoddev/relauncher/WrappingFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package com.mcmoddev.relauncher;
2222

2323
import com.mcmoddev.relauncher.api.BaseProcessManager;
24+
import com.mcmoddev.relauncher.api.CustomScriptManager;
2425
import com.mcmoddev.relauncher.api.DiscordIntegration;
2526
import com.mcmoddev.relauncher.api.JarUpdater;
2627
import com.mcmoddev.relauncher.api.LauncherConfig;
@@ -68,4 +69,8 @@ public JarUpdater createUpdater(final Object config) {
6869
return delegate.getSelfUpdateUrl(tagName);
6970
}
7071

72+
@Override
73+
public CustomScriptManager createScriptManager(final T config) {
74+
return delegate.createScriptManager(config);
75+
}
7176
}

0 commit comments

Comments
 (0)