├── Mock Linux Shell in Java ├── bin │ ├── commands │ │ ├── Cat.class │ │ ├── Cd.class │ │ ├── CommandInterface.class │ │ ├── Cp.class │ │ ├── Echo.class │ │ ├── Exit.class │ │ ├── Get.class │ │ ├── Grep.class │ │ ├── History.class │ │ ├── Ls.class │ │ ├── Man.class │ │ ├── Mkdir.class │ │ ├── Mv.class │ │ ├── Number.class │ │ ├── Popd.class │ │ ├── Pushd.class │ │ └── Pwd.class │ ├── driver │ │ └── JShell.class │ ├── exceptions │ │ ├── FileDirectoryExistsException.class │ │ └── InvalidSyntaxException.class │ ├── helpers │ │ ├── Directory.class │ │ ├── File.class │ │ ├── FileExists.class │ │ ├── FormatMe.class │ │ ├── InputParser.class │ │ ├── PathWalker.class │ │ ├── Pathchecker.class │ │ ├── Reflection.class │ │ ├── SplitPaths.class │ │ ├── StdOutput.class │ │ └── Tree.class │ └── test │ │ ├── CatTest.class │ │ ├── CdTest.class │ │ ├── CpTest.class │ │ ├── DirectoryTest.class │ │ ├── EchoTest.class │ │ ├── ExitTest.class │ │ ├── FileExistsTest.class │ │ ├── FileTest.class │ │ ├── FormatMeTest.class │ │ ├── GetTest.class │ │ ├── GrepTest.class │ │ ├── HistoryTest.class │ │ ├── InputparserTest.class │ │ ├── LsTest.class │ │ ├── ManTest.class │ │ ├── MkdirTest.class │ │ ├── MvTest.class │ │ ├── PathWalkerTest.class │ │ ├── PopdTest.class │ │ ├── PushdTest.class │ │ ├── PwdTest.class │ │ ├── SplitPathsTest.class │ │ └── TestNumber.class ├── crcCards │ ├── Cat.txt │ ├── Cd.txt │ ├── CommandInterface.txt │ ├── Directory.txt │ ├── Echo.txt │ ├── File.txt │ ├── FormatMe.txt │ ├── Get.txt │ ├── Grep.txt │ ├── History.txt │ ├── InputParser.txt │ ├── JShell.txt │ ├── Ls.txt │ ├── Man.txt │ ├── Mkdir.txt │ ├── Number.txt │ ├── Popd.txt │ ├── Pushd.txt │ ├── Pwd.txt │ ├── StdOutput.txt │ ├── Tree.txt │ └── readMeForCrcCards.txt ├── dailyScrumMeetings │ ├── leejos14Sprint1October21.txt │ ├── leejos14Sprint2October24.txt │ ├── leejos14Sprint2October27.txt │ ├── leejos14Sprint3November3.txt │ ├── leejos14Sprint3October30.txt │ ├── leejos14Sprint4November11.txt │ ├── leejos14Sprint4November15.txt │ ├── leejos14Sprint5November20.txt │ ├── leejos14Sprint5November22.txt │ ├── ondertanSprint1October21.txt │ ├── ondertanSprint2October24.txt │ ├── ondertanSprint2October27.txt │ ├── ondertanSprint3November3.txt │ ├── ondertanSprint3October30.txt │ ├── ondertanSprint4November11.txt │ ├── ondertanSprint4November15.txt │ ├── ondertanSprint5November19.txt │ ├── ondertanSprint5November22.txt │ ├── readMeDailyScrumMeetings.txt │ ├── sharm389Sprint1October21.txt │ ├── sharm389Sprint2October24.txt │ ├── sharm389Sprint2October27.txt │ ├── sharm389Sprint3November3.txt │ ├── sharm389Sprint3October30.txt │ └── sharm389Sprint4November11.txt ├── productBacklog │ ├── productBacklog2.txt │ ├── productBacklogFor2A.txt │ └── readMeProductBacklog.txt ├── sprints │ ├── Sprint1Backlog.txt │ ├── Sprint2Backlog.txt │ ├── Sprint3Backlog.txt │ ├── Sprint4Backlog.txt │ ├── Sprint5Backlog.txt │ └── readMeSprints.txt └── src │ ├── commands │ ├── Cat.java │ ├── Cd.java │ ├── CommandInterface.java │ ├── Cp.java │ ├── Echo.java │ ├── Exit.java │ ├── Get.java │ ├── Grep.java │ ├── History.java │ ├── Ls.java │ ├── Man.java │ ├── Mkdir.java │ ├── Mv.java │ ├── Number.java │ ├── Popd.java │ ├── Pushd.java │ └── Pwd.java │ ├── driver │ └── JShell.java │ ├── exceptions │ ├── FileDirectoryExistsException.java │ └── InvalidSyntaxException.java │ ├── helpers │ ├── Directory.java │ ├── File.java │ ├── FileExists.java │ ├── FormatMe.java │ ├── InputParser.java │ ├── PathWalker.java │ ├── Pathchecker.java │ ├── Reflection.java │ ├── SplitPaths.java │ ├── StdOutput.java │ └── Tree.java │ └── test │ ├── CatTest.java │ ├── CdTest.java │ ├── CpTest.java │ ├── DirectoryTest.java │ ├── EchoTest.java │ ├── ExitTest.java │ ├── FileExistsTest.java │ ├── FileTest.java │ ├── FormatMeTest.java │ ├── GetTest.java │ ├── GrepTest.java │ ├── HistoryTest.java │ ├── InputparserTest.java │ ├── LsTest.java │ ├── ManTest.java │ ├── MkdirTest.java │ ├── MvTest.java │ ├── PathWalkerTest.java │ ├── PopdTest.java │ ├── PushdTest.java │ ├── PwdTest.java │ ├── SplitPathsTest.java │ └── TestNumber.java └── README.md /Mock Linux Shell in Java/bin/commands/Cat.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/Cat.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/commands/Cd.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/Cd.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/commands/CommandInterface.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/CommandInterface.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/commands/Cp.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/Cp.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/commands/Echo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/Echo.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/commands/Exit.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/Exit.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/commands/Get.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/Get.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/commands/Grep.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/Grep.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/commands/History.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/History.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/commands/Ls.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/Ls.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/commands/Man.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/Man.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/commands/Mkdir.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/Mkdir.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/commands/Mv.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/Mv.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/commands/Number.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/Number.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/commands/Popd.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/Popd.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/commands/Pushd.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/Pushd.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/commands/Pwd.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/commands/Pwd.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/driver/JShell.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/driver/JShell.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/exceptions/FileDirectoryExistsException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/exceptions/FileDirectoryExistsException.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/exceptions/InvalidSyntaxException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/exceptions/InvalidSyntaxException.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/helpers/Directory.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/helpers/Directory.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/helpers/File.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/helpers/File.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/helpers/FileExists.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/helpers/FileExists.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/helpers/FormatMe.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/helpers/FormatMe.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/helpers/InputParser.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/helpers/InputParser.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/helpers/PathWalker.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/helpers/PathWalker.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/helpers/Pathchecker.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/helpers/Pathchecker.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/helpers/Reflection.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/helpers/Reflection.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/helpers/SplitPaths.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/helpers/SplitPaths.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/helpers/StdOutput.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/helpers/StdOutput.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/helpers/Tree.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/helpers/Tree.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/CatTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/CatTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/CdTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/CdTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/CpTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/CpTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/DirectoryTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/DirectoryTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/EchoTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/EchoTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/ExitTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/ExitTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/FileExistsTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/FileExistsTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/FileTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/FileTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/FormatMeTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/FormatMeTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/GetTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/GetTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/GrepTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/GrepTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/HistoryTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/HistoryTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/InputparserTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/InputparserTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/LsTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/LsTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/ManTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/ManTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/MkdirTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/MkdirTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/MvTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/MvTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/PathWalkerTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/PathWalkerTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/PopdTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/PopdTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/PushdTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/PushdTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/PwdTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/PwdTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/SplitPathsTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/SplitPathsTest.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/bin/test/TestNumber.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arjun-Sharma1/Mock-Linux-Shell-in-Java/5f01326dceec5463fcb6d1e757e10ac0eab2e796/Mock Linux Shell in Java/bin/test/TestNumber.class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/Cat.txt: -------------------------------------------------------------------------------- 1 | Class Name: Cat 2 | Parent Class: Echo 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Display the name and the contents of a file 7 | 8 | Collaborators: 9 | * Directory class 10 | * File -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/Cd.txt: -------------------------------------------------------------------------------- 1 | Class Name: Cd 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Change the current working directory 7 | * Move up and down into a directory 8 | 9 | 10 | Collaborators: 11 | * Directory -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/CommandInterface.txt: -------------------------------------------------------------------------------- 1 | Class Name: CommandInterface 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Framework of all commands 7 | 8 | Collaborators: 9 | * Directory -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/Directory.txt: -------------------------------------------------------------------------------- 1 | Class Name: Directory 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Organize folders and files into a hierarchical structure 7 | * Keeps track of the current working directory 8 | * Changes current directory 9 | * Gets content from a tree node 10 | * Check if certain directory exists 11 | 12 | Collaborators: 13 | * File 14 | * Tree 15 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/Echo.txt: -------------------------------------------------------------------------------- 1 | Class Name: Echo 2 | Parent Class: NONE 3 | Subclasses: Cat 4 | 5 | Responsibilities: 6 | * Creates a new file if file does not exist 7 | * Overwrites old contents of if if it already exists 8 | * Appends content to a file 9 | 10 | Collaborators: 11 | * File 12 | * Directory -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/File.txt: -------------------------------------------------------------------------------- 1 | Class Name: File 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Stores the name of the file 7 | * Stores contents of the file 8 | 9 | Collaborators: 10 | * NONE -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/FormatMe.txt: -------------------------------------------------------------------------------- 1 | Class Name: FormatMe 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Formats the string for appropriate inputs 7 | 8 | 9 | Collaborators: 10 | 11 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/Get.txt: -------------------------------------------------------------------------------- 1 | Class Name: Get 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Gets all text files from a given URL 7 | * Saves all of the text files into current directory 8 | 9 | Collaborators: 10 | * Directory 11 | * File 12 | * PathChecker 13 | * SplitPath 14 | * PathWalker -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/Grep.txt: -------------------------------------------------------------------------------- 1 | Class Name: Grep 2 | Parent Class: Echo 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Finds lines in files that has the regular expression and prints it 7 | 8 | Collaborators: 9 | * Directory 10 | * File 11 | * PathChecker 12 | * SplitPath -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/History.txt: -------------------------------------------------------------------------------- 1 | Class Name: History 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Store commands from the shell 7 | * Returns all the items in the history 8 | * Returns n number of the most recent items in the history 9 | 10 | Collaborators: 11 | * Directory -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/InputParser.txt: -------------------------------------------------------------------------------- 1 | Class Name: InputParser 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Determines whether an input is valid or not 7 | 8 | 9 | Collaborators: 10 | * NONE -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/JShell.txt: -------------------------------------------------------------------------------- 1 | Class Name: JShell 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Accepts known 7 | 8 | * Start up when ran by the user 9 | * Shut down when 'exit' is entered by user 10 | * Provide access to different commands for the user 11 | * Display a command line and accept a commands from keyboard 12 | 13 | Collaborators: 14 | * CommandInterface 15 | * InputParser -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/Ls.txt: -------------------------------------------------------------------------------- 1 | Class Name: Ls 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Prints out all files in current directory or in a given path 7 | * Prints out all directories in the current directory or in a given path 8 | 9 | Collaborators: 10 | * Directory -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/Man.txt: -------------------------------------------------------------------------------- 1 | Class Name: Man 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Prints a manual for all the commands available in the shell 7 | 8 | 9 | Collaborators: 10 | * NONE -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/Mkdir.txt: -------------------------------------------------------------------------------- 1 | Class Name: Mkdir 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Create a directory in current directory 7 | * Create a directory in a given file path 8 | 9 | 10 | Collaborators: 11 | * Directory 12 | * Tree 13 | * FormatMe -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/Number.txt: -------------------------------------------------------------------------------- 1 | Class Name: Number 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Recalls a command in the history 7 | 8 | 9 | Collaborators: 10 | * Directory 11 | * Tree 12 | * History 13 | * Reflection -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/Popd.txt: -------------------------------------------------------------------------------- 1 | Class Name: Popd 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Checks if there is a directory stored, changes the current directory to the stored directory 7 | 8 | Collaborators: 9 | * Directory -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/Pushd.txt: -------------------------------------------------------------------------------- 1 | Class Name: Pushd 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Stores the current directory 7 | 8 | Collaborators: 9 | * Directory 10 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/Pwd.txt: -------------------------------------------------------------------------------- 1 | Class Name: Pwd 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Prints the current working directory with the whole path 7 | 8 | Collaborators: 9 | * Directory -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/StdOutput.txt: -------------------------------------------------------------------------------- 1 | Class Name: StdOutput 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Redirects a commands output into a file 7 | * Can overwrite a file or append to a file also 8 | 9 | Collaborators: 10 | * Directory 11 | * File 12 | * PathChecker 13 | * SplitPath 14 | * PathWalker 15 | * Reflection 16 | * Man 17 | * Mkdir 18 | * Cat 19 | * Ls 20 | * Grep 21 | * History 22 | * Mv 23 | * Pushd 24 | * Popd -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/Tree.txt: -------------------------------------------------------------------------------- 1 | Class Name: Tree 2 | Parent Class: NONE 3 | Subclasses: NONE 4 | 5 | Responsibilities: 6 | * Create a Tree 7 | * Add nodes 8 | * Subtract nodes 9 | * Read contents of nodes 10 | * Be able to store String and node in nodes 11 | 12 | Collaborators: 13 | * File -------------------------------------------------------------------------------- /Mock Linux Shell in Java/crcCards/readMeForCrcCards.txt: -------------------------------------------------------------------------------- 1 | --All your crc cards will reside in here. 2 | 3 | --Your code structure MUST always reflect the design outlined in CRC Cards. 4 | 5 | --If at any point you change or modify your design: 6 | ----a) Change your CRC Cards to reflect the new design. 7 | ----b) Change your code sturcture so that it reflects the new design. 8 | 9 | --Follow the same format as in Assignment1 for crc cards. 10 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/leejos14Sprint1October21.txt: -------------------------------------------------------------------------------- 1 | What did I do last time? 2 | - Checked out from the repository 3 | - Made crc cards 4 | - Updated crc cards to meet new definitions of classes 5 | - Made framework of JShell 6 | - Helped making tree for directory class 7 | - Added File class 8 | 9 | What do I plan to do now? 10 | - Finish JShell framework 11 | - Finish the File class 12 | - Make echo class 13 | 14 | Am I blocked on anything? 15 | - Blocked on making File class to work with trees -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/leejos14Sprint2October24.txt: -------------------------------------------------------------------------------- 1 | What did I do last time? 2 | - Finish JShell framework 3 | - worked on the File class 4 | - Worked on Echo class 5 | 6 | 7 | What do I plan to do now? 8 | - Finish File class 9 | - Finish echo class 10 | - Interconnect the JShell class with other classes 11 | 12 | Am I blocked on anything? 13 | - Blocked on making Echo class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/leejos14Sprint2October27.txt: -------------------------------------------------------------------------------- 1 | What did I do last time? 2 | - Implemented hashtables into the jshell 3 | - Worked on Echo class 4 | - Finished the File class 5 | 6 | 7 | What do I plan to do now? 8 | - Finish echo class 9 | - Interconnect the JShell class with other classes 10 | 11 | Am I blocked on anything? 12 | - Blocked on completing the Echo class -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/leejos14Sprint3November3.txt: -------------------------------------------------------------------------------- 1 | What did I do last time? 2 | - Add comments to echo class 3 | - Add comments to file class 4 | - Add comments to exit class 5 | - Add comments to cat class 6 | 7 | 8 | What do I plan to do now? 9 | - Add type contracts to echo class 10 | - Implement singletones to echo class 11 | - Add type contracts to file class 12 | - Add type contracts to exit class 13 | - Add type contracts to cat class 14 | 15 | Am I blocked on anything? 16 | - Blocked on singleton design for echo -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/leejos14Sprint3October30.txt: -------------------------------------------------------------------------------- 1 | What did I do last time? 2 | - Finished echo class 3 | - Finished cat class 4 | - Added additional functionality to file class 5 | 6 | 7 | What do I plan to do now? 8 | - Add comments to echo class 9 | - Add comments to file class 10 | - Add comments to exit class 11 | - Add comments to cat class 12 | 13 | Am I blocked on anything? 14 | - Blocked on added comments -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/leejos14Sprint4November11.txt: -------------------------------------------------------------------------------- 1 | What did I do last time? 2 | - Add type contracts to echo class 3 | - Add type contracts to file class 4 | - Add type contracts to exit class 5 | - Add type contracts to cat class 6 | - Made echo more modular by splitting all the functions into seperate methods 7 | 8 | 9 | What do I plan to do now? 10 | - Added error class 11 | - Add save command to echo 12 | 13 | 14 | Am I blocked on anything? 15 | - Blocked on adding save command to echo -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/leejos14Sprint4November15.txt: -------------------------------------------------------------------------------- 1 | What did I do last time? 2 | - Created an error class 3 | - Made cat accept multiple files of same directory 4 | - Added comments to new cat method 5 | 6 | 7 | What do I plan to do now? 8 | - Fill in error class 9 | - Implement partial and full paths into class 10 | 11 | 12 | Am I blocked on anything? 13 | - Making cat take partial and full paths -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/leejos14Sprint5November20.txt: -------------------------------------------------------------------------------- 1 | What did I do last time? 2 | - implemented partial and full paths to echo 3 | - implemented partial and full paths to cat 4 | - created geturl class 5 | 6 | What do I plan to do now? 7 | - finish geturl class 8 | - finish history command 9 | 10 | 11 | Am I blocked on anything? 12 | - finish geturl -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/leejos14Sprint5November22.txt: -------------------------------------------------------------------------------- 1 | What did I do last time? 2 | - Finished get calss 3 | - fixed echo class 4 | - Fixed cat class 5 | - Added test cases for SplitPath and FileExists 6 | - Added crc for get url 7 | 8 | What do I plan to do now? 9 | 10 | 11 | 12 | Am I blocked on anything? 13 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/ondertanSprint1October21.txt: -------------------------------------------------------------------------------- 1 | What did I do last time? 2 | - considered the implementation of the overall shell 3 | - brainstormed ideas but the crcCards 4 | - Started on the tree class 5 | 6 | What do I plan to do now? 7 | - Finish the tree class 8 | - work on new tasks for sprint 2 9 | - finalize the design portion, as there were some undecided parts among the group 10 | 11 | Am I blocked on anything? 12 | - we are thinking of working off a tree, the idea needs to be smoothed out and the implementation of the tree needs to be perfected, have some issues with adding parents as of this moment -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/ondertanSprint2October24.txt: -------------------------------------------------------------------------------- 1 | What did I do this time? 2 | - Added crc cards 3 | - Updated old crc cards 4 | - Worked on the Tree class 5 | 6 | What do I plan to do now? 7 | - Work on man class 8 | - Create pwd class 9 | - Complete pwd class 10 | - Debug pwd class 11 | 12 | Am I blocked on anything? 13 | - General limitations, like random bugs and logical misconceptions -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/ondertanSprint2October27.txt: -------------------------------------------------------------------------------- 1 | What did I do this time? 2 | - complete Pwd class 3 | - Worked on the man class 4 | 5 | What do I plan to do now? 6 | - Complete man class 7 | - Test pwd class 8 | 9 | Am I blocked on anything? 10 | - General limitations, like random bugs and logical misconceptions -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/ondertanSprint3November3.txt: -------------------------------------------------------------------------------- 1 | What did I do this time? 2 | - Debug Pwd and allow it to work with Shell 3 | - JUnit test pwd class 4 | 5 | What do I plan to do now? 6 | - JUnit test mkdir class 7 | - JUnit test exit class 8 | - JUnit test man class 9 | - JUnit test cd class 10 | - JUnit test ls class 11 | 12 | Am I blocked on anything? 13 | - Having to get the same type of output to be able to use assert equal -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/ondertanSprint3October30.txt: -------------------------------------------------------------------------------- 1 | What did I do this time? 2 | - implemented new functionality to the Pwd class 3 | - Finished the man class 4 | 5 | What do I plan to do now? 6 | - Think up test scenarios 7 | - Start test cases 8 | - Update all the crcCards (as they became out of date as we were developing) 9 | 10 | Am I blocked on anything? 11 | - Doing test cases are very tedious 12 | - Limited knowledge of how testing in java works -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/ondertanSprint4November11.txt: -------------------------------------------------------------------------------- 1 | What did I do this time? 2 | - Read and comprehended the new requirements 3 | - Went over some old code from A2 4 | 5 | What do I plan to do now? 6 | - Create grep command 7 | - Implement ! command 8 | 9 | Am I blocked on anything? 10 | - Implementing the parser in to my functions -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/ondertanSprint4November15.txt: -------------------------------------------------------------------------------- 1 | What did I do this time? 2 | - Started on grep class 3 | 4 | What do I plan to do now? 5 | - Complete grep command 6 | - Add test cases for grep 7 | - Complete old test cases that were not optimal 8 | 9 | Am I blocked on anything? 10 | - No, thanks to the video about Regex, there are no more misconceptions -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/ondertanSprint5November19.txt: -------------------------------------------------------------------------------- 1 | What did I do this time? 2 | - Completed grep class main functionality 3 | 4 | What do I plan to do now? 5 | - Add recursion to grep 6 | - Add test cases for grep 7 | - Complete old test cases that were not optimal 8 | - help with get 9 | 10 | Am I blocked on anything? 11 | - the recursion for grep -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/ondertanSprint5November22.txt: -------------------------------------------------------------------------------- 1 | What did I do this time? 2 | - Completed grep 3 | - Updated man with the new commands 4 | - Updated test cases for Directory 5 | - Updated test cases for Echo 6 | - Updated test cases for Cat 7 | 8 | What do I plan to do now? 9 | - Think up test scenarios 10 | - Complete test cases 11 | - Update crcCards (as they became out of date as we were developing) 12 | 13 | Am I blocked on anything? 14 | - Doing test cases are very tedious -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/readMeDailyScrumMeetings.txt: -------------------------------------------------------------------------------- 1 | Each one of you is responsible for adding a file in this folder every three days with the following contents: Do not ask your colleague to commit for you. That won't count. 2 | 3 | a) What did I work on last time? 4 | 5 | b) What do I plan to work on now? 6 | 7 | c) Am I blocked on anything? 8 | 9 | 10 | Example1: 11 | 12 | What did I do last time? 13 | - worked on JShell and FileOperation 14 | - brainstormed design ideas with team for echo and mkdir commands. 15 | 16 | What do I plan to do now? 17 | - finish JShell and FileOperation 18 | - work on new tasks for sprint 2 19 | - start and finish Man, Echo, Mv 20 | 21 | Am I blocked on anything? 22 | - Need FileSystem, StandardOutput, StandardError, and Command to be completed (or at least prototyped) before I can continue working 23 | 24 | 25 | The filename for this will be: 26 | UTORUserNameSprint#Date.txt 27 | 28 | for example: 29 | 30 | c1abcxyzSprint1October17.txt 31 | 32 | where c1abcxyz=UTORUserName 33 | 1 in Sprint1=Sprint # 34 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/sharm389Sprint1October21.txt: -------------------------------------------------------------------------------- 1 | What did I do this time? 2 | - Added crc cards 3 | - Added items to product backlog 4 | - Added items to sprint backlog 5 | - Updated old crc cards 6 | - Worked on Jshell class 7 | - Assisted with Tree class 8 | - Added exception class 9 | 10 | What do I plan to do now? 11 | - Work on exception class 12 | - Fix product backlog 13 | - Work on History Class 14 | 15 | Am I blocked on anything? 16 | - Blocked on fixing exception class 17 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/sharm389Sprint2October24.txt: -------------------------------------------------------------------------------- 1 | What did I do this time? 2 | - Added sprint log #2 3 | - Coded the history class 4 | - Coded some of the man class 5 | - Debugged the history class 6 | - Added a few commands to Jshell 7 | - Assisted with the Tree class 8 | - Commented on history and man class 9 | 10 | What do I plan to do now? 11 | - Create the ls class 12 | - Check the crc cards since we recently updated design 13 | - Assist with the echo and directory class 14 | 15 | Am I blocked on anything? 16 | - Not at the moment -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/sharm389Sprint2October27.txt: -------------------------------------------------------------------------------- 1 | What did I do this time? 2 | - Coded most of ls class 3 | - Changed crc cards since we got rid of some classes 4 | - Still working on the echo class 5 | - Directory class renamed to tree class and finished 6 | - Assited in implementing hashtables into jshell 7 | 8 | What do I plan to do now? 9 | - Adding hashtables to man class 10 | - Finish coding rest of man class 11 | - Assist on optimizing jshell 12 | - Debugging ls class 13 | - Continue working/assit on echo class 14 | 15 | Am I blocked on anything? 16 | - Debugging the ls class(Still causing some errors) 17 | - Trying to find ways to add polymorphism to design -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/sharm389Sprint3November3.txt: -------------------------------------------------------------------------------- 1 | What did I do this time? 2 | - Added an interface to our design 3 | - Added an execute method for each class 4 | - Created new Jshell code 5 | - Coded input parser class 6 | - Coded path checker class 7 | 8 | What do I plan to do now? 9 | - Assist with J unit tests 10 | - Start commenting my own code 11 | - Fix variable names 12 | - Read over crc cards 13 | 14 | Am I blocked on anything? 15 | - Nope! -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/sharm389Sprint3October30.txt: -------------------------------------------------------------------------------- 1 | What did I do this time? 2 | - Still Coding ls(Had to restart after a huge mistake) 3 | - Refactoring some code for classes 4 | - Optimized Jshell 5 | - Created Sprint Backlog 3 6 | - Finished man class 7 | 8 | What do I plan to do now? 9 | - Debugging mkdir and ls classes 10 | - Trying to implement an interface 11 | - Trying to incorporate inheritence into echo class 12 | - Debug cd class 13 | 14 | 15 | Am I blocked on anything? 16 | - Trying to find ways to make Jshell more efficient using one of the design 17 | patterns -------------------------------------------------------------------------------- /Mock Linux Shell in Java/dailyScrumMeetings/sharm389Sprint4November11.txt: -------------------------------------------------------------------------------- 1 | What did I do this time? 2 | - Attempted to add -r command to ls 3 | - Tried to implement displaying all ls subdirectories 4 | - Added pathchecker class 5 | - Implemented path checker class into ls 6 | 7 | What do I plan to do now? 8 | - Fix the recursively display subdirectories 9 | - Add -r command to jshell 10 | - Debug ls 11 | - Add pathchecker to other classes 12 | 13 | Am I blocked on anything? 14 | - Recursively displaying all subdirectories -------------------------------------------------------------------------------- /Mock Linux Shell in Java/productBacklog/productBacklog2.txt: -------------------------------------------------------------------------------- 1 | UserStory: Create a file with all the commands I wrote 2 | As a user of the JShell, I want to be able to capture the output of the commands 3 | and save it onto a file 4 | Estimated Time: 4 hours 5 | 6 | UserStory: List all subdirectories 7 | As a user of the JShell, I want to be able to see all the content of my current 8 | working directory and all of its subdirectories. 9 | Estimated Time: 3 hours 10 | 11 | UserStory: Move directories or files 12 | As a user of the JShell, I want to be able to move a directory/file to another 13 | directory/path. 14 | Estimated Time: 1 hour 15 | 16 | UserStory: Copy directories 17 | As a user of the JShell, I want to be able to create a copy of a directory or 18 | file and place it into another path or directory. 19 | Estimated Time: 1 hour 20 | 21 | UserStory: Retrieve a file from a URL 22 | As a user of the JShell, I want to be able to retrieve a file from a URL and 23 | place it in my current directory 24 | Estimated Time: 3 hour 25 | 26 | UserStory: Execute previous commands 27 | As a user of the JShell, I want to be able to use the command I previously 28 | typed on the shell 29 | Estimated Time: 2 hour 30 | 31 | UserStory: View content of multiple files at once 32 | As a user of the JShell, I want to be able to view the contents of multiple 33 | files at once 34 | Estimated Time: 1 hour 35 | 36 | UserStory: Find lines containing my regex 37 | As a user of the JShell, I want to be able to find all of the lines containing 38 | the regex/string 39 | Estimated Time: 4 hour 40 | 41 | UserStory: Find all file containing my regex 42 | As a user of the JShell, I want to be able to get all of the files that contain 43 | the regex I specified. 44 | Estimated Time: 4 hour -------------------------------------------------------------------------------- /Mock Linux Shell in Java/productBacklog/productBacklogFor2A.txt: -------------------------------------------------------------------------------- 1 | Story: Create new Directories With a Specific Name 2 | As a user of the JShell, I want to be able to create a directory so that I can 3 | better organize my files 4 | Estimated time implement: 2 Hours 5 | 6 | Story: Exit the shell 7 | As a user of the JShell, I want to be able to close the program at any given 8 | time so that I can save memory on my computer 9 | Estimated time implement: 30 minutes 10 | 11 | Story: Check what Files I Have in My Current Directory 12 | As a user of the JShell, I want to be able to see what files are in my current 13 | directory so that I can know what I have saved on my computer. 14 | Estimated time implement: 1 hour 15 | 16 | Story: See the path for my current working directory 17 | As a user of the JShell, I want to be able to see the path of my current 18 | working directory so that I know where my file is located and don't have to 19 | search for it next time. 20 | Estimated time implement: 1 hours 21 | 22 | Story: Save my old directory and add a new directory that will be my current working directory 23 | Estimated time implement: 3 hours 24 | 25 | Story: Go Back to the Previous Directory 26 | As a user of the Jshell, I want to be able to go back the the previous 27 | directory I was working in so I don't have to waste time searching for my 28 | previous directory 29 | Estimated time implement: 30 minutes 30 | 31 | Story: See my recent commands 32 | As a user of the Jshell, I want to be able to see my recent/previous commands 33 | so that I can keep track of how I altered my file(s). 34 | Estimated time implement: 1 hour 35 | 36 | Story: See contents of my file 37 | As a user of the JShell, I want to be able to see the contents of my file so 38 | I can edit it and make changes to it. 39 | Estimated time implement: 2 hours 40 | 41 | Story: Save text that I type into shell into a file 42 | As a user of the JShell, I want to be able to save text I write on the JShell 43 | so that I am able to write reminders down for later or my ideas. 44 | Estimated time implement: 2 hours 45 | 46 | Story: Add text to a existing file 47 | As a user of the JShell, I want to be add text to an already exisiting file 48 | so that I can keep all my ideas in one place. 49 | Estimated time implement: 30 minutes 50 | 51 | Story: Find Help 52 | As a user of the JShell, I want to be able to get help to find what commands 53 | are on the JShell and what they do so that I can navigate smoothly on the 54 | JShell. 55 | Estimated time implement: 2 hours 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/productBacklog/readMeProductBacklog.txt: -------------------------------------------------------------------------------- 1 | 1) You will create a single file called productBacklogFor2A.txt in here. 2 | 3 | 2) You can follow the lecture slides on Scrum Software Development Process on how to create user stories for this. 4 | 5 | 3) The product backlog essentially will contain all the usecases/user stories, functional requirements of your project. These are the entities that the customer expects at the due date of your assignment. 6 | 7 | 4) This is the very first thing that you will do before starting any work on Assignment2. 8 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/sprints/Sprint1Backlog.txt: -------------------------------------------------------------------------------- 1 | //Sprint # Backlog. 2 | October 18 to October 23 3 | 4 | 5 | Product Backlog items to be implemented: 6 | a) Navigate the contents of the file system 7 | b) Exit the shell 8 | c) Check if User input is valid 9 | d) Check what Files I Have in My Current Directory 10 | e) Update and add crc cards 11 | 12 | Specific tasks to be accomplished: 13 | a-1. (Exception) Code exception class. 14 | a-2. (CRC Cards) Adjust crc cards. 15 | a-3. Start coding man class 16 | b-1. (Tree) Code Tree class. 17 | b-2. (Planing) Theorize other classes. 18 | b-3. (CRC Cards) Adjust crc cards. 19 | c-1. (File) Write the base code for the File class 20 | c-2. (JShell) Begin coding the structure of the command line interpreter 21 | c-3. Attempt to code echo class 22 | d-1. (Directory) Write the base code for the directory class 23 | d-2. (CRC Cards) Adjust crc cards. 24 | d-3. Attempt to start mkdir class 25 | 26 | 27 | These tasks are assigned as follows: 28 | 29 | User: Arjun 30 | Tasks: a-1, a-2, a-3 31 | 32 | User: Tanay 33 | Tasks: b-1, b-2, b-3 34 | 35 | User: Joseph 36 | Tasks: c-1, c-2 37 | 38 | User: Taras 39 | Tasks: d-1, d-2 40 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/sprints/Sprint2Backlog.txt: -------------------------------------------------------------------------------- 1 | //Sprint #2 Backlog. 2 | October 24 to October 29 3 | 4 | 5 | Product Backlog items to be implemented: 6 | a) Create directories with specific names 7 | b) See path of current working directory 8 | c) See contents of current working directory 9 | d) Go back to previous directory 10 | e) Add text to an existing file, and create a file 11 | f) Push and pop commands 12 | 13 | Specific tasks to be accomplished: 14 | a-1) Create ls class 15 | a-2) Finish coding the ls class 16 | a-3) Debug ls class and fix and errors 17 | b-1) Create pwd class 18 | b-2) Code the pwd class 19 | b-3) Debug pwd class and fix errors 20 | b-4) Complete man class 21 | c-1) Code the echo class 22 | c-2) Implement commands into the jshell class 23 | c-3) Fix the file class 24 | d-1) Create the pushd and popd class 25 | d-2) Check for errors in the mkdir class 26 | d-3) Finish the directory class 27 | 28 | 29 | These tasks are assigned as follows: 30 | 31 | User: Arjun 32 | Tasks: a-1, a-2, a-3 33 | 34 | User: Tanay 35 | Tasks: b-1, b-2, b-3 36 | 37 | User: Joseph 38 | Tasks: c-1, c-2, c-3 39 | 40 | User: Taras 41 | Tasks: d-1, d-2, d-3 -------------------------------------------------------------------------------- /Mock Linux Shell in Java/sprints/Sprint3Backlog.txt: -------------------------------------------------------------------------------- 1 | //Sprint # Backlog. 2 | October 31 to November 5th 3 | 4 | 5 | Product Backlog items to be implemented: 6 | a) See my recent commands 7 | b) See contents of my file 8 | c) Find Help 9 | d) JUnit Test Cases 10 | 11 | Specific tasks to be accomplished: 12 | a-1. Finish Coding History Class 13 | a-2. Finish Coding Ls class 14 | b-1. Create test cases for all classes 15 | b-2. Start commenting on classes 16 | b-3. (CRC Cards) Adjust crc cards. 17 | c-1. Implement new polymorphism/interface design into Jshell 18 | c-2. Fix echo class 19 | d-1. Debug mkdir class 20 | d-2. Assist with implementing new design for Jshell 21 | 22 | 23 | These tasks are assigned as follows: 24 | 25 | User: Arjun 26 | Tasks: a-1, a-2 27 | 28 | User: Tanay 29 | Tasks: b-1, b-2 30 | 31 | User: Joseph 32 | Tasks: c-1, c-2 33 | 34 | User: Taras 35 | Tasks: d-1, d-2 36 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/sprints/Sprint4Backlog.txt: -------------------------------------------------------------------------------- 1 | //Sprint 4 Backlog. 2 | November 9 to November 13 3 | 4 | 5 | Product Backlog items to be implemented: 6 | a) List all subdirectories of a directory 7 | b) Create a file with all the commands I wrote 8 | c) Move directories or files 9 | d) Copy directories 10 | e) View content of multiple files at once 11 | 12 | Specific tasks to be accomplished: 13 | a-1. Implement ls to recursively view all subdirectories 14 | a-2. Finish Coding Ls class 15 | b-1. Create copy and mv classes 16 | b-2. Implement the copy command 17 | b-3. Implement the mv command 18 | b-4. Implement mv to work with relative paths 19 | c-1. Create new exception class to account for new errors 20 | c-2. Implement echo on a command(Save the command and its output) 21 | d-1. Implement ! to find a previous command after n amount of commands 22 | d-2. Create grep command 23 | 24 | These tasks are assigned as follows: 25 | 26 | User: Arjun 27 | Tasks: a-1, a-2 28 | 29 | User: Taras 30 | Tasks: b-1,b-2, b-3, b-4 31 | 32 | User: Tanay 33 | Tasks: d-1,d-2 34 | 35 | User: Joseph 36 | Tasks: c-1,c-2 -------------------------------------------------------------------------------- /Mock Linux Shell in Java/sprints/Sprint5Backlog.txt: -------------------------------------------------------------------------------- 1 | //Sprint 4 Backlog. 2 | November 15 to November 20 3 | 4 | 5 | Product Backlog items to be implemented: 6 | a) Retrieve a file from a URL 7 | b) Find lines containing my regex 8 | c) Find all files containing my regex 9 | d) Add test cases/comment code 10 | 11 | Specific tasks to be accomplished: 12 | a-1. Fix ! command not being put into history 13 | a-2. Allow ls to take multple arguments/paths 14 | b-1. Start creating test cases 15 | b-2. Add comments to current code/java docs 16 | c-1. Create the geturl class 17 | c-2. Implement the get url class 18 | d-1. Implement grep command for multiple files 19 | d-2. Finish debugging grep command 20 | 21 | These tasks are assigned as follows: 22 | 23 | User: Arjun 24 | Tasks: a-1, a-2 25 | 26 | User: Taras 27 | Tasks: b-1,b-2 28 | 29 | User: Tanay 30 | Tasks: d-1,d-2 31 | 32 | User: Joseph 33 | Tasks: c-1,c-2 -------------------------------------------------------------------------------- /Mock Linux Shell in Java/sprints/readMeSprints.txt: -------------------------------------------------------------------------------- 1 | 1) From your product backlog, break the number of features such that are distributed across multiple sprints. 2 | 3 | 2) Each sprint will last for a maximum of 6 days. You have in total of roughly 3 or 4 sprints. Your first sprint should begin by 18th October 2015. 4 | 5 | One time table for your sprints i.e. 3 sprints could be as follows: 6 | 7 | Sprint1 is from 18th October to 23rd October. 8 | Sprint2 is from 24th October to 29th October. 9 | Sprint3 is from 30th October to 5th November. 10 | 11 | 3) Before start of each sprint, create a sprint backlog. Your sprint backlog will contain clearly what you as a team plan to accomplish in that sprint and how these tasks(code, testing, update of crc cards, etc etc) are distributed across team members. The scrum leader must take the lead on this. 12 | 13 | 4) The filename for your sprint backlog will be: 14 | 15 | Sprint#Backlog.txt 16 | 17 | For example: 18 | Sprint1Backlog.txt 19 | Sprint2Backlog.txt 20 | 21 | 5) This backlog must be the very first thing you will do at start of sprint. You cannot begin with the implementation or any phase of your project without first creating a sprint backlog for that sprint. 22 | 23 | 6) Remember this is easy for me to check by comparing SVN time stamps. 24 | 25 | 7) If you have certain tasks that did not get completed in the sprint. Make sure to mention these and enter them in the start of the next sprint backlog. 26 | 27 | For Example: 28 | 29 | 30 | //Sprint # Backlog. 31 | October XX to October XX 32 | 33 | 34 | Product Backlog items to be implemented: 35 | a) Prompt the user for input 36 | b) Parse the user input through an interpreter 37 | c) etc 38 | d) etc 39 | e) Navigate the contents of the file system 40 | 41 | Specific tasks to be accomplished: 42 | a-1. (JShell) Begin coding the structure of the command line interpreter 43 | a-2. (JShell) Have the shell continually prompt the user for input 44 | b-1. (JShell) Parse the user input for proper keywords 45 | b-2. etc 46 | c-1. etc 47 | c-2. etc 48 | d-1. etc 49 | e-1. etc 50 | e-2. (Directory) Write the base code for the Directory class 51 | e-3. (File) Write the base code for the File class 52 | e-4. etc 53 | e-5. etc 54 | 55 | 56 | These tasks are assigned as follows: 57 | 58 | User: User1 59 | Tasks: e-1, e-2, e-3 60 | 61 | User: User2 62 | Tasks: a-1, a-2, e-5 63 | 64 | User: User3 65 | Tasks: b-1, b-2, e-4 66 | 67 | User: User4 68 | Tasks: c-1, c-2, d-1 69 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/commands/Cat.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package commands; 32 | 33 | import java.util.*; 34 | 35 | import helpers.*; 36 | 37 | 38 | /** 39 | * Class Name: Cat, This class holds methods to display the contents of FILE in 40 | * the shell. 41 | */ 42 | public class Cat implements CommandInterface { 43 | 44 | /** 45 | * Processes an input string into their respective files depending on how many 46 | * files are inputed. 47 | * 48 | * @param dir the dir 49 | * @param inputs The use input that will be broken down into seperate file 50 | * Strings 51 | * @return output 52 | */ 53 | public static List interpreter(Directory dir, String inputs) { 54 | // Breaks down the file into separate Strings for each file name 55 | String[] all = inputs.trim().substring(3).trim().split("\\s+"); 56 | Cd change = new Cd(); 57 | String currentPath = Pwd.printDir(dir); 58 | SplitPaths divide = new SplitPaths(); 59 | Pathchecker valid = new Pathchecker(); 60 | List output = new ArrayList(); // Output array 61 | // Cycles through paths 62 | for (int file = 0; file < all.length; file++) { 63 | change.switchDir(dir, currentPath); // Switch back to current directory 64 | String[] pathFile = divide.pathSplit(all[file]); // Path and file name 65 | if (pathFile[0].equals("")) { // Is a direct file 66 | output.add(getFileInfo(dir, all[file])); // Adds output 67 | } else if (valid.pathCheck(dir, pathFile[0])) { 68 | change.switchDir(dir, pathFile[0]); // Changes file path 69 | output.add(getFileInfo(dir, pathFile[1])); // Adds the output 70 | } else { // No file or directory 71 | output.add("cat: " + all[file] + ": No such file or directory"); 72 | } 73 | } 74 | change.switchDir(dir, currentPath); // Returns to current path 75 | return output; 76 | } 77 | 78 | /** 79 | * Returns a string representation of the file and it's contents. 80 | * 81 | * @param dir the directory 82 | * @param file The file name that will be searched for 83 | * @return output 84 | */ 85 | public static String getFileInfo(Directory dir, String file) { 86 | // Default return string 87 | String output = "cat: " + file + ": No such file or directory"; 88 | // Gets list of current directory 89 | List files = dir.rawWorkingDir().getRawChildren(); 90 | // Loops through objects in the tree 91 | for (int data = 0; data < files.size(); data++) { 92 | // Checks if the nodes are of type File 93 | if (files.get(data).getRawItems() instanceof File) { 94 | // Gets the specific file object 95 | File current = (File) files.get(data).getRawItems(); 96 | if (current.getFileName().equals(file)) { 97 | // Output changes if the file is found 98 | output = current.getContent(); 99 | } 100 | } 101 | } 102 | // Returns output 103 | return output; 104 | } 105 | 106 | /** 107 | * The main method. 108 | * 109 | * @param args the arguments 110 | */ 111 | public void execute(Directory dir, String input, Stack Holder) { 112 | Cat.interpreter(dir, input); 113 | // Changes the list into an iterator 114 | Iterator out = Cat.interpreter(dir, input).iterator(); 115 | // Outputs the files whether it is invalid or not 116 | while (out.hasNext()) { 117 | System.out.println(out.next()); 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/commands/Cd.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package commands; 32 | 33 | import java.util.Stack; 34 | 35 | import helpers.Directory; 36 | import helpers.PathWalker; 37 | 38 | /** 39 | * Class Name: Cd This class navigates through the tree with help of other 40 | * classes. 41 | */ 42 | public class Cd implements CommandInterface { 43 | /** 44 | * Changes the current working directory to the specified. Returns an error if 45 | * directory does not exist. 46 | * 47 | * @param explorer, holds the series of directories that switchDir should 48 | * navigate. 49 | * @param input, the directory to be switched to, also can be a path of 50 | * folders. 51 | * 52 | * @return boolean 53 | */ 54 | public static boolean switchDir(Directory explorer, String input) { 55 | String initialDir = Pwd.printDir(explorer); 56 | if (input.contentEquals("/")) {// switch to root 57 | explorer.changeCurrentDir("/"); 58 | return true;// switch was made 59 | } else if (input.indexOf("/") == 0) {// relative path 60 | explorer.changeCurrentDir("/"); 61 | } 62 | String path[] = input.trim().split("/");// populate array with paths 63 | for (int i = 0; i < path.length; i++) {// go through all the paths 64 | if (path[i].contentEquals("..")// go to parent folder 65 | && !explorer.workingDir().contentEquals("/")) { 66 | explorer.changeCurrentDir(explorer.getParentDir()); 67 | } else if (path[i].contentEquals(".")// go to parent folder 68 | && !explorer.workingDir().contentEquals("/")) { 69 | return true; 70 | } else if (!explorer.cdOneDown(path[i]) && !path[i].contentEquals("")) { 71 | System.out.println("cd: " + path[i] + ": No such directory"); 72 | PathWalker.goToPath(explorer, initialDir); 73 | return false;// indicate the switch was not made to other methods 74 | } 75 | } 76 | return true;// switch was made if this code is reached 77 | } 78 | 79 | /** 80 | * Used by Jshell interface to execute the above methods 81 | * 82 | */ 83 | public void execute(Directory dir, String input, Stack Holder) { 84 | // cut cd and space out of input string 85 | if (input.split("\\s+").length == 2) { 86 | input = input.substring(3).trim(); 87 | Cd.switchDir(dir, input); 88 | } else { 89 | System.out.println("cd: Incorrect input try again."); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/commands/CommandInterface.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package commands; 32 | 33 | import java.util.Stack; 34 | import helpers.Directory; 35 | 36 | /** 37 | * Class Name: CommanInterface This class is necessary for JShell to call on 38 | * classes properly. 39 | */ 40 | public interface CommandInterface { 41 | void execute(Directory dir, String input, Stack holder); 42 | } 43 | 44 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/commands/Cp.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package commands; 32 | 33 | import java.util.List; 34 | import java.util.Stack; 35 | 36 | import helpers.Directory; 37 | import helpers.File; 38 | import helpers.FormatMe; 39 | import helpers.PathWalker; 40 | import helpers.Pathchecker; 41 | import helpers.Tree; 42 | 43 | 44 | public class Cp implements CommandInterface { 45 | 46 | /** 47 | * Checks the path from the given string, holds the copied tree, pastes it in 48 | * the new destination if it exists. 49 | * 50 | * @param explorer, holds the series of directories 51 | * 52 | * @param dir, holds the target and destination path 53 | */ 54 | protected static boolean CopyDir(Directory explorer, String[] dir) { 55 | if (dir[0].equals(".") && dir[1].equals(".")) { 56 | System.out.println("Cannot make same directory sub-directory of itself."); 57 | } 58 | String initialDir = Pwd.printDir(explorer);// original directory holder 59 | if (PathWalker.goToPath(explorer, dir[0])) { // path that needs to be copied 60 | Tree temp = copyFolders(explorer); // recursively duplicate tree 61 | PathWalker.goToPath(explorer, initialDir); // go back to original 62 | if (PathWalker.goToPath(explorer, dir[1])) { // go to destination 63 | explorer.insertMe(temp, explorer.rawWorkingDir());// put the duplicate 64 | PathWalker.goToPath(explorer, initialDir);// go back to original 65 | return true; 66 | } else { 67 | System.out.println("Second path does not exist"); 68 | return false; 69 | } 70 | } else { 71 | System.out.println("First path does not exist"); 72 | return false; 73 | } 74 | 75 | 76 | } 77 | 78 | /** 79 | * Recursively copies the tree and its children. The function copies all the 80 | * sub-directories that are under the current directory. 81 | * 82 | * @param explorer, holds the series of directories 83 | * 84 | * @return Tree, returns the copy of the directories below the current one. 85 | */ 86 | private static Tree copyFolders(Directory explorer) { 87 | if (explorer.getContents().trim() == "") {// no sub directories 88 | return new Tree(explorer.workingDir()); // base case 89 | } else { 90 | Tree temp = new Tree(explorer.workingDir()); // current directory tree 91 | String oldDir = explorer.workingDir(); 92 | List objects = explorer.getRawChildren();// all sub-directories 93 | for (int i = 0; i < objects.size(); i++) { 94 | if (((Tree) objects.get(i)).getRawItems() instanceof File) { 95 | File tempf = // copying file data 96 | new File( 97 | ((File) ((Tree) objects.get(i)).getRawItems()).getFileName(), 98 | ((File) ((Tree) objects.get(i)).getRawItems()).getContent()); 99 | temp.addChild(new Tree(tempf)); 100 | if (explorer.workingDir().equals("/")) {// no need to copy whole tree 101 | return new Tree(tempf); 102 | } 103 | } else if (((Tree) objects.get(i)).getRawItems() instanceof String) { 104 | explorer.cdOneDown(((Tree) objects.get(i)).getItems()); // go into it 105 | temp.addChild(copyFolders(explorer)); // recursive call 106 | explorer.changeCurrentDir(oldDir); // change back to original 107 | } 108 | } 109 | return temp; // return whole tree 110 | } 111 | } 112 | 113 | /** 114 | * Used by Jshell interface to execute the above methods 115 | * 116 | */ 117 | public void execute(Directory dir, String input, Stack Holder) { 118 | if (input.trim().length() < 3) { 119 | System.out.println("Not valid input. There are no arguments"); 120 | } else { 121 | String[] paths = input.substring(3).trim().split("\\s+"); // get array of 122 | // paths 123 | Cp.CopyDir(dir, paths); 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/commands/Exit.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package commands; 32 | 33 | import java.util.Stack; 34 | 35 | import helpers.Directory; 36 | 37 | /** 38 | * Class Name: Exit, Exits out of the Jshell 39 | */ 40 | public class Exit implements CommandInterface { 41 | 42 | /** 43 | * Checks if the current input is equal to exit 44 | * 45 | * @param input 46 | * @return boolean 47 | */ 48 | public static boolean checkString(String input) { 49 | return input.trim().equals("exit"); 50 | } 51 | 52 | /** 53 | * Used by Jshell interface to execute the above methods 54 | * 55 | */ 56 | public void execute(Directory dir, String input, Stack Holder) { 57 | Exit.checkString(input); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/commands/Get.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package commands; 32 | 33 | import java.io.IOException; 34 | import java.net.MalformedURLException; 35 | import java.net.URL; 36 | import java.util.Scanner; 37 | import java.util.Stack; 38 | 39 | import exceptions.*; 40 | import helpers.*; 41 | 42 | /** 43 | * Class Name: Get this class gets a text file from a url and adds it to the 44 | * current working directory 45 | */ 46 | public class Get implements CommandInterface { 47 | /** 48 | * Creates a text file from a website url 49 | * 50 | * @param input Single string of the user input 51 | * @throws FileDirectoryExistsException 52 | */ 53 | private static void getUrl(Directory dir, String input) 54 | throws FileDirectoryExistsException, MalformedURLException, IOException { 55 | // Trims the input so it is only a url 56 | input = input.trim().substring(3).trim(); 57 | Echo e = new Echo(); 58 | URL url; 59 | String fileName = SplitPaths.pathSplit(input)[1]; // Gets file name 60 | url = new URL(input); 61 | Scanner s = new Scanner(url.openStream()); // Opens web page 62 | String content = ""; 63 | 64 | while (s.hasNext()) { 65 | content = content + s.nextLine() + "\n"; // Appends contents 66 | } 67 | // Adds file to current directory 68 | e.execute(dir, "echo \"" + content + "\" > " + fileName, null); 69 | s.close(); // Closes scanner 70 | } 71 | 72 | 73 | /** 74 | * Used by Jshell interface to execute the above methods 75 | * 76 | */ 77 | public void execute(Directory dir, String input, Stack Holder) { 78 | try { 79 | getUrl(dir, input); 80 | } catch (FileDirectoryExistsException e1) { 81 | System.out.println( 82 | "echo: cannot create file '" + e1.getError() + "': Directory exists"); 83 | } catch (MalformedURLException e2) { // Invalid url 84 | System.out.println("get: " + e2.getMessage() + ": url not found"); 85 | } catch (IOException e3) { // Invalid syntax 86 | System.out.println("get: " + e3.getMessage() + ": invalid syntax"); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/commands/Grep.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package commands; 32 | 33 | import java.util.List; 34 | import java.util.Stack; 35 | import java.util.regex.Pattern; 36 | import helpers.Directory; 37 | import helpers.File; 38 | import helpers.Pathchecker; 39 | import helpers.SplitPaths; 40 | import helpers.Tree; 41 | 42 | // TODO: Auto-generated Javadoc 43 | /** 44 | * The Class Grep. 45 | */ 46 | public class Grep implements CommandInterface { 47 | 48 | /** The counter. */ 49 | private static int counter = 0; 50 | 51 | /** 52 | * Find regex.Finds the strings that contain the given regular expression 53 | * 54 | * @param directory the directory 55 | * @param input the input 56 | * @return the string 57 | */ 58 | public static String findRegex(Directory directory, String input) { 59 | String finalLines = ""; 60 | String[] arguments = input.trim().split("\\s+"); 61 | String regex = arguments[0]; 62 | // String path = arguments[1]; 63 | if (!Pathchecker.pathCheck(directory, arguments[1])) 64 | return "Invalid path, please try again"; // If file path is incorrect 65 | String[] output = SplitPaths.pathSplit(arguments[1]); 66 | if (directory.peekType(output[1]).equals("File")) { 67 | if (!Pwd.printDir(directory).endsWith("/")) { 68 | finalLines = Pwd.printDir(directory) + "/" + output[1].trim() + ":"; 69 | } else { 70 | finalLines = Pwd.printDir(directory) + output[1].trim() + ":"; 71 | } 72 | File file = (File) directory.getChild(output[1]); 73 | String[] array = file.getContent().trim().split("\n"); 74 | for (String currentLine : array) { 75 | if (Grep.isRegex(currentLine, regex)) { 76 | while (counter > 0) { 77 | finalLines += "\n" + currentLine; 78 | counter = counter - 1; 79 | } 80 | } 81 | } 82 | } 83 | return finalLines; 84 | } 85 | 86 | 87 | /** 88 | * Recursive regex. 89 | * 90 | * @param dir the dir 91 | * @param input the input 92 | */ 93 | private static void recursiveRegex(Directory dir, String input) { 94 | String[] arguments = input.trim().split("\\s+"); 95 | String regex = arguments[0]; 96 | String[] children = dir.getContents().trim().split("\\s+"); 97 | if (dir.getContents().trim() == "") {// Base Case(directory has no children) 98 | // Stop recursion 99 | } else { 100 | for (String child : children) { 101 | if (dir.peekType(child).equals("Folder")) {// recursive only if folder** 102 | String dirHolder = dir.workingDir(); 103 | Cd.switchDir(dir, child); 104 | recursiveRegex(dir, input); 105 | dir.changeCurrentDir(dirHolder); 106 | } else { 107 | if (Pwd.printDir(dir).equals("/")) { 108 | System.out.println( 109 | findRegex(dir, regex + " " + Pwd.printDir(dir) + child)); 110 | } else { 111 | System.out.println( 112 | findRegex(dir, regex + " " + Pwd.printDir(dir) + "/" + child)); 113 | } 114 | } 115 | } 116 | } 117 | } 118 | 119 | /** 120 | * Checks if is regex. 121 | * 122 | * @param input the input 123 | * @param regex the regex 124 | * @return true, if is regex 125 | */ 126 | private static boolean isRegex(String input, String regex) { 127 | Pattern pattern = Pattern.compile(regex); 128 | java.util.regex.Matcher matcher = pattern.matcher(input); 129 | while (matcher.find()) { 130 | counter += 1; 131 | } 132 | if (counter >= 1) { 133 | return true; 134 | } else { 135 | return false; 136 | } 137 | } 138 | 139 | /** 140 | * Used by Jshell interface to execute the above methods 141 | * 142 | */ 143 | @Override 144 | public void execute(Directory dir, String input, Stack holder) { 145 | input = input.substring(4); 146 | String path[] = input.trim().split("\\s+"); 147 | for (int currentPath = 1; currentPath < path.length; currentPath++) { 148 | if (path.length < 2) { 149 | System.out.println("Incorrect input, Missing path or regex"); 150 | } else if (!path[0].contains("-R") && !path[0].contains("-r")) { 151 | input = path[0] + " " + path[currentPath]; 152 | System.out.println(findRegex(dir, input)); 153 | } else { 154 | if (path[currentPath].equals("-R") || path[currentPath].equals("-r")) { 155 | } else if (path[currentPath].endsWith(".txt") 156 | || path[currentPath].endsWith(".html")) { 157 | System.out.println("Please specify directory, not file path"); 158 | } else if (currentPath == 1) { 159 | } else { 160 | input = input.trim().substring(2) + path[currentPath]; 161 | String dirHolder = dir.workingDir(); 162 | Cd.switchDir(dir, path[currentPath]); 163 | recursiveRegex(dir, input); 164 | dir.changeCurrentDir(dirHolder); 165 | } 166 | } 167 | } 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/commands/History.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | 32 | package commands; 33 | 34 | import java.util.*; 35 | import java.util.regex.Matcher; 36 | import java.util.regex.Pattern; 37 | 38 | import helpers.Directory; 39 | 40 | /** 41 | * Class Name: History This class holds methods that show the history of 42 | * previous typed commands 43 | */ 44 | public class History implements CommandInterface { 45 | // The stack that holds all of the commands 46 | private static Stack historyHolder; 47 | // The number of items the user wants to see(Optional parameter) 48 | private static int numOfitems; 49 | 50 | /** 51 | * This method prints out all of the commands in the history stack 52 | * 53 | * @param Itemholder, the stack in which all commands are stored 54 | * @return finalOutput, a string 55 | */ 56 | public static String showStack(Stack Itemholder) { 57 | historyHolder = Itemholder; 58 | int initialSize = historyHolder.size(); 59 | String finalOutput = ""; 60 | if (historyHolder.size() == 0) { 61 | } 62 | // Iterates through stack to print each element in it 63 | for (int element = 0; element < initialSize; element++) { 64 | if (element != initialSize - 1) { 65 | finalOutput += 66 | (element + 1) + " " + historyHolder.elementAt(element) + "\n"; 67 | } else { 68 | finalOutput += (element + 1) + " " + historyHolder.elementAt(element); 69 | } 70 | } 71 | return finalOutput; 72 | } 73 | 74 | // Prints all n-Number of items 75 | /** 76 | * This method Prints all n-Number of items specified by user 77 | * 78 | * @param Itemholder, the stack in which all commands are stored 79 | * @param items 80 | * @return finalOutput, a string 81 | */ 82 | public static String showStack(Stack Itemholder, int items) { 83 | historyHolder = Itemholder; 84 | numOfitems = items; 85 | String finalOutput = ""; 86 | int numOfPops = historyHolder.size() - numOfitems; 87 | int initialSize = historyHolder.size(); 88 | // Checks if n items specified by user is less than 0 89 | if (numOfitems < 0) { 90 | return "History out of Bounds"; 91 | } 92 | // Checks if n items specified by user is greater then length of the stack 93 | else if (numOfPops < 0) { 94 | return showStack(Itemholder); 95 | } 96 | // Iterates through stack to print n-number of items requested by user 97 | else { 98 | for (int item = numOfPops; item < initialSize; item++) { 99 | if (item != initialSize - 1) { 100 | finalOutput += 101 | (item + 1) + " " + historyHolder.elementAt(item) + "\n"; 102 | } else { 103 | finalOutput += (item + 1) + " " + historyHolder.elementAt(item); 104 | } 105 | } 106 | return finalOutput; 107 | } 108 | } 109 | 110 | /** 111 | * Used by Jshell interface to execute the above methods 112 | */ 113 | public void execute(Directory dir, String input, Stack Holder) { 114 | String output = ""; 115 | Pattern pattern = Pattern.compile( 116 | "(\\s*)^(history)(\\s+)" 117 | + "((>>|>)(\\s+)([^!@$\\&*()?:\\[\\]\"\\<\\>'`|={}\\;]+))", 118 | Pattern.DOTALL); // Includes \n in STRING 119 | Matcher matcher = pattern.matcher(input); 120 | if (matcher.matches()) { 121 | Echo e = new Echo(); 122 | output = History.showStack(Holder); 123 | String file = "echo \"" + output + "\" " + matcher.group(4); 124 | e.execute(dir, file, null); 125 | } else { 126 | String input1 = input; 127 | input1 = input1.trim().substring(7).trim(); 128 | if (input1.contains(" ")) { 129 | output = "history: too many arguments"; 130 | } else { 131 | String temp[] = input.split(" "); 132 | if (temp.length == 1) { 133 | output = History.showStack(Holder); 134 | } else { 135 | output = History.showStack(Holder, Integer.parseInt(temp[1])); 136 | } 137 | } 138 | System.out.println(output); 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/commands/Ls.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package commands; 32 | 33 | import java.util.Stack; 34 | 35 | import helpers.Directory; 36 | 37 | /** 38 | * Class Name: Ls This class prints out the contents of the current directory or 39 | * specified one. 40 | */ 41 | public class Ls implements CommandInterface { 42 | 43 | /** 44 | * Checks contents of a relative path(directory). Returns error if path does 45 | * not exist 46 | * 47 | * @param explorer, holds the series of directories 48 | * @param input, the directory to be checked 49 | * @return contents, the contents of the current directory 50 | */ 51 | public static String listDir(Directory explorer, String input) { 52 | String contents = "";// final string holder 53 | String oldDir = explorer.workingDir();// to roll back on directory 54 | if (input.contentEquals("")) {// single ls 55 | contents = Pwd.printDir(explorer) + ":" 56 | + explorer.rawWorkingDir().getChildren() + "\n"; 57 | return contents;// return string for testing 58 | } 59 | String path[] = null; 60 | if (input.startsWith("/")) { 61 | path = input.trim().substring(1).split("/"); // Trims the input 62 | explorer.changeCurrentDir("/"); 63 | } else { 64 | path = input.trim().split("/"); // Trims the input 65 | } 66 | boolean con = true;// directory we are looking for is child of current 67 | for (int i = 0; i < path.length - 1 && con; i++) { // go to path 68 | if (!path[i].contentEquals("")) {// ignore empty strings 69 | con = explorer.cdOneDown(path[i]); 70 | } 71 | } 72 | if (con 73 | && explorer.peekType(path[path.length - 1]).contentEquals("Folder")) { 74 | explorer.cdOneDown(path[path.length - 1]);// go into last folder 75 | contents = Pwd.printDir(explorer) + ":" 76 | + explorer.rawWorkingDir().getChildren() + "\n"; 77 | } else if (con && explorer.checkDir(path[path.length - 1])) {// its a file 78 | contents = path[path.length - 1]; 79 | } else if (!explorer.checkDir(path[path.length - 1])) {// not found 80 | contents = "ls: cannot access " + input + ": No such file or directory"; 81 | } 82 | explorer.changeCurrentDir(oldDir);// go back to original directory 83 | return contents; 84 | } 85 | 86 | /** 87 | * Checks contents of a relative or absolute path and its lists all of its 88 | * subdirectories recuirsively. Returns error if path does not exist 89 | * 90 | * @param dir, holds the series of directories 91 | * @return 92 | */ 93 | public static String recursivelyListAllDir(Directory dir) { 94 | String finalOutput= listDir(dir, ""); // Prints current directory 95 | if (dir.getContents().trim() == "") {// Base Case(directory has no children) 96 | // Stop recursion 97 | } else { // Goes through each childs subdirectories recursively 98 | String[] children = dir.getContents().trim().split("\\s+"); 99 | for (String child : children) { 100 | if (dir.peekType(child).equals("Folder")) {// recursive only if folder** 101 | String dirHolder = dir.workingDir(); 102 | Cd.switchDir(dir, child); 103 | finalOutput += "\n"+recursivelyListAllDir(dir); 104 | dir.changeCurrentDir(dirHolder); 105 | } 106 | } 107 | } 108 | return finalOutput; 109 | } 110 | 111 | /** 112 | * Used by Jshell interface to execute the above methods 113 | * 114 | */ 115 | public void execute(Directory dir, String input, Stack Holder) { 116 | input = input.trim().substring(2); 117 | String path[] = input.trim().split("\\s+"); 118 | for (String paths : path) { 119 | if (!path[0].contains("-R") && !path[0].contains("-r")) { 120 | System.out.println(listDir(dir, paths)); 121 | } else { 122 | if (path.length < 2) { 123 | System.out.println(recursivelyListAllDir(dir)); 124 | } else { 125 | if (paths.equals("-R") || paths.equals("-r")) { 126 | } else if (dir.peekType(paths).equals("File")) { 127 | System.out.println(paths); 128 | } else { 129 | String dirHolder = dir.workingDir(); 130 | Cd.switchDir(dir, paths); 131 | System.out.println(recursivelyListAllDir(dir)); 132 | dir.changeCurrentDir(dirHolder); 133 | } 134 | } 135 | } 136 | } 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/commands/Mkdir.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package commands; 32 | 33 | import java.util.Stack; 34 | 35 | import helpers.Directory; 36 | import helpers.FormatMe; 37 | import helpers.PathWalker; 38 | import helpers.Tree; 39 | 40 | /** 41 | * Class Name: Mkdir This class navigates through the directories and creates a 42 | * folder or creates a folder in the current directory. 43 | */ 44 | public class Mkdir implements CommandInterface { 45 | /** 46 | * Creates a specified directory. Returns error if path does not exist or if 47 | * directory already there. 48 | * 49 | * @param files, holds the series of directories that newDir needs to be 50 | * inserted into. 51 | * @param dir, the directory to be inserted, also can be a path of folders. 52 | */ 53 | private static void makeDir(Directory files, String dir) { 54 | String oldDir = files.workingDir();// for switching back 55 | boolean inDir = true; 56 | String newDir = ""; 57 | 58 | if (dir.lastIndexOf("/") > 0) { 59 | newDir = dir.trim().substring(dir.lastIndexOf("/") + 1); 60 | String path = dir.trim().substring(0, dir.lastIndexOf("/")); 61 | inDir = PathWalker.goToPath(files, path); 62 | } else { 63 | if (dir.startsWith("/")) { 64 | newDir = dir.trim().substring(1); 65 | files.changeCurrentDir("/"); 66 | } else { 67 | newDir = dir.trim(); 68 | } 69 | } 70 | if (!files.checkDir(newDir) && inDir) {// path does not exist 71 | Tree insert = new Tree(newDir); 72 | files.insertMe(insert, files.rawWorkingDir()); 73 | } else if (files.checkDir(newDir) && inDir) { // path exists 74 | System.out 75 | .println("mkdir: cannot create directory '" + dir + "': File exists"); 76 | } else if (!inDir) { 77 | System.out.println("mkdir: no such directory"); 78 | } 79 | files.changeCurrentDir(oldDir);// change back to the old directory 80 | } 81 | 82 | /** 83 | * Used by Jshell interface to execute the above methods 84 | * 85 | */ 86 | public void execute(Directory dir, String input, Stack Holder) { 87 | String[] path = FormatMe.cutDirMkdir(input); // get array of paths 88 | if (path != null && !input.trim().contentEquals("")) {// check for errors 89 | for (int i = 0; i < path.length; i++) {// go through all the paths 90 | makeDir(dir, path[i]); 91 | } 92 | } else { 93 | System.out.println("mkdir: Invalid input try again."); 94 | } 95 | } 96 | 97 | } 98 | 99 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/commands/Mv.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | package commands; 31 | 32 | import helpers.Directory; 33 | import helpers.File; 34 | import helpers.PathWalker; 35 | import helpers.Tree; 36 | 37 | import java.util.List; 38 | import java.util.Stack; 39 | 40 | public class Mv extends Cp { 41 | 42 | /** 43 | * Deletes the target path from the tree of directories. 44 | * 45 | * @param explorer, holds the series of directories 46 | * 47 | * @param input, holds the initial path marked for deletion 48 | */ 49 | private void delPath(Directory explorer, String input) { 50 | String initialDir = Pwd.printDir(explorer); // original directory 51 | if (PathWalker.goToPath(explorer, input)) { // if its a path go to it 52 | if (!explorer.workingDir().contentEquals("/")) { // cannot delete root 53 | Tree object = explorer.rawWorkingDir(); // path to be deleted 54 | explorer.changeCurrentDir(explorer.getParentDir()); // go up 55 | explorer.getRawChildren().remove(object);// remove from children list 56 | } 57 | } 58 | if (input.contains("/")) {// if its a path and was not able to go into it 59 | input = input.substring(0, input.lastIndexOf("/")); 60 | PathWalker.goToPath(explorer, input); 61 | } 62 | List objects = explorer.getRawChildren();// list all sub-directories 63 | for (int i = 0; i < objects.size(); i++) {// for every directory in sub 64 | if (((Tree) objects.get(i)).getRawItems() instanceof File) { 65 | if (((File) ((Tree) objects.get(i)).getRawItems()).getFileName() 66 | .equals(input)) { 67 | explorer.getRawChildren().remove(objects.get(i)); // remove it 68 | } 69 | } 70 | } 71 | PathWalker.goToPath(explorer, initialDir); // go back to original path 72 | } 73 | 74 | /** 75 | * Used by Jshell interface to execute the above methods 76 | * 77 | */ 78 | public void execute(Directory dir, String input, Stack Holder) { 79 | if (input.trim().length() < 3) { 80 | System.out.println("Not valid input. There are no arguments"); 81 | } else { 82 | String[] paths = input.substring(3).trim().split("\\s+"); // get array of 83 | // paths 84 | if (CopyDir(dir, paths)) {// copy the indicated directories or files 85 | delPath(dir, paths[0]); // delete the initial directories or files 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/commands/Number.java: -------------------------------------------------------------------------------- 1 | package commands; 2 | 3 | import java.util.Stack; 4 | 5 | import helpers.Directory; 6 | import helpers.Reflection; 7 | 8 | // TODO: Auto-generated Javadoc 9 | /** 10 | * The Class Number is used to recall previous commands. 11 | */ 12 | public class Number implements CommandInterface { 13 | 14 | /** 15 | * Recall previous command that has has been stored in History and invokes it 16 | * 17 | * @param dir the dir 18 | * @param input the input 19 | * @param history the history 20 | * @return the string 21 | */ 22 | public static String recallCommand(Directory dir, String input, 23 | Stack history) { 24 | int commandNumber = Integer.parseInt(input); 25 | Stack holder = history; 26 | if (!(commandNumber >= history.size()) && !(commandNumber <= 0)) { 27 | Stack itemHolder = new Stack(); 28 | // Places items from history stack into a holder stack 29 | while (history.size() != commandNumber) { 30 | itemHolder.push(history.pop()); 31 | } 32 | String topStack = (String) history.peek(); // Item on top of the stack 33 | if (helpers.InputParser.validate(topStack)) { // checks if item is valid 34 | Reflection.execute(dir, topStack, holder); 35 | } else if (topStack.startsWith("!")) { 36 | input = "Number " + input; 37 | helpers.Reflection.execute(dir, input, holder); 38 | } else { 39 | for (int command = 0; command < itemHolder.size(); command++) { 40 | history.push(itemHolder.pop()); 41 | } 42 | return "Invalid input! Please try again"; 43 | } 44 | // Puts everything back into the history stack 45 | for (int command = 0; command < itemHolder.size(); command++) { 46 | history.push(itemHolder.pop()); 47 | } 48 | return ""; 49 | } else { 50 | return "Error out of bounds"; 51 | } 52 | } 53 | 54 | /** 55 | * Used by Jshell interface to execute the above methods 56 | * 57 | */ 58 | public void execute(Directory dir, String input, Stack holder) { 59 | input = input.replaceAll("\\D+", ""); 60 | System.out.println(recallCommand(dir, input, holder)); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/commands/Popd.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package commands; 32 | 33 | import java.util.Stack; 34 | 35 | import helpers.Directory; 36 | 37 | /** 38 | * Class Name: Popd This class holds methods removes the top entry from the 39 | * directory stack, and cd into it. 40 | */ 41 | public class Popd implements CommandInterface { 42 | 43 | /** 44 | * Checks if there is a directory in the stack and cd's into it. 45 | * 46 | * @param explorer the explorer 47 | */ 48 | public static void popd(Directory explorer) { 49 | if (Pushd.getStack().size() > 0) { 50 | explorer.changeCurrentDir("/"); 51 | Cd.switchDir(explorer, (String) Pushd.getStack().pop()); 52 | } else { 53 | System.out.println("popd: directory stack empty"); 54 | } 55 | 56 | } 57 | 58 | /** 59 | * Used by Jshell interface to execute the above methods 60 | * 61 | */ 62 | public void execute(Directory dir, String input, Stack Holder) { 63 | popd(dir); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/commands/Pushd.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package commands; 32 | 33 | import java.util.Stack; 34 | 35 | import helpers.Directory; 36 | 37 | 38 | /** 39 | * Class Name: Pushd This class pops the directory that is stored in the stack 40 | * and changes the working directory to that directory. 41 | */ 42 | public class Pushd implements CommandInterface { 43 | 44 | /** The holder. */ 45 | private static Stack holder = new Stack(); 46 | 47 | /** 48 | * Pushd. 49 | * 50 | * @param explorer the explorer 51 | * @param dir the dir 52 | * @return 53 | */ 54 | public static String pushd(Directory explorer, String dir) { 55 | String temp = Pwd.printDir(explorer); 56 | String path[] = dir.trim().split("/"); 57 | for (int i = 0; i < path.length; i++) { 58 | if (explorer.cdOneDown(path[i])) { 59 | holder.push(temp); 60 | } else { 61 | return "pushd: " + dir + ": No such file or directory"; 62 | } 63 | } 64 | return ""; 65 | } 66 | 67 | /** 68 | * Gets the stack. 69 | * 70 | * @return the stack 71 | */ 72 | public static Stack getStack() { 73 | return holder; 74 | } 75 | 76 | /** 77 | * Used by Jshell interface to execute the above methods 78 | * 79 | */ 80 | public void execute(Directory dir, String input, Stack Holder) { 81 | input = input.substring(5).trim(); 82 | System.out.println(pushd(dir, input)); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/commands/Pwd.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package commands; 32 | 33 | import java.util.Stack; 34 | import java.util.regex.Matcher; 35 | import java.util.regex.Pattern; 36 | 37 | import helpers.Directory; 38 | 39 | /** 40 | * Class Name: Pwd This class holds methods to show the current directories 41 | * path. 42 | */ 43 | public class Pwd implements CommandInterface { 44 | 45 | // Holds the current file path 46 | private Pwd getFilePath; 47 | 48 | /** 49 | * 50 | * @param explorer 51 | * @return "/" if we are in root, else find the path of current dir and return 52 | * it 53 | * 54 | * @return printDir, string of the current working directory 55 | */ 56 | public static String printDir(Directory directory) { 57 | String printDir = ""; 58 | printDir = directory.workingDir() + "/"; 59 | if (directory.workingDir() == "/") { 60 | // Checks if the working directory is the root of the tree 61 | return "/"; 62 | } else { 63 | while (directory.getParentDir() != "/") { 64 | // Goes through the loop until the root directory is found 65 | printDir = directory.getParentDir() + "/" + printDir; 66 | // Concatenates the string name of all directories in to a string 67 | directory.changeCurrentDir(directory.getParentDir()); 68 | // Makes the current directory the parent directory 69 | } 70 | } 71 | directory.changeCurrentDir(directory.getParentDir()); 72 | printDir = printDir.substring(0, printDir.length() - 1); 73 | printDir = "/" + printDir; 74 | Cd.switchDir(directory, printDir); 75 | // Reverts the current directory to the directory before the 76 | // function was called 77 | return printDir; 78 | 79 | } 80 | 81 | public void execute(Directory dir, String input, Stack Holder) { 82 | String output = ""; 83 | Pattern pattern = Pattern.compile( 84 | "(\\s*)^(pwd)(\\s+)" 85 | + "((>>|>)(\\s+)([^!@$\\&*()?:\\[\\]\"\\<\\>'`|={}\\;]+))", 86 | Pattern.DOTALL); // Includes \n in STRING 87 | Matcher matcher = pattern.matcher(input); 88 | if (matcher.matches()) { 89 | Echo e = new Echo(); 90 | output = printDir(dir); 91 | String file = "echo \"" + output + "\" " + matcher.group(4); 92 | e.execute(dir, file, null); 93 | } else if (input.split("\\s+").length == 1) { 94 | input = input.trim().substring(3); 95 | System.out.println(printDir(dir)); 96 | } else { 97 | System.out.println("pwd: error: invalid arguments"); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/driver/JShell.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | package driver; 31 | 32 | import java.io.*; 33 | import java.util.*; 34 | 35 | import helpers.*; 36 | 37 | /** 38 | * Class Name: JShell This class captures the input and based on it executes the 39 | * proper class or sends an error if. 40 | */ 41 | public class JShell { 42 | public static void main(String[] args) throws IOException { 43 | BufferedReader objReader = 44 | new BufferedReader(new InputStreamReader(System.in)); 45 | Stack holder = new Stack(); // Stack for history 46 | String input = ""; // First input 47 | Directory dir = new Directory(); 48 | // Exits if "exit" is inputed by the user 49 | while (!commands.Exit.checkString(input)) { 50 | System.out.print("/# "); // Path 51 | input = objReader.readLine().trim();// Input 52 | if (!input.isEmpty()) { // Creates a stack that holds all user input 53 | holder.push(input); 54 | } 55 | String command[] = input.trim().split("\\s+");// Splits the string 56 | // Checks if the command is valid 57 | if (input.isEmpty()) { // Does nothing if user input is empty 58 | } else if (InputParser.validate(command[0]) && !command[0].equals("echo") 59 | && (input.contains(">") || input.contains(">>"))) { 60 | StdOutput.stdOutput(dir, input, holder); 61 | } else if (input.matches("![0-9]+")) { 62 | input = "Number " + input; 63 | helpers.Reflection.execute(dir, input, holder); 64 | } else if (InputParser.validate(input)) { // Checks validity of path 65 | helpers.Reflection.execute(dir, input, holder); 66 | } else { 67 | System.out.println("Invalid input! Please try again"); 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/exceptions/FileDirectoryExistsException.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package exceptions; 32 | 33 | 34 | /** 35 | * Class Name: FileDirectoryExistsException is an exception class when a file or 36 | * directory is trying to be created when the same directory or file with the 37 | * same name exists. 38 | */ 39 | public class FileDirectoryExistsException extends Exception { 40 | 41 | /** The error. */ 42 | private String error = ""; 43 | 44 | /** 45 | * Instantiates a new file directory exists exception. 46 | * 47 | * @param input the input 48 | */ 49 | public FileDirectoryExistsException(String input) { 50 | this.error = input; 51 | } 52 | 53 | /** 54 | * Gets the error. 55 | * 56 | * @return the error 57 | */ 58 | public String getError() { 59 | return this.error; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/exceptions/InvalidSyntaxException.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package exceptions; 32 | 33 | 34 | /** 35 | * Class Name: InvalidSyntaxException is an exception class when invalid syntax 36 | * is used as input. 37 | */ 38 | public class InvalidSyntaxException extends Exception { 39 | 40 | /** The error. */ 41 | private String error = ""; 42 | 43 | /** 44 | * Instantiates a new invalid syntax exception. 45 | * 46 | * @param input the input 47 | */ 48 | public InvalidSyntaxException(String input) { 49 | this.error = input; 50 | } 51 | 52 | /** 53 | * Gets the error. 54 | * 55 | * @return the error 56 | */ 57 | public String getError() { 58 | return this.error; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/helpers/File.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package helpers; 32 | 33 | /** 34 | * Class Name: File, 35 | * This class holds the file name and its contents and returns them at command. 36 | */ 37 | public class File { 38 | 39 | /** The file name. */ 40 | private String fileName = ""; 41 | 42 | /** The content. */ 43 | private String content = ""; 44 | 45 | /** 46 | * Constructs the file object. 47 | * 48 | * @param newFile the name of the file 49 | * @param newContent the content of the file 50 | */ 51 | public File(String newFile, String newContent) { 52 | this.fileName = newFile; 53 | this.content = newContent; 54 | } 55 | 56 | /** 57 | * Sets the fileName of the file. 58 | * 59 | * @param file the new fileName to be replaced 60 | */ 61 | public void setFileName(String file) { 62 | this.fileName = file; 63 | } 64 | 65 | /** 66 | * Sets the content of the file. 67 | * 68 | * @param set the new content to be rewritten 69 | */ 70 | public void setContent(String set) { 71 | this.content = set; 72 | } 73 | 74 | /** 75 | * Gets the file name. 76 | * 77 | * @return fileName, Returns the file's name 78 | */ 79 | public String getFileName() { 80 | return fileName; 81 | } 82 | 83 | /** 84 | * Gets the content. 85 | * 86 | * @return content, Returns the file's content 87 | */ 88 | public String getContent() { 89 | return content; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/helpers/FileExists.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package helpers; 32 | 33 | import java.util.List; 34 | 35 | /** 36 | * Class Name: FileExists, 37 | * Checks if a file is present in the current directory. 38 | */ 39 | public class FileExists { 40 | 41 | /** 42 | * Checks if the file exists in the tree. 43 | * 44 | * @param directory Navigates through the current directory 45 | * @param fileName The file name that will be searched for 46 | * @return exists Returns a boolean of whether the file exists or not 47 | */ 48 | public static boolean getFileExists(Directory directory, String fileName) { 49 | boolean exists = false; // Files doesn't exist by default 50 | // Gets the objects in the current directory 51 | List files = directory.rawWorkingDir().getRawChildren(); 52 | // Loops through data 53 | for (int data = 0; data < files.size(); data++) { 54 | // Finds a File object 55 | if (files.get(data).getRawItems() instanceof File) { 56 | File current = (File) files.get(data).getRawItems(); 57 | // File exists if the filename is the same as specified 58 | if (current.getFileName().equals(fileName)) { 59 | exists = true; 60 | } 61 | } 62 | } 63 | return exists; // Returns whether the file exists or not 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/helpers/FormatMe.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package helpers; 32 | 33 | /** 34 | * Class Name: FormatMe, 35 | * Provides format for the raw input string, giving errors for incorrect 36 | * characters. 37 | */ 38 | public class FormatMe { 39 | 40 | /** 41 | * Checks if the input string contains invalid directory characters. Returns 42 | * true if string is valid false otherwise. 43 | * 44 | * @param input the input 45 | * @return boolean 46 | */ 47 | public static boolean testDirString(String input) { 48 | String invalidChars = "!@$&*()?:[]\"<>\'`|={}\\,;";// invalid chars 49 | for (int i = 0; i < 23; i++) {// loop through all invalid 50 | if (input.contains("" + invalidChars.charAt(i))) { 51 | System.out.println("Directory Includes Invalid Character(s): " 52 | + invalidChars.charAt(i)); 53 | return false;// error occurred 54 | } else if (input.contains(".") && !input.contains("/")) { 55 | System.out.println("Directory Includes Invalid Character(s): ."); 56 | return false;// invalid character can imply up one directory 57 | } 58 | } 59 | return true; 60 | } 61 | 62 | /** 63 | * Cuts the input string up specific to the MkDir function Returns an array of 64 | * directories or an array of null if error occured. 65 | * 66 | * @param input string of raw input from Jshell. 67 | * @return path, empty 68 | */ 69 | public static String[] cutDirMkdir(String input) { 70 | input = input.trim().substring(5);// cut mkdir out 71 | if (FormatMe.testDirString(input)) {// check for invalid characters 72 | String path[] = input.trim().split("\\s+");// split paths 73 | return path;// send back 74 | } 75 | return null;// error occurred sending back null 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/helpers/InputParser.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package helpers; 32 | 33 | import java.util.Hashtable; 34 | 35 | /** 36 | * Class Name: InputParser, 37 | * Checks if input is valid or invalid. 38 | */ 39 | public class InputParser { 40 | 41 | /** 42 | * Validates if the given input by the user and checks if it is correct 43 | * 44 | * @param input the input given to JShell 45 | * @return true, if the given input is an valid input 46 | */ 47 | public static boolean validate(String input) { 48 | final int dataCap = Integer.MAX_VALUE; 49 | Hashtable classes = new Hashtable(); 50 | classes.put("mkdir", dataCap); 51 | classes.put("grep", dataCap); 52 | classes.put("cd", 2); 53 | classes.put("ls", dataCap); 54 | classes.put("pwd", 3); 55 | classes.put("pushd", 2); 56 | classes.put("popd", 1); 57 | classes.put("history", 3); 58 | classes.put("cat", dataCap); 59 | classes.put("echo", dataCap); 60 | classes.put("man", 2); 61 | classes.put("exit", 1); 62 | classes.put("mv", dataCap); 63 | classes.put("cp", dataCap); 64 | classes.put("get", 2); 65 | String temp[] = input.trim().split("\\s+"); 66 | if (classes.get(temp[0]) != null 67 | && classes.get(temp[0]) > (temp.length - 1)) { 68 | return true; 69 | } 70 | return false; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/helpers/PathWalker.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package helpers; 32 | 33 | /** 34 | * The Class PathWalker. 35 | */ 36 | public class PathWalker { 37 | 38 | /** 39 | * Goes to path regardless of the absolute or regular path. 40 | * 41 | * @param explorer the explorer 42 | * @param path the path 43 | * @return true, if successful 44 | */ 45 | public static boolean goToPath(Directory explorer, String path) { 46 | 47 | if (!Pathchecker.pathCheck(explorer, path) && !path.equals("/")) { 48 | return false; 49 | } 50 | // System.out.println("This is printing" +path.startsWith("/")); 51 | if (path.startsWith("/")) {// absolute path 52 | // System.out.println( "This is printing"); 53 | explorer.changeCurrentDir("/"); 54 | 55 | } 56 | String path1[] = path.trim().split("/"); 57 | for (int i = 0; i < path1.length; i++) {// go through all the direct 58 | if (path1[i].contentEquals("..") 59 | && !explorer.workingDir().contentEquals("/")) { 60 | explorer.changeCurrentDir(explorer.getParentDir()); 61 | } else if (path1[i].contentEquals(".")) { 62 | return true; 63 | 64 | } else if (!path1[i].contentEquals("")) {// go into path 65 | explorer.cdOneDown(path1[i]); 66 | } 67 | } 68 | return true; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/helpers/Pathchecker.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package helpers; 32 | 33 | import commands.Cd; 34 | import commands.Mkdir; 35 | 36 | /** 37 | * The Class Pathchecker. 38 | */ 39 | public class Pathchecker { 40 | 41 | /** 42 | * Pathcheck. Returns true if the given relative or absolute file path is 43 | * correct,false otherwise 44 | * 45 | * @param explorer is the directory the file path exists in 46 | * @param input the relative or absolute file path 47 | * @return boolean, returns true if the file path that was given is correct 48 | */ 49 | public static boolean pathCheck(Directory explorer, String input) { 50 | String dirHolder = explorer.workingDir(); // holds current directory 51 | if (input == "/") { 52 | return true; 53 | } 54 | if (input.startsWith("/")) { // checks if path is absolute or relative 55 | String temp[] = input.trim().substring(1).split("/"); 56 | explorer.changeCurrentDir("/"); 57 | for (int x = 0; x < temp.length; x++) { // Iterates through path if valid 58 | if (!explorer.checkDir(temp[x])) { 59 | explorer.changeCurrentDir(dirHolder); 60 | return false; 61 | } 62 | if (explorer.peekType(temp[x]).equals("File")) { 63 | return true; 64 | } 65 | Cd.switchDir(explorer, temp[x]); 66 | } 67 | } else { // This only occurs if path is not absolute 68 | String temp[] = input.trim().split("/"); 69 | for (int x = 0; x < temp.length; x++) { // Iterates through relative path 70 | if (!explorer.checkDir(temp[x])) { 71 | explorer.changeCurrentDir(dirHolder); 72 | return false; // If path is not found return false 73 | } 74 | if (explorer.peekType(temp[x]).equals("File")) { 75 | return true; 76 | } 77 | Cd.switchDir(explorer, temp[x]); 78 | } 79 | } 80 | explorer.changeCurrentDir(dirHolder); // If path is found return true 81 | return true; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/helpers/Reflection.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package helpers; 32 | 33 | import java.lang.reflect.InvocationTargetException; 34 | import java.lang.reflect.Method; 35 | import java.util.Stack; 36 | 37 | /** 38 | * The Class Reflection. 39 | */ 40 | public class Reflection { 41 | 42 | /** 43 | * Turns a user input into a Class object and executes the execute method 44 | * 45 | * @param dir the dir 46 | * @param input the input from the user 47 | * @param holder the holder 48 | */ 49 | public static void execute(Directory dir, String input, Stack holder) { 50 | String command[] = input.trim().split("\\s+"); 51 | // Checks if the command is valid 52 | String userInput = "commands." + command[0].substring(0, 1).toUpperCase() 53 | + command[0].substring(1); 54 | try { 55 | Class classCommand = Class.forName(userInput); 56 | Object obj = classCommand.newInstance(); 57 | classCommand.getClass(); 58 | Method method = classCommand.getDeclaredMethod("execute", dir.getClass(), 59 | userInput.getClass(), holder.getClass()); 60 | method.invoke(obj, dir, input, holder); 61 | } catch (InstantiationException | IllegalAccessException 62 | | ClassNotFoundException | IllegalArgumentException 63 | | InvocationTargetException | NoSuchMethodException 64 | | SecurityException e) { 65 | e.printStackTrace(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/helpers/SplitPaths.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package helpers; 32 | 33 | import commands.Cd; 34 | import commands.Mkdir; 35 | 36 | /** 37 | * Class Name: SplitPaths This class splits up a path into it's constituents a 38 | * directory path and a file ex. /1/2/3/4/5.txt splits into /1/2/3/4/ and 5.txt 39 | */ 40 | public class SplitPaths { 41 | /** 42 | * Processes an input string into their respective files divides it into a 43 | * path and a file 44 | * 45 | * @param path The input that will be processed 46 | * @return output The file path and the file name that will be returned 47 | */ 48 | public static String[] pathSplit(String input) { 49 | int fileSize = input.length(); // Get input's length 50 | // The file name is the last entry of / followed by the rest of the string 51 | String fileName = input.substring(input.lastIndexOf('/') + 1, fileSize); 52 | // The file path is the file name subtracted by the input's length 53 | String path = input.substring(0, fileSize - fileName.length()); 54 | String[] output = {path, fileName}; // Create output array 55 | return output; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/helpers/StdOutput.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package helpers; 32 | 33 | import java.util.List; 34 | import java.util.Stack; 35 | import commands.Cat; 36 | import commands.Echo; 37 | import commands.Grep; 38 | import commands.History; 39 | import commands.Ls; 40 | import commands.Man; 41 | import commands.Pushd; 42 | import commands.Pwd; 43 | 44 | /** 45 | * The Class StdOutput. 46 | * Creates a file for the commands output 47 | */ 48 | public class StdOutput { 49 | 50 | /** 51 | * Std output. Stores the output of commands in a test file 52 | * 53 | * @param dir the directory the function works off of 54 | * @param input the input string 55 | * @param Holder the holder stack 56 | */ 57 | public static void stdOutput(Directory dir, String input, Stack Holder) { 58 | String argument[] = input.trim().split(" "); 59 | String content = ""; 60 | Echo echo = new Echo(); 61 | String redirection = ""; 62 | if(input.contains(">")){ 63 | redirection = " > "; 64 | } 65 | else if(input.contains(">>")){ 66 | redirection = " >> "; 67 | } 68 | if (InputParser.validate(argument[0])) { 69 | if (argument[0].equals("ls")) { 70 | input = formatInput(input).substring(2).trim(); 71 | if (argument[1].equals("-r") || argument[1].equals("-R")) { 72 | input = input.substring(2).trim(); 73 | content = Ls.recursivelyListAllDir(dir); 74 | echo.execute(dir, "echo " + "\"" + content + "\"" + redirection 75 | + argument[argument.length - 1], null); 76 | } else { 77 | content = Ls.listDir(dir, input); 78 | echo.execute(dir, "echo " + "\"" + content + "\"" + redirection 79 | + argument[argument.length - 1], null); 80 | } 81 | } else if (argument[0].equals("man")) { 82 | content = Man.checkString(argument[1]); 83 | echo.execute(dir, "echo " + "\"" + content + "\"" + redirection 84 | + argument[argument.length - 1], null); 85 | } else if (argument[0].equals("cat")) { 86 | input = formatInput(input).substring(3).trim(); 87 | content = Cat.getFileInfo(dir, input); 88 | echo.execute(dir, "echo " + "\"" + content + "\"" + redirection 89 | + argument[argument.length - 1], null); 90 | } else if (argument[0].equals("cp")) { 91 | input = formatInput(input).substring(2).trim(); 92 | content = ""; 93 | echo.execute(dir, "echo " + "\"" + content + "\"" + redirection 94 | + argument[argument.length - 1], null); 95 | } else if (argument[0].equals("grep")) { 96 | input = formatInput(input).substring(4).trim(); 97 | content = Grep.findRegex(dir, input); 98 | echo.execute(dir, "echo " + "\"" + content + "\"" + redirection 99 | + argument[argument.length - 1], null); 100 | } else if (argument[0].equals("history")) { 101 | content = History.showStack(Holder); 102 | echo.execute(dir, "echo " + "\"" + content + "\"" + redirection 103 | + argument[argument.length - 1], null); 104 | } else if (argument[0].equals("popd")) { 105 | content = History.showStack(Holder); 106 | echo.execute(dir, "echo " + "\"" + content + "\"" + redirection 107 | + argument[argument.length - 1], null); 108 | } else if (argument[0].equals("pushd")) { 109 | input = formatInput(input).substring(5).trim(); 110 | content = Pushd.pushd(dir, input); 111 | echo.execute(dir, "echo " + "\"" + content + "\"" + redirection 112 | + argument[argument.length - 1], null); 113 | } else if (argument[0].equals("pwd")) { 114 | input = formatInput(input).substring(3).trim(); 115 | content = Pwd.printDir(dir); 116 | echo.execute(dir, "echo " + "\"" + content + "\"" + redirection 117 | + argument[argument.length - 1], null); 118 | } 119 | else if (argument[0].equals("mkdir")) { 120 | content = ""; 121 | echo.execute(dir, "echo " + "\"" + content + "\"" + redirection 122 | + argument[argument.length - 1], null); 123 | } 124 | else if (argument[0].equals("cd")) { 125 | content = ""; 126 | echo.execute(dir, "echo " + "\"" + content + "\"" + redirection 127 | + argument[argument.length - 1], null); 128 | } 129 | } 130 | } 131 | 132 | 133 | /** 134 | * Format input. 135 | * 136 | * @param input1 the input1 137 | * @return the string 138 | */ 139 | private static String formatInput(String input1) { 140 | String commands[] = input1.trim().split(" "); 141 | int i = 0; 142 | String finalOutput = ""; 143 | while (!commands[i].equals(">>") && !commands[i].equals(">")) { 144 | finalOutput += commands[i] + " "; 145 | i++; 146 | } 147 | return finalOutput; 148 | 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/helpers/Tree.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | package helpers; 31 | 32 | import helpers.File; 33 | import java.util.ArrayList; 34 | import java.util.List; 35 | 36 | // TODO: Auto-generated Javadoc 37 | /** 38 | * Class Name: Tree Operates a tree with nodes holds children parents and items 39 | * of nodes. 40 | * 41 | * @param the generic type 42 | */ 43 | public class Tree { 44 | 45 | /** The children. */ 46 | private List> children = new ArrayList>(); 47 | 48 | /** The parent. */ 49 | private Tree parent = null; 50 | 51 | /** The items. */ 52 | private T items = null; 53 | 54 | /** 55 | * Instantiates a new tree. 56 | * 57 | * @param data the data 58 | */ 59 | public Tree(T data) { 60 | // constructor for the tree with one input 61 | this.items = data; 62 | } 63 | 64 | /** 65 | * Instantiates a new tree. 66 | * 67 | * @param item the item 68 | * @param parent the parent 69 | */ 70 | public Tree(T item, Tree parent) { 71 | // constructor for the tree object with two inputs 72 | this.items = item; 73 | this.parent = parent; 74 | } 75 | 76 | /** 77 | * Gets the children. 78 | * 79 | * @return the children 80 | */ 81 | public String getChildren() { 82 | String names = ""; 83 | for (int i = 0; i < children.size(); i++) { 84 | names = names + " " + children.get(i).getItems(); 85 | } 86 | return names; 87 | } 88 | 89 | /** 90 | * Gets the raw children. 91 | * 92 | * @return the raw children 93 | */ 94 | public List> getRawChildren() { 95 | // Returns an ArrayList of children 96 | return children; 97 | } 98 | 99 | /** 100 | * Sets the parent. 101 | * 102 | * @param parent the new parent 103 | */ 104 | public void setParent(Tree parent) { 105 | // Adds a new tree to the tree as a parent 106 | this.parent = parent; 107 | } 108 | 109 | /** 110 | * Gets the parent. 111 | * 112 | * @return the parent 113 | */ 114 | public Tree getParent() { 115 | // Returns the parent of tree 116 | return parent; 117 | } 118 | 119 | /** 120 | * Adds the child. 121 | * 122 | * @param data the data 123 | */ 124 | public void addChild(T data) { 125 | // Adds a child to the current tree object 126 | // Creates a tree object with "data" 127 | Tree child = new Tree(data); 128 | // Sets parent of "child" to current tree 129 | child.setParent(this); 130 | // Adds "child" as child for tree 131 | this.children.add(child); 132 | } 133 | 134 | /** 135 | * Adds the child. 136 | * 137 | * @param child the child 138 | */ 139 | public void addChild(Tree child) { 140 | // Adds the "child" tree object to the current tree 141 | child.setParent(this); 142 | // Sets the child of current object to "child" 143 | this.children.add(child); 144 | } 145 | 146 | /** 147 | * Gets the items. 148 | * 149 | * @return the items 150 | */ 151 | public String getItems() { 152 | if (this.items instanceof File) { 153 | return ((File) this.items).getFileName(); 154 | } else { 155 | return (String) this.items; 156 | } 157 | } 158 | 159 | /** 160 | * Gets the raw items. 161 | * 162 | * @return the raw items 163 | */ 164 | public T getRawItems() { 165 | return this.items; 166 | } 167 | 168 | /** 169 | * Sets the items. 170 | * 171 | * @param data the new items 172 | */ 173 | public void setItems(T data) { 174 | this.items = data; 175 | } 176 | 177 | /** 178 | * Checks if is root. 179 | * 180 | * @return true, if is root 181 | */ 182 | public boolean isRoot() { 183 | return (this.parent == null); 184 | } 185 | 186 | /** 187 | * Checks if is leaf. 188 | * 189 | * @return true, if is leaf 190 | */ 191 | public boolean isLeaf() { 192 | if (this.children.size() == 0) 193 | return true; 194 | else 195 | return false; 196 | } 197 | 198 | /** 199 | * Removes the parent. 200 | */ 201 | public void removeParent() { 202 | this.parent = null; 203 | } 204 | } 205 | 206 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/CatTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | import java.util.Stack; 35 | import org.junit.Before; 36 | import org.junit.Test; 37 | import commands.*; 38 | import helpers.Directory; 39 | 40 | public class CatTest { 41 | 42 | String input; 43 | Directory dir; 44 | Echo echo; 45 | Mkdir mkdir; 46 | Cd cd; 47 | String output; 48 | String expected; 49 | 50 | @Before 51 | public void setUp(){ 52 | dir = new Directory(); 53 | echo = new Echo(); 54 | mkdir = new Mkdir(); 55 | cd = new Cd(); 56 | input = ""; 57 | output = ""; 58 | expected = ""; 59 | } 60 | 61 | @Test 62 | public void testFile() { 63 | // Cat a file in the home directory 64 | input = "echo \"file\" > fileName"; 65 | echo.execute(dir, input, null); 66 | expected = "file"; 67 | output = Cat.getFileInfo(dir, "fileName"); 68 | assertEquals(expected, output); 69 | } 70 | 71 | @Test 72 | public void testCatNewDir() { 73 | // Cat a file in a different folder 74 | input = "echo \"file\" > home"; 75 | echo.execute(dir, input, null); 76 | expected = "file"; 77 | output = Cat.getFileInfo(dir, "home"); 78 | assertEquals(expected, output); 79 | } 80 | @Test 81 | public void testCatNewDir2() { 82 | input = "newfile"; 83 | echo.execute(dir, input, null); 84 | cd.switchDir(dir, input); 85 | input = "echo \"file\" > fileName"; 86 | echo.execute(dir, input, null); 87 | output = Cat.getFileInfo(dir, "fileName"); 88 | expected = "file"; 89 | assertEquals(expected, output); 90 | } 91 | 92 | @Test 93 | public void testError() { 94 | // Cat a file in the home directory 95 | expected = "cat: fileName: No such file or directory"; 96 | output = Cat.getFileInfo(dir, "fileName"); 97 | assertEquals(expected, output); 98 | } 99 | } 100 | 101 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/CdTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import java.util.Stack; 34 | 35 | import org.junit.Before; 36 | import org.junit.Test; 37 | import commands.*; 38 | import helpers.*; 39 | import static org.junit.Assert.*; 40 | 41 | public class CdTest { 42 | Directory dir; 43 | Mkdir mkDir; 44 | Cd cd; 45 | 46 | @Before 47 | public void setUp() { 48 | dir = new Directory(); 49 | mkDir = new Mkdir(); 50 | cd = new Cd(); 51 | } 52 | 53 | @Test 54 | public void testChanginDirectoryFromRoot() { 55 | // Test changing the directory from the root directory 56 | mkDir.execute(dir, "mkdir /Folder1", null); 57 | cd.execute(dir, "cd /Folder1", null); 58 | assertEquals("Folder1", dir.workingDir()); 59 | } 60 | 61 | @Test 62 | public void testInputWithoutSlash() { 63 | // Test if the method accepts with the "/" 64 | mkDir.execute(dir, "mkdir /Folder1", null); 65 | cd.execute(dir, "cd Folder1", null); 66 | assertEquals("Folder1", dir.workingDir()); 67 | } 68 | 69 | @Test 70 | public void testInputWithSlash() { 71 | // Test if accepts with the "/" 72 | mkDir.execute(dir, "mkdir /Folder1", null); 73 | cd.execute(dir, "cd /Folder1", null); 74 | assertEquals("Folder1", dir.workingDir()); 75 | } 76 | 77 | @Test 78 | public void testChangeDirToPath() { 79 | // Test if cd accepts a full path 80 | mkDir.execute(dir, 81 | "mkdir /Folder1 /Folder1/Folder2 /Folder1/Folder" + "2/Folder3", null); 82 | cd.execute(dir, "cd Folder1/Folder2/Folder3", null); 83 | assertEquals("Folder3", dir.workingDir()); 84 | } 85 | 86 | @Test 87 | public void testGoingUpAndDownATree() { 88 | // Test if cd can go up and down a directory 89 | mkDir.execute(dir, 90 | "mkdir /Folder1 /Folder1/Folder2 /Folder1/Folder2/Folder3", null); 91 | cd.execute(dir, "cd Folder1/Folder2/Folder3", null); 92 | cd.execute(dir, "cd ..", null); 93 | assertEquals("Folder2", dir.workingDir()); 94 | } 95 | 96 | @Test 97 | public void testGoingToRoot() { 98 | // Test going to root (cd /) as input 99 | mkDir.execute(dir, "mkdir /Folder1", null); 100 | cd.execute(dir, "cd /", null); 101 | assertEquals("/", dir.workingDir()); 102 | } 103 | 104 | @Test 105 | public void testGoingUpWhileInRoot() { 106 | // Test trying to go up from root 107 | mkDir.execute(dir, "mkdir /Folder1", null); 108 | cd.execute(dir, "cd /..", null); 109 | assertEquals("/", dir.workingDir()); 110 | } 111 | 112 | @Test 113 | public void testChangeDirToNonExistentDir() { 114 | // Test trying to go up from root 115 | mkDir.execute(dir, "mkdir /Folder1", null); 116 | cd.execute(dir, "cd Folder2", null); 117 | assertEquals("/", dir.workingDir()); 118 | } 119 | 120 | @Test 121 | public void testUsingDotDotWithFilePath() { 122 | // Test if cd can go up and down a directory using a single path 123 | mkDir.execute(dir, 124 | "mkdir /Folder1 /Folder1/Folder2 /Folder1/Folder" + "2/Folder3", null); 125 | cd.execute(dir, "cd Folder1/Folder2/Folder3/..", null); 126 | assertEquals("Folder2", dir.workingDir()); 127 | } 128 | 129 | @Test 130 | public void testWithIncorrectFilePath() { 131 | // Test full path where some folder does not exist 132 | mkDir.execute(dir, 133 | "mkdir /Folder1 /Folder1/Folder2 /Folder1/Folder2/Folder3", null); 134 | cd.execute(dir, "cd /Folder1/Folder3", null); 135 | assertEquals("/", dir.workingDir()); 136 | } 137 | 138 | @Test 139 | public void testChangeDirToRootContinually() { 140 | // Test trying to go up from root 141 | mkDir.execute(dir, "mkdir /Folder1", null); 142 | cd.execute(dir, "cd /////////////", null); 143 | assertEquals("/", dir.workingDir()); 144 | } 145 | 146 | @Test 147 | public void testNonsensicalInput() { 148 | // Test weird characters as input 149 | mkDir.execute(dir, "mkdir /Folder1", null); 150 | cd.execute(dir, "cd @$^#$@#^#%&$ro69ky8ornr5h3", null); 151 | assertEquals("/", dir.workingDir()); 152 | } 153 | 154 | @Test 155 | public void testGoUpDirContinually() { 156 | // Test trying to go up from root 157 | mkDir.execute(dir, "mkdir /Folder1", null); 158 | cd.execute(dir, "cd /......................", null); 159 | assertEquals("/", dir.workingDir()); 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/CpTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | 35 | import org.junit.Before; 36 | 37 | import helpers.Directory; 38 | import helpers.File; 39 | import helpers.Tree; 40 | 41 | import org.junit.Test; 42 | 43 | import commands.Cd; 44 | import commands.Cp; 45 | import commands.Ls; 46 | import commands.Mkdir; 47 | import commands.Mv; 48 | 49 | public class CpTest { 50 | Mkdir mkdir; 51 | Directory dir; 52 | Cd cd; 53 | Cp cp; 54 | Ls ls; 55 | Mv mv; 56 | 57 | @Before 58 | public void setUp() { 59 | mkdir = new Mkdir(); 60 | dir = new Directory(); 61 | cd = new Cd(); 62 | cp = new Cp(); 63 | ls = new Ls(); 64 | mv = new Mv(); 65 | } 66 | 67 | @Test 68 | public void testOneCopy() { 69 | mkdir.execute(dir, "mkdir this that", null); 70 | cp.execute(dir, "cp this that", null); 71 | String dirs = ls.listDir(dir, ""); 72 | String dirs2 = ls.listDir(dir, "that"); 73 | assertEquals("/: this that\n", dirs); 74 | assertEquals("that: this\n", dirs2); 75 | } 76 | 77 | @Test 78 | public void testMultipleCopy() { 79 | mkdir.execute(dir, "mkdir this this/one this/one/two that", null); 80 | cp.execute(dir, "cp this that", null); 81 | String dirs = ls.listDir(dir, ""); 82 | String dirs2 = ls.listDir(dir, "that"); 83 | String dirs3 = ls.listDir(dir, "that/this"); 84 | String dirs4 = ls.listDir(dir, "that/this/one"); 85 | assertEquals("/: this that\n", dirs); 86 | assertEquals("that: this\n", dirs2); 87 | assertEquals("that/this: one\n", dirs3); 88 | assertEquals("that/this/one: two\n", dirs4); 89 | } 90 | 91 | @Test 92 | public void testWrongFirstCopy() { 93 | mkdir.execute(dir, "mkdir this this/one this/one/two that", null); 94 | cp.execute(dir, "cp Wrong that", null); 95 | String dirs = ls.listDir(dir, ""); 96 | String dirs2 = ls.listDir(dir, "that"); 97 | assertEquals("/: this that\n", dirs); 98 | assertEquals("that:\n", dirs2); 99 | } 100 | 101 | @Test 102 | public void testWrongSecondCopy() { 103 | mkdir.execute(dir, "mkdir this this/one this/one/two that", null); 104 | cp.execute(dir, "cp this WRONG", null); 105 | String dirs = ls.listDir(dir, ""); 106 | String dirs2 = ls.listDir(dir, "that"); 107 | assertEquals("/: this that\n", dirs); 108 | assertEquals("that:\n", dirs2); 109 | } 110 | 111 | @Test 112 | public void testFileCopy() { 113 | mkdir.execute(dir, "mkdir this that", null); 114 | File demo = new File("NAME", "CONTENT"); 115 | Tree demoCont = new Tree(demo); 116 | dir.insertMe(demoCont, dir.rawWorkingDir()); 117 | cp.execute(dir, "cp NAME this", null); 118 | String dirs = ls.listDir(dir, ""); 119 | String dirs2 = ls.listDir(dir, "this"); 120 | assertEquals("/: this that NAME\n", dirs); 121 | assertEquals("this: NAME\n", dirs2); 122 | } 123 | 124 | @Test 125 | public void testFileAndFolderCopy() { 126 | mkdir.execute(dir, "mkdir this this/one this/one/two that", null); 127 | File demo = new File("NAME", "CONTENT"); 128 | Tree demoCont = new Tree(demo); 129 | cd.execute(dir, "cd this/one", null); 130 | dir.insertMe(demoCont, dir.rawWorkingDir()); 131 | cd.execute(dir, "cd ../..", null); 132 | cp.execute(dir, "cp this that", null); 133 | String dirs = ls.listDir(dir, ""); 134 | String dirs2 = ls.listDir(dir, "this"); 135 | String dirs3 = ls.listDir(dir, "this/one"); 136 | assertEquals("/: this that\n", dirs); 137 | assertEquals("this: one\n", dirs2); 138 | assertEquals("this/one: two NAME\n", dirs3); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/DirectoryTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | import org.junit.Before; 35 | import helpers.*; 36 | import org.junit.Test; 37 | import commands.Cd; 38 | import commands.Echo; 39 | import commands.Mkdir; 40 | 41 | public class DirectoryTest { 42 | Directory dir; 43 | Mkdir mkdir; 44 | Cd cd; 45 | Echo echo; 46 | 47 | @Before 48 | public void setUp(){ 49 | dir = new Directory(); 50 | mkdir = new Mkdir(); 51 | cd = new Cd(); 52 | echo = new Echo(); 53 | } 54 | 55 | @Test // Checks current working directory 56 | public void testWorkingDirEmpty() { 57 | assertEquals("/", dir.workingDir()); 58 | } 59 | 60 | @Test // Checks current working directory 61 | public void testWorkingDir() { 62 | mkdir.execute(dir, "mkdir Folder1", null); 63 | cd.execute(dir, "cd Folder1", null); 64 | assertEquals("Folder1", dir.workingDir()); 65 | } 66 | 67 | @Test // Checks current working directory 68 | public void testWorkingDirWithMultipleSubFolders() { 69 | mkdir.execute(dir, 70 | "mkdir Folder1 Folder1/Folder2 Folder1/Folder2/Folder3", null); 71 | cd.execute(dir, "cd Folder1/Folder2/Folder3", null); 72 | assertEquals("Folder3", dir.workingDir()); 73 | } 74 | 75 | @Test // tests contents of current directory 76 | public void testGetContentsEmpty() { 77 | assertEquals("", dir.getContents()); 78 | } 79 | 80 | @Test // Checks current working directory 81 | public void testGetContentsWithOneFolder() { 82 | mkdir.execute(dir, "mkdir Folder1", null); 83 | assertEquals(" Folder1", dir.getContents()); 84 | } 85 | 86 | @Test // Checks current working directory 87 | public void testGetContentsWithMultipleFolders() { 88 | mkdir.execute(dir, "mkdir Folder1 Fodler2 Folder3 Folder4", null); 89 | assertEquals(" Folder1 Fodler2 Folder3 Folder4", dir.getContents()); 90 | } 91 | 92 | @Test // 93 | public void testCheckDirEmpty(){ 94 | assertEquals(false, dir.checkDir("any directory")); 95 | } 96 | 97 | @Test // 98 | public void testHasChildrenWithoutChildren(){ 99 | assertEquals(false, dir.hasChildren()); 100 | } 101 | 102 | @Test // 103 | public void testHasChildrenWithChild(){ 104 | mkdir.execute(dir, "mkdir Folder1", null); 105 | assertEquals(true, dir.hasChildren()); 106 | } 107 | 108 | @Test // 109 | public void testHasChildrenWithChildren(){ 110 | mkdir.execute(dir, "mkdir Folder1 Folder2 Folder3 Folder4", null); 111 | assertEquals(true, dir.hasChildren()); 112 | } 113 | 114 | @Test // 115 | public void testHasChildrenWhenFile(){ 116 | echo.execute(dir, "echo \"test\" > test.txt", null); 117 | assertEquals(true, dir.hasChildren()); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/EchoTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | 35 | import java.util.Stack; 36 | 37 | import org.junit.Before; 38 | import org.junit.Test; 39 | 40 | import commands.Cat; 41 | import commands.Echo; 42 | import commands.Mkdir; 43 | import helpers.Directory; 44 | import helpers.FileExists; 45 | 46 | public class EchoTest { 47 | String input; 48 | Directory dir; 49 | Echo echo; 50 | Mkdir mkdir; 51 | String output; 52 | String expected; 53 | 54 | @Before 55 | public void setUp() { 56 | input = ""; 57 | output = ""; 58 | expected = ""; 59 | dir = new Directory(); 60 | echo = new Echo(); 61 | mkdir = new Mkdir(); 62 | } 63 | 64 | @Test 65 | public void testAddBase() { 66 | // Adds a file to the base directory 67 | input = "echo \"file\" > fileName"; 68 | echo.execute(dir, input, null); 69 | expected = "file"; 70 | output = Cat.getFileInfo(dir, "fileName"); 71 | assertEquals(expected, output); 72 | } 73 | 74 | @Test 75 | public void testAddAppend() { 76 | // Adds and appends a file 77 | input = "echo \"file\" > fileName"; 78 | echo.execute(dir, input, null); 79 | input = "echo \"add\" >> fileName"; 80 | echo.execute(dir, input, null); 81 | expected = "fileadd"; 82 | output = Cat.getFileInfo(dir, "fileName"); 83 | assertEquals(expected, output); 84 | } 85 | 86 | @Test 87 | public void testAddAppendEdit() { 88 | // Adds and appends a file and rewrites the file 89 | input = "echo \"file\" > fileName"; 90 | echo.execute(dir, input, null); 91 | input = "echo \"add\" >> fileName"; 92 | echo.execute(dir, input, null); 93 | output = Cat.getFileInfo(dir, "fileName"); 94 | expected = "fileadd"; 95 | assertEquals(expected, output); 96 | input = "echo \"reset\" > fileName"; 97 | echo.execute(dir, input, null); 98 | expected = "reset"; 99 | output = Cat.getFileInfo(dir, "fileName"); 100 | assertEquals(expected, output); 101 | } 102 | 103 | @Test 104 | public void testCheckFileExists() { 105 | // Checks if file exists 106 | input = "echo \"file\" > fileName"; 107 | echo.execute(dir, input, null); 108 | boolean status = FileExists.getFileExists(dir, "fileName"); 109 | assertEquals(true, status); 110 | } 111 | 112 | @Test 113 | public void testCheckFileNotExists() { 114 | // Checks if file doesn't exists 115 | boolean status = FileExists.getFileExists(dir, "fileName"); 116 | assertEquals(false, status); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/ExitTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | 35 | import java.util.Stack; 36 | import org.junit.Test; 37 | import commands.*; 38 | import helpers.*; 39 | 40 | public class ExitTest { 41 | Exit exit; 42 | Stack a; 43 | Directory dir; 44 | 45 | 46 | 47 | @Test 48 | public void testIfExitWorks() { 49 | exit = new Exit(); 50 | dir = new Directory(); 51 | assertTrue(exit.checkString("exit")); 52 | 53 | } 54 | 55 | @Test 56 | public void testIfExitWorksWithWrongInput() { 57 | exit = new Exit(); 58 | dir = new Directory(); 59 | assertFalse(exit.checkString("wrong input")); 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/FileExistsTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | import java.util.Stack; 35 | import org.junit.Test; 36 | 37 | import commands.*; 38 | import helpers.*; 39 | 40 | public class FileExistsTest { 41 | String input = ""; // First input 42 | Directory dir = new Directory(); 43 | Echo e = new Echo(); 44 | Mkdir m = new Mkdir(); 45 | Cd c = new Cd(); 46 | Stack holder = new Stack(); 47 | FileExists exists = new FileExists(); 48 | boolean output; 49 | boolean expected; 50 | 51 | @Test 52 | public void testExistsRoot() { 53 | // Tests if the file exists at the root 54 | input = "echo \"Hello world\" > file"; 55 | e.execute(dir, input, null); //Creates file in root 56 | output = exists.getFileExists(dir, "file"); // Looks for file 57 | expected = true; // Should be true 58 | assertEquals(expected, output); 59 | } 60 | 61 | @Test 62 | public void testNotExistsRoot() { 63 | // Tests if the file exists at the root 64 | input = "echo \"Hello world\" > file"; 65 | e.execute(dir, input, null); //Creates file in root 66 | output = exists.getFileExists(dir, "notFile"); // Looks for notFile 67 | expected = false; // Should be true 68 | assertEquals(expected, output); 69 | } 70 | 71 | @Test 72 | public void testExistsNewPath() { 73 | // Tests if the file exists at a different path 74 | input = "mkdir folder1"; 75 | m.execute(dir, input, null); // Makes the folder folder1 76 | c.execute(dir, "cd folder1", null); // Switches to folder1 77 | input = "echo \"hello world\" > file"; 78 | e.execute(dir, input, null); //Creates file in folder1 79 | output = exists.getFileExists(dir, "file"); //Looks for file 80 | expected = true; // Should be true 81 | assertEquals(expected, output); 82 | } 83 | 84 | @Test 85 | public void testNotExistsNewPath() { 86 | // Tests if the file doesn't exists at a different path 87 | input = "mkdir folder1"; 88 | m.execute(dir, input, null); //Makes folder folder1 89 | c.execute(dir, "cd folder1", null); // Switches to folder 1 90 | input = "echo \"hello world\" > notFile"; 91 | e.execute(dir, input, null); // Creates files in folder1 92 | output = exists.getFileExists(dir, "file"); // Looks for file 93 | expected = false; // Should be false 94 | assertEquals(expected, output); 95 | } 96 | 97 | @Test 98 | public void testFileNotSamePath() { 99 | // Tests accessing a file of different path but the file doesn't exists 100 | // in the current path 101 | input = "echo \"hello world\" > file"; 102 | e.execute(dir, input, null);//Creates file in root 103 | input = "mkdir folder1"; 104 | m.execute(dir, input, null); //Makes folder folder1 105 | c.execute(dir, "cd folder1", null); //Navigate to folder1 106 | output = exists.getFileExists(dir, "file"); //Looks for file 107 | expected = false; // Should be false because file is in root not folder1 108 | assertEquals(expected, output); 109 | } 110 | } -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/FileTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | 35 | import org.junit.Test; 36 | import helpers.File; 37 | 38 | public class FileTest { 39 | File file; 40 | String name; 41 | String content; 42 | 43 | 44 | @Test 45 | public void testGetName() { 46 | name = "TestFile"; 47 | content = "this is file content, this is arbitrary"; 48 | file = new File(name, content); 49 | assertEquals(name, file.getFileName()); 50 | 51 | } 52 | 53 | @Test 54 | public void testSetName() { 55 | name = "TestFile"; 56 | content = "this is file content, this is arbitrary"; 57 | file = new File(name, content); 58 | file.setFileName("NewName"); 59 | assertEquals("NewName", file.getFileName()); 60 | 61 | 62 | } 63 | 64 | @Test 65 | public void testSetContent() { 66 | name = "TestFile"; 67 | content = "this is file content, this is arbitrary"; 68 | file = new File(name, content); 69 | file.setContent("New content"); 70 | assertEquals("New content", file.getContent()); 71 | 72 | } 73 | 74 | @Test 75 | public void testGetContent() { 76 | name = "TestFile"; 77 | content = "this is file content, this is arbitrary"; 78 | file = new File(name, content); 79 | assertEquals(content, file.getContent()); 80 | 81 | } 82 | 83 | 84 | } 85 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/FormatMeTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | 35 | import org.junit.Test; 36 | 37 | import helpers.FormatMe; 38 | 39 | public class FormatMeTest { 40 | String input = ""; 41 | boolean output; 42 | boolean expected; 43 | String [] out; 44 | helpers.FormatMe test = new helpers.FormatMe(); 45 | @Test 46 | public void singleIllegal() { 47 | // Checks for a single illegal character 48 | input = "$ajdhsajhdjk"; 49 | output = FormatMe.testDirString(input); 50 | expected = false; 51 | assertEquals(expected, output); 52 | } 53 | 54 | @Test 55 | public void multiIllegal() { 56 | // Checks for multiple illegal characters 57 | input = "$aj#dhsa/jhdjk"; 58 | output = FormatMe.testDirString(input); 59 | expected = false; 60 | assertEquals(expected, output); 61 | } 62 | 63 | @Test 64 | public void pass() { 65 | // Checks for multiple illegal characters 66 | input = "ajdhsajhdjk"; 67 | output = FormatMe.testDirString(input); 68 | expected = true; 69 | assertEquals(expected, output); 70 | } 71 | 72 | @Test 73 | public void cutSingleDir() { 74 | // Checks for single split paths 75 | input = "mkdir one/two/three"; 76 | out = FormatMe.cutDirMkdir(input); 77 | String [] ex = {"one/two/three"}; 78 | assertArrayEquals(ex, out); 79 | } 80 | 81 | @Test 82 | public void cutTwoDir() { 83 | // Checks for two split paths 84 | input = "mkdir one/two/three 1/2/3"; 85 | out = FormatMe.cutDirMkdir(input); 86 | String [] ex = {"one/two/three", "1/2/3"}; 87 | assertArrayEquals(ex, out); 88 | } 89 | 90 | @Test 91 | public void cutInvalid() { 92 | // Checks for paths with invalid characters 93 | input = "mkdir one/two/th>/ree 1/2/3"; 94 | out = FormatMe.cutDirMkdir(input); 95 | String [] ex = {null}; 96 | assertArrayEquals(ex, out); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/GetTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | 35 | import java.util.Stack; 36 | 37 | import org.junit.Test; 38 | import commands.*; 39 | import helpers.*; 40 | 41 | public class GetTest { 42 | 43 | String expected = ""; 44 | boolean exBool = false; 45 | String actual = ""; 46 | boolean actBool = false; 47 | String input = ""; 48 | Mkdir m = new Mkdir(); 49 | Get g = new Get(); 50 | Cat c = new Cat(); 51 | Cd cd = new Cd(); 52 | FileExists f = new FileExists(); 53 | Directory dir = new Directory(); 54 | 55 | @Test 56 | public void testInvalidUrl() { 57 | // Tests for an invalid url 58 | input = "get invalidURl"; 59 | g.execute(dir, input, null); 60 | exBool = false; 61 | actBool = f.getFileExists(dir, input); 62 | assertEquals(exBool, actBool); // Checks if file exists 63 | } 64 | 65 | @Test 66 | public void testValidUrl() { 67 | // Tests for an valid url 68 | input = "get https://raw.github.com/jmflee/t/master/s.txt"; 69 | g.execute(dir, input, null); 70 | actBool = f.getFileExists(dir, "s.txt"); // Checks if file exists 71 | exBool = true; 72 | assertEquals(exBool, actBool); 73 | actual = c.getFileInfo(dir, "s.txt"); // Checks contents of files 74 | expected = "this is a test\n"; 75 | assertEquals(expected, actual); 76 | } 77 | 78 | @Test 79 | public void testValidUrlDifferetDir() { 80 | // Tests for an valid url in a different directory 81 | m.execute(dir, "mkdir folder1", null); // Creates folder1 82 | cd.execute(dir, "cd folder1", null); // Changes cd to folder1 83 | input = "get https://raw.github.com/jmflee/t/master/s.txt"; 84 | g.execute(dir, input, null); 85 | actBool = f.getFileExists(dir, "s.txt"); // Checks if file exists 86 | exBool = true; 87 | assertEquals(exBool, actBool); 88 | actual = c.getFileInfo(dir, "s.txt"); // Checks contents of files 89 | expected = "this is a test\n"; 90 | assertEquals(expected, actual); 91 | cd.execute(dir, "cd ..", null); 92 | actBool = f.getFileExists(dir, "s.txt"); // Checks if file exists 93 | exBool = false; 94 | assertEquals(exBool, actBool); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/GrepTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | import org.junit.Before; 35 | import org.junit.Test; 36 | import commands.Cd; 37 | import commands.Echo; 38 | import commands.Grep; 39 | import commands.Mkdir; 40 | import helpers.Directory; 41 | 42 | public class GrepTest { 43 | Directory dir; 44 | Mkdir mkdir; 45 | Cd cd; 46 | Grep grep; 47 | Echo echo; 48 | String expected; 49 | String actual; 50 | 51 | @Before 52 | public void setUp(){ 53 | dir = new Directory(); 54 | mkdir = new Mkdir(); 55 | cd = new Cd(); 56 | grep = new Grep(); 57 | echo = new Echo(); 58 | expected = ""; 59 | actual = ""; 60 | } 61 | @Test 62 | public void testCorrectSingleLine () { 63 | echo.execute(dir, 64 | "echo " + "\"hello\"" + " > test.txt", null); 65 | expected = "/test.txt:\nhello"; 66 | actual = grep.findRegex(dir, "hello test.txt"); 67 | assertEquals(expected, actual); 68 | } 69 | @Test 70 | public void testCorrectMultipleLine() { 71 | echo.execute(dir, 72 | "echo " + "\"hello\nhello\"" + " > test.txt", null); 73 | expected = "/test.txt:\nhello\nhello"; 74 | actual = grep.findRegex(dir, "hello test.txt"); 75 | assertEquals(expected, actual); 76 | } 77 | @Test 78 | public void testCorrectMultipleLineMultipleRegex() { 79 | echo.execute(dir, 80 | "echo " + "\"hellotanayhello\nhello\"" + " > test.txt", null); 81 | expected = "/test.txt:\nhellotanayhello\nhellotanayhello\nhello"; 82 | actual = grep.findRegex(dir, "hello test.txt"); 83 | assertEquals(expected, actual); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/HistoryTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | 35 | import java.util.Stack; 36 | 37 | import org.junit.Test; 38 | 39 | import commands.Cd; 40 | import commands.History; 41 | import commands.Ls; 42 | import commands.Man; 43 | import commands.Mkdir; 44 | import helpers.Directory; 45 | 46 | public class HistoryTest { 47 | Stack commands = new Stack(); 48 | Ls ls; 49 | Mkdir mkDir; 50 | Cd cd; 51 | Directory dir; 52 | 53 | @Test // Adds multiple commands to history 54 | public void multipleCommandsInHistory() { 55 | commands.push("a"); 56 | commands.push("2"); 57 | commands.push("3"); 58 | commands.push("mkdir 123"); 59 | commands.push("history"); 60 | String expectedVal = 61 | "1 a\n" + "2 2\n" + "3 3\n" + "4 mkdir 123\n" + "5 history"; 62 | assertEquals(expectedVal, History.showStack(commands)); 63 | } 64 | 65 | @Test // Checks if corrent first user input is returned 66 | public void oneCommand() { 67 | commands.push("history"); 68 | String expectedVal = "1 history"; 69 | assertEquals(expectedVal, History.showStack(commands)); 70 | } 71 | 72 | @Test 73 | public void noCommands() { // Checks if no commands inputed by user 74 | String expectedVal = ""; 75 | assertEquals(expectedVal, History.showStack(commands)); 76 | } 77 | 78 | @Test // Shows the history of N items specified by user 79 | public void showNitems() { 80 | commands.push("hello"); 81 | commands.push("cd poo"); 82 | commands.push("ls"); 83 | commands.push("mkdir 123"); 84 | commands.push("history"); 85 | String expectedVal = "3 ls\n" + "4 mkdir 123\n" + "5 history"; 86 | assertEquals(expectedVal, History.showStack((commands), 3)); 87 | } 88 | 89 | // Checks if user has put in a number greater than the commands that 90 | // have been used 91 | @Test 92 | public void showGreaterThanCommandsEntered() { 93 | commands.push("hello"); 94 | commands.push("cd poo"); 95 | commands.push("ls"); 96 | commands.push("mkdir 123"); 97 | commands.push("history"); 98 | String expectedVal = 99 | "1 hello\n" + "2 cd poo\n" + "3 ls\n" + "4 mkdir 123\n" + "5 history"; 100 | assertEquals(expectedVal, History.showStack((commands), 20)); 101 | } 102 | 103 | @Test //Tests if user has entered a number that is negative 104 | public void negativeNumberInput() { 105 | commands.push("hello"); 106 | commands.push("cd poo"); 107 | commands.push("ls"); 108 | commands.push("mkdir 123"); 109 | commands.push("history"); 110 | String expectedVal = "History out of Bounds"; 111 | assertEquals(expectedVal, History.showStack((commands), -20)); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/InputparserTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.assertEquals; 34 | import helpers.*; 35 | import org.junit.Test; 36 | 37 | public class InputparserTest { 38 | 39 | String input = ""; // First input 40 | boolean output ; 41 | boolean expected; 42 | 43 | @Test //Tests if input is valid 44 | public void validInput() { 45 | input = "mkdir League of Legends"; 46 | expected = true; 47 | output = InputParser.validate(input); 48 | assertEquals(expected, output); 49 | } 50 | 51 | @Test //Tests if input is invalid 52 | public void invalidInput() { 53 | // Cat a file in the home directory 54 | input = "I love League of Legends"; 55 | expected = false; 56 | output = InputParser.validate(input); 57 | assertEquals(expected, output); 58 | } 59 | 60 | @Test //Tests if input is invalid 61 | public void invalidInputWithCapitals() { 62 | // Cat a file in the home directory 63 | input = "MKDIR My IGN IS L1ttle Noob"; 64 | expected = false; 65 | output = InputParser.validate(input); 66 | assertEquals(expected, output); 67 | } 68 | 69 | @Test //Tests if input is invalid 70 | public void multipleCommandsTogether() { 71 | // multiple commands together 72 | input = "mkdir echo ls"; 73 | expected = true; 74 | output = InputParser.validate(input); 75 | assertEquals(expected, output); 76 | } 77 | 78 | @Test //Tests if input is invalid 79 | public void noSpacesInCommands() { 80 | // no spaces in the command 81 | input = "mkdirechos"; 82 | expected = false; 83 | output = InputParser.validate(input); 84 | assertEquals(expected, output); 85 | } 86 | 87 | @Test //Tests if input is invalid 88 | public void CommandsInMiddle() { 89 | // command in middle of invalid inputs 90 | input = "League mkdir Is Life"; 91 | expected = false; 92 | output = InputParser.validate(input); 93 | assertEquals(expected, output); 94 | } 95 | 96 | } 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/LsTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | import java.util.Stack; 35 | 36 | import org.junit.Before; 37 | import org.junit.Test; 38 | import commands.*; 39 | import helpers.*; 40 | 41 | public class LsTest { 42 | 43 | Stack a = new Stack(); 44 | Mkdir mkDir; 45 | Cd cd; 46 | Directory dir; 47 | 48 | 49 | @Before 50 | public void setUp(){ 51 | dir = new Directory(); 52 | a = new Stack(); 53 | cd = new Cd(); 54 | } 55 | @Test 56 | public void testOnlyRootInTree() { 57 | // Tests ls when the tree only has a root 58 | // try using the getChildren function via Directory 59 | assertEquals("/:\n", Ls.listDir(dir, "")); 60 | 61 | } 62 | 63 | @Test // First cd into a folder then ls it 64 | public void testCdThenLs() { 65 | mkDir.execute(dir, "mkdir /File1 /File1/File2 File3 File4", null); 66 | cd.execute(dir, "cd /File1", null); 67 | assertEquals("/File1: File2\n", Ls.listDir(dir, "")); 68 | } 69 | 70 | @Test // Ls multiple relative paths 71 | public void testMultiplePaths() { 72 | mkDir.execute(dir, "mkdir /File1 /File1/File2 File3 File4", null); 73 | assertEquals("/File1/File2:\n", Ls.listDir(dir, "File1/File2")); 74 | } 75 | 76 | @Test // Ls a file path 77 | public void testFilePath() { 78 | dir = new Directory(); 79 | mkDir = new Mkdir(); 80 | cd = new Cd(); 81 | Echo echo = new Echo(); 82 | echo.execute(dir, "echo \"file\" > fileName.txt", null); 83 | assertEquals("fileName.txt", Ls.listDir(dir, "fileName.txt")); 84 | } 85 | 86 | @Test // Ls -r without any other arguments 87 | public void testRecursiveLs() { 88 | dir = new Directory(); 89 | mkDir = new Mkdir(); 90 | cd = new Cd(); 91 | mkDir.execute(dir, "mkdir /File1 /File1/File2 File3 File4", null); 92 | String expected = 93 | "/: File1 File3 File4\n\n/File1: File2\n\n/File1/File2:\n\n/File3:\n\n/File4:" 94 | + "\n"; 95 | assertEquals(expected, Ls.recursivelyListAllDir(dir)); 96 | } 97 | 98 | @Test // Ls multiple recursive paths 99 | public void testMultipleRecursivePaths() { 100 | dir = new Directory(); 101 | mkDir = new Mkdir(); 102 | cd = new Cd(); 103 | mkDir.execute(dir, "mkdir /File1 /File1/File2 File3 File4", null); 104 | String expected = 105 | "/: File1 File3 File4\n\n/File1: File2\n\n/File1/File2:\n\n/File3:\n\n/File4:" 106 | + "\n"; 107 | assertEquals(expected, Ls.recursivelyListAllDir(dir)); 108 | cd.execute(dir, "cd /File1/File2", null); 109 | String expected2 = "/File1/File2:\n"; 110 | assertEquals(expected2, Ls.recursivelyListAllDir(dir)); 111 | 112 | } 113 | 114 | 115 | } 116 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/MkdirTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | import helpers.Directory; 35 | 36 | import java.util.Stack; 37 | 38 | import org.junit.Test; 39 | 40 | import commands.Cd; 41 | import commands.Mkdir; 42 | 43 | public class MkdirTest { 44 | 45 | Directory dir = new Directory(); 46 | Mkdir mkdir = new Mkdir(); 47 | 48 | @Test 49 | public void testCreatingDirectory() { 50 | mkdir.execute(dir, "mkdir /Folder1", null); 51 | assertEquals("/", dir.workingDir()); // make sure no switch was made 52 | assertEquals(" Folder1", dir.rawWorkingDir().getChildren()); // checking 53 | // children 54 | } 55 | 56 | @Test 57 | public void testCreatingCreatingMultipleDirectories() { 58 | mkdir.execute(dir, 59 | "mkdir Folder1 Folder1/Folder2 Folder1/Folder2/" + "Folder3", null); 60 | assertEquals("/", dir.workingDir()); // make sure no switch was made 61 | assertEquals(" Folder1", dir.rawWorkingDir().getChildren()); 62 | // checking children 63 | } 64 | 65 | @Test // Tests for invalid characters in the name 66 | public void testCreatingInvalidCharacters() { 67 | mkdir.execute(dir, 68 | "mkdir /Foas.%$#$%lder1 Folder1 Folder1/Folder2/" + "Folde$r3", null); 69 | assertEquals("/", dir.workingDir()); // make sure no switch was made 70 | assertEquals("", dir.rawWorkingDir().getChildren()); 71 | } 72 | 73 | @Test // Tests if path exists or not 74 | public void testPathDoesntExist() { 75 | mkdir.execute(dir, "mkdir /Folder1/Folder2/Hi", null); 76 | assertEquals("/", dir.workingDir()); // make sure no switch was made 77 | assertEquals("", dir.rawWorkingDir().getChildren()); 78 | } 79 | 80 | @Test // Tests if multiple paths at once are made 81 | public void MultiplePathsAtOnce() { 82 | mkdir.execute(dir, "mkdir Folder1 /Folder1/Folder2/Hi", null); 83 | Cd.switchDir(dir, "Folder1"); 84 | assertEquals("Folder1", dir.workingDir()); // make sure no switch was made 85 | assertEquals("", dir.rawWorkingDir().getChildren()); 86 | } 87 | 88 | @Test // Tests if directory can be made after using .. 89 | public void testCreationOfFolderUsingDotDot() { 90 | mkdir.execute(dir, "mkdir Folder1", null); 91 | Cd.switchDir(dir, "Folder1"); 92 | mkdir.execute(dir, "mkdir ../HelloWorld", null); 93 | assertEquals("Folder1", dir.workingDir()); // make sure no switch was made 94 | assertEquals("", dir.rawWorkingDir().getChildren()); 95 | } 96 | 97 | @Test // Tests if directory of already existing name can be made 98 | public void testFolderWithExistingName() { 99 | mkdir.execute(dir, "mkdir Folder1 Folder1", null); 100 | mkdir.execute(dir, "mkdir Folder1", null); 101 | assertEquals("/", dir.workingDir()); // make sure no switch was made 102 | assertEquals(" Folder1", dir.rawWorkingDir().getChildren()); 103 | } 104 | 105 | @Test // Tests if directory with 1 letter can be made 106 | public void testOneLetterFolders() { 107 | mkdir.execute(dir, "mkdir B", null); 108 | assertEquals("/", dir.workingDir()); // make sure no switch was made 109 | assertEquals(" B", dir.rawWorkingDir().getChildren()); 110 | } 111 | 112 | 113 | } 114 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/MvTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | import helpers.Directory; 35 | import helpers.File; 36 | import helpers.Tree; 37 | 38 | import org.junit.Test; 39 | 40 | import commands.Cd; 41 | import commands.Cp; 42 | import commands.Ls; 43 | import commands.Mkdir; 44 | import commands.Mv; 45 | 46 | public class MvTest { 47 | Mkdir mkdir = new Mkdir(); 48 | Directory dir = new Directory(); 49 | Cd cd = new Cd(); 50 | Cp cp = new Cp(); 51 | Ls ls = new Ls(); 52 | Mv mv = new Mv(); 53 | 54 | @Test 55 | public void testOneMove() { 56 | mkdir.execute(dir, "mkdir this that", null); 57 | mv.execute(dir, "mv this that", null); 58 | String dirs = ls.listDir(dir, ""); 59 | String dirs2 = ls.listDir(dir, "that"); 60 | assertEquals("/: that\n", dirs); 61 | assertEquals("that: this\n", dirs2); 62 | } 63 | @Test 64 | public void testMultipleMove() { 65 | mkdir.execute(dir, "mkdir this this/one this/one/two that", null); 66 | mv.execute(dir, "mv this that", null); 67 | String dirs = ls.listDir(dir, ""); 68 | String dirs2 = ls.listDir(dir, "that"); 69 | String dirs3 = ls.listDir(dir, "that/this"); 70 | String dirs4 = ls.listDir(dir, "that/this/one"); 71 | assertEquals("/: that\n", dirs); 72 | assertEquals("that: this\n", dirs2); 73 | assertEquals("that/this: one\n", dirs3); 74 | assertEquals("that/this/one: two\n", dirs4); 75 | } 76 | 77 | @Test 78 | public void testWrongFirstMove() { 79 | mkdir.execute(dir, "mkdir this this/one this/one/two that", null); 80 | mv.execute(dir, "mv Wrong that", null); 81 | String dirs = ls.listDir(dir, ""); 82 | String dirs2 = ls.listDir(dir, "that"); 83 | assertEquals("/: this that\n", dirs); 84 | assertEquals("that:\n", dirs2); 85 | 86 | } 87 | @Test 88 | public void testWrongSecondMove() { 89 | mkdir.execute(dir, "mkdir this this/one this/one/two that", null); 90 | mv.execute(dir, "mv this WRONG", null); 91 | String dirs = ls.listDir(dir, ""); 92 | String dirs2 = ls.listDir(dir, "that"); 93 | assertEquals("/: this that\n", dirs); 94 | assertEquals("that:\n", dirs2); 95 | 96 | } 97 | 98 | @Test 99 | public void testFileMove() { 100 | mkdir.execute(dir, "mkdir this that", null); 101 | File demo = new File("NAME","CONTENT"); 102 | Tree demoCont = new Tree(demo); 103 | dir.insertMe(demoCont, dir.rawWorkingDir()); 104 | mv.execute(dir, "mv NAME this", null); 105 | 106 | String dirs = ls.listDir(dir, ""); 107 | String dirs2 = ls.listDir(dir, "this"); 108 | assertEquals("/: this that\n", dirs); 109 | assertEquals("this: NAME\n", dirs2); 110 | 111 | } 112 | 113 | @Test 114 | public void testFileAndFolderMove() { 115 | mkdir.execute(dir, "mkdir this this/one this/one/two that", null); 116 | File demo = new File("NAME","CONTENT"); 117 | Tree demoCont = new Tree(demo); 118 | cd.execute(dir, "cd this/one", null); 119 | dir.insertMe(demoCont, dir.rawWorkingDir()); 120 | cd.execute(dir, "cd ../..", null); 121 | mv.execute(dir, "mv this that", null); 122 | 123 | String dirs = ls.listDir(dir, ""); 124 | String dirs2 = ls.listDir(dir, "that"); 125 | String dirs3 = ls.listDir(dir, "that/this/one"); 126 | assertEquals("/: that\n", dirs); 127 | assertEquals("that: this\n", dirs2); 128 | assertEquals("that/this/one: two NAME\n", dirs3); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/PathWalkerTest.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import static org.junit.Assert.*; 4 | import helpers.Directory; 5 | import helpers.PathWalker; 6 | 7 | 8 | import java.util.Stack; 9 | 10 | import org.junit.Before; 11 | import org.junit.Test; 12 | 13 | import helpers.File; 14 | import helpers.Tree; 15 | 16 | import commands.Number; 17 | import commands.Cd; 18 | import commands.Cp; 19 | import commands.Ls; 20 | import commands.Mkdir; 21 | import commands.Mv; 22 | 23 | public class PathWalkerTest { 24 | Mkdir mkdir; 25 | Directory dir; 26 | Cd cd; 27 | Cp cp; 28 | Ls ls; 29 | Mv mv; 30 | PathWalker pathWalker; 31 | 32 | @Before 33 | public void setUp() { 34 | mkdir = new Mkdir(); 35 | dir = new Directory(); 36 | cd = new Cd(); 37 | cp = new Cp(); 38 | ls = new Ls(); 39 | mv = new Mv(); 40 | pathWalker = new PathWalker(); 41 | mkdir.execute(dir, "mkdir this that this/one this/one/two", null); 42 | } 43 | 44 | @Test 45 | public void testRelativePath() { 46 | boolean test =pathWalker.goToPath(dir, "this/one"); 47 | String test2 = ls.listDir(dir, ""); 48 | assertEquals("/this/one: two\n", test2); 49 | assertEquals(true, test); 50 | } 51 | 52 | @Test 53 | public void testAbsolutePath() { 54 | boolean test =pathWalker.goToPath(dir, "this/one"); 55 | boolean test3 = pathWalker.goToPath(dir, "/that"); 56 | String test2 = ls.listDir(dir, ""); 57 | assertEquals("/that:\n", test2); 58 | assertEquals(true, test); 59 | assertEquals(true, test3); 60 | } 61 | @Test 62 | public void testWrongPath() { 63 | boolean test =pathWalker.goToPath(dir, "wrong"); 64 | boolean test3 = pathWalker.goToPath(dir, "/wrong"); 65 | String test2 = ls.listDir(dir, ""); 66 | assertEquals("/: this that\n", test2); 67 | assertEquals(false, test); 68 | assertEquals(false, test3); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/PopdTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | import helpers.Directory; 35 | import helpers.Tree; 36 | 37 | import java.util.Stack; 38 | 39 | import org.junit.After; 40 | import org.junit.AfterClass; 41 | import org.junit.Before; 42 | import org.junit.BeforeClass; 43 | import org.junit.Test; 44 | 45 | import commands.Popd; 46 | import commands.Pushd; 47 | 48 | public class PopdTest { 49 | Directory explorer = new Directory(); 50 | Tree a = new Tree("FOLDER1"); 51 | Pushd push = new Pushd(); 52 | Tree b = new Tree("FOLDER2"); 53 | Popd pop = new Popd(); 54 | 55 | @Test 56 | public void creation() { 57 | explorer.insertMe(b, explorer.rawWorkingDir());// put b in root 58 | explorer.insertMe(a, b);// so /root/folder2/folder1 workingDir = root 59 | push.getStack().push("/FOLDER2"); // format here has to be same as if 60 | // pwd.printDir() returns 61 | pop.execute(explorer, null, null);// goes into folder2 62 | // working directory should be folder2 63 | assertEquals("FOLDER2", explorer.workingDir()); 64 | // stack should contain nothing 65 | assertEquals(2, push.getStack().size()); 66 | } 67 | 68 | // test switching more then once 69 | @Test 70 | public void switchMultipleTimes() { 71 | explorer.insertMe(b, explorer.rawWorkingDir());// put b in root 72 | explorer.insertMe(a, b);// so /root/folder2/folder1 workingDir = root 73 | push.getStack().push("/FOLDER2"); // format here has to be same as if 74 | // pwd.printDir() returns 75 | push.getStack().push("/FOLDER3"); // format here has to be same as if 76 | // pwd.printDir() returns 77 | pop.execute(explorer, null, null);// goes into folder2 78 | // working directory should be folder2 79 | assertEquals("/", explorer.workingDir()); 80 | // stack should contain nothing 81 | assertEquals(1, Pushd.getStack().size()); 82 | } 83 | 84 | @Test 85 | public void emptyStack() { 86 | explorer.insertMe(b, explorer.rawWorkingDir());// put b in root 87 | explorer.insertMe(a, b);// so /root/folder2/folder1 workingDir = root 88 | pop.execute(explorer, null, null);// goes into folder2 89 | // working directory should be folder2 90 | assertEquals("FOLDER2", explorer.workingDir()); 91 | // stack should contain nothing 92 | assertEquals(0, Pushd.getStack().size()); 93 | } 94 | 95 | @Test 96 | public void multipleItemsInPopd() { 97 | explorer.insertMe(b, explorer.rawWorkingDir());// put b in root 98 | explorer.insertMe(a, b);// so /root/folder2/folder1 workingDir = root 99 | push.getStack().push("/FOLDER2"); // format here has to be same as if 100 | // pwd.printDir() returns 101 | push.getStack().push("/FOLDER3"); // format here has to be same as if 102 | // pwd.printDir() returns 103 | push.getStack().push("/FOLDER4"); // format here has to be same as if 104 | // pwd.printDir() returns 105 | pop.execute(explorer, null, null);// goes into folder2 106 | // working directory should be folder2 107 | assertEquals("/", explorer.workingDir()); 108 | // stack should contain nothing 109 | assertEquals(2, Pushd.getStack().size()); 110 | } 111 | 112 | 113 | 114 | } 115 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/PushdTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | 35 | import java.util.Stack; 36 | 37 | import helpers.*; 38 | import commands.*; 39 | 40 | import org.junit.Test; 41 | 42 | public class PushdTest { 43 | Directory explorer = new Directory(); 44 | Tree a = new Tree("FOLDER1"); 45 | Pushd testVar = new Pushd(); 46 | Tree b = new Tree("FOLDER2"); 47 | 48 | @Test 49 | public void invalidInput() { 50 | explorer.insertMe(b, explorer.rawWorkingDir());// put b in root 51 | explorer.insertMe(b, a);// put a in b 52 | testVar.execute(explorer, "pushd FOLDER6", null);// make it go in folder2\ 53 | assertEquals("/", explorer.workingDir()); 54 | } 55 | 56 | @Test 57 | public void invalidChar() { 58 | explorer.insertMe(b, explorer.rawWorkingDir());// put b in root 59 | explorer.insertMe(b, a);// put a in b 60 | testVar.execute(explorer, "pushd FOLDER%4//2", null);// make it go in folder2 61 | assertEquals("/", explorer.workingDir()); 62 | } 63 | 64 | @Test 65 | public void goToPreviousDirectory() { 66 | explorer.insertMe(b, explorer.rawWorkingDir());// put b in root 67 | explorer.insertMe(b, a);// put a in b 68 | testVar.execute(explorer, "pushd FOLDER2", null);// make it go in folder2 69 | // working directory should be folder2 70 | assertEquals("FOLDER2", explorer.workingDir()); 71 | // stack should contain one directory 72 | assertEquals(1, testVar.getStack().size()); 73 | // root should be in the stack 74 | assertEquals("/", testVar.getStack().peek()); 75 | } 76 | 77 | // test / as input 78 | 79 | } 80 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/PwdTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import commands.*; 34 | import static org.junit.Assert.*; 35 | import java.util.Stack; 36 | import org.junit.Test; 37 | import helpers.Directory; 38 | 39 | public class PwdTest { 40 | String expectedVal; 41 | Directory dir; 42 | Mkdir m; 43 | Stack a; 44 | 45 | 46 | @Test 47 | public void testWhenDirectorycetoryIsAtRoot() { 48 | // tests when the current directory is at root 49 | dir = new Directory(); 50 | // m = new Mkdir(); 51 | expectedVal = "/"; 52 | assertEquals(expectedVal, Pwd.printDir(dir)); 53 | } 54 | 55 | 56 | @Test 57 | public void testWhenDirectorycetoryAtTheEndOfTree() { 58 | // tests if the pwd command works when the current directory is 59 | // at the very end of the tree 60 | dir = new Directory(); 61 | m = new Mkdir(); 62 | a = new Stack(); 63 | // Populating the tree 64 | m.execute(dir, "mkdir folder1", a); 65 | Cd.switchDir(dir, "/folder1"); 66 | m.execute(dir, "mkdir folder2", a); 67 | Cd.switchDir(dir, "/folder2"); 68 | m.execute(dir, "mkdir folder3", a); 69 | Cd.switchDir(dir, "/folder3"); 70 | // Testing the pwd class 71 | expectedVal = "/folder1/folder2/folder3"; 72 | assertEquals(expectedVal, Pwd.printDir(dir)); 73 | 74 | } 75 | 76 | @Test 77 | public void testWhenDirectoryectoryIsInTheMiddleOfTree() { 78 | // test if the pwd command works when the current directory is 79 | // anywhere between the root and the last child of the tree 80 | dir = new Directory(); 81 | m = new Mkdir(); 82 | a = new Stack(); 83 | // Populating the tree 84 | m.execute(dir, "mkdir folder1", a); 85 | Cd.switchDir(dir, "/folder1"); 86 | m.execute(dir, "mkdir folder2", a); 87 | Cd.switchDir(dir, "/folder2"); 88 | m.execute(dir, "mkdir folder3", a); 89 | Cd.switchDir(dir, "/folder3"); 90 | m.execute(dir, "mkdir folder4", a); 91 | Cd.switchDir(dir, "/folder4"); 92 | m.execute(dir, "mkdir folder5", a); 93 | Cd.switchDir(dir, "/folder5"); 94 | // Making the current directory somewhere in the middle of the tree 95 | Cd.switchDir(dir, "/.."); 96 | Cd.switchDir(dir, "/.."); 97 | Cd.switchDir(dir, "/.."); 98 | // Testing the pwd class 99 | expectedVal = "/folder1/folder2"; 100 | assertEquals(expectedVal, Pwd.printDir(dir)); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/SplitPathsTest.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | 31 | package test; 32 | 33 | import static org.junit.Assert.*; 34 | import java.util.Stack; 35 | import org.junit.Test; 36 | 37 | import commands.*; 38 | import helpers.*; 39 | 40 | public class SplitPathsTest { 41 | String input = ""; // First input 42 | String[] actual = new String[2]; // Actual output 43 | String[] expected = new String[2]; // Expected output 44 | SplitPaths s = new SplitPaths(); 45 | 46 | @Test 47 | public void testSplitFull() { 48 | // Tests a split full path 49 | input = "/file1/file2/file3/file4/text.txt"; 50 | expected[0] = "/file1/file2/file3/file4/"; 51 | expected[1] = "text.txt"; 52 | actual = s.pathSplit(input); 53 | assertEquals(expected[0], actual[0]); 54 | assertEquals(expected[1], actual[1]); 55 | } 56 | 57 | @Test 58 | public void testSplitPartial() { 59 | // Tests a split partial path 60 | input = "file1/file2/file3/file4/text.txt"; 61 | expected[0] = "file1/file2/file3/file4/"; 62 | expected[1] = "text.txt"; 63 | actual = s.pathSplit(input); 64 | assertEquals(expected[0], actual[0]); 65 | assertEquals(expected[1], actual[1]); 66 | } 67 | 68 | @Test 69 | public void testSplitRoot() { 70 | // Tests a split root 71 | input = "/text.txt"; 72 | expected[0] = "/"; 73 | expected[1] = "text.txt"; 74 | actual = s.pathSplit(input); 75 | assertEquals(expected[0], actual[0]); 76 | assertEquals(expected[1], actual[1]); 77 | } 78 | 79 | @Test 80 | public void testSplitNoPath() { 81 | // Tests a split with no path 82 | input = "text.txt"; 83 | expected[0] = ""; 84 | expected[1] = "text.txt"; 85 | actual = s.pathSplit(input); 86 | assertEquals(expected[0], actual[0]); 87 | assertEquals(expected[1], actual[1]); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Mock Linux Shell in Java/src/test/TestNumber.java: -------------------------------------------------------------------------------- 1 | // ********************************************************** 2 | // Assignment2: 3 | // Student1: 4 | // UTOR user_name: sharm389 5 | // UT Student #: 1000275132 6 | // Author: Arjun Sharma 7 | // 8 | // Student2: 9 | // UTOR user_name: leejos14 10 | // UT Student #: 1001175346 11 | // Author: Joseph Lee 12 | // 13 | // Student3: 14 | // UTOR user_name: zelenenk 15 | // UT Student #: 1001400307 16 | // Author: Taras Zelenenkyy 17 | // 18 | // Student4: 19 | // UTOR user_name: ondertan 20 | // UT Student #: 1001088468 21 | // Author: Tanay Altan Onder 22 | // 23 | // 24 | // Honor Code: I pledge that this program represents my own 25 | // program code and that I have coded on my own. I received 26 | // help from no one in designing and debugging my program. 27 | // I have also read the plagiarism section in the course info 28 | // sheet of CSC 207 and understand the consequences. 29 | // ********************************************************* 30 | package test; 31 | 32 | import static org.junit.Assert.*; 33 | 34 | import java.util.Stack; 35 | 36 | import org.junit.Before; 37 | import org.junit.Test; 38 | 39 | import helpers.Directory; 40 | import helpers.File; 41 | import helpers.Tree; 42 | 43 | import org.junit.Test; 44 | 45 | import commands.Number; 46 | import commands.Cd; 47 | import commands.Cp; 48 | import commands.Ls; 49 | import commands.Mkdir; 50 | import commands.Mv; 51 | 52 | 53 | public class TestNumber { 54 | Mkdir mkdir; 55 | Directory dir; 56 | Cd cd; 57 | Cp cp; 58 | Ls ls; 59 | Mv mv; 60 | Number number; 61 | 62 | @Before 63 | public void setUp() { 64 | mkdir = new Mkdir(); 65 | dir = new Directory(); 66 | cd = new Cd(); 67 | cp = new Cp(); 68 | ls = new Ls(); 69 | mv = new Mv(); 70 | number = new Number(); 71 | } 72 | 73 | @Test 74 | public void testEmptyHistory() { 75 | Stack history = new Stack(); 76 | String test = number.recallCommand(dir, "3", history); 77 | assertEquals("Error out of bounds", test); 78 | } 79 | 80 | @Test 81 | public void testOutOfBoundsHistory() { 82 | Stack history = new Stack(); 83 | history.push("ONE"); 84 | String test = number.recallCommand(dir, "3", history); 85 | assertEquals("Error out of bounds", test); 86 | } 87 | 88 | @Test 89 | public void testWrongCommandHistory() { 90 | Stack history = new Stack(); 91 | history.push("WRONG"); 92 | history.push("WRONG"); 93 | history.push("WRONG"); 94 | String test = number.recallCommand(dir, "3", history); 95 | assertEquals("Invalid input! Please try again", test); 96 | } 97 | @Test 98 | public void testFunctionCallHistory() { 99 | Stack history = new Stack(); 100 | history.push("WRONG"); 101 | history.push("WRONG"); 102 | history.push("mkdir this"); 103 | String test = number.recallCommand(dir, "3", history); 104 | String test2 = ls.listDir(dir,"" ); 105 | assertEquals("/: this\n", test2); 106 | assertEquals("", test); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mock-Linux-Shell-in-Java 2 | In a team of 4 members we created a mock shell that implements core linux commands. All commits were made on svn and used we used the scrum approach to code this project. This project took around 1.5 months to complete and is now finished. 3 | 4 | Project can be run by downloading all files and then compiling JShell.java located in /src/Driver/JShell.java 5 | --------------------------------------------------------------------------------