Package org.vafer.jdeb.utils
Class Utils
java.lang.Object
org.vafer.jdeb.utils.Utils
Simple utils functions.
ATTENTION: don't use outside of jdeb
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringconvertToDebianVersion(String version, boolean apply, String envName, String template, Date timestamp)Convert the project version to a version suitable for a Debian package.static intcopy(InputStream pInput, OutputStream pOutput)static StringdefaultString(String str, String fallback)Return fallback if first string is null or emptystatic Collection<String>Get the known locations where the secure keyring can be located.static FileTries to guess location of the user secure keyring using various heuristics.static booleanisBlank(CharSequence cs)Check if a CharSequence is whitespace, empty ("") or null.static booleanisNullOrEmpty(String str)Returns true if string is null or empty.static StringjoinLocalPath(String... paths)static StringjoinUnixPath(String... paths)static StringExtracts value from map if given value is null.static StringConstruct new path by replacing file directory part.static StringreplaceVariables(VariableResolver pResolver, String pExpression, String pOpen, String pClose)Substitute the variables in the given expression with the values from the resolverstatic Stringstatic Stringstatic StringtoHex(byte[] bytes)static byte[]toUnixLineEndings(InputStream input)Replaces new line delimiters in the input stream with the Unix line feed.
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
copy
- Throws:
IOException
-
toHex
-
stripPath
-
joinUnixPath
-
joinLocalPath
-
stripLeadingSlash
-
replaceVariables
public static String replaceVariables(VariableResolver pResolver, String pExpression, String pOpen, String pClose)Substitute the variables in the given expression with the values from the resolver- Parameters:
pResolver-pExpression-
-
toUnixLineEndings
Replaces new line delimiters in the input stream with the Unix line feed.- Parameters:
input-- Throws:
IOException
-
convertToDebianVersion
public static String convertToDebianVersion(String version, boolean apply, String envName, String template, Date timestamp)Convert the project version to a version suitable for a Debian package. -SNAPSHOT suffixes are replaced with a timestamp (~yyyyMMddHHmmss). The separator before a rc, alpha or beta version is replaced with '~' such that the version is always ordered before the final or GA release.- Parameters:
version- the project version to convert to a Debian package versiontemplate- the template used to replace -SNAPSHOT, the timestamp format is in brackets, the rest of the string is preserved (prefix[yyMMdd]suffix -> prefix151230suffix)timestamp- the UTC date used as the timestamp to replace the SNAPSHOT suffix.
-
movePath
Construct new path by replacing file directory part. No files are actually modified.- Parameters:
file- path to movetarget- new path directory
-
lookupIfEmpty
Extracts value from map if given value is null.- Parameters:
value- current valueprops- properties to extract value fromkey- property name to extract- Returns:
- initial value or value extracted from map
-
getKnownPGPSecureRingLocations
Get the known locations where the secure keyring can be located. Looks through known locations of the GNU PG secure keyring.- Returns:
- The location of the PGP secure keyring if it was found, null otherwise
-
guessKeyRingFile
Tries to guess location of the user secure keyring using various heuristics.- Returns:
- path to the keyring file
- Throws:
FileNotFoundException- if no keyring file found
-
isNullOrEmpty
Returns true if string is null or empty. -
defaultString
Return fallback if first string is null or empty -
isBlank
Check if a CharSequence is whitespace, empty ("") or null.StringUtils.isBlank(null) = true StringUtils.isBlank("") = true StringUtils.isBlank(" ") = true StringUtils.isBlank("bob") = false StringUtils.isBlank(" bob ") = false- Parameters:
cs- the CharSequence to check, may be null- Returns:
trueif the CharSequence is null, empty or whitespace
-