Class VersionTagger

All Implemented Interfaces:
Generator, Renamable, ResourceProvider

public class VersionTagger extends AbstractGenerator

A generator that creates a new Git tag that denotes a Project's version. The version to be used for the tag is based on the project's Version property. Together with the prefix returned by the prefix evaluator, it forms the tag.

The generator reads the property jdbld.versionTagger.mode to determine how the version for the tag is computed. If the property is not set, the generator uses the version as-is. If set to one of the algorithm constants (NEXT_MAJOR, NEXT_MINOR, NEXT_PATCH, CLOSEST_MAJOR, CLOSEST_MINOR, CLOSEST_PATCH), it increments the respective version component. The next algorithms always increment, while the closest algorithms only increment if the version has a pre-release qualifier (usually SNAPSHOT). Use the -P flag to set the algorithm on the command line, e.g. jdbld -Pjdbld.versionTagger.mode=nextMinor.

The generator creates annotated tags with a default message of "Release tag <tag>". You can override this message by setting property jdbld.versionTagger.message.

The generator uses an instance of Git to access the repository. If also required elsewhere, the jdbld configuration should associate the build project with the instance using setGitApi(org.jdrupes.builder.api.RootProject). Else that property will be set on first usage of the generator.

This provider is made available as an extension. org.jdrupes:jdbld-ext-git:

  • Field Details

    • DRY_RUN

      public static final String DRY_RUN
      If defined and not equal to false prevents the actual creation of the tag.
      See Also:
    • MODE

      public static final String MODE
      Defines the evaluation mode for the new version.
      See Also:
    • CLOSEST_MAJOR

      public static final String CLOSEST_MAJOR

      Creates a new tag that increments the major version if the current version has a pre-release qualifier (e.g. 0.3.1-SNAPSHOT becomes 1.0.0). Does nothing if the version has no snapshot qualifier.

      Use jdbld -Pjdbld.versionTagger.mode=closestMajor to set the algorithm.

      See Also:
    • CLOSEST_MINOR

      public static final String CLOSEST_MINOR

      Creates a new tag that increments the minor version if the current version has a pre-release qualifier (e.g. 0.3.1-SNAPSHOT becomes 0.4.0). Does nothing if the version has no snapshot qualifier.

      Use jdbld -Pjdbld.versionTagger.mode=closestMinor to set the algorithm.

      See Also:
    • CLOSEST_PATCH

      public static final String CLOSEST_PATCH

      Creates a new tag that increments the patch version if the current version has a pre-release qualifier (e.g. 0.3.1-SNAPSHOT becomes 0.3.2). Does nothing if the version has no snapshot qualifier.

      Use jdbld -Pjdbld.versionTagger.mode=closestPatch to set the algorithm.

      See Also:
    • NEXT_MAJOR

      public static final String NEXT_MAJOR

      Creates a new tag that increments the major version regardless of any qualifier (e.g. 0.3.1 becomes 1.0.0).

      Use jdbld -Pjdbld.versionTagger.mode=nextMajor to set the algorithm.

      See Also:
    • NEXT_MINOR

      public static final String NEXT_MINOR

      Creates a new tag that increments the minor version regardless of any qualifier (e.g. 0.3.1 becomes 0.4.0).

      Use jdbld -Pjdbld.versionTagger.mode=nextMinor to set the algorithm.

      See Also:
    • NEXT_PATCH

      public static final String NEXT_PATCH

      Creates a new tag that increments the patch version regardless of any qualifier (e.g. 0.3.1 becomes 0.3.2).

      Use jdbld -Pjdbld.versionTagger.mode=nextPatch to set the algorithm.

      See Also:
  • Constructor Details

    • VersionTagger

      public VersionTagger(Project project)
      Instantiates a new version reporter.
      Parameters:
      project - the project
  • Method Details

    • setGitApi

      public static org.eclipse.jgit.api.Git setGitApi(RootProject project)
      Sets the property GitProperties.GitApi on the root project to an instance of Git. Does nothing if the property is already set.
      Parameters:
      project - the new git api
      Returns:
      the Git instance
    • preReleaseQualifiers

      public VersionTagger preReleaseQualifiers(String... preReleaseQualifier)
      Sets the pre-release qualifiers. Defaults to "SNAPSHOT".
      Parameters:
      preReleaseQualifier - the pre release qualifier
      Returns:
      the version tagger
    • prefixEvalutor

      Sets the function that determines the prefix for the version tag. The tag is formed by concatenating the prefix with the project's version. Defaults to "v".
      Parameters:
      evaluator - the function that takes a project and returns the prefix string
      Returns:
      this generator for chaining
    • doProvide

      protected <R extends Resource> Collection<R> doProvide(ResourceRequest<R> requested)
      Description copied from class: AbstractProvider
      Invoked by ResourceProviderSpi.provide(ResourceRequest) after checking if the invocation is allowed.
      Specified by:
      doProvide in class AbstractProvider
      Type Parameters:
      R - the generic type
      Parameters:
      requested - the request for resources
      Returns:
      the stream