package jetbrains.buildServer.autotools.server;

import java.util.HashMap;
import java.util.Map;
import jetbrains.buildServer.serverSide.PropertiesProcessor;
import jetbrains.buildServer.serverSide.RunType;
import jetbrains.buildServer.serverSide.RunTypeRegistry;
import jetbrains.buildServer.web.openapi.PluginDescriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static jetbrains.buildServer.autotools.common.AutotoolsBuildConstants.*;

/**
 * Created on 12.07.2017.
 * @author     : Nadezhda Demina
 */
public class AutotoolsBuildRunType extends RunType{

  /**
   * Descriptor for AutotoolsRunnerPlugin
   */
  private final PluginDescriptor myPluginDescriptor;
  public AutotoolsBuildRunType(@NotNull final RunTypeRegistry runTypeRegistry, @NotNull final PluginDescriptor descriptor) {
    runTypeRegistry.registerRunType(this);
    myPluginDescriptor = descriptor;
  }

  @NotNull
  @Override
  public String getType() {
    return TYPE;
  }

  @NotNull
  @Override
  public String getDisplayName() {
    return DISPLAY_NAME;
  }

  @NotNull
  @Override
  public String getDescription() {
    return DESCRIPTION;
  }

  @Nullable
  @Override
  public PropertiesProcessor getRunnerPropertiesProcessor() {
    return null;
  }


  @Override
  public String getEditRunnerParamsJspFilePath() {
    return myPluginDescriptor.getPluginResourcesPath("editAutotoolsBuildRunner.jsp");
  }

  @Override
  public String getViewRunnerParamsJspFilePath() {
    return myPluginDescriptor.getPluginResourcesPath("viewAutotoolsBuildRunner.jsp");
  }

  @NotNull
  @Override
  public Map<String, String> getDefaultRunnerProperties() {

    final Map<String, String> properties = new HashMap<>();
    properties.put(UI_NEED_AUTORECONF, Boolean.toString(true));
    properties.put(UI_ADDITIONAL_MAKE_PARAMS, "all");
    properties.put(UI_ADDITIONAL_CONF_PARAMS, "");
    properties.put(UI_MAKE_CHECK, "check");
    properties.put(UI_NEED_DEJAGNU_VALID_XML, Boolean.toString(true));
    return properties;
  }
}

@@ -59,23 +59,17 @@
 va.util.
-HashMap
+*
 ;%0Aimport
@@ -74,20 +74,112 @@
 rt j
-ava.util.Map
+etbrains.buildServer.requirements.Requirement;%0Aimport jetbrains.buildServer.requirements.RequirementType
 ;%0Aim
@@ -1002,35 +1002,24 @@
 iptor;%0A  %7D%0A%0A
-  @NotNull%0A
   @Override%0A
@@ -1010,32 +1010,43 @@
  %7D%0A%0A  @Override%0A
+  @NotNull%0A
   public String 
@@ -2095,24 +2095,24 @@
 ing(true));%0A
-
     return p
@@ -2125,11 +2125,553 @@
 ies;%0A  %7D
+%0A%0A  @NotNull%0A  @Override%0A  public List%3CRequirement%3E getRunnerSpecificRequirements(@NotNull Map%3CString, String%3E runParameters) %7B%0A    final List%3CRequirement%3E requirements = new LinkedList%3C%3E();%0A    requirements.add(new Requirement(TOOL_AUTOCONF, null, RequirementType.EXISTS));%0A    requirements.add(new Requirement(TOOL_MAKE, null, RequirementType.EXISTS));%0A    requirements.add(new Requirement(TOOL_TAR, null, RequirementType.EXISTS));%0A    requirements.add(new Requirement(TOOL_GZIP, null, RequirementType.EXISTS));%0A    return requirements;%0A  %7D
 %0A%7D%0A

add tool requirements in autotools-server