Class Make

  • All Implemented Interfaces:
    Command

    public class Make
    extends Object
    The Make command takes care of building the release artifacts. This class is not meant to be used in multi-threaded environments.
    • Field Detail

      • DEFAULT_TEMPLATE_RESOURCE_NAME

        public static final String DEFAULT_TEMPLATE_RESOURCE_NAME
        The name of the resource to load for the default template. Value: "changelog.tpl".
        See Also:
        Constant Field Values
    • Constructor Detail

      • Make

        public Make​(State state,
                    Repository repository)
        Standard constructor.
        Parameters:
        state - the state reference
        repository - the repository reference
        Throws:
        NullPointerException - if a given argument is null
    • Method Detail

      • getChangelogFile

        protected File getChangelogFile()
                                 throws DataAccessException,
                                        IllegalPropertyException
        Returns the reference to the configured changelog file, if configured, or null of no destination file has been set by the configuration.
        Returns:
        the reference to the configured changelog file, if configured
        Throws:
        DataAccessException - in case the configuration can't be loaded for some reason.
        IllegalPropertyException - in case the configuration has some illegal options.
      • isUpToDate

        public boolean isUpToDate()
                           throws DataAccessException,
                                  IllegalPropertyException,
                                  GitException
        Returns true if this command is up to date, which means that the internal state (Command.state()) would not change by running (Command.run()) the command again. It other words, when this method returns true any invocation of the (Command.run()) method is needless and idempotent about the state. This method uses the quickest method to verify whether the state is up to date or not. This method must not rely on dependencies and it must always evaluate its own status independently. As a general rule this method checks if its inputs (i.e. from the configuration) have changed since the last run.
        Returns:
        true if this command is up to date
        Throws:
        DataAccessException - in case the configuration can't be loaded for some reason.
        IllegalPropertyException - in case the configuration has some illegal options.
        GitException - in case of unexpected issues when accessing the Git repository.
        See Also:
        Command.state(), Command.run()
      • state

        public final State state()
        Returns the state object.
        Specified by:
        state in interface Command
        Returns:
        the state object that was passed in the constructor (never null, even when or after Command.run() returns null).
      • repository

        public final Repository repository()
        Returns the repository object.
        Returns:
        the repository object.
      • getCurrentBranch

        protected String getCurrentBranch()
                                   throws GitException
        Returns the name of the current branch or a commit SHA-1 if the repository is in the detached head state.
        Returns:
        the name of the current branch or a commit SHA-1 if the repository is in the detached head state.
        Throws:
        GitException - in case of unexpected issues when accessing the Git repository.
        See Also:
        repository()
      • getLatestCommit

        protected String getLatestCommit()
                                  throws GitException
        Returns the SHA-1 identifier of the last commit in the current branch.
        Returns:
        the SHA-1 identifier of the last commit in the current branch or code if the repository has no commits yet.
        Throws:
        GitException - in case of unexpected issues when accessing the Git repository.
        See Also:
        repository()
      • isRepositoryClean

        protected boolean isRepositoryClean()
                                     throws GitException
        Returns true if the repository is in a clean state (no uncommitted changes).
        Returns:
        true if the repository is in a clean state (no uncommitted changes).
        Throws:
        GitException - in case of unexpected issues when accessing the Git repository.
        See Also:
        repository()
      • isInternalAttributeUpToDate

        protected boolean isInternalAttributeUpToDate​(String attributeName,
                                                      Object expectedValue)
        Returns true if the internal attributes map contains an attribute with the given name and its value equals the given expected value. The comparison is always performed using the Object.toString() method of the expected value.
        Parameters:
        attributeName - the name of the attribute to check. It can't be null
        expectedValue - the expected value of the attribute. It may be null
        Returns:
        true if the internal attributes map contains an attribute with the given name and its value equals the given expected value.
      • getInternalAttribute

        protected String getInternalAttribute​(String attributeName)
        Retrieves the attribute with the given name from the internal attributes map. The returned value is always the Object.toString() representation of the stored value.
        Parameters:
        attributeName - the name of the attribute to store. It can't be null
        Returns:
        the value of the attribute, if available, otherwise null
      • putInternalAttribute

        protected void putInternalAttribute​(String attributeName,
                                            Object attributeValue)
        Stores the attribute with the given name to the internal attributes map. The stored value is always performed the Object.toString() of the given value.
        Parameters:
        attributeName - the name of the attribute to store. It can't be null
        attributeValue - the value of the attribute. It may be null
      • renderTemplate

        protected String renderTemplate​(String template)
                                 throws IllegalPropertyException
        Renders the given template using the internal State object as the context.
        Parameters:
        template - the string template to render.
        Returns:
        the rendered template. It is null if the given template is null.
        Throws:
        IllegalPropertyException - in case the given template can't be rendered.
      • renderTemplateAsBoolean

        protected Boolean renderTemplateAsBoolean​(String template)
                                           throws IllegalPropertyException
        Renders the given template using the internal State object as the context, returning the boolean value, according to Templates.toBoolean(String).
        Parameters:
        template - the string template to render.
        Returns:
        the rendered template as boolean. It is false if the given template is null.
        Throws:
        IllegalPropertyException - in case the given template can't be rendered.
      • renderTemplateAsInteger

        protected Integer renderTemplateAsInteger​(String template)
                                           throws IllegalPropertyException
        Renders the given template using the internal State object as the context, returning the integer value, according to Templates.toInteger(String).
        Parameters:
        template - the string template to render.
        Returns:
        the rendered template as integer. It is 0 if the given template is null.
        Throws:
        IllegalPropertyException - in case the given template can't be rendered.
      • resolveServiceOptions

        protected Map<String,​String> resolveServiceOptions​(Map<String,​String> options)
                                                          throws IllegalPropertyException
        Resolves the given options by rendering each value of the given map as a template. Keys are left unchanged.
        Parameters:
        options - the options to resolve.
        Returns:
        a new map with the same keys as the input map but values resolved as templates.
        Throws:
        IllegalPropertyException - in case the given values can't be rendered as templates.