From 54b9600c3150647be913782e9f602a1346a783fa Mon Sep 17 00:00:00 2001 From: Kateryna Oblakevych Date: Wed, 10 Apr 2024 15:46:56 +0300 Subject: [PATCH 1/2] feat: type and parser version options for file upload --- .../com/crowdin/cli/commands/Actions.java | 2 +- .../cli/commands/actions/CliActions.java | 4 ++-- .../commands/actions/FileUploadAction.java | 8 ++++++++ .../picocli/FileUploadSubcommand.java | 20 +++++++++++++++++-- .../resources/messages/messages.properties | 3 +++ .../cli/commands/actions/CliActionsTest.java | 2 +- .../actions/FileUploadActionTest.java | 20 ++++++++++--------- .../picocli/FileUploadSubcommandTest.java | 2 +- .../commands/picocli/PicocliTestUtils.java | 2 +- versions.properties | 3 +-- 10 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/crowdin/cli/commands/Actions.java b/src/main/java/com/crowdin/cli/commands/Actions.java index 7a69ce6c..4592aee4 100644 --- a/src/main/java/com/crowdin/cli/commands/Actions.java +++ b/src/main/java/com/crowdin/cli/commands/Actions.java @@ -129,7 +129,7 @@ NewAction preTranslate( NewAction labelDelete(String title); - NewAction fileUpload(File file, String branch, boolean autoUpdate, List labels, String destination, List excludedLanguages, boolean plainView, boolean cleanupMode, boolean updateString); + NewAction fileUpload(File file, String branch, boolean autoUpdate, List labels, String destination, String type, Integer parserVersion, List excludedLanguages, boolean plainView, boolean cleanupMode, boolean updateString); NewAction fileUploadTranslation(File file, String branch, String dest, String languageId, boolean plainView); diff --git a/src/main/java/com/crowdin/cli/commands/actions/CliActions.java b/src/main/java/com/crowdin/cli/commands/actions/CliActions.java index a68b36e1..8c444696 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/CliActions.java +++ b/src/main/java/com/crowdin/cli/commands/actions/CliActions.java @@ -270,8 +270,8 @@ public NewAction labelDelete(String title) { } @Override - public NewAction fileUpload(File file, String branch, boolean autoUpdate, List labels, String destination, List excludedLanguages, boolean plainView, boolean cleanupMode, boolean updateStrings) { - return new FileUploadAction(file, branch, autoUpdate, labels, destination, cleanupMode, updateStrings, excludedLanguages, plainView); + public NewAction fileUpload(File file, String branch, boolean autoUpdate, List labels, String destination, String type, Integer parserVersion, List excludedLanguages, boolean plainView, boolean cleanupMode, boolean updateStrings) { + return new FileUploadAction(file, branch, autoUpdate, labels, destination, type, parserVersion, cleanupMode, updateStrings, excludedLanguages, plainView); } @Override diff --git a/src/main/java/com/crowdin/cli/commands/actions/FileUploadAction.java b/src/main/java/com/crowdin/cli/commands/actions/FileUploadAction.java index 94eacaa5..02966f09 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/FileUploadAction.java +++ b/src/main/java/com/crowdin/cli/commands/actions/FileUploadAction.java @@ -39,6 +39,8 @@ class FileUploadAction implements NewAction { private final boolean autoUpdate; private final List labels; private final String dest; + private final String type; + private final Integer parserVersion; private final boolean cleanupMode; private final boolean updateStrings; private final List excludedLanguages; @@ -137,6 +139,12 @@ public void act(Outputter out, ProjectProperties properties, ProjectClient clien AddFileRequest request = new AddFileRequest(); request.setName(fileDestName); request.setStorageId(storageId); + if (nonNull(type)) { + request.setType(type); + } + if (nonNull(parserVersion)) { + request.setParserVersion(parserVersion); + } Optional directoryId = getOrCreateDirectoryId(out, client, project, properties, branch.orElse(null)); directoryId.ifPresent(request::setDirectoryId); diff --git a/src/main/java/com/crowdin/cli/commands/picocli/FileUploadSubcommand.java b/src/main/java/com/crowdin/cli/commands/picocli/FileUploadSubcommand.java index 471c74f9..73ba3b0c 100644 --- a/src/main/java/com/crowdin/cli/commands/picocli/FileUploadSubcommand.java +++ b/src/main/java/com/crowdin/cli/commands/picocli/FileUploadSubcommand.java @@ -9,6 +9,7 @@ import picocli.CommandLine.Parameters; import java.io.File; +import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -31,7 +32,13 @@ class FileUploadSubcommand extends ActCommandProject { protected List labels; @Option(names = {"-d", "--dest"}, paramLabel = "...", descriptionKey = "crowdin.file.upload.dest", order = -2) - private String destination; + protected String destination; + + @Option(names = {"--type"}, descriptionKey = "crowdin.file.upload.type", paramLabel = "...", order = -2) + protected String type; + + @Option(names = {"--parser-version"}, descriptionKey = "crowdin.file.upload.parser", paramLabel = "...", order = -2) + protected Integer parserVersion; @Option(names = {"--excluded-language"}, descriptionKey = "params.excluded-languages", paramLabel = "...", order = -2) protected List excludedLanguages; @@ -48,11 +55,20 @@ class FileUploadSubcommand extends ActCommandProject { @Option(names = {"--plain"}, descriptionKey = "crowdin.list.usage.plain") protected boolean plainView; + @Override + protected List checkOptions() { + List errors = new ArrayList<>(); + if (parserVersion != null && type == null) { + errors.add(RESOURCE_BUNDLE.getString("error.file.type_required")); + } + return errors; + } + @Override protected NewAction getAction(Actions actions) { if (Objects.nonNull(languageId)) { return actions.fileUploadTranslation(file, branch, destination, languageId, plainView); } - return actions.fileUpload(file, branch, autoUpdate, labels, destination, excludedLanguages, plainView, cleanupMode, updateStrings); + return actions.fileUpload(file, branch, autoUpdate, labels, destination, type, parserVersion, excludedLanguages, plainView, cleanupMode, updateStrings); } } diff --git a/src/main/resources/messages/messages.properties b/src/main/resources/messages/messages.properties index 7ca738f9..e45651e3 100755 --- a/src/main/resources/messages/messages.properties +++ b/src/main/resources/messages/messages.properties @@ -126,6 +126,8 @@ crowdin.file.upload.usage.description=Upload a file to a Crowdin project crowdin.file.upload.usage.customSynopsis=@|fg(green) crowdin file upload|@ [CONFIG OPTIONS] [OPTIONS] crowdin.file.upload.file=Path to file to upload crowdin.file.upload.dest=File destination in the Crowdin project +crowdin.file.upload.type=File type +crowdin.file.upload.parser=Parser version crowdin.file.upload.auto-update=Specify whether to update the file in the Crowdin project if it already exists crowdin.file.upload.cleanup-mode=Specify whether to delete all strings with a system label that do not exist in the file crowdin.file.upload.update-strings=Specify whether to update strings that have the same keys @@ -552,6 +554,7 @@ error.screenshot.not_updated=Screenshot was not updated error.label.not_found=Couldn't find label by the specified title error.file.dest_required='dest' parameter required to specify source file path +error.file.type_required='--type' is required for '--parser-version' option error.response.401=Couldn't authorize. Check your 'api_token' error.response.403=You do not have permission to view/edit project with provided id diff --git a/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java b/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java index b808825b..1a4792ab 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java @@ -159,7 +159,7 @@ void testLabelDelete() { @Test void testFileUpload() { - assertNotNull(actions.fileUpload(null, null, false, null, null, null,false, true, false)); + assertNotNull(actions.fileUpload(null, null, false, null, null, null, null, null,false, true, false)); } @Test diff --git a/src/test/java/com/crowdin/cli/commands/actions/FileUploadActionTest.java b/src/test/java/com/crowdin/cli/commands/actions/FileUploadActionTest.java index ff302296..647ad38e 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/FileUploadActionTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/FileUploadActionTest.java @@ -61,7 +61,7 @@ public void testUpload_FileBasedProject() throws ResponseException { when(client.uploadStorage(eq("first.po"), any())) .thenReturn(1L); - NewAction action = new FileUploadAction(fileToUpload, null, false, null, null, false, false, null, false); + NewAction action = new FileUploadAction(fileToUpload, null, false, null, null, "po", 3, false, false, null, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -69,6 +69,8 @@ public void testUpload_FileBasedProject() throws ResponseException { AddFileRequest addFileRequest = new AddFileRequest() {{ setName("first.po"); setStorageId(1L); + setType("po"); + setParserVersion(3); }}; verify(client).addSource(eq(addFileRequest)); verifyNoMoreInteractions(client); @@ -103,7 +105,7 @@ public void testUpload_StringBasedProject() throws ResponseException { when(client.addSourceStringsBased(any())).thenReturn(progress); when(client.getUploadStringsStatus(any())).thenReturn(progressFinished); - NewAction action = new FileUploadAction(fileToUpload, "branch", false, null, null, false, false, null, false); + NewAction action = new FileUploadAction(fileToUpload, "branch", false, null, null, null, null,false, false, null, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -137,7 +139,7 @@ public void testUploadUpdate_FileBasedProject() throws ResponseException { when(client.uploadStorage(eq("first.po"), any())) .thenReturn(1L); - NewAction action = new FileUploadAction(fileToUpload, null, true, null, null, false, false, null, false); + NewAction action = new FileUploadAction(fileToUpload, null, true, null, null, null, null, false, false, null, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -164,7 +166,7 @@ public void testUploadNoAutoUpdate_FileBasedProject() throws ResponseException { when(client.downloadFullProject()) .thenReturn(build); - NewAction action = new FileUploadAction(fileToUpload, null, false, null, null, false, false, null, false); + NewAction action = new FileUploadAction(fileToUpload, null, false, null, null, null, null, false, false, null, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -192,7 +194,7 @@ public void testUploadWhenBranchMissed_FileBasedProject() throws ResponseExcepti .thenReturn(1L); when(client.addBranch(any())).thenReturn(branch); - NewAction action = new FileUploadAction(fileToUpload, "main", false, null, null, false, false, null, false); + NewAction action = new FileUploadAction(fileToUpload, "main", false, null, null, null, null, false, false, null, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -229,7 +231,7 @@ public void testUploadLabel_FileBasedProject() throws ResponseException { when(client.listLabels()).thenReturn(Collections.emptyList()); when(client.addLabel(any())).thenReturn(label); - NewAction action = new FileUploadAction(fileToUpload, null, false, Collections.singletonList("main_label"), null, false, false, null, false); + NewAction action = new FileUploadAction(fileToUpload, null, false, Collections.singletonList("main_label"), null, null, null, false, false, null, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -262,7 +264,7 @@ public void testUploadExcludedLangs_FileBasedProject() throws ResponseException .thenReturn(1L); when(client.listLabels()).thenReturn(Collections.emptyList()); - NewAction action = new FileUploadAction(fileToUpload, null, false, null, null, false, false, Arrays.asList("ua", "fr"), false); + NewAction action = new FileUploadAction(fileToUpload, null, false, null, null, null, null, false, false, Arrays.asList("ua", "fr"), false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -296,7 +298,7 @@ public void testUploadWithDest_FileBasedProject() throws ResponseException { .thenReturn(directory); when(client.uploadStorage(eq("save.po"), any())) .thenReturn(1L); - NewAction action = new FileUploadAction(fileToUpload, null, false, null, "path/to/save.po", false, false, null, false); + NewAction action = new FileUploadAction(fileToUpload, null, false, null, "path/to/save.po", null, null,false, false, null, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -340,7 +342,7 @@ public void testUploadCleanUpModeAndUpdateStrings_StringBasedProject() throws Re when(client.addSourceStringsBased(any())).thenReturn(progress); when(client.getUploadStringsStatus(any())).thenReturn(progressFinished); - NewAction action = new FileUploadAction(fileToUpload, "branch", false, null, null, true, true, null, false); + NewAction action = new FileUploadAction(fileToUpload, "branch", false, null, null, null, null, true, true, null, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); diff --git a/src/test/java/com/crowdin/cli/commands/picocli/FileUploadSubcommandTest.java b/src/test/java/com/crowdin/cli/commands/picocli/FileUploadSubcommandTest.java index 64bfbeeb..95f67119 100644 --- a/src/test/java/com/crowdin/cli/commands/picocli/FileUploadSubcommandTest.java +++ b/src/test/java/com/crowdin/cli/commands/picocli/FileUploadSubcommandTest.java @@ -11,7 +11,7 @@ class FileUploadSubcommandTest extends PicocliTestUtils { @Test public void testFileUpload() { this.execute(CommandNames.FILE, CommandNames.FILE_UPLOAD, "file.txt"); - verify(actionsMock).fileUpload(any(), any(), anyBoolean(), any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean()); + verify(actionsMock).fileUpload(any(), any(), anyBoolean(), any(), any(), any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean()); this.check(true); } diff --git a/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java b/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java index cf830a57..435cd781 100644 --- a/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java +++ b/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java @@ -119,7 +119,7 @@ void mockActions() { .thenReturn(actionMock); when(actionsMock.labelDelete(any())) .thenReturn(actionMock); - when(actionsMock.fileUpload(any(), any(), anyBoolean(), any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean())) + when(actionsMock.fileUpload(any(), any(), anyBoolean(), any(), any(), any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean())) .thenReturn(actionMock); when(actionsMock.fileUploadTranslation(any(), any(), any(), any(), anyBoolean())) .thenReturn(actionMock); diff --git a/versions.properties b/versions.properties index 18475330..1ac2acf8 100644 --- a/versions.properties +++ b/versions.properties @@ -43,8 +43,7 @@ version.commons-io..commons-io=2.14.0 version.commons-cli..commons-cli=1.5.0 -version.com.github.crowdin..crowdin-api-client-java=1.15.2 - +version.com.github.crowdin..crowdin-api-client-java=1.15.4 plugin.org.asciidoctor.jvm.convert=3.3.2 plugin.com.github.spotbugs=5.2.4 From fd9f0cc63c869bbf291616bca5b70aa76f500da0 Mon Sep 17 00:00:00 2001 From: Kateryna Oblakevych Date: Wed, 10 Apr 2024 17:45:30 +0300 Subject: [PATCH 2/2] fixes --- .../java/com/crowdin/cli/commands/actions/CliActionsTest.java | 2 +- .../com/crowdin/cli/commands/actions/DownloadActionTest.java | 4 ++-- .../crowdin/cli/commands/actions/FileUploadActionTest.java | 4 ++-- versions.properties | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java b/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java index 1a4792ab..bea13dbc 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java @@ -159,7 +159,7 @@ void testLabelDelete() { @Test void testFileUpload() { - assertNotNull(actions.fileUpload(null, null, false, null, null, null, null, null,false, true, false)); + assertNotNull(actions.fileUpload(null, null, false, null, null, null, null, null, false, true, false)); } @Test diff --git a/src/test/java/com/crowdin/cli/commands/actions/DownloadActionTest.java b/src/test/java/com/crowdin/cli/commands/actions/DownloadActionTest.java index 1c4df514..76f11ab6 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/DownloadActionTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/DownloadActionTest.java @@ -136,7 +136,7 @@ public void testProjectOneFittingFile() throws IOException, ResponseException { })); NewAction action = - new DownloadAction(files, false, null, null,false, null, false, false, false, false, false); + new DownloadAction(files, false, null, null, false, null, false, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(null); @@ -552,7 +552,7 @@ public void testProjectOneFittingFile_UploadedWithoutHierarchy() throws IOExcept })); NewAction action = - new DownloadAction(files, false, null, null,false, null, false, false, false, false, false); + new DownloadAction(files, false, null, null, false, null, false, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(null); diff --git a/src/test/java/com/crowdin/cli/commands/actions/FileUploadActionTest.java b/src/test/java/com/crowdin/cli/commands/actions/FileUploadActionTest.java index 647ad38e..5cb3a5e5 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/FileUploadActionTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/FileUploadActionTest.java @@ -105,7 +105,7 @@ public void testUpload_StringBasedProject() throws ResponseException { when(client.addSourceStringsBased(any())).thenReturn(progress); when(client.getUploadStringsStatus(any())).thenReturn(progressFinished); - NewAction action = new FileUploadAction(fileToUpload, "branch", false, null, null, null, null,false, false, null, false); + NewAction action = new FileUploadAction(fileToUpload, "branch", false, null, null, null, null, false, false, null, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -298,7 +298,7 @@ public void testUploadWithDest_FileBasedProject() throws ResponseException { .thenReturn(directory); when(client.uploadStorage(eq("save.po"), any())) .thenReturn(1L); - NewAction action = new FileUploadAction(fileToUpload, null, false, null, "path/to/save.po", null, null,false, false, null, false); + NewAction action = new FileUploadAction(fileToUpload, null, false, null, "path/to/save.po", null, null, false, false, null, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); diff --git a/versions.properties b/versions.properties index 1ac2acf8..5b4ca215 100644 --- a/versions.properties +++ b/versions.properties @@ -44,6 +44,7 @@ version.commons-io..commons-io=2.14.0 version.commons-cli..commons-cli=1.5.0 version.com.github.crowdin..crowdin-api-client-java=1.15.4 + plugin.org.asciidoctor.jvm.convert=3.3.2 plugin.com.github.spotbugs=5.2.4