Skip to content

Commit

Permalink
Merge pull request #396 from crowdin/fix-dest
Browse files Browse the repository at this point in the history
fix 'dest'
  • Loading branch information
andrii-bodnar authored Sep 17, 2021
2 parents 79f62eb + bf8350e commit 44f0fe5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
8 changes: 3 additions & 5 deletions src/main/java/com/crowdin/cli/utils/PlaceholderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -153,4 +155,25 @@ private static Stream<Arguments> 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<Arguments> 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"))
);
}
}

0 comments on commit 44f0fe5

Please sign in to comment.