@@ -130,11 +130,29 @@ abstract class ParseV2SupportedConfigurationsTask @Inject constructor(
130130 out .println (" public static final Map<String, String> REVERSE_PROPERTY_KEYS_MAP;" )
131131 out .println ()
132132 out .println (" static {" )
133+ out .println (" SUPPORTED = initSupported();" )
134+ out .println (" ALIASES = initAliases();" )
135+ out .println (" ALIAS_MAPPING = initAliasMapping();" )
136+ out .println (" DEPRECATED = initDeprecated();" )
137+ out .println (" REVERSE_PROPERTY_KEYS_MAP = initReversePropertyKeysMap();" )
138+ out .println (" }" )
133139 out .println ()
134140
135- // SUPPORTED
141+ // initSupported() - split into two helper functions to avoid "code too large" error
142+ out .println (" private static Map<String, List<SupportedConfiguration>> initSupported() {" )
136143 out .println (" Map<String, List<SupportedConfiguration>> supportedMap = new HashMap<>();" )
137- for ((key, configList) in supported.toSortedMap()) {
144+ out .println (" initSupported1(supportedMap);" )
145+ out .println (" initSupported2(supportedMap);" )
146+ out .println (" return Collections.unmodifiableMap(supportedMap);" )
147+ out .println (" }" )
148+ out .println ()
149+
150+ val sortedSupported = supported.toSortedMap().entries.toList()
151+ val midpoint = sortedSupported.size / 2
152+
153+ // initSupported1() - first half
154+ out .println (" private static void initSupported1(Map<String, List<SupportedConfiguration>> supportedMap) {" )
155+ for ((key, configList) in sortedSupported.take(midpoint)) {
138156 out .print (" supportedMap.put(\" ${esc(key)} \" , Collections.unmodifiableList(Arrays.asList(" )
139157 val configIter = configList.iterator()
140158 while (configIter.hasNext()) {
@@ -148,13 +166,35 @@ abstract class ParseV2SupportedConfigurationsTask @Inject constructor(
148166 out .print (" )" )
149167 if (configIter.hasNext()) out .print (" , " )
150168 }
151- out .println (" )));\n " )
169+ out .println (" )));" )
152170 }
153- out .println (" SUPPORTED = Collections.unmodifiableMap(supportedMap); " )
171+ out .println (" } " )
154172 out .println ()
155173
156- // ALIASES
157- 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" )
174+ // initSupported2() - second half
175+ out .println (" private static void initSupported2(Map<String, List<SupportedConfiguration>> supportedMap) {" )
176+ for ((key, configList) in sortedSupported.drop(midpoint)) {
177+ out .print (" supportedMap.put(\" ${esc(key)} \" , Collections.unmodifiableList(Arrays.asList(" )
178+ val configIter = configList.iterator()
179+ while (configIter.hasNext()) {
180+ val config = configIter.next()
181+ out .print (" new SupportedConfiguration(" )
182+ out .print (" ${escNullableString(config.version)} , " )
183+ out .print (" ${escNullableString(config.type)} , " )
184+ out .print (" ${escNullableString(config.default)} , " )
185+ out .print (" Arrays.asList(${quoteList(config.aliases)} ), " )
186+ out .print (" Arrays.asList(${quoteList(config.propertyKeys)} )" )
187+ out .print (" )" )
188+ if (configIter.hasNext()) out .print (" , " )
189+ }
190+ out .println (" )));" )
191+ }
192+ out .println (" }" )
193+ out .println ()
194+
195+ // initAliases()
196+ 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" )
197+ out .println (" private static Map<String, List<String>> initAliases() {" )
158198 out .println (" Map<String, List<String>> aliasesMap = new HashMap<>();" )
159199 for ((canonical, list) in aliases.toSortedMap()) {
160200 out .printf(
@@ -163,34 +203,39 @@ abstract class ParseV2SupportedConfigurationsTask @Inject constructor(
163203 quoteList(list)
164204 )
165205 }
166- out .println (" ALIASES = Collections.unmodifiableMap(aliasesMap);" )
206+ out .println (" return Collections.unmodifiableMap(aliasesMap);" )
207+ out .println (" }" )
167208 out .println ()
168209
169- // ALIAS_MAPPING
210+ // initAliasMapping()
211+ out .println (" private static Map<String, String> initAliasMapping() {" )
170212 out .println (" Map<String, String> aliasMappingMap = new HashMap<>();" )
171213 for ((alias, target) in aliasMapping.toSortedMap()) {
172214 out .printf(" aliasMappingMap.put(\" %s\" , \" %s\" );\n " , esc(alias), esc(target))
173215 }
174- out .println (" ALIAS_MAPPING = Collections.unmodifiableMap(aliasMappingMap);" )
216+ out .println (" return Collections.unmodifiableMap(aliasMappingMap);" )
217+ out .println (" }" )
175218 out .println ()
176219
177- // DEPRECATED
220+ // initDeprecated()
221+ out .println (" private static Map<String, String> initDeprecated() {" )
178222 out .println (" Map<String, String> deprecatedMap = new HashMap<>();" )
179223 for ((oldKey, note) in deprecated.toSortedMap()) {
180224 out .printf(" deprecatedMap.put(\" %s\" , \" %s\" );\n " , esc(oldKey), esc(note))
181225 }
182- out .println (" DEPRECATED = Collections.unmodifiableMap(deprecatedMap);" )
226+ out .println (" return Collections.unmodifiableMap(deprecatedMap);" )
227+ out .println (" }" )
183228 out .println ()
184229
185- // REVERSE_PROPERTY_KEYS_MAP
230+ // initReversePropertyKeysMap()
231+ out .println (" private static Map<String, String> initReversePropertyKeysMap() {" )
186232 out .println (" Map<String, String> reversePropertyKeysMapping = new HashMap<>();" )
187233 for ((propertyKey, config) in reversePropertyKeysMap.toSortedMap()) {
188234 out .printf(" reversePropertyKeysMapping.put(\" %s\" , \" %s\" );\n " , esc(propertyKey), esc(config))
189235 }
190- out .println (" REVERSE_PROPERTY_KEYS_MAP = Collections.unmodifiableMap(reversePropertyKeysMapping);" )
191- out .println ()
192-
236+ out .println (" return Collections.unmodifiableMap(reversePropertyKeysMapping);" )
193237 out .println (" }" )
238+
194239 out .println (" }" )
195240 }
196241 }
0 commit comments