@@ -349,43 +349,42 @@ static def sanitizeDimensionName(str) {
349
349
}
350
350
351
351
static def modifyProductFlavorInContent (content , dimension , flavor ) {
352
- def indexStart = content. indexOf(" productFlavors" );
353
- def index = indexStart + " productFlavors" . length();
354
- def indexEnd = -1 ;
355
- def nestedOpenBracketsCount = 0 ;
356
-
357
- while (index < content. length())
358
- {
359
- // print content[index];
360
- if (content[index] == " }" )
361
- {
362
- nestedOpenBracketsCount-- ;
363
-
364
- if (nestedOpenBracketsCount == 0 )
365
- {
366
- indexEnd = index;
367
- break ;
352
+ def PRODUCT_FLAVORS = " productFlavors"
353
+ def indexStart = content. indexOf(PRODUCT_FLAVORS )
354
+ def index = indexStart + PRODUCT_FLAVORS . length()
355
+ def indexEnd = -1
356
+ def nestedOpenBracketsCount = 0
357
+
358
+ if (indexStart != -1 ) {
359
+ // get the index of the closing bracket of the productFlavors { } scope
360
+ while (index < content. length()) {
361
+ // print content[index];
362
+ if (content[index] == " }" ) {
363
+ nestedOpenBracketsCount--
364
+
365
+ if (nestedOpenBracketsCount == 0 ) {
366
+ indexEnd = index
367
+ break
368
+ }
369
+ } else if (content[index] == " {" ) {
370
+ nestedOpenBracketsCount++
368
371
}
369
- }
370
- else if (content[index] == " {" )
371
- {
372
- nestedOpenBracketsCount++ ;
373
- }
374
372
375
- index++ ;
373
+ index++
374
+ }
376
375
}
377
376
378
- if (indexEnd != -1 )
379
- {
377
+
378
+ if (indexEnd != -1 ) {
379
+ // replace the productFlavor dimension with a shorter one - F0, F1, F2, etc.
380
380
// full content of productFlavors { ... } -> the substring is parenthesis to parenthesis -> { ... }
381
- def oldProductFlavorsText = content. substring(indexStart, indexEnd + 1 );
381
+ def oldProductFlavorsText = content. substring(indexStart, indexEnd + 1 )
382
382
383
383
def newProductFlavorsContent = updateProductFlavorsContent(flavor, dimension, oldProductFlavorsText);
384
384
385
- return content. replace(oldProductFlavorsText, newProductFlavorsContent);
386
- }
387
- else
388
- {
385
+ return content. replace(oldProductFlavorsText, newProductFlavorsContent)
386
+ } else {
387
+ // create a productFlavor dimension - F0, F1, F2, etc.
389
388
def androidContentExists = content. indexOf(" android {" ) != -1 ;
390
389
def newProductFlavorsContent = createProductFlavorsContent(flavor, dimension, ! androidContentExists);
391
390
0 commit comments