<commit_before>/*
 * Copyright 2000-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.appengine.actions;

import com.intellij.appengine.cloud.AppEngineCloudType;
import com.intellij.appengine.cloud.AppEngineServerConfiguration;
import com.intellij.appengine.facet.AppEngineFacet;
import com.intellij.execution.ProgramRunnerUtil;
import com.intellij.execution.RunnerAndConfigurationSettings;
import com.intellij.execution.executors.DefaultRunExecutor;
import com.intellij.facet.ProjectFacetManager;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.remoteServer.configuration.RemoteServer;
import com.intellij.remoteServer.configuration.RemoteServersManager;
import com.intellij.remoteServer.configuration.deployment.DeploymentConfigurationManager;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * @author nik
 */
public class UploadApplicationAction extends AnAction {
  public static final String LAST_RUN_CONFIGURATION_PROPERTY = "JAVA_APP_ENGINE_LAST_RUN_CONFIGURATION";

  @Override
  public void update(AnActionEvent e) {
    final Project project = e.getProject();
    e.getPresentation().setEnabledAndVisible(
      project != null && !ProjectFacetManager.getInstance(project).getFacets(AppEngineFacet.ID).isEmpty());

    if (project != null) {
      String text;
      RunnerAndConfigurationSettings configurationToRun = getConfigurationToRun(project);
      if (configurationToRun == null) {
        text = getTemplatePresentation().getText();
      }
      else {
        text = "Upload App Engine Application '" + configurationToRun.getName() + "'";
      }
      e.getPresentation().setText(text);
    }
  }

  @Nullable
  private static RunnerAndConfigurationSettings getConfigurationToRun(@NotNull Project project) {
    List<RunnerAndConfigurationSettings> configurations = DeploymentConfigurationManager.getInstance(project).getDeploymentConfigurations(AppEngineCloudType.getInstance());<commit_msg>IDEA-140785 Replace check getFacets().size() > 0 with hasFacet() which stops on first match<commit_after>/*
 * Copyright 2000-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.appengine.actions;

import com.intellij.appengine.cloud.AppEngineCloudType;
import com.intellij.appengine.cloud.AppEngineServerConfiguration;
import com.intellij.appengine.facet.AppEngineFacet;
import com.intellij.execution.ProgramRunnerUtil;
import com.intellij.execution.RunnerAndConfigurationSettings;
import com.intellij.execution.executors.DefaultRunExecutor;
import com.intellij.facet.ProjectFacetManager;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.remoteServer.configuration.RemoteServer;
import com.intellij.remoteServer.configuration.RemoteServersManager;
import com.intellij.remoteServer.configuration.deployment.DeploymentConfigurationManager;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * @author nik
 */
public class UploadApplicationAction extends AnAction {
  public static final String LAST_RUN_CONFIGURATION_PROPERTY = "JAVA_APP_ENGINE_LAST_RUN_CONFIGURATION";

  @Override
  public void update(AnActionEvent e) {
    final Project project = e.getProject();
    e.getPresentation().setEnabledAndVisible(
      project != null && ProjectFacetManager.getInstance(project).hasFacets(AppEngineFacet.ID));

    if (project != null) {
      String text;
      RunnerAndConfigurationSettings configurationToRun = getConfigurationToRun(project);
      if (configurationToRun == null) {
        text = getTemplatePresentation().getText();
      }
      else {
        text = "Upload App Engine Application '" + configurationToRun.getName() + "'";
      }
      e.getPresentation().setText(text);
    }
  }

  @Nullable
  private static RunnerAndConfigurationSettings getConfigurationToRun(@NotNull Project project) {
    List<RunnerAndConfigurationSettings> configurations = DeploymentConfigurationManager.getInstance(project).getDeploymentConfigurations(AppEngineCloudType.getInstance());
{'fraction_non_alphanumeric': 0.08829208355274706, 'fraction_numerical': 0.0054414604177637355, 'mean_word_length': 5.303097345132743, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5330241', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1532, 'n_words': 370}