Skip to content

Commit 37cdb65

Browse files
committed
Command Searching
View changelog entry #101 for details.
1 parent 3078445 commit 37cdb65

File tree

7 files changed

+147
-36
lines changed

7 files changed

+147
-36
lines changed

ROADMAP.md

+9-10
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ This section provides a list of "foundational" elements that MUST be finished be
3535
- [ ] Files
3636
- [x] Reading (I #16) (PR #17) (CL #68)
3737
- [x] Writing (PR #1) (CL #9)
38-
- [ ] Moving
38+
- [x] Moving (I #81) (PR #79) (CL #101)
3939
- [x] Deleting (PR #5) (CL #40)
4040
- [ ] Editing
41-
- [ ] Renaming
42-
- [ ] Directories
41+
- [x] Renaming (PR #67) (CL #101)
42+
- [x] Directories
4343
- [x] Listing (PR #2) (CL #17)
44-
- [ ] Moving
44+
- [x] Moving (PR #79) (CL #101)
4545
- [x] Change working directory (PR #3) (CL #28)
46-
- [ ] Deleting
46+
- [x] Deleting (PR #67) (CL #101)
4747
- [x] Creating (PR #5) (CL #41)
48-
- [ ] Renaming
49-
- [x] Clear screen (I #33) (PR #44)
50-
- [ ] Full help information (I #40)
51-
- [ ] Command help (`-h`/`help`)
48+
- [x] Renaming (PR #67) (CL #101)
49+
- [x] Clear screen (I #33) (PR #44) (CL #91)
50+
- [x] Full help information (I #40) (PR #79) (CL #101)
51+
- [x] Command help (`-h`/`help`) (I #40) (PR #79) (CL #101)
5252
- [x] Run external executable programs (I #32) (PR #46) (CL #93)
5353
- [x] Tab completion (I #31) (PR #34) (CL #88)
5454
- [x] System process listing (PR #9) (CL #60)
@@ -57,7 +57,6 @@ This section provides a list of "foundational" elements that MUST be finished be
5757
- [ ] Environment Variables (I #) (CL #74)
5858
- [ ] Create new terminal window instance
5959
- [x] Internet file downloader (I #45) (PR #61) (CL #96)
60-
- [x] Internet file downloader (I #45)
6160

6261
## Tracking
6362
To track this list, it is placed in the [v1.0.0 Roadmap](https://github.com/Sergix/JTerm/milestone/1) milestone. All Issues and Pull Requests that are designated to complete a task on the milestone tracker should be marked as so.

build.bat

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ cls
33

44
rd /S /Q target
55

6-
mvn clean package
6+
mvn -e clean package
7+
run

changelog.txt

+63-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,65 @@
1-
(#100)[11/8/2017-13:28 0.6.2 ojles]
1+
(#101)[11/19/2017-16:23 0.6.1 Sergix]
2+
Removed org.reflections import. JTerm.initCommands() has been updated to compensate.
3+
Closed #40.
4+
Closed #47.
5+
- PR #78.
6+
Closed #48.
7+
Closed #52 (wontfix).
8+
Closed #53.
9+
Closed #71.
10+
- PR #74.
11+
Closed #73.
12+
Closed #75.
13+
Closed PR #77.
14+
- PR #79.
15+
Closed #81.
16+
Closed PR #82.
17+
- PR #83.
18+
Merged #74.
19+
- Thanks @lbenedetto!
20+
- Added a fully functioning JavaX GUI!
21+
- Runs commands without recreating anything.
22+
- Added log functions to JTerm.java
23+
- log()
24+
- logln()
25+
- All output should be through these from now on.
26+
- Added ProtectedDocument class
27+
- Added ProtectedTextComponent class
28+
- Added Terminal class (GUI)
29+
- Added com.intellij.forms_rt import for Terminal.form GUI layout.
30+
Merged #78.
31+
- Thanks @nanoandrew4!
32+
- Added ArrowKeyHandler class.
33+
- Added ArrowKeys enum.
34+
- Added Command enum.
35+
- Added KeyHandler class.
36+
- Added Keys enum.
37+
- Moved UNIX and Windows input functions from Input class to UnixInput and WinInput classes, respectively.
38+
- Added FileAutocomplete class.
39+
- Added Util functions.
40+
- removeSpaces()
41+
- containsOnlySpaces()
42+
Merged #67, #79.
43+
- Thanks @ojles!
44+
- Added a Command interface.
45+
- Command methods now have a @Command annotation.
46+
- All commands are automatically updated and stored in a global hashmap.
47+
- Added target/ to .gitignore.
48+
- Added CommandException class.
49+
- Added functions to Util.java.
50+
- getRunTime()
51+
- clearLine()
52+
- getAsArray()
53+
- getAsString()
54+
- getRest()
55+
- getFullPath()
56+
Merged #83.
57+
- Thanks @Kaperskyguru!
58+
- Created Files.move()
59+
Updated ROADMAP.md.
60+
Pushed updates to Git.
61+
62+
(#100)[11/8/2017-13:28 0.6.1 ojles]
263
Added Command interface with execute() method
364
Added CommandException for package jterm.command.*
465
Implemented Command interface in all command classes
@@ -7,6 +68,7 @@
768
Moved helper methods from JTerm to Util.java
869
Fixed ping command
970
Fixed Exec.java, witch was not printing all the data got from the executed process
71+
1072
(#99)[11/5/2017-14:50 0.6.1 Sergix]
1173
Removed lang3 dependency from POM and all imports.
1274
Fixed issue where InputHandler was outputting an extra newline.

pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@
5757
</build>
5858

5959
<dependencies>
60-
<dependency>
61-
<groupId>org.reflections</groupId>
62-
<artifactId>reflections</artifactId>
63-
<version>0.9.10</version>
64-
</dependency>
6560
<dependency>
6661
<groupId>junit</groupId>
6762
<artifactId>junit-dep</artifactId>

run.bat

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
set option="nogui"
44

55
cd target
6-
if EXIST "jterm-%JTERM_VERSION%-jar-with-dependencies.jar" (
6+
if exist "jterm-%JTERM_VERSION%-jar-with-dependencies.jar" (
77
ren jterm-%JTERM_VERSION%.jar jterm-%JTERM_VERSION%-no-deps.jar
88
ren jterm-%JTERM_VERSION%-jar-with-dependencies.jar jterm-v%JTERM_VERSION%.jar
99
)
1010

11-
if %1 EQU %option% (
11+
if not exist "jterm-v%JTERM_VERSION%.jar" (
12+
exit
13+
)
14+
15+
if "%1" EQU %option% (
1216
java -jar jterm-v%JTERM_VERSION%.jar headless
1317
) else (
1418
java -jar jterm-v%JTERM_VERSION%.jar

src/main/java/jterm/JTerm.java

+65-5
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,26 @@
2323
import jterm.gui.Terminal;
2424
import jterm.io.InputHandler;
2525
import jterm.util.Util;
26-
import org.reflections.Reflections;
27-
import org.reflections.scanners.MethodAnnotationsScanner;
2826

2927
import javax.swing.*;
3028
import java.io.BufferedReader;
3129
import java.io.InputStreamReader;
3230
import java.lang.reflect.InvocationTargetException;
3331
import java.lang.reflect.Method;
32+
import java.lang.reflect.Constructor;
33+
import java.lang.annotation.Annotation;
3434
import java.util.HashMap;
3535
import java.util.List;
3636
import java.util.Map;
3737
import java.util.Set;
38+
import java.util.ArrayList;
39+
import java.util.zip.ZipEntry;
40+
import java.util.zip.ZipInputStream;
41+
import java.net.URLDecoder;
42+
import java.net.URL;
43+
import java.io.File;
44+
import java.io.IOException;
45+
import java.security.CodeSource;
3846

3947
public class JTerm {
4048
private static final Map<String, CommandExecutor> COMMANDS = new HashMap<>();
@@ -104,8 +112,61 @@ public static void executeCommand(String options) {
104112
}
105113

106114
private static void initCommands() {
107-
Reflections reflections = new Reflections("jterm.command", new MethodAnnotationsScanner());
108-
Set<Method> methods = reflections.getMethodsAnnotatedWith(Command.class);
115+
// Reflections reflections = new Reflections("jterm.command", new MethodAnnotationsScanner());
116+
// Set<Method> methods = reflections.getMethodsAnnotatedWith(Command.class);
117+
ArrayList<Method> methods = new ArrayList<Method>();
118+
Method[] unsortedMethods = {};
119+
ArrayList<String> classes = new ArrayList<String>();
120+
121+
try {
122+
CodeSource src = JTerm.class.getProtectionDomain().getCodeSource();
123+
if (src != null) {
124+
URL jar = src.getLocation();
125+
ZipInputStream zip = new ZipInputStream(jar.openStream());
126+
while (true) {
127+
ZipEntry e = zip.getNextEntry();
128+
if (e == null)
129+
break;
130+
String name = e.getName();
131+
if (name.startsWith("jterm/command")) {
132+
classes.add(
133+
name.replace('/', '.')
134+
.substring(0, name.length() - 6)
135+
);
136+
}
137+
}
138+
}
139+
} catch (IOException ioe) {
140+
System.out.println(ioe);
141+
}
142+
143+
classes.remove(0);
144+
145+
for (int i = 0; i < classes.size(); i++) {
146+
try {
147+
Class<?> clazz = Class.forName(classes.get(i));
148+
Constructor<?> constructor = clazz.getConstructor();
149+
Object obj = constructor.newInstance();
150+
151+
unsortedMethods = obj.getClass().getDeclaredMethods();
152+
for (Method method : unsortedMethods) {
153+
Annotation[] annotations = method.getDeclaredAnnotations();
154+
if (method.isAnnotationPresent(Command.class)) {
155+
methods.add(method);
156+
}
157+
}
158+
} catch (ClassNotFoundException cnfe) {
159+
System.out.println(cnfe);
160+
} catch (NoSuchMethodException nsme) {
161+
// System.out.println(nsme);
162+
} catch (InstantiationException ie) {
163+
// System.out.println(ie);
164+
} catch (IllegalAccessException iae) {
165+
System.out.println(iae);
166+
} catch (InvocationTargetException iae) {
167+
// System.out.println(iae);
168+
}
169+
}
109170

110171
for (Method method : methods) {
111172
method.setAccessible(true);
@@ -117,7 +178,6 @@ private static void initCommands() {
117178
.setMinOptions(command.minOptions())
118179
.setCommand((List<String> options) -> {
119180
try {
120-
System.out.println(options);
121181
method.invoke(null, options);
122182
} catch (Exception e) {
123183
System.err.println("Weird stuff...");

src/main/java/jterm/command/Files.java

+2-12
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
import static jterm.JTerm.logln;
3434

3535
public class Files {
36-
@Command(name = "mv", minOptions = 2)
36+
// @ojles and @Kaperskyguru
37+
@Command(name = "mv", "move", minOptions = 2)
3738
public static void move(List<String> options) {
3839
String sourceName = Util.getFullPath(options.get(0));
3940
String destinationName = Util.getFullPath(options.get(1));
@@ -205,15 +206,4 @@ public static void download(List<String> options) {
205206
Util.clearLine(update, false);
206207
logln("\nFile downloaded successfully in: " + Util.getRunTime(System.currentTimeMillis() - start), true);
207208
}
208-
209-
@Command(name = {"move", "mv"}, minOptions = 2)
210-
public static void moveFile(File fileName, String newLocation){
211-
if(fileName.renameTo(new File(newLocation + fileName.getName()))){
212-
System.out.println(fileName + "Successfully Moved");
213-
}else{
214-
System.out.println(fileName + "Failed to Moved");
215-
}
216-
217-
}
218-
219209
}

0 commit comments

Comments
 (0)