Skip to content

Commit 8287340

Browse files
committed
Filter un-exist resources in app service combo box
1 parent 3a7b562 commit 8287340

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/appservice/AppServiceComboBox.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import com.intellij.ui.SimpleListCellRenderer;
1111
import com.intellij.ui.components.fields.ExtendableTextComponent;
1212
import com.microsoft.azure.toolkit.intellij.common.AzureComboBox;
13+
import com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion;
14+
import com.microsoft.azure.toolkit.lib.appservice.model.Runtime;
15+
import com.microsoft.azure.toolkit.lib.appservice.service.IAppService;
1316
import com.microsoft.azure.toolkit.lib.webapp.WebAppService;
1417
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
1518
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
@@ -19,6 +22,7 @@
1922
import javax.swing.*;
2023
import java.util.List;
2124
import java.util.Objects;
25+
import java.util.Optional;
2226

2327
public abstract class AppServiceComboBox<T extends AppServiceComboBoxModel> extends AzureComboBox<T> {
2428

@@ -71,6 +75,17 @@ protected String getItemText(final Object item) {
7175
}
7276
}
7377

78+
protected boolean isJavaAppService(IAppService appService) {
79+
try {
80+
return Optional.ofNullable(appService.getRuntime()).map(Runtime::getJavaVersion)
81+
.map(javaVersion -> !Objects.equals(javaVersion, JavaVersion.OFF))
82+
.orElse(false);
83+
} catch (final RuntimeException e) {
84+
// app service may have been removed while parsing, return false in this case
85+
return false;
86+
}
87+
}
88+
7489
protected abstract void createResource();
7590

7691
public static class AppComboBoxRender extends SimpleListCellRenderer {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.microsoft.azure.toolkit.intellij.appservice.AppServiceComboBox;
1010
import com.microsoft.azure.toolkit.lib.Azure;
1111
import com.microsoft.azure.toolkit.lib.appservice.AzureAppService;
12-
import com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion;
1312
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
1413
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
1514
import com.microsoft.tooling.msservices.components.DefaultLoader;
@@ -44,7 +43,7 @@ protected void createResource() {
4443
)
4544
protected List<FunctionAppComboBoxModel> loadAppServiceModels() {
4645
return Azure.az(AzureAppService.class).functionApps().parallelStream()
47-
.filter(functionApp -> functionApp.getRuntime().getJavaVersion() != JavaVersion.OFF)
46+
.filter(this::isJavaAppService)
4847
.map(FunctionAppComboBoxModel::new)
4948
.sorted((app1, app2) -> app1.getAppName().compareToIgnoreCase(app2.getAppName()))
5049
.collect(Collectors.toList());

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/webapp/WebAppComboBox.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ protected void createResource() {
4949
)
5050
protected List<WebAppComboBoxModel> loadAppServiceModels() {
5151
final List<IWebApp> webApps = Azure.az(AzureAppService.class).webapps(false);
52-
return webApps.stream()
53-
.filter(webApp -> webApp.getRuntime().getJavaVersion() != null && webApp.getRuntime().getJavaVersion() != JavaVersion.OFF)
54-
.sorted((a, b) -> a.name().compareToIgnoreCase(b.name()))
55-
.map(WebAppComboBoxModel::new)
56-
.collect(Collectors.toList());
52+
return webApps.stream().parallel()
53+
.filter(this::isJavaAppService)
54+
.sorted((a, b) -> a.name().compareToIgnoreCase(b.name()))
55+
.map(WebAppComboBoxModel::new)
56+
.collect(Collectors.toList());
5757
}
5858
}

0 commit comments

Comments
 (0)