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

[FIXED JENKINS-40921][FIXED JENKINS-33020] Only display triggers that make sense for a folder computation #89

Merged
merged 3 commits into from Mar 2, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -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;
Expand Down Expand Up @@ -110,7 +111,6 @@ public abstract class ComputedFolder<I extends TopLevelItem> extends AbstractFol
* 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}.
Expand Down Expand Up @@ -342,6 +342,17 @@ public Map<TriggerDescriptor,Trigger<?>> getTriggers() {
return triggers.toMap();
}

public List<TriggerDescriptor> getTriggerDescriptors() {
Copy link
Member

Choose a reason for hiding this comment

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

@Restricted(DoNotUse.class)

List<TriggerDescriptor> result = new ArrayList<TriggerDescriptor>();
for (TriggerDescriptor d: Trigger.for_(this)) {
if (d instanceof TimerTrigger.DescriptorImpl) {
continue;
Copy link
Member

Choose a reason for hiding this comment

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

Arguably better done using DescriptorVisibilityFilter, so that it would apply automatically to any other UIs offering Triggers here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am assuming that core will add DescriptorVisibilityFilter support to Trigger.for_(Item) in which case this is just a second level filtering

Copy link
Member

Choose a reason for hiding this comment

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

Not to for_, since that operates without context. Rather you would have to call h.filterDescriptors when invoking descriptorList. Or use a higher-level control which does this automatically, if there is one.

}
result.add(d);
}
return result;
}

public void addTrigger(Trigger trigger) {
Trigger old = triggers.get(trigger.getDescriptor());
if (old != null) {
Expand Down
Expand Up @@ -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}"/>
Copy link
Member

Choose a reason for hiding this comment

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

I think this only actually works by accident in config-trigger.jelly. Better style is to use the field attribute.

Either way, you need a configRoundtrip test verifying that the databinding code is correct.

Copy link
Member Author

Choose a reason for hiding this comment

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

actually it works because it is seriously old-school binding!

<f:section title="${%Orphaned Item Strategy}">
<j:set var="orphanedItemStrategyDescriptors" value="${instance.orphanedItemStrategyDescriptors}"/>
<f:block>
Expand Down
@@ -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
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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> {

Expand Down