Skip to content

Commit f47c560

Browse files
committed
remove JCommander dependency.
1 parent b35f145 commit f47c560

7 files changed

Lines changed: 15 additions & 32 deletions

File tree

MODULE.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [
4343
"org.apache.tomcat:annotations-api:6.0.53",
4444
"org.checkerframework:checker-qual:3.12.0",
4545
"org.codehaus.mojo:animal-sniffer-annotations:1.23",
46-
"org.jcommander:jcommander:1.83",
4746
]
4847
# GRPC_DEPS_END
4948

repositories.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [
4747
"org.apache.tomcat:annotations-api:6.0.53",
4848
"org.checkerframework:checker-qual:3.12.0",
4949
"org.codehaus.mojo:animal-sniffer-annotations:1.23",
50-
"org.jcommander:jcommander:1.83",
5150
]
5251
# GRPC_DEPS_END
5352

s2a/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ java_library(
5959
deps = [
6060
":s2a_identity",
6161
":token_fetcher",
62-
artifact("org.jcommander:jcommander"),
62+
artifact("com.google.guava:guava"),
6363
],
6464
)
6565

s2a/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ dependencies {
2626
libraries.protobuf.java,
2727
libraries.conscrypt,
2828
libraries.guava.jre // JRE required by protobuf-java-util from grpclb
29-
compileOnly 'org.jcommander:jcommander:1.83'
3029
def nettyDependency = implementation project(':grpc-netty')
3130
compileOnly libraries.javax.annotation
3231

@@ -44,7 +43,6 @@ dependencies {
4443
libraries.conscrypt,
4544
libraries.netty.transport.epoll
4645

47-
testImplementation 'org.jcommander:jcommander:1.83'
4846
testImplementation 'com.google.truth:truth:1.4.2'
4947
testImplementation 'com.google.truth.extensions:truth-proto-extension:1.4.2'
5048
testImplementation libraries.guava.testlib

s2a/src/main/java/io/grpc/s2a/handshaker/tokenmanager/SingleTokenFetcher.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,15 @@
1616

1717
package io.grpc.s2a.handshaker.tokenmanager;
1818

19-
import com.beust.jcommander.Parameter;
20-
import com.beust.jcommander.Parameters;
19+
import com.google.common.annotations.VisibleForTesting;
2120
import io.grpc.s2a.handshaker.S2AIdentity;
2221
import java.util.Optional;
2322

2423
/** Fetches a single access token via an environment variable. */
24+
@SuppressWarnings("NonFinalStaticField")
2525
public final class SingleTokenFetcher implements TokenFetcher {
2626
private static final String ENVIRONMENT_VARIABLE = "S2A_ACCESS_TOKEN";
27-
28-
/** Set an access token via a flag. */
29-
@Parameters(separators = "=")
30-
public static class Flags {
31-
@Parameter(
32-
names = "--s2a_access_token",
33-
description = "The access token used to authenticate to S2A.")
34-
private static String accessToken = System.getenv(ENVIRONMENT_VARIABLE);
35-
36-
public synchronized void reset() {
37-
accessToken = null;
38-
}
39-
}
27+
private static String accessToken = System.getenv(ENVIRONMENT_VARIABLE);
4028

4129
private final String token;
4230

@@ -45,7 +33,12 @@ public synchronized void reset() {
4533
* {@code Optional} instance if the token could not be fetched.
4634
*/
4735
public static Optional<TokenFetcher> create() {
48-
return Optional.ofNullable(Flags.accessToken).map(SingleTokenFetcher::new);
36+
return Optional.ofNullable(accessToken).map(SingleTokenFetcher::new);
37+
}
38+
39+
@VisibleForTesting
40+
public static void setAccessToken(String token) {
41+
accessToken = token;
4942
}
5043

5144
private SingleTokenFetcher(String token) {

s2a/src/test/java/io/grpc/s2a/handshaker/GetAuthenticationMechanismsTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package io.grpc.s2a.handshaker;
1818

19-
import com.beust.jcommander.JCommander;
2019
import com.google.common.truth.Expect;
2120
import io.grpc.s2a.handshaker.S2AIdentity;
2221
import io.grpc.s2a.handshaker.tokenmanager.SingleTokenFetcher;
@@ -32,13 +31,11 @@
3231
public final class GetAuthenticationMechanismsTest {
3332
@Rule public final Expect expect = Expect.create();
3433
private static final String TOKEN = "access_token";
35-
private static final String[] SET_TOKEN = {"--s2a_access_token", TOKEN};
36-
private static final SingleTokenFetcher.Flags FLAGS = new SingleTokenFetcher.Flags();
3734

3835
@BeforeClass
3936
public static void setUpClass() {
4037
// Set the token that the client will use to authenticate to the S2A.
41-
JCommander.newBuilder().addObject(FLAGS).build().parse(SET_TOKEN);
38+
SingleTokenFetcher.setAccessToken(TOKEN);
4239
}
4340

4441
@Test

s2a/src/test/java/io/grpc/s2a/handshaker/tokenmanager/SingleTokenAccessTokenManagerTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import static com.google.common.truth.Truth.assertThat;
2020

21-
import com.beust.jcommander.JCommander;
2221
import io.grpc.s2a.handshaker.S2AIdentity;
2322
import java.util.Optional;
2423
import org.junit.Before;
@@ -30,25 +29,23 @@
3029
public final class SingleTokenAccessTokenManagerTest {
3130
private static final S2AIdentity IDENTITY = S2AIdentity.fromSpiffeId("spiffe_id");
3231
private static final String TOKEN = "token";
33-
private static final String[] SET_TOKEN = {"--s2a_access_token", TOKEN};
34-
private static final SingleTokenFetcher.Flags FLAGS = new SingleTokenFetcher.Flags();
3532

3633
@Before
3734
public void setUp() {
38-
FLAGS.reset();
35+
SingleTokenFetcher.setAccessToken(null);
3936
}
4037

4138
@Test
4239
public void getDefaultToken_success() throws Exception {
43-
JCommander.newBuilder().addObject(FLAGS).build().parse(SET_TOKEN);
40+
SingleTokenFetcher.setAccessToken(TOKEN);
4441
Optional<AccessTokenManager> manager = AccessTokenManager.create();
4542
assertThat(manager).isPresent();
4643
assertThat(manager.get().getDefaultToken()).isEqualTo(TOKEN);
4744
}
4845

4946
@Test
5047
public void getToken_success() throws Exception {
51-
JCommander.newBuilder().addObject(FLAGS).build().parse(SET_TOKEN);
48+
SingleTokenFetcher.setAccessToken(TOKEN);
5249
Optional<AccessTokenManager> manager = AccessTokenManager.create();
5350
assertThat(manager).isPresent();
5451
assertThat(manager.get().getToken(IDENTITY)).isEqualTo(TOKEN);
@@ -61,7 +58,7 @@ public void getToken_noEnvironmentVariable() throws Exception {
6158

6259
@Test
6360
public void create_success() throws Exception {
64-
JCommander.newBuilder().addObject(FLAGS).build().parse(SET_TOKEN);
61+
SingleTokenFetcher.setAccessToken(TOKEN);
6562
Optional<AccessTokenManager> manager = AccessTokenManager.create();
6663
assertThat(manager).isPresent();
6764
assertThat(manager.get().getToken(IDENTITY)).isEqualTo(TOKEN);

0 commit comments

Comments
 (0)