Package pl.project13.core
Class GitDataProvider
- java.lang.Object
-
- pl.project13.core.GitDataProvider
-
- All Implemented Interfaces:
GitProvider
- Direct Known Subclasses:
JGitProvider,NativeGitProvider
public abstract class GitDataProvider extends java.lang.Object implements GitProvider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceGitDataProvider.SupplierEx<T>
-
Field Summary
Fields Modifier and Type Field Description protected intabbrevLengthprotected CommitIdGenerationModecommitIdGenerationModeprotected java.lang.StringdateFormatprotected java.lang.StringdateFormatTimeZoneprotected java.lang.StringevaluateOnCommitprotected java.util.List<java.lang.String>excludePropertiesprotected GitDescribeConfiggitDescribeprotected java.util.List<java.lang.String>includeOnlyPropertiesprotected LoggerBridgelogprotected booleanofflineprotected java.lang.StringprefixDotprotected booleanuseBranchNameFromBuildEnvironment
-
Constructor Summary
Constructors Constructor Description GitDataProvider(LoggerBridge log)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringdetermineBranchName(java.util.Map<java.lang.String,java.lang.String> env)If running within Jenkins/Hudson, honor the branch name passed via GIT_BRANCH env var.protected java.text.SimpleDateFormatgetSimpleDateFormatWithTimeZone()voidloadGitData(java.lang.String evaluateOnCommit, java.util.Properties properties)protected voidloadShortDescribe(java.util.Properties properties)protected voidmaybePut(java.util.Properties properties, java.lang.String key, GitDataProvider.SupplierEx<java.lang.String> value)static <T> GitDataProvider.SupplierEx<T>memoize(GitDataProvider.SupplierEx<T> delegate)GitDataProvidersetAbbrevLength(int abbrevLength)GitDataProvidersetCommitIdGenerationMode(CommitIdGenerationMode commitIdGenerationMode)GitDataProvidersetDateFormat(java.lang.String dateFormat)GitDataProvidersetDateFormatTimeZone(java.lang.String dateFormatTimeZone)GitDataProvidersetExcludeProperties(java.util.List<java.lang.String> excludeProperties)GitDataProvidersetGitDescribe(GitDescribeConfig gitDescribe)GitDataProvidersetIncludeOnlyProperties(java.util.List<java.lang.String> includeOnlyProperties)GitDataProvidersetOffline(boolean offline)GitDataProvidersetPrefixDot(java.lang.String prefixDot)GitDataProvidersetUseBranchNameFromBuildEnvironment(boolean useBranchNameFromBuildEnvironment)protected java.lang.StringstripCredentialsFromOriginUrl(java.lang.String gitRemoteString)If the git remote value is a URI and contains a user info component, strip the password from it if it exists.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface pl.project13.core.GitProvider
finalCleanUp, getAbbrevCommitId, getAheadBehind, getBranchName, getBuildAuthorEmail, getBuildAuthorName, getClosestTagCommitCount, getClosestTagName, getCommitAuthorEmail, getCommitAuthorName, getCommitAuthorTime, getCommitCommitterTime, getCommitId, getCommitMessageFull, getCommitMessageShort, getCommitTime, getGitDescribe, getRemoteOriginUrl, getTags, getTotalCommitCount, init, isDirty, prepareGitToExtractMoreDetailedRepoInformation
-
-
-
-
Field Detail
-
log
@Nonnull protected final LoggerBridge log
-
prefixDot
protected java.lang.String prefixDot
-
abbrevLength
protected int abbrevLength
-
dateFormat
protected java.lang.String dateFormat
-
dateFormatTimeZone
protected java.lang.String dateFormatTimeZone
-
gitDescribe
protected GitDescribeConfig gitDescribe
-
commitIdGenerationMode
protected CommitIdGenerationMode commitIdGenerationMode
-
evaluateOnCommit
protected java.lang.String evaluateOnCommit
-
useBranchNameFromBuildEnvironment
protected boolean useBranchNameFromBuildEnvironment
-
excludeProperties
protected java.util.List<java.lang.String> excludeProperties
-
includeOnlyProperties
protected java.util.List<java.lang.String> includeOnlyProperties
-
offline
protected boolean offline
-
-
Constructor Detail
-
GitDataProvider
public GitDataProvider(@Nonnull LoggerBridge log)
-
-
Method Detail
-
setGitDescribe
public GitDataProvider setGitDescribe(GitDescribeConfig gitDescribe)
-
setPrefixDot
public GitDataProvider setPrefixDot(java.lang.String prefixDot)
-
setAbbrevLength
public GitDataProvider setAbbrevLength(int abbrevLength)
-
setDateFormat
public GitDataProvider setDateFormat(java.lang.String dateFormat)
-
setCommitIdGenerationMode
public GitDataProvider setCommitIdGenerationMode(CommitIdGenerationMode commitIdGenerationMode)
-
setDateFormatTimeZone
public GitDataProvider setDateFormatTimeZone(java.lang.String dateFormatTimeZone)
-
setUseBranchNameFromBuildEnvironment
public GitDataProvider setUseBranchNameFromBuildEnvironment(boolean useBranchNameFromBuildEnvironment)
-
setExcludeProperties
public GitDataProvider setExcludeProperties(java.util.List<java.lang.String> excludeProperties)
-
setIncludeOnlyProperties
public GitDataProvider setIncludeOnlyProperties(java.util.List<java.lang.String> includeOnlyProperties)
-
setOffline
public GitDataProvider setOffline(boolean offline)
-
loadGitData
public void loadGitData(@Nonnull java.lang.String evaluateOnCommit, @Nonnull java.util.Properties properties) throws GitCommitIdExecutionException- Throws:
GitCommitIdExecutionException
-
loadShortDescribe
protected void loadShortDescribe(@Nonnull java.util.Properties properties) throws GitCommitIdExecutionException- Throws:
GitCommitIdExecutionException
-
determineBranchName
protected java.lang.String determineBranchName(@Nonnull java.util.Map<java.lang.String,java.lang.String> env) throws GitCommitIdExecutionExceptionIf running within Jenkins/Hudson, honor the branch name passed via GIT_BRANCH env var. This is necessary because Jenkins/Hudson always invoke build in a detached head state.- Parameters:
env- environment settings- Returns:
- results of getBranchName() or, if in Jenkins/Hudson, value of GIT_BRANCH
- Throws:
GitCommitIdExecutionException- the branch name could not be determined
-
getSimpleDateFormatWithTimeZone
protected java.text.SimpleDateFormat getSimpleDateFormatWithTimeZone()
-
maybePut
protected void maybePut(@Nonnull java.util.Properties properties, java.lang.String key, GitDataProvider.SupplierEx<java.lang.String> value) throws GitCommitIdExecutionException- Throws:
GitCommitIdExecutionException
-
memoize
public static <T> GitDataProvider.SupplierEx<T> memoize(GitDataProvider.SupplierEx<T> delegate)
-
stripCredentialsFromOriginUrl
protected java.lang.String stripCredentialsFromOriginUrl(java.lang.String gitRemoteString) throws GitCommitIdExecutionExceptionIf the git remote value is a URI and contains a user info component, strip the password from it if it exists. Note that this method will return an empty string if any failure occurred, while stripping the password from the credentials. This merely serves as save-guard to avoid any potential password exposure inside generated properties. This method further operates on the assumption that a valid URL schema follows the rules outlined in RFC-2396 in section "3.2.2. Server-based Naming Authority" which declares the following as valid URL schema:<userinfo>@<host>:<port>
The "userinfo" part is declared in the same section allowing the following pattern:userinfo = *( unreserved | escaped | ";" | ":" | "&" | "=" | "+" | "$" | "," )The "unreserved" part is declared in section "2.3. Unreserved Characters" as the following:unreserved = alphanum | mark mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" alphanum = alpha | digit digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" alpha = lowalpha | upalpha lowalpha = "a" | "b" | "c" | ... | "x" | "y" | "z" upalpha = "A" | "B" | "C" | ... | "X" | "Y" | "Z"- Parameters:
gitRemoteString- The value of the git remote- Returns:
- returns the gitRemoteUri with stripped password (might be used in http or https)
- Throws:
GitCommitIdExecutionException- Exception when URI is invalid
-
-