Package pl.project13.core
Class GitDataProvider
java.lang.Object
pl.project13.core.GitDataProvider
- All Implemented Interfaces:
GitProvider
- Direct Known Subclasses:
JGitProvider,NativeGitProvider
An abstract Interface that dictates what functionality a
GitProvider needs to fullfill.
As of now this project implements two variants of a GitProvider.
Namely NativeGitProvider which uses the native git binaries and
JGitProvider which uses a java git implementation (jgit).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceRepresents a supplier of results that is allowed to throw aGitCommitIdExecutionException. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThecommit abbreviation lengthprotected CommitIdGenerationModeThegit commit id generation mode.protected StringThedate formatfor all generated properties.protected StringThedate format time zonefor all generated properties.protected StringAllow to tell the plugin what commit should be used as reference to generate the properties from.Can be used to exclude certain properties from being emitted (e.g. filter out properties that you *don't* want to expose).protected GitDescribeConfigTheGitDescribeConfig.Can be used to include only certain properties into the resulting file (e.g. include only properties that you *want* to expose).protected final LogInterfaceLogging provider which will be used to log events.protected booleanWhen set totrue, the plugin will not try to contact any remote repositories.protected StringTheprefixused for all generated properties.protected booleanWhen set totruethis plugin will try to use the branch name from build environment. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor to encapsulates all references required to dertermine all git-data. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringdetermineBranchName(Map<String, String> env) If running within Jenkins/Hudson, honor the branch name passed via GIT_BRANCH env var.protected SimpleDateFormatprotected voidloadGitData(String evaluateOnCommit, Map<String, String> env, Properties properties) Main function that will attempt to load the desired properties from the git repository.protected voidloadShortDescribe(Properties properties) protected voidmaybePut(Properties properties, String key, GitDataProvider.SupplierEx<String> value) static <T> GitDataProvider.SupplierEx<T>memoize(GitDataProvider.SupplierEx<T> delegate) setAbbrevLength(int abbrevLength) Sets thecommit abbreviation lengthfor theGitProvidersetCommitIdGenerationMode(CommitIdGenerationMode commitIdGenerationMode) Sets thegit commit id generation modefor theGitProvidersetDateFormat(String dateFormat) Sets thedate formatfor all generated properties for theGitProvidersetDateFormatTimeZone(String dateFormatTimeZone) Sets thedate format time zonefor all generated properties for theGitProvidersetExcludeProperties(List<String> excludeProperties) Can be used to exclude certain properties from being emitted (e.g. filter out properties that you *don't* want to expose).setGitDescribe(GitDescribeConfig gitDescribe) Sets theGitDescribeConfigfor theGitProvidersetIncludeOnlyProperties(List<String> includeOnlyProperties) Can be used to include only certain properties into the resulting file (e.g. include only properties that you *want* to expose).setOffline(boolean offline) When set totrue, the plugin will not try to contact any remote repositories.setPrefixDot(String prefixDot) Sets theprefixused for all generated properties for theGitProvidersetUseBranchNameFromBuildEnvironment(boolean useBranchNameFromBuildEnvironment) Sets the Indicator if the branch name should be obtained from the build environment, or by the plugin.protected StringstripCredentialsFromOriginUrl(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, waitMethods 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, getTag, getTags, getTotalCommitCount, init, isDirty, prepareGitToExtractMoreDetailedRepoInformation
-
Field Details
-
log
Logging provider which will be used to log events. -
prefixDot
Theprefixused for all generated properties. -
abbrevLength
protected int abbrevLengthThecommit abbreviation length -
dateFormat
Thedate formatfor all generated properties. -
dateFormatTimeZone
Thedate format time zonefor all generated properties. -
gitDescribe
TheGitDescribeConfig. -
commitIdGenerationMode
Thegit commit id generation mode. -
evaluateOnCommit
Allow to tell the plugin what commit should be used as reference to generate the properties from. Defaults toHEAD. -
useBranchNameFromBuildEnvironment
protected boolean useBranchNameFromBuildEnvironmentWhen set totruethis plugin will try to use the branch name from build environment. Set tofalseto use JGit/GIT to get current branch name which can be useful when using the JGitflow maven plugin. See https://github.com/git-commit-id/git-commit-id-maven-plugin/issues/24 -
excludeProperties
Can be used to exclude certain properties from being emitted (e.g. filter out properties that you *don't* want to expose). May be useful when you want to hidegit.remote.origin.url(maybe because it contains your repo password?), or the email of the committer etc. -
includeOnlyProperties
Can be used to include only certain properties into the resulting file (e.g. include only properties that you *want* to expose). This feature was implemented to avoid big exclude properties tag when we only want very few specific properties. The inclusion rules, will be overruled by the exclude rules (e.g. you can write an inclusion rule that applies for multiple properties and then exclude a subset of them). -
offline
protected boolean offlineWhen set totrue, the plugin will not try to contact any remote repositories. Any operations will only use the local state of the repo. If set tofalse, it will executegit fetchoperations e.g. to determine theaheadandbehindbranch information.
-
-
Constructor Details
-
GitDataProvider
Constructor to encapsulates all references required to dertermine all git-data.- Parameters:
log- logging provider which will be used to log events
-
-
Method Details
-
setGitDescribe
Sets theGitDescribeConfigfor theGitProvider- Parameters:
gitDescribe- TheGitDescribeConfig- Returns:
- The
GitProviderwith the correspondingGitDescribeConfig.
-
setPrefixDot
Sets theprefixused for all generated properties for theGitProvider- Parameters:
prefixDot- Theprefixused for all generated properties- Returns:
- The
GitProviderwith the correspondingprefix.
-
setAbbrevLength
Sets thecommit abbreviation lengthfor theGitProvider- Parameters:
abbrevLength- Thecommit abbreviation length- Returns:
- The
GitProviderwith the correspondingcommit abbreviation length.
-
setDateFormat
Sets thedate formatfor all generated properties for theGitProvider- Parameters:
dateFormat- Thedate formatfor all generated properties.- Returns:
- The
GitProviderwith the correspondingdate format.
-
setCommitIdGenerationMode
Sets thegit commit id generation modefor theGitProvider- Parameters:
commitIdGenerationMode- Thegit commit id generation mode- Returns:
- The
GitProviderwith the correspondinggit commit id generation mode.
-
setDateFormatTimeZone
Sets thedate format time zonefor all generated properties for theGitProvider- Parameters:
dateFormatTimeZone- Thedate format time zonefor all generated properties.- Returns:
- The
GitProviderwith the correspondingdate format time zone.
-
setUseBranchNameFromBuildEnvironment
public GitDataProvider setUseBranchNameFromBuildEnvironment(boolean useBranchNameFromBuildEnvironment) Sets the Indicator if the branch name should be obtained from the build environment, or by the plugin.- Parameters:
useBranchNameFromBuildEnvironment- When set totruethis plugin will try to use the branch name from build environment. Set tofalseto use JGit/GIT to get current branch name which can be useful when using the JGitflow maven plugin. See https://github.com/git-commit-id/git-commit-id-maven-plugin/issues/24- Returns:
- The
GitProviderwith the corresponding Indicator set.
-
setExcludeProperties
Can be used to exclude certain properties from being emitted (e.g. filter out properties that you *don't* want to expose). May be useful when you want to hidegit.remote.origin.url(maybe because it contains your repo password?), or the email of the committer etc.- Parameters:
excludeProperties- The properties that shall be excluded from generation.- Returns:
- The
GitProviderwith the correspondingproperties exclusion list.
-
setIncludeOnlyProperties
Can be used to include only certain properties into the resulting file (e.g. include only properties that you *want* to expose). This feature was implemented to avoid big exclude properties tag when we only want very few specific properties. The inclusion rules, will be overruled by the exclude rules (e.g. you can write an inclusion rule that applies for multiple properties and then exclude a subset of them).- Parameters:
includeOnlyProperties- The properties that shall only be included in the generation.- Returns:
- The
GitProviderwith the correspondingproperties inclusion only list.
-
setOffline
When set totrue, the plugin will not try to contact any remote repositories. Any operations will only use the local state of the repo. If set tofalse, it will executegit fetchoperations e.g. to determine theaheadandbehindbranch information.- Parameters:
offline- Indicator if the plugin should operate inofflineoronline-mode.- Returns:
- The
GitProviderwith the corresponding Indicator set.
-
loadGitData
protected void loadGitData(@Nonnull String evaluateOnCommit, @Nonnull Map<String, String> env, @Nonnull Properties properties) throws GitCommitIdExecutionExceptionMain function that will attempt to load the desired properties from the git repository.- Parameters:
evaluateOnCommit- The commit that should be used as reference to generate the properties from. Defaults toHEAD.env- unmodifiable string map view of the current system environmentSystem.getenv(java.lang.String).properties- The Properties-Set that should be enriched by the generated one.- Throws:
GitCommitIdExecutionException- In case any problem occurred during loading of the properties from the git repository.
-
loadShortDescribe
protected void loadShortDescribe(@Nonnull Properties properties) throws GitCommitIdExecutionException - Throws:
GitCommitIdExecutionException
-
determineBranchName
protected String determineBranchName(@Nonnull Map<String, 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- unmodifiable string map view of the current system environmentSystem.getenv(java.lang.String).- Returns:
- results of getBranchName() or, if in Jenkins/Hudson, value of GIT_BRANCH
- Throws:
GitCommitIdExecutionException- the branch name could not be determined
-
getSimpleDateFormatWithTimeZone
-
maybePut
protected void maybePut(@Nonnull Properties properties, String key, GitDataProvider.SupplierEx<String> value) throws GitCommitIdExecutionException - Throws:
GitCommitIdExecutionException
-
memoize
-
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
-