Skip to content

Commit

Permalink
Showing 2 changed files with 54 additions and 34 deletions.
44 changes: 27 additions & 17 deletions src/main/java/jenkins/branch/MultiBranchProjectViewHolder.java
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@
import com.cloudbees.hudson.plugins.folder.views.AbstractFolderViewHolder;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Extension;
import hudson.model.Descriptor;
import hudson.model.ListView;
@@ -70,12 +71,12 @@ public class MultiBranchProjectViewHolder extends AbstractFolderViewHolder {
* The list of {@link View}s.
*/
@GuardedBy("this")
private transient List<View> views = null;
private transient volatile List<View> views = null;
/**
* The primary view name.
*/
@GuardedBy("this")
private transient String primaryView = null;
private transient volatile String primaryView = null;

/**
* Constructor.
@@ -92,21 +93,12 @@ public MultiBranchProjectViewHolder(MultiBranchProject<?, ?> owner) {
*/
@NonNull
@Override
public synchronized List<View> getViews() {
public List<View> getViews() {
if (owner.getItems().isEmpty()) {
// when there are no branches nor pull requests to show, switch to the special welcome view
return Collections.singletonList(owner.getWelcomeView());
}
if (views == null) {
List<View> views = new ArrayList<>();
for (SCMHeadCategory c : SCMHeadCategory.collectAndSimplify(owner.getSCMSources()).values()) {
views.add(new ViewImpl(owner, c));
if (c.isUncategorized()) {
primaryView = c.getName();
}
}
this.views = views;
}
ensureViews();
return views;
}

@@ -122,14 +114,12 @@ public void setViews(@NonNull List<? extends View> views) {
* {@inheritDoc}
*/
@Override
public synchronized String getPrimaryView() {
public String getPrimaryView() {
if (owner.getItems().isEmpty()) {
// when there are no branches nor pull requests to show, switch to the special welcome view
return BaseEmptyView.VIEW_NAME;
}
if (primaryView == null) {
getViews(); // will set primaryView for us
}
ensureViews();
return primaryView;
}

@@ -141,6 +131,26 @@ public void setPrimaryView(@CheckForNull String name) {
// ignore
}

/**
* Initialize views and primaryView
*/
private void ensureViews() {
if (views == null) {
synchronized(this) {
if (views == null) {
List<View> views = new ArrayList<>();
for (SCMHeadCategory c : SCMHeadCategory.collectAndSimplify(owner.getSCMSources()).values()) {
views.add(new ViewImpl(owner, c));
if (c.isUncategorized()) {
primaryView = c.getName();
}
}
this.views = views;
}
}
}
}

/**
* {@inheritDoc}
*/
44 changes: 27 additions & 17 deletions src/main/java/jenkins/branch/OrganizationFolderViewHolder.java
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@
import com.cloudbees.hudson.plugins.folder.views.AbstractFolderViewHolder;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Extension;
import hudson.model.ListView;
import hudson.model.View;
@@ -68,12 +69,12 @@ public class OrganizationFolderViewHolder extends AbstractFolderViewHolder {
* The list of {@link View}s.
*/
@GuardedBy("this")
private transient List<View> views = null;
private transient volatile List<View> views = null;
/**
* The primary view name.
*/
@GuardedBy("this")
private transient String primaryView = null;
private transient volatile String primaryView = null;

/**
* Constructor.
@@ -90,17 +91,8 @@ public OrganizationFolderViewHolder(OrganizationFolder owner) {
*/
@NonNull
@Override
public synchronized List<View> getViews() {
if (views == null) {
List<View> views = new ArrayList<>();
for (SCMSourceCategory c : SCMSourceCategory.collectAndSimplify(owner.getNavigators()).values()) {
views.add(new ViewImpl(owner, c));
if (c.isUncategorized()) {
primaryView = c.getName();
}
}
this.views = views;
}
public List<View> getViews() {
ensureViews();
return views;
}

@@ -116,13 +108,31 @@ public void setViews(@NonNull List<? extends hudson.model.View> views) {
* {@inheritDoc}
*/
@Override
public synchronized String getPrimaryView() {
if (primaryView == null) {
getViews(); // will set primaryView for us
}
public String getPrimaryView() {
ensureViews();
return primaryView;
}

/**
* Initialize views and primaryView
*/
private void ensureViews() {
if (views == null) {
synchronized(this) {
if (views == null) {
List<View> views = new ArrayList<>();
for (SCMSourceCategory c : SCMSourceCategory.collectAndSimplify(owner.getNavigators()).values()) {
views.add(new ViewImpl(owner, c));
if (c.isUncategorized()) {
primaryView = c.getName();
}
}
this.views = views;
}
}
}
}

/**
* {@inheritDoc}
*/

0 comments on commit a1c604b

Please sign in to comment.