Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit 45ad1e0

Browse files
authored
Merge pull request #428 from microsoft/trboehre/build-and-formatting
Build and code style changes
2 parents 937df4a + 098bf25 commit 45ad1e0

File tree

284 files changed

+11222
-6974
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+11222
-6974
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio
3131

3232
This project uses linting rules to enforce code standardization. These rules are specified in the file [bot-checkstyle.xml](./etc/bot-checkstyle.xml) with [CheckStyle](https://checkstyle.org/) and are hooked to Maven's build cycle.
3333

34-
**INFO**: Since the CheckStyle plugin is hook to the build cycle, this makes the build **fail** in case there are linting warnings in the project files so be sure to check that the code doesn't break any rule.
34+
**INFO**: Since the CheckStyle and PMD plugins are hooked into the build cycle, this makes the build **fail** in cases where there are linting warnings in the project files. Errors will be in the file ./target/checkstyle-result.xml and ./target/pmd.xml.
3535

3636
CheckStyle is available in different flavours:
3737
- [Visual Studio Code plugin](https://marketplace.visualstudio.com/items?itemName=shengchen.vscode-checkstyle)
@@ -41,6 +41,32 @@ CheckStyle is available in different flavours:
4141

4242
**INFO**: Be sure to configure your IDE to use the file [bot-checkstyle.xml](./etc/bot-checkstyle.xml) instead of the default rules.
4343

44+
## Build and IDE
45+
46+
Any IDE that can import and work with Maven projects should work. As a matter of practice we use the command line to perform Maven builds. If your IDE can be configured to defer build and run to Maven it should also work.
47+
- Java
48+
- We use the [Azul JDK 8](https://www.azul.com/downloads/azure-only/zulu/?version=java-8-lts&architecture=x86-64-bit&package=jdk) to build and test with. While not a requirement to develop the SDK with, it is recommended as this is what Azure is using for Java 1.8. If you do install this JDK, make sure your IDE is targeting that JVM, and your path (from command line) and JAVA_HOME point to that.
49+
50+
- Visual Studio Code
51+
- Extensions
52+
- Java Extension Pack by Microsoft
53+
- Checkstyle for Java by ShengChen (Optional)
54+
- EditorConfig for VS Code by EditorConfig (Recommended)
55+
- Recommended setup
56+
- Open the settings for "Language Support for Java by RedHat" and set:
57+
- Java > Format > Settings: Profile = "BotFramework"
58+
- Java > Format > Settings: Url = "etc/botframework-java-formatter.xml"
59+
- This will format the code (on command) to BotFramework style.
60+
61+
- IntelliJ
62+
- Extensions
63+
- Checkstyle by IDEA
64+
- Eclipse Code Formatter by Vojtech-Krasa (Recommended)
65+
- Recommended setup
66+
- When importing the SDK for the first time, make sure "Auto import" is checked.
67+
- If the Eclipse Code Formatter was installed:
68+
- Got to Settings > Other Settings -> Eclipse Code Formatter, and set the formatter config file to etc/botframework-java-formatter.xml
69+
4470
## Reporting Security Issues
4571

4672
Security issues and bugs should be reported privately, via email, to the Microsoft Security

etc/bot-checkstyle.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@
6969

7070
<!-- Miscellaneous other checks. -->
7171
<!-- See http://checkstyle.sourceforge.net/config_misc.html -->
72-
<module name="RegexpSingleline">
72+
<!-- <module name="RegexpSingleline">
7373
<property name="format" value="\s+$"/>
7474
<property name="minimum" value="0"/>
7575
<property name="maximum" value="0"/>
7676
<property name="message" value="Line has trailing spaces."/>
77-
</module>
77+
</module> -->
7878

7979
<!-- Checks for Headers -->
8080
<!-- See http://checkstyle.sourceforge.net/config_header.html -->

etc/botframework-java-formatter.xml

Lines changed: 365 additions & 0 deletions
Large diffs are not rendered by default.

libraries/bot-builder/src/main/java/com/microsoft/bot/builder/ActivityHandler.java

Lines changed: 308 additions & 202 deletions
Large diffs are not rendered by default.

libraries/bot-builder/src/main/java/com/microsoft/bot/builder/AutoSaveStateMiddleware.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import java.util.concurrent.CompletableFuture;
88

99
/**
10-
* Middleware to automatically call .SaveChanges() at the end of the turn for all BotState class it is managing.
10+
* Middleware to automatically call .SaveChanges() at the end of the turn for
11+
* all BotState class it is managing.
1112
*/
1213
public class AutoSaveStateMiddleware implements Middleware {
1314
/**
@@ -67,15 +68,16 @@ public AutoSaveStateMiddleware add(BotState botState) {
6768
}
6869

6970
/**
70-
* Middleware implementation which calls savesChanges automatically at the end of the turn.
71+
* Middleware implementation which calls savesChanges automatically at the end
72+
* of the turn.
7173
*
7274
* @param turnContext The context object for this turn.
73-
* @param next The delegate to call to continue the bot middleware pipeline.
75+
* @param next The delegate to call to continue the bot middleware
76+
* pipeline.
7477
* @return A task representing the asynchronous operation.
7578
*/
7679
@Override
7780
public CompletableFuture<Void> onTurn(TurnContext turnContext, NextDelegate next) {
78-
return next.next()
79-
.thenCompose(result -> botStateSet.saveAllChanges(turnContext));
81+
return next.next().thenCompose(result -> botStateSet.saveAllChanges(turnContext));
8082
}
8183
}

libraries/bot-builder/src/main/java/com/microsoft/bot/builder/Bot.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ public interface Bot {
1212
/**
1313
* When implemented in a bot, handles an incoming activity.
1414
*
15-
* @param turnContext The context object for this turn. Provides information about the
16-
* incoming activity, and other data needed to process the activity.
15+
* @param turnContext The context object for this turn. Provides information
16+
* about the incoming activity, and other data needed to
17+
* process the activity.
1718
* @return A task that represents the work queued to execute.
1819
*/
1920
CompletableFuture<Void> onTurn(TurnContext turnContext);

libraries/bot-builder/src/main/java/com/microsoft/bot/builder/BotAdapter.java

Lines changed: 95 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,24 @@
1212
import java.util.concurrent.CompletionException;
1313

1414
/**
15-
* Represents a bot adapter that can connect a bot to a service endpoint.
16-
* This class is abstract.
17-
* <p>The bot adapter encapsulates authentication processes and sends
18-
* activities to and receives activities from the Bot Connector Service. When your
19-
* bot receives an activity, the adapter creates a context object, passes it to your
20-
* bot's application logic, and sends responses back to the user's channel.</p>
21-
* <p>Use {@link #use(Middleware)} to add {@link Middleware} objects
22-
* to your adapter’s middleware collection. The adapter processes and directs
23-
* incoming activities in through the bot middleware pipeline to your bot’s logic
24-
* and then back out again. As each activity flows in and out of the bot, each piece
25-
* of middleware can inspect or act upon the activity, both before and after the bot
26-
* logic runs.</p>
15+
* Represents a bot adapter that can connect a bot to a service endpoint. This
16+
* class is abstract.
17+
* <p>
18+
* The bot adapter encapsulates authentication processes and sends activities to
19+
* and receives activities from the Bot Connector Service. When your bot
20+
* receives an activity, the adapter creates a context object, passes it to your
21+
* bot's application logic, and sends responses back to the user's channel.
22+
* </p>
23+
* <p>
24+
* Use {@link #use(Middleware)} to add {@link Middleware} objects to your
25+
* adapter’s middleware collection. The adapter processes and directs incoming
26+
* activities in through the bot middleware pipeline to your bot’s logic and
27+
* then back out again. As each activity flows in and out of the bot, each piece
28+
* of middleware can inspect or act upon the activity, both before and after the
29+
* bot logic runs.
30+
* </p>
2731
*
28-
* {@link TurnContext}
29-
* {@link Activity}
30-
* {@link Bot}
31-
* {@link Middleware}
32+
* {@link TurnContext} {@link Activity} {@link Bot} {@link Middleware}
3233
*/
3334
public abstract class BotAdapter {
3435
/**
@@ -42,18 +43,22 @@ public abstract class BotAdapter {
4243
private OnTurnErrorHandler onTurnError;
4344

4445
/**
45-
* Gets the error handler that can catch exceptions in the middleware or application.
46+
* Gets the error handler that can catch exceptions in the middleware or
47+
* application.
4648
*
47-
* @return An error handler that can catch exceptions in the middleware or application.
49+
* @return An error handler that can catch exceptions in the middleware or
50+
* application.
4851
*/
4952
public OnTurnErrorHandler getOnTurnError() {
5053
return onTurnError;
5154
}
5255

5356
/**
54-
* Sets the error handler that can catch exceptions in the middleware or application.
57+
* Sets the error handler that can catch exceptions in the middleware or
58+
* application.
5559
*
56-
* @param withTurnError An error handler that can catch exceptions in the middleware or application.
60+
* @param withTurnError An error handler that can catch exceptions in the
61+
* middleware or application.
5762
*/
5863
public void setOnTurnError(OnTurnErrorHandler withTurnError) {
5964
onTurnError = withTurnError;
@@ -72,9 +77,9 @@ protected MiddlewareSet getMiddlewareSet() {
7277
* Adds middleware to the adapter's pipeline.
7378
*
7479
* @param middleware The middleware to add.
75-
* @return The updated adapter object.
76-
* Middleware is added to the adapter at initialization time.
77-
* For each turn, the adapter calls middleware in the order in which you added it.
80+
* @return The updated adapter object. Middleware is added to the adapter at
81+
* initialization time. For each turn, the adapter calls middleware in
82+
* the order in which you added it.
7883
*/
7984
public BotAdapter use(Middleware middleware) {
8085
middlewareSet.use(middleware);
@@ -86,69 +91,85 @@ public BotAdapter use(Middleware middleware) {
8691
*
8792
* @param context The context object for the turn.
8893
* @param activities The activities to send.
89-
* @return A task that represents the work queued to execute.
90-
* If the activities are successfully sent, the task result contains
91-
* an array of {@link ResourceResponse} objects containing the IDs that
92-
* the receiving channel assigned to the activities.
93-
* {@link TurnContext#onSendActivities(SendActivitiesHandler)}
94+
* @return A task that represents the work queued to execute. If the activities
95+
* are successfully sent, the task result contains an array of
96+
* {@link ResourceResponse} objects containing the IDs that the
97+
* receiving channel assigned to the activities.
98+
* {@link TurnContext#onSendActivities(SendActivitiesHandler)}
9499
*/
95-
public abstract CompletableFuture<ResourceResponse[]> sendActivities(TurnContext context,
96-
List<Activity> activities);
100+
public abstract CompletableFuture<ResourceResponse[]> sendActivities(
101+
TurnContext context,
102+
List<Activity> activities
103+
);
97104

98105
/**
99106
* When overridden in a derived class, replaces an existing activity in the
100107
* conversation.
101108
*
102109
* @param context The context object for the turn.
103110
* @param activity New replacement activity.
104-
* @return A task that represents the work queued to execute.
105-
* If the activity is successfully sent, the task result contains
106-
* a {@link ResourceResponse} object containing the ID that the receiving
107-
* channel assigned to the activity.
108-
* <p>Before calling this, set the ID of the replacement activity to the ID
109-
* of the activity to replace.</p>
110-
* {@link TurnContext#onUpdateActivity(UpdateActivityHandler)}
111+
* @return A task that represents the work queued to execute. If the activity is
112+
* successfully sent, the task result contains a
113+
* {@link ResourceResponse} object containing the ID that the receiving
114+
* channel assigned to the activity.
115+
* <p>
116+
* Before calling this, set the ID of the replacement activity to the ID
117+
* of the activity to replace.
118+
* </p>
119+
* {@link TurnContext#onUpdateActivity(UpdateActivityHandler)}
111120
*/
112-
public abstract CompletableFuture<ResourceResponse> updateActivity(TurnContext context,
113-
Activity activity);
121+
public abstract CompletableFuture<ResourceResponse> updateActivity(
122+
TurnContext context,
123+
Activity activity
124+
);
114125

115126
/**
116127
* When overridden in a derived class, deletes an existing activity in the
117128
* conversation.
118129
*
119130
* @param context The context object for the turn.
120131
* @param reference Conversation reference for the activity to delete.
121-
* @return A task that represents the work queued to execute.
122-
* The {@link ConversationReference#getActivityId} of the conversation
123-
* reference identifies the activity to delete.
124-
* {@link TurnContext#onDeleteActivity(DeleteActivityHandler)}
132+
* @return A task that represents the work queued to execute. The
133+
* {@link ConversationReference#getActivityId} of the conversation
134+
* reference identifies the activity to delete.
135+
* {@link TurnContext#onDeleteActivity(DeleteActivityHandler)}
125136
*/
126-
public abstract CompletableFuture<Void> deleteActivity(TurnContext context, ConversationReference reference);
137+
public abstract CompletableFuture<Void> deleteActivity(
138+
TurnContext context,
139+
ConversationReference reference
140+
);
127141

128142
/**
129143
* Starts activity processing for the current bot turn.
130144
*
131-
* The adapter calls middleware in the order in which you added it.
132-
* The adapter passes in the context object for the turn and a next delegate,
133-
* and the middleware calls the delegate to pass control to the next middleware
134-
* in the pipeline. Once control reaches the end of the pipeline, the adapter calls
135-
* the {@code callback} method. If a middleware component does not call
136-
* the next delegate, the adapter does not call any of the subsequent middleware’s
137-
* {@link Middleware#onTurn(TurnContext, NextDelegate)}
138-
* methods or the callback method, and the pipeline short circuits.
145+
* The adapter calls middleware in the order in which you added it. The adapter
146+
* passes in the context object for the turn and a next delegate, and the
147+
* middleware calls the delegate to pass control to the next middleware in the
148+
* pipeline. Once control reaches the end of the pipeline, the adapter calls the
149+
* {@code callback} method. If a middleware component does not call the next
150+
* delegate, the adapter does not call any of the subsequent middleware’s
151+
* {@link Middleware#onTurn(TurnContext, NextDelegate)} methods or the callback
152+
* method, and the pipeline short circuits.
139153
*
140-
* <p>When the turn is initiated by a user activity (reactive messaging), the
154+
* <p>
155+
* When the turn is initiated by a user activity (reactive messaging), the
141156
* callback method will be a reference to the bot's
142-
* {@link Bot#onTurn(TurnContext)} method. When the turn is
143-
* initiated by a call to {@link #continueConversation(String, ConversationReference, BotCallbackHandler)}
144-
* (proactive messaging), the callback method is the callback method that was provided in the call.</p>
157+
* {@link Bot#onTurn(TurnContext)} method. When the turn is initiated by a call
158+
* to
159+
* {@link #continueConversation(String, ConversationReference, BotCallbackHandler)}
160+
* (proactive messaging), the callback method is the callback method that was
161+
* provided in the call.
162+
* </p>
145163
*
146164
* @param context The turn's context object.
147165
* @param callback A callback method to run at the end of the pipeline.
148166
* @return A task that represents the work queued to execute.
149167
* @throws NullPointerException {@code context} is null.
150168
*/
151-
protected CompletableFuture<Void> runPipeline(TurnContext context, BotCallbackHandler callback) {
169+
protected CompletableFuture<Void> runPipeline(
170+
TurnContext context,
171+
BotCallbackHandler callback
172+
) {
152173
BotAssert.contextNotNull(context);
153174

154175
// Call any registered Middleware Components looking for ReceiveActivity()
@@ -175,24 +196,30 @@ protected CompletableFuture<Void> runPipeline(TurnContext context, BotCallbackHa
175196
* Sends a proactive message to a conversation.
176197
*
177198
* @param botAppId The application ID of the bot. This parameter is ignored in
178-
* single tenant the Adapters (Console, Test, etc) but is critical to the BotFrameworkAdapter
179-
* which is multi-tenant aware.
199+
* single tenant the Adapters (Console, Test, etc) but is
200+
* critical to the BotFrameworkAdapter which is multi-tenant
201+
* aware.
180202
* @param reference A reference to the conversation to continue.
181203
* @param callback The method to call for the resulting bot turn.
182-
* @return A task that represents the work queued to execute.
183-
* Call this method to proactively send a message to a conversation.
184-
* Most channels require a user to initiate a conversation with a bot
185-
* before the bot can send activities to the user.
204+
* @return A task that represents the work queued to execute. Call this method
205+
* to proactively send a message to a conversation. Most channels
206+
* require a user to initiate a conversation with a bot before the bot
207+
* can send activities to the user.
186208
*
187-
* {@link #runPipeline(TurnContext, BotCallbackHandler)}
209+
* {@link #runPipeline(TurnContext, BotCallbackHandler)}
188210
*/
189-
public CompletableFuture<Void> continueConversation(String botAppId,
190-
ConversationReference reference,
191-
BotCallbackHandler callback) {
211+
public CompletableFuture<Void> continueConversation(
212+
String botAppId,
213+
ConversationReference reference,
214+
BotCallbackHandler callback
215+
) {
192216

193217
CompletableFuture<Void> pipelineResult = new CompletableFuture<>();
194218

195-
try (TurnContextImpl context = new TurnContextImpl(this, reference.getContinuationActivity())) {
219+
try (TurnContextImpl context = new TurnContextImpl(
220+
this,
221+
reference.getContinuationActivity()
222+
)) {
196223
pipelineResult = runPipeline(context, callback);
197224
} catch (Exception e) {
198225
pipelineResult.completeExceptionally(e);

0 commit comments

Comments
 (0)