provide file to blame on exceptions
This commit is contained in:
parent
778490b8d8
commit
d078e3d8f6
@ -1,6 +1,5 @@
|
|||||||
package de.marhali.easyi18n.io;
|
package de.marhali.easyi18n.io;
|
||||||
|
|
||||||
import com.intellij.openapi.diagnostic.Logger;
|
|
||||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
|
||||||
@ -12,6 +11,7 @@ import de.marhali.easyi18n.model.*;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,18 +37,15 @@ public class IOHandler {
|
|||||||
this.parserStrategyType = settings.getParserStrategy();
|
this.parserStrategyType = settings.getParserStrategy();
|
||||||
this.parserStrategy = parserStrategyType.getStrategy()
|
this.parserStrategy = parserStrategyType.getStrategy()
|
||||||
.getDeclaredConstructor(SettingsState.class).newInstance(settings);
|
.getDeclaredConstructor(SettingsState.class).newInstance(settings);
|
||||||
|
|
||||||
Logger.getInstance(IOHandler.class).debug("Using: ",
|
|
||||||
settings.getFolderStrategy(), settings.getParserStrategy(), settings.getFilePattern());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads translation files from the local project into our data structure. <br>
|
* Reads translation files from the local project into our data structure. <br>
|
||||||
* <b>Note:</b> This method needs to be called from a Read-Action-Context (see ApplicationManager)
|
* <b>Note:</b> This method needs to be called from a Read-Action-Context (see ApplicationManager)
|
||||||
* @return Translation data based on the configured strategies
|
* @return Translation data based on the configured strategies
|
||||||
* @throws Exception Could not read translation data
|
* @throws IOException Could not read translation data
|
||||||
*/
|
*/
|
||||||
public @NotNull TranslationData read() throws Exception {
|
public @NotNull TranslationData read() throws IOException {
|
||||||
String localesPath = this.settings.getLocalesPath();
|
String localesPath = this.settings.getLocalesPath();
|
||||||
|
|
||||||
if(localesPath == null || localesPath.isEmpty()) {
|
if(localesPath == null || localesPath.isEmpty()) {
|
||||||
@ -65,7 +62,11 @@ public class IOHandler {
|
|||||||
List<TranslationFile> translationFiles = this.folderStrategy.analyzeFolderStructure(localesDirectory);
|
List<TranslationFile> translationFiles = this.folderStrategy.analyzeFolderStructure(localesDirectory);
|
||||||
|
|
||||||
for(TranslationFile file : translationFiles) {
|
for(TranslationFile file : translationFiles) {
|
||||||
this.parserStrategy.read(file, data);
|
try {
|
||||||
|
this.parserStrategy.read(file, data);
|
||||||
|
} catch(Exception ex) {
|
||||||
|
throw new IOException(file + "\n\n" + ex.getMessage(), ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@ -75,9 +76,9 @@ public class IOHandler {
|
|||||||
* Writes the provided translation data to the local project files <br>
|
* Writes the provided translation data to the local project files <br>
|
||||||
* <b>Note:</b> This method must be called from an Write-Action-Context (see ApplicationManager)
|
* <b>Note:</b> This method must be called from an Write-Action-Context (see ApplicationManager)
|
||||||
* @param data Cached translation data to save
|
* @param data Cached translation data to save
|
||||||
* @throws Exception Write action failed
|
* @throws IOException Write action failed
|
||||||
*/
|
*/
|
||||||
public void write(@NotNull TranslationData data) throws Exception {
|
public void write(@NotNull TranslationData data) throws IOException {
|
||||||
String localesPath = this.settings.getLocalesPath();
|
String localesPath = this.settings.getLocalesPath();
|
||||||
|
|
||||||
if(localesPath == null || localesPath.isEmpty()) {
|
if(localesPath == null || localesPath.isEmpty()) {
|
||||||
@ -88,7 +89,11 @@ public class IOHandler {
|
|||||||
this.folderStrategy.constructFolderStructure(localesPath, this.parserStrategyType, data);
|
this.folderStrategy.constructFolderStructure(localesPath, this.parserStrategyType, data);
|
||||||
|
|
||||||
for(TranslationFile file : translationFiles) {
|
for(TranslationFile file : translationFiles) {
|
||||||
this.parserStrategy.write(data, file);
|
try {
|
||||||
|
this.parserStrategy.write(data, file);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new IOException(file + "\n\n" + ex.getMessage(), ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import de.marhali.easyi18n.model.*;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,14 +23,14 @@ public abstract class ParserStrategy {
|
|||||||
* @param file File to read from
|
* @param file File to read from
|
||||||
* @param data Target translation data to save the parsed data
|
* @param data Target translation data to save the parsed data
|
||||||
*/
|
*/
|
||||||
public abstract void read(@NotNull TranslationFile file, @NotNull TranslationData data) throws IOException;
|
public abstract void read(@NotNull TranslationFile file, @NotNull TranslationData data) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the relevant data to the translation file (consider namespace and locale)
|
* Writes the relevant data to the translation file (consider namespace and locale)
|
||||||
* @param data Translation data cache
|
* @param data Translation data cache
|
||||||
* @param file Target translation file
|
* @param file Target translation file
|
||||||
*/
|
*/
|
||||||
public abstract void write(@NotNull TranslationData data, @NotNull TranslationFile file) throws IOException;
|
public abstract void write(@NotNull TranslationData data, @NotNull TranslationFile file) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines translation node to use for parsing
|
* Determines translation node to use for parsing
|
||||||
|
@ -28,7 +28,7 @@ public class JsonParserStrategy extends ParserStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull TranslationFile file, @NotNull TranslationData data) throws IOException {
|
public void read(@NotNull TranslationFile file, @NotNull TranslationData data) throws Exception {
|
||||||
data.addLocale(file.getLocale());
|
data.addLocale(file.getLocale());
|
||||||
|
|
||||||
VirtualFile vf = file.getVirtualFile();
|
VirtualFile vf = file.getVirtualFile();
|
||||||
@ -43,7 +43,7 @@ public class JsonParserStrategy extends ParserStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(@NotNull TranslationData data, @NotNull TranslationFile file) throws IOException {
|
public void write(@NotNull TranslationData data, @NotNull TranslationFile file) throws Exception {
|
||||||
TranslationNode targetNode = super.getTargetNode(data, file);
|
TranslationNode targetNode = super.getTargetNode(data, file);
|
||||||
|
|
||||||
JsonObject output = new JsonObject();
|
JsonObject output = new JsonObject();
|
||||||
|
@ -10,7 +10,6 @@ import de.marhali.easyi18n.model.TranslationNode;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
@ -26,7 +25,7 @@ public class PropertiesParserStrategy extends ParserStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull TranslationFile file, @NotNull TranslationData data) throws IOException {
|
public void read(@NotNull TranslationFile file, @NotNull TranslationData data) throws Exception {
|
||||||
data.addLocale(file.getLocale());
|
data.addLocale(file.getLocale());
|
||||||
|
|
||||||
VirtualFile vf = file.getVirtualFile();
|
VirtualFile vf = file.getVirtualFile();
|
||||||
@ -41,7 +40,7 @@ public class PropertiesParserStrategy extends ParserStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(@NotNull TranslationData data, @NotNull TranslationFile file) throws IOException {
|
public void write(@NotNull TranslationData data, @NotNull TranslationFile file) throws Exception {
|
||||||
TranslationNode targetNode = super.getTargetNode(data, file);
|
TranslationNode targetNode = super.getTargetNode(data, file);
|
||||||
TranslationData targetData = new TranslationData(data.getLocales(), targetNode);
|
TranslationData targetData = new TranslationData(data.getLocales(), targetNode);
|
||||||
|
|
||||||
|
@ -9,10 +9,10 @@ import de.marhali.easyi18n.model.TranslationFile;
|
|||||||
import de.marhali.easyi18n.model.TranslationNode;
|
import de.marhali.easyi18n.model.TranslationNode;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import thito.nodeflow.config.MapSection;
|
import thito.nodeflow.config.MapSection;
|
||||||
import thito.nodeflow.config.Section;
|
import thito.nodeflow.config.Section;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ public class YamlParserStrategy extends ParserStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull TranslationFile file, @NotNull TranslationData data) throws IOException {
|
public void read(@NotNull TranslationFile file, @NotNull TranslationData data) throws Exception {
|
||||||
data.addLocale(file.getLocale());
|
data.addLocale(file.getLocale());
|
||||||
|
|
||||||
VirtualFile vf = file.getVirtualFile();
|
VirtualFile vf = file.getVirtualFile();
|
||||||
@ -40,7 +40,7 @@ public class YamlParserStrategy extends ParserStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(@NotNull TranslationData data, @NotNull TranslationFile file) throws IOException {
|
public void write(@NotNull TranslationData data, @NotNull TranslationFile file) throws Exception {
|
||||||
TranslationNode targetNode = super.getTargetNode(data, file);
|
TranslationNode targetNode = super.getTargetNode(data, file);
|
||||||
|
|
||||||
Section output = new MapSection();
|
Section output = new MapSection();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user