-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-98 Move to okaeri-configs. #105
Open
vLuckyyy
wants to merge
14
commits into
master
Choose a base branch
from
move-to-okaeri
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
55cd408
Init commit
failutee 5badd4a
Improve code
failutee bc68ea5
Move TemplateSerializer to ConfigFactory class
failutee 5b046da
Update builds.gradle.kts
failutee d607c3d
Match code-style
failutee 198e71c
Merge branch 'master' into 'move-to-okaeri'
vLuckyyy 9d25f51
Fix post-merge problems
vLuckyyy c249e45
Remove panda.std, after litecommands remove.
vLuckyyy 7f91448
Fix, improve config.
vLuckyyy c91b05b
Update config in readme, after move to okaeri.
vLuckyyy 42cdfc3
Follow rollczi's suggestions
vLuckyyy 2e7b614
Follow rollczi's suggestions
vLuckyyy e64a2e9
Fix relocation.
vLuckyyy dc20450
Remove useless serdes commons.
vLuckyyy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
chatformatter-core/src/main/java/com/eternalcode/formatter/config/ConfigManager.java
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
chatformatter-core/src/main/java/com/eternalcode/formatter/config/ConfigService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.eternalcode.formatter.config; | ||
|
||
import eu.okaeri.configs.ConfigManager; | ||
import eu.okaeri.configs.OkaeriConfig; | ||
import eu.okaeri.configs.serdes.commons.SerdesCommons; | ||
import eu.okaeri.configs.yaml.snakeyaml.YamlSnakeYamlConfigurer; | ||
import org.yaml.snakeyaml.DumperOptions; | ||
import org.yaml.snakeyaml.LoaderOptions; | ||
import org.yaml.snakeyaml.Yaml; | ||
import org.yaml.snakeyaml.constructor.Constructor; | ||
import org.yaml.snakeyaml.representer.Representer; | ||
import org.yaml.snakeyaml.resolver.Resolver; | ||
|
||
import java.io.File; | ||
|
||
public class ConfigService { | ||
|
||
public <T extends OkaeriConfig> T create(Class<T> config, File file) { | ||
T configFile = ConfigManager.create(config); | ||
|
||
YamlSnakeYamlConfigurer yamlConfigurer = new YamlSnakeYamlConfigurer(this.createYaml()); | ||
|
||
configFile | ||
.withConfigurer(yamlConfigurer) | ||
.withSerdesPack(registry -> registry.register(new TemplateSerializer())) | ||
.withBindFile(file) | ||
.withRemoveOrphans(true) | ||
.saveDefaults() | ||
.load(true); | ||
|
||
return configFile; | ||
} | ||
|
||
private Yaml createYaml() { | ||
LoaderOptions loaderOptions = new LoaderOptions(); | ||
Constructor constructor = new Constructor(loaderOptions); | ||
|
||
DumperOptions dumperOptions = new DumperOptions(); | ||
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.AUTO); | ||
dumperOptions.setIndent(2); | ||
dumperOptions.setSplitLines(false); | ||
|
||
Representer representer = new CustomRepresenter(dumperOptions); | ||
Resolver resolver = new Resolver(); | ||
|
||
return new Yaml(constructor, representer, dumperOptions, loaderOptions, resolver); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
chatformatter-core/src/main/java/com/eternalcode/formatter/config/CustomRepresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.eternalcode.formatter.config; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.yaml.snakeyaml.DumperOptions; | ||
import org.yaml.snakeyaml.nodes.Node; | ||
import org.yaml.snakeyaml.nodes.Tag; | ||
import org.yaml.snakeyaml.representer.Represent; | ||
import org.yaml.snakeyaml.representer.Representer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
|
||
class CustomRepresenter extends Representer { | ||
|
||
public CustomRepresenter(DumperOptions options) { | ||
super(options); | ||
this.representers.put(Integer.class, new RepresentInteger()); | ||
this.representers.put(ArrayList.class, new RepresentList()); | ||
this.representers.put(Boolean.class, new RepresentBoolean()); | ||
this.representers.put(String.class, new RepresentString()); | ||
this.representers.put(Map.class, new RepresentMap()); | ||
this.representers.put(HashMap.class, new RepresentMap()); | ||
this.representers.put(LinkedHashMap.class, new RepresentMap()); | ||
this.representers.put(ImmutableMap.class, new RepresentMap()); | ||
} | ||
|
||
private class RepresentString implements Represent { | ||
@Override | ||
public Node representData(Object data) { | ||
if (data instanceof String && ((String) data).contains(" ")) { | ||
return representScalar(Tag.STR, (String) data, DumperOptions.ScalarStyle.DOUBLE_QUOTED); | ||
} | ||
|
||
return representScalar(Tag.STR, data.toString(), DumperOptions.ScalarStyle.PLAIN); | ||
} | ||
} | ||
|
||
private class RepresentMap implements Represent { | ||
public Node representData(Object data) { | ||
return representMapping(Tag.MAP, (Map<?, ?>) data, DumperOptions.FlowStyle.BLOCK); | ||
} | ||
} | ||
|
||
private class RepresentBoolean implements Represent { | ||
@Override | ||
public Node representData(Object data) { | ||
return representScalar(Tag.BOOL, data.toString(), DumperOptions.ScalarStyle.PLAIN); | ||
} | ||
} | ||
|
||
private class RepresentInteger implements Represent { | ||
@Override | ||
public Node representData(Object data) { | ||
return representScalar(Tag.INT, data.toString(), DumperOptions.ScalarStyle.PLAIN); | ||
} | ||
} | ||
|
||
private class RepresentList implements Represent { | ||
@Override | ||
public Node representData(Object data) { | ||
return representSequence(getTag(data.getClass(), Tag.SEQ), (Iterable<?>) data, DumperOptions.FlowStyle.BLOCK); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you force add
"
?