From bf8350e5edd20ca36de030fa7b6ebf321909099b Mon Sep 17 00:00:00 2001 From: Daniil Barabash Date: Wed, 1 Sep 2021 12:16:26 +0300 Subject: [PATCH] fix 'dest' --- .../functionality/PropertiesBeanUtils.java | 3 +-- .../crowdin/cli/utils/PlaceholderUtil.java | 8 +++---- .../PropertiesBeanUtilsTest.java | 23 +++++++++++++++++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/crowdin/cli/commands/functionality/PropertiesBeanUtils.java b/src/main/java/com/crowdin/cli/commands/functionality/PropertiesBeanUtils.java index 2a29cd479..8d3f743d9 100644 --- a/src/main/java/com/crowdin/cli/commands/functionality/PropertiesBeanUtils.java +++ b/src/main/java/com/crowdin/cli/commands/functionality/PropertiesBeanUtils.java @@ -92,7 +92,6 @@ public static boolean isUrlValid(String baseUrl) { * @return built source file destination */ public static String prepareDest(String dest, String sourceFile, PlaceholderUtil placeholderUtil) { - String dest2 = TranslationsUtils.replaceDoubleAsterisk(dest, dest, sourceFile); - return placeholderUtil.replaceFileDependentPlaceholders(Utils.noSepAtStart(dest2), new File(sourceFile)); + return placeholderUtil.replaceFileDependentPlaceholders(Utils.noSepAtStart(dest), new File(sourceFile)); } } diff --git a/src/main/java/com/crowdin/cli/utils/PlaceholderUtil.java b/src/main/java/com/crowdin/cli/utils/PlaceholderUtil.java index e602836ae..3815adf42 100644 --- a/src/main/java/com/crowdin/cli/utils/PlaceholderUtil.java +++ b/src/main/java/com/crowdin/cli/utils/PlaceholderUtil.java @@ -185,12 +185,10 @@ public String replaceFileDependentPlaceholders(String toFormat, File file) { toFormat = toFormat.contains(PLACEHOLDER_FILE_EXTENTION) ? toFormat.replace(PLACEHOLDER_FILE_EXTENTION, fileExt) : toFormat; toFormat = toFormat.contains(PLACEHOLDER_ORIGINAL_PATH) ? toFormat.replace(PLACEHOLDER_ORIGINAL_PATH, fileParent) : toFormat; - if (toFormat.contains(Utils.PATH_SEPARATOR + "**")) { + if (toFormat.contains("**")) { String doubleAsterisks = - Utils.PATH_SEPARATOR - + StringUtils.removeStart(fileParent, - StringUtils.removeStart(StringUtils.substringBefore(toFormat, Utils.PATH_SEPARATOR + "**"), Utils.PATH_SEPARATOR)); - toFormat = toFormat.replace(Utils.PATH_SEPARATOR + "**", doubleAsterisks); + StringUtils.removeStart(fileParent, Utils.noSepAtEnd(Utils.noSepAtStart(StringUtils.substringBefore(toFormat, "**")))); + toFormat = toFormat.replace("**", doubleAsterisks); } toFormat = toFormat.replaceAll("[\\\\/]+", Utils.PATH_SEPARATOR_REGEX); diff --git a/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBeanUtilsTest.java b/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBeanUtilsTest.java index be6f4ff15..343c46e58 100644 --- a/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBeanUtilsTest.java +++ b/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBeanUtilsTest.java @@ -1,5 +1,7 @@ package com.crowdin.cli.commands.functionality; +import com.crowdin.cli.utils.PlaceholderUtil; +import com.crowdin.cli.utils.PlaceholderUtilBuilder; import com.crowdin.cli.utils.Utils; import com.crowdin.client.sourcefiles.model.UpdateOption; import org.junit.jupiter.api.Test; @@ -153,4 +155,25 @@ private static Stream testIsUrlValid() { arguments("https://myorg.e-test.crowdin.com") ); } + + @ParameterizedTest + @MethodSource + public void testPrepareDest(String dest, String sourceFile, String expected) { + PlaceholderUtil placeholderUtil = PlaceholderUtilBuilder.STANDART.build("/does/not/matter"); + String result = PropertiesBeanUtils.prepareDest(dest, sourceFile, placeholderUtil); + assertEquals(expected, result, String.format("dest: %s SourceFile: %s", dest, sourceFile)); + } + + private static Stream testPrepareDest() { + return Stream.of( + arguments( + Utils.normalizePath("/frontend/**/%original_file_name%"), + Utils.normalizePath("intl/messages/en-US.json"), + Utils.normalizePath("frontend/intl/messages/en-US.json")), + arguments( + Utils.normalizePath("/**/%file_name%_hmm.%file_extension%"), + Utils.normalizePath("en_GB/avmedia/source/framework_hmm.po"), + Utils.normalizePath("en_GB/avmedia/source/framework_hmm_hmm.po")) + ); + } }