Skip to content

Commit 3767bfb

Browse files
committed
Merge remote-tracking branch 'WPIRoboticsProjects/master'
2 parents d048d0b + 56a5ba1 commit 3767bfb

File tree

7 files changed

+63
-56
lines changed

7 files changed

+63
-56
lines changed

build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ project(":core") {
104104
compile group: 'com.thoughtworks.xstream', name: 'xstream', version: '1.4.8'
105105
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
106106
compile group: 'com.google.guava', name: 'guava', version: '18.0'
107-
compile group: 'com.google.inject', name: 'guice', version: '4.0'
107+
// We use the no_aop version of Guice because the aop isn't avaiable in arm java
108+
// http://stackoverflow.com/a/15235190/3708426
109+
// https://github.com/google/guice/wiki/OptionalAOP
110+
compile group: 'com.google.inject', name: 'guice', version: '4.0', classifier: 'no_aop'
108111
compile group: 'com.google.inject.extensions', name: 'guice-assistedinject', version: '4.0'
109112
}
110113

core/src/main/java/edu/wpi/grip/core/GRIPCoreModule.java

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import edu.wpi.grip.core.sources.MultiImageFileSource;
1717
import edu.wpi.grip.core.util.ExceptionWitness;
1818

19-
import java.util.logging.Level;
20-
import java.util.logging.Logger;
19+
import java.io.IOException;
20+
import java.util.logging.*;
2121

2222
/**
2323
* A Guice {@link com.google.inject.Module} for GRIP's core package. This is where instances of {@link Pipeline},
@@ -29,6 +29,47 @@ public class GRIPCoreModule extends AbstractModule {
2929
private final EventBus eventBus = new EventBus(this::onSubscriberException);
3030

3131
public GRIPCoreModule() {
32+
//Set up the global level logger. This handles IO for all loggers.
33+
final Logger globalLogger = LogManager.getLogManager().getLogger("");//This is our global logger
34+
35+
try {
36+
// Remove the default handlers that stream to System.err
37+
for(Handler handler : globalLogger.getHandlers()) {
38+
globalLogger.removeHandler(handler);
39+
}
40+
41+
final Handler fileHandler = new FileHandler("%h/GRIP.log");//Log to the file "GRIPlogger.log"
42+
43+
//Set level to handler and logger
44+
fileHandler.setLevel(Level.FINE);
45+
globalLogger.setLevel(Level.FINE);
46+
47+
// We need to stream to System.out instead of System.err
48+
final StreamHandler sh = new StreamHandler(System.out, new SimpleFormatter()) {
49+
50+
@Override
51+
public synchronized void publish(final LogRecord record) {
52+
super.publish(record);
53+
// For some reason this doesn't happen automatically.
54+
// This will ensure we get all of the logs printed to the console immediately
55+
// when running on a remote device.
56+
flush();
57+
}
58+
};
59+
sh.setLevel(Level.CONFIG);
60+
61+
globalLogger.addHandler(sh); // Add stream handler
62+
63+
globalLogger.addHandler(fileHandler);//Add the handler to the global logger
64+
65+
fileHandler.setFormatter(new SimpleFormatter());//log in text, not xml
66+
67+
globalLogger.config("Configuration done.");//Log that we are done setting up the logger
68+
69+
} catch (IOException exception) {//Something happened setting up file IO
70+
throw new IllegalStateException("Failed to configure the Logger", exception);
71+
}
72+
3273
Thread.setDefaultUncaughtExceptionHandler(this::onThreadException);
3374
}
3475

@@ -68,6 +109,7 @@ private void onSubscriberException(Throwable exception, SubscriberExceptionConte
68109
logger.log(Level.FINE, "EventBus Subscriber threw InterruptedException", exception);
69110
Thread.currentThread().interrupt();
70111
} else {
112+
logger.log(Level.SEVERE, "An event subscriber threw an exception", exception);
71113
eventBus.post(new UnexpectedThrowableEvent(exception, "An event subscriber threw an exception"));
72114
}
73115
}
@@ -77,6 +119,8 @@ private void onThreadException(Thread thread, Throwable exception) {
77119
logger.log(Level.FINE, "InterruptedException from thread " + thread, exception);
78120
Thread.currentThread().interrupt();
79121
} else {
122+
// This can potentially happen before the main class has even been loaded to handle these exceptions
123+
logger.log(Level.SEVERE, "Uncaught Exception on thread " + thread, exception);
80124
eventBus.post(new UnexpectedThrowableEvent(exception, thread + " threw an exception"));
81125
}
82126
}

core/src/main/java/edu/wpi/grip/core/Main.java

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public class Main {
2828
@Inject
2929
private Logger logger;
3030

31+
@SuppressWarnings("PMD.SystemPrintln")
3132
public static void main(String[] args) throws IOException, InterruptedException {
33+
System.out.println("Loading Dependency Injection Framework");
3234
final Injector injector = Guice.createInjector(new GRIPCoreModule());
3335
injector.getInstance(Main.class).start(args);
3436
}
@@ -38,31 +40,10 @@ public void start(String[] args) throws IOException, InterruptedException {
3840
if (args.length != 1) {
3941
System.err.println("Usage: GRIP.jar project.grip");
4042
return;
43+
} else {
44+
logger.log(Level.INFO, "Loading file " + args[0]);
4145
}
4246

43-
//Set up the global level logger. This handles IO for all loggers.
44-
Logger globalLogger = LogManager.getLogManager().getLogger("");//This is our global logger
45-
46-
Handler fileHandler = null;//This will be our handler for the global logger
47-
48-
try {
49-
fileHandler = new FileHandler("%h/GRIP.log");//Log to the file "GRIPlogger.log"
50-
51-
globalLogger.addHandler(fileHandler);//Add the handler to the global logger
52-
53-
fileHandler.setFormatter(new SimpleFormatter());//log in text, not xml
54-
55-
//Set level to handler and logger
56-
fileHandler.setLevel(Level.FINE);
57-
globalLogger.setLevel(Level.FINE);
58-
59-
globalLogger.config("Configuration done.");//Log that we are done setting up the logger
60-
61-
} catch (IOException exception) {//Something happened setting up file IO
62-
throw new IllegalStateException(exception);
63-
}
64-
65-
6647
Operations.addOperations(eventBus);
6748
CVOperations.addOperations(eventBus);
6849

@@ -73,7 +54,7 @@ public void start(String[] args) throws IOException, InterruptedException {
7354

7455

7556
// This is done in order to indicate to the user using the deployment UI that this is running
76-
System.out.println("SUCCESS! The project is running in headless mode!");
57+
logger.log(Level.INFO, "SUCCESS! The project is running in headless mode!");
7758
// There's nothing more to do in the main thread since we're in headless mode - sleep forever
7859
for (; ; ) {
7960
Thread.sleep(Integer.MAX_VALUE);

ui/src/main/java/edu/wpi/grip/ui/DeployerController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ public StreamToTextArea(TextArea outputArea) {
5555
}
5656

5757
public StreamToTextArea reset() {
58-
outputArea.clear();
58+
Platform.runLater(outputArea::clear);
5959
return this;
6060
}
6161

6262
@Override
6363
public void write(int i) throws IOException {
64-
outputArea.appendText(String.valueOf((char) i));
64+
Platform.runLater(()-> outputArea.appendText(String.valueOf((char) i)));
6565
}
6666
}
6767

ui/src/main/java/edu/wpi/grip/ui/Main.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import javafx.stage.Stage;
2121

2222
import javax.inject.Inject;
23-
import java.io.IOException;
24-
import java.util.logging.*;
2523

2624
public class Main extends Application {
2725

@@ -53,29 +51,6 @@ public Main() {
5351
@Override
5452
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
5553
public void start(Stage stage) throws Exception {
56-
57-
//Set up the global level logger. This handles IO for all loggers.
58-
Logger globalLogger = LogManager.getLogManager().getLogger("");//This is our global logger
59-
60-
Handler fileHandler = null;//This will be our handler for the global logger
61-
62-
try {
63-
fileHandler = new FileHandler("%h/GRIP.log");//Log to the file "GRIP.log"
64-
65-
globalLogger.addHandler(fileHandler);//Add the handler to the global logger
66-
67-
fileHandler.setFormatter(new SimpleFormatter());//log in text, not xml
68-
69-
//Set level to handler and logger
70-
fileHandler.setLevel(Level.FINE);
71-
globalLogger.setLevel(Level.FINE);
72-
73-
globalLogger.config("Configuration done.");//Log that we are done setting up the logger
74-
75-
} catch (IOException exception) {//Something happened setting up file IO
76-
throw new IllegalStateException(exception);
77-
}
78-
7954
root = FXMLLoader.load(Main.class.getResource("MainWindow.fxml"), null, null, injector::getInstance);
8055
root.setStyle("-fx-font-size: " + DPIUtility.FONT_SIZE + "px");
8156

ui/src/main/java/edu/wpi/grip/ui/MainWindowController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import javafx.scene.control.SplitPane;
1414
import javafx.scene.layout.Region;
1515
import javafx.stage.FileChooser;
16+
import javafx.stage.FileChooser.ExtensionFilter;
1617

1718
import javax.inject.Inject;
1819
import java.io.File;
@@ -110,6 +111,9 @@ public void openProject() throws IOException {
110111
if (showConfirmationDialogAndWait()) {
111112
final FileChooser fileChooser = new FileChooser();
112113
fileChooser.setTitle("Open Project");
114+
fileChooser.getExtensionFilters().addAll(
115+
new ExtensionFilter("GRIP File", "*.grip"),
116+
new ExtensionFilter("All Files", "*.*"));
113117

114118
project.getFile().ifPresent(file -> fileChooser.setInitialDirectory(file.getParentFile()));
115119

@@ -149,6 +153,7 @@ public boolean saveProject() throws IOException {
149153
public boolean saveProjectAs() throws IOException {
150154
final FileChooser fileChooser = new FileChooser();
151155
fileChooser.setTitle("Save Project As");
156+
fileChooser.getExtensionFilters().add(new ExtensionFilter("GRIP File", "*.grip"));
152157

153158
project.getFile().ifPresent(file -> fileChooser.setInitialDirectory(file.getParentFile()));
154159

@@ -184,4 +189,3 @@ public void deployFRC() {
184189

185190
}
186191
}
187-

ui/src/main/java/edu/wpi/grip/ui/util/deployment/DeployedInstanceManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ public synchronized void start() throws IOException {
180180
synchronized (this) {
181181
sshThread = Optional.empty();
182182
}
183+
eventBus.post(new StartedStoppedEvent(this));
183184
}
184185
}, "SSH Monitor Thread");
185186
launcher.setUncaughtExceptionHandler((thread, exception) -> {
@@ -216,7 +217,6 @@ public synchronized void stop() throws IOException {
216217
}
217218
runStop();
218219
} while (isStarted() && !Thread.interrupted());
219-
eventBus.post(new StartedStoppedEvent(this));
220220
}
221221

222222
/**

0 commit comments

Comments
 (0)