Package io.fabric8.maven.docker.util
Class EnvUtil
- java.lang.Object
-
- io.fabric8.maven.docker.util.EnvUtil
-
public class EnvUtil extends Object
Utility class for various (loosely related) environment related tasks.- Since:
- 04.04.14
- Author:
- roland
-
-
Field Summary
Fields Modifier and Type Field Description static StringDOCKER_HTTP_PORTstatic StringMAVEN_PROPERTY_REGEXPstatic StringPROPERTY_COMBINE_POLICY_SUFFIX
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringconvertTcpToHttpUrl(String connect)static StringensureRegistryHttpUrl(String registry)static List<String>extractFromPropertiesAsList(String prefix, Properties properties)Extract from given properties a list of string values.static List<Properties>extractFromPropertiesAsListOfProperties(String prefix, Properties properties)static Map<String,String>extractFromPropertiesAsMap(String prefix, Properties properties)Extract part of given properties as a map.static StringextractLargerVersion(String versionA, String versionB)Compare to version strings and return the larger version strings.static StringextractMavenPropertyName(String propName)Extract from a Maven property which is in the form ${name} the name.static StringfirstRegistryOf(String... checkFirst)Return the first non null registry given.static StringfixupPath(String path)Fix path on Windows machines, i.e.static StringformatDurationTill(long start)Calculate the duration between now and the given time Taken mostly from http://stackoverflow.com/a/5062810/207604 .static PropertiesgetPropertiesWithSystemOverrides(org.apache.maven.project.MavenProject project)Return all properties in Maven project, merged with all System properties (-D flags sent to Maven).static StringgetUserHome()Get User's HOME directory pathstatic booleangreaterOrEqualsVersion(String versionA, String versionB)Check whether the first given API version is larger or equals the second given versionstatic booleanisMaven350OrLater(org.apache.maven.execution.MavenSession mavenSession)static booleanisWindows()static DateloadTimestamp(File tsFile)static FileprepareAbsoluteOutputDirPath(MojoParameters params, String dir, String path)static FileprepareAbsoluteSourceDirPath(MojoParameters params, 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 Iterableat 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 voidstoreTimestamp(File tsFile, Date buildDate)static StringstringJoin(List list, String separator)Join a list of objects to a string with a given separator by calling Object.toString() on the elements.
-
-
-
Field Detail
-
MAVEN_PROPERTY_REGEXP
public static final String MAVEN_PROPERTY_REGEXP
- See Also:
- Constant Field Values
-
DOCKER_HTTP_PORT
public static final String DOCKER_HTTP_PORT
- See Also:
- Constant Field Values
-
PROPERTY_COMBINE_POLICY_SUFFIX
public static final String PROPERTY_COMBINE_POLICY_SUFFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
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 isnull, the other version is returned (which can be null as well)- Parameters:
versionA- first version numberversionB- 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 againstversionB- 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 Iterableat commas. - Parameters:
input- Iterable over strings.- Returns:
- An Iterable over string which breaks down each input element at comma boundaries
-
stringJoin
public 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.- Parameters:
list- to joinseparator- separator to use- Returns:
- the joined string.
-
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 mapproperties- 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 extractedproperties- 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.
-
prepareAbsoluteOutputDirPath
public static File prepareAbsoluteOutputDirPath(MojoParameters params, String dir, String path)
-
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
-
loadTimestamp
public static Date loadTimestamp(File tsFile) throws IOException
- Throws:
IOException
-
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
-
-