Skip to content

Commit 2cf5193

Browse files
authored
Identify and properly label all compat projects (#753)
1 parent 3c8a0c7 commit 2cf5193

File tree

3 files changed

+86
-21
lines changed

3 files changed

+86
-21
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ plugin.compatibility.error.update.link=Please {0}click here{1} to ensure that yo
2323

2424
appengine.name=App Engine (BETA)
2525
appengine.environment.name.flexible=App Engine flexible
26+
appengine.environment.name.mvm=App Engine MVM
2627
appengine.environment.name.standard=App Engine standard
2728
appengine.tools.menu.item.label=Deploy to App Engine...
2829
appengine.version.label=Version\:

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.intellij.openapi.util.text.StringUtil;
4747
import com.intellij.openapi.vfs.LocalFileSystem;
4848
import com.intellij.openapi.vfs.VirtualFile;
49+
import com.intellij.psi.xml.XmlTag;
4950
import com.intellij.remoteServer.configuration.deployment.DeploymentSource;
5051
import com.intellij.ui.DocumentAdapter;
5152
import com.intellij.ui.awt.RelativePoint;
@@ -78,6 +79,7 @@
7879
*/
7980
public class AppEngineDeploymentRunConfigurationEditor extends
8081
SettingsEditor<AppEngineDeploymentConfiguration> {
82+
private Project project;
8183

8284
private JComboBox configTypeComboBox;
8385
private JPanel appEngineConfigFilesPanel;
@@ -113,6 +115,7 @@ public AppEngineDeploymentRunConfigurationEditor(
113115
final Project project,
114116
final AppEngineDeployable deploymentSource,
115117
final AppEngineHelper appEngineHelper) {
118+
this.project = project;
116119
this.deploymentSource = deploymentSource;
117120

118121
versionIdField.setPlaceholderText(GctBundle.message("appengine.flex.version.placeholder.text"));
@@ -122,7 +125,7 @@ public AppEngineDeploymentRunConfigurationEditor(
122125

123126
environment = deploymentSource.getEnvironment();
124127

125-
if (environment == AppEngineEnvironment.APP_ENGINE_FLEX) {
128+
if (environment.isFlexible()) {
126129
appEngineCostWarningLabel.setText(
127130
GctBundle.message("appengine.flex.deployment.cost.warning",
128131
COST_WARNING_OPEN_TAG,
@@ -131,8 +134,10 @@ public AppEngineDeploymentRunConfigurationEditor(
131134
COST_WARNING_CLOSE_TAG));
132135
appEngineCostWarningLabel.addHyperlinkListener(new BrowserOpeningHyperLinkListener());
133136
appEngineCostWarningLabel.setBackground(editorPanel.getBackground());
137+
environmentLabel.setText(getEnvironmentDisplayableLabel());
134138
} else {
135139
appEngineCostWarningLabel.setVisible(false);
140+
environmentLabel.setText(environment.localizedLabel());
136141
}
137142

138143
configTypeComboBox.setModel(new DefaultComboBoxModel(ConfigType.values()));
@@ -214,7 +219,6 @@ public File get() {
214219
versionOverrideCheckBox.addItemListener(
215220
new CustomFieldOverrideListener(versionOverrideCheckBox, versionIdField));
216221

217-
environmentLabel.setText(environment.localizedLabel());
218222
appEngineFlexConfigPanel.setVisible(
219223
environment == AppEngineEnvironment.APP_ENGINE_FLEX
220224
&& !AppEngineUtil.isFlexCompat(project, deploymentSource));
@@ -278,6 +282,23 @@ void setProjectSelector(ProjectSelector projectSelector) {
278282
this.projectSelector = projectSelector;
279283
}
280284

285+
/**
286+
* If a project's appengine-web.xml contains <env>flex</env> then we want to override
287+
* the default localized label of the environment
288+
*/
289+
private String getEnvironmentDisplayableLabel() {
290+
XmlTag compatConfig = AppEngineUtil.getFlexCompatXmlConfiguration(project, deploymentSource);
291+
292+
if (compatConfig != null) {
293+
if ("env".equalsIgnoreCase(compatConfig.getName())
294+
&& "flex".equalsIgnoreCase(compatConfig.getValue().getTrimmedText())) {
295+
return GctBundle.message("appengine.environment.name.mvm");
296+
}
297+
}
298+
299+
return environment.localizedLabel();
300+
}
301+
281302
private void updateJarWarSelector() {
282303
userSpecifiedArtifactPanel.setVisible(isUserSpecifiedPathDeploymentSource());
283304
}

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

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.intellij.psi.PsiManager;
4141
import com.intellij.psi.xml.XmlFile;
4242
import com.intellij.psi.xml.XmlTag;
43+
import com.intellij.remoteServer.configuration.deployment.ArtifactDeploymentSource;
4344
import com.intellij.remoteServer.configuration.deployment.DeploymentSource;
4445
import com.intellij.remoteServer.configuration.deployment.ModuleDeploymentSource;
4546
import com.intellij.util.xml.DomFileElement;
@@ -130,30 +131,25 @@ && isJarOrWarMavenBuild(project, module)) {
130131
}
131132

132133
/**
133-
* Determines if a project is set up like an App Engine standard project but is configured
134-
* in 'compatibility' mode. This indicates that the project runs in the flexible environment.
134+
* Returns the xml tag corresponding to the project's appengine-web.xml compat configuration
135+
* or null if there isn't one.
135136
*/
136-
public static boolean isFlexCompat(@NotNull Project project, @NotNull DeploymentSource source) {
137-
Artifact artifact;
138-
if (source instanceof AppEngineArtifactDeploymentSource) {
139-
artifact = ((AppEngineArtifactDeploymentSource) source).getArtifact();
140-
if (artifact != null) {
141-
return isFlexCompat(project, artifact);
142-
}
143-
}
144-
145-
return false;
137+
@Nullable
138+
public static XmlTag getFlexCompatXmlConfiguration(@NotNull Project project,
139+
@NotNull DeploymentSource source) {
140+
return getFlexCompatXmlConfiguration(project, getArtifact(source));
146141
}
147142

148-
private static boolean isFlexCompat(@NotNull Project project,
149-
@NotNull Artifact artifact) {
150-
if (!isAppEngineStandardArtifact(project, artifact)) {
151-
return false;
143+
@Nullable
144+
private static XmlTag getFlexCompatXmlConfiguration(@NotNull Project project,
145+
@Nullable Artifact artifact) {
146+
147+
if (artifact == null || !isAppEngineStandardArtifact(project, artifact)) {
148+
return null;
152149
}
153150

154151
XmlFile webXml = loadAppEngineStandardWebXml(project, artifact);
155152

156-
boolean isVmTrue = false;
157153
if (webXml != null) {
158154
DomManager manager = DomManager.getDomManager(project);
159155
DomFileElement element = manager.getFileElement(webXml);
@@ -163,13 +159,60 @@ private static boolean isFlexCompat(@NotNull Project project,
163159
if (root != null) {
164160
XmlTag vmTag = root.findFirstSubTag("vm");
165161
if (vmTag != null) {
166-
isVmTrue = Boolean.parseBoolean(vmTag.getValue().getTrimmedText());
162+
return vmTag;
163+
} else {
164+
return root.findFirstSubTag("env");
167165
}
168166
}
169167
}
170168
}
171169

172-
return isVmTrue;
170+
return null;
171+
}
172+
173+
/**
174+
* Determines if a project is set up like an App Engine standard project but is configured
175+
* in 'compatibility' mode. This indicates that the project runs in the flexible environment.
176+
*
177+
* <p>A flex compat project has an appengine-web.xml with either:
178+
* {@code
179+
* <vm>true</vm>
180+
* <env>flex</env>
181+
* }
182+
*/
183+
public static boolean isFlexCompat(@NotNull Project project, @NotNull DeploymentSource source) {
184+
return isFlexCompat(project, getArtifact(source));
185+
}
186+
187+
private static boolean isFlexCompat(@NotNull Project project, @Nullable Artifact artifact) {
188+
if (artifact == null) {
189+
return false;
190+
}
191+
192+
XmlTag compatConfig = getFlexCompatXmlConfiguration(project, artifact);
193+
194+
if (compatConfig == null) {
195+
return false;
196+
}
197+
198+
String tagName = compatConfig.getName();
199+
200+
if ("vm".equalsIgnoreCase(tagName)) {
201+
return Boolean.parseBoolean(compatConfig.getValue().getTrimmedText());
202+
} else if ("env".equalsIgnoreCase(tagName)) {
203+
return "flex".equalsIgnoreCase(compatConfig.getValue().getTrimmedText());
204+
} else {
205+
return false;
206+
}
207+
}
208+
209+
@Nullable
210+
private static Artifact getArtifact(@NotNull DeploymentSource source) {
211+
if (source instanceof ArtifactDeploymentSource) {
212+
return ((ArtifactDeploymentSource) source).getArtifact();
213+
}
214+
215+
return null;
173216
}
174217

175218
private static AppEngineArtifactDeploymentSource createArtifactDeploymentSource(

0 commit comments

Comments
 (0)