Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression bugs in pr 214 #228

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Changes from 7 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
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ public void run() {

try {
Path translationsDirectoryPath = inputFilePath.getParent().resolve("translations");

if (Objects.equals(extractionType, "configs")) {
tempsConfig = Files.createTempDirectory("configs");
} else tempsConfig = null;
tempsConfig = Files.createTempDirectory("configs");
if (!Files.exists(translationsDirectoryPath))
Files.createDirectories(translationsDirectoryPath);
if (translationFile == null) {
Expand All @@ -93,6 +90,9 @@ public void run() {
// Check if the input path is a directory or a JSON file
if (Files.isDirectory(inputFilePath)) {
if (Objects.equals(extractionType, "configs") || inputFilePath.endsWith("configs")) {
hilpitome marked this conversation as resolved.
Show resolved Hide resolved
// handle case where extractionType has not been given and inputFilePath ends with
// configs
if (Objects.equals(extractionType, null)) extractionType = "configs";
hilpitome marked this conversation as resolved.
Show resolved Hide resolved
Set<String> targetFields = FCTConstants.configTranslatables;
copyDirectoryContent(inputFilePath, tempsConfig);
extractContent(translationFile, inputFilePath, targetFields, extractionType);
Expand Down Expand Up @@ -379,7 +379,12 @@ private void extractContent(
// Handle the case where inputFilePath is a directory (folders may contain multiple JSON
// files)

Files.walk(tempsConfig)
Path inputDir;
if (extractionType.equals("configs")) {
hilpitome marked this conversation as resolved.
Show resolved Hide resolved
inputDir = tempsConfig;
} else inputDir = inputFilePath;

Files.walk(inputDir)
.filter(Files::isRegularFile)
.filter(file -> file.toString().endsWith(".json"))
.forEach(
Expand All @@ -402,7 +407,8 @@ private void extractContent(
processJsonFile(file, textToHash, targetFields);
}
} catch (IOException | NoSuchAlgorithmException e) {
deleteDirectoryRecursively(tempsConfig);
if (tempsConfig != null && Files.exists(tempsConfig))
deleteDirectoryRecursively(tempsConfig);
throw new RuntimeException(
"Error while reading file " + file.getFileName() + " " + e);
}
Expand All @@ -426,7 +432,7 @@ private void extractContent(
existingProperties.putAll(textToHash);
writePropertiesFile(existingProperties, translationFile);
FctUtils.printInfo(String.format("Translation file\u001b[36m %s \u001b[0m", translationFile));
if (tempsConfig != null) deleteDirectoryRecursively(tempsConfig);
if (tempsConfig != null && Files.exists(tempsConfig)) deleteDirectoryRecursively(tempsConfig);
}

private static void processJsonFile(
Expand Down
Loading