-
Notifications
You must be signed in to change notification settings - Fork 11
/
graphFreeStyleParams.groovy
165 lines (143 loc) · 5.06 KB
/
graphFreeStyleParams.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*** BEGIN META {
"name" : "graphFreeStyleParams",
"comment" : "Creates a dot structure for visualization of project parameter flow with Graphviz/GVEdit",
"parameters" : [ 'jobName'],
"core": "2.121",
"authors" : [
{ name : "Ioannis K. Moutsatsos" }
]
} END META**/
/*
Node Graph for Freestyle Parameters
Custom support for
hudson.model.StringParameterDefinition
hudson.model.BooleanParameterDefinition
hudson.model.TextParameterDefinition
hudson.model.FileParameterDefinition
class org.biouno.unochoice.ChoiceParameter
class org.biouno.unochoice.CascadeChoiceParameter
class org.biouno.unochoice.DynamicReferenceParameter
*/
job=jenkins.model.Jenkins.instance.getJob(jobName)
paramList=[]
scriptNode=[:]
gColorNames=['darkolivegreen1','burlywood2','coral','aquamarine1','oldlace','plum1','sienna2','lightgray','darkorange1','gold','magenta1','orangered2','tan','lavender','greenyellow']
booleanStyle="""[fillcolor=yellow, style="rounded,filled",shape=diamond, color=blue]"""
stringStyle="""[shape=plaintext]"""
textStyle="""[shape=underline, color=blue]"""
defaultStyle="""[shape=rect, color=green]"""
acStyle="""[shape=invhouse, color=blue]"""
cascadeStyle="""[shape=oval, color=blue]"""
fileStyle="""[shape=tab, color=black]"""
drStyle="""[shape=hexagon, color=blue]""" //class unochoice.DynamicReferenceParameter
drHiddenStyle="""[style=filled, shape=hexagon, fillcolor=gray]""" //hidden (ET_FORMATTED_HIDDEN_HTML) unochoice.DynamicReferenceParameter
scriptLink="""[dir=both color="maroon4"]"""
seqId=1
job.properties.each{
//println it.value.class
if( it.value.class==hudson.model.ParametersDefinitionProperty){
it.value.getParameterDefinitions().each{pdn->
paramNode=[:]
//println '\n\t'+pdn.name
//println '\t\t'+pdn.getClass() +'\n'
paramName=pdn.name.replace('.','_') //dot does not support names with dot
if (paramName==''){
paramName="UNNAMED_$seqId"
}
paramNode.put('name',paramName)
paramNode.put('class',pdn.getClass())
paramNode.put('scriptType','na')
paramNode.put('scriptName','na')
paramNode.put('choiceType','na')
paramNode.put('refParam',[])
if (pdn in org.biouno.unochoice.UnoChoiceParameter
&& pdn.getScript().getClass()==org.biouno.unochoice.model.ScriptlerScript ){
//println '\t\t'+pdn.getScript().scriptlerScriptId
//println '\t\t'+pdn.getScript().descriptor.plugin
// println '\t\t'+pdn.getScript().getParameters()
paramNode.put('scriptType','ScriptlerScript')
paramNode.put('scriptName',pdn.getScript().scriptlerScriptId)
paramNode.put('choiceType',pdn.getChoiceType())
}
if (pdn in org.biouno.unochoice.CascadeChoiceParameter || pdn in org.biouno.unochoice.DynamicReferenceParameter){
//println '\t\t'+"${pdn.getChoiceType()}:\t${pdn.name}"
paramNode.put('choiceType',pdn.getChoiceType())
paramNode.put('refParam',pdn.getReferencedParameters().tokenize(','))
}
paramList.add(paramNode)
seqId++
}
} //end each Parameter Definition Property
} //end each job properties
//print pre-amble
println """
digraph {
rankdir=LR;
subgraph cluster_0 {
label="$jobName Parameters";
"""
paramList.each{l=it.value->
switch(l.class as String){
case "class hudson.model.BooleanParameterDefinition":
println "\t${l.name}$booleanStyle;"
break
case "class hudson.model.StringParameterDefinition":
println "\t${l.name}$stringStyle;"
break
case "class hudson.model.FileParameterDefinition":
println "\t${l.name}$fileStyle;"
break
case "class hudson.model.TextParameterDefinition":
println "\t${l.name}$textStyle;"
break
case "class org.biouno.unochoice.ChoiceParameter":
println "\t${l.name}$acStyle;"
break
case "class org.biouno.unochoice.CascadeChoiceParameter":
println "\t${l.name}$cascadeStyle;"
break
case "class org.biouno.unochoice.DynamicReferenceParameter":
if(l.choiceType=='ET_FORMATTED_HIDDEN_HTML'){
println "\t${l.name}$drHiddenStyle;"
}else{
println "\t${l.name}$drStyle;"
}
break
default:
println "\t${l.name}$defaultStyle;"
}
/* if (l.refParam.size==0){
println "\t${l.name};"
if ((l.class as String).contains('Boolean')){
println "\t${l.name}$booleanStyle;"
}
}
*/
l.refParam.each{
println "\t$it -> ${l.name};"
}
}
//close cluster_0 start cluster_1
println """}
subgraph cluster_1{
label="scripts";"""
gcn=0
paramList.each{l=it.value->
if(l.scriptName!='na'){
scriptLabel=l.scriptName.replace('.groovy','')
println "\t$scriptLabel[shape=box, style=filled, fillcolor=${gColorNames[gcn]}];"
println "\t${l.name}[style=filled, fillcolor=${gColorNames[gcn]}];"
println "\t$scriptLabel -> ${l.name}$scriptLink;"
gcn++
if (gcn>gColorNames.size){
//recycle colors
gcn=0
}
}
}
//close cluster_1
println """
}
}
"""
return null