public void configureConfiguration(
      SimpleProgramParameters parameters, CommonProgramRunConfigurationParameters configuration) {
    Project project = configuration.getProject();
    Module module = getModule(configuration);

    parameters
        .getProgramParametersList()
        .addParametersString(expandPath(configuration.getProgramParameters(), module, project));

    parameters.setWorkingDirectory(getWorkingDir(configuration, project, module));

    parameters.setupEnvs(configuration.getEnvs(), configuration.isPassParentEnvs());
    if (parameters.getEnv() != null) {
      Map<String, String> expanded = new HashMap<String, String>();
      for (Map.Entry<String, String> each : parameters.getEnv().entrySet()) {
        expanded.put(each.getKey(), expandPath(each.getValue(), module, project));
      }
      parameters.setEnv(expanded);
    }
  }
  @Nullable
  public String getWorkingDir(
      CommonProgramRunConfigurationParameters configuration, Project project, Module module) {
    String workingDirectory = configuration.getWorkingDirectory();
    String defaultWorkingDir = getDefaultWorkingDir(project);

    if (workingDirectory == null || workingDirectory.trim().length() == 0) {
      workingDirectory = defaultWorkingDir;
    }
    if (workingDirectory == null) return null;
    workingDirectory = expandPath(workingDirectory, module, project);
    if (!FileUtil.isAbsolute(workingDirectory) && defaultWorkingDir != null) {
      if (("$" + PathMacroUtil.MODULE_DIR_MACRO_NAME + "$").equals(workingDirectory)) {
        return defaultWorkingDir;
      }
      workingDirectory = defaultWorkingDir + "/" + workingDirectory;
    }
    return workingDirectory;
  }
 @Override
 protected void validateConfiguration(
     @NotNull RunConfigurationBase configuration, boolean isExecution) throws Exception {
   super.validateConfiguration(configuration, isExecution);
   if (configuration instanceof ModuleBasedConfiguration
       && configuration instanceof CommonProgramRunConfigurationParameters) {
     final String workingDirectory =
         ((CommonProgramRunConfigurationParameters) configuration).getWorkingDirectory();
     if (("$" + PathMacroUtil.MODULE_DIR_MACRO_NAME + "$").equals(workingDirectory)) {
       final RunConfigurationModule runConfigurationModule =
           ((ModuleBasedConfiguration) configuration).getConfigurationModule();
       final String projectPath =
           ExternalSystemApiUtil.getExternalProjectPath(runConfigurationModule.getModule());
       if (StringUtil.isNotEmpty(projectPath)) {
         ((CommonProgramRunConfigurationParameters) configuration)
             .setWorkingDirectory(projectPath);
       }
     }
   }
 }