Skip to content

Commit 781989b

Browse files
authored
Merge pull request #6032 from microsoft/run-configuration/refactor
[Task #1890183] Migrate to web app deployment configuration panel in run configuration panel
2 parents 4e063c1 + 7fc0235 commit 781989b

File tree

15 files changed

+236
-666
lines changed

15 files changed

+236
-666
lines changed

PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.webapp/src/com/microsoft/azuretools/webapp/ui/AppServiceCreateDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ protected void fillJavaVersion() {
11211121
private void recordUserSettings() {
11221122
try {
11231123
CommonUtils.setPreference(CommonUtils.SUBSCRIPTION, getSelectedItem(comboSubscription));
1124-
CommonUtils.setPreference(CommonUtils.RUNTIME_OS, model.getOS().toString());
1124+
CommonUtils.setPreference(CommonUtils.RUNTIME_OS, model.getOperatingSystem());
11251125
CommonUtils.setPreference(CommonUtils.RUNTIME_LINUX, getSelectedItem(comboLinuxRuntime));
11261126
CommonUtils.setPreference(CommonUtils.RUNTIME_JAVAVERSION, getSelectedItem(cbJavaVersion));
11271127
CommonUtils.setPreference(CommonUtils.RUNTIME_WEBCONTAINER, getSelectedItem(comboWebContainer));

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ public void setArtifact(@Nullable final AzureArtifact azureArtifact) {
5656
this.setValue(new ItemReference<>(artifact -> artifactManager.equalsAzureArtifact(cachedArtifact, artifact)));
5757
}
5858

59+
@Override
60+
public AzureArtifact getValue() {
61+
if (value instanceof ItemReference && ((ItemReference<?>) value).is(cachedArtifact)) {
62+
return cachedArtifact;
63+
}
64+
return super.getValue();
65+
}
66+
5967
@Nonnull
6068
@Override
6169
@AzureOperation(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public abstract class AzureComboBox<T> extends ComboBox<T> implements AzureFormI
5353
private final TailingDebouncer refresher;
5454
private AzureComboBoxEditor loadingSpinner;
5555
private AzureComboBoxEditor inputEditor;
56-
private Object value;
5756
private boolean valueNotSet = true;
5857
private boolean isRefreshing = false;
58+
protected Object value;
5959
protected boolean enabled = true;
6060
@Getter
6161
@Setter

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public T getValue() {
9090
final Runtime platform = this.selectorRuntime.getValue();
9191
final AzureArtifact artifact = this.selectorApplication.getValue();
9292

93-
final T result = (T) (this.config == null ? initConfig() : this.config).toBuilder().build();
93+
final T result = (T) (this.config == null ? initConfig() : this.config);
9494
result.setName(name);
9595
result.setRuntime(platform);
9696

@@ -129,8 +129,7 @@ public void setValue(final T config) {
129129
public List<AzureFormInput<?>> getInputs() {
130130
final AzureFormInput<?>[] inputs = {
131131
this.textName,
132-
this.selectorRuntime,
133-
this.selectorApplication
132+
this.selectorRuntime
134133
};
135134
return Arrays.asList(inputs);
136135
}

PluginsAndFeatures/azure-toolkit-for-intellij/src/main/java/com/microsoft/azure/toolkit/intellij/webapp/runner/webappconfig/WebAppRunState.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.microsoft.azuretools.utils.WebAppUtils;
3030
import com.microsoft.intellij.RunProcessHandler;
3131
import org.apache.commons.collections4.MapUtils;
32+
import org.apache.commons.compress.utils.FileNameUtils;
3233
import org.apache.commons.lang3.StringUtils;
3334
import org.jetbrains.annotations.NotNull;
3435
import org.jetbrains.annotations.Nullable;
@@ -49,6 +50,7 @@
4950
import static com.microsoft.intellij.ui.messages.AzureBundle.message;
5051

5152
public class WebAppRunState extends AzureRunProfileState<IAppService> {
53+
private File artifact;
5254
private WebAppConfiguration webAppConfiguration;
5355
private final IntelliJWebAppSettingModel webAppSettingModel;
5456

@@ -65,14 +67,13 @@ public WebAppRunState(Project project, WebAppConfiguration webAppConfiguration)
6567
@Override
6668
@AzureOperation(name = "webapp.deploy_artifact", params = {"this.webAppConfiguration.getWebAppName()"}, type = AzureOperation.Type.ACTION)
6769
public IAppService executeSteps(@NotNull RunProcessHandler processHandler, @NotNull Operation operation) throws Exception {
68-
File file = new File(getTargetPath());
69-
if (!file.exists()) {
70-
throw new FileNotFoundException(message("webapp.deploy.error.noTargetFile", file.getAbsolutePath()));
70+
artifact = new File(getTargetPath());
71+
if (!artifact.exists()) {
72+
throw new FileNotFoundException(message("webapp.deploy.error.noTargetFile", artifact.getAbsolutePath()));
7173
}
72-
webAppConfiguration.setTargetName(file.getName());
7374
final IWebAppBase deployTarget = getOrCreateDeployTargetFromAppSettingModel(processHandler);
7475
updateApplicationSettings(deployTarget, processHandler);
75-
AzureWebAppMvpModel.getInstance().deployArtifactsToWebApp(deployTarget, file, webAppSettingModel.isDeployToRoot(), processHandler);
76+
AzureWebAppMvpModel.getInstance().deployArtifactsToWebApp(deployTarget, artifact, webAppSettingModel.isDeployToRoot(), processHandler);
7677
return deployTarget;
7778
}
7879

@@ -118,9 +119,8 @@ protected void onSuccess(IAppService result, @NotNull RunProcessHandler processH
118119
AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, result));
119120
}
120121
updateConfigurationDataModel(result);
121-
int indexOfDot = webAppSettingModel.getTargetName().lastIndexOf(".");
122-
final String fileName = webAppSettingModel.getTargetName().substring(0, indexOfDot);
123-
final String fileType = webAppSettingModel.getTargetName().substring(indexOfDot + 1);
122+
final String fileName = FileNameUtils.getBaseName(artifact.getName());
123+
final String fileType = FileNameUtils.getExtension(artifact.getName());
124124
final String url = getUrl(result, fileName, fileType);
125125
processHandler.setText(message("appService.deploy.hint.succeed"));
126126
processHandler.setText("URL: " + url);

PluginsAndFeatures/azure-toolkit-for-intellij/src/main/java/com/microsoft/azure/toolkit/intellij/webapp/runner/webappconfig/slimui/AppServiceComboBox.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.microsoft.azure.toolkit.lib.webapp.WebAppService;
1919
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
2020
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
21+
import lombok.Setter;
2122
import org.apache.commons.lang3.StringUtils;
2223
import rx.Subscription;
2324

@@ -31,6 +32,7 @@ public abstract class AppServiceComboBox<T extends AppServiceConfig> extends Azu
3132
protected Project project;
3233
protected Subscription subscription;
3334

35+
@Setter
3436
protected T configModel;
3537

3638
public AppServiceComboBox(final Project project) {
@@ -39,19 +41,11 @@ public AppServiceComboBox(final Project project) {
3941
this.setRenderer(new AppComboBoxRender());
4042
}
4143

42-
@Override
43-
public void setValue(T value) {
44-
if (isDraftResource(value)) {
45-
configModel = value;
46-
}
47-
super.setValue(value);
48-
}
49-
5044
@NotNull
5145
@Override
5246
protected List<? extends T> loadItems() throws Exception {
5347
final List<T> items = loadAppServiceModels();
54-
if (configModel != null && StringUtils.isEmpty(configModel.getResourceId())) {
48+
if (isDraftResource(configModel)) {
5549
final boolean exist = items.stream().anyMatch(item -> AppServiceConfig.isSameApp(item, configModel));
5650
if (!exist) {
5751
items.add(configModel);
@@ -60,6 +54,14 @@ protected List<? extends T> loadItems() throws Exception {
6054
return items;
6155
}
6256

57+
@Override
58+
public T getValue() {
59+
if (value instanceof ItemReference && ((ItemReference<?>) value).is(configModel)) {
60+
return configModel;
61+
}
62+
return super.getValue();
63+
}
64+
6365
protected abstract List<T> loadAppServiceModels() throws Exception;
6466

6567
@Nullable
@@ -116,6 +118,6 @@ private String getAppServiceLabel(AppServiceConfig appServiceModel) {
116118
}
117119

118120
private static boolean isDraftResource(final AppServiceConfig config) {
119-
return StringUtils.isEmpty(config.getResourceId());
121+
return config != null && StringUtils.isEmpty(config.getResourceId());
120122
}
121123
}

PluginsAndFeatures/azure-toolkit-for-intellij/src/main/java/com/microsoft/azure/toolkit/intellij/webapp/runner/webappconfig/slimui/WebAppDeployConfigurationPanel.java

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@
1111
import com.intellij.ui.HideableDecorator;
1212
import com.intellij.ui.HyperlinkLabel;
1313
import com.microsoft.azure.toolkit.ide.appservice.model.AzureArtifactConfig;
14+
import com.microsoft.azure.toolkit.ide.appservice.model.DeploymentSlotConfig;
1415
import com.microsoft.azure.toolkit.ide.appservice.webapp.model.WebAppConfig;
1516
import com.microsoft.azure.toolkit.ide.appservice.webapp.model.WebAppDeployRunConfigurationModel;
1617
import com.microsoft.azure.toolkit.intellij.common.AzureArtifact;
1718
import com.microsoft.azure.toolkit.intellij.common.AzureArtifactComboBox;
1819
import com.microsoft.azure.toolkit.intellij.common.AzureArtifactManager;
1920
import com.microsoft.azure.toolkit.intellij.common.AzureArtifactType;
21+
import com.microsoft.azure.toolkit.intellij.common.AzureComboBox;
2022
import com.microsoft.azure.toolkit.intellij.common.AzureFormPanel;
2123
import com.microsoft.azure.toolkit.lib.Azure;
2224
import com.microsoft.azure.toolkit.lib.appservice.AzureWebApp;
25+
import com.microsoft.azure.toolkit.lib.appservice.model.Runtime;
2326
import com.microsoft.azure.toolkit.lib.appservice.model.WebContainer;
2427
import com.microsoft.azure.toolkit.lib.appservice.service.IWebAppDeploymentSlot;
2528
import com.microsoft.azure.toolkit.lib.common.form.AzureFormInput;
@@ -38,7 +41,10 @@
3841
import java.awt.event.FocusEvent;
3942
import java.awt.event.FocusListener;
4043
import java.awt.event.MouseEvent;
44+
import java.text.DateFormat;
45+
import java.text.SimpleDateFormat;
4146
import java.util.Arrays;
47+
import java.util.Date;
4248
import java.util.List;
4349
import java.util.Objects;
4450
import java.util.Optional;
@@ -82,14 +88,16 @@ public class WebAppDeployConfigurationPanel extends JPanel implements AzureFormP
8288
public WebAppDeployConfigurationPanel(@NotNull Project project) {
8389
super();
8490
this.project = project;
91+
$$$setupUI$$$();
92+
comboBoxWebApp.addItemListener(e -> loadDeploymentSlot(getSelectedWebApp()));
93+
comboBoxArtifact.addItemListener(e -> chkToRoot.setVisible(isAbleToDeployToRoot(comboBoxArtifact.getValue())));
8594

8695
final ButtonGroup slotButtonGroup = new ButtonGroup();
8796
slotButtonGroup.add(rbtNewSlot);
8897
slotButtonGroup.add(rbtExistingSlot);
89-
rbtExistingSlot.addActionListener(e -> toggleSlotType(true));
90-
rbtNewSlot.addActionListener(e -> toggleSlotType(false));
91-
92-
chkDeployToSlot.addActionListener(e -> toggleSlotPanel(chkDeployToSlot.isSelected()));
98+
rbtExistingSlot.addItemListener(e -> toggleSlotType(true));
99+
rbtNewSlot.addItemListener(e -> toggleSlotType(false));
100+
chkDeployToSlot.addItemListener(e -> toggleSlotPanel(chkDeployToSlot.isSelected()));
93101

94102
final Icon informationIcon = AllIcons.General.ContextHelp;
95103
btnSlotHover.setIcon(informationIcon);
@@ -120,14 +128,13 @@ public void focusLost(FocusEvent focusEvent) {
120128
lblArtifact.setLabelFor(comboBoxArtifact);
121129
lblWebApp.setLabelFor(comboBoxWebApp);
122130

131+
final DateFormat df = new SimpleDateFormat("yyMMddHHmmss");
132+
txtNewSlotName.setText(String.format(DEFAULT_SLOT_NAME, df.format(new Date())));
133+
123134
slotDecorator = new HideableDecorator(pnlSlotHolder, DEPLOYMENT_SLOT, true);
124135
slotDecorator.setContentComponent(pnlSlot);
125136
}
126137

127-
public void toggleSlotVisibility(final boolean visible) {
128-
slotDecorator.setOn(visible);
129-
}
130-
131138
private void setComboBoxDefaultValue(JComboBox comboBox, Object value) {
132139
UIUtils.listComboBoxItems(comboBox).stream().filter(item -> item.equals(value)).findFirst().ifPresent(defaultItem -> comboBox.setSelectedItem(value));
133140
}
@@ -141,10 +148,11 @@ private boolean isAbleToDeployToRoot(final AzureArtifact azureArtifact) {
141148
if (selectedWebApp == null || azureArtifact == null) {
142149
return false;
143150
}
144-
final WebContainer webContainer = selectedWebApp.getRuntime().getWebContainer();
151+
final String webContainer = Optional.ofNullable(selectedWebApp.getRuntime())
152+
.map(Runtime::getWebContainer).map(WebContainer::getValue).orElse(null);
145153
final String packaging = AzureArtifactManager.getInstance(project).getPackaging(azureArtifact);
146154
final boolean isDeployingWar = StringUtils.equalsAnyIgnoreCase(packaging, MavenConstants.TYPE_WAR, "ear");
147-
return isDeployingWar && StringUtils.containsAnyIgnoreCase(webContainer.getValue(), "tomcat", "jboss");
155+
return isDeployingWar && StringUtils.containsAnyIgnoreCase(webContainer, "tomcat", "jboss");
148156
}
149157

150158
private void toggleSlotPanel(boolean slot) {
@@ -173,7 +181,6 @@ private void createUIComponents() {
173181
lblNewSlot.addHyperlinkListener(e -> rbtNewSlot.doClick());
174182

175183
comboBoxWebApp = new WebAppComboBox(project);
176-
comboBoxWebApp.addItemListener(e -> loadDeploymentSlot(getSelectedWebApp()));
177184
comboBoxWebApp.refreshItems();
178185

179186
comboBoxArtifact = new AzureArtifactComboBox(this.project);
@@ -220,26 +227,57 @@ private synchronized void fillDeploymentSlots(List<IWebAppDeploymentSlot> slotLi
220227
@Override
221228
public void setValue(WebAppDeployRunConfigurationModel data) {
222229
// artifact
223-
Optional.ofNullable(data.getArtifactConfig()).map(config -> AzureArtifactManager.getInstance(this.project)
224-
.getAzureArtifactById(AzureArtifactType.valueOf(config.getArtifactType()), config.getArtifactIdentifier()))
230+
Optional.ofNullable(data.getArtifactConfig())
231+
.filter(config -> !StringUtils.isAnyEmpty(config.getArtifactIdentifier(), config.getArtifactType()))
232+
.map(config -> AzureArtifactManager.getInstance(this.project)
233+
.getAzureArtifactById(AzureArtifactType.valueOf(config.getArtifactType()), config.getArtifactIdentifier()))
225234
.ifPresent(artifact -> comboBoxArtifact.setArtifact(artifact));
226235
// web app
227-
Optional.ofNullable(data.getWebAppConfig()).ifPresent(webApp -> comboBoxWebApp.setValue(webApp));
236+
Optional.ofNullable(data.getWebAppConfig()).ifPresent(webApp -> {
237+
comboBoxWebApp.setConfigModel(webApp);
238+
comboBoxWebApp.setValue(new AzureComboBox.ItemReference<>(item -> WebAppConfig.isSameApp(item, webApp)));
239+
toggleSlotPanel(webApp.getDeploymentSlot() != null);
240+
Optional.ofNullable(webApp.getDeploymentSlot()).ifPresent(slot -> {
241+
chkDeployToSlot.setSelected(true);
242+
rbtNewSlot.setSelected(slot.isNewCreate());
243+
rbtExistingSlot.setSelected(!slot.isNewCreate());
244+
toggleSlotType(!slot.isNewCreate());
245+
if (slot.isNewCreate()) {
246+
txtNewSlotName.setText(slot.getName());
247+
cbxSlotConfigurationSource.addItem(slot.getConfigurationSource());
248+
cbxSlotConfigurationSource.setSelectedItem(slot.getConfigurationSource());
249+
} else {
250+
cbxSlotName.addItem(slot.getName());
251+
cbxSlotName.setSelectedItem(slot.getName());
252+
}
253+
});
254+
});
228255
// configuration
229256
chkToRoot.setSelected(data.isDeployToRoot());
230257
chkOpenBrowser.setSelected(data.isOpenBrowserAfterDeployment());
258+
slotDecorator.setOn(data.isSlotPanelVisible());
231259
}
232260

233261
@Override
234262
public WebAppDeployRunConfigurationModel getValue() {
235263
final AzureArtifact artifact = comboBoxArtifact.getValue();
236-
final AzureArtifactConfig artifactConfig = AzureArtifactConfig.builder().artifactType(artifact.getType().name())
237-
.artifactIdentifier(AzureArtifactManager.getInstance(project).getArtifactIdentifier(artifact)).build();
264+
final AzureArtifactConfig artifactConfig = artifact == null ? null :
265+
AzureArtifactConfig.builder().artifactType(artifact.getType().name())
266+
.artifactIdentifier(AzureArtifactManager.getInstance(project).getArtifactIdentifier(artifact)).build();
267+
final DeploymentSlotConfig slotConfig = chkDeployToSlot.isSelected() ? rbtExistingSlot.isSelected() ?
268+
DeploymentSlotConfig.builder().newCreate(false).name(Objects.toString(cbxSlotName.getSelectedItem(), null)).build() :
269+
DeploymentSlotConfig.builder().newCreate(true).name(txtNewSlotName.getText())
270+
.configurationSource(Objects.toString(cbxSlotConfigurationSource.getSelectedItem(), null)).build() : null;
271+
final WebAppConfig webAppConfig = comboBoxWebApp.getValue();
272+
if (webAppConfig != null) {
273+
webAppConfig.setDeploymentSlot(slotConfig);
274+
}
238275
return WebAppDeployRunConfigurationModel.builder()
239-
.webAppConfig(comboBoxWebApp.getValue())
276+
.webAppConfig(webAppConfig)
240277
.artifactConfig(artifactConfig)
241278
.openBrowserAfterDeployment(chkOpenBrowser.isSelected())
242279
.deployToRoot(chkToRoot.isSelected())
280+
.slotPanelVisible(slotDecorator.isExpanded())
243281
.build();
244282
}
245283

PluginsAndFeatures/azure-toolkit-for-intellij/src/main/java/com/microsoft/azure/toolkit/intellij/webapp/runner/webappconfig/slimui/WebAppDeployMvpViewSlim.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

PluginsAndFeatures/azure-toolkit-for-intellij/src/main/java/com/microsoft/azure/toolkit/intellij/webapp/runner/webappconfig/slimui/WebAppDeployViewPresenterSlim.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)