/src/main/java/com/atlassian/bamboo/plugin/dotnet/support/DotNetTestConfigurationHelper.java
Java | 99 lines | 73 code | 15 blank | 11 comment | 6 complexity | c45bd5226407b6c53d1cc5d8fc0cc4c4 MD5 | raw file
Possible License(s): BSD-3-Clause
- package com.atlassian.bamboo.plugin.dotnet.support;
- import com.atlassian.bamboo.configuration.ConfigurationMap;
- import com.atlassian.bamboo.configuration.ConfigurationMapImpl;
- import com.atlassian.bamboo.plugin.dotnet.tests.mbunit.MBUnitCollectorTaskType;
- import com.atlassian.bamboo.plugin.dotnet.tests.mstest.MSTestCollectorTaskType;
- import com.atlassian.bamboo.plugin.dotnet.tests.mstest.MSTestRunnerTaskType;
- import com.atlassian.bamboo.plugin.dotnet.tests.nunit.NUnitCollectorTaskType;
- import com.atlassian.bamboo.plugin.dotnet.visualstudio.DevenvToVisualStudioTaskConverter;
- import com.atlassian.bamboo.task.TaskConfigConstants;
- import com.atlassian.bamboo.task.TaskDefinition;
- import com.atlassian.bamboo.task.TaskDefinitionImpl;
- import com.atlassian.bamboo.task.conversion.LegacyBuilderToTaskConverter;
- import com.atlassian.bamboo.task.conversion.TaskIdSupplier;
- import com.atlassian.core.util.map.EasyMap;
- import com.atlassian.util.concurrent.Supplier;
- import com.google.common.collect.Lists;
- import org.apache.log4j.Logger;
- import org.jetbrains.annotations.NotNull;
- import java.util.List;
- import java.util.Map;
- /**
- * Helper for {@link LegacyBuilderToTaskConverter} that transforms the test component of legacy builder configurations
- */
- public class DotNetTestConfigurationHelper
- {
- private static final Logger log = Logger.getLogger(DotNetTestConfigurationHelper.class);
- // ------------------------------------------------------------------------------------------------------- Constants
- private static final String NUNIT_TEST_CHECKED = "dotNetTestChecked";
- private static final String MBUNIT_TEST_CHECKED = "mbunitTestChecked";
- private static final String MSBUILD_TEST_CHECKED = "mstestTestChecked";
- private static final String MSBUILD_RUN_TEST_CHECKED = "mstestRunTests";
- private static final String NUNIT_PLUGIN_KEY = "com.atlassian.bamboo.plugin.dotnet:nunit";
- private static final String MBUNIT_PLUGIN_KEY = "com.atlassian.bamboo.plugin.dotnet:mbunit";
- private static final String MSTEST_PLUGIN_KEY = "com.atlassian.bamboo.plugin.dotnet:mstest";
- private static final String MSTEST_RUNNER_PLUGIN_KEY = "com.atlassian.bamboo.plugin.dotnet:mstestRunner";
- // ------------------------------------------------------------------------------------------------- Type Properties
- // ---------------------------------------------------------------------------------------------------- Dependencies
- // ---------------------------------------------------------------------------------------------------- Constructors
- private DotNetTestConfigurationHelper()
- {
- }
- // ----------------------------------------------------------------------------------------------- Interface Methods
- // -------------------------------------------------------------------------------------------------- Action Methods
- public static List<TaskDefinition> convertPossibleTestIntegrations(final TaskIdSupplier taskIdSupplier, final String pluginKey, final Map<String, String> map)
- {
- final ConfigurationMap config = new ConfigurationMapImpl(map);
- final List<TaskDefinition> definitions = Lists.newLinkedList();
- if (config.getAsBoolean(NUNIT_TEST_CHECKED))
- {
- final String directory = config.get(NUnitCollectorTaskType.TEST_DIRECTORY);
- final String workingDirectory = config.get(TaskConfigConstants.CFG_WORKING_SUB_DIRECTORY);
- definitions.add(createTaskDefinition(taskIdSupplier, NUNIT_PLUGIN_KEY, EasyMap.build(NUnitCollectorTaskType.TEST_DIRECTORY, directory,
- TaskConfigConstants.CFG_WORKING_SUB_DIRECTORY, workingDirectory)));
- }
- if (config.getAsBoolean(MBUNIT_TEST_CHECKED))
- {
- final String directory = config.get(MBUnitCollectorTaskType.TEST_DIRECTORY);
- definitions.add(createTaskDefinition(taskIdSupplier, MBUNIT_PLUGIN_KEY, EasyMap.build(MBUnitCollectorTaskType.TEST_DIRECTORY, directory)));
- }
- if (config.getAsBoolean(MSBUILD_RUN_TEST_CHECKED) && config.getAsBoolean(MSBUILD_TEST_CHECKED))
- {
- final String label = pluginKey.equals(DevenvToVisualStudioTaskConverter.PLUGIN_KEY) ? config.get(MSTestRunnerTaskType.LABEL) : null;
- final String container = config.get(MSTestRunnerTaskType.CONTAINER);
- final String runConfig = config.get(MSTestRunnerTaskType.RUN_CONFIG);
- final String directory = config.get(MSTestCollectorTaskType.TEST_DIRECTORY);
- definitions.add(createTaskDefinition(taskIdSupplier, MSTEST_RUNNER_PLUGIN_KEY, EasyMap.build(MSTestRunnerTaskType.LABEL, label,
- MSTestRunnerTaskType.CONTAINER, container,
- MSTestRunnerTaskType.RUN_CONFIG, runConfig,
- MSTestRunnerTaskType.RESULTS_FILE, directory)));
- }
- else if (config.getAsBoolean(MSBUILD_TEST_CHECKED))
- {
- final String directory = config.get(MSTestCollectorTaskType.TEST_DIRECTORY);
- definitions.add(createTaskDefinition(taskIdSupplier, MSTEST_PLUGIN_KEY, EasyMap.build(MSTestCollectorTaskType.TEST_DIRECTORY, directory)));
- }
- return definitions;
- }
- // -------------------------------------------------------------------------------------------------- Public Methods
- // -------------------------------------------------------------------------------------- Basic Accessors / Mutators
- private static TaskDefinition createTaskDefinition(@NotNull TaskIdSupplier taskIdSupplier, @NotNull String pluginKey, Map<String, String> config)
- {
- return new TaskDefinitionImpl(taskIdSupplier.get(), pluginKey, null, config, true);
- }
- }