/* * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package jetbrains.buildServer.buildTriggers.url; import com.intellij.openapi.diagnostic.Logger; import jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor; import jetbrains.buildServer.buildTriggers.BuildTriggerService; import jetbrains.buildServer.buildTriggers.BuildTriggeringPolicy; import jetbrains.buildServer.buildTriggers.async.AsyncPolledBuildTriggerFactory; import jetbrains.buildServer.serverSide.InvalidProperty; import jetbrains.buildServer.serverSide.PropertiesProcessor; import jetbrains.buildServer.util.StringUtil; import jetbrains.buildServer.web.openapi.PluginDescriptor; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import static jetbrains.buildServer.buildTriggers.url.UrlBuildTriggerUtil.DISPLAY_NAME; import static jetbrains.buildServer.buildTriggers.url.UrlBuildTriggerUtil.URL_PARAM; /** * User: vbedrosova * Date: 06.12.10 * Time: 13:19 */ public final class UrlBuildTrigger extends BuildTriggerService { @NotNull private static final Logger LOG = LoggerFactory.getLogger(UrlBuildTrigger.class); @NotNull private final PluginDescriptor myPluginDescriptor; @NotNull private final BuildTriggeringPolicy myPolicy; public UrlBuildTrigger( @NotNull final PluginDescriptor pluginDescriptor, @NotNull final AsyncPolledBuildTriggerFactory triggerFactory, @NotNull final ResourceHashProviderFactory resourceHashProviderFactory) { myPluginDescriptor = pluginDescriptor; myPolicy = triggerFactory.createBuildTrigger(new UrlAsyncBuildTrigger(resourceHashProviderFactory), LOG); } @NotNull @Override public String getName() { return "urlBuildTrigger"; } @NotNull @Override public String getDisplayName() { return DISPLAY_NAME; } @NotNull @Override public String describeTrigger(@NotNull BuildTriggerDescriptor buildTriggerDescriptor) { return "Wait for a change at " + buildTriggerDescriptor.getProperties().get(URL_PARAM) + " URL"; } @NotNull @Override public BuildTriggeringPolicy getBuildTriggeringPolicy() { return myPolicy; } @Override public PropertiesProcessor getTriggerPropertiesProcessor() { return properties -> { final ArrayList invalidProps = new ArrayList<>(); final String url = properties.get(URL_PARAM); if (StringUtil.isEmptyOrSpaces(url)) { invalidProps.add(new InvalidProperty(URL_PARAM, "URL must be specified")); } final String err = ResourceHashProviderFactory.checkUrl(url); if (StringUtil.isNotEmpty(err)) { invalidProps.add(new InvalidProperty(URL_PARAM, err)); } return invalidProps; }; } @Override public String getEditParametersUrl() { return myPluginDescriptor.getPluginResourcesPath("editUrlBuildTrigger.jsp"); } @Override public boolean isMultipleTriggersPerBuildTypeAllowed() { return true; } }