Class JenkinsUtils


  • public class JenkinsUtils
    extends java.lang.Object
    Collection of static methods to be used globally.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static com.google.gson.Gson GSON_PARSER  
      static com.google.gson.JsonParser JSON_PARSER  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected JenkinsUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addEnvironmentVariables​(java.util.Map<java.lang.String,​java.lang.String> addEnvVars)
      Add the passed environment variables to the currently existing env-vars.
      static JenkinsAuthentication inferAuthentication()
      Find credentials (Basic, Bearer, or Anonymous) from system/environment.
      static java.lang.String inferEndpoint()
      Find endpoint searching first within `System Properties` and then within `Environment Variables` returning whichever has a value first.
      static java.util.Properties inferOverrides()
      Find jclouds overrides (e.g.
      static <T> java.util.List<T> nullToEmpty​(java.lang.Iterable<? extends T> input)
      Convert passed Iterable into an ImmutableList.
      static <K,​V>
      java.util.Map<K,​V>
      nullToEmpty​(java.util.Map<? extends K,​? extends V> input)
      Convert passed Map into an ImmutableMap.
      static com.google.gson.JsonElement nullToJsonElement​(com.google.gson.JsonElement input)
      Convert passed Map into a JsonElement.
      static com.google.gson.JsonElement nullToJsonElement​(java.lang.String input)
      Convert passed String into a JsonElement.
      static com.google.gson.JsonElement nullToJsonElement​(java.util.Map input)
      Convert passed Map into a JsonElement.
      static void removeEnvironmentVariables​(java.util.Collection<java.lang.String> removeEnvVars)
      Remove the passed environment variables keys from the environment.
      static java.lang.String retriveExternalValue​(java.lang.String systemProperty, java.lang.String environmentVariable)
      If the passed systemProperty is non-null we will attempt to query the `System Properties` for a value and return it.
      static void setEnvironmentVariables​(java.util.Map<java.lang.String,​java.lang.String> newEnvVars)
      Re-set the environment variables with passed map.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • GSON_PARSER

        public static final com.google.gson.Gson GSON_PARSER
      • JSON_PARSER

        public static final com.google.gson.JsonParser JSON_PARSER
    • Constructor Detail

      • JenkinsUtils

        protected JenkinsUtils()
    • Method Detail

      • nullToEmpty

        public static <T> java.util.List<T> nullToEmpty​(java.lang.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> java.util.Map<K,​V> nullToEmpty​(java.util.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​(java.util.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​(java.lang.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 java.lang.String retriveExternalValue​(@Nullable
                                                            java.lang.String systemProperty,
                                                            @Nullable
                                                            java.lang.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 java.lang.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 JenkinsAuthentication inferAuthentication()
        Find credentials (Basic, Bearer, or Anonymous) from system/environment.
        Returns:
        BitbucketCredentials
      • inferOverrides

        public static java.util.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​(java.util.Map<java.lang.String,​java.lang.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​(java.util.Collection<java.lang.String> removeEnvVars)
        Remove the passed environment variables keys from the environment.
        Parameters:
        removeEnvVars - the env-var keys to be removed.
      • setEnvironmentVariables

        public static void setEnvironmentVariables​(java.util.Map<java.lang.String,​java.lang.String> newEnvVars)
        Re-set the environment variables with passed map.
        Parameters:
        newEnvVars - map to reset env-vars with.