Initialize default view earlier in the init process. (#8413)

* Initialize default view earlier in the init process.

Perform the default view initialization next to loading the
configuration from disk.

This is more consistent as the primary view and views are cleared just
before loading from disk, which leads to a temporary inconsistent state while
Jenkins initializes.

* Update core/src/main/java/jenkins/model/Jenkins.java

Co-authored-by: Jesse Glick <jglick@cloudbees.com>

* View initialization should happen even when the config file doesn't exist.

* Add a test

---------

Co-authored-by: Jesse Glick <jglick@cloudbees.com>
This commit is contained in:
Vincent LatombeandJesse Glick authored and GitHub committed 2023-08-29 18:59:14 +02:00
1 parent 8365d61dbe
commit 7b1dfd8d83
2 files changed
+42 -10

No files matched your search

+9 -10
View File
@@ -3378,6 +3378,15 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
// load from disk
cfg.unmarshal(Jenkins.this);
}
// initialize views by inserting the default view if necessary
// this is both for clean Jenkins and for backward compatibility.
if (views.isEmpty() || primaryView == null) {
View v = new AllView(AllView.DEFAULT_VIEW_NAME);
setViewOwner(v);
views.add(0, v);
primaryView = v.getViewName();
}
primaryView = AllView.migrateLegacyPrimaryAllViewLocalizedName(views, primaryView);
configLoaded = true;
try {
checkRawBuildsDir(buildsDir);
@@ -3536,16 +3545,6 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
getAssignedLabels();
}
// initialize views by inserting the default view if necessary
// this is both for clean Jenkins and for backward compatibility.
if (views.size() == 0 || primaryView == null) {
View v = new AllView(AllView.DEFAULT_VIEW_NAME);
setViewOwner(v);
views.add(0, v);
primaryView = v.getViewName();
}
primaryView = AllView.migrateLegacyPrimaryAllViewLocalizedName(views, primaryView);
if (useSecurity != null && !useSecurity) {
// forced reset to the unsecure mode.
// this works as an escape hatch for people who locked themselves out.