Skip to content

Commit 4cfc8af

Browse files
authored
Remove old sdk from App Engine Standard new project wizard (#809)
1 parent 31e5d52 commit 4cfc8af

File tree

8 files changed

+73
-110
lines changed

8 files changed

+73
-110
lines changed

google-cloud-tools-plugin/resources/messages/CloudToolsBundle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ appengine.version.label=Version\:
3434
appengine.environment.label=Environment\:
3535
appengine.cloudsdk.location.label=Cloud SDK directory\:
3636
appengine.cloudsdk.location.browse.window.title=Browse to Cloud SDK directory
37-
appengine.cloudsdk.location.missing.message=Please select a Cloud SDK home directory.
37+
appengine.cloudsdk.location.invalid.message=No Cloud SDK was found in this directory.
38+
appengine.cloudsdk.location.missing.message=Cloud SDK home directory is not specified.
3839
appengine.appyaml.location.browse.window.title=Browse to your app.yaml location
3940
appengine.flex.configtype.auto.label=Auto
4041
appengine.flex.configtype.custom.label=Custom

google-cloud-tools-plugin/src/com/google/cloud/tools/intellij/appengine/cloud/AppEngineCloudConfigurable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void apply() throws ConfigurationException {
9393
if (StringUtil.isEmpty(cloudSdkPanel.getCloudSdkDirectory())
9494
|| !CloudSdkUtil.containsCloudSdkExecutable(cloudSdkPanel.getCloudSdkDirectory())) {
9595
throw new RuntimeConfigurationError(
96-
GctBundle.message("appengine.cloudsdk.location.missing.message"));
96+
GctBundle.message("appengine.cloudsdk.location.invalid.message"));
9797
} else {
9898
CloudSdkService.getInstance().setCloudSdkHomePath(cloudSdkPanel.getCloudSdkDirectory());
9999
}

google-cloud-tools-plugin/src/com/google/cloud/tools/intellij/appengine/facet/AppEngineSupportConfigurable.form

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.google.cloud.tools.intellij.appengine.facet.AppEngineSupportProvider.AppEngineSupportConfigurable">
3-
<grid id="7dca6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
3+
<grid id="7dca6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
6-
<xy x="20" y="20" width="500" height="85"/>
6+
<xy x="20" y="20" width="500" height="134"/>
77
</constraints>
88
<properties/>
99
<border type="none"/>
1010
<children>
1111
<grid id="27dc6" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
1212
<margin top="0" left="0" bottom="0" right="0"/>
1313
<constraints>
14-
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
14+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
1515
</constraints>
1616
<properties/>
1717
<border type="none"/>
@@ -39,22 +39,11 @@
3939
</component>
4040
</children>
4141
</grid>
42-
<grid id="9fcfc" binding="mySdkPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
43-
<constraints>
44-
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
45-
</constraints>
46-
<properties/>
47-
<border type="none"/>
48-
<children/>
49-
</grid>
50-
<grid id="2bae7" binding="myErrorPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
42+
<nested-form id="997ee" form-file="com/google/cloud/tools/intellij/appengine/sdk/CloudSdkPanel.form" binding="cloudSdkPanel" custom-create="true">
5143
<constraints>
52-
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
44+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
5345
</constraints>
54-
<properties/>
55-
<border type="none"/>
56-
<children/>
57-
</grid>
46+
</nested-form>
5847
</children>
5948
</grid>
6049
</form>

google-cloud-tools-plugin/src/com/google/cloud/tools/intellij/appengine/facet/AppEngineSupportProvider.java

Lines changed: 13 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717
package com.google.cloud.tools.intellij.appengine.facet;
1818

1919
import com.google.cloud.tools.intellij.appengine.sdk.AppEngineSdk;
20-
import com.google.cloud.tools.intellij.appengine.sdk.impl.AppEngineSdkUtil;
20+
import com.google.cloud.tools.intellij.appengine.sdk.CloudSdkPanel;
21+
import com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService;
2122
import com.google.cloud.tools.intellij.appengine.util.AppEngineUtilLegacy;
2223

2324
import com.intellij.facet.FacetManager;
2425
import com.intellij.facet.FacetType;
25-
import com.intellij.facet.ui.ValidationResult;
2626
import com.intellij.framework.FrameworkTypeEx;
2727
import com.intellij.framework.addSupport.FrameworkSupportInModuleConfigurable;
2828
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
29-
import com.intellij.icons.AllIcons;
3029
import com.intellij.ide.fileTemplates.FileTemplate;
3130
import com.intellij.ide.fileTemplates.FileTemplateManager;
3231
import com.intellij.ide.util.frameworkSupport.FrameworkSupportModel;
@@ -46,8 +45,6 @@
4645
import com.intellij.openapi.roots.libraries.LibraryTable;
4746
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
4847
import com.intellij.openapi.roots.ui.configuration.FacetsProvider;
49-
import com.intellij.openapi.ui.LabeledComponent;
50-
import com.intellij.openapi.util.text.StringUtil;
5148
import com.intellij.openapi.vfs.VfsUtil;
5249
import com.intellij.openapi.vfs.VfsUtilCore;
5350
import com.intellij.openapi.vfs.VirtualFile;
@@ -58,16 +55,12 @@
5855
import com.intellij.packaging.elements.ArtifactRootElement;
5956
import com.intellij.packaging.elements.PackagingElementFactory;
6057
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
61-
import com.intellij.ui.DocumentAdapter;
62-
import com.intellij.ui.HyperlinkLabel;
6358

6459
import org.jetbrains.annotations.NotNull;
6560
import org.jetbrains.annotations.Nullable;
6661
import org.jetbrains.annotations.TestOnly;
6762
import org.jetbrains.jps.appengine.model.PersistenceApi;
6863

69-
import java.awt.BorderLayout;
70-
import java.awt.Component;
7164
import java.io.IOException;
7265
import java.util.Collection;
7366
import java.util.Collections;
@@ -76,8 +69,6 @@
7669
import javax.swing.JComboBox;
7770
import javax.swing.JComponent;
7871
import javax.swing.JPanel;
79-
import javax.swing.event.DocumentEvent;
80-
import javax.swing.text.JTextComponent;
8172

8273
/**
8374
* @author nik
@@ -264,65 +255,24 @@ public FrameworkSupportInModuleConfigurable createConfigurable(
264255

265256
@TestOnly
266257
public static void setSdkPath(FrameworkSupportInModuleConfigurable configurable, String path) {
267-
((AppEngineSupportConfigurable) configurable).mySdkEditor.setPath(path);
258+
((AppEngineSupportConfigurable) configurable).cloudSdkPanel.setCloudSdkDirectoryText(path);
268259
}
269260

270261
private class AppEngineSupportConfigurable extends FrameworkSupportInModuleConfigurable implements
271262
FrameworkSupportModelListener {
272263

273264
private final FrameworkSupportModel myFrameworkSupportModel;
274265
private JPanel myMainPanel;
275-
private final AppEngineSdkEditor mySdkEditor;
276266
private JComboBox myPersistenceApiComboBox;
277-
private JPanel mySdkPanel;
278-
private final HyperlinkLabel myErrorLabel;
279-
private JPanel myErrorPanel;
267+
private CloudSdkPanel cloudSdkPanel;
280268

281269
private AppEngineSupportConfigurable(FrameworkSupportModel model) {
282270
myFrameworkSupportModel = model;
283-
mySdkEditor = new AppEngineSdkEditor(model.getProject());
284-
mySdkPanel
285-
.add(LabeledComponent.create(mySdkEditor.getMainComponent(), "Google App Engine SDK:"),
286-
BorderLayout.CENTER);
287271
PersistenceApiComboboxUtil.setComboboxModel(myPersistenceApiComboBox, true);
288272
if (model.isFrameworkSelected(JPA_FRAMEWORK_ID)) {
289273
myPersistenceApiComboBox.setSelectedItem(PersistenceApi.JPA.getDisplayName());
290274
}
291275
model.addFrameworkListener(this);
292-
293-
myErrorLabel = new HyperlinkLabel();
294-
myErrorLabel.setIcon(AllIcons.RunConfigurations.ConfigurationWarning);
295-
myErrorLabel.setVisible(false);
296-
myErrorLabel.setHyperlinkTarget(AppEngineSdkUtil.APP_ENGINE_DOWNLOAD_URL);
297-
myErrorPanel.add(BorderLayout.CENTER, myErrorLabel);
298-
299-
final Component component = mySdkEditor.getComboBox().getEditor().getEditorComponent();
300-
if (component instanceof JTextComponent) {
301-
((JTextComponent) component).getDocument().addDocumentListener(new DocumentAdapter() {
302-
@Override
303-
protected void textChanged(DocumentEvent event) {
304-
checkSdk();
305-
}
306-
});
307-
}
308-
checkSdk();
309-
}
310-
311-
private void checkSdk() {
312-
final String path = mySdkEditor.getPath();
313-
if (StringUtil.isEmptyOrSpaces(path)) {
314-
myErrorLabel.setVisible(true);
315-
myErrorLabel.setHyperlinkText("App Engine SDK path not specified. ", "Download", "");
316-
myMainPanel.repaint();
317-
return;
318-
}
319-
320-
final ValidationResult result = AppEngineSdkUtil.checkPath(path);
321-
myErrorLabel.setVisible(!result.isOk());
322-
if (!result.isOk()) {
323-
myErrorLabel.setText("App Engine SDK path is not correct");
324-
}
325-
myMainPanel.repaint();
326276
}
327277

328278
public void frameworkSelected(@NotNull FrameworkSupportProvider provider) {
@@ -345,8 +295,11 @@ public void wizardStepUpdated() {
345295
public void addSupport(@NotNull Module module,
346296
@NotNull ModifiableRootModel rootModel,
347297
@NotNull ModifiableModelsProvider modifiableModelsProvider) {
298+
CloudSdkService.getInstance().setCloudSdkHomePath(cloudSdkPanel.getCloudSdkDirectory());
299+
348300
AppEngineSupportProvider.this
349-
.addSupport(module, rootModel, myFrameworkSupportModel, mySdkEditor.getPath(),
301+
.addSupport(module, rootModel, myFrameworkSupportModel,
302+
cloudSdkPanel.getCloudSdkDirectory(),
350303
PersistenceApiComboboxUtil.getSelectedApi(myPersistenceApiComboBox));
351304
}
352305

@@ -355,5 +308,10 @@ public void addSupport(@NotNull Module module,
355308
public JComponent createComponent() {
356309
return myMainPanel;
357310
}
311+
312+
@SuppressWarnings("checkstyle:abbreviationaswordinname")
313+
private void createUIComponents() {
314+
cloudSdkPanel = new CloudSdkPanel(CloudSdkService.getInstance());
315+
}
358316
}
359317
}

google-cloud-tools-plugin/src/com/google/cloud/tools/intellij/appengine/sdk/CloudSdkPanel.form

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424
<component id="14e06" class="javax.swing.JLabel" binding="warningMessage">
2525
<constraints>
2626
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
27-
<preferred-size width="32" height="37"/>
27+
<preferred-size width="32" height="24"/>
2828
</grid>
2929
</constraints>
3030
<properties>
31-
<foreground color="-65536"/>
3231
<text value="Label"/>
3332
</properties>
3433
</component>

google-cloud-tools-plugin/src/com/google/cloud/tools/intellij/appengine/sdk/CloudSdkPanel.java

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.cloud.tools.intellij.util.GctBundle;
2222
import com.google.cloud.tools.intellij.util.SystemEnvironmentProvider;
2323

24+
import com.intellij.icons.AllIcons.RunConfigurations;
2425
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
2526
import com.intellij.openapi.options.ConfigurationException;
2627
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
@@ -46,6 +47,7 @@ public class CloudSdkPanel {
4647

4748
public CloudSdkPanel(@NotNull CloudSdkService cloudSdkService) {
4849
warningMessage.setVisible(false);
50+
warningMessage.setIcon(RunConfigurations.ConfigurationWarning);
4951

5052
if (cloudSdkService.getCloudSdkHomePath() == null) {
5153
final String cloudSdkDirectoryPath
@@ -65,7 +67,36 @@ public CloudSdkPanel(@NotNull CloudSdkService cloudSdkService) {
6567
);
6668

6769
cloudSdkDirectoryField.getTextField().getDocument()
68-
.addDocumentListener(new SdkDirectoryFieldListener());
70+
.addDocumentListener(new DocumentAdapter() {
71+
@Override
72+
protected void textChanged(DocumentEvent event) {
73+
checkSdk();
74+
}
75+
});
76+
77+
checkSdk();
78+
}
79+
80+
private void checkSdk() {
81+
String path = cloudSdkDirectoryField.getText();
82+
83+
if (StringUtil.isEmpty(path)) {
84+
warningMessage.setVisible(true);
85+
warningMessage.setText(
86+
GctBundle.message("appengine.cloudsdk.location.missing.message"));
87+
return;
88+
}
89+
90+
boolean isValid = CloudSdkUtil.containsCloudSdkExecutable(path);
91+
if (isValid) {
92+
cloudSdkDirectoryField.getTextField().setForeground(JBColor.black);
93+
warningMessage.setVisible(false);
94+
} else {
95+
cloudSdkDirectoryField.getTextField().setForeground(JBColor.red);
96+
warningMessage.setVisible(true);
97+
warningMessage.setText(
98+
GctBundle.message("appengine.cloudsdk.location.invalid.message"));
99+
}
69100
}
70101

71102
@VisibleForTesting
@@ -84,10 +115,7 @@ public boolean isModified() {
84115
}
85116

86117
public void apply() throws ConfigurationException {
87-
if (!StringUtil.isEmpty(getCloudSdkDirectory())
88-
&& CloudSdkUtil.containsCloudSdkExecutable(getCloudSdkDirectory())) {
89-
CloudSdkService.getInstance().setCloudSdkHomePath(getCloudSdkDirectory());
90-
}
118+
CloudSdkService.getInstance().setCloudSdkHomePath(getCloudSdkDirectory());
91119
}
92120

93121
public void reset() {
@@ -106,22 +134,4 @@ public void setCloudSdkDirectoryText(String path) {
106134
public JPanel getComponent() {
107135
return cloudSdkPanel;
108136
}
109-
110-
private class SdkDirectoryFieldListener extends DocumentAdapter {
111-
112-
@Override
113-
protected void textChanged(DocumentEvent event) {
114-
String path = cloudSdkDirectoryField.getText();
115-
boolean isValid = CloudSdkUtil.containsCloudSdkExecutable(path);
116-
if (isValid) {
117-
cloudSdkDirectoryField.getTextField().setForeground(JBColor.black);
118-
warningMessage.setVisible(false);
119-
} else {
120-
cloudSdkDirectoryField.getTextField().setForeground(JBColor.red);
121-
warningMessage.setVisible(true);
122-
warningMessage.setText(
123-
GctBundle.message("appengine.cloudsdk.location.missing.message"));
124-
}
125-
}
126-
}
127137
}

google-cloud-tools-plugin/testSrc/com/google/cloud/tools/intellij/appengine/cloud/AppEngineCloudConfigurableTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class AppEngineCloudConfigurableTest extends PlatformTestCase {
4343
private TextFieldWithBrowseButton cloudSdkDirectoryField;
4444

4545
private static final String CLOUD_SDK_DIR_PATH = new File("/a/b/c/gcloud-sdk").getAbsolutePath();
46-
private static final String MISSING_SDK_DIR_WARNING = "Please select a Cloud SDK home directory.";
46+
private static final String INVALID_SDK_DIR_WARNING = "No Cloud SDK was found in this directory.";
4747

4848
@Override
4949
public void setUp() throws Exception {
@@ -89,7 +89,7 @@ public void testApply_invalidSdk() {
8989
appEngineCloudConfigurable.apply();
9090
fail("Applying settings without a valid SDK should throw exception.");
9191
} catch (ConfigurationException ce) {
92-
assertEquals(MISSING_SDK_DIR_WARNING, ce.getMessage());
92+
assertEquals(INVALID_SDK_DIR_WARNING, ce.getMessage());
9393
}
9494
}
9595

google-cloud-tools-plugin/testSrc/com/google/cloud/tools/intellij/appengine/sdk/CloudSdkPanelTest.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@
2020
import static org.mockito.Mockito.mock;
2121
import static org.mockito.Mockito.when;
2222

23+
import com.google.cloud.tools.intellij.appengine.util.CloudSdkUtil;
2324
import com.google.cloud.tools.intellij.util.SystemEnvironmentProvider;
2425

2526
import com.intellij.openapi.application.ApplicationManager;
2627
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
2728
import com.intellij.testFramework.PlatformTestCase;
2829

30+
import org.junit.rules.TemporaryFolder;
2931
import org.picocontainer.MutablePicoContainer;
3032

3133
import java.io.File;
34+
import java.io.IOException;
3235

3336
import javax.swing.JLabel;
3437

@@ -45,10 +48,7 @@ public class CloudSdkPanelTest extends PlatformTestCase {
4548
private JLabel warningMessage;
4649
private TextFieldWithBrowseButton cloudSdkDirectoryField;
4750

48-
private static final String CLOUD_SDK_EXECUTABLE_PATH = new File("/a/b/c/gcloud-sdk/bin/gcloud").getAbsolutePath();
49-
private static final String CLOUD_SDK_DIR_PATH = new File("/a/b/c/gcloud-sdk").getAbsolutePath();
50-
51-
private static final String MISSING_SDK_DIR_WARNING = "Please select a Cloud SDK home directory.";
51+
private static final String INVALID_SDK_DIR_WARNING = "No Cloud SDK was found in this directory.";
5252

5353
@Override
5454
public void setUp() throws Exception {
@@ -73,17 +73,23 @@ public void testSetupWithoutSdkInPath() {
7373
when(environmentProvider.findInPath(anyString())).thenReturn(null);
7474
initCloudSdkPanel();
7575

76-
assertFalse(warningMessage.isVisible());
76+
assertTrue(warningMessage.isVisible());
7777
assertEmpty(cloudSdkDirectoryField.getText());
7878
}
7979

80-
public void testSetupWithSdkInPath() {
80+
public void testSetupWithSdkInPath() throws IOException {
81+
TemporaryFolder tempFolder = new TemporaryFolder();
82+
tempFolder.create();
83+
File executable = new File(tempFolder.newFolder("bin"), CloudSdkUtil.getSystemCommand());
84+
executable.createNewFile();
85+
8186
when(environmentProvider.findInPath(anyString()))
82-
.thenReturn(new File(CLOUD_SDK_EXECUTABLE_PATH));
87+
.thenReturn(executable);
8388
initCloudSdkPanel();
8489

8590
assertFalse(warningMessage.isVisible());
86-
assertEquals(CLOUD_SDK_DIR_PATH, cloudSdkDirectoryField.getText());
91+
assertEquals(CloudSdkUtil.toSdkHomeDirectory(executable.getPath()),
92+
cloudSdkDirectoryField.getText());
8793
}
8894

8995
public void testSetupWithInvalidSdk() {
@@ -93,7 +99,7 @@ public void testSetupWithInvalidSdk() {
9399
cloudSdkDirectoryField.setText("/some/invalid/path");
94100

95101
assertTrue(warningMessage.isVisible());
96-
assertEquals(MISSING_SDK_DIR_WARNING, warningMessage.getText());
102+
assertEquals(INVALID_SDK_DIR_WARNING, warningMessage.getText());
97103
}
98104

99105
public void testApplyWith_invalidSdk() throws Exception {

0 commit comments

Comments
 (0)