Package com.cdancy.bitbucket.rest
Class BitbucketUtils
- java.lang.Object
-
- com.cdancy.bitbucket.rest.BitbucketUtils
-
public class BitbucketUtils extends Object
Collection of static methods to be used globally.
-
-
Field Summary
Fields Modifier and Type Field Description static com.google.gson.GsonGSON_PARSERstatic com.google.gson.JsonParserJSON_PARSER
-
Constructor Summary
Constructors Modifier Constructor Description protectedBitbucketUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddEnvironmentVariables(Map<String,String> addEnvVars)Add the passed environment variables to the currently existing env-vars.static BitbucketAuthenticationinferAuthentication()Find credentials (Basic, Bearer, or Anonymous) from system/environment.static StringinferEndpoint()Find endpoint searching first within `System Properties` and then within `Environment Variables` returning whichever has a value first.static PropertiesinferOverrides()Find jclouds overrides (e.g.static <T> List<T>nullToEmpty(Iterable<? extends T> input)Convert passed Iterable into an ImmutableList.static <K,V>
Map<K,V>nullToEmpty(Map<? extends K,? extends V> input)Convert passed Map into an ImmutableMap.static com.google.gson.JsonElementnullToJsonElement(com.google.gson.JsonElement input)Convert passed Map into a JsonElement.static com.google.gson.JsonElementnullToJsonElement(String input)Convert passed String into a JsonElement.static com.google.gson.JsonElementnullToJsonElement(Map input)Convert passed Map into a JsonElement.static voidremoveEnvironmentVariables(Collection<String> removeEnvVars)Remove the passed environment variables keys from the environment.static StringretriveExternalValue(String systemProperty, String environmentVariable)If the passed systemProperty is non-null we will attempt to query the `System Properties` for a value and return it.static voidsetEnvironmentVariables(Map<String,String> newEnvVars)Re-set the environment variables with passed map.
-
-
-
Method Detail
-
nullToEmpty
public static <T> List<T> nullToEmpty(Iterable<? extends T> input)
Convert passed Iterable into an ImmutableList.- Type Parameters:
T- an arbitrary type.- Parameters:
input- the Iterable to copy.- Returns:
- ImmutableList or empty ImmutableList if `input` is null.
-
nullToEmpty
public static <K,V> Map<K,V> nullToEmpty(Map<? extends K,? extends V> input)
Convert passed Map into an ImmutableMap.- Type Parameters:
K- an arbitrary type.V- an arbitrary type.- Parameters:
input- the Map to copy.- Returns:
- ImmutableMap or empty ImmutableMap if `input` is null.
-
nullToJsonElement
public static com.google.gson.JsonElement nullToJsonElement(Map input)
Convert passed Map into a JsonElement.- Parameters:
input- the Map to convert.- Returns:
- JsonElement or empty JsonElement if `input` is null.
-
nullToJsonElement
public static com.google.gson.JsonElement nullToJsonElement(com.google.gson.JsonElement input)
Convert passed Map into a JsonElement.- Parameters:
input- the Map to convert.- Returns:
- JsonElement or empty JsonElement if `input` is null.
-
nullToJsonElement
public static com.google.gson.JsonElement nullToJsonElement(String input)
Convert passed String into a JsonElement.- Parameters:
input- the String to convert.- Returns:
- JsonElement or empty JsonElement if `input` is null.
-
retriveExternalValue
public static String retriveExternalValue(@Nullable String systemProperty, @Nullable String environmentVariable)
If the passed systemProperty is non-null we will attempt to query the `System Properties` for a value and return it. If no value was found, and environmentVariable is non-null, we will attempt to query the `Environment Variables` for a value and return it. If both are either null or can't be found than null will be returned.- Parameters:
systemProperty- possibly existent System Property.environmentVariable- possibly existent Environment Variable.- Returns:
- found external value or null.
-
inferEndpoint
public static String inferEndpoint()
Find endpoint searching first within `System Properties` and then within `Environment Variables` returning whichever has a value first.- Returns:
- endpoint or null if it can't be found.
-
inferAuthentication
public static BitbucketAuthentication inferAuthentication()
Find credentials (Basic, Bearer, or Anonymous) from system/environment.- Returns:
- BitbucketCredentials
-
inferOverrides
public static Properties inferOverrides()
Find jclouds overrides (e.g. Properties) first searching within System Properties and then within Environment Variables (former takes precedance).- Returns:
- Properties object with populated jclouds properties.
-
addEnvironmentVariables
public static void addEnvironmentVariables(Map<String,String> addEnvVars)
Add the passed environment variables to the currently existing env-vars.- Parameters:
addEnvVars- the env-vars to add.
-
removeEnvironmentVariables
public static void removeEnvironmentVariables(Collection<String> removeEnvVars)
Remove the passed environment variables keys from the environment.- Parameters:
removeEnvVars- the env-var keys to be removed.
-
-