Skip to content

Commit aa2d985

Browse files
committed
Prepare for release!
- 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
1 parent 7a40a93 commit aa2d985

File tree

10 files changed

+173
-38
lines changed

10 files changed

+173
-38
lines changed

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<groupId>com.github.cshubhamrao</groupId>
1010
<artifactId>AUtDv2</artifactId>
1111
<name>Auto Upload to Drive v2</name>
12-
<description>An application to automatically backup your NetBeans Projects and MySQL screenshots to Google Drive.</description>
12+
<description>An application to automatically backup your NetBeans Projects, MySQL screenshots, and MySQL databases to Google Drive.</description>
1313
<organization>
1414
<name>Shubham Rao</name>
1515
</organization>
@@ -20,6 +20,7 @@
2020
<maven.compiler.source>1.8</maven.compiler.source>
2121
<maven.compiler.target>1.8</maven.compiler.target>
2222
<mainClass>com.github.cshubhamrao.AUtDv2.gui.MainUI</mainClass>
23+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2324
</properties>
2425

2526
<build>

src/main/java/com/github/cshubhamrao/AUtDv2/gui/MainUI.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,18 @@
2525

2626
import com.github.cshubhamrao.AUtDv2.util.Log;
2727
import java.io.IOException;
28-
2928
import javafx.application.Application;
3029
import javafx.fxml.FXMLLoader;
3130
import javafx.scene.Parent;
3231
import javafx.scene.Scene;
3332
import javafx.stage.Stage;
3433

3534
/**
35+
* Main GUI class for application. This class loads the {@code MainUI.fxml} file and displays the
36+
* rendered GUI.
3637
*
37-
* @author shubham
38+
* @see UIController
39+
* @author Shubham Rao
3840
*/
3941
public class MainUI extends Application {
4042

src/main/java/com/github/cshubhamrao/AUtDv2/gui/UIController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import javafx.scene.control.TextField;
4040

4141
/**
42-
* FXML Controller class
42+
* FXML Controller class. for {@code MainUI.fxml}
4343
*
4444
* @author Shubham Rao
4545
*/

src/main/java/com/github/cshubhamrao/AUtDv2/os/AppRunner.java

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,44 @@
3131
import java.util.logging.Level;
3232

3333
/**
34+
* An interface to allow running programs from the OS. Implementations have to set the
35+
* {@link CommandLine} for the application to be executed, by overriding the
36+
* {@link AppRunner#setCommand()} and calling {@link AppRunner#setCommand(CommandLine)} inside the
37+
* method.
3438
*
35-
* @author Shubham Rao <cshubhamrao@gmail.com>
39+
* @see OSLib
40+
* @author Shubham Rao (cshubhamrao@gmail.com)
3641
*/
37-
abstract class AppRunner {
42+
public abstract class AppRunner {
3843

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

46+
/**
47+
* Sets the {@link CommandLine} to execute.
48+
*
49+
* This function must be called by implementations inside {@link AppRunner#setCommand()} when it
50+
* is overridden.
51+
*
52+
* @param command command to execute
53+
*/
4154
protected void setCommand(CommandLine command) {
4255
this.command = command;
4356
}
4457

4558
private CommandLine command;
4659

60+
/**
61+
* Current Architecture
62+
*
63+
* @see OSLib#getCurrentArchitecture()
64+
*/
4765
public final OSLib.Architecture arch;
66+
67+
/**
68+
* Current Operating System
69+
*
70+
* @see OSLib#getCurrentOS()
71+
*/
4872
public final OSLib.OperatingSystem os;
4973

5074
AppRunner() {
@@ -58,6 +82,10 @@ CommandLine getCommand() {
5882
return command;
5983
}
6084

85+
/**
86+
* Runs the OS specific Command. Exit code is logged.
87+
*
88+
*/
6189
public void run() {
6290
setCommand();
6391
ProcessBuilder pb = new ProcessBuilder(command.getFullCommand());
@@ -67,18 +95,22 @@ public void run() {
6795
new Thread(() -> {
6896
try {
6997
logger.log(Level.INFO, "Exit Code: {0} ", p.waitFor());
70-
}
71-
catch (InterruptedException ex) {
72-
logger.log(Level.SEVERE, null, ex);
98+
} catch (InterruptedException ex) {
99+
logger.log(Level.SEVERE, "Error getting exit code", ex);
73100
}
74101
}
75102
).start();
76-
}
77-
catch (IOException ex) {
78-
logger.log(Level.SEVERE, null, ex);
103+
} catch (IOException ex) {
104+
logger.log(Level.SEVERE, "Error in running program.", ex);
79105
}
80106
}
81107

108+
/**
109+
* Class representing a Command along with its arguments.
110+
*
111+
* Encapsulates an OS dependent Command, with executable's name and its arguments.
112+
* @author Shubham Rao (cshubhamrao@gmail.com)
113+
*/
82114
protected class CommandLine {
83115

84116
private String commandName;
@@ -99,38 +131,83 @@ protected class CommandLine {
99131
this(command, "");
100132
}
101133

134+
/**
135+
* Gets the name of executable.
136+
*
137+
* @return name of executable
138+
*/
102139
public String getCommandName() {
103140
return commandName;
104141
}
105142

143+
/**
144+
* Sets the name of executable.
145+
*
146+
* @param commandName name of executable
147+
*/
106148
public void setCommandName(String commandName) {
107149
this.commandName = commandName;
108150
updateFullCommand();
109151
}
110152

153+
/**
154+
* Gets the arguments
155+
*
156+
* @return arguments
157+
*/
111158
public List<String> getArguments() {
112159
return arguments;
113160
}
114161

162+
/**
163+
* Adds arguments to the command.
164+
*
165+
* @param args arguments
166+
*/
115167
public final void addArguments(String... args) {
116168
arguments.addAll(Arrays.asList(args));
117169
updateFullCommand();
118170
}
119171

172+
/**
173+
* Replaces arguments of the command.
174+
*
175+
* @param arguments list containing arguments
176+
*/
120177
public void setArguments(ArrayList<String> arguments) {
121178
this.arguments = arguments;
122179
updateFullCommand();
123180
}
124181

182+
/**
183+
* Returns the command name along with its arguments.
184+
*
185+
* First element is the command name, remaining elements are its arguments.
186+
*
187+
* @return command with arguments included.
188+
*/
125189
public List<String> getFullCommand() {
126190
logger.log(Level.INFO, "Command: {0}", this.toString());
127191
return fullCommand;
128192
}
129193

194+
/**
195+
* Sets the command name along with its arguments.
196+
*
197+
* First element must be the command name,
198+
* remaining elements, its arguments.
199+
*
200+
* @param fullCommand command along with arguments
201+
*/
130202
public void setFullCommand(ArrayList<String> fullCommand) {
131203
this.fullCommand = fullCommand;
132204
}
133205

206+
/**
207+
* Returns command and its arguments as a String.
208+
*
209+
* @return command and its arguments as String
210+
*/
134211
@Override
135212
public String toString() {
136213
StringBuilder command = new StringBuilder(this.fullCommand.get(0));

src/main/java/com/github/cshubhamrao/AUtDv2/os/MySqlDumpRunner.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
package com.github.cshubhamrao.AUtDv2.os;
2525

2626
import com.github.cshubhamrao.AUtDv2.util.Log;
27-
2827
import java.io.IOException;
2928
import java.io.UncheckedIOException;
3029
import java.nio.file.Files;
@@ -38,14 +37,20 @@
3837
import java.util.stream.Stream;
3938

4039
/**
40+
* Runs mysqldump to create DB dumps. The dumps are stored as {@code dbName.sql} in the current
41+
* directory. The database is assumed to exist.
4142
*
42-
* @author Shubham Rao
43+
* @author Shubham Rao (cshubhamrao@gmail.com)
4344
*/
4445
public class MySqlDumpRunner extends AppRunner {
4546

4647
private static final Logger logger = Log.logger;
4748
private final String dbName;
4849

50+
/**
51+
*
52+
* @param dbName name of database to dump
53+
*/
4954
public MySqlDumpRunner(String dbName) {
5055
this.dbName = dbName;
5156
}

src/main/java/com/github/cshubhamrao/AUtDv2/os/MySqlImportRunner.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,21 @@
3939
import java.util.stream.Stream;
4040

4141
/**
42+
* Finds and runs mysql to restore DBs from backup
4243
*
43-
* @author "Shubham Rao <cshubhamrao@gmail.com>"
44+
* @author Shubham Rao (cshubhamrao@gmail.com)
4445
*/
4546
public class MySqlImportRunner extends AppRunner {
4647

4748
private static final Logger logger = Log.logger;
4849
private final String sqlFile;
4950
private final String dbName;
5051

52+
/**
53+
*
54+
* @param sqlFile Path to .sql file containing DB Dump.
55+
* @param dbName Name of database to create.
56+
*/
5157
public MySqlImportRunner(String sqlFile, String dbName) {
5258
this.sqlFile = sqlFile;
5359
this.dbName = dbName;
@@ -61,7 +67,7 @@ void setCommand() {
6167
String cmd = Paths.get(System.getenv("WINDIR"), "system32", "cmd.exe").toString();
6268
command.setCommandName(cmd);
6369
command.addArguments("/C");
64-
command.addArguments("start", "\"Creating MySQL Dump\"");
70+
command.addArguments("start", "\"Importing from MySQL Dump\"");
6571
command.addArguments("/D", windowsLocation());
6672
command.addArguments("cmd /K", "mysql.exe");
6773
command.addArguments("--user=root", "--password", "--verbose");

src/main/java/com/github/cshubhamrao/AUtDv2/os/MySqlRunner.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
import java.util.stream.Stream;
3737

3838
/**
39+
* Finds and runs the mysql Command Line
3940
*
40-
* @author "Shubham Rao <cshubhamrao@gmail.com>"
41+
* @author Shubham Rao (cshubhamrao@gmail.com)
4142
*/
4243
public class MySqlRunner extends AppRunner {
4344

src/main/java/com/github/cshubhamrao/AUtDv2/os/NetBeansRunner.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,14 @@
3434
import java.util.logging.Level;
3535

3636
/**
37+
* Finds and runs NetBeans
3738
*
38-
* @author Shubham Rao <cshubhamrao@gmail.com>
39+
* @author Shubham Rao (cshubhamrao@gmail.com)
3940
*/
4041
public class NetBeansRunner extends AppRunner {
4142

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

44-
public NetBeansRunner() {
45-
super();
46-
}
47-
4845
@Override
4946
void setCommand() {
5047
String location = "";
@@ -73,8 +70,7 @@ private String windowsLocation() {
7370
nbLocs.add(pat);
7471
logger.log(Level.INFO, "Added {0} to nbLocs", pat.toString());
7572
});
76-
}
77-
catch (IOException ex) {
73+
} catch (IOException ex) {
7874
logger.log(Level.SEVERE, null, ex);
7975
}
8076
}

0 commit comments

Comments
 (0)