11package datadog.gradle.plugin.config
22
33import org.gradle.api.DefaultTask
4- import org.gradle.kotlin.dsl.property
54import org.gradle.api.model.ObjectFactory
65import org.gradle.api.tasks.Input
76import org.gradle.api.tasks.InputFile
@@ -12,6 +11,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
1211import org.gradle.api.tasks.CacheableTask
1312import org.gradle.api.tasks.PathSensitive
1413import org.gradle.api.tasks.PathSensitivity
14+ import org.gradle.kotlin.dsl.property
1515import java.io.File
1616import java.io.FileInputStream
1717import java.io.PrintWriter
@@ -131,11 +131,29 @@ abstract class ParseV2SupportedConfigurationsTask @Inject constructor(
131131 out .println (" public static final Map<String, String> REVERSE_PROPERTY_KEYS_MAP;" )
132132 out .println ()
133133 out .println (" static {" )
134+ out .println (" SUPPORTED = initSupported();" )
135+ out .println (" ALIASES = initAliases();" )
136+ out .println (" ALIAS_MAPPING = initAliasMapping();" )
137+ out .println (" DEPRECATED = initDeprecated();" )
138+ out .println (" REVERSE_PROPERTY_KEYS_MAP = initReversePropertyKeysMap();" )
139+ out .println (" }" )
134140 out .println ()
135141
136- // SUPPORTED
142+ // initSupported() - split into two helper functions to avoid "code too large" error
143+ out .println (" private static Map<String, List<SupportedConfiguration>> initSupported() {" )
137144 out .println (" Map<String, List<SupportedConfiguration>> supportedMap = new HashMap<>();" )
138- for ((key, configList) in supported.toSortedMap()) {
145+ out .println (" initSupported1(supportedMap);" )
146+ out .println (" initSupported2(supportedMap);" )
147+ out .println (" return Collections.unmodifiableMap(supportedMap);" )
148+ out .println (" }" )
149+ out .println ()
150+
151+ val sortedSupported = supported.toSortedMap().entries.toList()
152+ val midpoint = sortedSupported.size / 2
153+
154+ // initSupported1() - first half
155+ out .println (" private static void initSupported1(Map<String, List<SupportedConfiguration>> supportedMap) {" )
156+ for ((key, configList) in sortedSupported.take(midpoint)) {
139157 out .print (" supportedMap.put(\" ${esc(key)} \" , Collections.unmodifiableList(Arrays.asList(" )
140158 val configIter = configList.iterator()
141159 while (configIter.hasNext()) {
@@ -151,11 +169,33 @@ abstract class ParseV2SupportedConfigurationsTask @Inject constructor(
151169 }
152170 out .println (" )));" )
153171 }
154- out .println (" SUPPORTED = Collections.unmodifiableMap(supportedMap); " )
172+ out .println (" } " )
155173 out .println ()
156174
157- // ALIASES
158- out .println (" // Note: This top-level alias mapping will be deprecated once Config Registry is mature enough to understand which version of a config a customer is using" )
175+ // initSupported2() - second half
176+ out .println (" private static void initSupported2(Map<String, List<SupportedConfiguration>> supportedMap) {" )
177+ for ((key, configList) in sortedSupported.drop(midpoint)) {
178+ out .print (" supportedMap.put(\" ${esc(key)} \" , Collections.unmodifiableList(Arrays.asList(" )
179+ val configIter = configList.iterator()
180+ while (configIter.hasNext()) {
181+ val config = configIter.next()
182+ out .print (" new SupportedConfiguration(" )
183+ out .print (" ${escNullableString(config.version)} , " )
184+ out .print (" ${escNullableString(config.type)} , " )
185+ out .print (" ${escNullableString(config.default)} , " )
186+ out .print (" Arrays.asList(${quoteList(config.aliases)} ), " )
187+ out .print (" Arrays.asList(${quoteList(config.propertyKeys)} )" )
188+ out .print (" )" )
189+ if (configIter.hasNext()) out .print (" , " )
190+ }
191+ out .println (" )));" )
192+ }
193+ out .println (" }" )
194+ out .println ()
195+
196+ // initAliases()
197+ out .println (" // Note: This top-level alias mapping will be deprecated once Config Registry is mature enough to understand which version of a config a customer is using" )
198+ out .println (" private static Map<String, List<String>> initAliases() {" )
159199 out .println (" Map<String, List<String>> aliasesMap = new HashMap<>();" )
160200 for ((canonical, list) in aliases.toSortedMap()) {
161201 out .printf(
@@ -164,33 +204,37 @@ abstract class ParseV2SupportedConfigurationsTask @Inject constructor(
164204 quoteList(list)
165205 )
166206 }
167- out .println (" ALIASES = Collections.unmodifiableMap(aliasesMap);" )
207+ out .println (" return Collections.unmodifiableMap(aliasesMap);" )
208+ out .println (" }" )
168209 out .println ()
169210
170- // ALIAS_MAPPING
211+ // initAliasMapping()
212+ out .println (" private static Map<String, String> initAliasMapping() {" )
171213 out .println (" Map<String, String> aliasMappingMap = new HashMap<>();" )
172214 for ((alias, target) in aliasMapping.toSortedMap()) {
173215 out .printf(" aliasMappingMap.put(\" %s\" , \" %s\" );\n " , esc(alias), esc(target))
174216 }
175- out .println (" ALIAS_MAPPING = Collections.unmodifiableMap(aliasMappingMap);" )
217+ out .println (" return Collections.unmodifiableMap(aliasMappingMap);" )
218+ out .println (" }" )
176219 out .println ()
177220
178- // DEPRECATED
221+ // initDeprecated()
222+ out .println (" private static Map<String, String> initDeprecated() {" )
179223 out .println (" Map<String, String> deprecatedMap = new HashMap<>();" )
180224 for ((oldKey, note) in deprecated.toSortedMap()) {
181225 out .printf(" deprecatedMap.put(\" %s\" , \" %s\" );\n " , esc(oldKey), esc(note))
182226 }
183- out .println (" DEPRECATED = Collections.unmodifiableMap(deprecatedMap);" )
227+ out .println (" return Collections.unmodifiableMap(deprecatedMap);" )
228+ out .println (" }" )
184229 out .println ()
185230
186- // REVERSE_PROPERTY_KEYS_MAP
231+ // initReversePropertyKeysMap()
232+ out .println (" private static Map<String, String> initReversePropertyKeysMap() {" )
187233 out .println (" Map<String, String> reversePropertyKeysMapping = new HashMap<>();" )
188234 for ((propertyKey, config) in reversePropertyKeysMap.toSortedMap()) {
189235 out .printf(" reversePropertyKeysMapping.put(\" %s\" , \" %s\" );\n " , esc(propertyKey), esc(config))
190236 }
191- out .println (" REVERSE_PROPERTY_KEYS_MAP = Collections.unmodifiableMap(reversePropertyKeysMapping);" )
192- out .println ()
193-
237+ out .println (" return Collections.unmodifiableMap(reversePropertyKeysMapping);" )
194238 out .println (" }" )
195239 out .println (" }" )
196240 }
0 commit comments