Skip to content

Commit 714d8af

Browse files
committed
update
1 parent 4e58dd2 commit 714d8af

File tree

2 files changed

+45
-26
lines changed

2 files changed

+45
-26
lines changed

databricks-sdk-java/src/main/java/com/databricks/sdk/core/UserAgent.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,24 @@ public static String asString() {
142142
// List of CI/CD providers and their environment variables for detection
143143
private static List<CicdProvider> listCiCdProviders() {
144144
return Arrays.asList(
145-
new CicdProvider("github", Collections.singletonList(new EnvVar("GITHUB_ACTIONS", "true"))),
146-
new CicdProvider("gitlab", Collections.singletonList(new EnvVar("GITLAB_CI", "true"))),
147-
new CicdProvider("jenkins", Collections.singletonList(new EnvVar("JENKINS_URL", ""))),
148-
new CicdProvider("azure-devops", Collections.singletonList(new EnvVar("TF_BUILD", "True"))),
149-
new CicdProvider("circle", Collections.singletonList(new EnvVar("CIRCLECI", "true"))),
150-
new CicdProvider("travis", Collections.singletonList(new EnvVar("TRAVIS", "true"))),
151-
new CicdProvider("bitbucket", Collections.singletonList(new EnvVar("BITBUCKET_BUILD_NUMBER", ""))),
152-
new CicdProvider("google-cloud-build", Arrays.asList(
153-
new EnvVar("PROJECT_ID", ""),
154-
new EnvVar("BUILD_ID", ""),
155-
new EnvVar("PROJECT_NUMBER", ""),
156-
new EnvVar("LOCATION", "")
157-
)),
158-
new CicdProvider("aws-code-build", Collections.singletonList(new EnvVar("CODEBUILD_BUILD_ARN", ""))),
159-
new CicdProvider("tf-cloud", Collections.singletonList(new EnvVar("TFC_RUN_ID", "")))
160-
);
145+
new CicdProvider("github", Collections.singletonList(new EnvVar("GITHUB_ACTIONS", "true"))),
146+
new CicdProvider("gitlab", Collections.singletonList(new EnvVar("GITLAB_CI", "true"))),
147+
new CicdProvider("jenkins", Collections.singletonList(new EnvVar("JENKINS_URL", ""))),
148+
new CicdProvider("azure-devops", Collections.singletonList(new EnvVar("TF_BUILD", "True"))),
149+
new CicdProvider("circle", Collections.singletonList(new EnvVar("CIRCLECI", "true"))),
150+
new CicdProvider("travis", Collections.singletonList(new EnvVar("TRAVIS", "true"))),
151+
new CicdProvider(
152+
"bitbucket", Collections.singletonList(new EnvVar("BITBUCKET_BUILD_NUMBER", ""))),
153+
new CicdProvider(
154+
"google-cloud-build",
155+
Arrays.asList(
156+
new EnvVar("PROJECT_ID", ""),
157+
new EnvVar("BUILD_ID", ""),
158+
new EnvVar("PROJECT_NUMBER", ""),
159+
new EnvVar("LOCATION", ""))),
160+
new CicdProvider(
161+
"aws-code-build", Collections.singletonList(new EnvVar("CODEBUILD_BUILD_ARN", ""))),
162+
new CicdProvider("tf-cloud", Collections.singletonList(new EnvVar("TFC_RUN_ID", ""))));
161163
}
162164

163165
// Volatile field to ensure thread-safe lazy initialization
@@ -231,7 +233,11 @@ private static String cicdProvider() {
231233

232234
private static Environment env() {
233235
if (env == null) {
234-
env = new Environment(System.getenv(), System.getenv("PATH").split(File.pathSeparator), System.getProperty("os.name"));
236+
env =
237+
new Environment(
238+
System.getenv(),
239+
System.getenv("PATH").split(File.pathSeparator),
240+
System.getProperty("os.name"));
235241
}
236242
return env;
237243
}

databricks-sdk-java/src/test/java/com/databricks/sdk/core/UserAgentTest.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.databricks.sdk.core;
22

3+
import com.databricks.sdk.core.utils.Environment;
34
import java.util.ArrayList;
45
import java.util.HashMap;
5-
import com.databricks.sdk.core.utils.Environment;
66
import org.junit.jupiter.api.*;
77
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
@@ -65,26 +65,39 @@ public void testUserAgentWithSemverValue() {
6565

6666
@Test
6767
public void testUserAgentCicdNoProvider() {
68-
UserAgent.env = new Environment(new HashMap<>(), new ArrayList<>(), System.getProperty("os.name"));
68+
UserAgent.env =
69+
new Environment(new HashMap<>(), new ArrayList<>(), System.getProperty("os.name"));
6970
Assertions.assertFalse(UserAgent.asString().contains("cicd"));
7071
UserAgent.env = null;
7172
}
7273

7374
@Test
7475
public void testUserAgentCicdOneProvider() {
75-
UserAgent.env = new Environment(new HashMap<String, String>() {{
76-
put("GITHUB_ACTIONS", "true");
77-
}}, new ArrayList<>(), System.getProperty("os.name"));
76+
UserAgent.env =
77+
new Environment(
78+
new HashMap<String, String>() {
79+
{
80+
put("GITHUB_ACTIONS", "true");
81+
}
82+
},
83+
new ArrayList<>(),
84+
System.getProperty("os.name"));
7885
Assertions.assertTrue(UserAgent.asString().contains("cicd/github"));
7986
UserAgent.env = null;
8087
}
8188

8289
@Test
8390
public void testUserAgentCicdTwoProvider() {
84-
UserAgent.env = new Environment(new HashMap<String, String>() {{
85-
put("GITLAB_CI", "true");
86-
put("JENKINS_URL", "");
87-
}}, new ArrayList<>(), System.getProperty("os.name"));
91+
UserAgent.env =
92+
new Environment(
93+
new HashMap<String, String>() {
94+
{
95+
put("GITLAB_CI", "true");
96+
put("JENKINS_URL", "");
97+
}
98+
},
99+
new ArrayList<>(),
100+
System.getProperty("os.name"));
88101
Assertions.assertTrue(UserAgent.asString().contains("cicd/gitlab"));
89102
UserAgent.env = null;
90103
}

0 commit comments

Comments
 (0)