public class EnvUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
DOCKER_HTTP_PORT |
static String |
MAVEN_PROPERTY_REGEXP |
static String |
PROPERTY_COMBINE_POLICY_SUFFIX |
| Modifier and Type | Method and Description |
|---|---|
static String |
convertTcpToHttpUrl(String connect) |
static String |
ensureRegistryHttpUrl(String registry) |
static List<String> |
extractFromPropertiesAsList(String prefix,
Properties properties)
Extract from given properties a list of string values.
|
static Map<String,String> |
extractFromPropertiesAsMap(String prefix,
Properties properties)
Extract part of given properties as a map.
|
static String |
extractLargerVersion(String versionA,
String versionB)
Compare to version strings and return the larger version strings.
|
static String |
extractMavenPropertyName(String propName)
Extract from a Maven property which is in the form ${name} the name.
|
static File |
findBinaryFileInUserPath(String binaryName)
Find a binary in user's path
|
static String |
firstRegistryOf(String... checkFirst)
Return the first non-null registry given.
|
static String |
fixupPath(String path)
Fix path on Windows machines, i.e.
|
static String |
formatDurationTill(long start)
Calculate the duration between now and the given time
|
static String |
getEnv(String variableName)
Return the value of the given environment variable or null if it is not set.
|
static String |
getEnvVarOrSystemProperty(String varName,
String defaultValue) |
static String |
getEnvVarOrSystemProperty(String envVarName,
String systemProperty,
String defaultValue) |
static String |
getProcessorArchitecture()
Utility method to get underlying processor architecture
|
static String |
getProperty(String propertyName) |
static File |
getUserHome()
Return a
File pointing to the user's home directory. |
static boolean |
greaterOrEqualsVersion(String versionA,
String versionB)
Check whether the first given API version is larger or equals the second given version
|
static boolean |
isMacOs()
Is underlying Operating System from Mac OS family.
|
static boolean |
isWindows() |
static Date |
loadTimestamp(File tsFile) |
static void |
overrideEnvGetter(UnaryOperator<String> getter)
Don't use in production code.
|
static void |
overridePropertyGetter(UnaryOperator<String> propsGetter) |
static File |
prepareAbsoluteOutputDirPath(String outputDirectory,
String projectBaseDir,
String dir,
String path) |
static File |
prepareAbsoluteSourceDirPath(String sourceDirectory,
String projectBaseDir,
String path) |
static List<String> |
removeEmptyEntries(List<String> input)
Remove empty members of a list.
|
static List<String> |
splitAtCommasAndTrim(Iterable<String> input)
Split each element of an Iterable;<String;> at commas.
|
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.
|
static String[] |
splitOnSpaceWithEscape(String toSplit) |
static void |
storeTimestamp(File tsFile,
Date buildDate)
Create a timestamp file holding time in epoch seconds.
|
static String |
stringJoin(List list,
String separator)
Join a list of objects to a string with a given separator by calling Object.toString() on the elements.
|
public static final String MAVEN_PROPERTY_REGEXP
public static final String DOCKER_HTTP_PORT
public static final String PROPERTY_COMBINE_POLICY_SUFFIX
public static void overrideEnvGetter(UnaryOperator<String> getter)
getter - public static void overridePropertyGetter(UnaryOperator<String> propsGetter)
public static String extractLargerVersion(String versionA, String versionB)
If either version is null, the other version is returned (which can be null as well)
versionA - first version numberversionB - second version numberpublic static boolean greaterOrEqualsVersion(String versionA, String versionB)
versionA - first version to check againstversionB - the second versionpublic static List<String[]> splitOnLastColon(List<String> listToSplit)
listToSplit - list of strings to split@Nonnull public static List<String> removeEmptyEntries(@Nullable List<String> input)
input - A list of String@Nonnull public static List<String> splitAtCommasAndTrim(Iterable<String> input)
input - Iterable over strings.public static String stringJoin(List list, String separator)
list - to joinseparator - separator to usepublic static Map<String,String> extractFromPropertiesAsMap(String prefix, Properties properties)
NOTE: If key is "._combine" (PROPERTY_COMBINE_POLICY_SUFFIX) it is ignored! This is reserved for combine policy tweaking.
prefix - prefix which specifies the part which should be extracted as mapproperties - properties to extract frompublic static List<String> extractFromPropertiesAsList(String prefix, Properties properties)
NOTE: If suffix/index is "._combine" (PROPERTY_COMBINE_POLICY_SUFFIX) it is ignored!
This is reserved for combine policy tweaking.
prefix - for selecting the properties from which the list should be extractedproperties - properties from which to extract frompublic static String extractMavenPropertyName(String propName)
propName - property name to extractpublic static String fixupPath(String path)
path - path to fixpublic static String formatDurationTill(long start)
Taken mostly from http://stackoverflow.com/a/5062810/207604 . Kudos to @dblevins
start - starting time (in milliseconds)public static String firstRegistryOf(String... checkFirst)
checkFirst - list of registries to checkpublic static File prepareAbsoluteOutputDirPath(String outputDirectory, String projectBaseDir, String dir, String path)
public static File prepareAbsoluteSourceDirPath(String sourceDirectory, String projectBaseDir, String path)
public static void storeTimestamp(File tsFile, Date buildDate) throws IOException
tsFile - the File to store the timestamp in.buildDate - the Date of the timestamp.IOException - if the timestamp cannot be created.public static Date loadTimestamp(File tsFile) throws IOException
IOExceptionpublic static boolean isWindows()
public static File getUserHome()
File pointing to the user's home directory.public static String getEnv(String variableName)
variableName - name of the environment variable.public static String getEnvVarOrSystemProperty(String varName, String defaultValue)
public static String getEnvVarOrSystemProperty(String envVarName, String systemProperty, String defaultValue)
public static String getProcessorArchitecture()
public static boolean isMacOs()
Copyright © 2024. All rights reserved.