-
Notifications
You must be signed in to change notification settings - Fork 44
/
Dna.java
91 lines (80 loc) · 2.96 KB
/
Dna.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package dna;
import java.io.*;
import java.net.URISyntaxException;
import gui.Gui;
import logger.LogEvent;
import logger.Logger;
import sql.Sql;
/**
* Main class of the Discourse Network Analyzer (DNA).
*
* @author Philip Leifeld {@literal <philip.leifeld@essex.ac.uk>}
*/
public class Dna {
public static Dna dna;
public static Logger logger;
public static Sql sql;
public static final String date = "2024-02-04";
public static final String version = "3.0.11";
public static final String operatingSystem = System.getProperty("os.name");
public static File workingDirectory = null;
public static Gui gui;
public HeadlessDna headlessDna;
/**
* Create a new instance of DNA including the GUI.
*/
public Dna(String[] args) {
logger = new Logger();
sql = new Sql();
LogEvent l = new LogEvent(Logger.MESSAGE,
"DNA started. Version " + version + " (" + date + ").",
"DNA started. Version " + version + " (" + date + "). Operating system: " + operatingSystem + ".");
Dna.logger.log(l);
// determine JAR working directory as starting directory for file dialogs
String currentDir = "~/";
try {
currentDir = new File(HeadlessDna.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getPath();
} catch (URISyntaxException ex) {
LogEvent le = new LogEvent(Logger.WARNING,
"Current JAR working directory cannot be detected.",
"Tried to detect the current JAR working directory, but the path could not be detected. Will use the home user directory instead.",
ex);
logger.log(le);
}
workingDirectory = new File(currentDir);
// start GUI or headless DNA
if (args != null && args.length > 0 && args[0].equals("headless")) {
headlessDna = new HeadlessDna();
Dna.logger.addListener(headlessDna);
LogEvent l2 = new LogEvent(Logger.MESSAGE,
"DNA started in headless mode.",
"DNA started in headless mode to work with rDNA.");
Dna.logger.log(l2);
} else {
gui = new Gui();
}
}
/**
* Start DNA.
*
* @param args Any arguments from the terminal/command line/shell.
*/
public static void main(String[] args) {
Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler());
dna = new Dna(args);
}
/**
* Default exception handler. This catches all uncaught exceptions and logs
* them in the logger, instead of printing them on the terminal.
*/
private static final class DefaultExceptionHandler implements Thread.UncaughtExceptionHandler {
@Override
public void uncaughtException(Thread t, Throwable e) {
LogEvent le = new LogEvent(Logger.ERROR,
"Uncaught exception.",
"An uncaught exception occurred. This is most likely a bug. Please open a new issue at https://github.com/leifeld/dna/issues/ and paste the log event stack trace and the exception stack trace there as part of your error description, along with details of what happened and under what circumstances. Thank you.",
e);
logger.log(le);
}
}
}