From 927cad835567cd6619ca51c97546831b0f13edec Mon Sep 17 00:00:00 2001 From: Noam Lewis Date: Tue, 9 Jan 2024 02:56:37 +0200 Subject: [PATCH] fix: handle error-prone warnings (#1334) * fix: pom.xml - remove duplicate dependencies / plugin clauses that cause warnings This prevents the following errors: $ mvn install -DskipTests=true [INFO] Scanning for projects... [WARNING] [WARNING] Some problems were encountered while building the effective model for com.google.auth:google-auth-library-oauth2-http:jar:1.20.1-SNAPSHOT [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: junit:junit:jar -> duplicate declaration of version (?) @ line 249, column 17 [WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.apache.maven.plugins:maven-failsafe-plugin @ line 193, column 15 [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. [WARNING] [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. [WARNING] * fix: add missing @Override annotations on overriding methods --------- Co-authored-by: Noam Lewis Co-authored-by: Timur Sadykov --- .../auth/appengine/AppEngineCredentials.java | 2 ++ .../auth/oauth2/CloudShellCredentials.java | 2 ++ .../auth/oauth2/ComputeEngineCredentials.java | 2 ++ .../auth/oauth2/DownscopedCredentials.java | 1 + ...ernalAccountAuthorizedUserCredentials.java | 4 +++ .../oauth2/ExternalAccountCredentials.java | 2 ++ .../google/auth/oauth2/GdchCredentials.java | 2 ++ .../google/auth/oauth2/GoogleCredentials.java | 2 ++ .../auth/oauth2/IdTokenCredentials.java | 2 ++ .../auth/oauth2/IdentityPoolCredentials.java | 1 + .../auth/oauth2/ImpersonatedCredentials.java | 3 +++ .../google/auth/oauth2/OAuth2Credentials.java | 1 + .../oauth2/OAuth2CredentialsWithRefresh.java | 1 + .../com/google/auth/oauth2/OAuth2Utils.java | 1 + .../oauth2/ServiceAccountCredentials.java | 3 +++ .../google/auth/oauth2/UserCredentials.java | 6 +++++ .../DefaultCredentialsProviderTest.java | 3 +++ oauth2_http/pom.xml | 26 ++++++------------- 18 files changed, 46 insertions(+), 18 deletions(-) diff --git a/appengine/java/com/google/auth/appengine/AppEngineCredentials.java b/appengine/java/com/google/auth/appengine/AppEngineCredentials.java index 3af489d67..16d046907 100644 --- a/appengine/java/com/google/auth/appengine/AppEngineCredentials.java +++ b/appengine/java/com/google/auth/appengine/AppEngineCredentials.java @@ -139,6 +139,7 @@ public static Builder newBuilder() { return new Builder(); } + @Override public Builder toBuilder() { return new Builder(this); } @@ -175,6 +176,7 @@ public AppIdentityService getAppIdentityService() { return appIdentityService; } + @Override public AppEngineCredentials build() { return new AppEngineCredentials(scopes, appIdentityService); } diff --git a/oauth2_http/java/com/google/auth/oauth2/CloudShellCredentials.java b/oauth2_http/java/com/google/auth/oauth2/CloudShellCredentials.java index 8574f0108..2baa77f50 100644 --- a/oauth2_http/java/com/google/auth/oauth2/CloudShellCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/CloudShellCredentials.java @@ -115,6 +115,7 @@ public boolean equals(Object obj) { return this.authPort == other.authPort; } + @Override public Builder toBuilder() { return new Builder(this); } @@ -142,6 +143,7 @@ public int getAuthPort() { return authPort; } + @Override public CloudShellCredentials build() { return new CloudShellCredentials(authPort); } diff --git a/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java index 2e0c321d1..4fd1c1014 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java @@ -535,6 +535,7 @@ private void readObject(ObjectInputStream input) throws IOException, ClassNotFou transportFactory = newInstance(transportFactoryClassName); } + @Override public Builder toBuilder() { return new Builder(this); } @@ -675,6 +676,7 @@ public Collection getDefaultScopes() { return defaultScopes; } + @Override public ComputeEngineCredentials build() { return new ComputeEngineCredentials(this); } diff --git a/oauth2_http/java/com/google/auth/oauth2/DownscopedCredentials.java b/oauth2_http/java/com/google/auth/oauth2/DownscopedCredentials.java index a8447a69a..43709d779 100644 --- a/oauth2_http/java/com/google/auth/oauth2/DownscopedCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/DownscopedCredentials.java @@ -185,6 +185,7 @@ public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) { return this; } + @Override public DownscopedCredentials build() { return new DownscopedCredentials( sourceCredential, credentialAccessBoundary, transportFactory); diff --git a/oauth2_http/java/com/google/auth/oauth2/ExternalAccountAuthorizedUserCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ExternalAccountAuthorizedUserCredentials.java index e713f7452..d01623a62 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ExternalAccountAuthorizedUserCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ExternalAccountAuthorizedUserCredentials.java @@ -294,6 +294,7 @@ public boolean equals(Object obj) { && Objects.equals(this.quotaProjectId, credentials.quotaProjectId); } + @Override public Builder toBuilder() { return new Builder(this); } @@ -501,6 +502,7 @@ public Builder setClientSecret(String clientSecret) { * @param quotaProjectId the quota and billing project id to set * @return this {@code Builder} object */ + @Override @CanIgnoreReturnValue public Builder setQuotaProjectId(String quotaProjectId) { super.setQuotaProjectId(quotaProjectId); @@ -513,12 +515,14 @@ public Builder setQuotaProjectId(String quotaProjectId) { * @param accessToken the access token * @return this {@code Builder} object */ + @Override @CanIgnoreReturnValue public Builder setAccessToken(AccessToken accessToken) { super.setAccessToken(accessToken); return this; } + @Override public ExternalAccountAuthorizedUserCredentials build() { return new ExternalAccountAuthorizedUserCredentials(this); } diff --git a/oauth2_http/java/com/google/auth/oauth2/ExternalAccountCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ExternalAccountCredentials.java index bccd943eb..804df70df 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ExternalAccountCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ExternalAccountCredentials.java @@ -848,6 +848,7 @@ public Builder setTokenInfoUrl(String tokenInfoUrl) { * @param quotaProjectId the quota and billing project id to set * @return this {@code Builder} object */ + @Override @CanIgnoreReturnValue public Builder setQuotaProjectId(String quotaProjectId) { super.setQuotaProjectId(quotaProjectId); @@ -941,6 +942,7 @@ Builder setEnvironmentProvider(EnvironmentProvider environmentProvider) { return this; } + @Override public abstract ExternalAccountCredentials build(); } } diff --git a/oauth2_http/java/com/google/auth/oauth2/GdchCredentials.java b/oauth2_http/java/com/google/auth/oauth2/GdchCredentials.java index 4ffa87520..642dd7858 100644 --- a/oauth2_http/java/com/google/auth/oauth2/GdchCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/GdchCredentials.java @@ -311,6 +311,7 @@ public static Builder newBuilder() { return new Builder(); } + @Override public Builder toBuilder() { return new Builder(this); } @@ -475,6 +476,7 @@ public int getLifetime() { return lifetime; } + @Override public GdchCredentials build() { return new GdchCredentials(this); } diff --git a/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java b/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java index 4c10008c7..41388a9e8 100644 --- a/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java @@ -406,6 +406,7 @@ public static Builder newBuilder() { return new Builder(); } + @Override public Builder toBuilder() { return new Builder(this); } @@ -502,6 +503,7 @@ protected Builder(GoogleCredentials.Builder builder) { this.universeDomain = builder.universeDomain; } + @Override public GoogleCredentials build() { return new GoogleCredentials(this); } diff --git a/oauth2_http/java/com/google/auth/oauth2/IdTokenCredentials.java b/oauth2_http/java/com/google/auth/oauth2/IdTokenCredentials.java index a9bd03208..42bdbaa6e 100644 --- a/oauth2_http/java/com/google/auth/oauth2/IdTokenCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/IdTokenCredentials.java @@ -149,6 +149,7 @@ public boolean equals(Object obj) { && Objects.equals(this.targetAudience, other.targetAudience); } + @Override public Builder toBuilder() { return new Builder() .setIdTokenProvider(this.idTokenProvider) @@ -198,6 +199,7 @@ public List getOptions() { return this.options; } + @Override public IdTokenCredentials build() { return new IdTokenCredentials(this); } diff --git a/oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentials.java b/oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentials.java index fcfc7bb9b..776a01e05 100644 --- a/oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentials.java @@ -183,6 +183,7 @@ public static class Builder extends ExternalAccountCredentials.Builder { super(credentials); } + @Override @CanIgnoreReturnValue public Builder setWorkforcePoolUserProject(String workforcePoolUserProject) { super.setWorkforcePoolUserProject(workforcePoolUserProject); diff --git a/oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java index 641ddc462..f66b29a96 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java @@ -602,6 +602,7 @@ public boolean equals(Object obj) { && Objects.equals(this.iamEndpointOverride, other.iamEndpointOverride); } + @Override public Builder toBuilder() { return new Builder(this.sourceCredentials, this.targetPrincipal); } @@ -688,6 +689,7 @@ public HttpTransportFactory getHttpTransportFactory() { return transportFactory; } + @Override @CanIgnoreReturnValue public Builder setQuotaProjectId(String quotaProjectId) { super.setQuotaProjectId(quotaProjectId); @@ -710,6 +712,7 @@ public Calendar getCalendar() { return this.calendar; } + @Override public ImpersonatedCredentials build() { return new ImpersonatedCredentials(this); } diff --git a/oauth2_http/java/com/google/auth/oauth2/OAuth2Credentials.java b/oauth2_http/java/com/google/auth/oauth2/OAuth2Credentials.java index d1332bb29..94ddeb549 100644 --- a/oauth2_http/java/com/google/auth/oauth2/OAuth2Credentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/OAuth2Credentials.java @@ -630,6 +630,7 @@ public ListenableFutureTask getTask() { return this.task; } + @Override public void run() { task.run(); } diff --git a/oauth2_http/java/com/google/auth/oauth2/OAuth2CredentialsWithRefresh.java b/oauth2_http/java/com/google/auth/oauth2/OAuth2CredentialsWithRefresh.java index 14e3ddae8..954378f7b 100644 --- a/oauth2_http/java/com/google/auth/oauth2/OAuth2CredentialsWithRefresh.java +++ b/oauth2_http/java/com/google/auth/oauth2/OAuth2CredentialsWithRefresh.java @@ -113,6 +113,7 @@ public Builder setRefreshHandler(OAuth2RefreshHandler handler) { return this; } + @Override public OAuth2CredentialsWithRefresh build() { return new OAuth2CredentialsWithRefresh(this); } diff --git a/oauth2_http/java/com/google/auth/oauth2/OAuth2Utils.java b/oauth2_http/java/com/google/auth/oauth2/OAuth2Utils.java index a1d276bad..d4a29d515 100644 --- a/oauth2_http/java/com/google/auth/oauth2/OAuth2Utils.java +++ b/oauth2_http/java/com/google/auth/oauth2/OAuth2Utils.java @@ -99,6 +99,7 @@ class OAuth2Utils { static class DefaultHttpTransportFactory implements HttpTransportFactory { + @Override public HttpTransport create() { return HTTP_TRANSPORT; } diff --git a/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java index 69361e00c..a133b2e5b 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java @@ -996,6 +996,7 @@ public static Builder newBuilder() { return new Builder(); } + @Override public Builder toBuilder() { return new Builder(this); } @@ -1103,6 +1104,7 @@ public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) { return this; } + @Override @CanIgnoreReturnValue public Builder setQuotaProjectId(String quotaProjectId) { super.setQuotaProjectId(quotaProjectId); @@ -1188,6 +1190,7 @@ public boolean isDefaultRetriesEnabled() { return defaultRetriesEnabled; } + @Override public ServiceAccountCredentials build() { return new ServiceAccountCredentials(this); } diff --git a/oauth2_http/java/com/google/auth/oauth2/UserCredentials.java b/oauth2_http/java/com/google/auth/oauth2/UserCredentials.java index d4358d93b..67859c33d 100644 --- a/oauth2_http/java/com/google/auth/oauth2/UserCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/UserCredentials.java @@ -372,6 +372,7 @@ public static Builder newBuilder() { return new Builder(); } + @Override public Builder toBuilder() { return new Builder(this); } @@ -425,24 +426,28 @@ public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) { return this; } + @Override @CanIgnoreReturnValue public Builder setAccessToken(AccessToken token) { super.setAccessToken(token); return this; } + @Override @CanIgnoreReturnValue public Builder setExpirationMargin(Duration expirationMargin) { super.setExpirationMargin(expirationMargin); return this; } + @Override @CanIgnoreReturnValue public Builder setRefreshMargin(Duration refreshMargin) { super.setRefreshMargin(refreshMargin); return this; } + @Override @CanIgnoreReturnValue public Builder setQuotaProjectId(String quotaProjectId) { super.setQuotaProjectId(quotaProjectId); @@ -469,6 +474,7 @@ public HttpTransportFactory getHttpTransportFactory() { return transportFactory; } + @Override public UserCredentials build() { return new UserCredentials(this); } diff --git a/oauth2_http/javatests/com/google/auth/oauth2/DefaultCredentialsProviderTest.java b/oauth2_http/javatests/com/google/auth/oauth2/DefaultCredentialsProviderTest.java index 0047cd988..1bb44520e 100644 --- a/oauth2_http/javatests/com/google/auth/oauth2/DefaultCredentialsProviderTest.java +++ b/oauth2_http/javatests/com/google/auth/oauth2/DefaultCredentialsProviderTest.java @@ -606,6 +606,7 @@ private String tempFilePath(String filename) { private class LogHandler extends Handler { LogRecord lastRecord; + @Override public void publish(LogRecord record) { lastRecord = record; } @@ -614,8 +615,10 @@ public LogRecord getRecord() { return lastRecord; } + @Override public void close() {} + @Override public void flush() {} } diff --git a/oauth2_http/pom.xml b/oauth2_http/pom.xml index a1af91846..dc4441677 100644 --- a/oauth2_http/pom.xml +++ b/oauth2_http/pom.xml @@ -161,6 +161,14 @@ **/functional/*.java + + + + integration-test + verify + + + org.apache.maven.plugins @@ -175,18 +183,6 @@ sponge_log - - org.apache.maven.plugins - maven-failsafe-plugin - - - - integration-test - verify - - - - @@ -231,12 +227,6 @@ 1.3 test - - junit - junit - 4.13.2 - test - org.mockito mockito-core