Class SharedFunctions
java.lang.Object
org.apache.commons.release.plugin.SharedFunctions
Shared static functions for all of our Mojos.
- Since:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intI want a buffer that is an array with 1024 elements of bytes. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateMaking the constructor private because the class only contains static methods. -
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
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:
-
-
Constructor Details
-
SharedFunctions
private SharedFunctions()Making the constructor private because the class only contains static methods.
-
-
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- theFileto which to copy into.- Throws:
org.apache.maven.plugin.MojoExecutionException- if anIOExceptionorNullPointerExceptionis 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 theworkingDirectoryparameter.- Parameters:
log- is the Maven log for output logging, particularly in regards to error management.workingDirectory- is aFilethat represents the directory to first attempt to delete then create.- Throws:
org.apache.maven.plugin.MojoExecutionException- when anIOExceptionorNullPointerExceptionis caught for the purpose of bubbling the exception up to Maven properly.
-
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- 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- 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- 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- target.distServer- temp.settings- temp.settingsDecrypter- temp.username- temp.password- temp.
-