-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="com.github.jnr:jnr-posix:3.0.52" level="project" /> | ||
</component> | ||
</module> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: cn.makiser.jsh.Main | ||
Class-Path: . | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: cn.makiser.jsh.Main | ||
Class-Path: . | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package cn.makiser.jsh; | ||
|
||
import cn.makiser.jsh.io.ConsolePrinter; | ||
import cn.makiser.jsh.io.ConsoleScanner; | ||
import cn.makiser.jsh.io.Printer; | ||
import cn.makiser.jsh.io.Scanner; | ||
import cn.makiser.jsh.plugin.Plugin; | ||
import cn.makiser.jsh.plugin.PluginLoader; | ||
import cn.makiser.jsh.plugin.SystemBasicPlugin; | ||
import cn.makiser.jsh.shell.JavaShell; | ||
import jnr.posix.POSIX; | ||
import jnr.posix.POSIXFactory; | ||
import jnr.posix.util.DefaultPOSIXHandler; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Main { | ||
public static final POSIX posix = POSIXFactory | ||
.getPOSIX(new DefaultPOSIXHandler(), true); | ||
|
||
public final static List<Plugin> plugins = new ArrayList<>(); | ||
public static Printer lc_printer = new ConsolePrinter(); | ||
public static Scanner lc_scanner = new ConsoleScanner(); | ||
private static File workspace = null; | ||
|
||
public static void main(String[] args) { | ||
Main.lc_printer.println("JavaShell - Pd2's Shell"); | ||
try { | ||
R.freshAll(); | ||
Main.lc_printer.println( | ||
"VERSION: " + R.s_strings.get("jsh-version") + "\n" + | ||
"Copyright (c) 2020, Makiser_Tech."); | ||
workspace = new File(args[0]); | ||
if(!workspace.exists()) { | ||
workspace.mkdirs(); | ||
} | ||
//加载插件 | ||
File path = new File(workspace.getAbsolutePath() + "/plugins"); | ||
if(!path.exists()) { | ||
path.mkdir(); | ||
} | ||
File[] jars = path.listFiles(); | ||
assert jars != null; | ||
if(jars.length != 0) { | ||
for (File jar : jars) { | ||
PluginLoader loader = new PluginLoader(jar); | ||
Plugin plugin = loader.load(); | ||
plugins.add(plugin); | ||
} | ||
String s = R.strings.get("shell.plugin_load") | ||
.replaceAll("\\$num", String.valueOf(jars.length)); | ||
Main.lc_printer.println(s); | ||
} | ||
//加载系统组件 | ||
Plugin systemBasicPlugin = new SystemBasicPlugin(); | ||
plugins.add(systemBasicPlugin); | ||
//启动Shell | ||
JavaShell shell = new JavaShell(); | ||
shell.run(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
System.out.println('\n'); | ||
} | ||
} | ||
|
||
//get&set | ||
public static File getWorkspace() { | ||
return workspace; | ||
} | ||
|
||
public static void exit(int status) { | ||
System.exit(status); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package cn.makiser.jsh; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class R { | ||
public static final Map<String, String> strings = new HashMap<>(); | ||
public static final Map<String, String> s_strings = new HashMap<>(); | ||
|
||
public static void freshAll() { | ||
s_strings.put("jsh-version", "Alpha 1.0.1"); | ||
strings.put("shell.cmd_conflict1", "插件指令发生冲突, 是否继续加载?\n" + | ||
"若继续, 已载入的指令将被即将载入的覆盖."); | ||
strings.put("shell.cmd_conflict2", "您可以用指令 'jsh-info plugin.command' " + | ||
"输出各插件注册指令, 查看在何处发生冲突."); | ||
strings.put("shell.cmd_not_found", "未找到该指令, 请检查输入是否有误(区分大小写)."); | ||
strings.put("shell.plugin_load", "已载入 $num 个插件"); | ||
strings.put("cd.not_found", "目录不存在"); | ||
s_strings.put("at", "在"); | ||
s_strings.put("and", "和"); | ||
s_strings.put("info", "[信息] "); | ||
s_strings.put("warn", "[警告] "); | ||
s_strings.put("err", "[错误] "); | ||
s_strings.put("stop", "终止"); | ||
s_strings.put("exit", "退出"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package cn.makiser.jsh.io; | ||
|
||
public class ConsolePrinter implements Printer { | ||
@Override | ||
public void print(Object o) { | ||
System.out.print(o); | ||
} | ||
@Override | ||
public void println(Object o) { | ||
System.out.println(o); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cn.makiser.jsh.io; | ||
|
||
public class ConsoleScanner implements Scanner { | ||
java.util.Scanner scanner = new java.util.Scanner(System.in); | ||
|
||
@Override | ||
public String getLine() { | ||
return scanner.nextLine(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package cn.makiser.jsh.io; | ||
|
||
public interface Printer { | ||
void print(Object o); | ||
void println(Object o); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package cn.makiser.jsh.io; | ||
|
||
public interface Scanner { | ||
String getLine(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package cn.makiser.jsh.plugin; | ||
|
||
public class Manifest { | ||
public String runnableClass = "cn.makiser.jsh.plugin.Runnable"; | ||
|
||
public String pluginPackage = "cn.makiser.jsh.plugin"; | ||
public String pluginName = "Plugin"; | ||
public String pluginInfo = "There is nothing."; | ||
public String versionName = "1.0.0"; | ||
public Integer versionCode = 1; | ||
} |