Skip to content
Permalink
Browse files

Merge pull request #89 from stephenc/jenkins-40921

[FIXED JENKINS-40921][FIXED JENKINS-33020] Only display triggers that make sense for a folder computation
  • Loading branch information...
stephenc committed Mar 2, 2017
2 parents ea44cb6 + e6ea7d8 commit 0d35973205f9bf79eee02ba36dc380f02b6ecc0a
@@ -49,6 +49,7 @@
import hudson.model.queue.CauseOfBlockage;
import hudson.model.queue.SubTask;
import hudson.security.ACL;
import hudson.triggers.TimerTrigger;
import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor;
import hudson.util.DescribableList;
@@ -110,7 +111,6 @@
* Our {@link Trigger}s.
*/
private DescribableList<Trigger<?>,TriggerDescriptor> triggers;
// TODO p:config-triggers also expects there to be a BuildAuthorizationToken authToken option. Do we want one?

/**
* Our {@link FolderComputation}.
@@ -342,6 +342,19 @@ protected final String getSuccessfulDestination() {
return triggers.toMap();
}

@Restricted(NoExternalUse.class) // currently used only by jelly / stapler
public List<TriggerDescriptor> getTriggerDescriptors() {
// TODO remove this once core has support for DescriptorVisibilityFilter on Trigger.for_(Item)
List<TriggerDescriptor> result = new ArrayList<TriggerDescriptor>();
for (TriggerDescriptor d: Trigger.for_(this)) {
if (d instanceof TimerTrigger.DescriptorImpl) {
continue;
}
result.add(d);
}
return result;
}

public void addTrigger(Trigger trigger) {
Trigger old = triggers.get(trigger.getDescriptor());
if (old != null) {
@@ -26,7 +26,9 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:f="/lib/form" xmlns:p="/lib/hudson/project">
<st:include page="configure-entries" optional="true"/>
<p:config-trigger/>
<f:descriptorList title="${%triggers(it.computation.displayName)}"
descriptors="${it.triggerDescriptors}"
instances="${it.triggers}"/>
<f:section title="${%Orphaned Item Strategy}">
<j:set var="orphanedItemStrategyDescriptors" value="${instance.orphanedItemStrategyDescriptors}"/>
<f:block>
@@ -0,0 +1,24 @@
#
# The MIT License
#
# Copyright (c) 2017, CloudBees, Inc.
#
# 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.
#
triggers={0} Triggers
@@ -1,4 +1,4 @@
ComputedFolder.already_computing=Already computing
FolderComputation.DisplayName=Folder Computation
ThrottleComputationQueueTaskDispatcher.MaxConcurrentIndexing=At maximum indexing capacity
PeriodicFolderTrigger.DisplayName=Periodically if not otherwise run
PeriodicFolderTrigger.DisplayName=Periodically if not otherwise run
@@ -42,6 +42,7 @@
import hudson.model.TopLevelItem;
import hudson.model.View;
import hudson.model.ViewGroup;
import hudson.triggers.Trigger;
import hudson.views.DefaultViewsTabBar;
import hudson.views.ViewsTabBar;
import java.io.ByteArrayOutputStream;
@@ -59,6 +60,7 @@
import org.apache.commons.lang.StringUtils;
import org.junit.Test;

import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
@@ -339,6 +341,18 @@ public void run() {
assertThat(org.round, is(round));
}

@Test
public void triggersRoundtrip() throws Exception {
SampleComputedFolder s = r.jenkins.createProject(SampleComputedFolder.class, "s");
s.addTrigger(new PeriodicFolderTrigger("30m"));
SampleComputedFolder s2 = r.configRoundtrip(s);
Trigger<?> trigger = s2.getTriggers().get(r.jenkins.getDescriptorByType(PeriodicFolderTrigger.DescriptorImpl.class));
assertThat(trigger, notNullValue());
assertThat(trigger, instanceOf(PeriodicFolderTrigger.class));
assertThat(((PeriodicFolderTrigger)trigger).getInterval(), is("30m"));

}

@SuppressWarnings({"unchecked", "rawtypes"})
public static class SampleComputedFolder extends ComputedFolder<FreeStyleProject> {

0 comments on commit 0d35973

Please sign in to comment.
You can’t perform that action at this time.