java.lang.Object
hudson.model.Descriptor<GlobalConfiguration>
jenkins.model.GlobalConfiguration
com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl
All Implemented Interfaces:
ExtensionPoint, Describable<GlobalConfiguration>, Saveable, OnMaster

@ExportedBean @Extension @Symbol("gerrit-trigger") public class PluginImpl extends GlobalConfiguration
Main Plugin entrance.
Author:
Robert Sandell <robert.sandell@sonyericsson.com>
  • Field Details

    • DISPLAY_NAME

      public static final String DISPLAY_NAME
      What to call this plug-in to humans.
      See Also:
    • SYMBOL_NAME

      public static final String SYMBOL_NAME
      Machine readable plugin name.
      See Also:
    • PERMISSION_GROUP

      public static final PermissionGroup PERMISSION_GROUP
      Any special permissions needed by this plugin are grouped into this.
    • MANUAL_TRIGGER

      public static final Permission MANUAL_TRIGGER
      The permission that allows users to perform the ManualTriggerAction.
    • RETRIGGER

      public static final Permission RETRIGGER
      The permission that allows users to perform the RetriggerAction.
    • DEFAULT_SERVER_NAME

      public static final String DEFAULT_SERVER_NAME
      the default server name.
      See Also:
    • TEST_SSH_KEYFILE_LOCATION_PROPERTY

      public static final String TEST_SSH_KEYFILE_LOCATION_PROPERTY
      System property used during testing to replace the location of the public key for mock connections.
  • Constructor Details

    • PluginImpl

      public PluginImpl()
  • Method Details

    • getApi

      public Api getApi()
      Gets api.
      Returns:
      the api.
    • getInstance

      @CheckForNull public static PluginImpl getInstance()
      Returns the instance of this class. If Jenkins.getInstanceOrNull() ()} isn't available or the plugin class isn't registered null will be returned.
      Returns:
      the instance.
    • isActive

      public boolean isActive()
      Check if this plugin is active.
      Returns:
      true if active.
    • getServers

      @Exported public List<GerritServer> getServers()
      Get the list of Gerrit servers.
      Returns:
      the list of GerritServers
    • getServers_

      @NonNull public static List<GerritServer> getServers_()
      Get the list of Gerrit servers. Static shorthand for getServers(). If the plugin instance is not available, and empty list is returned.
      Returns:
      the list of GerritServers
    • getServerNames

      public List<String> getServerNames()
      Get the list of Gerrit server names.
      Returns:
      the list of server names as a list.
    • getServerNames_

      @NonNull public static List<String> getServerNames_()
      Static shorthand for getServerNames().
      Returns:
      the list of server names.
    • getServer

      public GerritServer getServer(String name)
      Get a GerritServer object by its name.
      Parameters:
      name - the name of the server to get.
      Returns:
      the GerritServer object to get, or null if no server has this name.
    • getServer_

      @CheckForNull public static GerritServer getServer_(String name)
      Get a GerritServer object by its name. Static short for getServer(String).
      Parameters:
      name - the name of the server to get.
      Returns:
      the GerritServer object to get, or null if no server has this name.
      See Also:
    • getServer

      public GerritServer getServer(com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
      Returns the Gerrit Server based on the GerritTriggerEvent.
      Parameters:
      event - The GerritTriggerEvent.
      Returns:
      GerritServer or null if no server could be found.
    • getServer_

      @CheckForNull public static GerritServer getServer_(com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
      Returns a GerritServer object based on a GerritTriggerEvent. Static short for getServer(GerritTriggeredEvent).
      Parameters:
      event - The GerritTriggerEvent.
      Returns:
      GerritServer or null if no server could be found.
    • getFirstServer

      @CheckForNull public GerritServer getFirstServer()
      Gets the first server in the server list. Or null if there are no servers.
      Returns:
      the server.
    • getFirstServer_

      @CheckForNull public static GerritServer getFirstServer_()
      Static shorthand for getFirstServer().
      Returns:
      the server if any.
    • setServers

      public void setServers(List<GerritServer> servers)
      Set the list of Gerrit servers.
      Parameters:
      servers - the list to be set.
    • addServer

      public List<GerritServer> addServer(GerritServer s)
      Add a server to the list.
      Parameters:
      s - the server to be added.
      Returns:
      the list after adding the server.
    • removeServer

      public List<GerritServer> removeServer(GerritServer s)
      Remove a server from the list.
      Parameters:
      s - the server to be removed.
      Returns:
      the list after removing the server.
    • containsServer

      public boolean containsServer(String serverName)
      Check whether the list of servers contains a GerritServer object of a specific name.
      Parameters:
      serverName - to check.
      Returns:
      whether the list contains a server with the given name.
    • containsServer_

      public static boolean containsServer_(String serverName)
      Static shorthand for containsServer(String).
      Parameters:
      serverName - to check.
      Returns:
      whether the list contains a server with the given name.
    • getServerConfig

      public static IGerritHudsonTriggerConfig getServerConfig(com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
      Finds the server config for the event's provider.
      Parameters:
      event - the event
      Returns:
      the config or null if no server could be found.
      See Also:
      • GerritTriggeredEvent.getProvider()
    • getPluginConfig

      public PluginConfig getPluginConfig()
      Gets the global config.
      Returns:
      the config.
    • setPluginConfig

      public void setPluginConfig(PluginConfig pluginConfig)
      Set plugin config.
      Parameters:
      pluginConfig - New config to set.
    • getPluginConfig_

      @CheckForNull public static PluginConfig getPluginConfig_()
      Gets the global config. Static short hand for getPluginConfig().
      Returns:
      the config.
    • save_

      public static void save_() throws IOException
      Static shorthand for Plugin.save().
      Throws:
      IOException - if save does so.
    • getConfigFile

      protected XmlFile getConfigFile()
      Overrides:
      getConfigFile in class Descriptor<GlobalConfiguration>
    • getHandler

      @NonNull public com.sonymobile.tools.gerrit.gerritevents.GerritHandler getHandler()
      Returns the GerritHandler object.
      Returns:
      gerritEventManager
    • getHandler_

      @CheckForNull public static com.sonymobile.tools.gerrit.gerritevents.GerritHandler getHandler_()
      Static shorthand for getHandler().
      Returns:
      gerritEventManager
    • getConfiguredJobs

      public List<Job> getConfiguredJobs(String serverName)
      Return the list of jobs configured with a server.
      Parameters:
      serverName - the name of the Gerrit server.
      Returns:
      the list of jobs configured with this server.
    • getConfiguredJobs_

      @NonNull public static List<Job> getConfiguredJobs_(String serverName)
      Static shorthand for getConfiguredJobs(String). Will return an empty list if plugin instance is null.
      Parameters:
      serverName - the name of the Gerrit server.
      Returns:
      the list of jobs configured with this server.
    • start

      public void start()
      Start the plugin.
    • initializeDispatchers

      @Initializer(after=SYSTEM_CONFIG_ADAPTED) public static void initializeDispatchers()
      Forces initialization of the Dispatchers. They need to register and listen to GerritEvents. Normally, it is lazy loaded when the first build is started.
    • load

      public void load()
      Load plugin config.
      Overrides:
      load in class Descriptor<GlobalConfiguration>
    • doXStreamRegistrations

      protected static void doXStreamRegistrations()
      Registers XStream alias and converters to handle backwards compatibility with old data.
    • stop

      public void stop()
      Stop the plugin.
    • gerritStart

      @Initializer(after=PLUGINS_STARTED, before=EXTENSIONS_AUGMENTED) @Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public static void gerritStart()
      Startup hook.
    • gerritStop

      @Terminator(after=COMPLETED) @Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public static void gerritStop()
      Shutdown hook.