Skip to content

Commit 6a781a5

Browse files
authored
Merge pull request #60 from simplelocalize/add-warnings-for-incorrect-paths-on-windows
Add support for '/' in file paths on Windows
2 parents e4a667e + e2a1369 commit 6a781a5

File tree

13 files changed

+190
-44
lines changed

13 files changed

+190
-44
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
JAVA_HOME: ./graalvm-ce-java11-20.1.0
6767
run: |
6868
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
69-
./graalvm-ce-java11-20.1.0/bin/native-image --no-server --report-unsupported-elements-at-runtime -cp simplelocalize-cli-${{env.VERSION}}.jar -H:Name="simplelocalize-cli-windows" io.simplelocalize.cli.SimplelocalizeCliCommand
69+
./graalvm-ce-java11-20.1.0/bin/native-image --no-server -Dmicronaut.env.deduction=false --report-unsupported-elements-at-runtime -cp simplelocalize-cli-${{env.VERSION}}.jar -H:Name="simplelocalize-cli-windows" io.simplelocalize.cli.SimplelocalizeCliCommand
7070
- name: "Optimize executable"
7171
uses: svenstaro/upx-action@v2
7272
with:
@@ -106,7 +106,7 @@ jobs:
106106
- name: "Install Native Image"
107107
run: gu install native-image
108108
- name: "Build Native Image"
109-
run: native-image --no-server --report-unsupported-elements-at-runtime -cp simplelocalize-cli-*.jar -H:Name="simplelocalize-cli-${{matrix.label}}" io.simplelocalize.cli.SimplelocalizeCliCommand
109+
run: native-image --no-server -Dmicronaut.env.deduction=false --report-unsupported-elements-at-runtime -cp simplelocalize-cli-*.jar -H:Name="simplelocalize-cli-${{matrix.label}}" io.simplelocalize.cli.SimplelocalizeCliCommand
110110
- name: "Optimize executable"
111111
uses: svenstaro/upx-action@v2
112112
with:

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.simplelocalize</groupId>
66
<artifactId>simplelocalize-cli</artifactId>
7-
<version>2.0.5</version>
7+
<version>2.0.6</version>
88
<packaging>jar</packaging>
99
<name>simplelocalize-cli</name>
1010
<description>Official SimpleLocalize Command Line Interface</description>
@@ -236,6 +236,7 @@
236236
<compilerArgs>
237237
<arg>-Amicronaut.processing.group=io.simplelocalize.cli</arg>
238238
<arg>-Amicronaut.processing.module=simplelocalize-cli</arg>
239+
<arg>-Amicronaut.env.deduction=false</arg>
239240
</compilerArgs>
240241
</configuration>
241242
<executions>

src/main/java/io/simplelocalize/cli/SimplelocalizeCliCommand.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@
2424
description =
2525
{
2626
"SimpleLocalize CLI is an official Localization CLI Tool for SimpleLocalize.io Platform",
27-
"Usage: 'simplelocalize-cli [command]'",
28-
"Visit https://docs.simplelocalize.io to learn more."
27+
"Usage: 'simplelocalize [command]'",
28+
"Visit https://simplelocalize.io/docs/ to learn more."
2929
},
3030
mixinStandardHelpOptions = true,
31-
version = {
32-
"SimpleLocalize CLI: " + Version.NUMBER,
33-
"JVM: ${java.version} (${java.vendor} ${java.vm.name} ${java.vm.version})",
34-
"OS: ${os.name} ${os.version} ${os.arch}"}
31+
version = {"SimpleLocalize CLI: " + Version.NUMBER + " (${os.name} ${os.version} ${os.arch})"}
3532
)
3633
public class SimplelocalizeCliCommand implements Runnable
3734
{
@@ -78,6 +75,8 @@ public void extract(
7875
{
7976
configuration.setSearchDir(searchDirectory);
8077
}
78+
ConfigurationValidator configurationValidator = new ConfigurationValidator();
79+
configurationValidator.validateExtractConfiguration(configuration);
8180
SimpleLocalizeClient client = SimpleLocalizeClient.create(configuration.getBaseUrl(), configuration.getApiKey());
8281
ExtractCommand extractCommand = new ExtractCommand(client, configuration);
8382
extractCommand.invoke();
@@ -89,8 +88,8 @@ public void extract(
8988
public void sync(
9089
@Option(names = {"--apiKey"}, description = "Project API Key") String apiKey,
9190
@Option(names = {"--uploadPath"}, description = "Path to file with translation or translation keys to upload. Use '{lang}' to define language key if you are uploading more than one file with translations.") String uploadPath,
92-
@Option(names = {"--uploadFormat"}, description = "Translations or keys format") String uploadFormat,
93-
@Option(names = {"--uploadOptions"}, split = ",", description = "(Optional) Read more about 'uploadOptions' param at docs.simplelocalize.io") List<String> uploadOptions,
91+
@Option(names = {"--uploadFormat"}, description = "Translations file format") String uploadFormat,
92+
@Option(names = {"--uploadOptions"}, split = ",", description = "(Optional) Upload options") List<String> uploadOptions,
9493
@Option(names = {"--downloadPath"}, description = "Directory where translations should be downloaded") String downloadPath,
9594
@Option(names = {"--downloadFormat"}, description = "Download format for translation file") String downloadFormat,
9695
@Option(names = {"--downloadOptions"}, split = ",", description = "(Optional) Download options") List<String> downloadOptions,
@@ -110,8 +109,8 @@ public void sync(
110109
public void upload(
111110
@Option(names = {"--apiKey"}, description = "Project API Key") String apiKey,
112111
@Option(names = {"--uploadPath"}, description = "Path to file with translation or translation keys to upload. Use '{lang}' to define language key if you are uploading more than one file with translations.") String uploadPath,
113-
@Option(names = {"--uploadFormat"}, description = "Translations or keys format") String uploadFormat,
114-
@Option(names = {"--uploadOptions"}, split = ",", description = "(Optional) Read more about 'uploadOptions' param at docs.simplelocalize.io") List<String> uploadOptions,
112+
@Option(names = {"--uploadFormat"}, description = "Translations file format") String uploadFormat,
113+
@Option(names = {"--uploadOptions"}, split = ",", description = "(Optional) Upload options") List<String> uploadOptions,
115114
@Option(names = {"--languageKey"}, description = "(Optional) Specify language key for single file upload") String languageKey,
116115
@Option(names = {"--customerId"}, description = "(Optional) Upload translations for given customerId") String customerId,
117116
@Option(names = {"--baseUrl"}, description = "(Optional) Set custom server URL") String baseUrl
@@ -156,6 +155,7 @@ public void upload(
156155

157156
ConfigurationValidator configurationValidator = new ConfigurationValidator();
158157
configurationValidator.validateUploadConfiguration(configuration);
158+
159159
SimpleLocalizeClient client = SimpleLocalizeClient.create(configuration.getBaseUrl(), configuration.getApiKey());
160160
UploadCommand uploadCommand = new UploadCommand(client, configuration);
161161
uploadCommand.invoke();
@@ -167,7 +167,7 @@ public void upload(
167167
public void download(
168168
@Option(names = {"--apiKey"}, description = "Project API Key") String apiKey,
169169
@Option(names = {"--downloadPath"}, description = "Directory where translations should be downloaded") String downloadPath,
170-
@Option(names = {"--downloadFormat"}, description = "Download format for translation file") String downloadFormat,
170+
@Option(names = {"--downloadFormat"}, description = "Translations file format") String downloadFormat,
171171
@Option(names = {"--downloadOptions"}, split = ",", description = "(Optional) Download options") List<String> downloadOptions,
172172
@Option(names = {"--languageKey"}, description = "(Optional) Setup languageKey parameter to download file with only one language translations") String languageKey,
173173
@Option(names = {"--customerId"}, description = "(Optional) Download translations for given customerId") String customerId,
@@ -214,6 +214,6 @@ public void download(
214214

215215
public void run()
216216
{
217-
log.warn(" 🤨 Please specify a command. Visit https://simplelocalize.io/docs/cli/get-started/ to learn more.");
217+
log.warn("Please specify a command. Visit https://simplelocalize.io/docs/cli/get-started/ to learn more.");
218218
}
219219
}

src/main/java/io/simplelocalize/cli/Version.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public class Version
44
{
55

6-
public static final String NUMBER = "2.0.5";
6+
public static final String NUMBER = "2.0.6";
77

88
private Version()
99
{

src/main/java/io/simplelocalize/cli/client/SimpleLocalizeClient.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ public void uploadKeys(Collection<String> keys) throws IOException, InterruptedE
6464
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
6565
throwOnError(httpResponse);
6666
int keysProcessed = JsonPath.read(httpResponse.body(), "$.data.uniqueKeysProcessed");
67-
log.info(" 🎉 Successfully uploaded {} keys", keysProcessed);
67+
log.info("Successfully uploaded {} keys", keysProcessed);
6868
}
6969

7070
public void uploadFile(UploadRequest uploadRequest) throws IOException, InterruptedException
7171
{
7272
Path uploadPath = uploadRequest.getPath();
73-
log.info(" 🌍 Uploading {}", uploadPath);
73+
log.info("Uploading {}", uploadPath);
7474
URI uri = uriFactory.buildUploadUri(uploadRequest);
7575
HttpRequest httpRequest = httpRequestFactory.createUploadFileRequest(uri, uploadRequest);
7676
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
@@ -79,7 +79,7 @@ public void uploadFile(UploadRequest uploadRequest) throws IOException, Interrup
7979

8080
public List<DownloadableFile> fetchDownloadableFiles(DownloadRequest downloadRequest) throws IOException, InterruptedException
8181
{
82-
log.info(" 🌍 Preparing translation files");
82+
log.info("Preparing files to download");
8383
URI downloadUri = uriFactory.buildDownloadUri(downloadRequest);
8484
HttpRequest httpRequest = httpRequestFactory.createGetRequest(downloadUri).build();
8585
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
@@ -105,14 +105,14 @@ public void downloadFile(DownloadableFile downloadableFile, String downloadPathT
105105
{
106106
Files.createDirectories(parentDirectory);
107107
}
108-
log.info(" 🌍 Downloading {}", savePath);
108+
log.info("Downloading {}", savePath);
109109
httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofFile(savePath, StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING));
110110
} catch (IOException e)
111111
{
112-
log.error(" 😝 Download failed: {}", savePath, e);
112+
log.error("Download failed: {}", savePath, e);
113113
} catch (InterruptedException e)
114114
{
115-
log.error(" 😝 Download interrupted: {}", savePath, e);
115+
log.error("Download interrupted: {}", savePath, e);
116116
Thread.currentThread().interrupt();
117117
}
118118
}
@@ -127,7 +127,7 @@ public int validateGate() throws IOException, InterruptedException
127127
Boolean passed = JsonPath.read(json, "$.data.passed");
128128
String message = JsonPath.read(json, "$.data.message");
129129
int status = JsonPath.read(json, "$.data.status");
130-
log.info(" 🌍 Gate result: {} (status: {}, message: {})", passed, status, message);
130+
log.info("Gate result: {} (status: {}, message: {})", passed, status, message);
131131
return status;
132132
}
133133

@@ -146,7 +146,7 @@ private void throwOnError(HttpResponse<?> httpResponse)
146146
{
147147
message = "Unknown error, HTTP Status: " + httpResponse.statusCode();
148148
}
149-
log.error(" 😝 Request failed: {}", message);
149+
log.error("Request failed: {}", message);
150150
throw new ApiRequestException(message, httpResponse);
151151
}
152152
}

src/main/java/io/simplelocalize/cli/command/DownloadCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ public void invoke()
5858
downloadableFiles
5959
.parallelStream()
6060
.forEach(downloadableFile -> client.downloadFile(downloadableFile, downloadPath));
61-
log.info(" 🎉 Download success!");
61+
log.info("Download success!");
6262
} catch (InterruptedException e)
6363
{
64-
log.error(" 😝 Translations could not be downloaded", e);
64+
log.error("Translations could not be downloaded", e);
6565
Thread.currentThread().interrupt();
6666
} catch (IOException e)
6767
{
68-
log.error(" 😝 Translations could not be downloaded", e);
68+
log.error("Translations could not be downloaded", e);
6969
System.exit(1);
7070
}
7171
}

src/main/java/io/simplelocalize/cli/command/ExtractCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ public void invoke()
3232
String searchDir = configuration.getSearchDir();
3333
String projectType = configuration.getProjectType();
3434

35-
log.info(" 🕵️‍♂️ Running keys extraction");
35+
log.info("Running keys extraction");
3636
ProjectProcessorFactory processorFactory = new ProjectProcessorFactory();
3737
ExtractionProcessor extractionProcessor = processorFactory.createForType(projectType);
3838
ExtractionResult result = extractionProcessor.process(Paths.get(searchDir));
3939

4040
Set<String> keys = result.getKeys();
4141
List<Path> processedFiles = result.getProcessedFiles();
42-
log.info(" 📦 Found {} unique keys in {} components", keys.size(), processedFiles.size());
42+
log.info("Found {} unique keys in {} components", keys.size(), processedFiles.size());
4343

4444
Set<String> ignoredKeys = new HashSet<>(configuration.getIgnoreKeys());
4545
keys.removeAll(ignoredKeys);
@@ -49,7 +49,7 @@ public void invoke()
4949
client.uploadKeys(keys);
5050
} catch (Exception e)
5151
{
52-
log.error(" 😝 Keys upload failed. Contact support: contact@simplelocalize.io", e);
52+
log.error("Keys upload failed. Contact support: contact@simplelocalize.io", e);
5353
Thread.currentThread().interrupt();
5454
}
5555
}

src/main/java/io/simplelocalize/cli/command/UploadCommand.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.simplelocalize.cli.configuration.Configuration;
77
import io.simplelocalize.cli.configuration.ConfigurationValidator;
88
import io.simplelocalize.cli.io.FileListReader;
9+
import io.simplelocalize.cli.util.WindowsUtils;
910
import org.apache.commons.lang3.StringUtils;
1011
import org.slf4j.Logger;
1112
import org.slf4j.LoggerFactory;
@@ -36,26 +37,31 @@ public UploadCommand(SimpleLocalizeClient client, Configuration configuration)
3637
public void invoke()
3738
{
3839
configurationValidator.validateUploadConfiguration(configuration);
40+
String uploadPath = configuration.getUploadPath();
41+
if (WindowsUtils.isWindows())
42+
{
43+
uploadPath = WindowsUtils.convertToWindowsPath(uploadPath);
44+
}
3945

40-
List<FileToUpload> filesToUpload = List.of();
46+
List<FileToUpload> filesToUpload;
4147
try
4248
{
43-
filesToUpload = fileListReader.findFilesToUpload(configuration.getUploadPath());
49+
filesToUpload = fileListReader.findFilesToUpload(uploadPath);
4450
} catch (IOException e)
4551
{
46-
log.error(" 😝 Matching files could not be found", e);
47-
System.exit(1);
52+
log.error("Matching files could not be found at {}", uploadPath, e);
53+
throw new IllegalArgumentException("Matching files could not be found", e);
4854
}
4955

50-
log.info(" 📄 Found {} files to upload", filesToUpload.size());
56+
log.info("Found {} files to upload", filesToUpload.size());
5157
for (FileToUpload fileToUpload : filesToUpload)
5258
{
5359
try
5460
{
5561
long length = fileToUpload.getPath().toFile().length();
5662
if (length == 0)
5763
{
58-
log.warn(" 🤔 Skipping empty file: {}", fileToUpload.getPath());
64+
log.warn("Skipping empty file: {}", fileToUpload.getPath());
5965
continue;
6066
}
6167

@@ -68,7 +74,7 @@ public void invoke()
6874
boolean isLanguageMatching = fileLanguageKey.equals(configurationLanguageKey);
6975
if (hasFileLanguageKey && hasConfigurationLanguageKey && !isLanguageMatching)
7076
{
71-
log.info(" 🤔 Skipping '{}' language, file: {}", fileToUpload.getLanguage(), fileToUpload.getPath());
77+
log.info("Skipping '{}' language, file: {}", fileToUpload.getLanguage(), fileToUpload.getPath());
7278
continue;
7379
}
7480

@@ -81,7 +87,7 @@ public void invoke()
8187
boolean isMultiLanguageFormat = isMultiLanguageFormat(configuration.getUploadFormat());
8288
if (!hasFileLanguageKey && !hasConfigurationLanguageKey && !isMultiLanguageFormat)
8389
{
84-
log.info(" 🤔 Language key not present in '--uploadPath' nor '--languageKey' parameter, file: {}", fileToUpload.getPath());
90+
log.info("Language key not present in '--uploadPath' nor '--languageKey' parameter, file: {}", fileToUpload.getPath());
8591
}
8692

8793
String uploadFormat = configuration.getUploadFormat();
@@ -99,10 +105,10 @@ public void invoke()
99105
client.uploadFile(uploadRequest);
100106
} catch (IOException e)
101107
{
102-
log.warn(" 😝 Upload failed: {}", fileToUpload.getPath(), e);
108+
log.warn("Upload failed: {}", fileToUpload.getPath(), e);
103109
} catch (InterruptedException e)
104110
{
105-
log.error(" 😝 Upload interrupted: {}", fileToUpload.getPath(), e);
111+
log.error("Upload interrupted: {}", fileToUpload.getPath(), e);
106112
Thread.currentThread().interrupt();
107113
}
108114
}

src/main/java/io/simplelocalize/cli/configuration/ConfigurationLoader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,20 @@ private Configuration load(Path configurationFilePath)
3939
Constructor yamlTargetClass = new Constructor(Configuration.class);
4040
Yaml yaml = new Yaml(yamlTargetClass);
4141

42+
log.info("Loading configuration file from: {}", configurationFilePath);
4243
Configuration configuration;
4344
try
4445
{
4546
InputStream inputStream = new FileInputStream(file);
4647
configuration = yaml.load(inputStream);
47-
log.info(" 🗄 Loaded configuration file from: {}", configurationFilePath);
48+
log.info("Configuration file loaded successfully");
4849
} catch (FileNotFoundException e)
4950
{
50-
log.info(" 🗄 No default configuration file at ./simplelocalize.yml");
51+
log.info("Configuration file not found");
5152
return new Configuration();
5253
} catch (Exception e)
5354
{
54-
log.error(" 😝 Unable to load configuration: {}", e.getMessage());
55+
log.error("Unable to load configuration: {}", e.getMessage());
5556
throw new ConfigurationException();
5657
}
5758
return configuration;

src/main/java/io/simplelocalize/cli/configuration/ConfigurationValidator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ public final class ConfigurationValidator
99
{
1010
private static final Logger log = LoggerFactory.getLogger(ConfigurationValidator.class);
1111

12+
public void validateExtractConfiguration(Configuration configuration)
13+
{
14+
validateIsNotEmptyOrNull(configuration.getApiKey(), "apiKey");
15+
validateIsNotEmptyOrNull(configuration.getProjectType(), "projectType");
16+
}
17+
1218
public void validateUploadConfiguration(Configuration configuration)
1319
{
1420
validateIsNotEmptyOrNull(configuration.getApiKey(), "apiKey");
@@ -32,5 +38,4 @@ private void validateIsNotEmptyOrNull(String format, String argumentName)
3238
throw new ConfigurationException();
3339
}
3440
}
35-
3641
}

0 commit comments

Comments
 (0)