-
Bug
-
Resolution: Unresolved
-
Minor
-
None
The methods getAllViews() and getView(name) of the ViewGroup as implemented in JENKINS-43322 are not working as expected.
It is not able find all views in nested viewgroups (namely in folder) as one would expect.
How to reproduce:
- create a folder
- create a view in the folder with name "viewInFolder"
- in script console run
fv = Jenkins.get().getAllViews()
for (v in fv) {
println(v.name)
}
Similarly running
view = Jenkins.get().getView("viewInFolder")
will not find the view.
The problem is that in the PR mentioned in above issue, it is assumed that ViewGroup is an instance of a View but items as folders can also be ViewGroups. (the same problematic behaviour can be also seen in plugins, e.g. prioritysorter).
My suggestion would be to implement a getViewByFullName method similar to getItemByFullName (which is not able to find views) and a method getAllViews(boolean recurseInFolders). The latter would call the current getAllViews() when set to false.
As view names and folder names can overlap (I can have a view with name "test" and a folder with name "test" at the same time). So it needs to be defined how the fullname of a a view is defined.
My Proposal would be to use "/" when the viewGroup is a folder (or another item) and "$" when the viewgroup itself is a View (e.g. as implemented in the nestedView plugin).
A view should then also be able to return its fullname.
So when referencing "abc/view1", it means "view1 in folder "abc".
When referencing "abc$view1" it means view1 in view "abc".
And "abc/def$view2" means view2, that is in view "def" which is in folder "abc"