Class BuildFlowScriptExtension

  • All Implemented Interfaces:
    ExtensionPoint
    Direct Known Subclasses:
    ShellBuildFlow

    public abstract class BuildFlowScriptExtension
    extends Object
    implements ExtensionPoint
    This class is an extension point to add new handlers for turning certain Builder into executable shell scripts
    Author:
    mhschroe
    • Constructor Detail

      • BuildFlowScriptExtension

        public BuildFlowScriptExtension()
    • Method Detail

      • initThread

        public static void initThread()
        This function is called before the first external call of getScriptsFor(File, AbstractProject, AbstractBuild, Builder, Map, AtomicInteger) is initiated.

        It is useful, because some BuildFlowScriptExtensions need access to a more persistent storage during the runtime of their script generation and that storage is usually a ThreadLocal field.

        A simple example is a script that should only be emitted once, no matter how often a property is encountered during script generation. The method itself can't make this storage available easily, without adding fields to the method signature that most extensions wouldn't even use.

      • init

        public abstract void init()
        Extension counterpart of initThread().
      • cleanUpThread

        public static void cleanUpThread()
        The logical counterpart to initThread(), but called after the last external call to the script generation is done.
      • cleanUp

        public abstract void cleanUp()
        Extension counterpart of cleanUpThread().
      • filterEnvironment

        public abstract void filterEnvironment​(Map<String,​String> env)
        Override this method to filter environment variables set at the beginning of the script.

        Variables can be added, modified or removed.

        Parameters:
        env - the environment to alter. Always mutable and never null.
      • getScriptsFor

        public abstract List<MetaScript> getScriptsFor​(File prefix,
                                                       AbstractProject<?,​?> project,
                                                       AbstractBuild<?,​?> build,
                                                       Builder step,
                                                       Map<String,​String> env,
                                                       AtomicInteger cnt)
        This method asks the extension to handle the given builder and return a valid set of scripts along with some metadata of how to handle it.

        If the extension does not handle that step type, it must return an empty list.

        Parameters:
        prefix - if not null, the prefix for the script files. If null, no prefix is used.
        project - the project that owns the builders. Is not necessarily the parent of build.
        build - the build for which the scripts should be generated. Is not necessarily a build of the given project.
        step - the build to generate a script for.
        env - the environment for the build script.
        cnt - a counter shared between all scripts of a build, so that you unique file names can be generated more easily.
        Returns:
        a list of MetaScript instances, may be empty, but never null.
      • getScriptsFor

        public static List<MetaScript> getScriptsFor​(File prefix,
                                                     AbstractProject<?,​?> project,
                                                     AbstractBuild<?,​?> build,
                                                     List<Builder> builders,
                                                     Map<String,​String> params,
                                                     AtomicInteger cnt)
        Uses the registered BuildFlowScriptExtension instances to turn the list of builders into a list of MetaScript instances that can be used in a script.

        Parameters:
        prefix - if not null, the prefix for the script files. If null, no prefix is used.
        project - the project that owns the builders. Is not necessarily the parent of build.
        build - the build for which the scripts should be generated. Is not necessarily a build of the given project.
        builders - the build steps to convert.
        params - the environment variables/parameters of the job
        cnt - a counter to generate unique IDs with
        Returns:
        the list of scripts that are the result of conversion. May be empty, but never null.
      • getDependentProjectsFor

        public static List<AbstractProject<?,​?>> getDependentProjectsFor​(AbstractProject<?,​?> p,
                                                                               Map<String,​Long> verMap)
        This method returns the list of dependent projects for the given project and versioning map.

        A dependent project is one that is started by (or after) the given project as a form of flow. The generated list should be identical to the one generated in the process of creating the list of scripts.

        Its main use is to allow the WebUI to enumerate all the CommandInterpreter instances that will be run in response to the given job starting.

        Parameters:
        p - the project to target.
        verMap - the versions to use.
        Returns:
        a list of projects. Will always contain at least the value of p.