1
1
package datadog .trace .api .git ;
2
2
3
- import static datadog .trace .api .git .GitInfo .DD_GIT_BRANCH ;
4
- import static datadog .trace .api .git .GitInfo .DD_GIT_COMMIT_AUTHOR_DATE ;
5
- import static datadog .trace .api .git .GitInfo .DD_GIT_COMMIT_AUTHOR_EMAIL ;
6
- import static datadog .trace .api .git .GitInfo .DD_GIT_COMMIT_AUTHOR_NAME ;
7
- import static datadog .trace .api .git .GitInfo .DD_GIT_COMMIT_COMMITTER_DATE ;
8
- import static datadog .trace .api .git .GitInfo .DD_GIT_COMMIT_COMMITTER_EMAIL ;
9
- import static datadog .trace .api .git .GitInfo .DD_GIT_COMMIT_COMMITTER_NAME ;
10
- import static datadog .trace .api .git .GitInfo .DD_GIT_COMMIT_MESSAGE ;
11
- import static datadog .trace .api .git .GitInfo .DD_GIT_COMMIT_SHA ;
12
- import static datadog .trace .api .git .GitInfo .DD_GIT_REPOSITORY_URL ;
13
- import static datadog .trace .api .git .GitInfo .DD_GIT_TAG ;
14
-
15
3
import datadog .trace .api .Config ;
16
- import datadog .trace .api .ConfigCollector ;
17
- import datadog .trace .api .ConfigOrigin ;
18
4
import datadog .trace .api .config .GeneralConfig ;
5
+ import datadog .trace .bootstrap .config .provider .ConfigProvider ;
19
6
import datadog .trace .bootstrap .instrumentation .api .Tags ;
7
+ import datadog .trace .util .Strings ;
20
8
import javax .annotation .Nullable ;
21
9
import org .slf4j .Logger ;
22
10
import org .slf4j .LoggerFactory ;
23
11
24
12
public class UserSuppliedGitInfoBuilder implements GitInfoBuilder {
25
13
14
+ public static final String DD_GIT_REPOSITORY_URL = "git.repository.url" ;
15
+ public static final String DD_GIT_BRANCH = "git.branch" ;
16
+ public static final String DD_GIT_TAG = "git.tag" ;
17
+ public static final String DD_GIT_COMMIT_SHA = "git.commit.sha" ;
18
+ public static final String DD_GIT_COMMIT_MESSAGE = "git.commit.message" ;
19
+ public static final String DD_GIT_COMMIT_AUTHOR_NAME = "git.commit.author.name" ;
20
+ public static final String DD_GIT_COMMIT_AUTHOR_EMAIL = "git.commit.author.email" ;
21
+ public static final String DD_GIT_COMMIT_AUTHOR_DATE = "git.commit.author.date" ;
22
+ public static final String DD_GIT_COMMIT_COMMITTER_NAME = "git.commit.committer.name" ;
23
+ public static final String DD_GIT_COMMIT_COMMITTER_EMAIL = "git.commit.committer.email" ;
24
+ public static final String DD_GIT_COMMIT_COMMITTER_DATE = "git.commit.committer.date" ;
26
25
private static final Logger log = LoggerFactory .getLogger (UserSuppliedGitInfoBuilder .class );
27
26
28
27
@ Override
29
28
public GitInfo build (@ Nullable String repositoryPath ) {
30
- String gitRepositoryUrl = System .getenv (DD_GIT_REPOSITORY_URL );
29
+ ConfigProvider configProvider = ConfigProvider .getInstance ();
30
+
31
+ String gitRepositoryUrl = configProvider .getString (DD_GIT_REPOSITORY_URL );
31
32
if (gitRepositoryUrl == null ) {
32
33
gitRepositoryUrl = Config .get ().getGlobalTags ().get (Tags .GIT_REPOSITORY_URL );
33
34
}
@@ -36,9 +37,9 @@ public GitInfo build(@Nullable String repositoryPath) {
36
37
// using the value returned by the CI Provider, so
37
38
// we need to normalize the value. Also, it can contain
38
39
// the tag (e.g. origin/tags/0.1.0)
39
- String gitTag = System . getenv (DD_GIT_TAG );
40
+ String gitTag = configProvider . getString (DD_GIT_TAG );
40
41
String gitBranch = null ;
41
- final String gitBranchOrTag = System . getenv (DD_GIT_BRANCH );
42
+ final String gitBranchOrTag = configProvider . getString (DD_GIT_BRANCH );
42
43
if (gitBranchOrTag != null ) {
43
44
if (!GitUtils .isTagReference (gitBranchOrTag )) {
44
45
gitBranch = GitUtils .normalizeBranch (gitBranchOrTag );
@@ -47,21 +48,18 @@ public GitInfo build(@Nullable String repositoryPath) {
47
48
}
48
49
}
49
50
50
- String gitCommitSha = System . getenv (DD_GIT_COMMIT_SHA );
51
+ String gitCommitSha = configProvider . getString (DD_GIT_COMMIT_SHA );
51
52
if (gitCommitSha == null ) {
52
53
gitCommitSha = Config .get ().getGlobalTags ().get (Tags .GIT_COMMIT_SHA );
53
54
}
54
55
55
- ConfigCollector .get ().put (DD_GIT_REPOSITORY_URL , gitRepositoryUrl , ConfigOrigin .ENV );
56
- ConfigCollector .get ().put (DD_GIT_COMMIT_SHA , gitCommitSha , ConfigOrigin .ENV );
57
-
58
- final String gitCommitMessage = System .getenv (DD_GIT_COMMIT_MESSAGE );
59
- final String gitCommitAuthorName = System .getenv (DD_GIT_COMMIT_AUTHOR_NAME );
60
- final String gitCommitAuthorEmail = System .getenv (DD_GIT_COMMIT_AUTHOR_EMAIL );
61
- final String gitCommitAuthorDate = System .getenv (DD_GIT_COMMIT_AUTHOR_DATE );
62
- final String gitCommitCommitterName = System .getenv (DD_GIT_COMMIT_COMMITTER_NAME );
63
- final String gitCommitCommitterEmail = System .getenv (DD_GIT_COMMIT_COMMITTER_EMAIL );
64
- final String gitCommitCommitterDate = System .getenv (DD_GIT_COMMIT_COMMITTER_DATE );
56
+ final String gitCommitMessage = configProvider .getString (DD_GIT_COMMIT_MESSAGE );
57
+ final String gitCommitAuthorName = configProvider .getString (DD_GIT_COMMIT_AUTHOR_NAME );
58
+ final String gitCommitAuthorEmail = configProvider .getString (DD_GIT_COMMIT_AUTHOR_EMAIL );
59
+ final String gitCommitAuthorDate = configProvider .getString (DD_GIT_COMMIT_AUTHOR_DATE );
60
+ final String gitCommitCommitterName = configProvider .getString (DD_GIT_COMMIT_COMMITTER_NAME );
61
+ final String gitCommitCommitterEmail = configProvider .getString (DD_GIT_COMMIT_COMMITTER_EMAIL );
62
+ final String gitCommitCommitterDate = configProvider .getString (DD_GIT_COMMIT_COMMITTER_DATE );
65
63
66
64
GitInfo gitInfo =
67
65
new GitInfo (
@@ -82,8 +80,8 @@ public GitInfo build(@Nullable String repositoryPath) {
82
80
if (repoUrl == null || repoUrl .isEmpty ()) {
83
81
log .error (
84
82
"Could not resolve git repository URL (can be provided via "
85
- + GitInfo . DD_GIT_REPOSITORY_URL
86
- + " env var, "
83
+ + Strings . propertyNameToEnvironmentVariableName ( DD_GIT_REPOSITORY_URL )
84
+ + " env var or corresponding system property , "
87
85
+ GeneralConfig .TAGS
88
86
+ " config property or by embedding git metadata at build time)" );
89
87
}
@@ -94,10 +92,10 @@ public GitInfo build(@Nullable String repositoryPath) {
94
92
"Git commit SHA could not be resolved or is invalid: "
95
93
+ commitSha
96
94
+ " (can be provided via "
97
- + GitInfo . DD_GIT_COMMIT_SHA
98
- + " env var, "
95
+ + Strings . propertyNameToEnvironmentVariableName ( DD_GIT_COMMIT_SHA )
96
+ + " env var or corresponding system property , "
99
97
+ GeneralConfig .TAGS
100
- + " config property or by embedding git metadata at build time; must be a full-length SHA_ " );
98
+ + " config property or by embedding git metadata at build time; must be a full-length SHA " );
101
99
}
102
100
}
103
101
0 commit comments