Class SharedFunctions
java.lang.Object
org.apache.commons.release.plugin.SharedFunctions
Shared static functions for all of our Mojos.
- Since:
- 1.0
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrevents instantiation of this utility class. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidstatic voidinitDirectory(org.apache.maven.plugin.logging.Log log, File workingDirectory) Cleans and then initializes an empty directory that is given by theworkingDirectoryparameter.static <T> TrequireNonNull(T obj) Checks that the specified object reference is notnull.static <T> TrequireNonNull(T obj, String message) Checks that the specified object reference is notnulland throws a customizedMojoExecutionExceptionif it is.static <T> TrequireNonNull(T obj, Supplier<String> messageSupplier) Checks that the specified object reference is notnulland throws a customizedMojoExecutionExceptionif it is.static voidsetAuthentication(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) Sets authentication information on the specifiedScmProviderRepository.
-
Field Details
-
BUFFER_BYTE_SIZE
-
-
Constructor Details
-
SharedFunctions
private SharedFunctions()Prevents instantiation of this utility class.
-
-
Method Details
-
copyFile
public static void copyFile(org.apache.maven.plugin.logging.Log log, File fromFile, File toFile) throws org.apache.maven.plugin.MojoExecutionException - Parameters:
log- TheLog, the Maven logger.fromFile- TheFilefrom which to copy.toFile- The destinationFile.- Throws:
org.apache.maven.plugin.MojoExecutionException- Thrown if anIOExceptionoccurs.
-
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 theworkingDirectoryparameter.- Parameters:
log- is the Maven log for output logging, particularly with regard to error management.workingDirectory- is aFilethat represents the directory to first attempt to delete and then create.- Throws:
org.apache.maven.plugin.MojoExecutionException- Thrown if anIOExceptionoccurs.
-
requireNonNull
Checks that the specified object reference is notnull. 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:
objif notnull- Throws:
org.apache.maven.plugin.MojoExecutionException- Thrown ifobjisnull.
-
requireNonNull
public static <T> T requireNonNull(T obj, String message) throws org.apache.maven.plugin.MojoExecutionException Checks that the specified object reference is notnulland throws a customizedMojoExecutionExceptionif 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 nullitymessage- detail message to be used in the event that aNullPointerExceptionis thrown- Returns:
objif notnull- Throws:
org.apache.maven.plugin.MojoExecutionException- Thrown ifobjisnull.
-
requireNonNull
public static <T> T requireNonNull(T obj, Supplier<String> messageSupplier) throws org.apache.maven.plugin.MojoExecutionException Checks that the specified object reference is notnulland throws a customizedMojoExecutionExceptionif 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 nullitymessageSupplier- supplier of the detail message to be used in the event that aNullPointerExceptionis thrown- Returns:
objif notnull- Throws:
org.apache.maven.plugin.MojoExecutionException- Thrown ifobjisnull.
-
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) Sets authentication information on the specifiedScmProviderRepository.- Parameters:
providerRepository- The repository to configure.distServer- The server ID used to look up credentials in Maven settings.settings- The Maven settings.settingsDecrypter- The decrypter for stored credentials.username- The fallback username when no server username is available.password- The fallback password when no server password is available.
-