Class EnvUtil


  • public class EnvUtil
    extends Object
    Utility class for various (loosely related) environment related tasks.
    Since:
    04.04.14
    Author:
    roland
    • Method Detail

      • convertTcpToHttpUrl

        public static String convertTcpToHttpUrl​(String connect)
      • extractLargerVersion

        public static String extractLargerVersion​(String versionA,
                                                  String versionB)
        Compare to version strings and return the larger version strings. This is used in calculating the minimal required API version for this plugin. Version strings must be comparable as floating numbers. The versions must be given in the format in a semantic version foramt (e.g. "1.23" If either version is null, the other version is returned (which can be null as well)
        Parameters:
        versionA - first version number
        versionB - second version number
        Returns:
        the larger version number
      • greaterOrEqualsVersion

        public static boolean greaterOrEqualsVersion​(String versionA,
                                                     String versionB)
        Check whether the first given API version is larger or equals the second given version
        Parameters:
        versionA - first version to check against
        versionB - the second version
        Returns:
        true if versionA is greater or equals versionB, false otherwise
      • splitOnLastColon

        public static List<String[]> splitOnLastColon​(List<String> listToSplit)
        Splits every element in the given list on the last colon in the name and returns a list with two elements: The left part before the colon and the right part after the colon. If the string doesn't contain a colon, the value is used for both elements in the returned arrays.
        Parameters:
        listToSplit - list of strings to split
        Returns:
        return list of 2-element arrays or an empty list if the given list is empty or null
      • removeEmptyEntries

        @Nonnull
        public static List<String> removeEmptyEntries​(@Nullable
                                                      List<String> input)
        Remove empty members of a list.
        Parameters:
        input - A list of String
        Returns:
        A list of Non-Empty (length>0) String
      • splitAtCommasAndTrim

        @Nonnull
        public static List<String> splitAtCommasAndTrim​(Iterable<String> input)
        Split each element of an Iterable at commas.
        Parameters:
        input - Iterable over strings.
        Returns:
        An Iterable over string which breaks down each input element at comma boundaries
      • splitOnSpaceWithEscape

        public static String[] splitOnSpaceWithEscape​(String toSplit)
      • getPropertiesWithSystemOverrides

        public static Properties getPropertiesWithSystemOverrides​(org.apache.maven.project.MavenProject project)
        Return all properties in Maven project, merged with all System properties (-D flags sent to Maven). System properties always takes precedence.
        Parameters:
        project - Project to extract Properties from
        Returns:
      • extractFromPropertiesAsMap

        public static Map<String,​String> extractFromPropertiesAsMap​(String prefix,
                                                                          Properties properties)
        Extract part of given properties as a map. The given prefix is used to find the properties, the rest of the property name is used as key for the map. NOTE: If key is "._combine" it is ignored! This is reserved for combine policy tweaking.
        Parameters:
        prefix - prefix which specifies the part which should be extracted as map
        properties - properties to extract from
        Returns:
        the extracted map or null if no such map exists
      • extractFromPropertiesAsList

        public static List<String> extractFromPropertiesAsList​(String prefix,
                                                               Properties properties)
        Extract from given properties a list of string values. The prefix is used to determine the subset of the given properties from which the list should be extracted, the rest is used as a numeric index. If the rest is not numeric, the order is not determined (all those props are appended to the end of the list) NOTE: If suffix/index is "._combine" it is ignored! This is reserved for combine policy tweaking.
        Parameters:
        prefix - for selecting the properties from which the list should be extracted
        properties - properties from which to extract from
        Returns:
        parsed list or null if no element with prefixes exists
      • extractFromPropertiesAsListOfProperties

        public static List<Properties> extractFromPropertiesAsListOfProperties​(String prefix,
                                                                               Properties properties)
      • extractMavenPropertyName

        public static String extractMavenPropertyName​(String propName)
        Extract from a Maven property which is in the form ${name} the name.
        Parameters:
        propName - property name to extrat
        Returns:
        the pure name or null if this is not a property name
      • fixupPath

        public static String fixupPath​(String path)
        Fix path on Windows machines, i.e. convert 'c:\...\' to '/c/..../'
        Parameters:
        path - path to fix
        Returns:
        the fixed path
      • formatDurationTill

        public static String formatDurationTill​(long start)
        Calculate the duration between now and the given time Taken mostly from http://stackoverflow.com/a/5062810/207604 . Kudos to @dblevins
        Parameters:
        start - starting time (in milliseconds)
        Returns:
        time in seconds
      • firstRegistryOf

        public static String firstRegistryOf​(String... checkFirst)
        Return the first non null registry given. Use the env var DOCKER_REGISTRY as final fallback
        Parameters:
        checkFirst - list of registries to check
        Returns:
        registry found or null if none.
      • ensureRegistryHttpUrl

        public static String ensureRegistryHttpUrl​(String registry)
      • prepareAbsoluteSourceDirPath

        public static File prepareAbsoluteSourceDirPath​(MojoParameters params,
                                                        String path)
      • storeTimestamp

        public static void storeTimestamp​(File tsFile,
                                          Date buildDate)
                                   throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • isWindows

        public static boolean isWindows()
      • isMaven350OrLater

        public static boolean isMaven350OrLater​(org.apache.maven.execution.MavenSession mavenSession)
      • getUserHome

        public static String getUserHome()
        Get User's HOME directory path
        Returns:
        a String value for user's home directory
      • resolveHomeReference

        @Nonnull
        public static String resolveHomeReference​(@Nonnull
                                                  String path)
        Resolve a path. If path starts with '~/', resolve rest of path against the user's home directory.
        Parameters:
        path - An absolute or relative path
        Returns:
        If path starts with '~/', the absolute file path; otherwise, the input path