From fae91a45be7818523c5cd94382110cb6150dafd0 Mon Sep 17 00:00:00 2001 From: Scarsz Date: Tue, 9 Feb 2021 01:29:32 -0800 Subject: [PATCH 1/9] bump version Took 12 seconds --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4333a59..b9de1cc 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ github.scarsz configuralize - 1.3.2 + 1.4.0 UTF-8 From 41846bb985ff005ee298804e21cfeabd9f840a2b Mon Sep 17 00:00:00 2001 From: Scarsz Date: Tue, 9 Feb 2021 01:41:13 -0800 Subject: [PATCH 2/9] remove ability to set instance fields doesn't make sense to have Took 12 minutes --- .../scarsz/configuralize/DynamicConfig.java | 37 +++---------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/src/main/java/github/scarsz/configuralize/DynamicConfig.java b/src/main/java/github/scarsz/configuralize/DynamicConfig.java index e55a35e..6214cf6 100644 --- a/src/main/java/github/scarsz/configuralize/DynamicConfig.java +++ b/src/main/java/github/scarsz/configuralize/DynamicConfig.java @@ -100,7 +100,7 @@ public void loadAll() throws IOException, ParseException { } /** - * Map this config's values to the target class's static fields + * Map this config's values to the target class's static fields marked with {@link Option} * @param targetClass the class to map values to * @param mappings mapping functions to use when mapping values to the appropriate type */ @@ -113,47 +113,22 @@ public void map(Class targetClass, MappingFunction... mappings) { * @param mappings mapping functions to use when mapping values to the appropriate type */ public void map(Class targetClass, List> mappings) { - mapFields(targetClass, null, mappings); + mapFields(targetClass, mappings); for (Class declared : targetClass.getDeclaredClasses()) { map(declared, mappings); } } /** - * Map this config's values to the given object's instance fields marked with {@link Option} - * @param object the class to map values to - * @param mappings mapping functions to use when mapping values to the appropriate type - */ - public void map(Object object, MappingFunction... mappings) { - map(object, Arrays.asList(mappings)); - } - /** - * Map this config's values to the given object's instance fields marked with {@link Option} - * @param object the class to map values to - * @param mappings mapping functions to use when mapping values to the appropriate type - */ - public void map(Object object, List> mappings) { - mapFields(object.getClass(), object, mappings); - for (Class declared : object.getClass().getDeclaredClasses()) { - map(declared, mappings); - } - } - - /** - * Iterate over the given class's declared fields, setting fields marked with {@link Option} to the option value + * Iterate over the given class's declared static fields, setting fields marked with {@link Option} to the option value * @param clazz the class to iterate fields for - * @param instance the instance to set values on, null will set fields statically instead * @param mappings mapping functions to use when mapping values to the appropriate type */ - private void mapFields(Class clazz, Object instance, List> mappings) { + private void mapFields(Class clazz, List> mappings) { for (Field field : clazz.getDeclaredFields()) { - if (instance == null && !Modifier.isStatic(field.getModifiers())) { - // we can only set static values because we don't have an instance - continue; - } + if (!Modifier.isStatic(field.getModifiers())) continue; if (!field.isAnnotationPresent(Option.class)) continue; - Option fieldAnnotation = field.getAnnotation(Option.class); String key = fieldAnnotation.key(); @@ -195,7 +170,7 @@ private void mapFields(Class clazz, Object instance, List> break; } } - field.set(instance, value); + field.set(null, value); } catch (IllegalAccessException e) { throw new RuntimeException("Field " + field + " is not accessible"); } catch (Throwable e) { From 0b30f3074d456cf3f88ab16f2d5f5a9bdc6fad1e Mon Sep 17 00:00:00 2001 From: Scarsz Date: Tue, 9 Feb 2021 01:41:47 -0800 Subject: [PATCH 3/9] add DynamicConfig#map to map fields to config class' static fields with example Took 34 seconds --- .../scarsz/configuralize/DynamicConfig.java | 15 ++++++++++ .../test/ChildDynamicConfigExample.java | 30 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/test/java/github/scarsz/configuralize/test/ChildDynamicConfigExample.java diff --git a/src/main/java/github/scarsz/configuralize/DynamicConfig.java b/src/main/java/github/scarsz/configuralize/DynamicConfig.java index 6214cf6..3038af8 100644 --- a/src/main/java/github/scarsz/configuralize/DynamicConfig.java +++ b/src/main/java/github/scarsz/configuralize/DynamicConfig.java @@ -99,6 +99,21 @@ public void loadAll() throws IOException, ParseException { } } + /** + * Map this config's values to this config's static fields marked with {@link Option} + * @param mappingFunctions mapping functions to use when mapping values to the appropriate type + */ + public void map(MappingFunction... mappingFunctions) { + map(this.getClass(), mappingFunctions); + } + /** + * Map this config's values to this config's static fields marked with {@link Option} + * @param mappingFunctions mapping functions to use when mapping values to the appropriate type + */ + public void map(List> mappingFunctions) { + map(this.getClass(), mappingFunctions); + } + /** * Map this config's values to the target class's static fields marked with {@link Option} * @param targetClass the class to map values to diff --git a/src/test/java/github/scarsz/configuralize/test/ChildDynamicConfigExample.java b/src/test/java/github/scarsz/configuralize/test/ChildDynamicConfigExample.java new file mode 100644 index 0000000..e1953d1 --- /dev/null +++ b/src/test/java/github/scarsz/configuralize/test/ChildDynamicConfigExample.java @@ -0,0 +1,30 @@ +package github.scarsz.configuralize.test; + +import github.scarsz.configuralize.DynamicConfig; +import github.scarsz.configuralize.ParseException; +import github.scarsz.configuralize.mapping.Option; +import org.junit.Assert; + +import java.io.File; +import java.io.IOException; + +public class ChildDynamicConfigExample extends DynamicConfig { + + @Option(key = "config key") + public static String configValue; + + @Option(key = "messages key") + public static String messagesValue; + + public ChildDynamicConfigExample() throws IOException, ParseException { + addSource(ChildDynamicConfigExample.class, "config", new File("config.yml")); + addSource(ChildDynamicConfigExample.class, "messages", new File("messages.yml")); + saveAllDefaults(); + loadAll(); + map(); + + Assert.assertEquals("value from config", configValue); + Assert.assertEquals("value from messages", messagesValue); + } + +} From d734c90b533b686deb8fe633c33f41de1b07b28d Mon Sep 17 00:00:00 2001 From: Austin Shapiro Date: Tue, 28 Dec 2021 00:03:42 -0800 Subject: [PATCH 4/9] remove commons-io dependency --- pom.xml | 9 ++------- .../github/scarsz/configuralize/Provider.java | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index b9de1cc..e63865e 100644 --- a/pom.xml +++ b/pom.xml @@ -66,17 +66,12 @@ org.yaml snakeyaml - 1.25 - - - commons-io - commons-io - 2.6 + 1.29 junit junit - 4.13.1 + 4.13.2 test diff --git a/src/main/java/github/scarsz/configuralize/Provider.java b/src/main/java/github/scarsz/configuralize/Provider.java index 02ebd4a..b35b2eb 100644 --- a/src/main/java/github/scarsz/configuralize/Provider.java +++ b/src/main/java/github/scarsz/configuralize/Provider.java @@ -1,15 +1,17 @@ package github.scarsz.configuralize; import alexh.weak.Dynamic; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; import org.yaml.snakeyaml.parser.ParserException; +import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; -import java.nio.charset.StandardCharsets; +import java.io.InputStreamReader; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.util.Map; import java.util.Objects; +import java.util.stream.Collectors; @SuppressWarnings({"SameParameterValue", "WeakerAccess"}) public class Provider { @@ -48,12 +50,16 @@ public void load() throws IOException, ParseException { this.values = loadValues(); } public Dynamic loadValues() throws ParseException, IOException { - return load(config, source, FileUtils.readFileToString(source.getFile(), "UTF-8")); + return load(config, source, new String(Files.readAllBytes(source.getFile().toPath()))); } public Dynamic loadResource() throws ParseException, IOException { try (InputStream stream = source.getResource().openStream()) { Objects.requireNonNull(stream, "Unknown resource " + source.getResourcePath(config.getLanguage())); - return load(config, source, IOUtils.toString(stream, StandardCharsets.UTF_8)); + try (InputStreamReader reader = new InputStreamReader(stream)) { + try (BufferedReader buffer = new BufferedReader(reader)) { + return load(config, source, buffer.lines().collect(Collectors.joining("\n"))); + } + } } } @@ -69,7 +75,7 @@ public void saveDefaults(boolean overwrite) throws IOException { String resource = source.getResourcePath(config.getLanguage()); try (InputStream stream = source.getResource().openStream()) { Objects.requireNonNull(stream, "Unknown resource " + source.getResourcePath(config.getLanguage())); - FileUtils.copyInputStreamToFile(stream, source.getFile()); + Files.copy(stream, source.getFile().toPath(), StandardCopyOption.REPLACE_EXISTING); } } From 6625ba7d61b0bc87c679cc3e833bc9bd3f341a56 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Sep 2022 18:03:44 +0000 Subject: [PATCH 5/9] Bump snakeyaml from 1.29 to 1.31 Bumps [snakeyaml](https://bitbucket.org/snakeyaml/snakeyaml) from 1.29 to 1.31. - [Commits](https://bitbucket.org/snakeyaml/snakeyaml/branches/compare/snakeyaml-1.31..snakeyaml-1.29) --- updated-dependencies: - dependency-name: org.yaml:snakeyaml dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e63865e..a0dc043 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ org.yaml snakeyaml - 1.29 + 1.31 junit From 2871b6d9bcd88f6e35524df2484eb2aa3b62cbee Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 14 Dec 2022 20:53:51 +0000 Subject: [PATCH 6/9] Bump snakeyaml from 1.29 to 1.32 --- updated-dependencies: - dependency-name: org.yaml:snakeyaml dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e63865e..e592021 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ org.yaml snakeyaml - 1.29 + 1.32 junit From 583ff51c25df3fd49f2fd822e28591982490adfd Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Thu, 13 Mar 2025 23:05:03 -0400 Subject: [PATCH 7/9] Add support for building a slim jar without shaded dependencies --- pom.xml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e63865e..af8563a 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,26 @@ UTF-8 + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.0 + + + slim-jar + package + + jar + + + slim + Configuralize-${project.version} + + + + + org.apache.maven.plugins maven-shade-plugin @@ -76,4 +96,4 @@ - + \ No newline at end of file From 6660806dc61a7273424705202b985fe54d9b169b Mon Sep 17 00:00:00 2001 From: Austin Shapiro Date: Sat, 15 Mar 2025 22:10:46 -0700 Subject: [PATCH 8/9] v1.4.1 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a4b7a49..2b1536d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ github.scarsz configuralize - 1.4.0 + 1.4.1 UTF-8 @@ -96,4 +96,4 @@ - \ No newline at end of file + From c0952fe20a6a848b37359cbe2c0fd57d380c11fa Mon Sep 17 00:00:00 2001 From: Austin Shapiro Date: Sat, 15 Mar 2025 22:11:16 -0700 Subject: [PATCH 9/9] v1.4.1 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f5b588..b3c1918 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Supports .yml files via SnakeYAML and .json files via json-simple. github.scarsz configuralize - 1.4.0 + 1.4.1 ```