Skip to content

Commit ca71051

Browse files
authored
Merge pull request #526 from mawinter69/base.view
Add a BaseView to ensure DefaultViewsTabBar is used
2 parents 04e86c7 + 8628d93 commit ca71051

File tree

4 files changed

+88
-116
lines changed

4 files changed

+88
-116
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package jenkins.branch;
2+
3+
import edu.umd.cs.findbugs.annotations.NonNull;
4+
import hudson.model.ListView;
5+
import hudson.model.View;
6+
import hudson.model.ViewGroup;
7+
import hudson.security.ACL;
8+
import hudson.security.Permission;
9+
import java.io.IOException;
10+
import jenkins.scm.api.SCMCategory;
11+
import org.kohsuke.accmod.Restricted;
12+
import org.kohsuke.accmod.restrictions.NoExternalUse;
13+
import org.springframework.security.core.Authentication;
14+
15+
@Restricted(NoExternalUse.class)
16+
public abstract class BaseView<T extends SCMCategory<?>> extends ListView {
17+
18+
private final T category;
19+
20+
public BaseView(ViewGroup owner, @NonNull T category) {
21+
super(category.getName(), owner);
22+
this.category = category;
23+
}
24+
25+
/**
26+
* {@inheritDoc}
27+
*/
28+
@Override
29+
public String getDisplayName() {
30+
return category.getDisplayName() + " (" + getItems().size() + ")";
31+
}
32+
33+
/**
34+
* {@inheritDoc}
35+
*/
36+
@Override
37+
public boolean isRecurse() {
38+
return false;
39+
}
40+
41+
/**
42+
* {@inheritDoc}
43+
*/
44+
@NonNull
45+
@Override
46+
public ACL getACL() {
47+
final ACL acl = super.getACL();
48+
return new ACL() {
49+
@Override
50+
public boolean hasPermission2(@NonNull Authentication a, @NonNull Permission permission) {
51+
if (View.CREATE.equals(permission)
52+
|| View.CONFIGURE.equals(permission)
53+
|| View.DELETE.equals(permission)) {
54+
return false;
55+
}
56+
return acl.hasPermission2(a, permission);
57+
}
58+
};
59+
}
60+
61+
/**
62+
* {@inheritDoc}
63+
*/
64+
@Override
65+
public void save() throws IOException {
66+
// no-op
67+
}
68+
}

src/main/java/jenkins/branch/MultiBranchProjectViewHolder.java

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@
2828
import edu.umd.cs.findbugs.annotations.CheckForNull;
2929
import hudson.Extension;
3030
import hudson.model.Descriptor;
31-
import hudson.model.ListView;
3231
import hudson.model.View;
3332
import hudson.model.ViewDescriptor;
3433
import hudson.model.ViewGroup;
35-
import hudson.security.ACL;
36-
import hudson.security.Permission;
3734
import hudson.util.DescribableList;
3835
import hudson.views.DefaultViewsTabBar;
3936
import hudson.views.JobColumn;
@@ -49,7 +46,6 @@
4946
import net.jcip.annotations.GuardedBy;
5047
import org.kohsuke.accmod.Restricted;
5148
import org.kohsuke.accmod.restrictions.NoExternalUse;
52-
import org.springframework.security.core.Authentication;
5349

5450
/**
5551
* Holds the view configuration for an {@link MultiBranchProject}.
@@ -199,13 +195,7 @@ public synchronized void invalidateCaches() {
199195
* A custom category specific view.
200196
*/
201197
@Restricted(NoExternalUse.class)
202-
public static class ViewImpl extends ListView {
203-
204-
/**
205-
* The category that this view selects.
206-
*/
207-
@NonNull
208-
private final SCMHeadCategory category;
198+
public static class ViewImpl extends BaseView<SCMHeadCategory> {
209199

210200
/**
211201
* Creates a new view.
@@ -214,10 +204,9 @@ public static class ViewImpl extends ListView {
214204
* @param category the category.
215205
*/
216206
public ViewImpl(ViewGroup owner, @NonNull SCMHeadCategory category) {
217-
super(category.getName(), owner);
218-
this.category = category;
207+
super(owner,category);
219208
try {
220-
getJobFilters().replaceBy(Collections.singletonList(new BranchCategoryFilter(category)));
209+
getJobFilters().replaceBy(List.of(new BranchCategoryFilter(category)));
221210
DescribableList<ListViewColumn, Descriptor<ListViewColumn>> columns = getColumns();
222211
columns.replace(columns.get(StatusColumn.class), new BranchStatusColumn());
223212
columns.replace(columns.get(JobColumn.class), new ItemColumn());
@@ -227,50 +216,6 @@ public ViewImpl(ViewGroup owner, @NonNull SCMHeadCategory category) {
227216
setRecurse(false);
228217
}
229218

230-
/**
231-
* {@inheritDoc}
232-
*/
233-
@Override
234-
public String getDisplayName() {
235-
return category.getDisplayName() + " (" + getItems().size() + ")";
236-
}
237-
238-
/**
239-
* {@inheritDoc}
240-
*/
241-
@Override
242-
public boolean isRecurse() {
243-
return false;
244-
}
245-
246-
/**
247-
* {@inheritDoc}
248-
*/
249-
@NonNull
250-
@Override
251-
public ACL getACL() {
252-
final ACL acl = super.getACL();
253-
return new ACL() {
254-
@Override
255-
public boolean hasPermission2(@NonNull Authentication a, @NonNull Permission permission) {
256-
if (View.CREATE.equals(permission)
257-
|| View.CONFIGURE.equals(permission)
258-
|| View.DELETE.equals(permission)) {
259-
return false;
260-
}
261-
return acl.hasPermission2(a, permission);
262-
}
263-
};
264-
}
265-
266-
/**
267-
* {@inheritDoc}
268-
*/
269-
@Override
270-
public void save() throws IOException {
271-
// no-op
272-
}
273-
274219
/**
275220
* Our descriptor
276221
*/

src/main/java/jenkins/branch/OrganizationFolderViewHolder.java

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@
2727
import com.cloudbees.hudson.plugins.folder.views.AbstractFolderViewHolder;
2828
import edu.umd.cs.findbugs.annotations.CheckForNull;
2929
import hudson.Extension;
30-
import hudson.model.ListView;
3130
import hudson.model.View;
3231
import hudson.model.ViewDescriptor;
3332
import hudson.model.ViewGroup;
34-
import hudson.security.ACL;
35-
import hudson.security.Permission;
3633
import hudson.views.DefaultViewsTabBar;
3734
import hudson.views.StatusColumn;
3835
import hudson.views.ViewsTabBar;
@@ -45,7 +42,6 @@
4542
import net.jcip.annotations.GuardedBy;
4643
import org.kohsuke.accmod.Restricted;
4744
import org.kohsuke.accmod.restrictions.NoExternalUse;
48-
import org.springframework.security.core.Authentication;
4945

5046
import static java.util.Arrays.asList;
5147

@@ -189,13 +185,7 @@ public synchronized void invalidateCaches() {
189185
* A custom category specific view.
190186
*/
191187
@Restricted(NoExternalUse.class)
192-
public static class ViewImpl extends ListView {
193-
194-
/**
195-
* The category that this view selects.
196-
*/
197-
@NonNull
198-
private final SCMSourceCategory category;
188+
public static class ViewImpl extends BaseView<SCMSourceCategory> {
199189

200190
/**
201191
* Creates a new view.
@@ -204,10 +194,9 @@ public static class ViewImpl extends ListView {
204194
* @param category the category.
205195
*/
206196
public ViewImpl(ViewGroup owner, @NonNull SCMSourceCategory category) {
207-
super(category.getName(), owner);
208-
this.category = category;
197+
super(owner,category);
209198
try {
210-
getJobFilters().replaceBy(asList(new MultiBranchCategoryFilter(category)));
199+
getJobFilters().replaceBy(List.of(new MultiBranchCategoryFilter(category)));
211200
getColumns().replaceBy(asList(
212201
new StatusColumn(),
213202
new WeatherColumn(),
@@ -220,50 +209,6 @@ public ViewImpl(ViewGroup owner, @NonNull SCMSourceCategory category) {
220209
setRecurse(false);
221210
}
222211

223-
/**
224-
* {@inheritDoc}
225-
*/
226-
@Override
227-
public String getDisplayName() {
228-
return category.getDisplayName() + " (" + getItems().size() + ")";
229-
}
230-
231-
/**
232-
* {@inheritDoc}
233-
*/
234-
@Override
235-
public boolean isRecurse() {
236-
return false;
237-
}
238-
239-
/**
240-
* {@inheritDoc}
241-
*/
242-
@NonNull
243-
@Override
244-
public ACL getACL() {
245-
final ACL acl = super.getACL();
246-
return new ACL() {
247-
@Override
248-
public boolean hasPermission2(@NonNull Authentication a, @NonNull Permission permission) {
249-
if (View.CREATE.equals(permission)
250-
|| View.CONFIGURE.equals(permission)
251-
|| View.DELETE.equals(permission)) {
252-
return false;
253-
}
254-
return acl.hasPermission2(a, permission);
255-
}
256-
};
257-
}
258-
259-
/**
260-
* {@inheritDoc}
261-
*/
262-
@Override
263-
public void save() throws IOException {
264-
// no-op
265-
}
266-
267212
/**
268213
* Our descriptor
269214
*/
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?jelly escape-by-default='true'?>
2+
<j:jelly xmlns:j="jelly:core" xmlns:t="/lib/hudson" xmlns:st="jelly:stapler">
3+
<j:set var="views" value="${it.owner.views}"/>
4+
<j:set var="currentView" value="${it}"/>
5+
<j:if test="${items.isEmpty()}">
6+
<st:include it="${it.owner.viewsTabBar}" page="viewTabs"/>
7+
<st:include it="${it}" page="noJob.jelly"/>
8+
</j:if>
9+
<j:if test="${!items.isEmpty()}">
10+
<t:projectView jobs="${items}" showViewTabs="true" columnExtensions="${it.columns}" indenter="${it.indenter}" itemGroup="${it.owner.itemGroup}">
11+
<st:include it="${it.owner.viewsTabBar}" page="viewTabs"/>
12+
</t:projectView>
13+
</j:if>
14+
</j:jelly>

0 commit comments

Comments
 (0)