diff options
author | Kristóf Marussy <kristof@marussy.com> | 2023-04-09 02:54:51 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2023-04-09 19:07:32 +0200 |
commit | d904e2150319439053d89c723733463c4810bde9 (patch) | |
tree | 974068147ce55eda08a27f8fa08e833f4f7d701e /buildSrc/src/main/java/tools/refinery/gradle/utils/SonarPropertiesUtils.java | |
parent | build: avoid repeating task names in build scripts (diff) | |
download | refinery-d904e2150319439053d89c723733463c4810bde9.tar.gz refinery-d904e2150319439053d89c723733463c4810bde9.tar.zst refinery-d904e2150319439053d89c723733463c4810bde9.zip |
build: organize build scripts into packages
Also take advantage of precompiled Kotlin scripts to write build scripts in a
more straightforward manner through generated accessors.
Might increase memory usage of Gradle.
Diffstat (limited to 'buildSrc/src/main/java/tools/refinery/gradle/utils/SonarPropertiesUtils.java')
-rw-r--r-- | buildSrc/src/main/java/tools/refinery/gradle/utils/SonarPropertiesUtils.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/buildSrc/src/main/java/tools/refinery/gradle/utils/SonarPropertiesUtils.java b/buildSrc/src/main/java/tools/refinery/gradle/utils/SonarPropertiesUtils.java new file mode 100644 index 00000000..3810fccf --- /dev/null +++ b/buildSrc/src/main/java/tools/refinery/gradle/utils/SonarPropertiesUtils.java | |||
@@ -0,0 +1,44 @@ | |||
1 | package tools.refinery.gradle.utils; | ||
2 | |||
3 | import java.util.ArrayList; | ||
4 | import java.util.Collections; | ||
5 | import java.util.Map; | ||
6 | |||
7 | public final class SonarPropertiesUtils { | ||
8 | private SonarPropertiesUtils() { | ||
9 | throw new IllegalStateException("This is a static utility class and should not be instantiated directly"); | ||
10 | } | ||
11 | |||
12 | /** | ||
13 | * Adds the entries to a Sonar property of list type. | ||
14 | * <p> | ||
15 | * According to the Sonar Gradle documentation for {@link org.sonarqube.gradle.SonarProperties}, property values | ||
16 | * are converted to Strings as follows: | ||
17 | * <ul> | ||
18 | * <li>{@code Iterable}s are recursively converted and joined into a comma-separated String.</li> | ||
19 | * <li>All other values are converted to Strings by calling their {@code toString()} method.</li> | ||
20 | * </ul> | ||
21 | * Therefore, we use {@link ArrayList} to retain lists entries, which will be recursively converted later. | ||
22 | * | ||
23 | * @param properties The sonar properties map returned by | ||
24 | * {@link org.sonarqube.gradle.SonarProperties#getProperties()}. | ||
25 | * @param propertyName The name of the property to append to. | ||
26 | * @param entries The entries to append. | ||
27 | */ | ||
28 | public static void addToList(Map<String, Object> properties, String propertyName, String... entries) { | ||
29 | ArrayList<Object> newValue; | ||
30 | var currentValue = properties.get(propertyName); | ||
31 | if (currentValue instanceof ArrayList<?> currentList) { | ||
32 | @SuppressWarnings("unchecked") | ||
33 | var objectList = (ArrayList<Object>) currentList; | ||
34 | newValue = objectList; | ||
35 | } else if (currentValue == null) { | ||
36 | newValue = new ArrayList<>(entries.length); | ||
37 | } else { | ||
38 | newValue = new ArrayList<>(entries.length + 1); | ||
39 | newValue.add(currentValue); | ||
40 | } | ||
41 | Collections.addAll(newValue, entries); | ||
42 | properties.put(propertyName, newValue); | ||
43 | } | ||
44 | } | ||