Class SharedFunctions


  • public final class SharedFunctions
    extends Object
    Shared static functions for all of our Mojos.
    Since:
    1.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int BUFFER_BYTE_SIZE
      I want a buffer that is an array with 1024 elements of bytes.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SharedFunctions()
      Making the constructor private because the class only contains static methods.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void copyFile​(org.apache.maven.plugin.logging.Log log, File fromFile, File toFile)
      Copies a File from the fromFile to the toFile and logs the failure using the Maven Log.
      static void initDirectory​(org.apache.maven.plugin.logging.Log log, File workingDirectory)
      Cleans and then initializes an empty directory that is given by the workingDirectory parameter.
      static <T> T requireNonNull​(T obj)
      Checks that the specified object reference is not null.
      static <T> T requireNonNull​(T obj, String message)
      Checks that the specified object reference is not null and throws a customized MojoExecutionException if it is.
      static <T> T requireNonNull​(T obj, Supplier<String> messageSupplier)
      Checks that the specified object reference is not null and throws a customized MojoExecutionException if it is.
      static void setAuthentication​(org.apache.maven.scm.provider.ScmProviderRepository providerRepository, String distServer, org.apache.maven.settings.Settings settings, org.apache.maven.settings.crypto.SettingsDecrypter settingsDecrypter, String username, String password)
      Set authentication information on the specified ScmProviderRepository.
    • Field Detail

      • BUFFER_BYTE_SIZE

        public static final int BUFFER_BYTE_SIZE
        I want a buffer that is an array with 1024 elements of bytes. We declare the constant here for the sake of making the code more readable.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SharedFunctions

        private SharedFunctions()
        Making the constructor private because the class only contains static methods.
    • Method Detail

      • copyFile

        public static void copyFile​(org.apache.maven.plugin.logging.Log log,
                                    File fromFile,
                                    File toFile)
                             throws org.apache.maven.plugin.MojoExecutionException
        Copies a File from the fromFile to the toFile and logs the failure using the Maven Log.
        Parameters:
        log - the Log, the maven logger.
        fromFile - the File from which to copy.
        toFile - the File to which to copy into.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if an IOException or NullPointerException is caught.
      • initDirectory

        public static void initDirectory​(org.apache.maven.plugin.logging.Log log,
                                         File workingDirectory)
                                  throws org.apache.maven.plugin.MojoExecutionException
        Cleans and then initializes an empty directory that is given by the workingDirectory parameter.
        Parameters:
        log - is the Maven log for output logging, particularly in regards to error management.
        workingDirectory - is a File that represents the directory to first attempt to delete then create.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - when an IOException or NullPointerException is caught for the purpose of bubbling the exception up to Maven properly.
      • requireNonNull

        public static <T> T requireNonNull​(T obj)
                                    throws org.apache.maven.plugin.MojoExecutionException
        Checks that the specified object reference is not null. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:
         public Foo(Bar bar) {
             this.bar = SharedFunctions.requireNonNull(bar);
         }
         
        Type Parameters:
        T - the type of the reference
        Parameters:
        obj - the object reference to check for nullity
        Returns:
        obj if not null
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if obj is null
      • requireNonNull

        public static <T> T requireNonNull​(T obj,
                                           String message)
                                    throws org.apache.maven.plugin.MojoExecutionException
        Checks that the specified object reference is not null and throws a customized MojoExecutionException if it is. This method is designed primarily for doing parameter validation in methods and constructors with multiple parameters, as demonstrated below:
         public Foo(Bar bar, Baz baz) {
             this.bar = SharedFunctions.requireNonNull(bar, "bar must not be null");
             this.baz = SharedFunctions.requireNonNull(baz, "baz must not be null");
         }
         
        Type Parameters:
        T - the type of the reference
        Parameters:
        obj - the object reference to check for nullity
        message - detail message to be used in the event that a NullPointerException is thrown
        Returns:
        obj if not null
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if obj is null
      • requireNonNull

        public static <T> T requireNonNull​(T obj,
                                           Supplier<String> messageSupplier)
                                    throws org.apache.maven.plugin.MojoExecutionException
        Checks that the specified object reference is not null and throws a customized MojoExecutionException if it is.

        Unlike the method requireNonNull(Object, String), this method allows creation of the message to be deferred until after the null check is made. While this may confer a performance advantage in the non-null case, when deciding to call this method care should be taken that the costs of creating the message supplier are less than the cost of just creating the string message directly.

        Type Parameters:
        T - the type of the reference
        Parameters:
        obj - the object reference to check for nullity
        messageSupplier - supplier of the detail message to be used in the event that a NullPointerException is thrown
        Returns:
        obj if not null
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if obj is null
      • setAuthentication

        public static void setAuthentication​(org.apache.maven.scm.provider.ScmProviderRepository providerRepository,
                                             String distServer,
                                             org.apache.maven.settings.Settings settings,
                                             org.apache.maven.settings.crypto.SettingsDecrypter settingsDecrypter,
                                             String username,
                                             String password)
        Set authentication information on the specified ScmProviderRepository.
        Parameters:
        providerRepository - target.
        distServer - temp.
        settings - temp.
        settingsDecrypter - temp.
        username - temp.
        password - temp.