diff --git a/pom.xml b/pom.xml
index 9356abf..5a220b3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
com.github.cshubhamrao
AUtDv2
Auto Upload to Drive v2
- An application to automatically backup your NetBeans Projects and MySQL screenshots to Google Drive.
+ An application to automatically backup your NetBeans Projects, MySQL screenshots, and MySQL databases to Google Drive.
Shubham Rao
@@ -20,6 +20,7 @@
1.8
1.8
com.github.cshubhamrao.AUtDv2.gui.MainUI
+ UTF-8
diff --git a/src/main/java/com/github/cshubhamrao/AUtDv2/gui/MainUI.java b/src/main/java/com/github/cshubhamrao/AUtDv2/gui/MainUI.java
index 772a0da..0251701 100644
--- a/src/main/java/com/github/cshubhamrao/AUtDv2/gui/MainUI.java
+++ b/src/main/java/com/github/cshubhamrao/AUtDv2/gui/MainUI.java
@@ -25,7 +25,6 @@
import com.github.cshubhamrao.AUtDv2.util.Log;
import java.io.IOException;
-
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
@@ -33,8 +32,11 @@
import javafx.stage.Stage;
/**
+ * Main GUI class for application. This class loads the {@code MainUI.fxml} file and displays the
+ * rendered GUI.
*
- * @author shubham
+ * @see UIController
+ * @author Shubham Rao
*/
public class MainUI extends Application {
diff --git a/src/main/java/com/github/cshubhamrao/AUtDv2/gui/UIController.java b/src/main/java/com/github/cshubhamrao/AUtDv2/gui/UIController.java
index 65269f6..3ea6d70 100644
--- a/src/main/java/com/github/cshubhamrao/AUtDv2/gui/UIController.java
+++ b/src/main/java/com/github/cshubhamrao/AUtDv2/gui/UIController.java
@@ -39,7 +39,7 @@
import javafx.scene.control.TextField;
/**
- * FXML Controller class
+ * FXML Controller class. for {@code MainUI.fxml}
*
* @author Shubham Rao
*/
diff --git a/src/main/java/com/github/cshubhamrao/AUtDv2/os/AppRunner.java b/src/main/java/com/github/cshubhamrao/AUtDv2/os/AppRunner.java
index 0fbfb1f..f4eb556 100644
--- a/src/main/java/com/github/cshubhamrao/AUtDv2/os/AppRunner.java
+++ b/src/main/java/com/github/cshubhamrao/AUtDv2/os/AppRunner.java
@@ -31,20 +31,44 @@
import java.util.logging.Level;
/**
+ * An interface to allow running programs from the OS. Implementations have to set the
+ * {@link CommandLine} for the application to be executed, by overriding the
+ * {@link AppRunner#setCommand()} and calling {@link AppRunner#setCommand(CommandLine)} inside the
+ * method.
*
- * @author Shubham Rao
+ * @see OSLib
+ * @author Shubham Rao (cshubhamrao@gmail.com)
*/
-abstract class AppRunner {
+public abstract class AppRunner {
private static final java.util.logging.Logger logger = Log.logger;
+ /**
+ * Sets the {@link CommandLine} to execute.
+ *
+ * This function must be called by implementations inside {@link AppRunner#setCommand()} when it
+ * is overridden.
+ *
+ * @param command command to execute
+ */
protected void setCommand(CommandLine command) {
this.command = command;
}
private CommandLine command;
+ /**
+ * Current Architecture
+ *
+ * @see OSLib#getCurrentArchitecture()
+ */
public final OSLib.Architecture arch;
+
+ /**
+ * Current Operating System
+ *
+ * @see OSLib#getCurrentOS()
+ */
public final OSLib.OperatingSystem os;
AppRunner() {
@@ -58,6 +82,10 @@ CommandLine getCommand() {
return command;
}
+ /**
+ * Runs the OS specific Command. Exit code is logged.
+ *
+ */
public void run() {
setCommand();
ProcessBuilder pb = new ProcessBuilder(command.getFullCommand());
@@ -67,18 +95,22 @@ public void run() {
new Thread(() -> {
try {
logger.log(Level.INFO, "Exit Code: {0} ", p.waitFor());
- }
- catch (InterruptedException ex) {
- logger.log(Level.SEVERE, null, ex);
+ } catch (InterruptedException ex) {
+ logger.log(Level.SEVERE, "Error getting exit code", ex);
}
}
).start();
- }
- catch (IOException ex) {
- logger.log(Level.SEVERE, null, ex);
+ } catch (IOException ex) {
+ logger.log(Level.SEVERE, "Error in running program.", ex);
}
}
+ /**
+ * Class representing a Command along with its arguments.
+ *
+ * Encapsulates an OS dependent Command, with executable's name and its arguments.
+ * @author Shubham Rao (cshubhamrao@gmail.com)
+ */
protected class CommandLine {
private String commandName;
@@ -99,38 +131,83 @@ protected class CommandLine {
this(command, "");
}
+ /**
+ * Gets the name of executable.
+ *
+ * @return name of executable
+ */
public String getCommandName() {
return commandName;
}
+ /**
+ * Sets the name of executable.
+ *
+ * @param commandName name of executable
+ */
public void setCommandName(String commandName) {
this.commandName = commandName;
updateFullCommand();
}
+ /**
+ * Gets the arguments
+ *
+ * @return arguments
+ */
public List getArguments() {
return arguments;
}
+ /**
+ * Adds arguments to the command.
+ *
+ * @param args arguments
+ */
public final void addArguments(String... args) {
arguments.addAll(Arrays.asList(args));
updateFullCommand();
}
+ /**
+ * Replaces arguments of the command.
+ *
+ * @param arguments list containing arguments
+ */
public void setArguments(ArrayList arguments) {
this.arguments = arguments;
updateFullCommand();
}
+ /**
+ * Returns the command name along with its arguments.
+ *
+ * First element is the command name, remaining elements are its arguments.
+ *
+ * @return command with arguments included.
+ */
public List getFullCommand() {
logger.log(Level.INFO, "Command: {0}", this.toString());
return fullCommand;
}
+ /**
+ * Sets the command name along with its arguments.
+ *
+ * First element must be the command name,
+ * remaining elements, its arguments.
+ *
+ * @param fullCommand command along with arguments
+ */
public void setFullCommand(ArrayList fullCommand) {
this.fullCommand = fullCommand;
}
+ /**
+ * Returns command and its arguments as a String.
+ *
+ * @return command and its arguments as String
+ */
@Override
public String toString() {
StringBuilder command = new StringBuilder(this.fullCommand.get(0));
diff --git a/src/main/java/com/github/cshubhamrao/AUtDv2/os/MySqlDumpRunner.java b/src/main/java/com/github/cshubhamrao/AUtDv2/os/MySqlDumpRunner.java
index 159a54d..e279d27 100644
--- a/src/main/java/com/github/cshubhamrao/AUtDv2/os/MySqlDumpRunner.java
+++ b/src/main/java/com/github/cshubhamrao/AUtDv2/os/MySqlDumpRunner.java
@@ -24,7 +24,6 @@
package com.github.cshubhamrao.AUtDv2.os;
import com.github.cshubhamrao.AUtDv2.util.Log;
-
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
@@ -38,14 +37,20 @@
import java.util.stream.Stream;
/**
+ * Runs mysqldump to create DB dumps. The dumps are stored as {@code dbName.sql} in the current
+ * directory. The database is assumed to exist.
*
- * @author Shubham Rao
+ * @author Shubham Rao (cshubhamrao@gmail.com)
*/
public class MySqlDumpRunner extends AppRunner {
private static final Logger logger = Log.logger;
private final String dbName;
+ /**
+ *
+ * @param dbName name of database to dump
+ */
public MySqlDumpRunner(String dbName) {
this.dbName = dbName;
}
diff --git a/src/main/java/com/github/cshubhamrao/AUtDv2/os/MySqlImportRunner.java b/src/main/java/com/github/cshubhamrao/AUtDv2/os/MySqlImportRunner.java
index 7f00607..f870e04 100644
--- a/src/main/java/com/github/cshubhamrao/AUtDv2/os/MySqlImportRunner.java
+++ b/src/main/java/com/github/cshubhamrao/AUtDv2/os/MySqlImportRunner.java
@@ -39,8 +39,9 @@
import java.util.stream.Stream;
/**
+ * Finds and runs mysql to restore DBs from backup
*
- * @author "Shubham Rao "
+ * @author Shubham Rao (cshubhamrao@gmail.com)
*/
public class MySqlImportRunner extends AppRunner {
@@ -48,6 +49,11 @@ public class MySqlImportRunner extends AppRunner {
private final String sqlFile;
private final String dbName;
+ /**
+ *
+ * @param sqlFile Path to .sql file containing DB Dump.
+ * @param dbName Name of database to create.
+ */
public MySqlImportRunner(String sqlFile, String dbName) {
this.sqlFile = sqlFile;
this.dbName = dbName;
@@ -61,7 +67,7 @@ void setCommand() {
String cmd = Paths.get(System.getenv("WINDIR"), "system32", "cmd.exe").toString();
command.setCommandName(cmd);
command.addArguments("/C");
- command.addArguments("start", "\"Creating MySQL Dump\"");
+ command.addArguments("start", "\"Importing from MySQL Dump\"");
command.addArguments("/D", windowsLocation());
command.addArguments("cmd /K", "mysql.exe");
command.addArguments("--user=root", "--password", "--verbose");
diff --git a/src/main/java/com/github/cshubhamrao/AUtDv2/os/MySqlRunner.java b/src/main/java/com/github/cshubhamrao/AUtDv2/os/MySqlRunner.java
index 0f598ab..26f2a50 100644
--- a/src/main/java/com/github/cshubhamrao/AUtDv2/os/MySqlRunner.java
+++ b/src/main/java/com/github/cshubhamrao/AUtDv2/os/MySqlRunner.java
@@ -36,8 +36,9 @@
import java.util.stream.Stream;
/**
+ * Finds and runs the mysql Command Line
*
- * @author "Shubham Rao "
+ * @author Shubham Rao (cshubhamrao@gmail.com)
*/
public class MySqlRunner extends AppRunner {
diff --git a/src/main/java/com/github/cshubhamrao/AUtDv2/os/NetBeansRunner.java b/src/main/java/com/github/cshubhamrao/AUtDv2/os/NetBeansRunner.java
index 98bd7f4..9e34574 100644
--- a/src/main/java/com/github/cshubhamrao/AUtDv2/os/NetBeansRunner.java
+++ b/src/main/java/com/github/cshubhamrao/AUtDv2/os/NetBeansRunner.java
@@ -34,17 +34,14 @@
import java.util.logging.Level;
/**
+ * Finds and runs NetBeans
*
- * @author Shubham Rao
+ * @author Shubham Rao (cshubhamrao@gmail.com)
*/
public class NetBeansRunner extends AppRunner {
private static final java.util.logging.Logger logger = Log.logger;
- public NetBeansRunner() {
- super();
- }
-
@Override
void setCommand() {
String location = "";
@@ -73,8 +70,7 @@ private String windowsLocation() {
nbLocs.add(pat);
logger.log(Level.INFO, "Added {0} to nbLocs", pat.toString());
});
- }
- catch (IOException ex) {
+ } catch (IOException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
diff --git a/src/main/java/com/github/cshubhamrao/AUtDv2/os/OSLib.java b/src/main/java/com/github/cshubhamrao/AUtDv2/os/OSLib.java
index c322eae..9ddbf76 100644
--- a/src/main/java/com/github/cshubhamrao/AUtDv2/os/OSLib.java
+++ b/src/main/java/com/github/cshubhamrao/AUtDv2/os/OSLib.java
@@ -31,26 +31,61 @@
import java.util.logging.Level;
/**
+ * Little utility class for OS specific tasks
*
- * @author Shubham Rao
+ * @author Shubham Rao (cshubhamrao@gmail.com)
*/
public class OSLib {
private static final java.util.logging.Logger logger = Log.logger;
+ /**
+ * Enumeration representing Operating Systems.
+ */
public enum OperatingSystem {
+
+ /**
+ * The Windows family of Operating System
+ */
WINDOWS,
+ /**
+ * Linux (only Linux)
+ */
LINUX,
+ /**
+ * Mac OS and Mac OS X
+ */
MAC,
+ /**
+ * Unknown OS
+ */
UNKNOWN
}
+ /**
+ * Enumeration representing Architecture.
+ */
public enum Architecture {
+
+ /**
+ * 32-bit architecture
+ */
i386,
+ /**
+ * 64-bit architecture
+ */
AMD64,
+ /**
+ * Unknown architecture
+ */
UNKNOWN
}
+ /**
+ * Gets the current OS where JVM is executing.
+ *
+ * @return current OS
+ */
public static OperatingSystem getCurrentOS() {
String os = System.getProperty("os.name");
if (os.startsWith("Linux")) return OperatingSystem.LINUX;
@@ -59,41 +94,54 @@ public static OperatingSystem getCurrentOS() {
else return OperatingSystem.UNKNOWN;
}
+ /**
+ * Gets the current Architecture where JVM is executing.
+ *
+ * @return current architecture
+ */
public static Architecture getCurrentArchitecture() {
String arch = System.getProperty("os.arch");
if (arch.startsWith("amd64")) return Architecture.AMD64;
/*
¯\_(ツ)_/¯
- STORY TIME: with a brave warrior tester [REDACTED], a troubled developer, a [baby-like]app
+ STORY TIME: with a brave warrior tester [REDACTED], a troubled developer, a [baby-like]app
and a [sluggish]PC
- Once upon a time (24/08/2016, 22:54 + ~00:20:00), a troubled developer (no points for
+ Once upon a time (24/08/2016, 22:54 + ~00:20:00), a troubled developer (no points for
guessing who) was in conversation about the pre-alpha build of his app. As with everything,
- things did not work(tm). Our brave warrior, [REDACTED] battled through strange errors (with
+ things did not work(tm). Our brave warrior, [REDACTED] battled through strange errors (with
no error info) about JVM creation; then updating JRE version; then inconsistent behaviour of
- GUI vs CMD... all on the (mobile)phone. Finally the GUI window opens, our warrior tester,
- [REDACTED] clicks "Run NetBeans", lo and behold, *nothing* happens. [REDACTED] tries again,
+ GUI vs CMD... all on the (mobile)phone. Finally the GUI window opens, our warrior tester,
+ [REDACTED] clicks "Run NetBeans", lo and behold, *nothing* happens. [REDACTED] tries again,
and the app... does nothing. "What went wrong?" That is the answer to the question.
"Check the Logs"... The logs are searched, the logs are scoured and our warrior finds...
*NOTHING*, literally. The logs have no mention of anything, let alone mention of *something*
going wrong.
- So what went wrong?
+ So what went wrong?
Our warrior tester used 32-bit Windows, a platform our baby app is not accustomed to.
- Guardian Java does little to intim[id]ate the app. Wrong architecture detection, thanks to
- Java and app thinks the architecture is UNKNOWN. Java please be consistent. Return my 12
+ Guardian Java does little to intim[id]ate the app. Wrong architecture detection, thanks to
+ Java and app thinks the architecture is UNKNOWN. Java please be consistent. Return my 12
hours...
*/
-
- // JAVA, Y U MAKE ME DO DIS? ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
+
+ // JAVA, Y U MAKE ME DO DIS? ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
else if (arch.startsWith("i386") || arch.contains("86")) return Architecture.i386;
return Architecture.UNKNOWN;
}
+ /**
+ * Returns directories where installed programs *can* be found.
+ *
+ * Current support is only for Windows, where it returns the "Program Files" directory.
+ *
+ * @return List of paths where programs can be installed.
+ */
protected static List getProgramDirs() {
ArrayList dirs = new ArrayList(2);
if (getCurrentOS() == OperatingSystem.WINDOWS) {
switch (getCurrentArchitecture()) {
case i386:
dirs.add(Paths.get(System.getenv("PROGRAMFILES")));
+ break;
case AMD64:
dirs.add(Paths.get(System.getenv("PROGRAMFILES")));
dirs.add(Paths.get(System.getenv("PROGRAMFILES(x86)")));
diff --git a/src/main/java/com/github/cshubhamrao/AUtDv2/util/Log.java b/src/main/java/com/github/cshubhamrao/AUtDv2/util/Log.java
index 47f1ed8..ef6cdcd 100644
--- a/src/main/java/com/github/cshubhamrao/AUtDv2/util/Log.java
+++ b/src/main/java/com/github/cshubhamrao/AUtDv2/util/Log.java
@@ -24,15 +24,14 @@
package com.github.cshubhamrao.AUtDv2.util;
import java.io.IOException;
-
-import java.util.logging.Logger;
import java.util.logging.FileHandler;
import java.util.logging.Level;
+import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
/**
*
- * @author "Shubham Rao "
+ * @author Shubham Rao (cshubhamrao@gmail.com)
*/
public class Log {