1
1
package org.nut.dynamatrix ;
2
2
3
+ import com.cloudbees.groovy.cps.NonCPS ;
3
4
import org.nut.dynamatrix.Utils ;
4
5
import org.nut.dynamatrix.dynamatrixGlobalState ;
5
6
6
7
/**
7
- * This class intends to represent one build request configuration
8
+ * This class intends to represent one build request configuration.
8
9
* An instance of it can be passed as the set of arguments for the
9
10
* customized run Dynamatrix routines, while some defaults can be
10
11
* applied so needed fields are all "defined" when we look at them.
@@ -46,8 +47,10 @@ class DynamatrixConfig implements Cloneable {
46
47
/* * Each of these labels can be String, GString or Pattern object
47
48
* to match labels (named as key=value pairs) of build agents:
48
49
* <pre>dynamatrixAxesLabels: ['OS', '${COMPILER}VER', 'ARCH'],</pre>
50
+ * Normally this object is a Set, but may be initialized as
51
+ * a String, List, etc. so a getter is provided.
49
52
*/
50
- public Set dynamatrixAxesLabels = []
53
+ public def dynamatrixAxesLabels = []
51
54
52
55
// TODO: Need a way to specify that we only want some extreme value
53
56
// but not the whole range, somehow specifiable per-system (e.g. to
@@ -260,9 +263,9 @@ class DynamatrixConfig implements Cloneable {
260
263
*
261
264
* @see #excludedNodelabels
262
265
*/
263
- public Set requiredNodelabels = []
266
+ public Set< String > requiredNodelabels = []
264
267
/* * @see #requiredNodelabels */
265
- public Set excludedNodelabels = []
268
+ public Set< String > excludedNodelabels = []
266
269
267
270
/**
268
271
* Same values as for {@code timeout() } step, e.g.
@@ -371,8 +374,16 @@ def parallelStages = prepareDynamatrix(
371
374
return (DynamatrixConfig ) super . clone();
372
375
}
373
376
377
+ /**
378
+ * Prepares the class instance settings for one of pre-defined
379
+ * default configurations:
380
+ * ['C', 'C-all', 'CXX', 'CXX-all', 'C+CXX', 'C+CXX-all']
381
+ *<br />
382
+ * Returns a boolean status (true if OK), or a string with error details.
383
+ * @see #initDefault(Map)
384
+ */
374
385
public def initDefault (String defaultCfg ) {
375
- def debugTrace = this . shouldDebugTrace()
386
+ boolean debugTrace = this . shouldDebugTrace()
376
387
377
388
if (debugTrace) this . script. println (" [DEBUG] DynamatrixConfig(String): called with defaultCfg = ${ Utils.castString(defaultCfg)} " )
378
389
@@ -567,9 +578,13 @@ def parallelStages = prepareDynamatrix(
567
578
this . initDefault(dynacfgOrig)
568
579
}
569
580
581
+ /**
582
+ * Returns a boolean status (true if OK), or a string with error details
583
+ * @see #initDefault(String)
584
+ */
570
585
public def initDefault (Map dynacfgOrig ) {
571
- def debugErrors = this . shouldDebugErrors()
572
- def debugTrace = this . shouldDebugTrace()
586
+ boolean debugErrors = this . shouldDebugErrors()
587
+ boolean debugTrace = this . shouldDebugTrace()
573
588
574
589
if (debugTrace) this . script. println (" [DEBUG] DynamatrixConfig(Map): called with dynacfgOrig = ${ Utils.castString(dynacfgOrig)} " )
575
590
@@ -579,13 +594,13 @@ def parallelStages = prepareDynamatrix(
579
594
// Combine a config with defaults from a Set passed to a groovy call()
580
595
if (dynacfgOrig. size() > 0 ) {
581
596
// Be sure to only mutilate a copy below, not the original object
582
- dynacfgOrig = dynacfgOrig. clone()
597
+ dynacfgOrig = ( Map )( dynacfgOrig. clone() )
583
598
584
599
// Note: in addition to standard contents of class DynamatrixConfig,
585
600
// the Map passed by caller may contain "defaultDynamatrixConfig" as
586
601
// a key for a String value to specify default pre-sets, e.g. "C".
587
602
if (dynacfgOrig. containsKey(' defaultDynamatrixConfig' )) {
588
- def str = dynacfgOrig[' defaultDynamatrixConfig' ]. toString()
603
+ String str = dynacfgOrig[' defaultDynamatrixConfig' ]. toString()
589
604
if (debugTrace) this . script. println (" [DEBUG] DynamatrixConfig(Map): calling initDefault(${ str} ) first" )
590
605
this . initDefault(str)
591
606
dynacfgOrig. remove(' defaultDynamatrixConfig' )
@@ -598,7 +613,13 @@ def parallelStages = prepareDynamatrix(
598
613
599
614
if (dynacfgOrig. containsKey(' dsbcStageTimeoutSettings' )) {
600
615
// Should be a Map or null; raise an error otherwise
601
- this . dsbcStageTimeoutSettings = dynacfgOrig. dsbcStageTimeoutSettings
616
+ if (dynacfgOrig. dsbcStageTimeoutSettings == null
617
+ || Utils . isMap(dynacfgOrig. dsbcStageTimeoutSettings)
618
+ ) {
619
+ this . dsbcStageTimeoutSettings = (Map )(dynacfgOrig. dsbcStageTimeoutSettings)
620
+ } else {
621
+ throw new InvalidClassException (" dsbcStageTimeoutSettings is not a Map" )
622
+ }
602
623
dynacfgOrig. remove(' dsbcStageTimeoutSettings' )
603
624
}
604
625
@@ -611,36 +632,36 @@ def parallelStages = prepareDynamatrix(
611
632
612
633
if (k. equals(" mergeMode" )) return // continue
613
634
try {
614
- def mergeMode = " replace"
635
+ String mergeMode = " replace"
615
636
try {
616
637
// Expected optional value "replace" or "merge"
617
- mergeMode = dynacfgOrig. mergeMode[k]. trim()
618
- dynacfgOrig. mergeMode. remove(k)
619
- } catch (Throwable t ) {} // keep default setting if no action requested
638
+ mergeMode = ((( Map )( dynacfgOrig[ ' mergeMode' ])) [k]) . toString() . trim()
639
+ ( Map )( dynacfgOrig[ ' mergeMode' ]) . remove(k)
640
+ } catch (Throwable ignored ) {} // keep default setting if no action requested
620
641
621
642
if (debugTrace) this . script. println (" [DEBUG] DynamatrixConfig(Map): mergeMode for k='${ k} ' is '${ mergeMode} '" )
622
643
switch (" ${ mergeMode} " ) {
623
644
case " merge" :
624
- if (debugTrace) this . script. println (" [DEBUG] DynamatrixConfig(Map): merging: ${ this[k]} \n with: ${ dynacfgOrig[k]} " )
625
- this [k] = Utils . mergeMapSet(this [k], dynacfgOrig[k])
626
- if (debugTrace) this . script. println (" [DEBUG] DynamatrixConfig(Map): result of merge: ${ this[k]} " )
645
+ if (debugTrace) this . script. println (" [DEBUG] DynamatrixConfig(Map): merging: ${ this[k.toString() ]} \n with: ${ dynacfgOrig[k]} " )
646
+ this [k. toString() ] = Utils . mergeMapSet(this [k. toString() ], dynacfgOrig[k])
647
+ if (debugTrace) this . script. println (" [DEBUG] DynamatrixConfig(Map): result of merge: ${ this[k.toString() ]} " )
627
648
break
628
649
629
650
case " replace" :
630
651
if (debugTrace) this . script. println (" [DEBUG] DynamatrixConfig(Map): replacing with: ${ dynacfgOrig[k]} " )
631
- this [k] = dynacfgOrig[k]
652
+ this [k. toString() ] = dynacfgOrig[k]
632
653
// if (debugTrace) this.script.println("[DEBUG] DynamatrixConfig(Map): result of replacement: ${this[k]}")
633
654
break
634
655
635
656
default :
636
657
if (debugTrace) this . script. println (" [DEBUG] DynamatrixConfig(Map): defaulting to replace with: ${ dynacfgOrig[k]} " )
637
- this [k] = dynacfgOrig[k]
658
+ this [k. toString() ] = dynacfgOrig[k]
638
659
// if (debugTrace) this.script.println("[DEBUG] DynamatrixConfig(Map): result of replacement: ${this[k]}")
639
660
break
640
661
}
641
662
} catch (Exception e) {
642
663
if (! errs. equals(" " )) errs + = " \n "
643
- def str = " [DEBUG] DynamatrixConfig(Map): ignoring unsupported config key from request: '${ k} ' => " + dynacfgOrig[k] + " : " + e. toString()
664
+ String str = " [DEBUG] DynamatrixConfig(Map): ignoring unsupported config key from request: '${ k} ' => " + dynacfgOrig[k] + " : " + e. toString()
644
665
errs + = str
645
666
if (debugTrace) this . script. println str
646
667
}
@@ -673,37 +694,47 @@ def parallelStages = prepareDynamatrix(
673
694
return this
674
695
}
675
696
676
- /*
697
+ public Set getDynamatrixAxesLabels () {
698
+ if (this . @dynamatrixAxesLabels != null
699
+ && ! Utils . isList(this . @dynamatrixAxesLabels)
700
+ ) {
701
+ this . sanitycheckDynamatrixAxesLabels()
702
+ }
703
+
704
+ return (Set )(this . @dynamatrixAxesLabels)
705
+ }
706
+
707
+ /**
677
708
* Our callers expect a few specific data constructs here:
678
709
* either a single string or pattern (that will be remade into
679
710
* a single-element array), or an array/list/set/... of such types
680
711
*/
681
712
public def sanitycheckDynamatrixAxesLabels () {
682
713
String errs = " "
683
- if (this . dynamatrixAxesLabels != null ) {
684
- if (Utils . isList(this . dynamatrixAxesLabels)) {
714
+ if (this . @ dynamatrixAxesLabels != null ) {
715
+ if (Utils . isList(this . @ dynamatrixAxesLabels)) {
685
716
// TODO: Match superclass to not list all children of Set etc?
686
717
// TODO: Check entries if this object that they are strings/patterns
687
- if (this . dynamatrixAxesLabels. size() > 0 )
718
+ if (this . @ dynamatrixAxesLabels. size() > 0 )
688
719
return true
689
720
// Else no automagic... but maybe got strict requirements?
690
721
if (this . dynamatrixRequiredLabelCombos. size() > 0 )
691
722
return true
692
723
errs + = " Initially requested dynamatrixAxesLabels and dynamatrixRequiredLabelCombos are both empty"
693
- } else if (Utils . isString(this . dynamatrixAxesLabels)) {
694
- if (this . dynamatrixAxesLabels. equals( " " )) {
695
- this . dynamatrixAxesLabels = null
724
+ } else if (Utils . isString(this . @ dynamatrixAxesLabels)) {
725
+ if (" " == this . @ dynamatrixAxesLabels?. toString( )) {
726
+ this . @ dynamatrixAxesLabels = null
696
727
} else {
697
- this . dynamatrixAxesLabels = [this . dynamatrixAxesLabels]
728
+ this . @ dynamatrixAxesLabels = [this . @ dynamatrixAxesLabels]
698
729
}
699
730
return true
700
- } else if (Utils . isRegex(this . dynamatrixAxesLabels)) {
701
- this . dynamatrixAxesLabels = [this . dynamatrixAxesLabels]
731
+ } else if (Utils . isRegex(this . @ dynamatrixAxesLabels)) {
732
+ this . @ dynamatrixAxesLabels = [this . @ dynamatrixAxesLabels]
702
733
return true
703
734
} else {
704
735
// if (!errs.equals("")) errs += "\n"
705
- errs + = " Not sure what type 'dynamatrixAxesLabels' is: ${ Utils.castString(this.dynamatrixAxesLabels)} "
706
- // this.dynamatrixAxesLabels = null
736
+ errs + = " Not sure what type 'dynamatrixAxesLabels' is: ${ Utils.castString(this.@ dynamatrixAxesLabels)} "
737
+ // this.@ dynamatrixAxesLabels = null
707
738
}
708
739
}
709
740
@@ -720,8 +751,8 @@ def parallelStages = prepareDynamatrix(
720
751
// deliberately does not include this.commonLabelExpr in the return
721
752
String commonLabelExpr = " "
722
753
723
- def debugErrors = this . shouldDebugErrors()
724
- def debugTrace = this . shouldDebugTrace()
754
+ boolean debugErrors = this . shouldDebugErrors()
755
+ boolean debugTrace = this . shouldDebugTrace()
725
756
726
757
// TODO: Use StringBuilder
727
758
if (Utils . isListNotEmpty(this . requiredNodelabels)) {
@@ -756,7 +787,9 @@ def parallelStages = prepareDynamatrix(
756
787
757
788
} // end of class DynamatrixConfig
758
789
790
+ /* * Used in {@link DynamatrixConfig#initDefault}() to pre-select tools and dynamatrix axes */
759
791
enum CompilerTypes {
760
792
// null,
793
+ /* * C/C++ compiler type */
761
794
C
762
795
}
0 commit comments