diff --git a/build/changelog/jterm-changelog-v0.3.0.txt b/build/changelog/jterm-changelog-v0.3.0.txt new file mode 100644 index 0000000..41d7ab0 --- /dev/null +++ b/build/changelog/jterm-changelog-v0.3.0.txt @@ -0,0 +1,26 @@ +Changelog entry: + +[6/4/2017-20:08 0.3.0 Sergix] + Release 0.3.0 has been pushed with the associated documentation and other data. + Documentation now includes a section covering commands that JTerm provides. + The Client/Server classes are included in the packaged source, although they are not actually used in the release executable; see associated release documentation for more details. + Pushed updates to Git. + +Full changes include: + - Created "Client" class + - Added "connect" command; called with `Client.Connect()` function + - NOT FUNCTIONING in this release; source is included + - Created "Server" class + - Added "server" command; called with `Server.Start()` function + - NOT FUNCTIONING in this release; source is included + - Created "Window" class + - Added "window" command; called with `new Window()` function + - Added the "md" command (Make Directory) that calls the new `Dir.NewDir()` function + - Added the "del" command (DELete) that calls the new `Files.Delete()` function + - In-development source code is now pushed to the `dev` branch on the repository, which will be merged with `master` on release + - Inputed commands convert to all lowercase + - `Write` class has been removed; member function moved to `Files` class + - The current directory will always end with a single "forward slash" (e.g. `/usr/home/`) + - Other minor fixes + +More information provided in published release documentation. \ No newline at end of file diff --git a/build/jar/jterm-v0.3.0.jar b/build/jar/jterm-v0.3.0.jar new file mode 100644 index 0000000..89a9883 Binary files /dev/null and b/build/jar/jterm-v0.3.0.jar differ diff --git a/build/src/jterm-src-v0.3.0.zip b/build/src/jterm-src-v0.3.0.zip new file mode 100644 index 0000000..7eb4dab Binary files /dev/null and b/build/src/jterm-src-v0.3.0.zip differ diff --git a/changelog.txt b/changelog.txt index 121f5ba..130b728 100644 --- a/changelog.txt +++ b/changelog.txt @@ -21,7 +21,6 @@ - Added command option parsing for WriteFile - Made inputed commands (not options) default to lowercase - Files.Delete deletes both files AND directories - - Created "dev" branch that will be used for development. Fixed incorrect date in last changelog entry. diff --git a/docs/release/jterm-v0.3.0-docs.md b/docs/release/jterm-v0.3.0-docs.md new file mode 100644 index 0000000..fed094f --- /dev/null +++ b/docs/release/jterm-v0.3.0-docs.md @@ -0,0 +1,81 @@ +# JTerm Documentation v0.3.0 + +## Table of Contents +``` +I. Table of Contents +II. Overview +III. Build Targets +IV. Changelog +V. New Features + A. Commands + B. Client/Server +VI. Active Command List +``` + +## Overview +This document provides information on changes included in release version "0.3.0". The JTerm project is still far from its official release, but the project has had enough changes to include it as a new pre-release version. This document was written by @Sergix and reviewed by @NCSGeek. + +## Build Targets +``` +[VERSION] [FILE] [STATE] +0.1.0 jterm-v0.1.0.jar OK +0.2.0 jterm-v0.2.0.jar OK +0.2.1 jterm-v0.2.1.jar OK +0.3.0 jterm-v0.3.0.jar OK +``` + +## Changelog +- Created "Client" class + - Added "connect" command; called with `Client.Connect()` function + - NOT FUNCTIONING in this release; source is included +- Created "Server" class + - Added "server" command; called with `Server.Start()` function + - NOT FUNCTIONING in this release; source is included +- Created "Window" class + - Added "window" command; called with `new Window()` function +- Added the "md" command (Make Directory) that calls the new `Dir.NewDir()` function +- Added the "del" command (DELete) that calls the new `Files.Delete()` function +- In-development source code is now pushed to the `dev` branch on the repository, which will be merged with `master` on release +- Inputed commands convert to all lowercase +- `Write` class has been removed; member function moved to `Files` class +- The current directory will always end with a single "forward slash" (e.g. `/usr/home/`) +- Other minor fixes + +## New Features + +### Commands +The commands `connect`, `server`, `md`, `del`, and `window` have been added to JTerm. The syntax for these commands are as follows: +``` +connect [-h] [-p port] address +server [-h] port +md [-h] name +del [-h] file/directory +window [-h] [-r] [-w width] [-l height] [-t title] +``` +`connect` AND `server` ARE NOT FUNCTIONABLE IN THIS RELEASE. +`-h` ALWAYS displays the command's help information in the console. `-r`, used for the `window` command, toggles resizability for the created window. + +### Client/Server +As mentioned before, a new Client/Server interface has been written for JTerm. However, this functionality has too many issues to be released yet. The source code and classes are packaged into the source build, as well as the JAR, but it is not able to be run. Any presented fixes to the issues are welcome. + +## Active Command List +- `help` - displays information about JTerm +- `quit` - Exits the JTerm application +- `write [-h] filename` - Opens an input prompt that will write the data to the new file named `filename` +- `dir [-f] [-h] [directory]` - Dispays extensive directory information, including files and subdirectories + - `-f` - toggles minimal output +- `cd [-h] directory` - Changes the directory to the location specified +- `pwd` - prints the current working directory +- `echo [-h] input` - outputs the input on a new line +- `del [-h] file/directory` - deletes the specified file or directory +- `md [-h] name` - creates a new directory +- `window [-h] [-r] [-w width] [-l height] [-t title]` - creates a new GUI window + - `-r` - toggles resizability + - `-w` - specifies window width + - `-l` - specifies window height + - `-t` - sets the name of the window, displayed in the title bar + +> JTerm 0.3.0 +> `jterm-v0.3.0.jar` +> This project and its source are held under the GNU General Public License, located in the LICENSE file in the project's directory. +> (c) 2017 diff --git a/src/main/java/com/jterm/Client.java b/src/main/java/com/jterm/Client.java new file mode 100644 index 0000000..d64eca3 --- /dev/null +++ b/src/main/java/com/jterm/Client.java @@ -0,0 +1,110 @@ +package main.java.com.jterm; + +import java.io.*; +import java.net.Socket; +import java.util.ArrayList; + +public class Client implements Runnable { + + private static BufferedReader input; + + public void run() { + + while (true) { + try { + String output = Client.input.readLine(); + if (output != null) + System.out.println(output); + + } catch (IOException ioe) { + return; + + } + + } + + } + + public static void Connect(ArrayList options) { + + String address = "0.0.0.0"; + String portInput = "80"; + boolean next = false; + + for (String option: options) { + if (option.equals("-h")) + { + System.out.println("Command syntax:\n\tconnect [-h] [-p port] address\n\nConnect to the specified IP address using TCP/IP. Default address is \"0.0.0.0\". Default port is 80."); + return; + + } + else if (option.equals("-p")) + { + next = true; + + } + else if (next) + { + portInput = option; + next = false; + + } + else + { + address = option; + + } + + } + + int i = 0; + int port = 0; + + while( i < portInput.length()) + { + port *= 10; + port += portInput.charAt(i++) - '0'; + + } + + try { + System.out.println("Connecting to " + address + ":" + port); + + Socket connection = new Socket(address, port); + InputStream input = connection.getInputStream(); + OutputStream output = connection.getOutputStream(); + BufferedReader bufferedSocketInput = new BufferedReader(new InputStreamReader(input)); + + Client.input = bufferedSocketInput; + + Client client = new Client(); + Thread readThread = new Thread(client); + readThread.start(); + + System.out.println("Connected to server. Enter a blank line to quit. Reading for input..."); + + while (true) { + BufferedReader bufferedSocketOutput = new BufferedReader(new InputStreamReader(System.in), 1); + String line = bufferedSocketOutput.readLine(); + + if (line.equals("")) + break; + output.write(line.getBytes()); + + output.close(); + bufferedSocketOutput.close(); + + } + + connection.close(); + + } + catch (IOException ioe) + { + System.out.println("Connection severed."); + + } + + } + +} diff --git a/src/main/java/com/jterm/Dir.java b/src/main/java/com/jterm/Dir.java index 7e291fa..da06272 100644 --- a/src/main/java/com/jterm/Dir.java +++ b/src/main/java/com/jterm/Dir.java @@ -126,12 +126,25 @@ public static void ChangeDir(ArrayList options) { // Test if the input exists and if it is a directory File dir = new File(newDirectory); - if (!dir.exists() || !dir.isDirectory()) { + File newDir = new File(JTerm.currentDirectory + newDirectory); + + if (newDir.exists() && newDir.isDirectory()) { + newDirectory = JTerm.currentDirectory + newDirectory; + + } + else if ((!dir.exists() || !dir.isDirectory()) && (!newDir.exists() || !newDir.isDirectory())) + { System.out.println("ERROR: Directory \"" + newDirectory + "\" is either does not exist or is not a valid directory."); return; } + if (!newDirectory.endsWith("/")) + { + newDirectory += "/"; + + } + // It does exist, and it is a directory, so just change the global working directory variable to the input JTerm.currentDirectory = newDirectory; @@ -163,4 +176,36 @@ public static void PrintWorkingDir(ArrayList options) { System.out.println(JTerm.currentDirectory); } + + /* + * NewDir() void + * + * Creates a new directory. + * + * -h + * Prints help information + * + * ArrayList options - command options + */ + public static void NewDir(ArrayList options) { + + String name = ""; + + for (String option: options) { + if (option.equals("-h")) + { + System.out.println("Command syntax:\n\tmd [-h] name\n\nCreates a new directory."); + return; + + } + else + { + name = JTerm.currentDirectory + option; + } + } + + File dir = new File(name); + dir.mkdir(); + } + } diff --git a/src/main/java/com/jterm/Files.java b/src/main/java/com/jterm/Files.java new file mode 100644 index 0000000..4afc96f --- /dev/null +++ b/src/main/java/com/jterm/Files.java @@ -0,0 +1,101 @@ +package main.java.com.jterm; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; + +public class Files { + + /* + * WriteFile() void + * + * Get input and write it to a file. + * + * ArrayList options - command options + * + * -h + * Prints help information + */ + public static void WriteFile(ArrayList options) { + + String filename = ""; + + for (String option: options) + { + if (option.equals("-h")) + { + System.out.println("Command syntax:\n\twrite [-h] filename\n\nOpens an input prompt in which to write text to a new file."); + return; + + } + else + { + filename = JTerm.currentDirectory + option; + + } + + } + + try { + System.out.println("Enter file contents:\n"); + BufferedReader inputStream = new BufferedReader(new InputStreamReader(System.in), 1); + String output = inputStream.readLine(); + + FileWriter fileWriter = new FileWriter(filename); + fileWriter.write(output); + fileWriter.close(); + + } + catch (IOException ioe) + { + System.out.println(ioe); + + } + + } + + /* + * Delete() void + * + * Delete the specified file or directory. + * + * ArrayList options - command options + * + * -h + * Prints help information + */ + public static void Delete(ArrayList options) { + + String filename = ""; + + for (String option: options) + { + if (option.equals("-h")) + { + System.out.println("Command syntax:\n\tdel [-h] file/directory\n\nDeletes the specified file or directory."); + return; + + } + else + { + filename = JTerm.currentDirectory + option; + + } + + } + + File dir = new File(filename); + if (!dir.exists()) { + System.out.println("ERROR: File/directory \"" + options.get(options.size() - 1) + "\" does not exist."); + return; + + } + + dir.delete(); + + } + +} diff --git a/src/main/java/com/jterm/JTerm.java b/src/main/java/com/jterm/JTerm.java index 687a595..e4bb5f6 100644 --- a/src/main/java/com/jterm/JTerm.java +++ b/src/main/java/com/jterm/JTerm.java @@ -3,17 +3,16 @@ import java.util.Scanner; import java.io.*; -import main.java.com.jterm.Write; import java.util.ArrayList; public class JTerm { // Global version variable - static String version = "0.1.0"; + static String version = "0.3.0"; // Global directory variable (use "cd" command to change) - // Default value "." is equal to the default directory set when the program starts - static String currentDirectory = "."; + // Default value "./" is equal to the default directory set when the program starts + static String currentDirectory = "./"; /* * main() void @@ -87,7 +86,7 @@ public static boolean Standby(BufferedReader user_input) { } // Switch through command names - switch (input) { + switch (input.toLowerCase()) { case "help": // Prints "JTerm v1.0" for example System.out.println("JTerm v" + version); @@ -100,7 +99,7 @@ public static boolean Standby(BufferedReader user_input) { case "write": // Get the last option, which is the filename, and send it the option list - Write.WriteFile(options); + Files.WriteFile(options); break; case "dir": @@ -115,10 +114,33 @@ public static boolean Standby(BufferedReader user_input) { Dir.PrintWorkingDir(options); break; - case "echo": Echo.EchoInput(options); break; + + case "delete": + case "del": + Files.Delete(options); + break; + + case "md": + Dir.NewDir(options); + break; + + case "read": + break; + + /*case "connect": + Client.Connect(options); + break; + + case "server": + Server.Start(options); + break;*/ + + case "window": + new Window(options); + break; default: // Fall back when unknown command is entered diff --git a/src/main/java/com/jterm/Server.java b/src/main/java/com/jterm/Server.java new file mode 100644 index 0000000..6b96708 --- /dev/null +++ b/src/main/java/com/jterm/Server.java @@ -0,0 +1,132 @@ +package main.java.com.jterm; + +import java.io.*; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.ArrayList; + +public class Server implements Runnable { + + private Socket socket; + public static boolean run = true; + public static int port = 0; + private static String line; + + Server(Socket newSocket) { + socket = newSocket; + + } + + public void run() { + + while (run) { + try { + InputStream input = socket.getInputStream(); + BufferedReader bufferedSocketInput = new BufferedReader(new InputStreamReader(input)); + + line = bufferedSocketInput.readLine(); + if (line.isEmpty()) { + break; + + } + System.out.println("\n" + line); + + bufferedSocketInput.close(); + + } + catch (IOException ioe) + { + System.out.println(ioe); + break; + + } + + } + + return; + + } + + public static void Start(ArrayList options) { + + String portInput = "80"; + + for (String option: options) + { + if(option.equals("-h")) + { + System.out.println("Command syntax:\n\tserver [-h] port\n\nStarts a TCP server socket that accepts "); + return; + + } + else + { + portInput = option; + + } + } + + int i = 0; + + while( i < portInput.length()) + { + port *= 10; + port += portInput.charAt(i++) - '0'; + + } + + try { + ServerSocket server = new ServerSocket(port); + + new Thread(new Runnable() { + + public void run() { + + while (true) + { + System.out.print("> "); + BufferedReader consoleInput = new BufferedReader(new InputStreamReader(System.in), 1); + try { + String input = consoleInput.readLine(); + switch (input) { + case "help": + System.out.println("Server currently opened on port " + port); + break; + + case "quit": + run = false; + return; + + } + + } catch (IOException ioe) { + System.out.println("Input Stream closed."); + break; + + } + + } + + } + + }).start(); + + while (run) { + Socket socket = server.accept(); + Server newRequest = new Server(socket); + new Thread(newRequest).start(); + + } + + server.close(); + + } + catch (IOException ioe) + { + System.out.println("ERROR: Server closed"); + + } + + } + +} diff --git a/src/main/java/com/jterm/Window.java b/src/main/java/com/jterm/Window.java new file mode 100644 index 0000000..a35a0dd --- /dev/null +++ b/src/main/java/com/jterm/Window.java @@ -0,0 +1,130 @@ +package main.java.com.jterm; + +import java.util.ArrayList; +import javax.swing.JFrame; + +public class Window { + + public static int windowCount = 0; + + private int id; + private JFrame window; + + /* + * Window() void + * + * Create a new JFrame window. + * + * ArrayList options - command options + * + * -h + * Prints help information + * + * -t title + * Sets the window title in + * the header + * + * -w width + * Sets the width of the window + * + * -l height + * Sets the height of the window + * + * -r + * Sets the window to be able to + * be resized + * + */ + Window(ArrayList options) { + + String title = ""; + int width = 500, height = 500; + boolean resizable = false; + + boolean titleNext = false, heightNext = false, widthNext = false; + + for (String option: options) + { + if (option.equals("-h")) + { + System.out.println("Command syntax:\t\nwindow [-h] [-r] [-w width] [-l height] [-t title]\n\nCreates a new programmable GUI window.\nDefault title is \"JTerm Window\", and the default width and height of the window is 500 x 500."); + return; + + } + else if(option.equals("-t")) + { + titleNext = true; + + } + else if(option.equals("-w")) + { + widthNext = true; + + } + else if(option.equals("-l")) + { + heightNext = true; + + } + else if(widthNext) + { + width = Integer.parseInt(option); + widthNext = false; + + } + + else if(heightNext) + { + height = Integer.parseInt(option); + heightNext = false; + + } + else if (option.equals("-r")) + { + resizable = true; + + } + else if(titleNext) + { + title += option + " "; + + } + + } + + windowCount += 1; + id = windowCount; + + JFrame window = new JFrame(title); + window.setSize(width, height); + window.setVisible(true); + window.setResizable(resizable); + + this.window = window; + + } + + /* + * GetId() int + * + * Returns the process ID of the window + */ + public int GetId() { + + return id; + + } + + /* + * GetId() JFrame + * + * Returns the JFrame object displaying + * the window + */ + public JFrame GetFrame() { + + return this.window; + + } + +} diff --git a/src/main/java/com/jterm/Write.java b/src/main/java/com/jterm/Write.java deleted file mode 100644 index d82c6f9..0000000 --- a/src/main/java/com/jterm/Write.java +++ /dev/null @@ -1,35 +0,0 @@ -package main.java.com.jterm; - -import java.io.*; -import java.util.ArrayList; - -public class Write { - - /* - * WriteFile() void - * - * Get input and write it to a file. - * - * ArrayList options - command options - */ - public static void WriteFile(ArrayList options) { - - try { - System.out.println("Enter file contents:\n"); - BufferedReader inputStream = new BufferedReader(new InputStreamReader(System.in), 1); - String output = inputStream.readLine(); - - FileWriter fileWriter = new FileWriter(options.get( options.size() ) ); - fileWriter.write(output); - fileWriter.close(); - - } - catch (IOException ioe) - { - System.out.println(ioe); - - } - - } - -}