Skip to content
This repository has been archived by the owner on Mar 15, 2023. It is now read-only.

Commit

Permalink
Added proper logging and refactored tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob van Mourik committed Feb 4, 2017
1 parent 4a2af52 commit 8e1784a
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .inno.iss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define AppName "i18n-editor"
#define AppVersion "1.0.0-beta.1"
#define AppVersion "1.0.0-beta.2"
#define AppPublisher "JvMs Software"
#define AppURL "https://github.com/jcbvm/i18n-editor"
#define AppExeName "i18n-editor.exe"
Expand Down
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
<version>3.5</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
<version>21.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.22</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
29 changes: 21 additions & 8 deletions src/main/java/com/jvms/i18neditor/editor/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.event.KeyAdapter;
Expand Down Expand Up @@ -46,6 +47,8 @@
import javax.swing.tree.TreePath;

import org.apache.commons.lang3.LocaleUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
Expand All @@ -70,6 +73,7 @@
*/
public class Editor extends JFrame {
private final static long serialVersionUID = 1113029729495390082L;
private final static Logger log = LoggerFactory.getLogger(Editor.class);

public final static String TITLE = "i18n-editor";
public final static String VERSION = "1.0.0-beta.2";
Expand Down Expand Up @@ -115,7 +119,7 @@ public void createProject(Path dir, ResourceType type) {
MessageBundle.get("dialogs.project.new.conflict.text"),
JOptionPane.YES_NO_OPTION);
if (importProject) {
importProject(dir, true);
importProject(dir, false);
return;
}
}
Expand All @@ -135,7 +139,7 @@ public void createProject(Path dir, ResourceType type) {
updateHistory();
updateUI();
} catch (IOException e) {
e.printStackTrace();
log.error("Error creating resource files", e);
showError(MessageBundle.get("resources.create.error"));
}
}
Expand Down Expand Up @@ -173,7 +177,7 @@ public void importProject(Path dir, boolean showEmptyProjectError) {
setupResource(resource);
project.addResource(resource);
} catch (IOException e) {
e.printStackTrace();
log.error("Error importing resource file " + resource.getPath(), e);
showError(MessageBundle.get("resources.import.error.single", resource.getPath().toString()));
}
});
Expand All @@ -186,7 +190,7 @@ public void importProject(Path dir, boolean showEmptyProjectError) {
updateHistory();
updateUI();
} catch (IOException e) {
e.printStackTrace();
log.error("Error importing resource files", e);
showError(MessageBundle.get("resources.import.error.multiple"));
}
}
Expand All @@ -198,8 +202,8 @@ public boolean saveProject() {
try {
Resources.write(resource, !project.isMinifyResources());
} catch (IOException e) {
e.printStackTrace();
error = true;
log.error("Error saving resource file " + resource.getPath(), e);
showError(MessageBundle.get("resources.write.error.single", resource.getPath().toString()));
}
}
Expand Down Expand Up @@ -341,7 +345,7 @@ public void showAddLocaleDialog() {
project.addResource(resource);
updateUI();
} catch (IOException e) {
e.printStackTrace();
log.error("Error creating new locale", e);
showError(MessageBundle.get("dialogs.locale.add.error.create"));
}
}
Expand Down Expand Up @@ -503,6 +507,15 @@ public boolean closeCurrentProject() {
return result;
}

public void openProjectDirectory() {
if (project == null) return;
try {
Desktop.getDesktop().open(project.getPath().toFile());
} catch (IOException ex) {
log.error("Unable to open project directory " + project.getPath(), ex);
}
}

public void launch() {
restoreEditorState();

Expand Down Expand Up @@ -631,8 +644,8 @@ public void filesDropped(java.io.File[] files) {
try {
Path path = Paths.get(files[0].getCanonicalPath());
importProject(path, true);
} catch (IOException e ) {
e.printStackTrace();
} catch (IOException e) {
log.error("Error importing resources via file drop", e);
showError(MessageBundle.get("resources.open.error.multiple"));
}
}
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/com/jvms/i18neditor/editor/EditorMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.awt.Desktop;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
Expand Down Expand Up @@ -137,13 +136,7 @@ private void setupUI() {

openContainingFolderMenuItem = new JMenuItem(MessageBundle.get("menu.file.folder.title"));
openContainingFolderMenuItem.setEnabled(false);
openContainingFolderMenuItem.addActionListener(e -> {
try {
Desktop.getDesktop().open(editor.getProject().getPath().toFile());
} catch (IOException ex) {
ex.printStackTrace();
}
});
openContainingFolderMenuItem.addActionListener(e -> editor.openProjectDirectory());

openRecentMenuItem = new JMenu(MessageBundle.get("menu.file.recent.title"));
openRecentMenuItem.setEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import java.util.Properties;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Strings;
import com.google.common.collect.Lists;

Expand All @@ -26,6 +29,7 @@
*/
public class ExtendedProperties extends Properties {
private final static long serialVersionUID = 6042931434040718478L;
private final static Logger log = LoggerFactory.getLogger(ExtendedProperties.class);
private final String listSeparator;

/**
Expand Down Expand Up @@ -75,6 +79,7 @@ public void load(Path path) {
try (InputStream in = Files.newInputStream(path)) {
load(in);
} catch (IOException e) {
log.error("Unable to load properties from " + path, e);
}
}

Expand All @@ -90,6 +95,7 @@ public void store(Path path) {
try (OutputStream out = new OutputStreamWrapper(Files.newOutputStream(path))) {
store(out, null);
} catch (IOException e) {
log.error("Unable to store properties to " + path, e);
}
}

Expand Down Expand Up @@ -164,6 +170,7 @@ public Integer getIntegerProperty(String key) {
try {
return Integer.parseInt(value);
} catch (Exception e) {
log.warn("Unable to parse integer property value " + value);
}
}
return null;
Expand Down Expand Up @@ -226,6 +233,7 @@ public <T extends Enum<T>> T getEnumProperty(String key, Class<T> enumType) {
try {
return T.valueOf(enumType, value);
} catch (Exception e) {
log.warn("Unable to parse enum property value " + value);
}
}
return null;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/jvms/i18neditor/util/GithubRepoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Charsets;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.gson.Gson;
Expand All @@ -19,6 +22,7 @@
* @author Jacob
*/
public final class GithubRepoUtil {
private final static Logger log = LoggerFactory.getLogger(GithubRepoUtil.class);
private final static Gson gson = new Gson();
private final static ExecutorService executor;

Expand All @@ -44,6 +48,7 @@ public static Future<GithubRepoReleaseData> getLatestRelease(String repo) {
return gson.fromJson(reader, GithubRepoReleaseData.class);
}
} catch (IOException e) {
log.error("Unable to retrieve latest github release data", e);
return null;
} finally {
if (connection != null) {
Expand Down
Loading

0 comments on commit 8e1784a

Please sign in to comment.