WorkspaceRunner.fromMap constructor

WorkspaceRunner.fromMap(
  1. Map<Object?, Object?> value
)

Implementation

factory WorkspaceRunner.fromMap(Map<Object?, Object?> value) {
  final rawArgs = value['args'];
  final rawEvidenceTypes = value['evidenceTypes'];
  if (rawArgs != null &&
      (rawArgs is! List || rawArgs.any((item) => item is! String))) {
    throw const FormatException('runner args must be string values');
  }
  if (rawEvidenceTypes != null &&
      (rawEvidenceTypes is! List ||
          rawEvidenceTypes.any((item) => item is! String || item.isEmpty))) {
    throw const FormatException('runner evidenceTypes must be string values');
  }
  final executable = value['executable'];
  if (executable != null &&
      (executable is! String || executable.trim().isEmpty)) {
    throw const FormatException(
      'runner executable must be a non-empty string',
    );
  }
  final rawKind = value['kind'];
  if (rawKind != null &&
      (rawKind is! String || !_runnerKinds.contains(rawKind))) {
    throw const FormatException(
      'runner kind must be one of gherkin, setup, test',
    );
  }
  final rawWorkingDirectory = value['workingDirectory'];
  if (rawWorkingDirectory != null &&
      (rawWorkingDirectory is! String ||
          rawWorkingDirectory.trim().isEmpty)) {
    throw const FormatException(
      'runner workingDirectory must be a non-empty string',
    );
  }
  final rawRunnerMode = value['runnerMode'];
  if (rawRunnerMode != null &&
      (rawRunnerMode is! String || !_runnerModes.contains(rawRunnerMode))) {
    throw const FormatException(
      'runner runnerMode must be one of auto, cli, directSnapshot',
    );
  }
  final rawTimeout = value['timeoutSeconds'];
  if (rawTimeout != null &&
      (rawTimeout is! num ||
          !rawTimeout.isFinite ||
          rawTimeout.toInt() <= 0)) {
    throw const FormatException(
      'runner timeoutSeconds must be a positive number',
    );
  }
  final rawProfiles = value['profiles'];
  if (rawProfiles != null &&
      (rawProfiles is! List ||
          rawProfiles.any(
            (item) => item is! String || item.trim().isEmpty,
          ))) {
    throw const FormatException('runner profiles must be non-empty strings');
  }
  return WorkspaceRunner(
    id: _requiredString(value, 'id'),
    target: _requiredString(value, 'target'),
    sourcePackage: _requiredString(value, 'sourcePackage'),
    sourceAdapter: _requiredString(value, 'sourceAdapter'),
    sourceCompatibilityId: _requiredString(value, 'sourceCompatibilityId'),
    runnerCompatibilityId: _requiredString(value, 'runnerCompatibilityId'),
    executable: executable as String?,
    args: rawArgs == null
        ? const []
        : List<String>.unmodifiable(rawArgs as List),
    evidenceTypes: rawEvidenceTypes == null
        ? const []
        : List<String>.unmodifiable(rawEvidenceTypes as List),
    kind: rawKind as String? ?? 'test',
    workingDirectory: rawWorkingDirectory as String?,
    runnerMode: rawRunnerMode as String? ?? 'auto',
    timeoutSeconds: rawTimeout == null ? 600 : (rawTimeout as num).toInt(),
    profiles: rawProfiles == null
        ? const []
        : List<String>.unmodifiable(rawProfiles as List),
    hasProfileRestriction: rawProfiles != null,
    extensions: Map.unmodifiable({
      for (final entry in value.entries)
        if (entry.key is String && !_knownKeys.contains(entry.key))
          entry.key as String: _freeze(entry.value),
    }),
  );
}