Skip to content

Commit

Permalink
Merge pull request #110 from simplelocalize/update-dependencies
Browse files Browse the repository at this point in the history
Release 2.6.0
  • Loading branch information
jpomykala authored Apr 17, 2024
2 parents e797efa + 589e170 commit 00e72d3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ public SimpleLocalizeUriFactory(String baseUrl)
this.baseUrl = baseUrl;
}

URI buildSendKeysURI()
{
return URI.create(baseUrl + "/cli/v1/keys");
}

URI buildDownloadUri(DownloadRequest downloadRequest)
{
String endpointUrl = baseUrl + "/cli/v2/download?downloadFormat=" + downloadRequest.format();
Expand All @@ -37,6 +32,12 @@ URI buildDownloadUri(DownloadRequest downloadRequest)
endpointUrl += "&downloadOptions=" + String.join(",", downloadOptions);
}

String namespace = downloadRequest.namespace();
if (StringUtils.isNotEmpty(namespace))
{
endpointUrl += "&namespace=" + namespace;
}

String customerId = downloadRequest.customerId();
if (StringUtils.isNotEmpty(customerId))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;

@Builder(setterPrefix = "with")
public record DownloadRequest(String format, String languageKey, String customerId, List<String> options, String sort)
public record DownloadRequest(String format, String languageKey, String customerId, String namespace,
List<String> options, String sort)
{
}
15 changes: 13 additions & 2 deletions src/main/java/io/simplelocalize/cli/command/DownloadCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class DownloadCommand implements CliCommand
{
Expand Down Expand Up @@ -49,6 +50,7 @@ public void invoke() throws IOException, InterruptedException
DownloadRequest downloadRequest = DownloadRequest.builder()
.withFormat(downloadFormat)
.withOptions(downloadOptions)
.withNamespace(namespace)
.withCustomerId(customerId)
.withLanguageKey(languageKey)
.withSort(sort)
Expand All @@ -59,7 +61,8 @@ public void invoke() throws IOException, InterruptedException
log.info("Customer ID: {}", customerId);
}

if (StringUtils.isNotEmpty(namespace))
boolean hasNamespace = StringUtils.isNotEmpty(namespace);
if (hasNamespace)
{
log.info("Namespace: {}", namespace);
}
Expand All @@ -74,11 +77,19 @@ public void invoke() throws IOException, InterruptedException
}
log.info("Download options: {}", downloadOptions);
List<DownloadableFile> downloadableFiles = client.fetchDownloadableFiles(downloadRequest);
int downloadedFilesCounter = 0;
for (DownloadableFile downloadableFile : downloadableFiles)
{
boolean isNamespaceMatches = Objects.equals(downloadableFile.namespace(), namespace);
if (hasNamespace && !isNamespaceMatches)
{
log.info("Skipping file download for namespace = {}", downloadableFile.namespace());
continue;
}
client.downloadFile(downloadableFile, downloadPath);
downloadedFilesCounter++;
}
log.info("Downloaded {} files from SimpleLocalize", downloadableFiles.size());
log.info("Downloaded {} file(s) from SimpleLocalize", downloadedFilesCounter);
}

}
22 changes: 7 additions & 15 deletions src/main/java/io/simplelocalize/cli/command/UploadCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,7 @@ public void invoke() throws IOException, InterruptedException
uploadPath = WindowsUtils.convertToWindowsPath(uploadPath);
}

List<FileToUpload> filesToUpload;
try
{
filesToUpload = fileListReader.findFilesToUpload(uploadPath);
} catch (IOException e)
{
log.error("Matching files could not be found at {}", uploadPath, e);
throw new IllegalArgumentException("Matching files could not be found", e);
}


List<FileToUpload> filesToUpload = fileListReader.findFilesToUpload(uploadPath);
String uploadFormat = configuration.getUploadFormat();
String customerId = configuration.getCustomerId();
List<String> uploadOptions = configuration.getUploadOptions();
Expand All @@ -76,13 +66,14 @@ public void invoke() throws IOException, InterruptedException
log.info("Dry run mode enabled, no files will be uploaded");
}

int uploadedFilesCounter = 0;
for (FileToUpload fileToUpload : filesToUpload)
{
Path path = fileToUpload.path();
long length = path.toFile().length();
if (length == 0)
{
log.warn("Skipping empty file: {}", path);
log.warn("Skipping empty file = {}", path);
continue;
}

Expand All @@ -96,7 +87,7 @@ public void invoke() throws IOException, InterruptedException
String language = fileToUpload.language();
if (hasFileLanguageKey && hasConfigurationLanguageKey && !isLanguageMatching)
{
log.info("Skipping '{}' language, file: {}", language, path);
log.info("Skipping '{}' language = {}", language, path);
continue;
}

Expand All @@ -109,7 +100,7 @@ public void invoke() throws IOException, InterruptedException
boolean isMultiLanguage = isMultiLanguage(configuration);
if (!hasFileLanguageKey && !hasConfigurationLanguageKey && !isMultiLanguage)
{
log.info("Language key not present in '--uploadPath' nor '--languageKey' parameter, file: {}", path);
log.info("Language key not present in '--uploadPath' nor '--languageKey' parameter = {}", path);
}

String effectiveNamespace = fileToUpload.namespace();
Expand All @@ -133,12 +124,13 @@ public void invoke() throws IOException, InterruptedException
{
log.info("Uploading file, language=[{}] namespace=[{}] = {}", effectiveLanguageKey, effectiveNamespace, path);
client.uploadFile(uploadRequest);
uploadedFilesCounter++;
}
}

if (!isDryRun)
{
log.info("Uploaded {} file(s) to SimpleLocalize", filesToUpload.size());
log.info("Uploaded {} file(s) to SimpleLocalize", uploadedFilesCounter);
}
}

Expand Down

0 comments on commit 00e72d3

Please sign in to comment.