Skip to content
This repository has been archived by the owner on Dec 3, 2022. It is now read-only.

Commit

Permalink
完善核心功能
Browse files Browse the repository at this point in the history
  • Loading branch information
maxelblack committed Jul 22, 2020
1 parent 68f0b7d commit c1075c6
Show file tree
Hide file tree
Showing 28 changed files with 675 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/artifacts/JavaShell_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/description.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions .idea/libraries/com_github_jnr_jnr_posix_3_0_52.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/project-template.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions JavaShell.iml
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>
4 changes: 4 additions & 0 deletions out/production/JavaShell/META-INF/MANIFEST.MF
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: .

4 changes: 4 additions & 0 deletions src/META-INF/MANIFEST.MF
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: .

76 changes: 76 additions & 0 deletions src/cn/makiser/jsh/Main.java
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);
}
}
27 changes: 27 additions & 0 deletions src/cn/makiser/jsh/R.java
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", "退出");
}
}
12 changes: 12 additions & 0 deletions src/cn/makiser/jsh/io/ConsolePrinter.java
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);
}
}
10 changes: 10 additions & 0 deletions src/cn/makiser/jsh/io/ConsoleScanner.java
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();
}
}
6 changes: 6 additions & 0 deletions src/cn/makiser/jsh/io/Printer.java
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);
}
5 changes: 5 additions & 0 deletions src/cn/makiser/jsh/io/Scanner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cn.makiser.jsh.io;

public interface Scanner {
String getLine();
}
11 changes: 11 additions & 0 deletions src/cn/makiser/jsh/plugin/Manifest.java
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;
}
Loading

0 comments on commit c1075c6

Please sign in to comment.