diff --git a/src/main/java/com/crowdin/cli/commands/Actions.java b/src/main/java/com/crowdin/cli/commands/Actions.java index 9ea8bf83..6bf99a25 100644 --- a/src/main/java/com/crowdin/cli/commands/Actions.java +++ b/src/main/java/com/crowdin/cli/commands/Actions.java @@ -62,7 +62,7 @@ NewAction stringList( boolean noProgress, boolean isVerbose, String file, String filter, String branchName, List labelNames, String croql, String directory, String scope, boolean plainView); NewAction uploadSources( - String branchName, boolean deleteObsolete, boolean noProgress, boolean autoUpdate, boolean debug, boolean plainView, boolean cache); + String branchName, boolean deleteObsolete, boolean noProgress, boolean autoUpdate, boolean debug, boolean plainView, boolean isVerbose, boolean cache); NewAction uploadTranslations( boolean noProgress, String languageId, String branchName, boolean importEqSuggestions, 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 51bc6064..324b8e9b 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/CliActions.java +++ b/src/main/java/com/crowdin/cli/commands/actions/CliActions.java @@ -112,9 +112,9 @@ public NewAction stringList( @Override public NewAction uploadSources( - String branchName, boolean deleteObsolete, boolean noProgress, boolean autoUpdate, boolean debug, boolean plainView, boolean cache + String branchName, boolean deleteObsolete, boolean noProgress, boolean autoUpdate, boolean debug, boolean plainView, boolean isVerbose, boolean cache ) { - return new UploadSourcesAction(branchName, deleteObsolete, noProgress, autoUpdate, debug, plainView, cache); + return new UploadSourcesAction(branchName, deleteObsolete, noProgress, autoUpdate, debug, plainView, isVerbose, cache); } @Override diff --git a/src/main/java/com/crowdin/cli/commands/actions/UploadSourcesAction.java b/src/main/java/com/crowdin/cli/commands/actions/UploadSourcesAction.java index 181f8687..e1ab5ff8 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/UploadSourcesAction.java +++ b/src/main/java/com/crowdin/cli/commands/actions/UploadSourcesAction.java @@ -49,15 +49,17 @@ class UploadSourcesAction implements NewAction getAction(Actions actions) { return (dryrun) ? actions.listSources(this.deleteObsolete, this.branch, this.noProgress, this.treeView, plainView) - : actions.uploadSources(this.branch, this.deleteObsolete, this.noProgress, this.autoUpdate, debug, plainView, cache); + : actions.uploadSources(this.branch, this.deleteObsolete, this.noProgress, this.autoUpdate, debug, plainView, this.isVerbose, cache); } @Override diff --git a/src/main/java/com/crowdin/cli/utils/cache/Cache.java b/src/main/java/com/crowdin/cli/utils/cache/Cache.java index d7563737..d5da1df2 100644 --- a/src/main/java/com/crowdin/cli/utils/cache/Cache.java +++ b/src/main/java/com/crowdin/cli/utils/cache/Cache.java @@ -5,6 +5,7 @@ import org.json.JSONObject; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; @@ -12,6 +13,7 @@ import static com.crowdin.cli.BaseCli.RESOURCE_BUNDLE; import static com.crowdin.cli.utils.console.ExecutionStatus.ERROR; +import static com.crowdin.cli.utils.console.ExecutionStatus.OK; public class Cache { @@ -19,13 +21,17 @@ public class Cache { private static JSONObject CACHE = new JSONObject(); + public static Path getCacheLocation() { + return Paths.get(CACHE_LOCATION).toAbsolutePath().normalize(); + } + public static void initialize(boolean plainView, Outputter out) { try { - if (!Files.exists(Paths.get(CACHE_LOCATION))) { + if (!Files.exists(getCacheLocation())) { return; } - String json = String.join("", Files.readAllLines(Paths.get(CACHE_LOCATION))); + String json = String.join("", Files.readAllLines(getCacheLocation())); CACHE = new JSONObject(json); } catch (Exception e) { @@ -37,10 +43,17 @@ public static void initialize(boolean plainView, Outputter out) { } } - public static void save(boolean plainView, Outputter out) { + public static void save(boolean plainView, boolean isVerbose, Outputter out) { try { - Files.createDirectories(Paths.get(CACHE_LOCATION).getParent()); - Files.write(Paths.get(CACHE_LOCATION), CACHE.toString(4).getBytes()); + Path cachePath = getCacheLocation(); + Files.createDirectories(cachePath.getParent()); + Files.write(cachePath, CACHE.toString(4).getBytes()); + if (!plainView && isVerbose) { + out.println(OK.withIcon(String.format( + RESOURCE_BUNDLE.getString("message.cache_saving"), + cachePath + ))); + } } catch (Exception e) { if (!plainView) { out.println(ERROR.withIcon(RESOURCE_BUNDLE.getString("error.cache_save"))); diff --git a/src/main/resources/messages/messages.properties b/src/main/resources/messages/messages.properties index 7ba49e66..c4d339f9 100755 --- a/src/main/resources/messages/messages.properties +++ b/src/main/resources/messages/messages.properties @@ -723,6 +723,7 @@ message.new_version_text.3=Please update for the best experience! message.uploading_file=@|green File '%s'|@ message.uploading_file_skipped=File '%s' was skipped since it is empty message.uploading_file_skipped_cached=File '%s' was skipped since it is up to date +message.cache_saving=Saving sources cache to the '%s' message.file_being_updated=File '%s' is currently being updated message.downloaded_file=@|green File '%s'|@ message.file_path=%s 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 562395f1..ebe9ed68 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java @@ -69,7 +69,7 @@ public void testStringList() { @Test public void testUploadSources() { - assertNotNull(actions.uploadSources(null, false, false, false, false, false, false)); + assertNotNull(actions.uploadSources(null, false, false, false, false, false, false, false)); } @Test diff --git a/src/test/java/com/crowdin/cli/commands/actions/UploadSourcesActionTest.java b/src/test/java/com/crowdin/cli/commands/actions/UploadSourcesActionTest.java index 6c3e6124..1bdbab6d 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/UploadSourcesActionTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/UploadSourcesActionTest.java @@ -73,7 +73,7 @@ public void testUploadOneSource_EmptyProject() throws ResponseException { when(client.uploadStorage(eq("first.po"), any())) .thenReturn(1L); - NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false); + NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -112,7 +112,7 @@ public void testUploadOneSourceWithNullContentSegmentation_EmptyProject() throws when(client.uploadStorage(eq("first.po"), any())) .thenReturn(1L); - NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false); + NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -151,7 +151,7 @@ public void testUploadPropertiesFileWithEscapeQuotes_EmptyProject() throws Respo when(client.uploadStorage(eq("first.properties"), any())) .thenReturn(1L); - NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false); + NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -192,7 +192,7 @@ public void testUploadJavaScriptFileWithExportQuotes_EmptyProject() throws Respo when(client.uploadStorage(eq("first.js"), any())) .thenReturn(1L); - NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false); + NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -243,7 +243,7 @@ public void testUploadFewSourceWithDirectories_EmptyProject() throws ResponseExc when(client.uploadStorage(eq("third.po"), any())) .thenReturn(3L); - NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false); + NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -318,7 +318,7 @@ public void testUploadOneSourceWithBranch_EmptyProject() throws ResponseExceptio when(client.addBranch(addBranchRequest)) .thenReturn(branch); - NewAction action = new UploadSourcesAction("newBranch", false, false, true, false, false, false); + NewAction action = new UploadSourcesAction("newBranch", false, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -358,7 +358,7 @@ public void testUploadOneSourceWithBranch_ProjectWithThatBranch() throws Respons when(client.uploadStorage(eq("first.po"), any())) .thenReturn(1L); - NewAction action = new UploadSourcesAction("newBranch", false, false, true, false, false, false); + NewAction action = new UploadSourcesAction("newBranch", false, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -396,7 +396,7 @@ public void testUploadOneSourceWithDirectory_ProjectNotPreserveHierarchy() throw when(client.uploadStorage(eq("first.po"), any())) .thenReturn(1L); - NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false); + NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -436,7 +436,7 @@ public void testUploadOneSourceWithDirectory_ProjectWithPreserveHierarchy() thro when(client.uploadStorage(eq("first.po"), any())) .thenReturn(1L); - NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false); + NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -475,7 +475,7 @@ public void testUploadOneSourceWithDest_Project() throws ResponseException { when(client.uploadStorage(eq("first.po"), any())) .thenReturn(1L); - NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false); + NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -524,7 +524,7 @@ public void testUploadOneSourceWithDestAndDeleteObsoleteOption_Project() throws when(client.uploadStorage(eq("/docs/en/index.md"), any())) .thenReturn(1L); - NewAction action = new UploadSourcesAction(null, true, false, true, false, false, false); + NewAction action = new UploadSourcesAction(null, true, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -571,7 +571,7 @@ public void testUploadOneSourceWithDestAndDeleteObsoleteOptionAndPlusName_Projec when(client.uploadStorage(eq("/docs/en/index+new.md"), any())) .thenReturn(1L); - NewAction action = new UploadSourcesAction(null, true, false, true, false, false, false); + NewAction action = new UploadSourcesAction(null, true, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -612,7 +612,7 @@ public void testUpdateOneUploadOneSource_Project() throws ResponseException { when(client.uploadStorage(eq("second.po"), any())) .thenReturn(2L); - NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false); + NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -664,7 +664,7 @@ public void testAddCsvFile_EmptyProject() throws ResponseException { when(client.uploadStorage(eq("first.csv"), any())) .thenReturn(1L); - NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false); + NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -710,7 +710,7 @@ public void testUploadOneSourceWithDest_DifferentPlaceholders_1_Project() throws when(client.uploadStorage(eq("first.po"), any())) .thenReturn(1L); - NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false); + NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -756,7 +756,7 @@ public void testUploadOneSourceWithDest_DifferentPlaceholders_2_Project() throws setId(3L); }}); - NewAction action = new UploadSourcesAction(null, false, false, true, true, false, false); + NewAction action = new UploadSourcesAction(null, false, false, true, true, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -811,7 +811,7 @@ public void testUploadOneSourceWithDest_DifferentPlaceholders_3_Project() throws setId(4L); }}); - NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false); + NewAction action = new UploadSourcesAction(null, false, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); @@ -861,7 +861,7 @@ public void testUploadOneSource_StringBasedProject() throws ResponseException { .thenReturn(1L); when(client.addSourceStringsBased(eq(uploadStringsRequest))).thenReturn(uploadStringsProgress); - NewAction action = new UploadSourcesAction("main", false, false, true, false, false, false); + NewAction action = new UploadSourcesAction("main", false, false, true, false, false, false, false); action.act(Outputter.getDefault(), pb, client); verify(client).downloadFullProject(); 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 2f648bcf..e1d03238 100644 --- a/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java +++ b/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java @@ -78,7 +78,7 @@ void mockActions() { .thenReturn(actionMock); when(actionsMock.stringList(anyBoolean(), anyBoolean(), any(), any(), any(), any(), any(), any(), any(), anyBoolean())) .thenReturn(actionMock); - when(actionsMock.uploadSources(any(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean())) + when(actionsMock.uploadSources(any(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean())) .thenReturn(actionMock); when(actionsMock.uploadTranslations(anyBoolean(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean())) .thenReturn(actionMock); diff --git a/src/test/java/com/crowdin/cli/commands/picocli/UploadSourcesCommandTest.java b/src/test/java/com/crowdin/cli/commands/picocli/UploadSourcesCommandTest.java index 0055c642..92792627 100644 --- a/src/test/java/com/crowdin/cli/commands/picocli/UploadSourcesCommandTest.java +++ b/src/test/java/com/crowdin/cli/commands/picocli/UploadSourcesCommandTest.java @@ -12,7 +12,7 @@ public class UploadSourcesCommandTest extends PicocliTestUtils { public void testUploadSources() { this.execute(CommandNames.UPLOAD); verify(actionsMock) - .uploadSources(any(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean()); + .uploadSources(any(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean()); this.check(true); }