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

Cert bug fixes #287

Merged
merged 20 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
9 changes: 7 additions & 2 deletions src/main/java/com/rcv/ContestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,13 @@ static ContestConfig loadContestConfig(String configPath) {
Logger.log(Level.INFO, "Successfully loaded contest config: %s", configPath);
// perform some additional sanity checks
if (rawConfig.validate()) {
// checks passed so continue processing
config = loadContestConfig(rawConfig, new File(configPath).getParent());
// source folder will be the parent of configPath
String parentFolder = new File(configPath).getParent();
// if there is no parent folder use current working directory
if (parentFolder == null) {
parentFolder = System.getProperty("user.dir");
}
config = loadContestConfig(rawConfig, parentFolder);
} else {
Logger.log(Level.SEVERE, "Failed to create contest config!");
}
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/com/rcv/GuiApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

package com.rcv;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Level;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.EventHandler;
Expand All @@ -28,10 +32,18 @@
public class GuiApplication extends Application {

@Override
public void start(Stage window) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/com/rcv/GuiConfigLayout.fxml"));
window.setTitle("RCVRC Tabulator");
window.setScene(new Scene(root));
public void start(Stage window) {
String resourcePath = "/com/rcv/GuiConfigLayout.fxml";
try {
Parent root = FXMLLoader.load(getClass().getResource(resourcePath));
window.setTitle("RCVRC Tabulator");
window.setScene(new Scene(root));
} catch (IOException exception) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
HEdingfield marked this conversation as resolved.
Show resolved Hide resolved
exception.printStackTrace(pw);
Logger.log(Level.SEVERE, "Failed to open: %s:\n%s. ", resourcePath, sw.toString());
}
// cache main window so we can parent file choosers to it
GuiContext context = GuiContext.getInstance();
context.setMainWindow(window);
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/com/rcv/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Logger {
// function: setup
// purpose: initialize logging module
// throws: IOException if unable to open output log file
static void setup() throws IOException {
static void setup() {
// cache default logger
logger = java.util.logging.Logger.getLogger("");
logger.setLevel(Level.FINE);
Expand All @@ -82,20 +82,27 @@ static void setup() throws IOException {
Path logPath =
Paths.get(System.getProperty("user.dir"), EXECUTION_LOG_FILE_NAME).toAbsolutePath();

// executionHandler writes to the execution log file
FileHandler executionHandler =
new FileHandler(
logPath.toString(), LOG_FILE_MAX_SIZE_BYTES, EXECUTION_LOG_FILE_COUNT, true);
executionHandler.setLevel(Level.INFO);
logger.addHandler(executionHandler);
// executionHandler writes to the execution log file in current working directory
try {
FileHandler executionHandler =
new FileHandler(
logPath.toString(), LOG_FILE_MAX_SIZE_BYTES, EXECUTION_LOG_FILE_COUNT, true);
executionHandler.setLevel(Level.INFO);
logger.addHandler(executionHandler);
} catch (IOException exception) {
log(Level.WARNING, (String.format("Failed to start system logging!\n" +
HEdingfield marked this conversation as resolved.
Show resolved Hide resolved
"Make sure you have write access in %s\n%s.",
System.getProperty("user.dir"),
exception.toString())));
}

// use our custom formatter for all installed handlers
for (Handler handler : logger.getHandlers()) {
handler.setFormatter(formatter);
}

// log results
log(Level.INFO, "RCV Tabulator logging execution to: %s", logPath.toString());
log(Level.INFO, "RCV Tabulator logging to: %s", logPath.toString());
}

// function: addTabulationFileLogging
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/com/rcv/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

package com.rcv;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
Expand All @@ -32,11 +31,7 @@ public class Main extends GuiApplication {
// param: args command line argument array
// returns: N/A
public static void main(String[] args) {
try {
Logger.setup();
} catch (IOException exception) {
System.err.print(String.format("Failed to start system logging!\n%s", exception.toString()));
}
Logger.setup();

// Determine if user intends to use the command-line interface, and gather args if so
boolean useCli = false;
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/com/rcv/TieBreak.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
package com.rcv;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.SortedMap;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -190,8 +193,8 @@ private String doInteractiveCli() {
String selectedCandidate = null;
while (selectedCandidate == null || selectedCandidate.isEmpty()) {
// TODO: Create and enable cancel option for interactive tiebreaker CLI
// container for user console input
String userInput = System.console().readLine();
Scanner sc = new Scanner(System.in);
String userInput = sc.nextLine();
try {
// user selected loser parsed to int
int choice = Integer.parseInt(userInput);
Expand Down Expand Up @@ -303,20 +306,20 @@ public String call() {
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("RCV Tiebreaker");
String resourcePath = "/com/rcv/GuiTiebreakerLayout.fxml";
FXMLLoader loader = new FXMLLoader(getClass().getResource(resourcePath));

try {
FXMLLoader loader = new FXMLLoader(getClass().getResource(resourcePath));
HEdingfield marked this conversation as resolved.
Show resolved Hide resolved
Parent root = loader.load();
GuiTiebreakerController controller = loader.getController();
controller.populateTiedCandidates(tiedCandidates);
window.setScene(new Scene(root));
window.showAndWait();
candidateToEliminate = controller.getCandidateToEliminate();
} catch (IOException exception) {
Logger.log(
Level.SEVERE, "Failed to open: %s:\n%s", resourcePath, exception.getCause().toString());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
exception.printStackTrace(pw);
Logger.log(Level.SEVERE, "Failed to open: %s:\n%s. ", resourcePath,sw.toString());
}

return candidateToEliminate;
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/test/java/com/rcv/TabulatorTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,7 @@ private static void compareJson(
// purpose: runs once at the beginning of testing to setup logging
@BeforeAll
static void setup() {
try {
Logger.setup();
} catch (IOException exception) {
// this is non-fatal
System.err.print(String.format("Failed to start system logging!\n%s", exception.toString()));
}
}

// function: invalidParamsTest
Expand Down