From 0e4b3034e6674758f6458dc914aa004e8b28dd49 Mon Sep 17 00:00:00 2001 From: Zhao Xiaojie Date: Thu, 17 Jan 2019 15:50:21 +0800 Subject: [PATCH 1/5] Add function to remove trigger --- .../hudson/plugins/folder/computed/ComputedFolder.java | 8 ++++++-- .../plugins/folder/computed/ComputedFolderTest.java | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java b/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java index 8c2649ff..2ec43620 100644 --- a/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java +++ b/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java @@ -501,13 +501,17 @@ public List getTriggerDescriptors() { } public void addTrigger(Trigger trigger) { + removeTrigger(trigger); + triggers.add(trigger); + trigger.start(this, true); + } + + public void removeTrigger(Trigger trigger) { Trigger old = triggers.get(trigger.getDescriptor()); if (old != null) { old.stop(); triggers.remove(old); } - triggers.add(trigger); - trigger.start(this, true); } /** diff --git a/src/test/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolderTest.java b/src/test/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolderTest.java index 24faed41..2dc6e916 100644 --- a/src/test/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolderTest.java +++ b/src/test/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolderTest.java @@ -443,6 +443,16 @@ public void triggersRoundtrip() throws Exception { } + @Test + public void cleanTriggers() throws Exception { + SampleComputedFolder s = r.jenkins.createProject(SampleComputedFolder.class, "s"); + s.addTrigger(new PeriodicFolderTrigger("30m")); + + s.removeTrigger(new PeriodicFolderTrigger("30m")); + + assertEquals(0, s.getTriggers().size()); + } + @Test @Issue("JENKINS-42511") public void concurrentEvents() throws Exception { From 718301c1e811deb0a7d97c51b2cbe3780c1b6708 Mon Sep 17 00:00:00 2001 From: Zhao Xiaojie Date: Mon, 18 Mar 2019 18:08:29 +0800 Subject: [PATCH 2/5] add javadoc comments --- .../hudson/plugins/folder/computed/ComputedFolder.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java b/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java index 2ec43620..a83c241c 100644 --- a/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java +++ b/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java @@ -500,12 +500,20 @@ public List getTriggerDescriptors() { return result; } + /** + * Update an old trigger or add a new one. + * @param trigger Target trigger instance. + */ public void addTrigger(Trigger trigger) { removeTrigger(trigger); triggers.add(trigger); trigger.start(this, true); } + /** + * Remove an exists trigger. + * @param trigger Target trigger instance. + */ public void removeTrigger(Trigger trigger) { Trigger old = triggers.get(trigger.getDescriptor()); if (old != null) { From 248be1aba2ccdfe6fc32b7928f96819ba23269d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Fern=C3=A1ndez?= <31063239+fcojfernandez@users.noreply.github.com> Date: Fri, 22 Mar 2019 09:51:34 +0800 Subject: [PATCH 3/5] Update src/test/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolderTest.java Co-Authored-By: LinuxSuRen --- .../hudson/plugins/folder/computed/ComputedFolderTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolderTest.java b/src/test/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolderTest.java index 2dc6e916..2f35e182 100644 --- a/src/test/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolderTest.java +++ b/src/test/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolderTest.java @@ -447,6 +447,8 @@ public void triggersRoundtrip() throws Exception { public void cleanTriggers() throws Exception { SampleComputedFolder s = r.jenkins.createProject(SampleComputedFolder.class, "s"); s.addTrigger(new PeriodicFolderTrigger("30m")); + + assertEquals(1, s.getTriggers().size()); s.removeTrigger(new PeriodicFolderTrigger("30m")); From 97d53e1ff9d6dd21126b884446f088841aa92339 Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Fri, 22 Mar 2019 09:51:42 +0800 Subject: [PATCH 4/5] Update src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java Co-Authored-By: LinuxSuRen --- .../hudson/plugins/folder/computed/ComputedFolder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java b/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java index a83c241c..09184c3f 100644 --- a/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java +++ b/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java @@ -511,7 +511,7 @@ public void addTrigger(Trigger trigger) { } /** - * Remove an exists trigger. + * Remove an existing trigger. * @param trigger Target trigger instance. */ public void removeTrigger(Trigger trigger) { From f774c34b4b583f9ac56f9007406ba7dac0dbc93c Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Fri, 22 Mar 2019 09:51:48 +0800 Subject: [PATCH 5/5] Update src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java Co-Authored-By: LinuxSuRen --- .../hudson/plugins/folder/computed/ComputedFolder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java b/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java index 09184c3f..cab64a31 100644 --- a/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java +++ b/src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java @@ -501,7 +501,7 @@ public List getTriggerDescriptors() { } /** - * Update an old trigger or add a new one. + * Update an existing trigger or add a new one. * @param trigger Target trigger instance. */ public void addTrigger(Trigger trigger) {