From 79326edd97fa41279adc2e50fca3d15641a9ebb6 Mon Sep 17 00:00:00 2001 From: Ignacio Albors Date: Wed, 2 Jan 2013 13:55:07 +0100 Subject: [PATCH 001/383] Swapped conditions to get all the builds in timeline graph. Since the builds are sorted from most to least recent, the limit method discarded the builds not in the same day as the last one. --- core/src/main/java/hudson/util/RunList.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/hudson/util/RunList.java b/core/src/main/java/hudson/util/RunList.java index 3d1a3499d3..3105d478cc 100644 --- a/core/src/main/java/hudson/util/RunList.java +++ b/core/src/main/java/hudson/util/RunList.java @@ -262,13 +262,14 @@ public class RunList extends AbstractList { public RunList byTimestamp(final long start, final long end) { return limit(new CountingPredicate() { - public boolean apply(int index,R r) { - return r.getTimeInMillis()() { - public boolean apply(R r) { + public boolean apply(int index, R r) { return start<=r.getTimeInMillis(); } + }).filter( + new Predicate() { + public boolean apply(R r) { + return r.getTimeInMillis() Date: Sun, 6 Jan 2013 21:25:29 +0100 Subject: [PATCH 002/383] Added test for byTimestamp method in RunList. --- .../test/java/hudson/util/RunListTest.java | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 core/src/test/java/hudson/util/RunListTest.java diff --git a/core/src/test/java/hudson/util/RunListTest.java b/core/src/test/java/hudson/util/RunListTest.java new file mode 100644 index 0000000000..f60b865131 --- /dev/null +++ b/core/src/test/java/hudson/util/RunListTest.java @@ -0,0 +1,96 @@ +/* + * The MIT License + * + * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * 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 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package hudson.util; + +import static org.mockito.Mockito.when; +import hudson.model.Run; + +import java.util.ArrayList; + +import junit.framework.TestCase; + +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +/** + * @author Ignacio Albors + */ +@RunWith(PowerMockRunner.class) +public class RunListTest extends TestCase { + + // RunList for byTimestamp tests + private RunList rlist; + + // RunList is ordered from most to least recent + private void setUpByTimestampRuns() { + Run r1 = PowerMockito.mock(Run.class); + Run r2 = PowerMockito.mock(Run.class); + + when(r1.getNumber()).thenReturn(1); + when(r2.getNumber()).thenReturn(2); + + when(r1.getTimeInMillis()).thenReturn(new Long(200)); + when(r2.getTimeInMillis()).thenReturn(new Long(300)); + + ArrayList list = new ArrayList(); + list.add(r2); + list.add(r1); + + rlist = RunList.fromRuns(list); + + } + + @PrepareForTest({Run.class}) + public void testbyTimestampAllRuns() { + + setUpByTimestampRuns(); + + RunList tested = rlist.byTimestamp(0, 400); + assertEquals(2, tested.toArray().length); + + } + + @PrepareForTest({Run.class}) + public void testbyTimestampFirstRun() { + setUpByTimestampRuns(); + // Only r1 + RunList tested = rlist.byTimestamp(150, 250); + assertEquals(1, tested.toArray().length); + assertEquals(1, tested.getFirstBuild().getNumber()); + + } + + @PrepareForTest({Run.class}) + public void testbyTimestampLastRun() { + + setUpByTimestampRuns(); + // Only r2 + RunList tested = rlist.byTimestamp(250, 350); + assertEquals(1, tested.toArray().length); + assertEquals(2, tested.getFirstBuild().getNumber()); + } + +} From 8ee743ec32fb30cd966b6054b5ef5b9a0d18b430 Mon Sep 17 00:00:00 2001 From: ialbors Date: Mon, 7 Jan 2013 21:19:10 +0100 Subject: [PATCH 003/383] Fixed indentation. --- core/src/main/java/hudson/util/RunList.java | 7 +- .../test/java/hudson/util/RunListTest.java | 80 +++++++++---------- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/core/src/main/java/hudson/util/RunList.java b/core/src/main/java/hudson/util/RunList.java index 3105d478cc..15d4adbcd7 100644 --- a/core/src/main/java/hudson/util/RunList.java +++ b/core/src/main/java/hudson/util/RunList.java @@ -265,10 +265,9 @@ public class RunList extends AbstractList { public boolean apply(int index, R r) { return start<=r.getTimeInMillis(); } - }).filter( - new Predicate() { - public boolean apply(R r) { - return r.getTimeInMillis()() { + public boolean apply(R r) { + return r.getTimeInMillis() is ordered from most to least recent private void setUpByTimestampRuns() { - Run r1 = PowerMockito.mock(Run.class); - Run r2 = PowerMockito.mock(Run.class); - - when(r1.getNumber()).thenReturn(1); - when(r2.getNumber()).thenReturn(2); - - when(r1.getTimeInMillis()).thenReturn(new Long(200)); - when(r2.getTimeInMillis()).thenReturn(new Long(300)); - - ArrayList list = new ArrayList(); - list.add(r2); - list.add(r1); - - rlist = RunList.fromRuns(list); - + Run r1 = PowerMockito.mock(Run.class); + Run r2 = PowerMockito.mock(Run.class); + + when(r1.getNumber()).thenReturn(1); + when(r2.getNumber()).thenReturn(2); + + when(r1.getTimeInMillis()).thenReturn(new Long(200)); + when(r2.getTimeInMillis()).thenReturn(new Long(300)); + + ArrayList list = new ArrayList(); + list.add(r2); + list.add(r1); + + rlist = RunList.fromRuns(list); + } - + @PrepareForTest({Run.class}) - public void testbyTimestampAllRuns() { - + public void testbyTimestampAllRuns() { + setUpByTimestampRuns(); - - RunList tested = rlist.byTimestamp(0, 400); - assertEquals(2, tested.toArray().length); - } - + RunList tested = rlist.byTimestamp(0, 400); + assertEquals(2, tested.toArray().length); + + } + @PrepareForTest({Run.class}) - public void testbyTimestampFirstRun() { - setUpByTimestampRuns(); - // Only r1 - RunList tested = rlist.byTimestamp(150, 250); - assertEquals(1, tested.toArray().length); - assertEquals(1, tested.getFirstBuild().getNumber()); + public void testbyTimestampFirstRun() { + setUpByTimestampRuns(); + // Only r1 + RunList tested = rlist.byTimestamp(150, 250); + assertEquals(1, tested.toArray().length); + assertEquals(1, tested.getFirstBuild().getNumber()); + + } - } - @PrepareForTest({Run.class}) - public void testbyTimestampLastRun() { + public void testbyTimestampLastRun() { + + setUpByTimestampRuns(); + // Only r2 + RunList tested = rlist.byTimestamp(250, 350); + assertEquals(1, tested.toArray().length); + assertEquals(2, tested.getFirstBuild().getNumber()); + } - setUpByTimestampRuns(); - // Only r2 - RunList tested = rlist.byTimestamp(250, 350); - assertEquals(1, tested.toArray().length); - assertEquals(2, tested.getFirstBuild().getNumber()); - } - } From 02d34ebc858db5e364151997fe2e9ed7c70ace62 Mon Sep 17 00:00:00 2001 From: lvotypko Date: Thu, 21 Mar 2013 05:47:46 +0100 Subject: [PATCH 004/383] Method getComputers() does not return computers for label expressions. --- core/src/main/java/hudson/model/View.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/hudson/model/View.java b/core/src/main/java/hudson/model/View.java index 3a65a6cac5..9f9e3b2e41 100644 --- a/core/src/main/java/hudson/model/View.java +++ b/core/src/main/java/hudson/model/View.java @@ -385,7 +385,7 @@ public abstract class View extends AbstractModelObject implements AccessControll for (Computer c : computers) { Node n = c.getNode(); if (n != null) { - if (labels.contains(null) && n.getMode() == Mode.NORMAL || !isDisjoint(n.getAssignedLabels(), labels)) { + if (labels.contains(null) && n.getMode() == Mode.NORMAL || !isDisjoint(labels, n)) { result.add(c); } } @@ -394,9 +394,9 @@ public abstract class View extends AbstractModelObject implements AccessControll return result; } - private boolean isDisjoint(Collection c1, Collection c2) { - for (Object o : c1) - if (c2.contains(o)) + private boolean isDisjoint(Collection