func TestCreateBuildOptionsMap(t *testing.T) {
	context := make(map[string]interface{})

	context[constants.CTX_BUILD_PATH] = "buildPath"
	context[constants.CTX_HARDWARE_FOLDERS] = []string{"hardware", "hardware2"}
	context[constants.CTX_TOOLS_FOLDERS] = []string{"tools"}
	context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
	context[constants.CTX_FQBN] = "fqbn"
	context[constants.CTX_SKETCH_LOCATION] = "sketchLocation"
	context[constants.CTX_VERBOSE] = true
	context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "ideVersion"
	context[constants.CTX_DEBUG_LEVEL] = 5

	create := builder.CreateBuildOptionsMap{}
	err := create.Run(context)
	NoError(t, err)

	buildOptions := context[constants.CTX_BUILD_OPTIONS].(map[string]string)
	require.Equal(t, 6, len(utils.KeysOfMapOfString(buildOptions)))
	require.Equal(t, "hardware,hardware2", buildOptions[constants.CTX_HARDWARE_FOLDERS])
	require.Equal(t, "tools", buildOptions[constants.CTX_TOOLS_FOLDERS])
	require.Equal(t, "libraries", buildOptions[constants.CTX_OTHER_LIBRARIES_FOLDERS])
	require.Equal(t, "fqbn", buildOptions[constants.CTX_FQBN])
	require.Equal(t, "sketchLocation", buildOptions[constants.CTX_SKETCH_LOCATION])
	require.Equal(t, "ideVersion", buildOptions[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION])

	require.Equal(t, "{\n"+
		"  \"fqbn\": \"fqbn\",\n"+
		"  \"hardwareFolders\": \"hardware,hardware2\",\n"+
		"  \"otherLibrariesFolders\": \"libraries\",\n"+
		"  \"runtime.ide.version\": \"ideVersion\",\n"+
		"  \"sketchLocation\": \"sketchLocation\",\n"+
		"  \"toolsFolders\": \"tools\"\n"+
		"}", context[constants.CTX_BUILD_OPTIONS_JSON].(string))
}
func (s *PlatformKeysRewriteLoader) Run(context map[string]interface{}) error {
	folders := context[constants.CTX_HARDWARE_FOLDERS].([]string)

	platformKeysRewriteTxtPath, err := findPlatformKeysRewriteTxt(folders)
	if err != nil {
		return utils.WrapError(err)
	}
	if platformKeysRewriteTxtPath == constants.EMPTY_STRING {
		return nil
	}

	platformKeysRewrite := types.PlatforKeysRewrite{}
	platformKeysRewrite.Rewrites = []types.PlatforKeyRewrite{}

	txt, err := props.Load(platformKeysRewriteTxtPath)
	keys := utils.KeysOfMapOfString(txt)
	sort.Strings(keys)

	for _, key := range keys {
		keyParts := strings.Split(key, ".")
		if keyParts[0] == constants.PLATFORM_REWRITE_OLD {
			rewriteKey := strings.Join(keyParts[2:], ".")
			oldValue := txt[key]
			newValue := txt[constants.PLATFORM_REWRITE_NEW+"."+strings.Join(keyParts[1:], ".")]
			platformKeyRewrite := types.PlatforKeyRewrite{Key: rewriteKey, OldValue: oldValue, NewValue: newValue}
			platformKeysRewrite.Rewrites = append(platformKeysRewrite.Rewrites, platformKeyRewrite)
		}
	}

	context[constants.CTX_PLATFORM_KEYS_REWRITE] = platformKeysRewrite

	return nil
}
func (s *DumpBuildProperties) Run(context map[string]interface{}) error {
	buildProperties := context[constants.CTX_BUILD_PROPERTIES].(map[string]string)

	keys := utils.KeysOfMapOfString(buildProperties)
	sort.Strings(keys)

	for _, key := range keys {
		fmt.Println(key + "=" + buildProperties[key])
	}

	return nil
}
func (s *DumpBuildProperties) Run(ctx *types.Context) error {
	buildProperties := ctx.BuildProperties

	keys := utils.KeysOfMapOfString(buildProperties)
	sort.Strings(keys)

	for _, key := range keys {
		fmt.Println(key + "=" + buildProperties[key])
	}

	return nil
}
func (s *PlatformKeysRewriteLoader) Run(ctx *types.Context) error {
	logger := ctx.GetLogger()
	folders := ctx.HardwareFolders

	platformKeysRewriteTxtPath, err := findPlatformKeysRewriteTxt(folders)
	if err != nil {
		return i18n.WrapError(err)
	}
	if platformKeysRewriteTxtPath == constants.EMPTY_STRING {
		return nil
	}

	platformKeysRewrite := types.PlatforKeysRewrite{}
	platformKeysRewrite.Rewrites = []types.PlatforKeyRewrite{}

	txt, err := props.Load(platformKeysRewriteTxtPath, logger)
	keys := utils.KeysOfMapOfString(txt)
	sort.Strings(keys)

	for _, key := range keys {
		keyParts := strings.Split(key, ".")
		if keyParts[0] == constants.PLATFORM_REWRITE_OLD {
			index, err := strconv.Atoi(keyParts[1])
			if err != nil {
				return i18n.WrapError(err)
			}
			rewriteKey := strings.Join(keyParts[2:], ".")
			oldValue := txt[key]
			newValue := txt[constants.PLATFORM_REWRITE_NEW+"."+strings.Join(keyParts[1:], ".")]
			platformKeyRewrite := types.PlatforKeyRewrite{Key: rewriteKey, OldValue: oldValue, NewValue: newValue}
			platformKeysRewrite.Rewrites = growSliceOfRewrites(platformKeysRewrite.Rewrites, index)
			platformKeysRewrite.Rewrites[index] = platformKeyRewrite
		}
	}

	ctx.PlatformKeyRewrites = platformKeysRewrite

	return nil
}