Skip to content

Commit 24cd40f

Browse files
committed
Merge branch 'endgame-s187' into develop.next
2 parents 103136f + 41f04b6 commit 24cd40f

File tree

26 files changed

+174
-117
lines changed

26 files changed

+174
-117
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common/survey/CustomerSurveyManager.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,12 @@ private void updateSurveyStatus(ICustomerSurvey survey, CustomerSurveyResponse r
114114
if (response == CustomerSurveyResponse.NEVER_SHOW_AGAIN) {
115115
customerSurveyConfiguration.setAcceptSurvey(false);
116116
} else {
117-
final int delay = response == CustomerSurveyResponse.ACCEPT ? TAKE_SURVEY_DELAY_BY_DAY : PUT_OFF_DELAY_BY_DAY;
118117
final CustomerSurveyConfiguration.CustomerSurveyStatus surveyStatus = getSurveyStatus(survey);
119-
surveyStatus.setSurveyTimes(surveyStatus.getSurveyTimes() + 1);
120-
surveyStatus.setLastSurveyDate(LocalDateTime.now());
118+
if (response == CustomerSurveyResponse.ACCEPT) {
119+
surveyStatus.setSurveyTimes(surveyStatus.getSurveyTimes() + 1);
120+
surveyStatus.setLastSurveyDate(LocalDateTime.now());
121+
}
122+
final int delay = response == CustomerSurveyResponse.ACCEPT ? TAKE_SURVEY_DELAY_BY_DAY : PUT_OFF_DELAY_BY_DAY;
121123
surveyStatus.setNextSurveyDate(LocalDateTime.now().plusDays(delay * 2));
122124
customerSurveyConfiguration.getSurveyStatus().stream()
123125
.filter(status -> !StringUtils.equalsIgnoreCase(status.getType(), survey.getType()))

PluginsAndFeatures/azure-toolkit-for-intellij/resources/com/microsoft/intellij/ui/messages/messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,7 @@ function.create.hint.created=Function app ({0}) created.
13901390
function.create.hint.startCreateFunction=The specified function app does not exist. Creating a new function app...
13911391
function.create.hint.functionCreated=Successfully created function app ({0})
13921392
function.create.error.targetExists=Failed to create function app ({0}), target function app already exists.
1393-
function.create.error.createApplicationInsightsFailed=Failed to create application insights for function app ({0})
1393+
function.create.error.createApplicationInsightsFailed=Skip binding application insights as failed to create insight instance for function app ({0})
13941394
function.create.error.dockerNotSupport=The 'docker' runtime is not supported in current version.
13951395
function.create.error.invalidRuntime=Unsupported runtime {0}
13961396
function.create.dialog.title=Create Function

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/arm/CreateDeploymentForm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ protected void doOKAction() {
148148
.withNewResourceGroup(rgNameTextFiled.getText(),
149149
com.microsoft.azure.management.resources.fluentcore.arm.Region.fromName(region.getName()));
150150
} else {
151-
ResourceGroup rg = ((ResourceEx<ResourceGroup>) rgNameCb.getSelectedItem()).getResource();
151+
ResourceGroup rg = (ResourceGroup) rgNameCb.getSelectedItem();
152152
List<ResourceEx<Deployment>> deployments = AzureMvpModel.getInstance()
153153
.getDeploymentByRgName(subs.getId(), rg.getName());
154154
boolean isExist = deployments.parallelStream()

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/database/PasswordUtils.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo;
1111
import org.apache.commons.lang3.CharUtils;
1212
import org.apache.commons.lang3.StringUtils;
13-
import org.apache.commons.text.similarity.LongestCommonSubsequence;
1413

1514
import javax.swing.*;
1615
import java.util.Arrays;
@@ -73,11 +72,10 @@ private static AzureValidationInfo validatePassword(String password, String user
7372
.type(AzureValidationInfo.Type.ERROR).build();
7473
}
7574
// validate longest common subsequence between username and password.
76-
LongestCommonSubsequence algorithm = new LongestCommonSubsequence();
77-
int longestCommonSubsequenceLength = algorithm.apply(username, password);
75+
int longestCommonSubstringLength = longestCommonSubstringLength(username, password);
7876
int usernameLength = StringUtils.length(username);
79-
if ((usernameLength > 0 && longestCommonSubsequenceLength == usernameLength)
80-
|| longestCommonSubsequenceLength >= LONGEST_COMMON_SUBSEQUENCE_BETWEEN_NAME_AND_PASSWORD) {
77+
if ((usernameLength > 0 && longestCommonSubstringLength == usernameLength)
78+
|| longestCommonSubstringLength >= LONGEST_COMMON_SUBSEQUENCE_BETWEEN_NAME_AND_PASSWORD) {
8179
final AzureValidationInfo.AzureValidationInfoBuilder builder = AzureValidationInfo.builder();
8280
return builder.input(input).message("Your password cannot contain all or part of the login name." +
8381
" Part of a login name is defined as three or more consecutive alphanumeric characters.")
@@ -86,6 +84,25 @@ private static AzureValidationInfo validatePassword(String password, String user
8684
return AzureValidationInfo.OK;
8785
}
8886

87+
private static int longestCommonSubstringLength(String left, String right) {
88+
if (StringUtils.isAnyBlank(left, right)) {
89+
return 0;
90+
}
91+
int max = 0;
92+
final int[][] dp = new int[left.length() + 1][right.length() + 1];
93+
for (int i = 0; i < left.length(); i++) {
94+
for (int j = 0; j < right.length(); j++) {
95+
if (left.charAt(i) == right.charAt(j)) {
96+
dp[i + 1][j + 1] = dp[i][j] + 1;
97+
} else {
98+
dp[i + 1][j + 1] = 0;
99+
}
100+
max = Math.max(max, dp[i + 1][j + 1]);
101+
}
102+
}
103+
return max;
104+
}
105+
89106
private static int countCharacterCategories(final String value) {
90107
final Boolean[] categories = new Boolean[] {false, false, false, false};
91108
for (char ch : value.toCharArray()) {

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/database/RegionComboBox.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public class RegionComboBox extends AzureComboBox<Region> {
2828
@Setter
2929
private Function<RegionComboBox, AzureValidationInfo> validateFunction;
3030

31-
private boolean validated;
32-
private boolean loaded;
31+
private boolean validateRequired;
32+
private boolean itemLoaded;
3333
private AzureValidationInfo validatedInfo;
3434

3535
public void setSubscription(Subscription subscription) {
@@ -55,7 +55,7 @@ protected List<? extends Region> loadItems() {
5555
return new ArrayList<>();
5656
}
5757
List<? extends Region> regions = Azure.az(AzureAccount.class).listRegions(subscription.getId());
58-
loaded = true;
58+
itemLoaded = true;
5959
return regions;
6060
}
6161

@@ -71,7 +71,7 @@ protected String getItemText(Object item) {
7171
public void setSelectedItem(Object value) {
7272
if (!Objects.equals(value, getSelectedItem())) {
7373
super.setSelectedItem(value);
74-
validated = false;
74+
validateRequired = true;
7575
} else {
7676
super.setSelectedItem(value);
7777
}
@@ -85,17 +85,17 @@ public boolean isRequired() {
8585
@NotNull
8686
@Override
8787
public AzureValidationInfo doValidate() {
88-
if (Objects.isNull(subscription) || !loaded) {
89-
return AzureValidationInfo.OK;
88+
if (Objects.isNull(subscription) || !itemLoaded) {
89+
return AzureValidationInfo.UNINITIALIZED;
9090
}
91-
if (validated && Objects.nonNull(validatedInfo)) {
92-
return validatedInfo;
91+
if (!validateRequired) {
92+
return Objects.nonNull(validatedInfo) ? validatedInfo : AzureValidationInfo.UNINITIALIZED;
9393
}
9494
validatedInfo = super.doValidate();
9595
if (AzureValidationInfo.OK.equals(validatedInfo)) {
9696
validatedInfo = validateFunction.apply(this);
9797
}
98-
validated = true;
98+
validateRequired = false;
9999
return validatedInfo;
100100
}
101101

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/database/ServerNameTextField.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public void setSubscriptionId(String subscriptionId) {
3636
@Override
3737
@NotNull
3838
public AzureValidationInfo doValidateValue() {
39+
if (StringUtils.isBlank(subscriptionId)) {
40+
return AzureValidationInfo.UNINITIALIZED;
41+
}
3942
final AzureValidationInfo info = super.doValidateValue();
4043
if (!AzureValidationInfo.OK.equals(info)) {
4144
return info;

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/function/action/CreateFunctionAppAction.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@
55

66
package com.microsoft.azure.toolkit.intellij.function.action;
77

8-
import com.intellij.notification.Notification;
9-
import com.intellij.notification.NotificationType;
10-
import com.intellij.notification.Notifications;
118
import com.intellij.openapi.progress.ProgressIndicator;
129
import com.intellij.openapi.progress.ProgressManager;
1310
import com.intellij.openapi.project.Project;
1411
import com.microsoft.azure.management.appservice.FunctionApp;
12+
import com.microsoft.azure.toolkit.intellij.common.messager.IntellijAzureMessager;
1513
import com.microsoft.azure.toolkit.intellij.function.FunctionAppCreationDialog;
1614
import com.microsoft.azure.toolkit.lib.common.exception.AzureExceptionHandler;
1715
import com.microsoft.azure.toolkit.lib.common.exception.AzureExceptionHandler.AzureExceptionAction;
16+
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
1817
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
1918
import com.microsoft.azure.toolkit.lib.common.operation.IAzureOperationTitle;
2019
import com.microsoft.azure.toolkit.lib.common.task.AzureTask;
2120
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
2221
import com.microsoft.azure.toolkit.lib.function.FunctionAppConfig;
2322
import com.microsoft.azure.toolkit.lib.function.FunctionAppService;
2423
import com.microsoft.azuretools.authmanage.AuthMethodManager;
24+
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
2525
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
26-
import com.microsoft.intellij.actions.AzureSignInAction;
2726
import com.microsoft.azuretools.utils.AzureUIRefreshCore;
2827
import com.microsoft.azuretools.utils.AzureUIRefreshEvent;
28+
import com.microsoft.intellij.actions.AzureSignInAction;
2929
import com.microsoft.intellij.util.AzureLoginHelper;
3030
import com.microsoft.tooling.msservices.helpers.Name;
3131
import com.microsoft.tooling.msservices.serviceexplorer.AzureActionEnum;
@@ -92,13 +92,20 @@ private void openDialog(final Project project, @Nullable final FunctionAppConfig
9292
@AzureOperation(name = "function.create_detail", params = {"config.getName()"}, type = AzureOperation.Type.ACTION)
9393
private Single<FunctionApp> createFunctionApp(final FunctionAppConfig config) {
9494
final IAzureOperationTitle title = title("function.create_detail", config.getName());
95+
final IntellijAzureMessager actionMessenger = new IntellijAzureMessager() {
96+
@Override
97+
public void info(@NotNull String message, String title) {
98+
// swallow info notification for action
99+
}
100+
};
95101
final AzureTask<FunctionApp> task = new AzureTask<>(null, title, false, () -> {
102+
AzureMessager.getContext().setMessager(actionMessenger);
96103
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
97104
indicator.setIndeterminate(true);
98105
return functionAppService.createFunctionApp(config);
99106
});
100107
return AzureTaskManager.getInstance().runInModalAsObservable(task).toSingle().doOnSuccess(app -> {
101-
this.notifyCreationSuccess(app);
108+
AzureMessager.getMessager().success(message("function.create.success.message", app.name()), message("function.create.success.title"));
102109
this.refreshAzureExplorer(app);
103110
});
104111
}
@@ -111,11 +118,4 @@ private void refreshAzureExplorer(FunctionApp app) {
111118
}
112119
});
113120
}
114-
115-
private void notifyCreationSuccess(final FunctionApp app) {
116-
final String title = message("function.create.success.title");
117-
final String message = message("function.create.success.message", app.name());
118-
final Notification notification = new Notification(NOTIFICATION_GROUP_ID, title, message, NotificationType.INFORMATION);
119-
Notifications.Bus.notify(notification);
120-
}
121121
}

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/function/runner/deploy/FunctionDeploymentState.java

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55

66
package com.microsoft.azure.toolkit.intellij.function.runner.deploy;
77

8+
import com.intellij.execution.process.ProcessOutputTypes;
89
import com.intellij.openapi.project.Project;
910
import com.intellij.psi.PsiMethod;
11+
import com.microsoft.azure.toolkit.intellij.common.messager.IntellijAzureMessager;
12+
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
1013
import com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionConfiguration;
1114
import com.microsoft.azure.management.appservice.AppServicePlan;
1215
import com.microsoft.azure.management.appservice.FunctionApp;
@@ -27,10 +30,12 @@
2730
import com.microsoft.azuretools.utils.AzureUIRefreshCore;
2831
import com.microsoft.azuretools.utils.AzureUIRefreshEvent;
2932
import com.microsoft.intellij.RunProcessHandler;
33+
import lombok.RequiredArgsConstructor;
3034
import org.apache.commons.lang.StringUtils;
3135
import org.jetbrains.annotations.NotNull;
3236
import org.jetbrains.annotations.Nullable;
3337

38+
import javax.annotation.Nonnull;
3439
import java.io.File;
3540
import java.io.IOException;
3641
import java.nio.file.Path;
@@ -57,6 +62,8 @@ public FunctionDeploymentState(Project project, FunctionDeployConfiguration func
5762
@Override
5863
@AzureOperation(name = "function.deploy.state", type = AzureOperation.Type.ACTION)
5964
public WebAppBase executeSteps(@NotNull RunProcessHandler processHandler, @NotNull Operation operation) throws Exception {
65+
final FunctionDeploymentMessenger messenger = new FunctionDeploymentMessenger(processHandler);
66+
AzureMessager.getContext().setMessager(messenger);
6067
// Update run time information by function app
6168
final FunctionApp functionApp;
6269
if (deployModel.isNewResource()) {
@@ -73,11 +80,7 @@ public WebAppBase executeSteps(@NotNull RunProcessHandler processHandler, @NotNu
7380
stagingFolder = FunctionUtils.getTempStagingFolder();
7481
deployModel.setDeploymentStagingDirectoryPath(stagingFolder.getPath());
7582
prepareStagingFolder(stagingFolder, processHandler, operation);
76-
final DeployFunctionHandler deployFunctionHandler = new DeployFunctionHandler(deployModel, message -> {
77-
if (processHandler.isProcessRunning()) {
78-
processHandler.setText(message);
79-
}
80-
}, operation);
83+
final DeployFunctionHandler deployFunctionHandler = new DeployFunctionHandler(deployModel, operation);
8184
return deployFunctionHandler.execute();
8285
}
8386

@@ -151,4 +154,32 @@ protected void onFail(@NotNull Throwable error, @NotNull RunProcessHandler proce
151154
protected Map<String, String> getTelemetryMap() {
152155
return functionDeployConfiguration.getModel().getTelemetryProperties();
153156
}
157+
158+
// todo: create shared run state messenger for all run states
159+
@RequiredArgsConstructor
160+
private static class FunctionDeploymentMessenger extends IntellijAzureMessager {
161+
private final RunProcessHandler processHandler;
162+
163+
@Override
164+
public void info(@Nonnull String message, String title) {
165+
processHandler.setText(message);
166+
}
167+
168+
@Override
169+
public void success(@Nonnull String message, String title) {
170+
processHandler.println(message, ProcessOutputTypes.SYSTEM);
171+
super.success(message, title);
172+
}
173+
174+
@Override
175+
public void error(@Nonnull String message, String title) {
176+
processHandler.println(message, ProcessOutputTypes.STDERR);
177+
super.error(message, title);
178+
}
179+
180+
@Override
181+
public void warning(@Nonnull String message, String title) {
182+
processHandler.setText(message);
183+
}
184+
}
154185
}

0 commit comments

Comments
 (0)