PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/atlassian/bamboo/plugin/dotnet/support/DotNetTestConfigurationHelper.java

https://bitbucket.org/atlassian/bamboo-dotnet-plugin/
Java | 99 lines | 73 code | 15 blank | 11 comment | 6 complexity | c45bd5226407b6c53d1cc5d8fc0cc4c4 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. package com.atlassian.bamboo.plugin.dotnet.support;
  2. import com.atlassian.bamboo.configuration.ConfigurationMap;
  3. import com.atlassian.bamboo.configuration.ConfigurationMapImpl;
  4. import com.atlassian.bamboo.plugin.dotnet.tests.mbunit.MBUnitCollectorTaskType;
  5. import com.atlassian.bamboo.plugin.dotnet.tests.mstest.MSTestCollectorTaskType;
  6. import com.atlassian.bamboo.plugin.dotnet.tests.mstest.MSTestRunnerTaskType;
  7. import com.atlassian.bamboo.plugin.dotnet.tests.nunit.NUnitCollectorTaskType;
  8. import com.atlassian.bamboo.plugin.dotnet.visualstudio.DevenvToVisualStudioTaskConverter;
  9. import com.atlassian.bamboo.task.TaskConfigConstants;
  10. import com.atlassian.bamboo.task.TaskDefinition;
  11. import com.atlassian.bamboo.task.TaskDefinitionImpl;
  12. import com.atlassian.bamboo.task.conversion.LegacyBuilderToTaskConverter;
  13. import com.atlassian.bamboo.task.conversion.TaskIdSupplier;
  14. import com.atlassian.core.util.map.EasyMap;
  15. import com.atlassian.util.concurrent.Supplier;
  16. import com.google.common.collect.Lists;
  17. import org.apache.log4j.Logger;
  18. import org.jetbrains.annotations.NotNull;
  19. import java.util.List;
  20. import java.util.Map;
  21. /**
  22. * Helper for {@link LegacyBuilderToTaskConverter} that transforms the test component of legacy builder configurations
  23. */
  24. public class DotNetTestConfigurationHelper
  25. {
  26. private static final Logger log = Logger.getLogger(DotNetTestConfigurationHelper.class);
  27. // ------------------------------------------------------------------------------------------------------- Constants
  28. private static final String NUNIT_TEST_CHECKED = "dotNetTestChecked";
  29. private static final String MBUNIT_TEST_CHECKED = "mbunitTestChecked";
  30. private static final String MSBUILD_TEST_CHECKED = "mstestTestChecked";
  31. private static final String MSBUILD_RUN_TEST_CHECKED = "mstestRunTests";
  32. private static final String NUNIT_PLUGIN_KEY = "com.atlassian.bamboo.plugin.dotnet:nunit";
  33. private static final String MBUNIT_PLUGIN_KEY = "com.atlassian.bamboo.plugin.dotnet:mbunit";
  34. private static final String MSTEST_PLUGIN_KEY = "com.atlassian.bamboo.plugin.dotnet:mstest";
  35. private static final String MSTEST_RUNNER_PLUGIN_KEY = "com.atlassian.bamboo.plugin.dotnet:mstestRunner";
  36. // ------------------------------------------------------------------------------------------------- Type Properties
  37. // ---------------------------------------------------------------------------------------------------- Dependencies
  38. // ---------------------------------------------------------------------------------------------------- Constructors
  39. private DotNetTestConfigurationHelper()
  40. {
  41. }
  42. // ----------------------------------------------------------------------------------------------- Interface Methods
  43. // -------------------------------------------------------------------------------------------------- Action Methods
  44. public static List<TaskDefinition> convertPossibleTestIntegrations(final TaskIdSupplier taskIdSupplier, final String pluginKey, final Map<String, String> map)
  45. {
  46. final ConfigurationMap config = new ConfigurationMapImpl(map);
  47. final List<TaskDefinition> definitions = Lists.newLinkedList();
  48. if (config.getAsBoolean(NUNIT_TEST_CHECKED))
  49. {
  50. final String directory = config.get(NUnitCollectorTaskType.TEST_DIRECTORY);
  51. final String workingDirectory = config.get(TaskConfigConstants.CFG_WORKING_SUB_DIRECTORY);
  52. definitions.add(createTaskDefinition(taskIdSupplier, NUNIT_PLUGIN_KEY, EasyMap.build(NUnitCollectorTaskType.TEST_DIRECTORY, directory,
  53. TaskConfigConstants.CFG_WORKING_SUB_DIRECTORY, workingDirectory)));
  54. }
  55. if (config.getAsBoolean(MBUNIT_TEST_CHECKED))
  56. {
  57. final String directory = config.get(MBUnitCollectorTaskType.TEST_DIRECTORY);
  58. definitions.add(createTaskDefinition(taskIdSupplier, MBUNIT_PLUGIN_KEY, EasyMap.build(MBUnitCollectorTaskType.TEST_DIRECTORY, directory)));
  59. }
  60. if (config.getAsBoolean(MSBUILD_RUN_TEST_CHECKED) && config.getAsBoolean(MSBUILD_TEST_CHECKED))
  61. {
  62. final String label = pluginKey.equals(DevenvToVisualStudioTaskConverter.PLUGIN_KEY) ? config.get(MSTestRunnerTaskType.LABEL) : null;
  63. final String container = config.get(MSTestRunnerTaskType.CONTAINER);
  64. final String runConfig = config.get(MSTestRunnerTaskType.RUN_CONFIG);
  65. final String directory = config.get(MSTestCollectorTaskType.TEST_DIRECTORY);
  66. definitions.add(createTaskDefinition(taskIdSupplier, MSTEST_RUNNER_PLUGIN_KEY, EasyMap.build(MSTestRunnerTaskType.LABEL, label,
  67. MSTestRunnerTaskType.CONTAINER, container,
  68. MSTestRunnerTaskType.RUN_CONFIG, runConfig,
  69. MSTestRunnerTaskType.RESULTS_FILE, directory)));
  70. }
  71. else if (config.getAsBoolean(MSBUILD_TEST_CHECKED))
  72. {
  73. final String directory = config.get(MSTestCollectorTaskType.TEST_DIRECTORY);
  74. definitions.add(createTaskDefinition(taskIdSupplier, MSTEST_PLUGIN_KEY, EasyMap.build(MSTestCollectorTaskType.TEST_DIRECTORY, directory)));
  75. }
  76. return definitions;
  77. }
  78. // -------------------------------------------------------------------------------------------------- Public Methods
  79. // -------------------------------------------------------------------------------------- Basic Accessors / Mutators
  80. private static TaskDefinition createTaskDefinition(@NotNull TaskIdSupplier taskIdSupplier, @NotNull String pluginKey, Map<String, String> config)
  81. {
  82. return new TaskDefinitionImpl(taskIdSupplier.get(), pluginKey, null, config, true);
  83. }
  84. }