From 9555b05c8c7d085418e7b4b03d5469480e3a7d9a Mon Sep 17 00:00:00 2001 From: Tracy Boehrer Date: Mon, 12 Aug 2019 09:56:55 -0500 Subject: [PATCH] Added PMD (as a linter test) to the projects. Botbuilder and Sample are skipped at present. --- .editorconfig | 3 ++ libraries/bot-connector/pom.xml | 3 -- .../microsoft/bot/connector/Attachments.java | 1 - .../bot/connector/Conversations.java | 1 - .../authentication/ChannelValidation.java | 1 - .../CredentialProviderImpl.java | 2 +- .../authentication/EmulatorValidation.java | 1 - .../authentication/JwtTokenExtractor.java | 4 -- .../authentication/JwtTokenValidation.java | 4 -- .../MicrosoftAppCredentials.java | 10 ++-- .../MicrosoftAppCredentialsInterceptor.java | 1 - .../connector/authentication/OAuthClient.java | 4 +- .../authentication/OAuthResponse.java | 3 +- .../implementation/ConnectorClientImpl.java | 2 - libraries/botbuilder-schema/pom.xml | 2 - .../microsoft/bot/schema/ActivityImpl.java | 30 ++++++------ .../com/microsoft/bot/schema/EntityImpl.java | 11 ++--- .../schema/models/ConversationAccount.java | 5 +- .../models/ConversationReferenceHelper.java | 2 +- libraries/botbuilder/pom.xml | 12 ++++- .../com/microsoft/bot/builder/BotAdapter.java | 1 - pom.xml | 49 +++++++++++++++++-- samples/bot-connector-sample/pom.xml | 10 ++++ 23 files changed, 97 insertions(+), 65 deletions(-) diff --git a/.editorconfig b/.editorconfig index f2a76d59..dabcc8d3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,3 +16,6 @@ insert_final_newline = true [*.md] trim_trailing_whitespace = false + +[*.xml] +indent_size = 2 diff --git a/libraries/bot-connector/pom.xml b/libraries/bot-connector/pom.xml index ef7f3678..c1493caa 100644 --- a/libraries/bot-connector/pom.xml +++ b/libraries/bot-connector/pom.xml @@ -249,11 +249,8 @@ - - - diff --git a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/Attachments.java b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/Attachments.java index 7d1d86ec..7c5cca1e 100644 --- a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/Attachments.java +++ b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/Attachments.java @@ -16,7 +16,6 @@ import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceFuture; import com.microsoft.rest.ServiceResponse; import java.io.InputStream; -import java.io.IOException; import rx.Observable; /** diff --git a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/Conversations.java b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/Conversations.java index 3660d1f4..e637aa7c 100644 --- a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/Conversations.java +++ b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/Conversations.java @@ -21,7 +21,6 @@ import com.microsoft.bot.schema.models.ResourceResponse; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceFuture; import com.microsoft.rest.ServiceResponse; -import java.io.IOException; import java.util.List; import rx.Observable; diff --git a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/ChannelValidation.java b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/ChannelValidation.java index 24c886e7..c05c2949 100644 --- a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/ChannelValidation.java +++ b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/ChannelValidation.java @@ -4,7 +4,6 @@ package com.microsoft.bot.connector.authentication; import com.microsoft.aad.adal4j.AuthenticationException; -import com.microsoft.bot.connector.authentication.JwtTokenExtractor; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; diff --git a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/CredentialProviderImpl.java b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/CredentialProviderImpl.java index 2d6eb1e0..77921647 100644 --- a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/CredentialProviderImpl.java +++ b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/CredentialProviderImpl.java @@ -33,7 +33,7 @@ public class CredentialProviderImpl extends BotCredentials implements Credential @Override public CompletableFuture getAppPasswordAsync(String appId) { - return CompletableFuture.completedFuture((this.appId.equals(appId) ? this.appPassword : null)); + return CompletableFuture.completedFuture(this.appId.equals(appId) ? this.appPassword : null); } @Override diff --git a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/EmulatorValidation.java b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/EmulatorValidation.java index 1a9bb919..5de42af9 100644 --- a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/EmulatorValidation.java +++ b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/EmulatorValidation.java @@ -6,7 +6,6 @@ package com.microsoft.bot.connector.authentication; import com.auth0.jwt.JWT; import com.auth0.jwt.interfaces.DecodedJWT; import com.microsoft.aad.adal4j.AuthenticationException; -import com.microsoft.bot.connector.authentication.JwtTokenExtractor; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; diff --git a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/JwtTokenExtractor.java b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/JwtTokenExtractor.java index b49f78a7..3273a846 100644 --- a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/JwtTokenExtractor.java +++ b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/JwtTokenExtractor.java @@ -9,9 +9,6 @@ import com.auth0.jwt.exceptions.JWTVerificationException; import com.auth0.jwt.interfaces.DecodedJWT; import com.auth0.jwt.interfaces.Verification; import com.microsoft.aad.adal4j.AuthenticationException; -import com.microsoft.bot.connector.authentication.ClaimsIdentity; -import com.microsoft.bot.connector.authentication.ClaimsIdentityImpl; -import com.microsoft.bot.connector.authentication.TokenValidationParameters; import org.apache.commons.lang3.StringUtils; import java.util.HashMap; @@ -20,7 +17,6 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import java.util.function.Function; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/JwtTokenValidation.java b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/JwtTokenValidation.java index f19c5c36..0c5ebd3d 100644 --- a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/JwtTokenValidation.java +++ b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/JwtTokenValidation.java @@ -3,11 +3,7 @@ package com.microsoft.bot.connector.authentication; -import com.auth0.jwt.interfaces.Claim; import com.microsoft.aad.adal4j.AuthenticationException; -import com.microsoft.bot.connector.authentication.MicrosoftAppCredentials; -import com.microsoft.bot.connector.authentication.ClaimsIdentityImpl; -import com.microsoft.bot.connector.authentication.EmulatorValidation; import com.microsoft.bot.schema.models.Activity; import java.util.concurrent.CompletableFuture; diff --git a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/MicrosoftAppCredentials.java b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/MicrosoftAppCredentials.java index bfc62731..f4c54e51 100644 --- a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/MicrosoftAppCredentials.java +++ b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/MicrosoftAppCredentials.java @@ -31,11 +31,11 @@ public class MicrosoftAppCredentials implements ServiceClientCredentials { private String currentToken = null; private long expiredTime = 0; - private static final Object cacheSync = new Object(); + //private static final Object cacheSync = new Object(); protected static final HashMap cache = new HashMap(); - public final String OAuthEndpoint = AuthenticationConstants.ToChannelFromBotLoginUrl; - public final String OAuthScope = AuthenticationConstants.ToChannelFromBotOAuthScope; + public final String OAuthEndpoint = ToChannelFromBotLoginUrl; + public final String OAuthScope = ToChannelFromBotOAuthScope; public String getTokenCacheKey() { @@ -83,7 +83,7 @@ public class MicrosoftAppCredentials implements ServiceClientCredentials { } - private boolean ShouldSetToken(String url) { + protected boolean ShouldSetToken(String url) { if (isTrustedServiceUrl(url)) { return true; } @@ -121,6 +121,8 @@ public class MicrosoftAppCredentials implements ServiceClientCredentials { URL url = new URL(serviceUrl); trustServiceUrl(url, expirationTime); } catch (MalformedURLException e) { + //TODO: What's missing here? + e.printStackTrace(); } } diff --git a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/MicrosoftAppCredentialsInterceptor.java b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/MicrosoftAppCredentialsInterceptor.java index 48d3f0d3..793ad89b 100644 --- a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/MicrosoftAppCredentialsInterceptor.java +++ b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/MicrosoftAppCredentialsInterceptor.java @@ -3,7 +3,6 @@ package com.microsoft.bot.connector.authentication; -import com.microsoft.bot.connector.authentication.MicrosoftAppCredentials; import okhttp3.Interceptor; import okhttp3.Request; import okhttp3.Response; diff --git a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/OAuthClient.java b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/OAuthClient.java index 902a2122..3263c79c 100644 --- a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/OAuthClient.java +++ b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/OAuthClient.java @@ -84,7 +84,7 @@ public class OAuthClient extends ServiceClient { throw new RuntimeException(e); } }) - .collect(joining("&", (uri.endsWith("?") ? uri : uri + "?"), "")); + .collect(joining("&", uri.endsWith("?") ? uri : uri + "?", "")); return new URI(newUri); @@ -177,8 +177,6 @@ public class OAuthClient extends ServiceClient { } return CompletableFuture.supplyAsync(() -> { - String invocationId = null; - // Construct URL HashMap qstrings = new HashMap<>(); qstrings.put("userId", userId); diff --git a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/OAuthResponse.java b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/OAuthResponse.java index 7b589f57..858889d0 100644 --- a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/OAuthResponse.java +++ b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/authentication/OAuthResponse.java @@ -1,7 +1,6 @@ package com.microsoft.bot.connector.authentication; -import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonProperty; import org.joda.time.DateTime; @@ -43,6 +42,6 @@ public class OAuthResponse } @JsonAnySetter - private HashMap properties; + public HashMap properties; } diff --git a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/implementation/ConnectorClientImpl.java b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/implementation/ConnectorClientImpl.java index 042ac1d8..5f9cb738 100644 --- a/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/implementation/ConnectorClientImpl.java +++ b/libraries/bot-connector/src/main/java/com/microsoft/bot/connector/implementation/ConnectorClientImpl.java @@ -11,7 +11,6 @@ import com.microsoft.azure.AzureClient; import com.microsoft.azure.AzureServiceClient; import com.microsoft.bot.connector.Attachments; import com.microsoft.bot.connector.ConnectorClient; -import com.microsoft.bot.connector.Conversations; import com.microsoft.rest.credentials.ServiceClientCredentials; import com.microsoft.rest.RestClient; import com.microsoft.rest.retry.RetryStrategy; @@ -19,7 +18,6 @@ import com.microsoft.rest.retry.RetryStrategy; import java.io.IOException; import java.io.InputStream; import java.util.Properties; -import java.util.stream.Stream; /** * Initializes a new instance of the ConnectorClientImpl class. diff --git a/libraries/botbuilder-schema/pom.xml b/libraries/botbuilder-schema/pom.xml index 8c98f322..479096fc 100644 --- a/libraries/botbuilder-schema/pom.xml +++ b/libraries/botbuilder-schema/pom.xml @@ -197,10 +197,8 @@ - - diff --git a/libraries/botbuilder-schema/src/main/java/com/microsoft/bot/schema/ActivityImpl.java b/libraries/botbuilder-schema/src/main/java/com/microsoft/bot/schema/ActivityImpl.java index 756deb39..67a8267a 100644 --- a/libraries/botbuilder-schema/src/main/java/com/microsoft/bot/schema/ActivityImpl.java +++ b/libraries/botbuilder-schema/src/main/java/com/microsoft/bot/schema/ActivityImpl.java @@ -4,8 +4,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.TreeNode; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.microsoft.bot.schema.ContactRelationUpdateActivity; -import com.microsoft.bot.schema.TraceActivity; import com.microsoft.bot.schema.models.*; @@ -79,7 +77,7 @@ public class ActivityImpl extends Activity { * @param value value of the operation * @param valueType valueType if helpful to identify the value schema (default is value.GetType().Name) * @param label descritive label of context. (Default is calling function name) - * @return + * @return */ public TraceActivity CreateTrace(String name) { return CreateTrace(name, null, null, null); @@ -160,7 +158,7 @@ public class ActivityImpl extends Activity { reply.withType(ActivityTypes.TRACE); reply.withTimestamp(DateTime.now()); reply.withAttachments(new ArrayList()); - reply.withEntities(new ArrayList());; + reply.withEntities(new ArrayList()); return reply; } @@ -624,31 +622,31 @@ public class ActivityImpl extends Activity { /** * Return an IMessageUpdateAcitvity if this is a MessageUpdate activity - * @return + * @return */ //public IMessageUpdateActivity AsMessageUpdateActivity() { return IsActivity(ActivityTypes.MessageUpdate) ? this : null; } /** * Return an IMessageDeleteActivity if this is a MessageDelete activity - * @return + * @return */ //public IMessageDeleteActivity AsMessageDeleteActivity() { return IsActivity(ActivityTypes.MessageDelete) ? this : null; } /** * Return an IMessageReactionActivity if this is a MessageReaction activity - * @return + * @return */ //public IMessageReactionActivity AsMessageReactionActivity() { return IsActivity(ActivityTypes.MessageReaction) ? this : null; } /** * Return an ISuggestionActivity if this is a Suggestion activity - * @return + * @return */ //public ISuggestionActivity AsSuggestionActivity() { return IsActivity(ActivityTypes.Suggestion) ? this : null; } /** * Return an ITraceActivity if this is a Trace activity - * @return + * @return */ //public ITraceActivity AsTraceActivity() { return IsActivity(ActivityTypes.Trace) ? this : null; } @@ -672,7 +670,7 @@ public class ActivityImpl extends Activity { return false; } - private Mention convertToMention(JsonNode node) { + public Mention convertToMention(JsonNode node) { try { return ActivityImpl.mapper.treeToValue(node, Mention.class); } catch (JsonProcessingException e) { @@ -697,7 +695,7 @@ public class ActivityImpl extends Activity { /** * Get channeldata as typed structure - * @param activity + * @param activity * @param TypeT type to use * @return typed Object or default(TypeT) */ @@ -706,7 +704,7 @@ public class ActivityImpl extends Activity { return null; if (classType.isInstance(this.channelData())) { - return ((TypeT) this.channelData()); + return (TypeT) this.channelData(); } JsonNode node = mapper.valueToTree(this.channelData()); return mapper.treeToValue((TreeNode) node, classType); @@ -714,10 +712,10 @@ public class ActivityImpl extends Activity { /** * Get channeldata as typed structure - * @param activity + * @param activity * @param TypeT type to use * @param instance The resulting instance, if possible - * @return + * @return * {@code true} if value of {@linkalso Activity.ChannelData} was coerceable to {@code TypeT}, {@code false} otherwise. */ @@ -734,8 +732,8 @@ public class ActivityImpl extends Activity { return new ResultPair(true, instance); } /** - * Clone a activity - * @param activity + * Clone a activity + * @param activity * @return new cloned activity */ public static Activity CloneActity(Activity activity) { diff --git a/libraries/botbuilder-schema/src/main/java/com/microsoft/bot/schema/EntityImpl.java b/libraries/botbuilder-schema/src/main/java/com/microsoft/bot/schema/EntityImpl.java index 2fa6fc75..e7daf126 100644 --- a/libraries/botbuilder-schema/src/main/java/com/microsoft/bot/schema/EntityImpl.java +++ b/libraries/botbuilder-schema/src/main/java/com/microsoft/bot/schema/EntityImpl.java @@ -77,11 +77,11 @@ public class EntityImpl extends Entity { */ /** - * @param T + * @param T */ /** - * @return + * @return */ public T GetAs(Class type) { @@ -112,8 +112,8 @@ public class EntityImpl extends Entity { /** * Set internal payload. - * @param T - * @param obj + * @param T + * @param obj */ public boolean SetAs(T obj) { @@ -142,6 +142,5 @@ public class EntityImpl extends Entity { return true; } - -}; +} diff --git a/libraries/botbuilder-schema/src/main/java/com/microsoft/bot/schema/models/ConversationAccount.java b/libraries/botbuilder-schema/src/main/java/com/microsoft/bot/schema/models/ConversationAccount.java index 46f83368..d7bfebcb 100644 --- a/libraries/botbuilder-schema/src/main/java/com/microsoft/bot/schema/models/ConversationAccount.java +++ b/libraries/botbuilder-schema/src/main/java/com/microsoft/bot/schema/models/ConversationAccount.java @@ -8,9 +8,6 @@ package com.microsoft.bot.schema.models; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.JsonNode; - -import java.util.HashMap; /** * Channel account information for a conversation. @@ -155,7 +152,7 @@ public class ConversationAccount { * while maintaining the object. * */ - private HashMap properties = new HashMap(); +// private HashMap properties = new HashMap(); /** * Overflow properties. diff --git a/libraries/botbuilder-schema/src/main/java/com/microsoft/bot/schema/models/ConversationReferenceHelper.java b/libraries/botbuilder-schema/src/main/java/com/microsoft/bot/schema/models/ConversationReferenceHelper.java index 3d1e0c76..34c62ff8 100644 --- a/libraries/botbuilder-schema/src/main/java/com/microsoft/bot/schema/models/ConversationReferenceHelper.java +++ b/libraries/botbuilder-schema/src/main/java/com/microsoft/bot/schema/models/ConversationReferenceHelper.java @@ -18,7 +18,7 @@ public class ConversationReferenceHelper { .withType(ActivityTypes.MESSAGE) .withId(UUID.randomUUID().toString()) .withRecipient(new ChannelAccount() - .withId((reference.bot().id())) + .withId(reference.bot().id()) .withName(reference.bot().name())) .withChannelId(reference.channelId()) .withServiceUrl(reference.serviceUrl()) diff --git a/libraries/botbuilder/pom.xml b/libraries/botbuilder/pom.xml index 3bd67b92..6aa0c64c 100644 --- a/libraries/botbuilder/pom.xml +++ b/libraries/botbuilder/pom.xml @@ -181,6 +181,16 @@ true + + org.apache.maven.plugins + maven-pmd-plugin + + true + + **/** + + + @@ -265,10 +275,8 @@ - - diff --git a/libraries/botbuilder/src/main/java/com/microsoft/bot/builder/BotAdapter.java b/libraries/botbuilder/src/main/java/com/microsoft/bot/builder/BotAdapter.java index 59f6a540..609b8935 100644 --- a/libraries/botbuilder/src/main/java/com/microsoft/bot/builder/BotAdapter.java +++ b/libraries/botbuilder/src/main/java/com/microsoft/bot/builder/BotAdapter.java @@ -135,7 +135,6 @@ public abstract class BotAdapter { callback.accept(context); } } - return; } diff --git a/pom.xml b/pom.xml index 8fbc7e67..f29e356f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,18 +4,31 @@ com.microsoft.bot bot-parent 4.0.0-a0 - + pom - + Microsoft BotBuilder SDK Parent This package contains the parent module of Microsoft BotBuilder SDK. https://github.com/Microsoft/botbuilder-java - + UTF-8 true + + + build + + true + + + + + + + + libraries/botbuilder-schema libraries/botbuilder @@ -66,7 +79,33 @@ true + + + org.apache.maven.plugins + maven-pmd-plugin + 3.12.0 + + true + + + + + check + + + + - - \ No newline at end of file + + + + + org.apache.maven.plugins + maven-pmd-plugin + 3.12.0 + + + + + diff --git a/samples/bot-connector-sample/pom.xml b/samples/bot-connector-sample/pom.xml index 342f7ea2..1eb6aebd 100644 --- a/samples/bot-connector-sample/pom.xml +++ b/samples/bot-connector-sample/pom.xml @@ -125,6 +125,16 @@ true + + org.apache.maven.plugins + maven-pmd-plugin + + true + + **/** + + +