4040import com .intellij .psi .PsiManager ;
4141import com .intellij .psi .xml .XmlFile ;
4242import com .intellij .psi .xml .XmlTag ;
43+ import com .intellij .remoteServer .configuration .deployment .ArtifactDeploymentSource ;
4344import com .intellij .remoteServer .configuration .deployment .DeploymentSource ;
4445import com .intellij .remoteServer .configuration .deployment .ModuleDeploymentSource ;
4546import 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