Skip to content

Commit

Permalink
Logging Added
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Nguyen committed Feb 5, 2018
1 parent 4ee9ca7 commit 2f1642f
Show file tree
Hide file tree
Showing 36 changed files with 545 additions and 602 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ dependencies {
compile('org.web3j:core:3.2.0')
compile group: 'commons-io', name: 'commons-io', version: '2.4'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
compile 'de.codecentric.centerdevice:centerdevice-nsmenufx:2.1.5'
}
25 changes: 0 additions & 25 deletions build/resources/main/kill_geth_popup.fxml

This file was deleted.

1 change: 1 addition & 0 deletions build/resources/main/logger.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java.util.logging.SimpleFormatter.format='%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n'
25 changes: 0 additions & 25 deletions out/production/resources/kill_geth_popup.fxml

This file was deleted.

1 change: 1 addition & 0 deletions out/production/resources/logger.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java.util.logging.SimpleFormatter.format='%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n'
102 changes: 58 additions & 44 deletions src/main/java/build_structure/Build.java
Original file line number Diff line number Diff line change
@@ -1,95 +1,109 @@
package build_structure;

import javafx.scene.control.Alert;
import ui.Global;
import ui.Init;
import utils.Utils;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.logging.Logger;

public class Build {
/**
* This Class Is Used To Insert Config Files And Binaries
*/
private static final Logger LOGGER = Logger.getLogger(Build.class.getName());
private String mainFolder = Global.getPath() + File.separator + "BCL_CL";
//> Windows
//>> Internal Paths
final private String winEthminerBinaryRes = "/binaries/windows/ethminer.exe";
final private String winStaticNodeRes = "/json/static-nodes.json";//=Mac
final private String winGenesisRes = "/json/genesis.json"; //==Mac
final private String winGethBinaryRes = "/binaries/windows/geth.exe";
final private String winStartCommandRes = "/commands/windows/start.cmd";
final private String winGethCommandRes = "/commands/windows/geth.cmd";
final private String winEthMinerCommandRes = "/commands/windows/ethminer.cmd";
//>> External Paths
private String winEthminerBinary = Global.getPath() + File.separator + "ethminer.exe";
private String winGenesis = Global.getPath() + File.separator + "genesis.json";//==Mac
private String winGethBinary = Global.getPath() + File.separator + "geth.exe";
private String winStartCommand = Global.getPath() + File.separator + "start.cmd";
private String winGethCommand = Global.getPath() + File.separator + "geth.cmd";
private String winEthMinerCommand = Global.getPath() + File.separator + "ethminer.cmd";
private String winStaticNode = Global.getPath() + File.separator + "BCL_Node" + File.separator
final private String winEthminerBinary = Global.getPath() + File.separator + "ethminer.exe";
final private String winGenesis = Global.getPath() + File.separator + "genesis.json";//==Mac
final private String winGethBinary = Global.getPath() + File.separator + "geth.exe";
final private String winStartCommand = Global.getPath() + File.separator + "start.cmd";
final private String winGethCommand = Global.getPath() + File.separator + "geth.cmd";
final private String winEthMinerCommand = Global.getPath() + File.separator + "ethminer.cmd";
final private String winStaticNode = Global.getPath() + File.separator + "BCL_Node" + File.separator
+ "geth" + File.separator + "static-nodes.json";//=Mac
//> Mac
//>> Commands

//>> Internal Paths
final private String macStaticNodeRes = "/json/static-nodes.json";//=Win
final private String macEthminerBinaryRes = "/binaries/mac/ethminer";
final private String macGenesisRes = "/json/genesis.json"; //==Win
private final String macGethBinaryRes = "/binaries/mac/geth";
private final String macStartCommandRes = "/commands/mac/start.command";
private final String macGethCommandRes = "/commands/mac/geth.command";
private final String macEthMinerCommandRes = "/commands/mac/ethminer.command";
//>> External Paths
private String macEthminerBinary = Global.getPath() + File.separator + "ethminer";
private String macGenesis = Global.getPath() + File.separator + "genesis.json";//==Win
private String macGethBinary = Global.getPath() + File.separator + "geth";
private String macStartCommand = Global.getPath() + File.separator + "start.command";
private String macGethCommand = Global.getPath() + File.separator + "geth.command";
private String macEthMinerCommand = Global.getPath() + File.separator + "ethminer.command";
private String macStaticNode = Global.getPath() + File.separator + "BCL_Node" + File.separator
final private String macEthminerBinary = Global.getPath() + File.separator + "ethminer";
final private String macGenesis = Global.getPath() + File.separator + "genesis.json";//==Win
final private String macGethBinary = Global.getPath() + File.separator + "geth";
final private String macStartCommand = Global.getPath() + File.separator + "start.command";
final private String macGethCommand = Global.getPath() + File.separator + "geth.command";
final private String macEthMinerCommand = Global.getPath() + File.separator + "ethminer.command";
final private String macStaticNode = Global.getPath() + File.separator + "BCL_Node" + File.separator
+ "geth" + File.separator + "static-nodes.json";//=Win

public void BCLFolder() {
LOGGER.addHandler(Global.getLog_fh());
LOGGER.config("Adding BCL Folder");
try {
Path path = Paths.get(mainFolder);
Files.createDirectories(path);
} catch (IOException e) {
System.out.println("Unable To Create BCL_CL Folder");
e.printStackTrace();
LOGGER.warning("COULDN'T CREATE BCL_FOLDER \n\n" + Arrays.toString(e.getStackTrace()));
LOGGER.warning("Attempted creating BCL Folder at " + mainFolder);
//Create Alert ->
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Cannot Build BCL_CL Folder ");
alert.setContentText("Please Report This Issue W/ Your Log File @ https://discord.gg/kDzP4P8");
alert.show();
}
}

public void binaries() {
LOGGER.addHandler(Global.getLog_fh());
LOGGER.config("Adding Binaries");
if (Global.getOS().contains("win")) {
String winGethBinaryRes = "/binaries/windows/geth.exe";
Utils.export_resource(winGethBinaryRes, winGethBinary);
LOGGER.config("Windows Geth Added");
String winGenesisRes = "/json/genesis.json";
Utils.export_resource(winGenesisRes, winGenesis);
LOGGER.config("Windows Genesis File Added");
String winEthminerBinaryRes = "/binaries/windows/ethminer.exe";
Utils.export_resource(winEthminerBinaryRes, winEthminerBinary);
LOGGER.config("Windows Ethminer Added");
String winStaticNodeRes = "/json/static-nodes.json";
Utils.export_resource(winStaticNodeRes, winStaticNode);
}
if (Global.getOS().contains("mac")) {
} else if (Global.getOS().contains("mac")) {
String macGethBinaryRes = "/binaries/mac/geth";
Utils.export_resource(macGethBinaryRes, macGethBinary);
LOGGER.config("Mac Geth Added");
String macGenesisRes = "/json/genesis.json";
Utils.export_resource(macGenesisRes, macGenesis);
LOGGER.config("Mac Genesis File Added");
String macEthminerBinaryRes = "/binaries/mac/ethminer";
Utils.export_resource(macEthminerBinaryRes, macEthminerBinary);
LOGGER.config("Mac Ethminer Added");
String macStaticNodeRes = "/json/static-nodes.json";
Utils.export_resource(macStaticNodeRes, macStaticNode);
}
//Linux Support Coming...
}

public void commands() {
if (Global.getOS().contains("win")) {
String winStartCommandRes = "/commands/windows/start.cmd";
Utils.export_resource(winStartCommandRes, winStartCommand);
String winGethCommandRes = "/commands/windows/geth.cmd";
Utils.export_resource(winGethCommandRes, winGethCommand);
String winEthMinerCommandRes = "/commands/windows/ethminer.cmd";
Utils.export_resource(winEthMinerCommandRes, winEthMinerCommand);
}
//NOTE: Not else for future linux support
if (Global.getOS().contains("mac")) {
} else if (Global.getOS().contains("mac")) {
String macStartCommandRes = "/commands/mac/start.command";
Utils.export_resource(macStartCommandRes, macStartCommand);
String macGethCommandRes = "/commands/mac/geth.command";
Utils.export_resource(macGethCommandRes, macGethCommand);
String macEthMinerCommandRes = "/commands/mac/ethminer.command";
Utils.export_resource(macEthMinerCommandRes, macEthMinerCommand);
}
}

public void start_command() {

//Linux Support Coming...
}
}
46 changes: 34 additions & 12 deletions src/main/java/build_structure/Commands.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package build_structure;

import ui.Global;
import ui.Init;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.logging.Logger;

public class Commands {
/**
* Used To Execute Sys Commands
*/
private static final Logger LOGGER = Logger.getLogger(Commands.class.getName());
//Mac Commands
final static private String macStartCommand = Global.getPath() + File.separator + "start.command";
final static private String macGethCommand = Global.getPath() + File.separator + "geth.command";
Expand All @@ -21,6 +28,8 @@ public class Commands {
Process p = null;

public void start() {
LOGGER.addHandler(Global.getLog_fh());
LOGGER.info("Running Start Command File");
Runnable r = () -> {
try {
ProcessBuilder pb = null;
Expand All @@ -33,14 +42,23 @@ public void start() {
startProcess(pb);
} catch (IOException e) {
e.printStackTrace();
LOGGER.warning("UNABLE TO RUN START COMMAND \n\n"+ Arrays.toString(e.getStackTrace()));
System.exit(1);
}
};

new Thread(r).start();
LOGGER.info("Reordering Thread Priorities For Geth");
reorder_threads(r);
}
private static void reorder_threads(Runnable r){
//Set Ui Thread Lower Priority Until Geth is Synced
Global.getUiThread().setPriority(Thread.MIN_PRIORITY);
Global.setGethThread(new Thread(r));
Global.getGethThread().setPriority(Thread.MAX_PRIORITY);
Global.getGethThread().start();
}

public void geth() {
LOGGER.addHandler(Global.getLog_fh());
LOGGER.info("Running Geth Command File");
Runnable r = () -> {
try {
ProcessBuilder pb = null;
Expand All @@ -53,14 +71,17 @@ public void geth() {
startProcess(pb);
} catch (IOException e) {
e.printStackTrace();
LOGGER.warning("UNABLE TO RUN GETH COMMAND \n\n"+ Arrays.toString(e.getStackTrace()));
System.exit(1);
}
};

new Thread(r).start();
//Set Ui Thread Lower Priority Until Geth is Synced
reorder_threads(r);
}

public void mine() {
LOGGER.addHandler(Global.getLog_fh());
LOGGER.info("Running Mining_Popup Command File");
try {
switch (Global.getOS()) {
case "mac":
Expand All @@ -73,11 +94,14 @@ public void mine() {
Global.getAppProcesses().add(p);
} catch (IOException e) {
e.printStackTrace();
LOGGER.warning("UNABLE TO RUN MINING COMMAND " + Arrays.toString(e.getStackTrace()));
System.exit(1);
}
}

public static void kill_geth_ethminer() {
LOGGER.addHandler(Global.getLog_fh());
LOGGER.info("Running Mining_Popup Command File");
try {
if (Global.getOS().contains("mac")) {
Process p = Runtime.getRuntime().exec("killall geth");
Expand All @@ -100,31 +124,29 @@ public static void kill_geth_ethminer() {
}
} catch (IOException e) {
e.printStackTrace();
LOGGER.warning("Unable to Kill Ethminer/Geth" + Arrays.toString(e.getStackTrace()));
System.exit(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

void startProcess(ProcessBuilder pb) throws IOException {
private void startProcess(ProcessBuilder pb) throws IOException {
LOGGER.addHandler(Global.getLog_fh());
LOGGER.info("Process Builder Started");
pb.redirectErrorStream(true);

/* Start the process */
Process proc = pb.start();
Global.getAppProcesses().add(proc);
System.out.println("Process started !");

/* Read the process's output */
String line;
BufferedReader in = new BufferedReader(new InputStreamReader(
proc.getInputStream()));
while ((line = in.readLine()) != null) {
System.out.println(line);
LOGGER.info("GETH: " + line);
}

/* Clean-up */
proc.destroy();
System.out.println("Process ended !");
Global.getAppProcesses().add(p);
}
}
14 changes: 12 additions & 2 deletions src/main/java/build_structure/Permission_Commands.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package build_structure;

import ui.Global;
import ui.Init;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.logging.Logger;

public class Permission_Commands {
final static String macPerm = "chmod -R 777 " + System.getProperty("user.home") + File.separator + "BCL_CL";
final static String winPerm = "icacls " + Global.getPath() + "/grant Users:F";
/**
* Provides Permissions For Necessary Files Withing BCL_CL
*/
private static final Logger LOGGER = Logger.getLogger(Permission_Commands.class.getName());
final private static String macPerm = "chmod -R 777 " + System.getProperty("user.home") + File.separator + "BCL_CL";
final private static String winPerm = "icacls " + Global.getPath() + "/grant Users:F";

public static void permission() {
LOGGER.addHandler(Global.getLog_fh());
LOGGER.info("Changing Permissions of BCL_CL Folder");
try {
if (Global.getOS().contains("mac")) {
Process p = Runtime.getRuntime().exec(macPerm);
Expand All @@ -25,6 +34,7 @@ public static void permission() {
}
} catch (IOException e) {
e.printStackTrace();
LOGGER.warning("COULDN'T CHANGE THE BCL_CL Permissions\n\n"+ Arrays.toString(e.getStackTrace()));
System.exit(1);
} catch (InterruptedException e) {
e.printStackTrace();
Expand Down
Loading

0 comments on commit 2f1642f

Please sign in to comment.