Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jenkins 19082 #898

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 20 additions & 20 deletions core/src/main/java/hudson/model/ListView.java
@@ -1,6 +1,6 @@
/*
* The MIT License
*
*
* Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi,
* Erik Ramfelt, Seiji Sogabe, Martin Eigenbrodt, Alan Harder
*
Expand All @@ -10,10 +10,10 @@
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -69,7 +69,7 @@ public class ListView extends View implements Saveable {
*/
@GuardedBy("this")
/*package*/ /*almost-final*/ SortedSet<String> jobNames = new TreeSet<String>(CaseInsensitiveComparator.INSTANCE);

private DescribableList<ViewJobFilter, Descriptor<ViewJobFilter>> jobFilters;

private DescribableList<ListViewColumn, Descriptor<ListViewColumn>> columns;
Expand All @@ -78,12 +78,12 @@ public class ListView extends View implements Saveable {
* Include regex string.
*/
private String includeRegex;

/**
* Whether to recurse in ItemGroups
*/
private boolean recurse;

/**
* Compiled include pattern from the includeRegex string.
*/
Expand Down Expand Up @@ -148,7 +148,7 @@ public DescribableList<ViewJobFilter, Descriptor<ViewJobFilter>> getJobFilters()
public DescribableList<ListViewColumn, Descriptor<ListViewColumn>> getColumns() {
return columns;
}

/**
* Returns a read-only view of all {@link Job}s in this view.
*
Expand Down Expand Up @@ -184,19 +184,19 @@ public List<TopLevelItem> getItems() {
}
// for sanity, trim off duplicates
items = new ArrayList<TopLevelItem>(new LinkedHashSet<TopLevelItem>(items));

return items;
}

@Override
public boolean contains(TopLevelItem item) {
return getItems().contains(item);
}

private void includeItems(ItemGroup<? extends TopLevelItem> parent, SortedSet<String> names) {
includeItems(parent, parent, names);
}

private void includeItems(ItemGroup<? extends TopLevelItem> root, ItemGroup<?> parent, SortedSet<String> names) {
if (includePattern != null) {
for (Item item : parent.getItems()) {
Expand All @@ -213,13 +213,13 @@ private void includeItems(ItemGroup<? extends TopLevelItem> root, ItemGroup<?> p
}
}
}

public synchronized boolean jobNamesContains(TopLevelItem item) {
if (item == null) return false;
return jobNames.contains(item.getRelativeNameFrom(getOwnerItemGroup()));
}



/**
* Adds the given item to this view.
Expand All @@ -236,11 +236,11 @@ public void add(TopLevelItem item) throws IOException {
public String getIncludeRegex() {
return includeRegex;
}

public boolean isRecurse() {
return recurse;
}

/*
* For testing purposes
*/
Expand Down Expand Up @@ -329,13 +329,13 @@ protected void submit(StaplerRequest req) throws ServletException, FormException
}
}

setIncludeRegex(req.getParameter("useincluderegex"));
setIncludeRegex(req.getParameter("useincluderegex"), req.getParameter("includeRegex"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for nullity of useincluderegex should be done here, no need to pass it to the method.


if (columns == null) {
columns = new DescribableList<ListViewColumn,Descriptor<ListViewColumn>>(this);
}
columns.rebuildHetero(req, json, ListViewColumn.all(), "columns");

if (jobFilters == null) {
jobFilters = new DescribableList<ViewJobFilter,Descriptor<ViewJobFilter>>(this);
}
Expand All @@ -344,9 +344,9 @@ protected void submit(StaplerRequest req) throws ServletException, FormException
String filter = Util.fixEmpty(req.getParameter("statusFilter"));
statusFilter = filter != null ? "1".equals(filter) : null;
}
public void setIncludeRegex(String includeRegex) {
if (includeRegex != null) {

public void setIncludeRegex(String useIncludeRegex, String includeRegex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is not meant to know it is called from a form submission, the signature change is unnecessary.

if (useIncludeRegex != null) {
this.includeRegex = Util.nullify(includeRegex);
if (this.includeRegex == null)
this.includePattern = null;
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/java/hudson/model/ListViewTest.java
Expand Up @@ -21,7 +21,7 @@

@RunWith(PowerMockRunner.class)
public class ListViewTest {

private interface ItemGroupOfNonTopLevelItem extends TopLevelItem, ItemGroup<Item> {}

@Test
Expand All @@ -42,7 +42,7 @@ public void listItemRecurseWorksWithNonTopLevelItems() throws IOException{
lv.add(ig);
assertEquals(1, lv.getItems().size());
}

@Test
@PrepareForTest({ListViewColumn.class,Items.class})
public void includeRegexProgrammatic() {
Expand All @@ -54,7 +54,7 @@ public void includeRegexProgrammatic() {
ItemGroup ig = mock(ItemGroup.class);
when(owner.getItemGroup()).thenReturn(ig);
ListView view = new ListView("test", owner);
view.setIncludeRegex(".*");
view.setIncludeRegex("on", ".*");
TopLevelItem it = Mockito.mock(TopLevelItem.class);
List<TopLevelItem> igContent = Arrays.asList((TopLevelItem) it);
when(Items.getAllItems(eq(ig), eq(TopLevelItem.class))).thenReturn(igContent);
Expand Down