Skip to content
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
2 changes: 1 addition & 1 deletion src/main/java/com/crowdin/cli/commands/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ NewAction<ProjectProperties, ProjectClient> stringList(
boolean noProgress, boolean isVerbose, String file, String filter, String branchName, List<String> labelNames, String croql, String directory, String scope, boolean plainView);

NewAction<PropertiesWithFiles, ProjectClient> 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<PropertiesWithFiles, ProjectClient> uploadTranslations(
boolean noProgress, String languageId, String branchName, boolean importEqSuggestions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public NewAction<ProjectProperties, ProjectClient> stringList(

@Override
public NewAction<PropertiesWithFiles, ProjectClient> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ class UploadSourcesAction implements NewAction<PropertiesWithFiles, ProjectClien
private boolean autoUpdate;
private boolean debug;
private boolean plainView;
private boolean isVerbose;
private boolean cache;

public UploadSourcesAction(String branchName, boolean deleteObsolete, boolean noProgress, boolean autoUpdate, boolean debug, boolean plainView, boolean cache) {
public UploadSourcesAction(String branchName, boolean deleteObsolete, boolean noProgress, boolean autoUpdate, boolean debug, boolean plainView, boolean isVerbose, boolean cache) {
this.branchName = branchName;
this.deleteObsolete = deleteObsolete;
this.noProgress = noProgress || plainView;
this.autoUpdate = autoUpdate;
this.debug = debug;
this.plainView = plainView;
this.isVerbose = isVerbose;
this.cache = cache;
}

Expand Down Expand Up @@ -445,7 +447,7 @@ public void act(Outputter out, PropertiesWithFiles pb, ProjectClient client) {

if (cache) {
Cache.setSourceHashes(sourceHashes);
Cache.save(plainView, out);
Cache.save(plainView, isVerbose, out);
}
})
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class UploadSourcesCommand extends ActCommandWithFiles {
protected NewAction<PropertiesWithFiles, ProjectClient> 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
Expand Down
23 changes: 18 additions & 5 deletions src/main/java/com/crowdin/cli/utils/cache/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,33 @@
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;
import java.util.stream.Collectors;

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 {

private static final String CACHE_LOCATION = System.getProperty("user.home") + Utils.PATH_SEPARATOR + ".crowdin" + Utils.PATH_SEPARATOR + "cache.json";

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) {
Expand All @@ -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")));
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void testUploadOneSource_EmptyProject() throws ResponseException {
when(client.uploadStorage(eq("first.po"), any()))
.thenReturn(1L);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -112,7 +112,7 @@ public void testUploadOneSourceWithNullContentSegmentation_EmptyProject() throws
when(client.uploadStorage(eq("first.po"), any()))
.thenReturn(1L);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -151,7 +151,7 @@ public void testUploadPropertiesFileWithEscapeQuotes_EmptyProject() throws Respo
when(client.uploadStorage(eq("first.properties"), any()))
.thenReturn(1L);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -192,7 +192,7 @@ public void testUploadJavaScriptFileWithExportQuotes_EmptyProject() throws Respo
when(client.uploadStorage(eq("first.js"), any()))
.thenReturn(1L);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -243,7 +243,7 @@ public void testUploadFewSourceWithDirectories_EmptyProject() throws ResponseExc
when(client.uploadStorage(eq("third.po"), any()))
.thenReturn(3L);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -318,7 +318,7 @@ public void testUploadOneSourceWithBranch_EmptyProject() throws ResponseExceptio
when(client.addBranch(addBranchRequest))
.thenReturn(branch);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction("newBranch", false, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction("newBranch", false, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -358,7 +358,7 @@ public void testUploadOneSourceWithBranch_ProjectWithThatBranch() throws Respons
when(client.uploadStorage(eq("first.po"), any()))
.thenReturn(1L);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction("newBranch", false, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction("newBranch", false, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -396,7 +396,7 @@ public void testUploadOneSourceWithDirectory_ProjectNotPreserveHierarchy() throw
when(client.uploadStorage(eq("first.po"), any()))
.thenReturn(1L);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -436,7 +436,7 @@ public void testUploadOneSourceWithDirectory_ProjectWithPreserveHierarchy() thro
when(client.uploadStorage(eq("first.po"), any()))
.thenReturn(1L);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -475,7 +475,7 @@ public void testUploadOneSourceWithDest_Project() throws ResponseException {
when(client.uploadStorage(eq("first.po"), any()))
.thenReturn(1L);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -524,7 +524,7 @@ public void testUploadOneSourceWithDestAndDeleteObsoleteOption_Project() throws
when(client.uploadStorage(eq("/docs/en/index.md"), any()))
.thenReturn(1L);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, true, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, true, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -571,7 +571,7 @@ public void testUploadOneSourceWithDestAndDeleteObsoleteOptionAndPlusName_Projec
when(client.uploadStorage(eq("/docs/en/index+new.md"), any()))
.thenReturn(1L);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, true, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, true, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -612,7 +612,7 @@ public void testUpdateOneUploadOneSource_Project() throws ResponseException {
when(client.uploadStorage(eq("second.po"), any()))
.thenReturn(2L);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -664,7 +664,7 @@ public void testAddCsvFile_EmptyProject() throws ResponseException {
when(client.uploadStorage(eq("first.csv"), any()))
.thenReturn(1L);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -710,7 +710,7 @@ public void testUploadOneSourceWithDest_DifferentPlaceholders_1_Project() throws
when(client.uploadStorage(eq("first.po"), any()))
.thenReturn(1L);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -756,7 +756,7 @@ public void testUploadOneSourceWithDest_DifferentPlaceholders_2_Project() throws
setId(3L);
}});

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, true, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, true, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -811,7 +811,7 @@ public void testUploadOneSourceWithDest_DifferentPlaceholders_3_Project() throws
setId(4L);
}});

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction(null, false, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -861,7 +861,7 @@ public void testUploadOneSource_StringBasedProject() throws ResponseException {
.thenReturn(1L);
when(client.addSourceStringsBased(eq(uploadStringsRequest))).thenReturn(uploadStringsProgress);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction("main", false, false, true, false, false, false);
NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction("main", false, false, true, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading