Class SharedFunctions
- java.lang.Object
-
- org.apache.commons.release.plugin.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)
static void
initDirectory(org.apache.maven.plugin.logging.Log log, File workingDirectory)
Cleans and then initializes an empty directory that is given by theworkingDirectory
parameter.static <T> T
requireNonNull(T obj)
Checks that the specified object reference is notnull
.static <T> T
requireNonNull(T obj, String message)
Checks that the specified object reference is notnull
and throws a customizedMojoExecutionException
if it is.static <T> T
requireNonNull(T obj, Supplier<String> messageSupplier)
Checks that the specified object reference is notnull
and throws a customizedMojoExecutionException
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 specifiedScmProviderRepository
.
-
-
-
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
- Parameters:
log
- theLog
, the maven logger.fromFile
- theFile
from which to copy.toFile
- theFile
to which to copy into.- Throws:
org.apache.maven.plugin.MojoExecutionException
- if anIOException
orNullPointerException
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 theworkingDirectory
parameter.- Parameters:
log
- is the Maven log for output logging, particularly in regards to error management.workingDirectory
- is aFile
that represents the directory to first attempt to delete then create.- Throws:
org.apache.maven.plugin.MojoExecutionException
- when anIOException
orNullPointerException
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 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:
obj
if notnull
- Throws:
org.apache.maven.plugin.MojoExecutionException
- ifobj
isnull
-
requireNonNull
public static <T> T requireNonNull(T obj, String message) throws org.apache.maven.plugin.MojoExecutionException
Checks that the specified object reference is notnull
and throws a customizedMojoExecutionException
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 nullitymessage
- detail message to be used in the event that aNullPointerException
is thrown- Returns:
obj
if notnull
- Throws:
org.apache.maven.plugin.MojoExecutionException
- ifobj
isnull
-
requireNonNull
public static <T> T requireNonNull(T obj, Supplier<String> messageSupplier) throws org.apache.maven.plugin.MojoExecutionException
Checks that the specified object reference is notnull
and throws a customizedMojoExecutionException
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 nullitymessageSupplier
- supplier of the detail message to be used in the event that aNullPointerException
is thrown- Returns:
obj
if notnull
- Throws:
org.apache.maven.plugin.MojoExecutionException
- ifobj
isnull
-
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 specifiedScmProviderRepository
.- Parameters:
providerRepository
- target.distServer
- temp.settings
- temp.settingsDecrypter
- temp.username
- temp.password
- temp.
-
-