Skip to content

Commit

Permalink
Introduced TriggeredItem to better abstract getTriggers (#7131)
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick authored Sep 28, 2022
1 parent 71a9276 commit d5d518e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 14 deletions.
7 changes: 4 additions & 3 deletions core/src/main/java/hudson/triggers/Trigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import jenkins.model.ParameterizedJobMixIn;
import jenkins.triggers.TriggeredItem;
import jenkins.util.SystemProperties;
import org.jenkinsci.Symbol;
import org.kohsuke.accmod.Restricted;
Expand All @@ -77,6 +77,7 @@
* put {@link Extension} on your {@link TriggerDescriptor} class.
*
* @author Kohsuke Kawaguchi
* @see TriggeredItem
*/
public abstract class Trigger<J extends Item> implements Describable<Trigger<?>>, ExtensionPoint {

Expand Down Expand Up @@ -279,9 +280,9 @@ public void run(AbstractProject p) {
}

// Process all triggers, except SCMTriggers when synchronousPolling is set
for (ParameterizedJobMixIn.ParameterizedJob<?, ?> p : inst.allItems(ParameterizedJobMixIn.ParameterizedJob.class)) {
for (TriggeredItem p : inst.allItems(TriggeredItem.class)) {
for (Trigger t : p.getTriggers().values()) {
if (!(t instanceof SCMTrigger && scmd.synchronousPolling)) {
if (!(p instanceof AbstractProject && t instanceof SCMTrigger && scmd.synchronousPolling)) {
if (t != null && t.spec != null && t.tabs != null) {
LOGGER.log(Level.FINE, "cron checking {0} with spec ‘{1}’", new Object[]{p, t.spec.trim()});

Expand Down
13 changes: 2 additions & 11 deletions core/src/main/java/jenkins/model/ParameterizedJobMixIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,18 @@
import hudson.model.queue.QueueTaskFuture;
import hudson.search.SearchIndexBuilder;
import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor;
import hudson.util.AlternativeUiTextProvider;
import hudson.views.BuildButtonColumn;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import jenkins.model.lazy.LazyBuildMixIn;
import jenkins.triggers.SCMTriggerItem;
import jenkins.triggers.TriggeredItem;
import jenkins.util.TimeDuration;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
Expand Down Expand Up @@ -321,7 +320,7 @@ public final String getBuildNowText() {
/**
* Marker for job using this mixin, and default implementations of many methods.
*/
public interface ParameterizedJob<JobT extends Job<JobT, RunT> & ParameterizedJobMixIn.ParameterizedJob<JobT, RunT> & Queue.Task, RunT extends Run<JobT, RunT> & Queue.Executable> extends BuildableItem {
public interface ParameterizedJob<JobT extends Job<JobT, RunT> & ParameterizedJobMixIn.ParameterizedJob<JobT, RunT> & Queue.Task, RunT extends Run<JobT, RunT> & Queue.Executable> extends BuildableItem, TriggeredItem {

/**
* Used for CLI binding.
Expand Down Expand Up @@ -373,14 +372,6 @@ default String getBuildNowText() {
return getParameterizedJobMixIn().getBuildNowText();
}

/**
* Gets currently configured triggers.
* You may use {@code <p:config-trigger/>} to configure them.
* @return a map from trigger kind to instance
* @see #getTrigger
*/
Map<TriggerDescriptor, Trigger<?>> getTriggers();

@Override
default boolean scheduleBuild(Cause c) {
return getParameterizedJobMixIn().scheduleBuild(c);
Expand Down
45 changes: 45 additions & 0 deletions core/src/main/java/jenkins/triggers/TriggeredItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* The MIT License
*
* Copyright 2022 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.
*/

package jenkins.triggers;

import hudson.model.Item;
import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor;
import java.util.Map;

/**
* An item which can be configured with {@link Trigger}s.
* @since TODO
*/
public interface TriggeredItem extends Item {

/**
* Gets currently configured triggers. You may use
* {@code <p:config-trigger/>} to configure them.
* @return a map from trigger kind to instance
*/
Map<TriggerDescriptor, Trigger<?>> getTriggers();

}

0 comments on commit d5d518e

Please sign in to comment.