Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: download multiple sources with the same destination #574

Merged
merged 2 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ public void act(Outputter out, PropertiesWithFiles properties, ProjectClient cli
String exportPattern = Utils.normalizePath(ProjectFilesUtils.getExportPattern(((File) filePaths.get(filePathKey)).getExportOptions()));
String translationPattern = TranslationsUtils.replaceDoubleAsterisk(fileBean.getSource(), fileBean.getTranslation(), filePathKey);
if (exportPattern == null || translationPattern.endsWith(exportPattern)) {
filePaths2.add(filePathKey);
String sourceName = new java.io.File(fileBean.getSource()).getName();
if(sourceName.equals(new java.io.File(filePathKey).getName()) || SourcesUtils.containsPattern(sourceName)) {
filePaths2.add(filePathKey);
}
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.IOException;
import java.io.PrintStream;
import java.net.URL;
import java.util.ArrayList;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -116,6 +117,8 @@ public void testDifferentPatterns() throws IOException {
.addBuiltFileBean("/folder_2/android_1.xml", "/%locale%/folder_2/%file_name%.xml")
.addBuiltFileBean("/folder_2/android_[2-3].xml", "/%locale%/folder_2/%file_name%.xml")
.addBuiltFileBean("/folder_2/android_4?.xml", "/%locale%/folder_2/%file_name%.xml")
.addBuiltFileBean("folder1/folder2/**/messages.json", "/folder1/folder2/**/%file_name%_%two_letters_code%.json", new ArrayList<>(), "/folder_on_crowdin/%original_path%/%file_name%.json")
.addBuiltFileBean("folder1/folder2/**/plugins.json", "/folder1/folder2/**/%file_name%_%two_letters_code%.json", new ArrayList<>(), "/folder_on_crowdin/%original_path%/%file_name%.json")
.setBasePath(project.getBasePath())
.setPreserveHierarchy(true)
.build();
Expand All @@ -127,13 +130,19 @@ public void testDifferentPatterns() throws IOException {
.addDirectory("f1", 202L, 201L, null)
.addDirectory("folder_1", 203L, 201L, null)
.addDirectory("folder_2", 204L, null, null)
.addDirectory("folder_on_crowdin", 205L, null, null)
.addDirectory("folder1", 206L, 205L, null)
.addDirectory("folder2", 207L, 206L, null)
.addDirectory("nested", 208L, 207L, null)
.addFile("android.xml", "gettext", 101L, 202L, null, "/%locale%/folder_1/f1/%file_name%.xml")
.addFile("android.xml", "gettext", 102L, 203L, null, "/%locale%/folder_1/folder_1/%file_name%.xml")
.addFile("android.xml", "gettext", 103L, 201L, null, "/%locale%/folder_1/%file_name%.xml")
.addFile("android_1.xml", "gettext", 104L, 204L, null, "/%locale%/folder_2/%file_name%.xml")
.addFile("android_2.xml", "gettext", 105L, 204L, null, "/%locale%/folder_2/%file_name%.xml")
.addFile("android_3.xml", "gettext", 106L, 204L, null, "/%locale%/folder_2/%file_name%.xml")
.addFile("android_4a.xml", "gettext", 107L, 204L, null, "/%locale%/folder_2/%file_name%.xml")
.addFile("messages.json", "json", 108L, 208L, null, "/folder1/folder2/nested/%file_name%_%two_letters_code%.json")
.addFile("plugins.json", "json", 109L, 208L, null, "/folder1/folder2/nested/%file_name%_%two_letters_code%.json")
.build());
URL urlMock = MockitoUtils.getMockUrl(getClass());
when(client.downloadFile(eq(101L)))
Expand All @@ -150,6 +159,10 @@ public void testDifferentPatterns() throws IOException {
.thenReturn(urlMock);
when(client.downloadFile(eq(107L)))
.thenReturn(urlMock);
when(client.downloadFile(eq(108L)))
.thenReturn(urlMock);
when(client.downloadFile(eq(109L)))
.thenReturn(urlMock);

FilesInterface files = mock(FilesInterface.class);

Expand All @@ -165,6 +178,8 @@ public void testDifferentPatterns() throws IOException {
verify(client).downloadFile(eq(105L));
verify(client).downloadFile(eq(106L));
verify(client).downloadFile(eq(107L));
verify(client).downloadFile(eq(108L));
verify(client).downloadFile(eq(109L));
verifyNoMoreInteractions(client);

verify(files).writeToFile(eq(Utils.joinPaths(project.getBasePath(), "/folder_1/android.xml")), any());
Expand All @@ -174,6 +189,8 @@ public void testDifferentPatterns() throws IOException {
verify(files).writeToFile(eq(Utils.joinPaths(project.getBasePath(), "/folder_2/android_2.xml")), any());
verify(files).writeToFile(eq(Utils.joinPaths(project.getBasePath(), "/folder_2/android_3.xml")), any());
verify(files).writeToFile(eq(Utils.joinPaths(project.getBasePath(), "/folder_2/android_4a.xml")), any());
verify(files).writeToFile(eq(Utils.joinPaths(project.getBasePath(), "/folder1/folder2/nested/messages.json")), any());
verify(files).writeToFile(eq(Utils.joinPaths(project.getBasePath(), "/folder1/folder2/nested/plugins.json")), any());
verifyNoMoreInteractions(files);
}

Expand Down