Skip to content

Commit 730c5a5

Browse files
committed
Merge remote-tracking branch 'origin/master' into 449-map-property-type
2 parents 32887b4 + e9b52ef commit 730c5a5

25 files changed

+279
-86
lines changed

.github/workflows/mega-linter.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
steps:
4848
# Git Checkout
4949
- name: Checkout Code
50-
uses: actions/checkout@v4
50+
uses: actions/checkout@v5
5151
with:
5252
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
5353

@@ -60,7 +60,7 @@ jobs:
6060

6161
# You can override MegaLinter flavor used to have faster performances
6262
# More info at https://megalinter.io/latest/flavors/
63-
uses: oxsecurity/megalinter/flavors/java@v8
63+
uses: oxsecurity/megalinter/flavors/java@v9
6464

6565
id: ml
6666

@@ -110,7 +110,7 @@ jobs:
110110
# Create pull request if applicable
111111
# (for now works only on PR from same repository, not from forks)
112112
- name: Create Pull Request with applied fixes
113-
uses: peter-evans/create-pull-request@v6
113+
uses: peter-evans/create-pull-request@v7
114114
id: cpr
115115
if: >-
116116
steps.ml.outputs.has_updated_sources == 1 &&
@@ -166,7 +166,7 @@ jobs:
166166
run: sudo chown -Rc $UID .git/
167167

168168
- name: Commit and push applied linter fixes
169-
uses: stefanzweifel/git-auto-commit-action@v5
169+
uses: stefanzweifel/git-auto-commit-action@v6
170170
if: >-
171171
steps.ml.outputs.has_updated_sources == 1 &&
172172
(

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ of the AuthMe Discord server.
2020

2121
No sweat if some points aren't met since they can be addressed in pull requests, and PRs can be squashed.
2222

23+
### Glossary
24+
25+
Try to use and write terms consistently. Some spellings:
26+
27+
- ConfigMe
28+
- Javadoc (always capitalized)
29+
- _no-arg constructor_ (not "zero-arg(s)")
30+
2331
## Code style
2432

2533
Please try to match the current code style. A few pointers:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# ConfigMe
22
[![Build Status](https://github.com/AuthMe/ConfigMe/actions/workflows/maven_jdk8.yml/badge.svg)](https://github.com/AuthMe/ConfigMe/actions?query=branch%3Amaster)
33
[![Coverage Status](https://coveralls.io/repos/github/AuthMe/ConfigMe/badge.svg?branch=master)](https://coveralls.io/github/AuthMe/ConfigMe?branch=master)
4-
[![Javadocs](https://www.javadoc.io/badge/ch.jalu/configme.svg)](https://www.javadoc.io/doc/ch.jalu/configme)
5-
[![MegaLinter](https://github.com/AuthMe/ConfigMe/workflows/MegaLinter/badge.svg?branch=master)](https://github.com/AuthMe/ConfigMe/actions?query=workflow%3AMegaLinter+branch%3Amaster)
4+
[![Javadoc](https://www.javadoc.io/badge/ch.jalu/configme.svg)](https://www.javadoc.io/doc/ch.jalu/configme)
5+
[![MegaLinter](https://github.com/AuthMe/ConfigMe/actions/workflows/mega-linter.yml/badge.svg?branch=master)](https://github.com/AuthMe/ConfigMe/actions?query=workflow%3AMegaLinter+branch%3Amaster)
66

77
A simple configuration management library with YAML support out of the box.
88

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4141
<project.jdkVersion>1.8</project.jdkVersion>
4242

43-
<version.junit>5.13.1</version.junit>
43+
<version.junit>5.13.4</version.junit>
4444
<version.mockito>4.11.0</version.mockito>
4545
</properties>
4646

@@ -95,7 +95,7 @@
9595
<plugin>
9696
<groupId>org.apache.maven.plugins</groupId>
9797
<artifactId>maven-javadoc-plugin</artifactId>
98-
<version>3.11.2</version>
98+
<version>3.12.0</version>
9999
<executions>
100100
<execution>
101101
<id>attach-javadocs</id>
@@ -109,7 +109,7 @@
109109
<plugin>
110110
<groupId>org.apache.maven.plugins</groupId>
111111
<artifactId>maven-gpg-plugin</artifactId>
112-
<version>3.2.7</version>
112+
<version>3.2.8</version>
113113
<executions>
114114
<execution>
115115
<id>sign-artifacts</id>
@@ -146,7 +146,7 @@
146146
<plugin>
147147
<groupId>org.apache.maven.plugins</groupId>
148148
<artifactId>maven-compiler-plugin</artifactId>
149-
<version>3.14.0</version>
149+
<version>3.14.1</version>
150150
<configuration>
151151
<source>${project.jdkVersion}</source>
152152
<target>${project.jdkVersion}</target>
@@ -157,7 +157,7 @@
157157
<plugin>
158158
<groupId>org.apache.maven.plugins</groupId>
159159
<artifactId>maven-surefire-plugin</artifactId>
160-
<version>3.5.3</version>
160+
<version>3.5.4</version>
161161
<configuration>
162162
<!-- Force the right file encoding during unit testing -->
163163
<argLine>-Dfile.encoding=${project.build.sourceEncoding} @{argLine}</argLine>
@@ -186,7 +186,7 @@
186186
<dependency>
187187
<groupId>org.yaml</groupId>
188188
<artifactId>snakeyaml</artifactId>
189-
<version>2.4</version>
189+
<version>2.5</version>
190190
</dependency>
191191

192192
<!-- TypeInfo and other utils -->

src/main/java/ch/jalu/configme/SettingsManagerBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private SettingsManagerBuilder(@NotNull PropertyResource resource) {
9191
*/
9292
@SafeVarargs
9393
public final @NotNull SettingsManagerBuilder configurationData(
94-
@NotNull Class<? extends SettingsHolder>... classes) {
94+
@NotNull Class<? extends SettingsHolder> @NotNull ... classes) {
9595
this.configurationData = ConfigurationDataBuilder.createConfiguration(classes);
9696
return this;
9797
}

src/main/java/ch/jalu/configme/beanmapper/Mapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.jetbrains.annotations.Nullable;
77

88
/**
9-
* Maps the values of a property reader to Java classes (referred to as beans). See the JavaDoc on the default
9+
* Maps the values of a property reader to Java classes (referred to as beans). See the Javadoc on the default
1010
* implementation, {@link MapperImpl}, for more details.
1111
*/
1212
public interface Mapper {

src/main/java/ch/jalu/configme/beanmapper/MapperImpl.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@
6666
*/
6767
public class MapperImpl implements Mapper {
6868

69-
/** Marker object to signal that null is meant to be used as value. */
70-
public static final Object RETURN_NULL = new Object();
71-
7269
// ---------
7370
// Fields and general configurable methods
7471
// ---------
@@ -125,13 +122,13 @@ public MapperImpl(@NotNull BeanDefinitionService beanDefinitionService,
125122
// Step 1: attempt simple value transformation
126123
Object exportValue = leafValueHandler.toExportValue(value, exportContext);
127124
if (exportValue != null || value == null) {
128-
return unwrapReturnNull(exportValue);
125+
return LeafValueHandler.unwrapReturnNull(exportValue);
129126
}
130127

131128
// Step 2: handle special cases like Collection
132129
exportValue = createExportValueForSpecialTypes(value, exportContext);
133130
if (exportValue != null) {
134-
return unwrapReturnNull(exportValue);
131+
return LeafValueHandler.unwrapReturnNull(exportValue);
135132
}
136133

137134
// Step 3: treat as bean
@@ -159,12 +156,12 @@ public MapperImpl(@NotNull BeanDefinitionService beanDefinitionService,
159156

160157
/**
161158
* Handles values of types which need special handling (such as Optional). Null means the value is not
162-
* a special type and that the export value should be built differently. Use {@link #RETURN_NULL} to
159+
* a special type and that the export value should be built differently. Use {@link LeafValueHandler#RETURN_NULL} to
163160
* signal that null should be used as the export value of the provided value.
164161
*
165162
* @param value the value to convert
166163
* @param exportContext export context
167-
* @return the export value to use or {@link #RETURN_NULL}, or null if not applicable
164+
* @return the export value to use or {@link LeafValueHandler#RETURN_NULL}, or null if not applicable
168165
*/
169166
protected @Nullable Object createExportValueForSpecialTypes(@Nullable Object value,
170167
@NotNull ExportContext exportContext) {
@@ -192,16 +189,12 @@ public MapperImpl(@NotNull BeanDefinitionService beanDefinitionService,
192189
Optional<?> optional = (Optional<?>) value;
193190
return optional
194191
.map(v -> toExportValue(v, exportContext.createChildContext(OPTIONAL_SPECIFIER)))
195-
.orElse(RETURN_NULL);
192+
.orElse(LeafValueHandler.RETURN_NULL);
196193
}
197194

198195
return null;
199196
}
200197

201-
protected static @Nullable Object unwrapReturnNull(@Nullable Object o) {
202-
return o == RETURN_NULL ? null : o;
203-
}
204-
205198
// ---------
206199
// Bean mapping
207200
// ---------

src/main/java/ch/jalu/configme/beanmapper/leafvaluehandler/LeafValueHandler.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
*/
2121
public interface LeafValueHandler {
2222

23+
/** Marker object to signal that null is meant to be used as value. */
24+
Object RETURN_NULL = new Object();
25+
2326
/**
2427
* Converts the given value to the target type (as defined by the mapping context), if supported. Otherwise,
2528
* null is returned. If a value is returned, its type is guaranteed to match the target type.
@@ -33,11 +36,25 @@ public interface LeafValueHandler {
3336
/**
3437
* Converts the value of a property to a value suitable for exporting. This method converts the opposite
3538
* way of {@link #convert}. Null is returned if this leaf value handler does not support the object's type.
39+
* If the leaf value handler determines that {@code null} should be used as export value, then {@link #RETURN_NULL}
40+
* is returned, which the caller needs to unwrap to {@code null}.
3641
*
3742
* @param value the value to convert
3843
* @param exportContext the export context (usually not needed)
3944
* @return the value suitable for exporting, or null if not applicable
4045
*/
4146
@Nullable Object toExportValue(@Nullable Object value, @NotNull ExportContext exportContext);
4247

48+
/**
49+
* Returns null if the object is {@link #RETURN_NULL}, otherwise the given object. Used to process return values
50+
* from methods like {@link #toExportValue}, where {@code null} means the instance doesn't support the value,
51+
* while {@link #RETURN_NULL} means null should be used as export value.
52+
*
53+
* @param object the object to potentially unwrap
54+
* @param <T> the object type
55+
* @return null, or the provided object
56+
*/
57+
static <T> @Nullable T unwrapReturnNull(@Nullable T object) {
58+
return object == RETURN_NULL ? null : object;
59+
}
4360
}

src/main/java/ch/jalu/configme/beanmapper/leafvaluehandler/LeafValueHandlerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public static final class Builder {
144144
* @param typesToAdd the leaf types to add
145145
* @return this builder
146146
*/
147-
public @NotNull Builder addTypes(@NotNull MapperLeafType... typesToAdd) {
147+
public @NotNull Builder addTypes(@NotNull MapperLeafType @NotNull ... typesToAdd) {
148148
leafTypes.addAll(Arrays.asList(typesToAdd));
149149
return this;
150150
}

src/main/java/ch/jalu/configme/beanmapper/leafvaluehandler/MapperLeafType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public interface MapperLeafType {
3030
* when {@link ch.jalu.configme.beanmapper.MapperImpl#toExportValue(Object)} is called.
3131
* Returns null if the leaf value handler cannot handle the value.
3232
* <p>
33-
* Return {@link ch.jalu.configme.beanmapper.MapperImpl#RETURN_NULL} to signal that null should be used
33+
* Return {@link LeafValueHandler#RETURN_NULL} to signal that null should be used
3434
* as the export value (returning {@code null} itself means this leaf value handler cannot handle it).
3535
*
3636
* @param value the value to convert to an export value, if possible

0 commit comments

Comments
 (0)