Skip to content

Commit

Permalink
Prepare for release!
Browse files Browse the repository at this point in the history
- Includes little fixes and changes that don't warrant separate commits.
- Javadoc is added for all classes and fixed where present
- Reformat all files and save them w/ UTF8 encoding
  • Loading branch information
cshubhamrao committed Aug 25, 2016
1 parent 7a40a93 commit aa2d985
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 38 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<groupId>com.github.cshubhamrao</groupId>
<artifactId>AUtDv2</artifactId>
<name>Auto Upload to Drive v2</name>
<description>An application to automatically backup your NetBeans Projects and MySQL screenshots to Google Drive.</description>
<description>An application to automatically backup your NetBeans Projects, MySQL screenshots, and MySQL databases to Google Drive.</description>
<organization>
<name>Shubham Rao</name>
</organization>
Expand All @@ -20,6 +20,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<mainClass>com.github.cshubhamrao.AUtDv2.gui.MainUI</mainClass>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/github/cshubhamrao/AUtDv2/gui/MainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@

import com.github.cshubhamrao.AUtDv2.util.Log;
import java.io.IOException;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import javafx.scene.control.TextField;

/**
* FXML Controller class
* FXML Controller class. for {@code MainUI.fxml}
*
* @author Shubham Rao
*/
Expand Down
93 changes: 85 additions & 8 deletions src/main/java/com/github/cshubhamrao/AUtDv2/os/AppRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @see OSLib
* @author Shubham Rao ([email protected])
*/
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() {
Expand All @@ -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());
Expand All @@ -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 ([email protected])
*/
protected class CommandLine {

private String commandName;
Expand All @@ -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<String> 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<String> 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<String> 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<String> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ([email protected])
*/
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,21 @@
import java.util.stream.Stream;

/**
* Finds and runs mysql to restore DBs from backup
*
* @author "Shubham Rao <[email protected]>"
* @author Shubham Rao ([email protected])
*/
public class MySqlImportRunner extends AppRunner {

private static final Logger logger = Log.logger;
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;
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
import java.util.stream.Stream;

/**
* Finds and runs the mysql Command Line
*
* @author "Shubham Rao <[email protected]>"
* @author Shubham Rao ([email protected])
*/
public class MySqlRunner extends AppRunner {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@
import java.util.logging.Level;

/**
* Finds and runs NetBeans
*
* @author Shubham Rao <[email protected]>
* @author Shubham Rao ([email protected])
*/
public class NetBeansRunner extends AppRunner {

private static final java.util.logging.Logger logger = Log.logger;

public NetBeansRunner() {
super();
}

@Override
void setCommand() {
String location = "";
Expand Down Expand Up @@ -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);
}
}
Expand Down
Loading

0 comments on commit aa2d985

Please sign in to comment.