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 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 StringdateFormatprotected StringdateFormatTimeZoneprotected StringevaluateOnCommitprotected List<String>excludePropertiesprotected GitDescribeConfiggitDescribeprotected List<String>includeOnlyPropertiesprotected LoggerBridgelogprotected booleanofflineprotected StringprefixDotprotected booleanuseBranchNameFromBuildEnvironment
-
Constructor Summary
Constructors Constructor Description GitDataProvider(LoggerBridge log)
-
Method Summary
-
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 String prefixDot
-
abbrevLength
protected int abbrevLength
-
dateFormat
protected String dateFormat
-
dateFormatTimeZone
protected String dateFormatTimeZone
-
gitDescribe
protected GitDescribeConfig gitDescribe
-
commitIdGenerationMode
protected CommitIdGenerationMode commitIdGenerationMode
-
evaluateOnCommit
protected String evaluateOnCommit
-
useBranchNameFromBuildEnvironment
protected boolean useBranchNameFromBuildEnvironment
-
offline
protected boolean offline
-
-
Constructor Detail
-
GitDataProvider
public GitDataProvider(@Nonnull LoggerBridge log)
-
-
Method Detail
-
setGitDescribe
public GitDataProvider setGitDescribe(GitDescribeConfig gitDescribe)
-
setPrefixDot
public GitDataProvider setPrefixDot(String prefixDot)
-
setAbbrevLength
public GitDataProvider setAbbrevLength(int abbrevLength)
-
setDateFormat
public GitDataProvider setDateFormat(String dateFormat)
-
setCommitIdGenerationMode
public GitDataProvider setCommitIdGenerationMode(CommitIdGenerationMode commitIdGenerationMode)
-
setDateFormatTimeZone
public GitDataProvider setDateFormatTimeZone(String dateFormatTimeZone)
-
setUseBranchNameFromBuildEnvironment
public GitDataProvider setUseBranchNameFromBuildEnvironment(boolean useBranchNameFromBuildEnvironment)
-
setExcludeProperties
public GitDataProvider setExcludeProperties(List<String> excludeProperties)
-
setIncludeOnlyProperties
public GitDataProvider setIncludeOnlyProperties(List<String> includeOnlyProperties)
-
setOffline
public GitDataProvider setOffline(boolean offline)
-
loadGitData
public void loadGitData(@Nonnull String evaluateOnCommit, @Nonnull Properties properties) throws GitCommitIdExecutionException
- Throws:
GitCommitIdExecutionException
-
loadShortDescribe
protected void loadShortDescribe(@Nonnull Properties properties) throws GitCommitIdExecutionException
- Throws:
GitCommitIdExecutionException
-
determineBranchName
protected String determineBranchName(@Nonnull Map<String,String> env) throws GitCommitIdExecutionException
If 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 SimpleDateFormat getSimpleDateFormatWithTimeZone()
-
maybePut
protected void maybePut(@Nonnull Properties properties, String key, GitDataProvider.SupplierEx<String> value) throws GitCommitIdExecutionException
- Throws:
GitCommitIdExecutionException
-
memoize
public static <T> GitDataProvider.SupplierEx<T> memoize(GitDataProvider.SupplierEx<T> delegate)
-
stripCredentialsFromOriginUrl
protected String stripCredentialsFromOriginUrl(String gitRemoteString) throws GitCommitIdExecutionException
If 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
-
-