de.caff.version

## Class ModuleVersionTool

- java.lang.Object
- - de.caff.version.ModuleVersionTool

-     public final class ModuleVersionTool
      extends java.lang.Object

  Helper class providing static methods to create and access classes implementing `ModuleVersionService`.
  Since:
    Dezember 28, 2021
  Author:
    Rammi

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `JAVA_SERVICE_TEMPLATE` Service class template.
    `static java.text.SimpleDateFormat` | `TIMESTAMP_FORMAT` Format used for timestamp, included in semantic vesion as build string.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `createJavaImpl(java.lang.String fullClassName, java.lang.String moduleName, SemVer version, java.util.Date releaseDate, java.io.File srcDir)` Write a Java file which implements this service.
    `static SemVer` | `extractFromJavaImpl(java.io.File javaImplFile)` Extract the semantic version from a Java service implementation.
    `static SemVer` | `extractFromJavaImpl(java.lang.String fullClassName, java.io.File srcDir)` Extract the semantic version from a Java service implementation.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### TIMESTAMP_FORMAT

          public static final java.text.SimpleDateFormat TIMESTAMP_FORMAT

      Format used for timestamp, included in semantic vesion as build string.

    - #### JAVA_SERVICE_TEMPLATE

          public static final java.lang.String JAVA_SERVICE_TEMPLATE

      Service class template. This is used as a format string for `String.format()`, where it expects the following arguments:
      1. The package of the created class, inluding the `package` keyword .
      2. The class name w/o package.
      3. The name of the module for which the service is created.
      4. The semantic version for which this is created.
      5. The creating class.
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### createJavaImpl

          public static void createJavaImpl(@NotNull
                                            java.lang.String fullClassName,
                                            @NotNull
                                            java.lang.String moduleName,
                                            @NotNull
                                            SemVer version,
                                            @NotNull
                                            java.util.Date releaseDate,
                                            @NotNull
                                            java.io.File srcDir)
                                     throws java.io.IOException

      Write a Java file which implements this service. This will create the package directory if necessary, then write a Java file which contains a service class implementing this interface with the given name which package/name combination which returns the `moduleName` and `version` as expected.
      Parameters:
        `fullClassName` - full class name including package
        `moduleName` - name of module, will be returned by `ModuleVersionService.getModuleName()` of the created service
        `version` - version of module, will be returned by `ModuleVersionService.getModuleVersion()` of the created service
        `releaseDate` - release date
        `srcDir` - root of the source tree, has to be an existing directory
      Throws:
        `java.io.IOException` - on write or directory creation arrors

    - #### extractFromJavaImpl

          @NotNull
          public static SemVer extractFromJavaImpl(@NotNull
                                                            java.io.File javaImplFile)
                                                     throws java.io.IOException

      Extract the semantic version from a Java service implementation. This is a simple-minded helper method which works with Java files created by `createJavaImpl(String, String, SemVer, Date, File)`, but not necessarily with other files.
      Parameters:
        `javaImplFile` - Java implementation or a module version service
      Returns:
        semantic module version
      Throws:
        `java.io.IOException` - on read errors or when no version was found

    - #### extractFromJavaImpl

          @Nullable
          public static SemVer extractFromJavaImpl(@NotNull
                                                             java.lang.String fullClassName,
                                                             @NotNull
                                                             java.io.File srcDir)
                                                      throws java.io.IOException

      Extract the semantic version from a Java service implementation.
      Parameters:
        `fullClassName` - full class name of the service implementation including package
        `srcDir` - root directory of the Java source tree
      Returns:
        semantic version, or `null` if implementation does not exist
      Throws:
        `java.io.IOException` - on read errors or if the file exists but does not contain an extractable version, compare `extractFromJavaImpl(File)`