├── .gitignore ├── LICENSE ├── README.md ├── build.sh ├── pom.xml ├── resourse ├── cd.png ├── command.jpg ├── commandList.jpg ├── command_demo.jpg ├── def.jpg ├── pipe.png ├── plugins.png ├── proc_exec.jpg ├── proc_list.jpg ├── proc_save.jpg ├── quit.jpg ├── start.png ├── xpocket.jpg └── xpocket_plugin.jpg ├── xpocket-agent ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── perfma │ │ └── xlab │ │ └── xpocket │ │ └── agent │ │ ├── XPocketAgent.java │ │ └── classloader │ │ └── XPocketAgentClassLoader.java │ └── resources │ └── META-INF │ └── MANIFEST.MF ├── xpocket-bridge ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── perfma │ └── xlab │ └── xpocket │ └── bridge │ ├── XpocketPluginBridge.java │ ├── dto │ └── Result.java │ ├── execution │ ├── BridgeExecutionExecutionEngineImpl.java │ ├── BridgeExecutionPipeLine.java │ ├── BridgeNamedObject.java │ └── ExecutionEngineHolder.java │ └── process │ ├── BridgeProcessDefinition.java │ └── BridgeXpocketProcess.java ├── xpocket-deploy ├── assembly │ └── assembly.xml ├── config │ └── logo.txt ├── plugins │ └── .dir ├── pom.xml ├── scripts │ ├── xpocket.bat │ ├── xpocket.sh │ ├── xpocket_jdk8.bat │ ├── xpocket_jdk8.sh │ ├── xpocket_jdk9+.bat │ └── xpocket_jdk9+.sh ├── scrolls │ └── .dir └── tools │ ├── linux │ └── tools.jar │ ├── macosx │ └── tools.jar │ └── windows │ ├── attach.dll │ └── tools.jar ├── xpocket-framework-spi ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── perfma │ └── xlab │ └── xpocket │ └── plugin │ ├── base │ └── NamedObject.java │ ├── command │ └── CommandLoader.java │ ├── context │ └── FrameworkPluginContext.java │ ├── execution │ ├── ExecutionEngine.java │ ├── Node.java │ └── XpocketProcessInfo.java │ ├── loader │ ├── NonavailablePluginLoader.java │ └── PluginLoader.java │ ├── manager │ ├── CommandManager.java │ ├── ExecutionManager.java │ ├── MainUIManager.java │ └── PluginManager.java │ ├── ui │ └── UIEngine.java │ └── util │ ├── Constants.java │ └── ServiceLoaderUtils.java ├── xpocket-jline ├── pom.xml └── src │ └── main │ ├── java │ ├── jline │ │ ├── AnsiWindowsTerminal.java │ │ ├── DefaultTerminal2.java │ │ ├── NoInterruptUnixTerminal.java │ │ ├── OSvTerminal.java │ │ ├── Terminal.java │ │ ├── Terminal2.java │ │ ├── TerminalFactory.java │ │ ├── TerminalSupport.java │ │ ├── UnixTerminal.java │ │ ├── UnsupportedTerminal.java │ │ ├── WindowsTerminal.java │ │ ├── console │ │ │ ├── ConsoleKeys.java │ │ │ ├── ConsoleReader.java │ │ │ ├── CursorBuffer.java │ │ │ ├── KeyMap.java │ │ │ ├── KillRing.java │ │ │ ├── Operation.java │ │ │ ├── UserInterruptException.java │ │ │ ├── WCWidth.java │ │ │ ├── completer │ │ │ │ ├── AggregateCompleter.java │ │ │ │ ├── AnsiStringsCompleter.java │ │ │ │ ├── ArgumentCompleter.java │ │ │ │ ├── CandidateListCompletionHandler.java │ │ │ │ ├── Completer.java │ │ │ │ ├── CompletionHandler.java │ │ │ │ ├── EnumCompleter.java │ │ │ │ ├── FileNameCompleter.java │ │ │ │ ├── NullCompleter.java │ │ │ │ ├── StringsCompleter.java │ │ │ │ └── package-info.java │ │ │ ├── history │ │ │ │ ├── FileHistory.java │ │ │ │ ├── History.java │ │ │ │ ├── MemoryHistory.java │ │ │ │ ├── PersistentHistory.java │ │ │ │ └── package-info.java │ │ │ ├── internal │ │ │ │ ├── ConsoleReaderInputStream.java │ │ │ │ └── ConsoleRunner.java │ │ │ └── package-info.java │ │ ├── internal │ │ │ ├── Ansi.java │ │ │ ├── Configuration.java │ │ │ ├── Curses.java │ │ │ ├── InfoCmp.java │ │ │ ├── InputStreamReader.java │ │ │ ├── Log.java │ │ │ ├── NonBlockingInputStream.java │ │ │ ├── Nullable.java │ │ │ ├── Preconditions.java │ │ │ ├── ShutdownHooks.java │ │ │ ├── TerminalLineSettings.java │ │ │ ├── TestAccessible.java │ │ │ ├── Urls.java │ │ │ └── package-info.java │ │ └── package-info.java │ └── org │ │ └── jline │ │ ├── builtins │ │ ├── Builtins.java │ │ ├── Commands.java │ │ ├── Completers.java │ │ ├── ConsoleEngine.java │ │ ├── ConsoleEngineImpl.java │ │ ├── InputRC.java │ │ ├── JlineCommandRegistry.java │ │ ├── Less.java │ │ ├── Nano.java │ │ ├── NfaMatcher.java │ │ ├── Options.java │ │ ├── ScreenTerminal.java │ │ ├── Source.java │ │ ├── Styles.java │ │ ├── SystemRegistry.java │ │ ├── SystemRegistryImpl.java │ │ ├── TTop.java │ │ ├── Tmux.java │ │ ├── Widgets.java │ │ └── telnet │ │ │ ├── Connection.java │ │ │ ├── ConnectionData.java │ │ │ ├── ConnectionEvent.java │ │ │ ├── ConnectionFilter.java │ │ │ ├── ConnectionListener.java │ │ │ ├── ConnectionManager.java │ │ │ ├── PortListener.java │ │ │ ├── Telnet.java │ │ │ └── TelnetIO.java │ │ ├── console │ │ ├── AbstractCommandRegistry.java │ │ ├── ArgDesc.java │ │ ├── CmdDesc.java │ │ ├── CommandInput.java │ │ ├── CommandMethods.java │ │ ├── CommandRegistry.java │ │ ├── ConfigurationPath.java │ │ ├── Printer.java │ │ └── ScriptEngine.java │ │ ├── keymap │ │ ├── BindingReader.java │ │ └── KeyMap.java │ │ ├── reader │ │ ├── Binding.java │ │ ├── Buffer.java │ │ ├── Candidate.java │ │ ├── Completer.java │ │ ├── CompletingParsedLine.java │ │ ├── EOFError.java │ │ ├── Editor.java │ │ ├── EndOfFileException.java │ │ ├── Expander.java │ │ ├── Highlighter.java │ │ ├── History.java │ │ ├── LineReader.java │ │ ├── LineReaderBuilder.java │ │ ├── Macro.java │ │ ├── MaskingCallback.java │ │ ├── ParsedLine.java │ │ ├── Parser.java │ │ ├── Reference.java │ │ ├── SyntaxError.java │ │ ├── UserInterruptException.java │ │ ├── Widget.java │ │ ├── impl │ │ │ ├── BufferImpl.java │ │ │ ├── DefaultExpander.java │ │ │ ├── DefaultHighlighter.java │ │ │ ├── DefaultParser.java │ │ │ ├── KillRing.java │ │ │ ├── LineReaderImpl.java │ │ │ ├── ReaderUtils.java │ │ │ ├── SimpleMaskingCallback.java │ │ │ ├── UndoTree.java │ │ │ ├── completer │ │ │ │ ├── AggregateCompleter.java │ │ │ │ ├── ArgumentCompleter.java │ │ │ │ ├── EnumCompleter.java │ │ │ │ ├── FileNameCompleter.java │ │ │ │ ├── NullCompleter.java │ │ │ │ ├── StringsCompleter.java │ │ │ │ ├── SystemCompleter.java │ │ │ │ └── package-info.java │ │ │ └── history │ │ │ │ ├── DefaultHistory.java │ │ │ │ └── package-info.java │ │ └── package-info.java │ │ ├── terminal │ │ ├── Attributes.java │ │ ├── Cursor.java │ │ ├── MouseEvent.java │ │ ├── Size.java │ │ ├── Terminal.java │ │ ├── TerminalBuilder.java │ │ ├── impl │ │ │ ├── AbstractPosixTerminal.java │ │ │ ├── AbstractPty.java │ │ │ ├── AbstractTerminal.java │ │ │ ├── AbstractWindowsConsoleWriter.java │ │ │ ├── AbstractWindowsTerminal.java │ │ │ ├── CursorSupport.java │ │ │ ├── DumbTerminal.java │ │ │ ├── ExecPty.java │ │ │ ├── ExternalTerminal.java │ │ │ ├── LineDisciplineTerminal.java │ │ │ ├── MouseSupport.java │ │ │ ├── NativeSignalHandler.java │ │ │ ├── PosixPtyTerminal.java │ │ │ ├── PosixSysTerminal.java │ │ │ ├── jansi │ │ │ │ ├── JansiNativePty.java │ │ │ │ ├── JansiSupportImpl.java │ │ │ │ ├── freebsd │ │ │ │ │ └── FreeBsdNativePty.java │ │ │ │ ├── linux │ │ │ │ │ └── LinuxNativePty.java │ │ │ │ ├── osx │ │ │ │ │ └── OsXNativePty.java │ │ │ │ ├── solaris │ │ │ │ │ └── SolarisNativePty.java │ │ │ │ └── win │ │ │ │ │ ├── JansiWinConsoleWriter.java │ │ │ │ │ ├── JansiWinSysTerminal.java │ │ │ │ │ └── WindowsAnsiWriter.java │ │ │ └── package-info.java │ │ └── spi │ │ │ ├── JansiSupport.java │ │ │ ├── JnaSupport.java │ │ │ └── Pty.java │ │ └── utils │ │ ├── AnsiWriter.java │ │ ├── AttributedCharSequence.java │ │ ├── AttributedString.java │ │ ├── AttributedStringBuilder.java │ │ ├── AttributedStyle.java │ │ ├── ClosedException.java │ │ ├── Colors.java │ │ ├── Curses.java │ │ ├── DiffHelper.java │ │ ├── Display.java │ │ ├── ExecHelper.java │ │ ├── InfoCmp.java │ │ ├── InputStreamReader.java │ │ ├── Levenshtein.java │ │ ├── Log.java │ │ ├── NonBlocking.java │ │ ├── NonBlockingInputStream.java │ │ ├── NonBlockingInputStreamImpl.java │ │ ├── NonBlockingPumpInputStream.java │ │ ├── NonBlockingPumpReader.java │ │ ├── NonBlockingReader.java │ │ ├── NonBlockingReaderImpl.java │ │ ├── OSUtils.java │ │ ├── PumpReader.java │ │ ├── ShutdownHooks.java │ │ ├── Signals.java │ │ ├── Status.java │ │ ├── StyleResolver.java │ │ ├── WCWidth.java │ │ ├── WriterOutputStream.java │ │ └── package-info.java │ └── resources │ ├── META-INF │ ├── native-image │ │ └── jline │ │ │ └── resource-config.json │ └── services │ │ └── org.jline.terminal.spi.JansiSupport │ ├── jline │ └── console │ │ └── completer │ │ └── CandidateListCompletionHandler.properties │ └── org │ └── jline │ ├── builtins │ ├── less-help.txt │ ├── nano-browser-help.txt │ ├── nano-goto-help.txt │ ├── nano-main-help.txt │ ├── nano-read-help.txt │ ├── nano-replace-help.txt │ ├── nano-search-help.txt │ ├── nano-search-replace-help.txt │ └── nano-write-help.txt │ └── utils │ ├── ansi.caps │ ├── capabilities.txt │ ├── colors.txt │ ├── dumb-color.caps │ ├── dumb.caps │ ├── rxvt-basic.cap │ ├── rxvt-unicode-256color.cap │ ├── rxvt-unicode.cap │ ├── rxvt.cap │ ├── screen-256color.caps │ ├── screen.caps │ ├── windows-256color.caps │ ├── windows-conemu.caps │ ├── windows-vtp.caps │ ├── windows.caps │ ├── xterm-256color.caps │ └── xterm.caps ├── xpocket-plugin-spi ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── perfma │ └── xlab │ └── xpocket │ └── spi │ ├── AbstractXPocketAgentPlugin.java │ ├── AbstractXPocketPlugin.java │ ├── XPocketAgentPlugin.java │ ├── XPocketPlugin.java │ ├── command │ ├── AbstractXPocketCommand.java │ ├── CommandInfo.java │ ├── CommandInfos.java │ ├── CommandList.java │ ├── XPocketCommand.java │ ├── XPocketProcessTemplate.java │ └── callback │ │ ├── ProcessCallback.java │ │ └── SimpleProcessCallback.java │ ├── context │ ├── CommandBaseInfo.java │ ├── ExecuteContext.java │ ├── JavaTarget.java │ ├── PluginBaseInfo.java │ ├── PluginType.java │ └── SessionContext.java │ └── process │ ├── XPocketProcess.java │ └── XPocketProcessAction.java ├── xpocket-runtime ├── pom.xml └── src │ └── main │ ├── java │ ├── com │ │ └── perfma │ │ │ └── xlab │ │ │ └── xpocket │ │ │ ├── classloader │ │ │ └── XPocketPluginClassLoader.java │ │ │ ├── command │ │ │ ├── AbstractSystemCommand.java │ │ │ └── impl │ │ │ │ ├── AttachCommand.java │ │ │ │ ├── CdCommand.java │ │ │ │ ├── ClearCommand.java │ │ │ │ ├── DetachCommand.java │ │ │ │ ├── EchoCommand.java │ │ │ │ ├── GrepCommand.java │ │ │ │ ├── HelpCommand.java │ │ │ │ ├── HistoryCommand.java │ │ │ │ ├── JPSCommand.java │ │ │ │ ├── KillCommand.java │ │ │ │ ├── ListPluginsCommand.java │ │ │ │ ├── QuitCommand.java │ │ │ │ ├── ScrollOperations.java │ │ │ │ ├── SessionCommand.java │ │ │ │ ├── SplitCommand.java │ │ │ │ ├── SysCommand.java │ │ │ │ ├── TTopCommand.java │ │ │ │ ├── TopCommand.java │ │ │ │ ├── TrimCommand.java │ │ │ │ ├── UseCommand.java │ │ │ │ └── VersionCommand.java │ │ │ ├── completer │ │ │ ├── CommandCompleter.java │ │ │ ├── GroupStringCompleter.java │ │ │ └── ParamsCompleter.java │ │ │ ├── console │ │ │ ├── EndOfInputException.java │ │ │ └── Output.java │ │ │ ├── context │ │ │ ├── AbstractExecuteContext.java │ │ │ ├── DefaultExecuteContext.java │ │ │ └── ExecuteContextWrapper.java │ │ │ ├── framework │ │ │ └── spi │ │ │ │ ├── execution │ │ │ │ └── pipeline │ │ │ │ │ ├── DefaultNode.java │ │ │ │ │ ├── DefaultProcessDefinition.java │ │ │ │ │ ├── DefaultProcessInfo.java │ │ │ │ │ ├── DefaultXPocketProcess.java │ │ │ │ │ ├── ExecutionPipeLine.java │ │ │ │ │ └── XPocketProcessOutputStream.java │ │ │ │ └── impl │ │ │ │ ├── CommandProcessor.java │ │ │ │ ├── DefaultCommandContext.java │ │ │ │ ├── DefaultCommandLoader.java │ │ │ │ ├── DefaultExecutionEngine.java │ │ │ │ ├── DefaultNamedObject.java │ │ │ │ ├── DefaultPluginContext.java │ │ │ │ ├── DefaultPluginLoader.java │ │ │ │ ├── DefaultUIEngine.java │ │ │ │ ├── XPocketStatusContext.java │ │ │ │ ├── agent │ │ │ │ ├── AgentNamedObject.java │ │ │ │ ├── AgentPluginLoaderImpl.java │ │ │ │ ├── AgentUIEngineImpl.java │ │ │ │ ├── XPocketAgentLauncher.java │ │ │ │ └── XPocketAgentShellProvider.java │ │ │ │ ├── agentlauncher │ │ │ │ ├── AgentLauncherNamedObject.java │ │ │ │ └── AgentLauncherUIEngineImpl.java │ │ │ │ ├── mxbean │ │ │ │ ├── MXBeanNamedObject.java │ │ │ │ ├── MXBeanUIEngineImpl.java │ │ │ │ └── XPocketMXBeanServiceImpl.java │ │ │ │ ├── once │ │ │ │ ├── OnceExecutionExecutionEngineImpl.java │ │ │ │ ├── OnceExecutionUIEngineImpl.java │ │ │ │ └── OnceNamedObject.java │ │ │ │ └── telnet │ │ │ │ ├── TelnetNamedObject.java │ │ │ │ └── TelnetUIEngineImpl.java │ │ │ ├── launcher │ │ │ └── XPocketLauncher.java │ │ │ ├── linereader │ │ │ └── XPocketLineReader.java │ │ │ ├── localjvm │ │ │ └── JvmPid.java │ │ │ ├── plugin │ │ │ └── adaptor │ │ │ │ └── JavaAgentCommandAdaptor.java │ │ │ ├── structure │ │ │ └── Pair.java │ │ │ └── utils │ │ │ ├── AsciiArtUtil.java │ │ │ ├── InternalVariableParse.java │ │ │ ├── JarUtils.java │ │ │ ├── LogoPrinter.java │ │ │ ├── ProcessUtil.java │ │ │ ├── RegexUtil.java │ │ │ ├── StringUtils.java │ │ │ ├── TerminalUtil.java │ │ │ ├── XPocketBanner.java │ │ │ ├── XPocketCommandHelper.java │ │ │ └── XPocketConstants.java │ └── org │ │ └── apache │ │ └── commons │ │ └── net │ │ ├── DatagramSocketClient.java │ │ ├── DatagramSocketFactory.java │ │ ├── DefaultDatagramSocketFactory.java │ │ ├── DefaultSocketFactory.java │ │ ├── MalformedServerReplyException.java │ │ ├── PrintCommandListener.java │ │ ├── ProtocolCommandEvent.java │ │ ├── ProtocolCommandListener.java │ │ ├── ProtocolCommandSupport.java │ │ ├── SocketClient.java │ │ ├── telnet │ │ ├── EchoOptionHandler.java │ │ ├── InvalidTelnetOptionException.java │ │ ├── SimpleOptionHandler.java │ │ ├── SuppressGAOptionHandler.java │ │ ├── Telnet.java │ │ ├── TelnetClient.java │ │ ├── TelnetCommand.java │ │ ├── TelnetInputListener.java │ │ ├── TelnetInputStream.java │ │ ├── TelnetNotificationHandler.java │ │ ├── TelnetOption.java │ │ ├── TelnetOptionHandler.java │ │ ├── TelnetOutputStream.java │ │ ├── TerminalTypeOptionHandler.java │ │ └── WindowSizeOptionHandler.java │ │ └── util │ │ └── ListenerList.java │ └── resources │ ├── META-INF │ └── services │ │ ├── com.perfma.xlab.xpocket.plugin.command.CommandLoader │ │ ├── com.perfma.xlab.xpocket.plugin.execution.ExecutionEngine │ │ ├── com.perfma.xlab.xpocket.plugin.loader.PluginLoader │ │ └── com.perfma.xlab.xpocket.plugin.ui.UIEngine │ └── asciiart │ └── asciiartdb ├── xpocket-scroll ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── perfma │ │ └── xlab │ │ └── xpocket │ │ └── scroll │ │ ├── ScriptName.java │ │ ├── Scroll.java │ │ ├── ScrollConstants.java │ │ ├── compile │ │ ├── ScrollCompiler.java │ │ └── ScrollScriptCompiler.java │ │ ├── exception │ │ └── ScrollParseException.java │ │ ├── groovy │ │ ├── BytesOutputCompilationUnit.java │ │ ├── BytesOutputCompiler.java │ │ ├── DynamicClassLoader.java │ │ ├── GroovyName.java │ │ ├── GroovyScriptCompiler.java │ │ └── GroovyScriptRunner.java │ │ ├── run │ │ ├── ScrollRunner.java │ │ └── ScrollScriptRunner.java │ │ └── utils │ │ └── BytesUtils.java │ └── resources │ └── META-INF │ └── services │ ├── com.perfma.xlab.xpocket.scroll.compile.ScrollScriptCompiler │ └── com.perfma.xlab.xpocket.scroll.run.ScrollScriptRunner ├── xpocket-sdk ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── perfma │ │ └── xlab │ │ └── xpocket │ │ └── rumtime │ │ └── spi │ │ └── impl │ │ └── DefaultPluginLoader.java │ └── resources │ └── META-INF │ └── services │ └── com.perfma.xlab.xpocket.plugin.loader.PluginLoader └── xpocket-tools ├── pom.xml └── src └── main └── java └── com └── perfma └── xlab └── tools └── process └── RunSystemTools.java /.gitignore: -------------------------------------------------------------------------------- 1 | /*.iml 2 | /*.ipr 3 | /*.iws 4 | /.classpath 5 | /.factorypath 6 | /.idea 7 | /.project 8 | /.settings 9 | /nb* 10 | /release.properties 11 | /target 12 | 13 | # These are needed if running in IDE without properties set 14 | /ibderby 15 | derby.log 16 | /bin/ 17 | */*.iml 18 | *.iml 19 | *.class 20 | *.zip 21 | *.gz 22 | *.so 23 | *.dylib 24 | *.so.1.1 25 | */target/* 26 | **/target/** 27 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | appName="XPocket" 3 | rm -rf ${appName}-*-ear.tar.gz 4 | rm -rf ${appName}-*-ear.zip 5 | mvn clean:clean 6 | mvn install -Dmaven.test.skip 7 | cp xpocket-deploy/target/${appName}-*-ear.* . -------------------------------------------------------------------------------- /resourse/cd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/resourse/cd.png -------------------------------------------------------------------------------- /resourse/command.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/resourse/command.jpg -------------------------------------------------------------------------------- /resourse/commandList.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/resourse/commandList.jpg -------------------------------------------------------------------------------- /resourse/command_demo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/resourse/command_demo.jpg -------------------------------------------------------------------------------- /resourse/def.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/resourse/def.jpg -------------------------------------------------------------------------------- /resourse/pipe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/resourse/pipe.png -------------------------------------------------------------------------------- /resourse/plugins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/resourse/plugins.png -------------------------------------------------------------------------------- /resourse/proc_exec.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/resourse/proc_exec.jpg -------------------------------------------------------------------------------- /resourse/proc_list.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/resourse/proc_list.jpg -------------------------------------------------------------------------------- /resourse/proc_save.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/resourse/proc_save.jpg -------------------------------------------------------------------------------- /resourse/quit.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/resourse/quit.jpg -------------------------------------------------------------------------------- /resourse/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/resourse/start.png -------------------------------------------------------------------------------- /resourse/xpocket.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/resourse/xpocket.jpg -------------------------------------------------------------------------------- /resourse/xpocket_plugin.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/resourse/xpocket_plugin.jpg -------------------------------------------------------------------------------- /xpocket-agent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.perfma.xlab 7 | xpocket-parent 8 | 2.1.2-alpha 9 | ../pom.xml 10 | 11 | 4.0.0 12 | 13 | xpocket-agent 14 | jar 15 | 16 | true 17 | 18 | 19 | 20 | 21 | com.perfma.wrapped 22 | com.sun.tools 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.apache.maven.plugins 30 | maven-jar-plugin 31 | 3.2.0 32 | 33 | 34 | src/main/resources/META-INF/MANIFEST.MF 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /xpocket-agent/src/main/java/com/perfma/xlab/xpocket/agent/classloader/XPocketAgentClassLoader.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.agent.classloader; 2 | 3 | import java.net.URL; 4 | import java.net.URLClassLoader; 5 | 6 | /** 7 | * 8 | * @author gongyu 9 | */ 10 | public class XPocketAgentClassLoader extends URLClassLoader { 11 | 12 | private ClassLoader parent; 13 | 14 | public XPocketAgentClassLoader(URL[] urls, ClassLoader cl) { 15 | super(urls, cl); 16 | } 17 | 18 | public XPocketAgentClassLoader(URL[] urls) { 19 | super(urls); 20 | } 21 | 22 | @Override 23 | public Class loadClass(String name) throws ClassNotFoundException { 24 | return loadClass(name, false); 25 | } 26 | 27 | @Override 28 | protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { 29 | synchronized (getClassLoadingLock(name)) { 30 | Class c = null; 31 | 32 | if (c == null) { 33 | // First, check if the class has already been loaded 34 | c = findLoadedClass(name); 35 | try { 36 | if (c == null) { 37 | c = findClass(name); 38 | } 39 | } catch (ClassNotFoundException e) { 40 | // ClassNotFoundException thrown if class not found 41 | // from the non-null parent class loader 42 | } 43 | } 44 | 45 | if (c == null) { 46 | if (parent != null) { 47 | c = parent.loadClass(name); 48 | } else { 49 | c = Class.forName(name); 50 | } 51 | } 52 | 53 | if (resolve) { 54 | resolveClass(c); 55 | } 56 | 57 | return c; 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /xpocket-agent/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Implementation-Title: xpocket-agent 3 | Premain-Class: com.perfma.xlab.xpocket.agent.XPocketAgent 4 | Implementation-Version: 2.0.1 5 | Agent-Class: com.perfma.xlab.xpocket.agent.XPocketAgent 6 | Can-Redefine-Classes: true 7 | Specification-Title: xpocket-agent 8 | Can-Retransform-Classes: true 9 | Build-Jdk-Spec: 1.8 10 | Specification-Version: 2.0.1 11 | -------------------------------------------------------------------------------- /xpocket-bridge/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | com.perfma.xlab 9 | xpocket-parent 10 | 2.1.1-RELEASE 11 | ../pom.xml 12 | 13 | xpocket-bridge 14 | 15 | 16 | 17 | com.perfma.xlab 18 | xpocket-plugin-spi 19 | 20 | 21 | com.perfma.xlab 22 | xpocket-runtime 23 | 24 | 25 | -------------------------------------------------------------------------------- /xpocket-bridge/src/main/java/com/perfma/xlab/xpocket/bridge/execution/BridgeExecutionExecutionEngineImpl.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.bridge.execution; 2 | 3 | import com.perfma.xlab.xpocket.plugin.execution.ExecutionEngine; 4 | import com.perfma.xlab.xpocket.plugin.execution.Node; 5 | import com.perfma.xlab.xpocket.plugin.execution.XpocketProcessInfo; 6 | import org.jline.reader.LineReader; 7 | 8 | /** 9 | * @author xinxian 10 | * @create 2021-03-23 16:42 11 | **/ 12 | public class BridgeExecutionExecutionEngineImpl extends BridgeNamedObject implements ExecutionEngine { 13 | 14 | @Override 15 | public void invoke(XpocketProcessInfo process, LineReader reader) throws Throwable { 16 | //NOTHING TO DO 17 | } 18 | 19 | @Override 20 | public void invoke(XpocketProcessInfo info) throws Throwable { 21 | BridgeExecutionPipeLine pipeline = new BridgeExecutionPipeLine(info.finalOutput()); 22 | //其实插件之间调用只支持单插件,所以这里的nodes只有一个元素 23 | for (Node node : info.nodes()) { 24 | pipeline.appendProcess(node); 25 | } 26 | pipeline.start(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /xpocket-bridge/src/main/java/com/perfma/xlab/xpocket/bridge/execution/BridgeExecutionPipeLine.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.bridge.execution; 2 | 3 | import com.perfma.xlab.xpocket.bridge.process.BridgeProcessDefinition; 4 | import com.perfma.xlab.xpocket.framework.spi.execution.pipeline.ExecutionPipeLine; 5 | import com.perfma.xlab.xpocket.framework.spi.execution.pipeline.XPocketProcessOutputStream; 6 | import com.perfma.xlab.xpocket.plugin.execution.Node; 7 | 8 | import java.io.OutputStream; 9 | 10 | /** 11 | * @author xinxian 12 | * @create 2021-03-23 17:30 13 | **/ 14 | public class BridgeExecutionPipeLine extends ExecutionPipeLine { 15 | public BridgeExecutionPipeLine(OutputStream finalOutput) { 16 | super(finalOutput); 17 | } 18 | 19 | @Override 20 | public void appendProcess(Node node) { 21 | BridgeProcessDefinition def = new BridgeProcessDefinition( 22 | node.getPluginContext(),node.getCmd(),node.getArgs()); 23 | def.setPipeline(this); 24 | def.setOutputStream(finalOutput); 25 | if(header == null) { 26 | header = def; 27 | tail = def; 28 | } else { 29 | def.setDefaultEnd(false); 30 | tail.setOutputStream(new XPocketProcessOutputStream(def)); 31 | tail.setNext(def); 32 | tail.setPipeline(null); 33 | tail = def; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /xpocket-bridge/src/main/java/com/perfma/xlab/xpocket/bridge/execution/BridgeNamedObject.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.bridge.execution; 2 | 3 | import com.perfma.xlab.xpocket.plugin.base.NamedObject; 4 | 5 | /** 6 | * @author xinxian 7 | * @create 2021-03-23 16:43 8 | **/ 9 | public class BridgeNamedObject implements NamedObject { 10 | private static final String NAME = "BRIDGE"; 11 | @Override 12 | public String name() { 13 | return NAME; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /xpocket-bridge/src/main/java/com/perfma/xlab/xpocket/bridge/execution/ExecutionEngineHolder.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.bridge.execution; 2 | 3 | import com.perfma.xlab.xpocket.plugin.execution.ExecutionEngine; 4 | 5 | /** 6 | * @author xinxian 7 | * @create 2021-03-24 14:31 8 | **/ 9 | public class ExecutionEngineHolder { 10 | 11 | public static ExecutionEngine getExecutionEgine() { 12 | return BridgeExecutionEgine.EXECUTION_ENGINE; 13 | } 14 | 15 | private static class BridgeExecutionEgine { 16 | private static final ExecutionEngine EXECUTION_ENGINE = new BridgeExecutionExecutionEngineImpl(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /xpocket-bridge/src/main/java/com/perfma/xlab/xpocket/bridge/process/BridgeProcessDefinition.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.bridge.process; 2 | 3 | import com.perfma.xlab.xpocket.command.impl.SysCommand; 4 | import com.perfma.xlab.xpocket.context.ExecuteContextWrapper; 5 | import com.perfma.xlab.xpocket.framework.spi.execution.pipeline.DefaultProcessDefinition; 6 | import com.perfma.xlab.xpocket.framework.spi.impl.XPocketStatusContext; 7 | import com.perfma.xlab.xpocket.spi.command.XPocketCommand; 8 | import com.perfma.xlab.xpocket.spi.context.PluginBaseInfo; 9 | 10 | /** 11 | * @author xinxian 12 | * @create 2021-03-23 17:02 13 | **/ 14 | public class BridgeProcessDefinition extends DefaultProcessDefinition { 15 | 16 | 17 | public BridgeProcessDefinition(PluginBaseInfo context, String cmd, String[] args) { 18 | super(context, cmd, args); 19 | } 20 | 21 | @Override 22 | public void execute(String input,ExecuteContextWrapper executeContextWrapper) throws Throwable { 23 | String[] realArgs; 24 | if (input == null || input.trim().isEmpty()) { 25 | realArgs = args; 26 | } else { 27 | if (context.getCommand(cmd) != null && context.getCommand(cmd).isPiped()) { 28 | realArgs = args; 29 | } else { 30 | realArgs = new String[args.length + 1]; 31 | realArgs[0] = input; 32 | System.arraycopy(args, 0, realArgs, 1, args.length); 33 | } 34 | } 35 | 36 | BridgeXpocketProcess process = new BridgeXpocketProcess(cmd, realArgs); 37 | process.setInput(input); 38 | process.setOutputStream(outputStream); 39 | process.setPdef(this); 40 | currentProcess = process; 41 | hasProcess = true; 42 | XPocketCommand command = context.getCommand(cmd); 43 | if (command == null) { 44 | //未找到的命令尝试交给系统命令 45 | command = SysCommand.getInstance(); 46 | } 47 | command.invoke(process, XPocketStatusContext.instance); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /xpocket-bridge/src/main/java/com/perfma/xlab/xpocket/bridge/process/BridgeXpocketProcess.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.bridge.process; 2 | 3 | import com.perfma.xlab.xpocket.bridge.XpocketPluginBridge; 4 | import com.perfma.xlab.xpocket.framework.spi.execution.pipeline.DefaultXPocketProcess; 5 | import com.perfma.xlab.xpocket.utils.TerminalUtil; 6 | 7 | 8 | /** 9 | * @author xinxian 10 | * @create 2021-03-23 15:05 11 | **/ 12 | public class BridgeXpocketProcess extends DefaultXPocketProcess { 13 | 14 | public BridgeXpocketProcess(String cmd, String[] args) { 15 | super(cmd, args); 16 | } 17 | @Override 18 | public void output(String output) { 19 | try { 20 | StringBuffer resultCache = XpocketPluginBridge.resultCache; 21 | if (output != null) { 22 | String[] lines = output.split(TerminalUtil.lineSeparator); 23 | for (String line : lines) { 24 | if (line != null) { 25 | resultCache.append(ansiRemovePattern.matcher(line) 26 | .replaceAll("")); 27 | } 28 | } 29 | } 30 | } catch (Throwable ex) { 31 | ex.printStackTrace(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /xpocket-deploy/config/logo.txt: -------------------------------------------------------------------------------- 1 | __ __ 2 | \ \/ / 3 | \ / 4 | / \ 5 | /_/\_\ 6 | ____ 7 | | _ \ 8 | | |_) | 9 | | __/ 10 | |_| 11 | 12 | ___ 13 | / _ \ 14 | | |_| | 15 | \___/ 16 | 17 | ____ 18 | / ___| 19 | | |___ 20 | \____| 21 | _ 22 | | | _ 23 | | |/ / 24 | | < 25 | |_|\_\ 26 | 27 | _____ 28 | / __ \ 29 | | |___/ 30 | \_____| 31 | _ 32 | _| |_ 33 | |_ _| 34 | | |_ 35 | |___| -------------------------------------------------------------------------------- /xpocket-deploy/plugins/.dir: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/xpocket-deploy/plugins/.dir -------------------------------------------------------------------------------- /xpocket-deploy/scripts/xpocket.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set BASEDIR=%~dp0 3 | 4 | PATH %PATH%;%JAVA_HOME%\bin\ 5 | for /f tokens^=2-5^ delims^=.-_^" %%j in ('java -fullversion 2^>^&1') do set "jver=%%j%%k%" 6 | 7 | set LAUNCHER="com.perfma.xlab.xpocket.launcher.XPocketLauncher" 8 | set tools_jar="%BASEDIR%/tools/windows/tools.jar" 9 | REM set DEBUG_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8002" 10 | 11 | if %jver% LSS 19 ( 12 | java -cp .;%tools_jar%;%BASEDIR%lib\* -DXPOCKET_PLUGIN_PATH=%BASEDIR%plugins %DEBUG_OPTS% -DXPOCKET_HOME=%BASEDIR% -DXPOCKET_CONFIG_PATH=%BASEDIR%config\ -Djava.library.path="%BASEDIR%/tools/windows/" %LAUNCHER% %* 13 | ) else ( 14 | java -cp .;%BASEDIR%\lib\* -DXPOCKET_PLUGIN_PATH=%BASEDIR%plugins %DEBUG_OPTS% -DXPOCKET_HOME=%BASEDIR% -DXPOCKET_CONFIG_PATH=%BASEDIR%config\ -Djava.library.path="%BASEDIR%/tools/windows/" %LAUNCHER% %* 15 | ) 16 | -------------------------------------------------------------------------------- /xpocket-deploy/scripts/xpocket.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cd `pwd` 3 | 4 | XPOCKET_HOME=`dirname $0` 5 | cd $XPOCKET_HOME 6 | XPOCKET_HOME=`pwd` 7 | 8 | OS="linux" 9 | OS_LINUX=`echo $OSTYPE|cut -c1-5` 10 | OS_MACOS=`echo $OSTYPE|cut -c1-6` 11 | 12 | if [ "$OS_LINUX" = "linux" ]; then 13 | OS="linux" 14 | elif [ "$OS_MACOS" = "darwin" ]; then 15 | OS="macosx" 16 | elif [ -z $OSTYPE ]; then 17 | OS="linux" 18 | fi 19 | 20 | JAVA_VERSION=`java -fullversion 2>&1 |awk -F"[ +\".]" '{print $5$6 }'` 21 | #DEBUG_OPT="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8002" 22 | 23 | 24 | JAVA_VER=$(java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1) 25 | LAUNCHER="com.perfma.xlab.xpocket.launcher.XPocketLauncher" 26 | 27 | 28 | if [ ${JAVA_VER} -le 8 ]; then 29 | tools_jar=`ls ${XPOCKET_HOME}/tools/${OS}/tools.jar` 30 | 31 | if [ -f ${JAVA_HOME}/lib/sa-jdi.jar ];then 32 | sa_jdi_jar=`ls ${JAVA_HOME}/lib/sa-jdi.jar` 33 | cp $sa_jdi_jar ${XPOCKET_HOME}/lib/ 34 | fi 35 | java -cp .:${tools_jar}:${XPOCKET_HOME}/lib/* ${DEBUG_OPT} -DXPOCKET_HOME=${XPOCKET_HOME}/ -DXPOCKET_PLUGIN_PATH=${XPOCKET_HOME}/plugins -DXPOCKET_CONFIG_PATH=${XPOCKET_HOME}/config/ -Djava.library.path=${XPOCKET_HOME}/tools/${OS}/ ${LAUNCHER} "$@" 36 | else 37 | java -cp .:${XPOCKET_HOME}/lib/* ${DEBUG_OPT} -DXPOCKET_HOME=${XPOCKET_HOME}/ -DXPOCKET_PLUGIN_PATH=${XPOCKET_HOME}/plugins -DXPOCKET_CONFIG_PATH=${XPOCKET_HOME}/config/ -Djava.library.path=${XPOCKET_HOME}/tools/${OS}/ ${LAUNCHER} "$@" 38 | fi 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /xpocket-deploy/scripts/xpocket_jdk8.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set BASEDIR=%~dp0 3 | 4 | set tools_jar="%BASEDIR%\tools\windows\tools.jar" 5 | set LAUNCHER="com.perfma.xlab.xpocket.launcher.XPocketLauncher" 6 | 7 | REM set DEBUG_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8002" 8 | java -cp .;%tools_jar%;%BASEDIR%lib\* -DXPOCKET_PLUGIN_PATH=%BASEDIR%plugins %DEBUG_OPTS% -DXPOCKET_HOME=%BASEDIR% -DXPOCKET_CONFIG_PATH=%BASEDIR%config\ -Djava.library.path="%BASEDIR%/tools/windows/" %LAUNCHER% %* 9 | -------------------------------------------------------------------------------- /xpocket-deploy/scripts/xpocket_jdk8.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cd `pwd` 3 | 4 | XPOCKET_HOME=`dirname $0` 5 | cd $XPOCKET_HOME 6 | XPOCKET_HOME=`pwd` 7 | 8 | OS="linux" 9 | OS_LINUX=`echo $OSTYPE|cut -c1-5` 10 | OS_MACOS=`echo $OSTYPE|cut -c1-6` 11 | 12 | if [ "$OS_LINUX" = "linux" ]; then 13 | OS="linux" 14 | elif [ "$OS_MACOS" = "darwin" ]; then 15 | OS="macosx" 16 | elif [ -z $OSTYPE ]; then 17 | echo "OSTYPE is not seted!Use default ostype: linux" 18 | OS="linux" 19 | fi 20 | 21 | JAVA_VERSION=`java -fullversion 2>&1 |awk -F"[ +\".]" '{print $5$6 }'` 22 | #DEBUG_OPT="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8002" 23 | tools_jar=`ls ${XPOCKET_HOME}/tools/${OS}/tools.jar` 24 | sa_jdi_jar=`ls ${JAVA_HOME}/lib/sa-jdi.jar` 25 | cp $sa_jdi_jar ${XPOCKET_HOME}/lib/ 26 | LAUNCHER="com.perfma.xlab.xpocket.launcher.XPocketLauncher" 27 | 28 | java -cp .:${tools_jar}:${XPOCKET_HOME}/lib/* ${DEBUG_OPT} -DXPOCKET_HOME=${XPOCKET_HOME}/ -DXPOCKET_PLUGIN_PATH=${XPOCKET_HOME}/plugins -DXPOCKET_CONFIG_PATH=${XPOCKET_HOME}/config/ -Djava.library.path=${XPOCKET_HOME}/tools/${OS}/ ${LAUNCHER} "$@" -------------------------------------------------------------------------------- /xpocket-deploy/scripts/xpocket_jdk9+.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set BASEDIR=%~dp0 3 | 4 | set tools_jar="%BASEDIR%/tools/windows/tools.jar" 5 | set LAUNCHER="com.perfma.xlab.xpocket.launcher.XPocketLauncher" 6 | 7 | REM set DEBUG_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8002" 8 | java -cp .;%BASEDIR%\lib\* -DXPOCKET_PLUGIN_PATH=%BASEDIR%plugins %DEBUG_OPTS% -DXPOCKET_HOME=%BASEDIR% -DXPOCKET_CONFIG_PATH=%BASEDIR%config\ -Djava.library.path="%BASEDIR%/tools/windows/" %LAUNCHER% %* 9 | -------------------------------------------------------------------------------- /xpocket-deploy/scripts/xpocket_jdk9+.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cd `pwd` 3 | 4 | XPOCKET_HOME=`dirname $0` 5 | cd $XPOCKET_HOME 6 | XPOCKET_HOME=`pwd` 7 | 8 | OS="linux" 9 | OS_LINUX=`echo $OSTYPE|cut -c1-5` 10 | OS_MACOS=`echo $OSTYPE|cut -c1-6` 11 | 12 | if [ "$OS_LINUX" = "linux" ]; then 13 | OS="linux" 14 | elif [ "$OS_MACOS" = "darwin" ]; then 15 | OS="macosx" 16 | elif [ -z $OSTYPE ]; then 17 | echo "OSTYPE is not seted!Use default ostype: linux" 18 | OS="linux" 19 | fi 20 | 21 | #DEBUG_OPT="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8002" 22 | LAUNCHER="com.perfma.xlab.xpocket.launcher.XPocketLauncher" 23 | 24 | java -cp .:${XPOCKET_HOME}/lib/* ${DEBUG_OPT} -DXPOCKET_HOME=${XPOCKET_HOME}/ -DXPOCKET_PLUGIN_PATH=${XPOCKET_HOME}/plugins -DXPOCKET_CONFIG_PATH=${XPOCKET_HOME}/config/ -Djava.library.path=${XPOCKET_HOME}/tools/${OS}/ ${LAUNCHER} "$@" -------------------------------------------------------------------------------- /xpocket-deploy/scrolls/.dir: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/xpocket-deploy/scrolls/.dir -------------------------------------------------------------------------------- /xpocket-deploy/tools/linux/tools.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/xpocket-deploy/tools/linux/tools.jar -------------------------------------------------------------------------------- /xpocket-deploy/tools/macosx/tools.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/xpocket-deploy/tools/macosx/tools.jar -------------------------------------------------------------------------------- /xpocket-deploy/tools/windows/attach.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/xpocket-deploy/tools/windows/attach.dll -------------------------------------------------------------------------------- /xpocket-deploy/tools/windows/tools.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PerfMa/xpocket/0326239b712a75cfc532604c6137de43ed5b5fcb/xpocket-deploy/tools/windows/tools.jar -------------------------------------------------------------------------------- /xpocket-framework-spi/src/main/java/com/perfma/xlab/xpocket/plugin/base/NamedObject.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.plugin.base; 2 | 3 | /** 4 | * 5 | * @author gongyu 6 | */ 7 | public interface NamedObject { 8 | 9 | /** 10 | * get name of this object 11 | * @return 12 | */ 13 | String name(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /xpocket-framework-spi/src/main/java/com/perfma/xlab/xpocket/plugin/command/CommandLoader.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.plugin.command; 2 | 3 | import com.perfma.xlab.xpocket.plugin.base.NamedObject; 4 | import com.perfma.xlab.xpocket.plugin.context.FrameworkPluginContext; 5 | 6 | import java.util.Map; 7 | import java.util.Set; 8 | 9 | /** 10 | * @author gongyu 11 | */ 12 | public interface CommandLoader extends NamedObject { 13 | 14 | /** 15 | * Gets the correspondence between the plug-in and the command list 16 | * key --- pluginName@pluginNameSpace 17 | * value --- command list 18 | * 19 | * @return 20 | */ 21 | Map> getCmdTable(); 22 | 23 | /** 24 | * Get the corresponding plug-in context through the command 25 | * 26 | * @param command 27 | * @return 28 | */ 29 | FrameworkPluginContext findByCommand(String command); 30 | 31 | /** 32 | * Add all commands corresponding to the plug-in list to the custom cache 33 | * 34 | * @param contexts 35 | * @return 36 | */ 37 | boolean addCommand(Set contexts); 38 | 39 | /** 40 | * Returns a collection of plug-in names for all commands 41 | * 42 | * @return 43 | */ 44 | Set cmdSet(); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /xpocket-framework-spi/src/main/java/com/perfma/xlab/xpocket/plugin/context/FrameworkPluginContext.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.plugin.context; 2 | 3 | import com.perfma.xlab.xpocket.spi.context.PluginBaseInfo; 4 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 5 | 6 | /** 7 | * @author gongyu 8 | */ 9 | public interface FrameworkPluginContext extends PluginBaseInfo { 10 | 11 | /** 12 | * Responsible for initialization 13 | * 14 | * @param process 15 | */ 16 | void init(XPocketProcess process); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /xpocket-framework-spi/src/main/java/com/perfma/xlab/xpocket/plugin/execution/ExecutionEngine.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.plugin.execution; 2 | 3 | import com.perfma.xlab.xpocket.plugin.base.NamedObject; 4 | import org.jline.reader.LineReader; 5 | 6 | /** 7 | * @author gongyu 8 | */ 9 | public interface ExecutionEngine extends NamedObject { 10 | 11 | /** 12 | * An instruction to 13 | * 14 | * @param process Encapsulates instruction information 15 | * @param reader Command line information reading class, assist the completion of terminal control 16 | * @throws Throwable 17 | */ 18 | void invoke(XpocketProcessInfo process, LineReader reader) throws Throwable; 19 | 20 | 21 | void invoke(XpocketProcessInfo info) throws Throwable; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /xpocket-framework-spi/src/main/java/com/perfma/xlab/xpocket/plugin/execution/Node.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.plugin.execution; 2 | 3 | 4 | import com.perfma.xlab.xpocket.spi.context.PluginBaseInfo; 5 | 6 | /** 7 | * Encapsulate command information 8 | * 9 | * @author gongyu 10 | */ 11 | public interface Node { 12 | 13 | /** 14 | * Gets the current plug-in context 15 | * 16 | * @return 17 | */ 18 | PluginBaseInfo getPluginContext(); 19 | 20 | /** 21 | * Get command name 22 | * 23 | * @return 24 | */ 25 | String getCmd(); 26 | 27 | /** 28 | * Get a list of parameters 29 | * 30 | * @return 31 | */ 32 | String[] getArgs(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /xpocket-framework-spi/src/main/java/com/perfma/xlab/xpocket/plugin/execution/XpocketProcessInfo.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.plugin.execution; 2 | 3 | import java.io.OutputStream; 4 | import java.util.List; 5 | 6 | /** 7 | * @author gongyu 8 | */ 9 | public interface XpocketProcessInfo { 10 | 11 | /** 12 | * Gets a list of command information 13 | * 14 | * @return 15 | */ 16 | List nodes(); 17 | 18 | /** 19 | * Get the output stream 20 | * 21 | * @return 22 | */ 23 | OutputStream finalOutput(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /xpocket-framework-spi/src/main/java/com/perfma/xlab/xpocket/plugin/loader/NonavailablePluginLoader.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.plugin.loader; 2 | 3 | 4 | import com.perfma.xlab.xpocket.plugin.context.FrameworkPluginContext; 5 | 6 | import java.util.Set; 7 | import java.util.TreeSet; 8 | 9 | /** 10 | * @author gongyu 11 | */ 12 | public class NonavailablePluginLoader implements PluginLoader { 13 | 14 | private static final String NAME = "N/A"; 15 | 16 | private static final Set emptySet = new TreeSet<>(); 17 | 18 | @Override 19 | public String name() { 20 | return NAME; 21 | } 22 | 23 | @Override 24 | public boolean loadPlugins(String resouceName) { 25 | return true; 26 | } 27 | 28 | @Override 29 | public Set getAvailablePlugins() { 30 | return emptySet; 31 | } 32 | 33 | @Override 34 | public Set getAllPlugins() { 35 | return emptySet; 36 | } 37 | 38 | @Override 39 | public void addPlugin(FrameworkPluginContext pluginContext) { 40 | // nop 41 | } 42 | 43 | @Override 44 | public FrameworkPluginContext getPlugin(String name,String namespace) { 45 | return null; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /xpocket-framework-spi/src/main/java/com/perfma/xlab/xpocket/plugin/manager/CommandManager.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.plugin.manager; 2 | 3 | import com.perfma.xlab.xpocket.plugin.command.CommandLoader; 4 | import com.perfma.xlab.xpocket.plugin.context.FrameworkPluginContext; 5 | import com.perfma.xlab.xpocket.plugin.util.Constants; 6 | import com.perfma.xlab.xpocket.plugin.util.ServiceLoaderUtils; 7 | 8 | import java.util.Map; 9 | import java.util.Set; 10 | 11 | /** 12 | * @author gongyu 13 | */ 14 | public class CommandManager { 15 | 16 | private static final CommandLoader cmdLoader; 17 | 18 | static { 19 | 20 | Map loaders = ServiceLoaderUtils.loadServices(CommandLoader.class); 21 | String run_mode = System.getProperty(Constants.RUN_MODE_KEY, Constants.DEFAULT_RUN_MODE).toUpperCase(); 22 | 23 | if (loaders.containsKey(run_mode)) { 24 | cmdLoader = loaders.get(run_mode); 25 | } else { 26 | cmdLoader = loaders.get(Constants.DEFAULT_RUN_MODE); 27 | } 28 | 29 | if(cmdLoader == null) { 30 | throw new RuntimeException("There is no COMMAND implementation exists in environment!"); 31 | } 32 | } 33 | 34 | public static Map> getCmdTable() { 35 | return cmdLoader.getCmdTable(); 36 | } 37 | 38 | public static FrameworkPluginContext findByCommand(String command) { 39 | return cmdLoader.findByCommand(command); 40 | } 41 | 42 | public static boolean addCommand(Set contexts) { 43 | return cmdLoader.addCommand(contexts); 44 | } 45 | 46 | public static Set cmdSet() { 47 | return cmdLoader.cmdSet(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /xpocket-framework-spi/src/main/java/com/perfma/xlab/xpocket/plugin/manager/ExecutionManager.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.plugin.manager; 2 | 3 | import com.perfma.xlab.xpocket.plugin.execution.ExecutionEngine; 4 | import com.perfma.xlab.xpocket.plugin.execution.XpocketProcessInfo; 5 | import com.perfma.xlab.xpocket.plugin.util.Constants; 6 | import com.perfma.xlab.xpocket.plugin.util.ServiceLoaderUtils; 7 | import org.jline.reader.LineReader; 8 | 9 | import java.util.Map; 10 | 11 | /** 12 | * @author gongyu 13 | */ 14 | public class ExecutionManager { 15 | 16 | private static final ExecutionEngine engine; 17 | 18 | static { 19 | Map engines = ServiceLoaderUtils.loadServices(ExecutionEngine.class); 20 | String run_mode = System.getProperty(Constants.RUN_MODE_KEY, Constants.DEFAULT_RUN_MODE).toUpperCase(); 21 | 22 | if (engines.containsKey(run_mode)) { 23 | engine = engines.get(run_mode); 24 | } else { 25 | engine = engines.get(Constants.DEFAULT_RUN_MODE); 26 | } 27 | 28 | if(engine == null) { 29 | throw new RuntimeException("There is no ENGINE implementation exists in environment!"); 30 | } 31 | } 32 | 33 | public static void invoke(XpocketProcessInfo process, LineReader reader) throws Throwable { 34 | engine.invoke(process, reader); 35 | } 36 | 37 | public static void invoke(XpocketProcessInfo process) throws Throwable { 38 | engine.invoke(process); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /xpocket-framework-spi/src/main/java/com/perfma/xlab/xpocket/plugin/manager/MainUIManager.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.plugin.manager; 2 | 3 | import com.perfma.xlab.xpocket.plugin.ui.UIEngine; 4 | import com.perfma.xlab.xpocket.plugin.util.Constants; 5 | import com.perfma.xlab.xpocket.plugin.util.ServiceLoaderUtils; 6 | import java.lang.instrument.Instrumentation; 7 | 8 | import java.util.Map; 9 | 10 | /** 11 | * @author gongyu 12 | */ 13 | public class MainUIManager { 14 | 15 | private static final UIEngine coreUI; 16 | 17 | static { 18 | Map UIs = ServiceLoaderUtils.loadServices(UIEngine.class); 19 | String run_mode = System.getProperty(Constants.RUN_MODE_KEY, Constants.DEFAULT_RUN_MODE).toUpperCase(); 20 | if(UIs.containsKey(run_mode)) { 21 | coreUI = UIs.get(run_mode); 22 | } else { 23 | coreUI = UIs.get(Constants.DEFAULT_RUN_MODE); 24 | } 25 | 26 | if(coreUI == null) { 27 | throw new RuntimeException("There is no UI implementation exists in environment!"); 28 | } 29 | } 30 | 31 | @Deprecated 32 | public static void start(String def, String[] args) { 33 | coreUI.start(def, args); 34 | } 35 | 36 | public static void start(String[] def, String[] args,Instrumentation inst) { 37 | coreUI.start(def, args, inst); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /xpocket-framework-spi/src/main/java/com/perfma/xlab/xpocket/plugin/ui/UIEngine.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.plugin.ui; 2 | 3 | import com.perfma.xlab.xpocket.plugin.base.NamedObject; 4 | import java.lang.instrument.Instrumentation; 5 | 6 | /** 7 | * @author gongyu 8 | */ 9 | public interface UIEngine extends NamedObject { 10 | 11 | /** 12 | * 以某个形式的资源文件启动UI引擎 13 | * 14 | * @param def 资源文件形式 例如 META-INF/xpocket.def,xpocket.def作为插件的配置文件,加载插件的时候需要用到 15 | * @param args 16 | * 17 | * Deprecated since 2.0.1-RELEASE,use start(String[] def, String[] args) instead 18 | * 19 | */ 20 | @Deprecated 21 | default void start(String def, String[] args) { 22 | throw new UnsupportedOperationException("It`s default implementation " 23 | + "for this method,what means your provider never implemented " 24 | + "this interface. "); 25 | } 26 | 27 | /** 28 | * start core ui engine with multiple def files 29 | * 30 | * @param def array of the def files,e.g. META-INF/xpocket.def 31 | * @param args 32 | * @param inst used when load by a Java Agent 33 | * 34 | */ 35 | default void start(String[] def, String[] args,Instrumentation inst) { 36 | start(def[0],args); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /xpocket-framework-spi/src/main/java/com/perfma/xlab/xpocket/plugin/util/Constants.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.plugin.util; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * @author gongyu 7 | */ 8 | public class Constants { 9 | 10 | public static final String DEFAULT_RUN_MODE = "DEFAULT"; 11 | 12 | public static final String RUN_MODE_KEY = "run_mode"; 13 | 14 | public static final String AGENT_MODE_KEY = "agent_mode"; 15 | 16 | public static final String XPOCKET_SIMPLE_MODE = "XPOCKET_SIMPLE_MODE"; 17 | 18 | public static final String USER_HOME = System.getProperty("user.dir") + File.separator + "xpocket-deploy"; 19 | 20 | public static final String HOME_NAME = "XPOCKET_HOME"; 21 | 22 | public static final String PLUGIN_PATH = "XPOCKET_PLUGIN_PATH"; 23 | 24 | public static final String CONFIG_PATH = "XPOCKET_CONFIG_PATH"; 25 | 26 | public static final String PLUGINS_DIR = "plugins"; 27 | 28 | public static final String CONFIG_DIR = "config"; 29 | 30 | private Constants() { 31 | } 32 | 33 | public static void initSystemProperties() { 34 | if (System.getProperty(HOME_NAME) == null) { 35 | System.setProperty(HOME_NAME, USER_HOME); 36 | } 37 | if (System.getProperty(PLUGIN_PATH) == null) { 38 | System.setProperty(PLUGIN_PATH, USER_HOME + File.separator + PLUGINS_DIR); 39 | } 40 | if (System.getProperty(CONFIG_PATH) == null) { 41 | System.setProperty(CONFIG_PATH, USER_HOME + File.separator + CONFIG_DIR + File.separator); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /xpocket-framework-spi/src/main/java/com/perfma/xlab/xpocket/plugin/util/ServiceLoaderUtils.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.plugin.util; 2 | 3 | import com.perfma.xlab.xpocket.plugin.base.NamedObject; 4 | import java.util.HashMap; 5 | import java.util.Iterator; 6 | import java.util.Map; 7 | import java.util.ServiceLoader; 8 | 9 | /** 10 | * 11 | * @author gongyu 12 | */ 13 | public class ServiceLoaderUtils { 14 | 15 | public static final Map loadServices( 16 | Class clazz) { 17 | ServiceLoader pluginLoaderLoader = ServiceLoader 18 | .load(clazz); 19 | Iterator it = pluginLoaderLoader.iterator(); 20 | Map services = new HashMap<>(); 21 | while(it.hasNext()) { 22 | V v = it.next(); 23 | services.put(v.name(), v); 24 | } 25 | 26 | return services; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /xpocket-jline/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.perfma.xlab 7 | xpocket-parent 8 | 2.1.2-alpha 9 | ../pom.xml 10 | 11 | 4.0.0 12 | 13 | xpocket-jline 14 | jar 15 | 16 | true 17 | 18 | 19 | 20 | 21 | org.fusesource.jansi 22 | jansi 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/NoInterruptUnixTerminal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline; 10 | 11 | // Based on Apache Karaf impl 12 | 13 | /** 14 | * Non-interruptible (via CTRL-C) {@link UnixTerminal}. 15 | * 16 | * @since 2.0 17 | */ 18 | public class NoInterruptUnixTerminal 19 | extends UnixTerminal 20 | { 21 | private String intr; 22 | 23 | public NoInterruptUnixTerminal() throws Exception { 24 | super(); 25 | } 26 | 27 | @Override 28 | public void init() throws Exception { 29 | super.init(); 30 | intr = getSettings().getPropertyAsString("intr"); 31 | if ("".equals(intr)) { 32 | intr = null; 33 | } 34 | if (intr != null) { 35 | getSettings().undef("intr"); 36 | } 37 | } 38 | 39 | @Override 40 | public void restore() throws Exception { 41 | if (intr != null) { 42 | getSettings().set("intr", intr); 43 | } 44 | super.restore(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/OSvTerminal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline; 10 | 11 | import jline.internal.Log; 12 | 13 | /** 14 | * Terminal that is used for OSv. This is seperate to unix terminal 15 | * implementation because exec cannot be used as currently used by UnixTerminal. 16 | * 17 | * This implimentation is derrived from the implementation at 18 | * https://github.com/cloudius-systems/mgmt/blob/master/crash/src/main/java/com/cloudius/cli/OSvTerminal.java 19 | * authored by Or Cohen. 20 | * 21 | * @author Or Cohen 22 | * @author Arun Neelicattu 23 | * @since 2.13 24 | */ 25 | public class OSvTerminal 26 | extends TerminalSupport 27 | { 28 | 29 | public Class sttyClass = null; 30 | public Object stty = null; 31 | 32 | public OSvTerminal() { 33 | super(true); 34 | 35 | setAnsiSupported(true); 36 | 37 | try { 38 | if (stty == null) { 39 | sttyClass = Class.forName("com.cloudius.util.Stty"); 40 | stty = sttyClass.newInstance(); 41 | } 42 | } catch (Exception e) { 43 | Log.warn("Failed to load com.cloudius.util.Stty", e); 44 | } 45 | } 46 | 47 | @Override 48 | public void init() throws Exception { 49 | super.init(); 50 | 51 | if (stty != null) { 52 | sttyClass.getMethod("jlineMode").invoke(stty); 53 | } 54 | } 55 | 56 | @Override 57 | public void restore() throws Exception { 58 | if (stty != null) { 59 | sttyClass.getMethod("reset").invoke(stty); 60 | } 61 | super.restore(); 62 | 63 | // Newline in end of restore like in jline.UnixTerminal 64 | System.out.println(); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/Terminal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline; 10 | 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.io.OutputStream; 14 | 15 | /** 16 | * Representation of the input terminal for a platform. 17 | * 18 | * @author Marc Prud'hommeaux 19 | * @author Jason Dillon 20 | * @since 2.0 21 | */ 22 | public interface Terminal 23 | { 24 | void init() throws Exception; 25 | 26 | void restore() throws Exception; 27 | 28 | void reset() throws Exception; 29 | 30 | boolean isSupported(); 31 | 32 | int getWidth(); 33 | 34 | int getHeight(); 35 | 36 | boolean isAnsiSupported(); 37 | 38 | /** 39 | * When ANSI is not natively handled, the output will have to be wrapped. 40 | */ 41 | OutputStream wrapOutIfNeeded(OutputStream out); 42 | 43 | /** 44 | * When using native support, return the InputStream to use for reading characters 45 | * else return the input stream passed as a parameter. 46 | * 47 | * @since 2.6 48 | */ 49 | InputStream wrapInIfNeeded(InputStream in) throws IOException; 50 | 51 | /** 52 | * For terminals that don't wrap when character is written in last column, 53 | * only when the next character is written. 54 | * These are the ones that have 'am' and 'xn' termcap attributes (xterm and 55 | * rxvt flavors falls under that category) 56 | */ 57 | boolean hasWeirdWrap(); 58 | 59 | boolean isEchoEnabled(); 60 | 61 | void setEchoEnabled(boolean enabled); 62 | 63 | void disableInterruptCharacter(); 64 | void enableInterruptCharacter(); 65 | 66 | String getOutputEncoding(); 67 | 68 | } 69 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/Terminal2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline; 10 | 11 | /** 12 | * Terminal extension. 13 | * 14 | * @author Guillaume Nodet 15 | * @since 2.13 16 | */ 17 | public interface Terminal2 extends Terminal 18 | { 19 | boolean getBooleanCapability(String capability); 20 | 21 | Integer getNumericCapability(String capability); 22 | 23 | String getStringCapability(String capability); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/UnsupportedTerminal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline; 10 | 11 | /** 12 | * An unsupported terminal. 13 | * 14 | * @author Marc Prud'hommeaux 15 | * @author Jason Dillon 16 | * @since 2.0 17 | */ 18 | public class UnsupportedTerminal 19 | extends TerminalSupport 20 | { 21 | public UnsupportedTerminal() { 22 | this(false, true); 23 | } 24 | 25 | public UnsupportedTerminal(boolean ansiSupported, boolean echoEnabled) { 26 | super(false); 27 | setAnsiSupported(ansiSupported); 28 | setEchoEnabled(echoEnabled); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/console/UserInterruptException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline.console; 10 | 11 | /** 12 | * This exception is thrown by {@link ConsoleReader#readLine} when 13 | * user interrupt handling is enabled and the user types the 14 | * interrupt character (ctrl-C). The partially entered line is 15 | * available via the {@link #getPartialLine()} method. 16 | */ 17 | public class UserInterruptException 18 | extends RuntimeException 19 | { 20 | private static final long serialVersionUID = 6172232572140736750L; 21 | 22 | private final String partialLine; 23 | 24 | public UserInterruptException(String partialLine) 25 | { 26 | this.partialLine = partialLine; 27 | } 28 | 29 | /** 30 | * @return the partially entered line when ctrl-C was pressed 31 | */ 32 | public String getPartialLine() 33 | { 34 | return partialLine; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/console/completer/Completer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline.console.completer; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * A completer is the mechanism by which tab-completion candidates will be resolved. 15 | * 16 | * @author Marc Prud'hommeaux 17 | * @author Jason Dillon 18 | * @since 2.3 19 | */ 20 | public interface Completer 21 | { 22 | // 23 | // FIXME: Check if we can use CharSequece for buffer? 24 | // 25 | 26 | /** 27 | * Populates candidates with a list of possible completions for the buffer. 28 | * 29 | * The candidates list will not be sorted before being displayed to the user: thus, the 30 | * complete method should sort the {@link List} before returning. 31 | * 32 | * @param buffer The buffer 33 | * @param cursor The current position of the cursor in the buffer 34 | * @param candidates The {@link List} of candidates to populate 35 | * @return The index of the buffer for which the completion will be relative 36 | */ 37 | int complete(String buffer, int cursor, List candidates); 38 | } 39 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/console/completer/CompletionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline.console.completer; 10 | 11 | import jline.console.ConsoleReader; 12 | 13 | import java.io.IOException; 14 | import java.util.List; 15 | 16 | /** 17 | * Handler for dealing with candidates for tab-completion. 18 | * 19 | * @author Marc Prud'hommeaux 20 | * @author Jason Dillon 21 | * @since 2.3 22 | */ 23 | public interface CompletionHandler 24 | { 25 | boolean complete(ConsoleReader reader, List candidates, int position) throws IOException; 26 | } 27 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/console/completer/EnumCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline.console.completer; 10 | 11 | import static jline.internal.Preconditions.checkNotNull; 12 | 13 | /** 14 | * {@link Completer} for {@link Enum} names. 15 | * 16 | * @author Jason Dillon 17 | * @since 2.3 18 | */ 19 | public class EnumCompleter 20 | extends StringsCompleter 21 | { 22 | public EnumCompleter(Class> source) { 23 | this(source, true); 24 | } 25 | 26 | public EnumCompleter(Class> source, boolean toLowerCase) { 27 | checkNotNull(source); 28 | 29 | for (Enum n : source.getEnumConstants()) { 30 | this.getStrings().add(toLowerCase ? n.name().toLowerCase() : n.name()); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/console/completer/NullCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline.console.completer; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Null completer. 15 | * 16 | * @author Marc Prud'hommeaux 17 | * @author Jason Dillon 18 | * @since 2.3 19 | */ 20 | public final class NullCompleter 21 | implements Completer 22 | { 23 | public static final NullCompleter INSTANCE = new NullCompleter(); 24 | 25 | public int complete(final String buffer, final int cursor, final List candidates) { 26 | return -1; 27 | } 28 | } -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/console/completer/StringsCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline.console.completer; 10 | 11 | import java.util.Arrays; 12 | import java.util.Collection; 13 | import java.util.List; 14 | import java.util.SortedSet; 15 | import java.util.TreeSet; 16 | 17 | import static jline.internal.Preconditions.checkNotNull; 18 | 19 | /** 20 | * Completer for a set of strings. 21 | * 22 | * @author Jason Dillon 23 | * @since 2.3 24 | */ 25 | public class StringsCompleter 26 | implements Completer 27 | { 28 | private final SortedSet strings = new TreeSet(); 29 | 30 | public StringsCompleter() { 31 | // empty 32 | } 33 | 34 | public StringsCompleter(final Collection strings) { 35 | checkNotNull(strings); 36 | getStrings().addAll(strings); 37 | } 38 | 39 | public StringsCompleter(final String... strings) { 40 | this(Arrays.asList(strings)); 41 | } 42 | 43 | public Collection getStrings() { 44 | return strings; 45 | } 46 | 47 | public int complete(final String buffer, final int cursor, final List candidates) { 48 | // buffer could be null 49 | checkNotNull(candidates); 50 | 51 | if (buffer == null) { 52 | candidates.addAll(strings); 53 | } 54 | else { 55 | for (String match : strings.tailSet(buffer)) { 56 | if (!match.startsWith(buffer)) { 57 | break; 58 | } 59 | 60 | candidates.add(match); 61 | } 62 | } 63 | 64 | return candidates.isEmpty() ? -1 : 0; 65 | } 66 | } -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/console/completer/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | /** 10 | * Console completer support. 11 | * 12 | * @since 2.3 13 | */ 14 | package jline.console.completer; -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/console/history/PersistentHistory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline.console.history; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * Persistent {@link History}. 15 | * 16 | * @author Jason Dillon 17 | * @since 2.3 18 | */ 19 | public interface PersistentHistory 20 | extends History 21 | { 22 | /** 23 | * Flush all items to persistent storage. 24 | * 25 | * @throws IOException Flush failed 26 | */ 27 | void flush() throws IOException; 28 | 29 | /** 30 | * Purge persistent storage and {@link #clear}. 31 | * 32 | * @throws IOException Purge failed 33 | */ 34 | void purge() throws IOException; 35 | } -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/console/history/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | /** 10 | * Console history support. 11 | * 12 | * @since 2.0 13 | */ 14 | package jline.console.history; -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/console/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | /** 10 | * Console support. 11 | * 12 | * @since 2.0 13 | */ 14 | package jline.console; -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/internal/Ansi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline.internal; 10 | 11 | import java.io.ByteArrayOutputStream; 12 | import java.io.IOException; 13 | 14 | import org.fusesource.jansi.AnsiOutputStream; 15 | 16 | /** 17 | * Ansi support. 18 | * 19 | * @author Guillaume Nodet 20 | * @since 2.13 21 | */ 22 | public class Ansi { 23 | 24 | public static String stripAnsi(String str) { 25 | if (str == null) return ""; 26 | try { 27 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 28 | AnsiOutputStream aos = new AnsiOutputStream(baos); 29 | aos.write(str.getBytes()); 30 | aos.close(); 31 | return baos.toString(); 32 | } catch (IOException e) { 33 | return str; 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/internal/Nullable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline.internal; 10 | 11 | import java.lang.annotation.*; 12 | 13 | /** 14 | * Marker for reference which can be a null value. 15 | * 16 | * @since 2.7 17 | */ 18 | @Documented 19 | @Retention(RetentionPolicy.CLASS) 20 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE}) 21 | public @interface Nullable 22 | { 23 | String value() default ""; 24 | } 25 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/internal/Preconditions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline.internal; 10 | 11 | // Some bits lifted from Guava's ( http://code.google.com/p/guava-libraries/ ) Preconditions. 12 | 13 | /** 14 | * Preconditions. 15 | * 16 | * @author Jason Dillon 17 | * @since 2.7 18 | */ 19 | public class Preconditions 20 | { 21 | public static T checkNotNull(final T reference) { 22 | if (reference == null) { 23 | throw new NullPointerException(); 24 | } 25 | return reference; 26 | } 27 | } -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/internal/TestAccessible.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline.internal; 10 | 11 | import java.lang.annotation.Documented; 12 | import java.lang.annotation.Retention; 13 | import java.lang.annotation.Target; 14 | 15 | import static java.lang.annotation.ElementType.CONSTRUCTOR; 16 | import static java.lang.annotation.ElementType.FIELD; 17 | import static java.lang.annotation.ElementType.METHOD; 18 | import static java.lang.annotation.ElementType.PARAMETER; 19 | import static java.lang.annotation.ElementType.TYPE; 20 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 | 22 | /** 23 | * Marker annotation for members which are exposed for testing access. 24 | * 25 | * @since 2.7 26 | */ 27 | @Retention(RUNTIME) 28 | @Target({TYPE, CONSTRUCTOR, METHOD, FIELD, PARAMETER}) 29 | @Documented 30 | public @interface TestAccessible 31 | { 32 | // empty 33 | } -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/internal/Urls.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | package jline.internal; 10 | 11 | import java.io.File; 12 | import java.net.MalformedURLException; 13 | import java.net.URL; 14 | 15 | /** 16 | * URL helpers. 17 | * 18 | * @author Jason Dillon 19 | * @author Guillaume Nodet 20 | * @since 2.7 21 | */ 22 | public class Urls 23 | { 24 | public static URL create(final String input) { 25 | if (input == null) { 26 | return null; 27 | } 28 | try { 29 | return new URL(input); 30 | } 31 | catch (MalformedURLException e) { 32 | return create(new File(input)); 33 | } 34 | } 35 | 36 | public static URL create(final File file) { 37 | try { 38 | return file != null ? file.toURI().toURL() : null; 39 | } 40 | catch (MalformedURLException e) { 41 | throw new IllegalStateException(e); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/internal/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | /** 10 | * Internal support. 11 | * 12 | * @since 2.0 13 | */ 14 | package jline.internal; -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/jline/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * http://www.opensource.org/licenses/bsd-license.php 8 | */ 9 | /** 10 | * JLine 2. 11 | * 12 | * @since 2.0 13 | */ 14 | package jline; -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/console/ArgDesc.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2020, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.console; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | import org.jline.utils.AttributedString; 15 | 16 | public class ArgDesc { 17 | private String name; 18 | private List description = new ArrayList(); 19 | 20 | public ArgDesc(String name) { 21 | this(name, new ArrayList()); 22 | } 23 | 24 | public ArgDesc(String name, List description) { 25 | this.name = name; 26 | this.description = new ArrayList<>(description); 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public List getDescription() { 34 | return description; 35 | } 36 | 37 | public static List doArgNames(List names) { 38 | List out = new ArrayList<>(); 39 | for (String n: names) { 40 | out.add(new ArgDesc(n)); 41 | } 42 | return out; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/console/CommandMethods.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2020, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.console; 10 | 11 | import java.util.List; 12 | import java.util.function.Consumer; 13 | import java.util.function.Function; 14 | 15 | import org.jline.reader.Completer; 16 | 17 | public class CommandMethods { 18 | Consumer execute; 19 | Function executeFunction; 20 | Function> compileCompleter; 21 | 22 | public CommandMethods(Function execute, Function> compileCompleter) { 23 | this.executeFunction = execute; 24 | this.compileCompleter = compileCompleter; 25 | } 26 | 27 | public CommandMethods(Consumer execute, Function> compileCompleter) { 28 | this.execute = execute; 29 | this.compileCompleter = compileCompleter; 30 | } 31 | 32 | public Consumer execute() { 33 | return execute; 34 | } 35 | 36 | public Function executeFunction() { 37 | return executeFunction; 38 | } 39 | 40 | public Function> compileCompleter() { 41 | return compileCompleter; 42 | } 43 | 44 | public boolean isConsumer() { 45 | return execute != null; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/Binding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader; 10 | 11 | /** 12 | * Marker interface for objects bound to key sequences. 13 | * 14 | * @see Macro 15 | * @see Reference 16 | * @see Widget 17 | * @see org.jline.keymap.KeyMap 18 | * 19 | * @author Guillaume Nodet 20 | */ 21 | public interface Binding { 22 | } 23 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/Buffer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2017, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader; 10 | 11 | public interface Buffer { 12 | 13 | /* 14 | * Read access 15 | */ 16 | 17 | int cursor(); 18 | 19 | int atChar(int i); 20 | 21 | int length(); 22 | 23 | int currChar(); 24 | 25 | int prevChar(); 26 | 27 | int nextChar(); 28 | 29 | /* 30 | * Movement 31 | */ 32 | 33 | boolean cursor(int position); 34 | 35 | int move(int num); 36 | 37 | boolean up(); 38 | 39 | boolean down(); 40 | 41 | boolean moveXY(int dx, int dy); 42 | 43 | /* 44 | * Modification 45 | */ 46 | 47 | boolean clear(); 48 | 49 | boolean currChar(int c); 50 | 51 | void write(int c); 52 | 53 | void write(int c, boolean overTyping); 54 | 55 | void write(CharSequence str); 56 | 57 | void write(CharSequence str, boolean overTyping); 58 | 59 | boolean backspace(); 60 | 61 | int backspace(int num); 62 | 63 | boolean delete(); 64 | 65 | int delete(int num); 66 | 67 | /* 68 | * String 69 | */ 70 | 71 | String substring(int start); 72 | 73 | String substring(int start, int end); 74 | 75 | String upToCursor(); 76 | 77 | String toString(); 78 | 79 | /* 80 | * Copy 81 | */ 82 | 83 | Buffer copy(); 84 | 85 | void copyFrom(Buffer buffer); 86 | 87 | } 88 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/Completer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2018, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * A completer is the mechanism by which tab-completion candidates will be resolved. 15 | * 16 | * @author Marc Prud'hommeaux 17 | * @author Jason Dillon 18 | * @author Guillaume Nodet 19 | * @since 2.3 20 | */ 21 | public interface Completer 22 | { 23 | /** 24 | * Populates candidates with a list of possible completions for the command line. 25 | * 26 | * The list of candidates will be sorted and filtered by the LineReader, so that 27 | * the list of candidates displayed to the user will usually be smaller than 28 | * the list given by the completer. Thus it is not necessary for the completer 29 | * to do any matching based on the current buffer. On the contrary, in order 30 | * for the typo matcher to work, all possible candidates for the word being 31 | * completed should be returned. 32 | * 33 | * @param reader The line reader 34 | * @param line The parsed command line 35 | * @param candidates The {@link List} of candidates to populate 36 | */ 37 | void complete(LineReader reader, ParsedLine line, List candidates); 38 | } 39 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/CompletingParsedLine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2018, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader; 10 | 11 | /** 12 | * An extension of {@link ParsedLine} that, being aware of the quoting and escaping rules 13 | * of the {@link org.jline.reader.Parser} that produced it, knows if and how a completion candidate 14 | * should be escaped/quoted. 15 | * 16 | * @author Eric Bottard 17 | */ 18 | public interface CompletingParsedLine extends ParsedLine { 19 | 20 | CharSequence escape(CharSequence candidate, boolean complete); 21 | 22 | int rawWordCursor(); 23 | 24 | int rawWordLength(); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/EOFError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jline.reader; 20 | 21 | public class EOFError extends SyntaxError { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | private final String missing; 26 | private final int openBrackets; 27 | private final String nextClosingBracket; 28 | 29 | public EOFError(int line, int column, String message) { 30 | this(line, column, message, null); 31 | } 32 | 33 | public EOFError(int line, int column, String message, String missing) { 34 | this(line, column, message, missing, 0, null); 35 | } 36 | 37 | public EOFError(int line, int column, String message, String missing, int openBrackets, String nextClosingBracket) { 38 | super(line, column, message); 39 | this.missing = missing; 40 | this.openBrackets = openBrackets; 41 | this.nextClosingBracket = nextClosingBracket; 42 | } 43 | 44 | public String getMissing() { 45 | return missing; 46 | } 47 | 48 | public int getOpenBrackets(){ 49 | return openBrackets; 50 | } 51 | 52 | public String getNextClosingBracket() { 53 | return nextClosingBracket; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/Editor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2019, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader; 10 | 11 | import java.io.IOException; 12 | import java.util.List; 13 | 14 | public interface Editor { 15 | public void open(List files) throws IOException; 16 | public void run() throws IOException; 17 | public void setRestricted(boolean restricted); 18 | } 19 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/EndOfFileException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader; 10 | 11 | /** 12 | * This exception is thrown by {@link LineReader#readLine} when 13 | * user the user types ctrl-D). 14 | */ 15 | public class EndOfFileException extends RuntimeException { 16 | 17 | private static final long serialVersionUID = 528485360925144689L; 18 | 19 | public EndOfFileException() { 20 | } 21 | 22 | public EndOfFileException(String message) { 23 | super(message); 24 | } 25 | 26 | public EndOfFileException(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | 30 | public EndOfFileException(Throwable cause) { 31 | super(cause); 32 | } 33 | 34 | public EndOfFileException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 35 | super(message, cause, enableSuppression, writableStackTrace); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/Expander.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader; 10 | 11 | public interface Expander { 12 | 13 | String expandHistory(History history, String line); 14 | 15 | String expandVar(String word); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/Highlighter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2019, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader; 10 | 11 | import java.util.regex.Pattern; 12 | 13 | import org.jline.utils.AttributedString; 14 | 15 | public interface Highlighter { 16 | 17 | AttributedString highlight(LineReader reader, String buffer); 18 | public void setErrorPattern(Pattern errorPattern); 19 | public void setErrorIndex(int errorIndex); 20 | } 21 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/Macro.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader; 10 | 11 | public class Macro implements Binding { 12 | 13 | private final String sequence; 14 | 15 | public Macro(String sequence) { 16 | this.sequence = sequence; 17 | } 18 | 19 | public String getSequence() { 20 | return sequence; 21 | } 22 | 23 | @Override 24 | public boolean equals(Object o) { 25 | if (this == o) return true; 26 | if (o == null || getClass() != o.getClass()) return false; 27 | Macro macro = (Macro) o; 28 | return sequence.equals(macro.sequence); 29 | } 30 | 31 | @Override 32 | public int hashCode() { 33 | return sequence.hashCode(); 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "Macro[" + 39 | sequence + ']'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/MaskingCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2018, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader; 10 | 11 | /** 12 | * Callback used to mask parts of the line 13 | */ 14 | public interface MaskingCallback { 15 | 16 | /** 17 | * Transforms the line before it is displayed so that 18 | * some parts can be hidden. 19 | * 20 | * @param line the current line being edited 21 | * @return the modified line to display 22 | */ 23 | String display(String line); 24 | 25 | /** 26 | * Transforms the line before storing in the history. 27 | * If the return value is empty or null, it will not be saved 28 | * in the history. 29 | * 30 | * @param line the line to be added to history 31 | * @return the modified line 32 | */ 33 | String history(String line); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/ParsedLine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2018, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * ParsedLine objects are returned by the {@link Parser} 15 | * during completion or when accepting the line. 16 | * 17 | * The instances should implement the {@link CompletingParsedLine} 18 | * interface so that escape chars and quotes can be correctly handled. 19 | * 20 | * @see Parser 21 | * @see CompletingParsedLine 22 | */ 23 | public interface ParsedLine { 24 | 25 | /** 26 | * The current word being completed. 27 | * If the cursor is after the last word, an empty string is returned. 28 | * 29 | * @return the word being completed or an empty string 30 | */ 31 | String word(); 32 | 33 | /** 34 | * The cursor position within the current word. 35 | * 36 | * @return the cursor position within the current word 37 | */ 38 | int wordCursor(); 39 | 40 | /** 41 | * The index of the current word in the list of words. 42 | * 43 | * @return the index of the current word in the list of words 44 | */ 45 | int wordIndex(); 46 | 47 | /** 48 | * The list of words. 49 | * 50 | * @return the list of words 51 | */ 52 | List words(); 53 | 54 | /** 55 | * The unparsed line. 56 | * 57 | * @return the unparsed line 58 | */ 59 | String line(); 60 | 61 | /** 62 | * The cursor position within the line. 63 | * 64 | * @return the cursor position within the line 65 | */ 66 | int cursor(); 67 | 68 | } 69 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/Reference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader; 10 | 11 | /** 12 | * A reference to a {@link Widget}. 13 | */ 14 | public class Reference implements Binding { 15 | 16 | private final String name; 17 | 18 | public Reference(String name) { 19 | this.name = name; 20 | } 21 | 22 | public String name() { 23 | return name; 24 | } 25 | 26 | @Override 27 | public boolean equals(Object o) { 28 | if (this == o) return true; 29 | if (o == null || getClass() != o.getClass()) return false; 30 | Reference func = (Reference) o; 31 | return name.equals(func.name); 32 | } 33 | 34 | @Override 35 | public int hashCode() { 36 | return name.hashCode(); 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "Reference[" + 42 | name + ']'; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/SyntaxError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jline.reader; 20 | 21 | public class SyntaxError extends RuntimeException { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | private final int line; 26 | private final int column; 27 | 28 | public SyntaxError(int line, int column, String message) { 29 | super(message); 30 | this.line = line; 31 | this.column = column; 32 | } 33 | 34 | public int column() { 35 | return column; 36 | } 37 | 38 | public int line() { 39 | return line; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/UserInterruptException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader; 10 | 11 | /** 12 | * This exception is thrown by {@link LineReader#readLine} when 13 | * user interrupt handling is enabled and the user types the 14 | * interrupt character (ctrl-C). The partially entered line is 15 | * available via the {@link #getPartialLine()} method. 16 | */ 17 | public class UserInterruptException 18 | extends RuntimeException 19 | { 20 | private static final long serialVersionUID = 6172232572140736750L; 21 | 22 | private final String partialLine; 23 | 24 | public UserInterruptException(String partialLine) 25 | { 26 | this.partialLine = partialLine; 27 | } 28 | 29 | /** 30 | * @return the partially entered line when ctrl-C was pressed 31 | */ 32 | public String getPartialLine() 33 | { 34 | return partialLine; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/Widget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader; 10 | 11 | /** 12 | * 13 | */ 14 | @FunctionalInterface 15 | public interface Widget extends Binding { 16 | 17 | boolean apply(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/impl/SimpleMaskingCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2017, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader.impl; 10 | 11 | import org.jline.reader.MaskingCallback; 12 | 13 | import java.util.Objects; 14 | 15 | /** 16 | * Simple {@link MaskingCallback} that will replace all the characters in the line with the given mask. 17 | * If the given mask is equal to {@link LineReaderImpl#NULL_MASK} then the line will be replaced with an empty String. 18 | */ 19 | public final class SimpleMaskingCallback implements MaskingCallback { 20 | private final Character mask; 21 | 22 | public SimpleMaskingCallback(Character mask) { 23 | this.mask = Objects.requireNonNull(mask, "mask must be a non null character"); 24 | } 25 | 26 | @Override 27 | public String display(String line) { 28 | if (mask.equals(LineReaderImpl.NULL_MASK)) { 29 | return ""; 30 | } else { 31 | StringBuilder sb = new StringBuilder(line.length()); 32 | for (int i = line.length(); i-- > 0;) { 33 | sb.append((char) mask); 34 | } 35 | return sb.toString(); 36 | } 37 | } 38 | 39 | @Override 40 | public String history(String line) { 41 | return null; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/impl/UndoTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader.impl; 10 | 11 | import java.util.function.Consumer; 12 | 13 | /** 14 | * Simple undo tree. 15 | * Note that the first added state can't be undone 16 | */ 17 | public class UndoTree { 18 | 19 | private final Consumer state; 20 | private final Node parent; 21 | private Node current; 22 | 23 | public UndoTree(Consumer s) { 24 | state = s; 25 | parent = new Node(null); 26 | parent.left = parent; 27 | clear(); 28 | } 29 | 30 | public void clear() { 31 | current = parent; 32 | } 33 | 34 | public void newState(T state) { 35 | Node node = new Node(state); 36 | current.right = node; 37 | node.left = current; 38 | current = node; 39 | } 40 | 41 | public boolean canUndo() { 42 | return current.left != parent; 43 | } 44 | 45 | public boolean canRedo() { 46 | return current.right != null; 47 | } 48 | 49 | public void undo() { 50 | if (!canUndo()) { 51 | throw new IllegalStateException("Cannot undo."); 52 | } 53 | current = current.left; 54 | state.accept(current.state); 55 | } 56 | 57 | public void redo() { 58 | if (!canRedo()) { 59 | throw new IllegalStateException("Cannot redo."); 60 | } 61 | current = current.right; 62 | state.accept(current.state); 63 | } 64 | 65 | private class Node { 66 | private final T state; 67 | private Node left = null; 68 | private Node right = null; 69 | 70 | public Node(T s) { 71 | state = s; 72 | } 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/impl/completer/EnumCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader.impl.completer; 10 | 11 | import java.util.Objects; 12 | 13 | import org.jline.reader.Candidate; 14 | import org.jline.reader.Completer; 15 | 16 | /** 17 | * {@link Completer} for {@link Enum} names. 18 | * 19 | * @author Jason Dillon 20 | * @since 2.3 21 | */ 22 | public class EnumCompleter extends StringsCompleter 23 | { 24 | public EnumCompleter(Class> source) { 25 | Objects.requireNonNull(source); 26 | for (Enum n : source.getEnumConstants()) { 27 | candidates.add(new Candidate(n.name().toLowerCase())); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/impl/completer/NullCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.reader.impl.completer; 10 | 11 | import java.util.List; 12 | 13 | import org.jline.reader.Candidate; 14 | import org.jline.reader.Completer; 15 | import org.jline.reader.LineReader; 16 | import org.jline.reader.ParsedLine; 17 | 18 | /** 19 | * Null completer. 20 | * 21 | * @author Marc Prud'hommeaux 22 | * @author Jason Dillon 23 | * @since 2.3 24 | */ 25 | public final class NullCompleter 26 | implements Completer 27 | { 28 | public static final NullCompleter INSTANCE = new NullCompleter(); 29 | 30 | public void complete(LineReader reader, final ParsedLine line, final List candidates) { 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/impl/completer/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | /** 10 | * JLine 3. 11 | * 12 | * @since 3.0 13 | */ 14 | package org.jline.reader.impl.completer; 15 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/impl/history/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | /** 10 | * JLine 3. 11 | * 12 | * @since 3.0 13 | */ 14 | package org.jline.reader.impl.history; 15 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/reader/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | /** 10 | * JLine 3. 11 | * 12 | * @since 3.0 13 | */ 14 | package org.jline.reader; -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/terminal/Cursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.terminal; 10 | 11 | /** 12 | * Class holding the cursor position. 13 | * 14 | * @see Terminal#getCursorPosition(java.util.function.IntConsumer) 15 | */ 16 | public class Cursor { 17 | 18 | private final int x; 19 | private final int y; 20 | 21 | public Cursor(int x, int y) { 22 | this.x = x; 23 | this.y = y; 24 | } 25 | 26 | public int getX() { 27 | return x; 28 | } 29 | 30 | public int getY() { 31 | return y; 32 | } 33 | 34 | @Override 35 | public boolean equals(Object o) { 36 | if (o instanceof Cursor) { 37 | Cursor c = (Cursor) o; 38 | return x == c.x && y == c.y; 39 | } else { 40 | return false; 41 | } 42 | } 43 | 44 | @Override 45 | public int hashCode() { 46 | return x * 31 + y; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "Cursor[" + "x=" + x + ", y=" + y + ']'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/terminal/MouseEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.terminal; 10 | 11 | import java.util.EnumSet; 12 | 13 | public class MouseEvent { 14 | 15 | public enum Type { 16 | Released, 17 | Pressed, 18 | Wheel, 19 | Moved, 20 | Dragged 21 | } 22 | 23 | public enum Button { 24 | NoButton, 25 | Button1, 26 | Button2, 27 | Button3, 28 | WheelUp, 29 | WheelDown 30 | } 31 | 32 | public enum Modifier { 33 | Shift, 34 | Alt, 35 | Control 36 | } 37 | 38 | private final Type type; 39 | private final Button button; 40 | private final EnumSet modifiers; 41 | private final int x; 42 | private final int y; 43 | 44 | public MouseEvent(Type type, Button button, EnumSet modifiers, int x, int y) { 45 | this.type = type; 46 | this.button = button; 47 | this.modifiers = modifiers; 48 | this.x = x; 49 | this.y = y; 50 | } 51 | 52 | public Type getType() { 53 | return type; 54 | } 55 | 56 | public Button getButton() { 57 | return button; 58 | } 59 | 60 | public EnumSet getModifiers() { 61 | return modifiers; 62 | } 63 | 64 | public int getX() { 65 | return x; 66 | } 67 | 68 | public int getY() { 69 | return y; 70 | } 71 | 72 | @Override 73 | public String toString() { 74 | return "MouseEvent[" + 75 | "type=" + type + 76 | ", button=" + button + 77 | ", modifiers=" + modifiers + 78 | ", x=" + x + 79 | ", y=" + y + 80 | ']'; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/terminal/Size.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2018, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.terminal; 10 | 11 | public class Size { 12 | 13 | private int rows; 14 | private int cols; 15 | 16 | public Size() { 17 | } 18 | 19 | public Size(int columns, int rows) { 20 | this(); 21 | setColumns(columns); 22 | setRows(rows); 23 | } 24 | 25 | public int getColumns() { 26 | return cols; 27 | } 28 | 29 | public void setColumns(int columns) { 30 | cols = (short) columns; 31 | } 32 | 33 | public int getRows() { 34 | return rows; 35 | } 36 | 37 | public void setRows(int rows) { 38 | this.rows = (short) rows; 39 | } 40 | 41 | /** 42 | * A cursor position combines a row number with a column position. 43 | *

44 | * Note each row has {@code col+1} different column positions, 45 | * including the right margin. 46 | *

47 | * 48 | * @param col the new column 49 | * @param row the new row 50 | * @return the cursor position 51 | */ 52 | public int cursorPos(int row, int col) { 53 | return row * (cols+1) + col; 54 | } 55 | 56 | public void copy(Size size) { 57 | setColumns(size.getColumns()); 58 | setRows(size.getRows()); 59 | } 60 | 61 | @Override 62 | public boolean equals(Object o) { 63 | if (o instanceof Size) { 64 | Size size = (Size) o; 65 | return rows == size.rows && cols == size.cols; 66 | } else { 67 | return false; 68 | } 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return rows * 31 + cols; 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "Size[" + "cols=" + cols + ", rows=" + rows + ']'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/terminal/impl/AbstractWindowsConsoleWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2017, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.terminal.impl; 10 | 11 | import java.io.IOException; 12 | import java.io.Writer; 13 | 14 | public abstract class AbstractWindowsConsoleWriter extends Writer { 15 | 16 | protected abstract void writeConsole(char[] text, int len) throws IOException; 17 | 18 | @Override 19 | public void write(char[] cbuf, int off, int len) throws IOException { 20 | char[] text = cbuf; 21 | if (off != 0) { 22 | text = new char[len]; 23 | System.arraycopy(cbuf, off, text, 0, len); 24 | } 25 | 26 | synchronized (this.lock) { 27 | writeConsole(text, len); 28 | } 29 | } 30 | 31 | @Override 32 | public void flush() { 33 | } 34 | 35 | @Override 36 | public void close() { 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/terminal/impl/NativeSignalHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.terminal.impl; 10 | 11 | import org.jline.terminal.Terminal.Signal; 12 | import org.jline.terminal.Terminal.SignalHandler; 13 | 14 | public final class NativeSignalHandler implements SignalHandler { 15 | 16 | public static final NativeSignalHandler SIG_DFL = new NativeSignalHandler(); 17 | 18 | public static final NativeSignalHandler SIG_IGN = new NativeSignalHandler(); 19 | 20 | private NativeSignalHandler() { 21 | } 22 | 23 | public void handle(Signal signal) { 24 | throw new UnsupportedOperationException(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/terminal/impl/jansi/win/JansiWinConsoleWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2017, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.terminal.impl.jansi.win; 10 | 11 | import org.fusesource.jansi.internal.WindowsSupport; 12 | import org.jline.terminal.impl.AbstractWindowsConsoleWriter; 13 | 14 | import java.io.IOException; 15 | 16 | import static org.fusesource.jansi.internal.Kernel32.GetStdHandle; 17 | import static org.fusesource.jansi.internal.Kernel32.STD_OUTPUT_HANDLE; 18 | import static org.fusesource.jansi.internal.Kernel32.WriteConsoleW; 19 | 20 | class JansiWinConsoleWriter extends AbstractWindowsConsoleWriter { 21 | 22 | private static final long console = GetStdHandle(STD_OUTPUT_HANDLE); 23 | private final int[] writtenChars = new int[1]; 24 | 25 | @Override 26 | protected void writeConsole(char[] text, int len) throws IOException { 27 | if (WriteConsoleW(console, text, len, writtenChars, 0) == 0) { 28 | throw new IOException("Failed to write to console: " + WindowsSupport.getLastErrorMessage()); 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/terminal/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | /** 10 | * JLine 3. 11 | * 12 | * @since 3.0 13 | */ 14 | package org.jline.terminal.impl; -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/terminal/spi/JansiSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2020, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.terminal.spi; 10 | 11 | import org.jline.terminal.Attributes; 12 | import org.jline.terminal.Size; 13 | import org.jline.terminal.Terminal; 14 | 15 | import java.io.IOException; 16 | import java.nio.charset.Charset; 17 | 18 | public interface JansiSupport { 19 | 20 | Pty current() throws IOException; 21 | 22 | Pty open(Attributes attributes, Size size) throws IOException; 23 | 24 | Terminal winSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, int codepage, boolean nativeSignals, Terminal.SignalHandler signalHandler) throws IOException; 25 | 26 | Terminal winSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, int codepage, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused) throws IOException; 27 | 28 | boolean isWindowsConsole(); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/terminal/spi/JnaSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2020, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.terminal.spi; 10 | 11 | import org.jline.terminal.Attributes; 12 | import org.jline.terminal.Size; 13 | import org.jline.terminal.Terminal; 14 | 15 | import java.io.IOException; 16 | import java.nio.charset.Charset; 17 | 18 | public interface JnaSupport { 19 | 20 | Pty current() throws IOException; 21 | 22 | Pty open(Attributes attributes, Size size) throws IOException; 23 | 24 | Terminal winSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, int codepage, boolean nativeSignals, Terminal.SignalHandler signalHandler) throws IOException; 25 | 26 | Terminal winSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, int codepage, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused) throws IOException; 27 | 28 | boolean isWindowsConsole(); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/terminal/spi/Pty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.terminal.spi; 10 | 11 | import java.io.Closeable; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.io.OutputStream; 15 | 16 | import org.jline.terminal.Attributes; 17 | import org.jline.terminal.Size; 18 | 19 | public interface Pty extends Closeable { 20 | 21 | InputStream getMasterInput() throws IOException; 22 | 23 | OutputStream getMasterOutput() throws IOException; 24 | 25 | InputStream getSlaveInput() throws IOException; 26 | 27 | OutputStream getSlaveOutput() throws IOException; 28 | 29 | Attributes getAttr() throws IOException; 30 | 31 | void setAttr(Attributes attr) throws IOException; 32 | 33 | Size getSize() throws IOException; 34 | 35 | void setSize(Size size) throws IOException; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/utils/ClosedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | package org.jline.utils; 10 | 11 | import java.io.IOException; 12 | 13 | public class ClosedException extends IOException { 14 | 15 | private static final long serialVersionUID = 3085420657077696L; 16 | 17 | public ClosedException() { 18 | } 19 | 20 | public ClosedException(String message) { 21 | super(message); 22 | } 23 | 24 | public ClosedException(String message, Throwable cause) { 25 | super(message, cause); 26 | } 27 | 28 | public ClosedException(Throwable cause) { 29 | super(cause); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/java/org/jline/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2016, the original author or authors. 3 | * 4 | * This software is distributable under the BSD license. See the terms of the 5 | * BSD license in the documentation provided with this software. 6 | * 7 | * https://opensource.org/licenses/BSD-3-Clause 8 | */ 9 | /** 10 | * JLine 3. 11 | * 12 | * @since 3.0 13 | */ 14 | package org.jline.utils; -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/META-INF/native-image/jline/resource-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "resources": [ 3 | {"pattern": "org/jline/utils/.*"} 4 | ] 5 | } -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/META-INF/services/org.jline.terminal.spi.JansiSupport: -------------------------------------------------------------------------------- 1 | org.jline.terminal.impl.jansi.JansiSupportImpl 2 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/jline/console/completer/CandidateListCompletionHandler.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2002-2016, the original author or authors. 3 | # 4 | # This software is distributable under the BSD license. See the terms of the 5 | # BSD license in the documentation provided with this software. 6 | # 7 | # http://www.opensource.org/licenses/bsd-license.php 8 | # 9 | 10 | DISPLAY_CANDIDATES=Display all %d possibilities? (y or n) 11 | DISPLAY_CANDIDATES_YES=y 12 | DISPLAY_CANDIDATES_NO=n 13 | DISPLAY_MORE=--More-- 14 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/org/jline/builtins/nano-browser-help.txt: -------------------------------------------------------------------------------- 1 | File Browser Help Text 2 | 3 | The file browser is used to visually browse the directory structure to select a file for reading or writing. You may use the arrow keys or Page Up/Down to browse through the files, and S or Enter to choose the selected file or enter the selected directory. To move up one level, select the directory called ".." at the top of the file list. 4 | 5 | The following function keys are available in the file browser: 6 | 7 | ^G (F1) Display this help text 8 | ^X (F2) Exit from the file browser 9 | ^W Search for a string or a regular expression 10 | (F16) (M-W) Repeat last search 11 | ^Y (F7) Move to the previous screen 12 | ^V (F8) Move to the next screen 13 | M-\ (M-|) Go to the first file in the list 14 | M-/ (M-?) Go to the last file in the list 15 | ^_ (F13) (M-G) Go to directory 16 | 17 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/org/jline/builtins/nano-goto-help.txt: -------------------------------------------------------------------------------- 1 | Go To Line Help Text 2 | 3 | Enter the line number that you wish to go to and hit Enter. If there are 4 | fewer lines of text than the number you entered, you will be brought to 5 | the last line of the file. 6 | 7 | The following function keys are available in Go To Line mode: 8 | 9 | ^G (F1) Display this help text 10 | ^C Cancel the current function 11 | ^Y Go to the first line of the file 12 | ^V Go to the last line of the file 13 | 14 | ^T Search for a string or a regular expression 15 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/org/jline/builtins/nano-read-help.txt: -------------------------------------------------------------------------------- 1 | Insert File Help Text 2 | 3 | Type in the name of a file to be inserted into the current file buffer at the current cursor location. 4 | 5 | The following function keys are available in Insert File mode: 6 | 7 | ^G (F1) Display this help text 8 | ^C Cancel the current function 9 | ^T Go to file browser 10 | ^X Execute external command 11 | M-F Toggle the use of a new buffer 12 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/org/jline/builtins/nano-replace-help.txt: -------------------------------------------------------------------------------- 1 | 2 | Search Command Help Text 3 | 4 | Enter the words or characters you would like to search for, and then press Enter. If there is a match for the text you entered, the screen will be updated to the location of the nearest match for the search string. 5 | 6 | The previous search string will be shown in brackets after the search prompt. Hitting Enter without entering any text will perform the previous search. 7 | 8 | The following function keys are available in Search mode: 9 | 10 | ^G (F1) Display this help text 11 | ^C Cancel the current function 12 | ^Y Go to the first line of the file 13 | ^V Go to the last line of the file 14 | 15 | ^P (Up) Recall the previous search/replace string 16 | ^N (Down) Recall the next search/replace string 17 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/org/jline/builtins/nano-search-help.txt: -------------------------------------------------------------------------------- 1 | Search Command Help Text 2 | 3 | Enter the words or characters you would like to search for, and then press Enter. If there is a match for the text you entered, the screen will be updated to the location of the nearest match for the search string. 4 | 5 | The previous search string will be shown in brackets after the search prompt. Hitting Enter without entering any text will perform the previous search. If you have selected text with the mark and then search to replace, only matches in the selected text will be replaced. 6 | 7 | The following function keys are available in Search mode: 8 | 9 | ^G (F1) Display this help text 10 | ^C Cancel the current function 11 | ^Y (F7) (M-\) Move to the first line of the file 12 | ^V (F8) (M-/) Move to the last line of the file 13 | ^R (F14) Replace a string or a regular expression 14 | ^T (F13) Go to line and column number 15 | ^W (M-() (M-9) Move to the beginning of the current paragraph 16 | ^O (M-)) (M-0) Move to the end of the current paragraph 17 | M-C Toggle the case sensitivity of the search 18 | M-B Reverse the direction of the search 19 | M-R Toggle the use of regular expressions 20 | ^P Recall the previous search/replace string 21 | ^N Recall the next search/replace string 22 | ^U (M-J) Justify the entire file 23 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/org/jline/builtins/nano-search-replace-help.txt: -------------------------------------------------------------------------------- 1 | 2 | Search Command Help Text 3 | 4 | Enter the words or characters you would like to search for, and then press Enter. If there is a match for the text you entered, the screen will be updated to the location of the nearest match for the search string. 5 | 6 | The previous search string will be shown in brackets after the search prompt. Hitting Enter without entering any text will perform the previous search. 7 | 8 | The following function keys are available in Search mode: 9 | 10 | ^G (F1) Display this help text 11 | ^C Cancel the current function 12 | M-C Toggle the case sensitivity of the search 13 | M-R Toggle the use of regular expressions 14 | M-B Reverse the direction of the search 15 | ^R Search for a string or a regular expression 16 | ^Y Go to the first line of the file 17 | ^V Go to the last line of the file 18 | 19 | ^P (Up) Recall the previous search/replace string 20 | ^N (Down) Recall the next search/replace string 21 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/org/jline/builtins/nano-write-help.txt: -------------------------------------------------------------------------------- 1 | Write File Help Text 2 | 3 | Type the name that you wish to save the current file as and press Enter to save the file. 4 | 5 | If you have selected text with the mark, you will be prompted to save only the selected portion to a separate file. To reduce the chance of overwriting the current file with just a portion of it, the current filename is not the default in this mode. 6 | 7 | The following function keys are available in Write File mode: 8 | 9 | ^G (F1) Display this help text 10 | ^C Cancel the current function 11 | ^T Go to file browser 12 | M-D Toggle the use of DOS format 13 | M-M Toggle the use of Mac format 14 | M-A Toggle appending 15 | M-P Toggle prepending 16 | M-B Toggle backing up of the original file 17 | 18 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/org/jline/utils/ansi.caps: -------------------------------------------------------------------------------- 1 | # Reconstructed via infocmp from file: /usr/share/terminfo/61/ansi 2 | ansi|ansi/pc-term compatible with color, 3 | am, mc5i, mir, msgr, 4 | colors#8, cols#80, it#8, lines#24, ncv#3, pairs#64, 5 | acsc=+\020\,\021-\030.^Y0\333`\004a\261f\370g\361h\260j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376, 6 | bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, clear=\E[H\E[J, 7 | cr=^M, cub=\E[%p1%dD, cub1=\E[D, cud=\E[%p1%dB, cud1=\E[B, 8 | cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH, 9 | cuu=\E[%p1%dA, cuu1=\E[A, dch=\E[%p1%dP, dch1=\E[P, 10 | dl=\E[%p1%dM, dl1=\E[M, ech=\E[%p1%dX, ed=\E[J, el=\E[K, 11 | el1=\E[1K, home=\E[H, hpa=\E[%i%p1%dG, ht=\E[I, hts=\EH, 12 | ich=\E[%p1%d@, il=\E[%p1%dL, il1=\E[L, ind=^J, 13 | indn=\E[%p1%dS, invis=\E[8m, kbs=^H, kcbt=\E[Z, kcub1=\E[D, 14 | kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, khome=\E[H, kich1=\E[L, 15 | mc4=\E[4i, mc5=\E[5i, nel=\r\E[S, op=\E[39;49m, 16 | rep=%p1%c\E[%p2%{1}%-%db, rev=\E[7m, rin=\E[%p1%dT, 17 | rmacs=\E[10m, rmpch=\E[10m, rmso=\E[m, rmul=\E[m, 18 | s0ds=\E(B, s1ds=\E)B, s2ds=\E*B, s3ds=\E+B, 19 | setab=\E[4%p1%dm, setaf=\E[3%p1%dm, 20 | sgr=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m, 21 | sgr0=\E[0;10m, smacs=\E[11m, smpch=\E[11m, smso=\E[7m, 22 | smul=\E[4m, tbc=\E[2g, u6=\E[%i%d;%dR, u7=\E[6n, 23 | u8=\E[?%[;0123456789]c, u9=\E[c, vpa=\E[%i%p1%dd, 24 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/org/jline/utils/dumb-color.caps: -------------------------------------------------------------------------------- 1 | dumb-color|80-column dumb tty with 256 coors, 2 | am, 3 | colors#256, cols#80, 4 | bel=^G, cr=^M, cud1=^J, ind=^J, 5 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/org/jline/utils/dumb.caps: -------------------------------------------------------------------------------- 1 | # Reconstructed via infocmp from file: /usr/share/terminfo/64/dumb 2 | dumb|80-column dumb tty, 3 | am, 4 | cols#80, 5 | bel=^G, cr=^M, cud1=^J, ind=^J, 6 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/org/jline/utils/screen-256color.caps: -------------------------------------------------------------------------------- 1 | # Reconstructed via infocmp from file: /usr/share/terminfo/73/screen-256color 2 | screen-256color|GNU Screen with 256 colors, 3 | am, km, mir, msgr, xenl, 4 | colors#256, cols#80, it#8, lines#24, ncv#3, pairs#32767, 5 | acsc=++\,\,--..00``aaffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, 6 | bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, civis=\E[?25l, 7 | clear=\E[H\E[J, cnorm=\E[34h\E[?25h, cr=^M, 8 | csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H, 9 | cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C, 10 | cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\EM, 11 | cvvis=\E[34l, dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM, 12 | dl1=\E[M, ed=\E[J, el=\E[K, el1=\E[1K, enacs=\E(B\E)0, 13 | flash=\Eg, home=\E[H, ht=^I, hts=\EH, ich=\E[%p1%d@, 14 | il=\E[%p1%dL, il1=\E[L, ind=^J, initc@, is2=\E)0, kbs=^H, 15 | kcbt=\E[Z, kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, 16 | kdch1=\E[3~, kend=\E[4~, kf1=\EOP, kf10=\E[21~, 17 | kf11=\E[23~, kf12=\E[24~, kf2=\EOQ, kf3=\EOR, kf4=\EOS, 18 | kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, 19 | khome=\E[1~, kich1=\E[2~, kmous=\E[M, knp=\E[6~, kpp=\E[5~, 20 | nel=\EE, op=\E[39;49m, rc=\E8, rev=\E[7m, ri=\EM, rmacs=^O, 21 | rmcup=\E[?1049l, rmir=\E[4l, rmkx=\E[?1l\E>, rmso=\E[23m, 22 | rmul=\E[24m, rs2=\Ec\E[?1000l\E[?25h, sc=\E7, 23 | setab=\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m, 24 | setaf=\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m, 25 | sgr=\E[0%?%p6%t;1%;%?%p1%t;3%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;m%?%p9%t\016%e\017%;, 26 | sgr0=\E[m\017, smacs=^N, smcup=\E[?1049h, smir=\E[4h, 27 | smkx=\E[?1h\E=, smso=\E[3m, smul=\E[4m, tbc=\E[3g, 28 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/org/jline/utils/screen.caps: -------------------------------------------------------------------------------- 1 | # Reconstructed via infocmp from file: /usr/share/terminfo/73/screen 2 | screen|VT 100/ANSI X3.64 virtual terminal, 3 | am, km, mir, msgr, xenl, 4 | colors#8, cols#80, it#8, lines#24, ncv#3, pairs#64, 5 | acsc=++\,\,--..00``aaffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, 6 | bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, civis=\E[?25l, 7 | clear=\E[H\E[J, cnorm=\E[34h\E[?25h, cr=^M, 8 | csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H, 9 | cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C, 10 | cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\EM, 11 | cvvis=\E[34l, dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM, 12 | dl1=\E[M, ed=\E[J, el=\E[K, el1=\E[1K, enacs=\E(B\E)0, 13 | flash=\Eg, home=\E[H, ht=^I, hts=\EH, ich=\E[%p1%d@, 14 | il=\E[%p1%dL, il1=\E[L, ind=^J, is2=\E)0, kbs=^H, kcbt=\E[Z, 15 | kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, 16 | kdch1=\E[3~, kend=\E[4~, kf1=\EOP, kf10=\E[21~, 17 | kf11=\E[23~, kf12=\E[24~, kf2=\EOQ, kf3=\EOR, kf4=\EOS, 18 | kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, 19 | khome=\E[1~, kich1=\E[2~, kmous=\E[M, knp=\E[6~, kpp=\E[5~, 20 | nel=\EE, op=\E[39;49m, rc=\E8, rev=\E[7m, ri=\EM, rmacs=^O, 21 | rmcup=\E[?1049l, rmir=\E[4l, rmkx=\E[?1l\E>, rmso=\E[23m, 22 | rmul=\E[24m, rs2=\Ec\E[?1000l\E[?25h, sc=\E7, 23 | setab=\E[4%p1%dm, setaf=\E[3%p1%dm, 24 | sgr=\E[0%?%p6%t;1%;%?%p1%t;3%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;m%?%p9%t\016%e\017%;, 25 | sgr0=\E[m\017, smacs=^N, smcup=\E[?1049h, smir=\E[4h, 26 | smkx=\E[?1h\E=, smso=\E[3m, smul=\E[4m, tbc=\E[3g, 27 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/org/jline/utils/windows-256color.caps: -------------------------------------------------------------------------------- 1 | windows-256color|windows with 256 colors terminal compatibility, 2 | am, mc5i, mir, msgr, 3 | colors#256, cols#80, it#8, lines#24, ncv#3, pairs#64, 4 | bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, clear=\E[H\E[J, 5 | cr=^M, cub=\E[%p1%dD, cub1=\E[D, cud=\E[%p1%dB, cud1=\E[B, 6 | cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH, 7 | cuu=\E[%p1%dA, cuu1=\E[A, 8 | il=\E[%p1%dL, il1=\E[L, 9 | dl=\E[%p1%dM, dl1=\E[M, 10 | ech=\E[%p1%dX, 11 | el=\E[K, ed=\E[J, 12 | el1=\E[1K, home=\E[H, hpa=\E[%i%p1%dG, 13 | ind=^J, 14 | invis=\E[8m, kbs=^H, kcbt=\E[Z, 15 | kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, 16 | khome=\E[H, 17 | op=\E[39;49m, 18 | rev=\E[7m, 19 | rmacs=\E[10m, rmpch=\E[10m, rmso=\E[m, rmul=\E[m, 20 | setab=\E[4%p1%dm, setaf=\E[3%p1%dm, 21 | sgr=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m, 22 | sgr0=\E[0;10m, 23 | smso=\E[7m, 24 | smul=\E[4m, 25 | kdch1=\E[3~, kich1=\E[2~, kend=\E[4~, knp=\E[6~, kpp=\E[5~, 26 | kf1=\EOP, kf2=\EOQ, kf3=\EOR, kf4=\EOS, kf5=\E[15~, kf6=\E[17~, 27 | kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, kf10=\E[21~, kf11=\E[23~, kf12=\E[24~, 28 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/org/jline/utils/windows-conemu.caps: -------------------------------------------------------------------------------- 1 | windows-conemu|conemu windows terminal, 2 | am, mc5i, mir, msgr, 3 | colors#256, cols#80, it#8, lines#24, ncv#3, pairs#64, 4 | bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, clear=\E[H\E[J, 5 | cr=^M, cub=\E[%p1%dD, cub1=\E[D, cud=\E[%p1%dB, cud1=\E[B, 6 | cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH, 7 | cuu=\E[%p1%dA, cuu1=\E[A, 8 | il=\E[%p1%dL, il1=\E[L, 9 | dl=\E[%p1%dM, dl1=\E[M, 10 | ech=\E[%p1%dX, 11 | el=\E[K, ed=\E[J, 12 | el1=\E[1K, home=\E[H, hpa=\E[%i%p1%dG, 13 | ind=^J, 14 | invis=\E[8m, kbs=^H, kcbt=\E[Z, 15 | kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, 16 | khome=\E[H, 17 | op=\E[39;49m, 18 | rev=\E[7m, 19 | rmacs=\E[10m, rmpch=\E[10m, rmso=\E[m, rmul=\E[m, 20 | setab=\E[4%p1%dm, setaf=\E[3%p1%dm, 21 | sgr=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m, 22 | sgr0=\E[0;10m, 23 | smso=\E[7m, 24 | smul=\E[4m, 25 | kdch1=\E[3~, kich1=\E[2~, kend=\E[4~, knp=\E[6~, kpp=\E[5~, 26 | kf1=\EOP, kf2=\EOQ, kf3=\EOR, kf4=\EOS, kf5=\E[15~, kf6=\E[17~, 27 | kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, kf10=\E[21~, kf11=\E[23~, kf12=\E[24~, 28 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/org/jline/utils/windows-vtp.caps: -------------------------------------------------------------------------------- 1 | windows-vtp|windows with virtual terminal processing, 2 | am, mc5i, mir, msgr, 3 | colors#256, cols#80, it#8, lines#24, ncv#3, pairs#64, 4 | bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, clear=\E[H\E[J, 5 | cr=^M, cub=\E[%p1%dD, cub1=\E[D, cud=\E[%p1%dB, cud1=\E[B, 6 | cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH, 7 | cuu=\E[%p1%dA, cuu1=\E[A, 8 | il=\E[%p1%dL, il1=\E[L, 9 | dl=\E[%p1%dM, dl1=\E[M, 10 | ech=\E[%p1%dX, 11 | el=\E[K, ed=\E[J, 12 | el1=\E[1K, home=\E[H, hpa=\E[%i%p1%dG, 13 | ind=^J, 14 | invis=\E[8m, kbs=^H, kcbt=\E[Z, 15 | kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, 16 | khome=\E[H, 17 | op=\E[39;49m, 18 | rev=\E[7m, 19 | rmacs=\E[10m, rmpch=\E[10m, rmso=\E[m, rmul=\E[m, 20 | setab=\E[4%p1%dm, setaf=\E[3%p1%dm, 21 | sgr=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m, 22 | sgr0=\E[0;10m, 23 | smso=\E[7m, 24 | smul=\E[4m, 25 | kdch1=\E[3~, kich1=\E[2~, kend=\E[4~, knp=\E[6~, kpp=\E[5~, 26 | kf1=\EOP, kf2=\EOQ, kf3=\EOR, kf4=\EOS, kf5=\E[15~, kf6=\E[17~, 27 | kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, kf10=\E[21~, kf11=\E[23~, kf12=\E[24~, 28 | smcup=\E[?1049h, rmcup=\E[?1049l, indn=\E[%p1%dS, rin=\E[%p1%dT, 29 | ich=\E[%p1%d@, dch=\E[%p1%dP, ech=\E[%p1%dX, il=\E[%p1%dL, dl=\E[%p1%dM, 30 | sc=\E7, rc=\E8, cnorm=\E[?12l\E[?25h, civis=\E[?25l, cvvis=\E[?12h\E[?25h, 31 | smkx=\E[?1h\E=, rmkx=\E[?1l\E>, u6=\E[%i%d;%dR, u7=\E[6n, 32 | hts=\EH, smacs=\E(0, rmacs=\E(B, 33 | csr=\E[%i%p1%d;%p2%dr, 34 | -------------------------------------------------------------------------------- /xpocket-jline/src/main/resources/org/jline/utils/windows.caps: -------------------------------------------------------------------------------- 1 | windows|windows terminal compatibility, 2 | am, mc5i, mir, msgr, 3 | colors#16, cols#80, it#8, lines#24, ncv#3, pairs#64, 4 | bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, clear=\E[H\E[J, 5 | cr=^M, cub=\E[%p1%dD, cub1=\E[D, cud=\E[%p1%dB, cud1=\E[B, 6 | cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH, 7 | cuu=\E[%p1%dA, cuu1=\E[A, 8 | il=\E[%p1%dL, il1=\E[L, 9 | dl=\E[%p1%dM, dl1=\E[M, 10 | ech=\E[%p1%dX, 11 | el=\E[K, ed=\E[J, 12 | el1=\E[1K, home=\E[H, hpa=\E[%i%p1%dG, 13 | ind=^J, 14 | invis=\E[8m, kbs=^H, kcbt=\E[Z, 15 | kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, 16 | khome=\E[H, 17 | op=\E[39;49m, 18 | rev=\E[7m, 19 | rmacs=\E[10m, rmpch=\E[10m, rmso=\E[m, rmul=\E[m, 20 | setab=\E[4%p1%dm, setaf=\E[3%p1%dm, 21 | sgr=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m, 22 | sgr0=\E[0;10m, 23 | smso=\E[7m, 24 | smul=\E[4m, 25 | kdch1=\E[3~, kich1=\E[2~, kend=\E[4~, knp=\E[6~, kpp=\E[5~, 26 | kf1=\EOP, kf2=\EOQ, kf3=\EOR, kf4=\EOS, kf5=\E[15~, kf6=\E[17~, 27 | kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, kf10=\E[21~, kf11=\E[23~, kf12=\E[24~, 28 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/AbstractXPocketAgentPlugin.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi; 2 | 3 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 4 | import java.lang.instrument.Instrumentation; 5 | 6 | /** 7 | * 8 | * @author gongyu 9 | */ 10 | public abstract class AbstractXPocketAgentPlugin extends AbstractXPocketPlugin 11 | implements XPocketAgentPlugin { 12 | 13 | @Override 14 | public void init(XPocketProcess process, Instrumentation inst, 15 | boolean isOnLoad) {} 16 | 17 | } 18 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/AbstractXPocketPlugin.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi; 2 | 3 | import com.perfma.xlab.xpocket.spi.context.SessionContext; 4 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 5 | 6 | /** 7 | * empty implementation of XPocketPlugin 8 | * @author gongyu 9 | */ 10 | public abstract class AbstractXPocketPlugin implements XPocketPlugin { 11 | 12 | @Override 13 | public void init(XPocketProcess process) {} 14 | 15 | @Override 16 | public void destory() throws Throwable {} 17 | 18 | @Override 19 | public void switchOn(SessionContext context) {} 20 | 21 | @Override 22 | public void switchOff(SessionContext context) {} 23 | 24 | @Override 25 | public void printLogo(XPocketProcess process) {} 26 | 27 | @Override 28 | public String logo() { 29 | return null; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/XPocketAgentPlugin.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi; 2 | 3 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 4 | import java.lang.instrument.Instrumentation; 5 | 6 | /** 7 | * Abstract Definition for Plugin that attached on target JVM processor. 8 | * @author gongyu 9 | */ 10 | public interface XPocketAgentPlugin extends XPocketPlugin { 11 | 12 | void init(XPocketProcess process,Instrumentation inst,boolean isOnLoad); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/XPocketPlugin.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi; 2 | 3 | import com.perfma.xlab.xpocket.spi.context.SessionContext; 4 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 5 | 6 | /** 7 | * @author TONG YIN 8 | */ 9 | public interface XPocketPlugin { 10 | 11 | /** 12 | * init the plugin 13 | * 14 | * @param process process info of current xpocket runtime 15 | */ 16 | void init(XPocketProcess process); 17 | 18 | /** 19 | * destory the resource current plugin used. 20 | * @throws java.lang.Throwable 21 | */ 22 | void destory() throws Throwable; 23 | 24 | /** 25 | * when XPocket switched on this plugin,it will call this method 26 | * @param context 27 | */ 28 | void switchOn(SessionContext context); 29 | 30 | /** 31 | * when XPocket switched off or leave this plugin,it will call this method 32 | * @param context 33 | */ 34 | void switchOff(SessionContext context); 35 | 36 | /** 37 | * print plugin`s own logo when switch in this plugin 38 | * @param process 39 | */ 40 | @Deprecated 41 | void printLogo(XPocketProcess process); 42 | 43 | /** 44 | * fetch logo string if the plugin has its own. 45 | * @return string object of plugin ascii art logo 46 | */ 47 | String logo(); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/command/AbstractXPocketCommand.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi.command; 2 | 3 | import com.perfma.xlab.xpocket.spi.context.SessionContext; 4 | import com.perfma.xlab.xpocket.spi.XPocketPlugin; 5 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 6 | 7 | /** 8 | * 9 | * @author gongyu 10 | */ 11 | public abstract class AbstractXPocketCommand implements XPocketCommand { 12 | 13 | protected XPocketPlugin plugin; 14 | 15 | @Override 16 | public boolean isPiped() { 17 | //false for default 18 | return false; 19 | } 20 | 21 | @Override 22 | public void init(XPocketPlugin plugin) { 23 | this.plugin = plugin; 24 | } 25 | 26 | @Override 27 | public boolean isAvailableNow(String cmd) { 28 | return true; 29 | } 30 | 31 | @Override 32 | public String details(String cmd) { 33 | return null; 34 | } 35 | 36 | @Override 37 | public void invoke(XPocketProcess process, SessionContext context) throws Throwable { 38 | invoke(process); 39 | } 40 | 41 | public void invoke(XPocketProcess process) throws Throwable {} 42 | 43 | @Override 44 | public String[] tips() { 45 | return null; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/command/CommandInfo.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi.command; 2 | 3 | import com.perfma.xlab.xpocket.spi.context.JavaTarget; 4 | import com.perfma.xlab.xpocket.spi.context.PluginType; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Repeatable; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | /** 12 | * 13 | * @author gongyu 14 | */ 15 | @Target(ElementType.TYPE) 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Repeatable(value=CommandInfos.class) 18 | public @interface CommandInfo { 19 | 20 | String name(); 21 | 22 | String shortName() default ""; 23 | 24 | String usage() default ""; 25 | 26 | PluginType type() default PluginType.ALL; 27 | 28 | JavaTarget target() default JavaTarget.ALL; 29 | 30 | int index() default 50; 31 | } 32 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/command/CommandInfos.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi.command; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * 10 | * @author gongyu 11 | */ 12 | @Target(ElementType.TYPE) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | public @interface CommandInfos { 15 | CommandInfo[] value(); 16 | } 17 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/command/CommandList.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi.command; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * 10 | * @author gongyu 11 | */ 12 | @Target(ElementType.TYPE) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | public @interface CommandList { 15 | 16 | String[] names(); 17 | 18 | String[] usage() default ""; 19 | } 20 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/command/XPocketCommand.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi.command; 2 | 3 | import com.perfma.xlab.xpocket.spi.XPocketPlugin; 4 | import com.perfma.xlab.xpocket.spi.context.SessionContext; 5 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 6 | 7 | /** 8 | * @author gongyu 9 | */ 10 | public interface XPocketCommand { 11 | 12 | 13 | /** 14 | * init XPocketCommand instance 15 | * @param plugin 16 | */ 17 | void init(XPocketPlugin plugin); 18 | 19 | /** 20 | * Do this command support piped execution. 21 | * 22 | * @return 23 | */ 24 | boolean isPiped(); 25 | 26 | /** 27 | * checking the command is avaible now 28 | * 29 | * @param cmd 30 | * @return 31 | */ 32 | boolean isAvailableNow(String cmd); 33 | 34 | /** 35 | * detail current command 36 | * @return 37 | */ 38 | String details(String cmd); 39 | 40 | /** 41 | * invoke 42 | * 43 | * @param process 44 | * @param context 45 | * @throws java.lang.Throwable 46 | */ 47 | void invoke(XPocketProcess process, SessionContext context) throws Throwable; 48 | 49 | /** 50 | * return some details of command usage. 51 | * @return 52 | */ 53 | String[] tips(); 54 | 55 | } 56 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/command/XPocketProcessTemplate.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi.command; 2 | 3 | import com.perfma.xlab.xpocket.spi.command.callback.ProcessCallback; 4 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 5 | import com.perfma.xlab.xpocket.spi.command.callback.SimpleProcessCallback; 6 | import java.util.Arrays; 7 | 8 | /** 9 | * 10 | * @author gongyu 11 | */ 12 | public class XPocketProcessTemplate { 13 | 14 | private static final String ERROR_MSG_FORMAT = "ERROR : execute %s failed " 15 | + "with params %s, on error : %s"; 16 | 17 | /** 18 | * execute process 19 | * @param process 20 | * @param callback 21 | */ 22 | public static void execute(XPocketProcess process, 23 | SimpleProcessCallback callback) { 24 | String cmd = process.getCmd(); 25 | String[] args = process.getArgs(); 26 | try { 27 | String output = callback.call(cmd, args); 28 | process.output(output); 29 | } catch (Throwable ex) { 30 | process.output(String.format(ERROR_MSG_FORMAT, 31 | cmd,Arrays.toString(args),ex.getMessage())); 32 | } finally { 33 | process.end(); 34 | } 35 | } 36 | 37 | public static void execute(XPocketProcess process, 38 | ProcessCallback callback) { 39 | String cmd = process.getCmd(); 40 | String[] args = process.getArgs(); 41 | try { 42 | String output = callback.call(process,cmd, args); 43 | process.output(output); 44 | } catch (Throwable ex) { 45 | process.output(String.format(ERROR_MSG_FORMAT, 46 | cmd,Arrays.toString(args),ex.getMessage())); 47 | } finally { 48 | process.end(); 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/command/callback/ProcessCallback.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi.command.callback; 2 | 3 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 4 | 5 | /** 6 | * 7 | * @author gongyu 8 | */ 9 | public interface ProcessCallback { 10 | 11 | /** 12 | * 13 | * @param process 14 | * @param cmd 15 | * @param args 16 | * @return 17 | * @throws Throwable 18 | */ 19 | String call(XPocketProcess process,String cmd,String[] args) throws Throwable; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/command/callback/SimpleProcessCallback.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi.command.callback; 2 | 3 | /** 4 | * 5 | * @author gongyu 6 | */ 7 | public interface SimpleProcessCallback { 8 | 9 | /** 10 | * 11 | * @param cmd 12 | * @param args 13 | * @return 14 | * @throws java.lang.Throwable 15 | */ 16 | String call(String cmd,String[] args) throws Throwable; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/context/CommandBaseInfo.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi.context; 2 | 3 | import com.perfma.xlab.xpocket.spi.command.XPocketCommand; 4 | 5 | /** 6 | * @author gongyu 7 | */ 8 | public interface CommandBaseInfo { 9 | 10 | /** 11 | * command name 12 | * 13 | * @return 14 | */ 15 | String name(); 16 | 17 | /** 18 | * short for command name 19 | * @return 20 | */ 21 | String shortName(); 22 | 23 | /** 24 | * command info 25 | * 26 | * @return 27 | */ 28 | String usage(); 29 | 30 | /** 31 | * command index, Determines the order in which information is displayed in Help 32 | * 33 | * @return 34 | */ 35 | int index(); 36 | 37 | /** 38 | * command instance 39 | * 40 | * @return 41 | */ 42 | XPocketCommand instance(); 43 | } 44 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/context/ExecuteContext.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi.context; 2 | 3 | /** 4 | * @author: ZQF 5 | * @date: 2021-04-16 6 | * @description: desc 7 | */ 8 | public interface ExecuteContext { 9 | 10 | /** 11 | * 添加内置变量 12 | * @param var 变量 13 | */ 14 | void addInternalVar(String var); 15 | } 16 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/context/JavaTarget.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi.context; 2 | 3 | /** 4 | * 5 | * @author gongyu 6 | */ 7 | public enum JavaTarget { 8 | ALL(0), 9 | JAVA8(8), 10 | JAVA9(9), 11 | JAVA10(10), 12 | JAVA11(11), 13 | JAVA12(12), 14 | JAVA13(13), 15 | JAVA14(14); 16 | 17 | private int version; 18 | 19 | JavaTarget(int version) { 20 | this.version = version; 21 | } 22 | 23 | public int getVersion() { 24 | return this.version; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/context/PluginType.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi.context; 2 | 3 | /** 4 | * @author gongyu 5 | */ 6 | public enum PluginType { 7 | 8 | JAVA,C,ALL,JAVA_AGENT; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/context/SessionContext.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi.context; 2 | 3 | /** 4 | * 5 | * @author gongyu 6 | */ 7 | public interface SessionContext { 8 | 9 | /** 10 | * Get current plugin context 11 | * @return 12 | */ 13 | PluginBaseInfo currentPlugin(); 14 | 15 | /** 16 | * Get current command context, if exist 17 | * @return 18 | */ 19 | CommandBaseInfo currentCommand(); 20 | 21 | /** 22 | * if current plugin attached on a process,here is the id of the process 23 | * @return 24 | */ 25 | int pid(); 26 | 27 | /** 28 | * tell XPocket if you attached on a process now 29 | * @param pid 30 | */ 31 | void setPid(int pid); 32 | 33 | /** 34 | * if current plugin connected a network,here is the infomation of the network 35 | * @return 36 | */ 37 | String networkInfo(); 38 | 39 | /** 40 | * tell XPocket if you connected a network now 41 | * @param networkInfo 42 | */ 43 | void setNetworkInfo(String networkInfo); 44 | 45 | /** 46 | * set a property 47 | * @param key 48 | * @param value 49 | */ 50 | void setProp(String key,String value); 51 | 52 | /** 53 | * get a property value 54 | * @param key 55 | * @return 56 | */ 57 | String getProp(String key); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/process/XPocketProcess.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi.process; 2 | 3 | import com.perfma.xlab.xpocket.spi.context.ExecuteContext; 4 | 5 | /** 6 | * @author gongyu 7 | */ 8 | public interface XPocketProcess { 9 | 10 | /** 11 | * get command name 12 | * 13 | * @return 14 | */ 15 | String getCmd(); 16 | 17 | /** 18 | * get command args 19 | * 20 | * @return 21 | */ 22 | String[] getArgs(); 23 | 24 | /** 25 | * get input for piped execution 26 | * 27 | * @return 28 | */ 29 | String input(); 30 | 31 | /** 32 | * output 33 | * 34 | * @param output 35 | */ 36 | void output(String output); 37 | 38 | /** 39 | * process end 40 | */ 41 | void end(); 42 | 43 | /** 44 | * Register to monitor 45 | * 46 | * @param action 47 | */ 48 | void register(XPocketProcessAction action); 49 | 50 | /** 51 | * unregister 52 | * 53 | * @param action 54 | */ 55 | void unregister(XPocketProcessAction action); 56 | 57 | /** 58 | * Get ExecuteContext 59 | * 60 | * @return 61 | */ 62 | ExecuteContext getExecuteContext(); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /xpocket-plugin-spi/src/main/java/com/perfma/xlab/xpocket/spi/process/XPocketProcessAction.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.spi.process; 2 | 3 | /** 4 | * 5 | * @author gongyu 6 | */ 7 | public interface XPocketProcessAction { 8 | 9 | void userInput(String input) throws Throwable; 10 | 11 | void interrupt() throws Throwable; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /xpocket-runtime/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.perfma.xlab 7 | xpocket-parent 8 | 2.1.2-alpha 9 | ../pom.xml 10 | 11 | 4.0.0 12 | 13 | xpocket-runtime 14 | jar 15 | 16 | 17 | true 18 | 19 | 20 | 21 | 22 | com.perfma.xlab 23 | xpocket-framework-spi 24 | 25 | 26 | com.perfma.xlab 27 | xpocket-jline 28 | 29 | 30 | com.perfma.xlab 31 | xpocket-scroll 32 | 33 | 34 | org.fusesource.jansi 35 | jansi 36 | 37 | 38 | org.apache.commons 39 | commons-exec 40 | 41 | 42 | commons-io 43 | commons-io 44 | 45 | 46 | 47 | com.perfma.wrapped 48 | com.sun.tools 49 | 50 | 51 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/command/AbstractSystemCommand.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.command; 2 | 3 | import com.perfma.xlab.xpocket.spi.command.AbstractXPocketCommand; 4 | import org.jline.reader.impl.LineReaderImpl; 5 | 6 | /** 7 | * 8 | * @author gongyu 9 | */ 10 | public abstract class AbstractSystemCommand extends AbstractXPocketCommand { 11 | 12 | private LineReaderImpl reader; 13 | 14 | protected LineReaderImpl getReader() { 15 | return reader; 16 | } 17 | 18 | public void setReader(LineReaderImpl reader) { 19 | this.reader = reader; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/command/impl/AttachCommand.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.command.impl; 2 | 3 | import com.perfma.xlab.xpocket.command.AbstractSystemCommand; 4 | import com.perfma.xlab.xpocket.spi.command.CommandInfo; 5 | import com.perfma.xlab.xpocket.spi.context.SessionContext; 6 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 7 | import com.perfma.xlab.xpocket.utils.XPocketConstants; 8 | 9 | /** 10 | * 11 | * @author gongyu 12 | */ 13 | @CommandInfo(name = "attach", usage = "attach on a java process,attach [pid]", index = 99) 14 | public class AttachCommand extends AbstractSystemCommand { 15 | 16 | @Override 17 | public void invoke(XPocketProcess process, SessionContext context) throws Throwable { 18 | String result; 19 | try { 20 | String pid = process.getArgs()[0]; 21 | String errorInfo = XPocketConstants.DEFAULT_ADAPTOR.attach(process, pid); 22 | if ("OK".equalsIgnoreCase(errorInfo)) { 23 | result = String.format("Attach to target process success : %s", 24 | pid); 25 | process.output(result); 26 | } else { 27 | result = String.format("ERROR : %s", errorInfo); 28 | process.output(result); 29 | process.end(); 30 | } 31 | } catch (Throwable ex) { 32 | result = String.format("ERROR : %s", ex.getMessage()); 33 | process.output(result); 34 | process.end(); 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/command/impl/CdCommand.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.command.impl; 2 | 3 | import com.perfma.xlab.xpocket.command.AbstractSystemCommand; 4 | import com.perfma.xlab.xpocket.framework.spi.impl.XPocketStatusContext; 5 | import com.perfma.xlab.xpocket.plugin.manager.PluginManager; 6 | import com.perfma.xlab.xpocket.spi.command.CommandInfo; 7 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 8 | import com.perfma.xlab.xpocket.utils.TerminalUtil; 9 | import com.perfma.xlab.xpocket.utils.XPocketConstants; 10 | 11 | /** 12 | * @author: TuGai 13 | **/ 14 | @CommandInfo(name = "cd", usage = "change current context to system", index = 13) 15 | public class CdCommand extends AbstractSystemCommand { 16 | 17 | @Override 18 | public void invoke(XPocketProcess process) { 19 | try { 20 | XPocketStatusContext.open(PluginManager 21 | .getPlugin(XPocketConstants.SYSTEM_PLUGIN_NAME, 22 | XPocketConstants.SYSTEM_PLUGIN_NS), process); 23 | TerminalUtil.printHelp(process, 24 | XPocketStatusContext.instance.currentPlugin()); 25 | process.end(); 26 | } catch (Throwable ex) { 27 | ex.printStackTrace(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/command/impl/ClearCommand.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.command.impl; 2 | 3 | import com.perfma.xlab.xpocket.command.AbstractSystemCommand; 4 | import com.perfma.xlab.xpocket.spi.command.CommandInfo; 5 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 6 | 7 | /** 8 | * @author gongyu 9 | */ 10 | @CommandInfo(name = "clear", usage = "clear the screan", index = 16) 11 | public class ClearCommand extends AbstractSystemCommand { 12 | 13 | @Override 14 | public void invoke(XPocketProcess process) throws Throwable { 15 | getReader().clearScreen(); 16 | process.end(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/command/impl/DetachCommand.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.command.impl; 2 | 3 | import com.perfma.xlab.xpocket.command.AbstractSystemCommand; 4 | import com.perfma.xlab.xpocket.spi.command.CommandInfo; 5 | import com.perfma.xlab.xpocket.spi.command.XPocketProcessTemplate; 6 | import com.perfma.xlab.xpocket.spi.context.SessionContext; 7 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 8 | import com.perfma.xlab.xpocket.utils.XPocketConstants; 9 | 10 | /** 11 | * 12 | * @author gongyu 13 | */ 14 | @CommandInfo(name = "detach", usage = "disconnect with the java process,detach", index = 99) 15 | public class DetachCommand extends AbstractSystemCommand { 16 | 17 | @Override 18 | public void invoke(XPocketProcess process, SessionContext context) throws Throwable { 19 | XPocketProcessTemplate.execute(process, 20 | (String cmd, String[] args) -> 21 | { 22 | XPocketConstants.DEFAULT_ADAPTOR.detach(process); 23 | return "Detach with target process success"; 24 | }); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/command/impl/EchoCommand.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.command.impl; 2 | 3 | import com.perfma.xlab.xpocket.command.AbstractSystemCommand; 4 | import com.perfma.xlab.xpocket.spi.command.CommandInfo; 5 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 6 | 7 | /** 8 | * @author: yin.tong 9 | **/ 10 | @CommandInfo(name = "echo", usage = "print input strings", index = 99) 11 | public class EchoCommand extends AbstractSystemCommand { 12 | 13 | @Override 14 | public void invoke(XPocketProcess process) { 15 | try { 16 | if(process.getArgs() != null && process.getArgs().length > 0) { 17 | process.output(process.getArgs()[0]); 18 | } 19 | process.end(); 20 | } catch (Throwable ex) { 21 | ex.printStackTrace(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/command/impl/GrepCommand.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.command.impl; 2 | 3 | import com.perfma.xlab.xpocket.command.AbstractSystemCommand; 4 | import com.perfma.xlab.xpocket.spi.command.CommandInfo; 5 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 6 | 7 | /** 8 | * @author gongyu 9 | */ 10 | @CommandInfo(name = "grep", usage = "grep -I [subText] handle content from pipe", index = 9) 11 | public class GrepCommand extends AbstractSystemCommand { 12 | 13 | @Override 14 | public boolean isPiped() { 15 | return true; 16 | } 17 | 18 | @Override 19 | public void invoke(XPocketProcess process) throws Throwable { 20 | 21 | String content = process.input(); 22 | String[] args = process.getArgs() == null 23 | ? new String[0] 24 | : process.getArgs(); 25 | String subText = null; 26 | boolean ignoreCase = true; 27 | 28 | for (int i = 0; i < args.length; i++) { 29 | String arg = args[i]; 30 | switch (arg) { 31 | case "-I": 32 | ignoreCase = false; 33 | break; 34 | default: 35 | subText = arg; 36 | } 37 | } 38 | 39 | if (content == null || subText == null) { 40 | process.end(); 41 | } 42 | 43 | if (ignoreCase && content.toLowerCase().contains(subText.toLowerCase())) { 44 | process.output(content); 45 | } else if (content.contains(subText)) { 46 | process.output(content); 47 | } 48 | 49 | process.end(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/command/impl/HistoryCommand.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.command.impl; 2 | 3 | import com.perfma.xlab.xpocket.command.AbstractSystemCommand; 4 | import com.perfma.xlab.xpocket.spi.command.CommandInfo; 5 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 6 | import org.jline.reader.History; 7 | 8 | import java.util.ListIterator; 9 | 10 | /** 11 | * @author xinxian 12 | * @create 2020-11-02 20:33 13 | **/ 14 | @CommandInfo(name = "history", usage = "list command history", index = 14) 15 | public class HistoryCommand extends AbstractSystemCommand { 16 | 17 | @Override 18 | public void invoke(XPocketProcess process) throws Throwable { 19 | History history = getReader().getHistory(); 20 | final ListIterator iterator = history.iterator(); 21 | while (iterator.hasNext()) { 22 | process.output(iterator.next().toString()); 23 | } 24 | process.end(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/command/impl/JPSCommand.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.command.impl; 2 | 3 | import com.perfma.xlab.xpocket.command.AbstractSystemCommand; 4 | import com.perfma.xlab.xpocket.localjvm.JvmPid; 5 | import com.perfma.xlab.xpocket.spi.command.CommandInfo; 6 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 7 | import com.perfma.xlab.xpocket.utils.ProcessUtil; 8 | import com.sun.tools.attach.VirtualMachine; 9 | import com.sun.tools.attach.VirtualMachineDescriptor; 10 | 11 | import java.util.*; 12 | 13 | /** 14 | * @author xinxian 15 | * @create 2020-09-08 14:35 16 | **/ 17 | @CommandInfo(name = "jps", usage = "list available java process,under linux, you can use the \"ps\" command to list all processes", index = 8) 18 | public class JPSCommand extends AbstractSystemCommand { 19 | 20 | @Override 21 | public void invoke(XPocketProcess process) { 22 | List out = new LinkedList(); 23 | for (JvmPid jvmPid : getLocalProcessList()) { 24 | if(!jvmPid.getPid().equals(ProcessUtil.getCurrentPid())){ 25 | out.add("@|yellow " + jvmPid.getPid() + "|@ @|white " + jvmPid.getCommand() + " |@"); 26 | } 27 | } 28 | for (String s : out) { 29 | process.output(s); 30 | } 31 | 32 | process.end(); 33 | } 34 | 35 | 36 | public Collection getLocalProcessList() { 37 | List localVms = VirtualMachine.list(); 38 | Set out = new HashSet<>(); 39 | for (VirtualMachineDescriptor vmd : localVms) { 40 | out.add(new JvmPid(vmd.id(), vmd.displayName())); 41 | } 42 | return out; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/command/impl/KillCommand.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.command.impl; 2 | 3 | import com.perfma.xlab.xpocket.command.AbstractSystemCommand; 4 | import com.perfma.xlab.xpocket.spi.command.CommandInfo; 5 | import com.perfma.xlab.xpocket.spi.command.XPocketProcessTemplate; 6 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 7 | import com.perfma.xlab.xpocket.utils.TerminalUtil; 8 | import java.io.IOException; 9 | 10 | /** 11 | * @author: TuGai 12 | * 13 | */ 14 | @CommandInfo(name = "kill", usage = "kill target java processor", index = 99) 15 | public class KillCommand extends AbstractSystemCommand { 16 | 17 | private static String[] killCmds =new String[0]; 18 | 19 | static { 20 | if(TerminalUtil.OS_NAME.toLowerCase().contains("win")) { 21 | killCmds = new String[]{"taskkill", "/F", "/PID",null}; 22 | } else { 23 | killCmds = new String[]{"kill", "-9", null}; 24 | } 25 | } 26 | 27 | @Override 28 | public void invoke(XPocketProcess process) { 29 | XPocketProcessTemplate.execute(process, 30 | (String cmd, String[] args) 31 | -> { 32 | String[] cmds = new String[killCmds.length]; 33 | System.arraycopy(killCmds, 0, cmds, 0, cmds.length); 34 | cmds[cmds.length - 1] = args[0]; 35 | ProcessBuilder builder = new ProcessBuilder(cmds).inheritIO(); 36 | Process p = builder.start(); 37 | p.waitFor(); 38 | return String.format("Process: %s killed!",args[0]); 39 | }); 40 | } 41 | 42 | public static void main(String[] args) throws InterruptedException, IOException { 43 | ProcessBuilder builder = new ProcessBuilder(new String[]{"taskkill", "/F", "/PID","3272"}).inheritIO(); 44 | Process p = builder.start(); 45 | p.waitFor(); 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/command/impl/QuitCommand.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.command.impl; 2 | 3 | import com.perfma.xlab.xpocket.command.AbstractSystemCommand; 4 | import com.perfma.xlab.xpocket.console.EndOfInputException; 5 | import com.perfma.xlab.xpocket.spi.command.CommandInfo; 6 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 7 | 8 | /** 9 | * @author xinxian 10 | * @create 2020-09-09 14:46 11 | **/ 12 | @CommandInfo(name = "quit", usage = "quit XPocket", index = 51) 13 | public class QuitCommand extends AbstractSystemCommand { 14 | @Override 15 | public void invoke(XPocketProcess process) { 16 | throw new EndOfInputException(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/command/impl/SessionCommand.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.command.impl; 2 | 3 | import com.perfma.xlab.xpocket.command.AbstractSystemCommand; 4 | import com.perfma.xlab.xpocket.framework.spi.impl.XPocketStatusContext; 5 | import com.perfma.xlab.xpocket.spi.command.CommandInfo; 6 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 7 | import com.perfma.xlab.xpocket.utils.TerminalUtil; 8 | 9 | /** 10 | * @author xinxian 11 | * @create 2020-10-21 17:56 12 | **/ 13 | @CommandInfo(name = "session", usage = "Show XPocket Status Context", index = 12) 14 | public class SessionCommand extends AbstractSystemCommand { 15 | 16 | @Override 17 | public void invoke(XPocketProcess process) { 18 | final XPocketStatusContext instance = XPocketStatusContext.instance; 19 | final int pid = instance.pid(); 20 | if (pid >= 0) { 21 | process.output("--------------------------" + TerminalUtil.lineSeparator); 22 | process.output("Has been attached : true" + TerminalUtil.lineSeparator); 23 | process.output("Pid : " + pid + TerminalUtil.lineSeparator); 24 | process.output("--------------------------" + TerminalUtil.lineSeparator); 25 | } 26 | process.end(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/command/impl/TrimCommand.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.command.impl; 2 | 3 | import com.perfma.xlab.xpocket.command.AbstractSystemCommand; 4 | import com.perfma.xlab.xpocket.spi.command.CommandInfo; 5 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 6 | 7 | /** 8 | * @author xinxian 9 | * @create 2020-11-04 17:48 10 | **/ 11 | @CommandInfo(name = "trim", usage = "removed any leading and trailing whitespace", index = 11) 12 | public class TrimCommand extends AbstractSystemCommand { 13 | 14 | @Override 15 | public void invoke(XPocketProcess process) throws Throwable { 16 | if (process.input() != null) { 17 | process.output(process.input().trim()); 18 | } else { 19 | final String[] args = process.getArgs(); 20 | if (args != null && args.length > 0) { 21 | StringBuilder sb = new StringBuilder(); 22 | for (int i = 0; i < args.length; i++) { 23 | sb.append(args[i]); 24 | } 25 | process.output(sb.toString().trim()); 26 | } 27 | } 28 | process.end(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/command/impl/VersionCommand.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.command.impl; 2 | 3 | import com.perfma.xlab.xpocket.command.AbstractSystemCommand; 4 | import com.perfma.xlab.xpocket.spi.command.CommandInfo; 5 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 6 | import com.perfma.xlab.xpocket.utils.XPocketConstants; 7 | 8 | /** 9 | * @author xinxian 10 | * @create 2020-12-09 16:01 11 | **/ 12 | @CommandInfo(name = "version", usage = "XPocket version info", index = 15) 13 | public class VersionCommand extends AbstractSystemCommand { 14 | 15 | @Override 16 | public void invoke(XPocketProcess process) throws Throwable { 17 | process.output("@|green Initiator : PerfMa |@"); 18 | process.output("@|green version : " + XPocketConstants.VERSION + " |@"); 19 | process.output("@|green github : " + XPocketConstants.GITHUB + " |@"); 20 | process.end(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/completer/GroupStringCompleter.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.completer; 2 | 3 | import java.util.Collection; 4 | import org.jline.reader.Candidate; 5 | import org.jline.reader.impl.completer.StringsCompleter; 6 | import org.jline.utils.AttributedString; 7 | 8 | /** 9 | * 10 | * @author gongyu 11 | */ 12 | public class GroupStringCompleter extends StringsCompleter { 13 | 14 | public GroupStringCompleter(Iterable strings,String groupName) { 15 | assert strings != null; 16 | for (String string : strings) { 17 | candidates.add(new Candidate(AttributedString.stripAnsi(string), string, groupName, null, null, null, true)); 18 | } 19 | } 20 | 21 | public GroupStringCompleter(Collection candidates) { 22 | super(candidates); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/console/EndOfInputException.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.console; 2 | 3 | public class EndOfInputException extends RuntimeException { 4 | 5 | private static final long serialVersionUID = 3663807951045296792L; 6 | } 7 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/context/AbstractExecuteContext.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.context; 2 | 3 | import com.perfma.xlab.xpocket.spi.context.ExecuteContext; 4 | 5 | /** 6 | * @author: ZQF 7 | * @date: 2021-04-16 8 | * @description: desc 9 | */ 10 | public abstract class AbstractExecuteContext implements ExecuteContext { 11 | public abstract void nextExecuteContext(); 12 | 13 | public abstract String get(int row, int column); 14 | 15 | public abstract void replaceZero(String value); 16 | } 17 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/context/DefaultExecuteContext.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.context; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * @author: ZQF 8 | * @date: 2021-04-16 9 | * @description: desc 10 | */ 11 | public class DefaultExecuteContext extends AbstractExecuteContext { 12 | 13 | private static final String PLACEHOLDER = "#Placeholder"; 14 | 15 | private final List> internalVarList = new ArrayList<>(); 16 | 17 | private List currentVar; 18 | 19 | DefaultExecuteContext(){ 20 | nextExecuteContext(); 21 | } 22 | 23 | @Override 24 | public void addInternalVar(String var) { 25 | assert currentVar != null; 26 | this.currentVar.add(var); 27 | } 28 | 29 | @Override 30 | public void nextExecuteContext() { 31 | this.currentVar = new ArrayList<>(); 32 | currentVar.add(PLACEHOLDER); 33 | internalVarList.add(currentVar); 34 | } 35 | 36 | @Override 37 | public String get(int row, int column) { 38 | if(row <= 0 || column < 0){ 39 | return null; 40 | } 41 | if(row == internalVarList.size()-1){ 42 | return null; 43 | } 44 | if(row < internalVarList.size() && internalVarList.get(row) != null 45 | && column < internalVarList.get(row).size()){ 46 | return internalVarList.get(row).get(column); 47 | } 48 | return null; 49 | } 50 | 51 | @Override 52 | public void replaceZero(String value) { 53 | int second = 2; 54 | if(internalVarList.size() == second){ 55 | return ; 56 | } 57 | this.internalVarList.get(internalVarList.size()-second).set(0, value); 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "DefaultExecuteContext{" + 63 | "internalVarList=" + internalVarList + 64 | ", currentVar=" + currentVar + 65 | '}'; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/context/ExecuteContextWrapper.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.context; 2 | 3 | 4 | /** 5 | * @author: ZQF 6 | * @date: 2021-04-16 7 | * @description: desc 8 | */ 9 | public class ExecuteContextWrapper { 10 | 11 | private AbstractExecuteContext executeContext; 12 | 13 | public ExecuteContextWrapper(){ 14 | this.executeContext = new DefaultExecuteContext(); 15 | } 16 | 17 | public void nextExecuteContext(){ 18 | this.executeContext.nextExecuteContext(); 19 | } 20 | 21 | public String get(int row, int column){ 22 | return this.executeContext.get(row, column); 23 | } 24 | 25 | public void addInternalVar(String var){ 26 | this.executeContext.addInternalVar(var); 27 | } 28 | 29 | public void replaceZero(String var){ 30 | this.executeContext.replaceZero(var); 31 | } 32 | 33 | public AbstractExecuteContext getExecuteContext() { 34 | return executeContext; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "ExecuteContextWrapper{" + 40 | "executeContext=" + executeContext + 41 | '}'; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/framework/spi/execution/pipeline/DefaultNode.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.framework.spi.execution.pipeline; 2 | 3 | import com.perfma.xlab.xpocket.plugin.execution.Node; 4 | import com.perfma.xlab.xpocket.spi.context.PluginBaseInfo; 5 | 6 | /** 7 | * @author gongyu 8 | */ 9 | public class DefaultNode implements Node { 10 | 11 | private final PluginBaseInfo context; 12 | private final String cmd; 13 | private final String[] args; 14 | 15 | public DefaultNode(PluginBaseInfo context, String cmd, String[] args) { 16 | this.context = context; 17 | 18 | String flag = context.getNamespace() + "."; 19 | int position = cmd.indexOf(flag); 20 | if (position >= 0) { 21 | this.cmd = cmd.substring(position + flag.length(), cmd.length()); 22 | } else { 23 | this.cmd = cmd; 24 | } 25 | this.args = args; 26 | } 27 | 28 | @Override 29 | public PluginBaseInfo getPluginContext() { 30 | return context; 31 | } 32 | 33 | @Override 34 | public String getCmd() { 35 | return cmd; 36 | } 37 | 38 | @Override 39 | public String[] getArgs() { 40 | return args; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/framework/spi/execution/pipeline/DefaultProcessInfo.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.framework.spi.execution.pipeline; 2 | 3 | import com.perfma.xlab.xpocket.plugin.execution.Node; 4 | import com.perfma.xlab.xpocket.plugin.execution.XpocketProcessInfo; 5 | import java.io.OutputStream; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * 11 | * @author gongyu 12 | */ 13 | public class DefaultProcessInfo implements XpocketProcessInfo { 14 | 15 | private final List nodes = new ArrayList<>(); 16 | 17 | private OutputStream output; 18 | 19 | @Override 20 | public List nodes() { 21 | return nodes; 22 | } 23 | 24 | @Override 25 | public OutputStream finalOutput() { 26 | return output; 27 | } 28 | 29 | public void setOutput(OutputStream output) { 30 | this.output = output; 31 | } 32 | 33 | public void addNode(Node node) { 34 | this.nodes.add(node); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/framework/spi/execution/pipeline/XPocketProcessOutputStream.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.framework.spi.execution.pipeline; 2 | 3 | import com.perfma.xlab.xpocket.context.ExecuteContextWrapper; 4 | 5 | import java.io.IOException; 6 | import java.io.OutputStream; 7 | 8 | /** 9 | * 10 | * @author gongyu 11 | */ 12 | public class XPocketProcessOutputStream extends OutputStream { 13 | 14 | private final DefaultProcessDefinition def; 15 | private final ExecuteContextWrapper executeContextWrapper; 16 | 17 | public XPocketProcessOutputStream(DefaultProcessDefinition def) { 18 | this(def,null); 19 | } 20 | 21 | public XPocketProcessOutputStream(DefaultProcessDefinition def, ExecuteContextWrapper executeContextWrapper) { 22 | this.def = def; 23 | this.executeContextWrapper = executeContextWrapper; 24 | } 25 | 26 | @Override 27 | public void write(int b) throws IOException { 28 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 29 | } 30 | 31 | @Override 32 | public void write(byte[] b, int off, int len) throws IOException { 33 | byte[] readyToWrite = new byte[len]; 34 | System.arraycopy(b, off, readyToWrite, 0, len); 35 | try { 36 | def.execute(new String(readyToWrite), executeContextWrapper); 37 | } catch (Throwable ex) { 38 | def.end(); 39 | throw new IOException(ex); 40 | } 41 | } 42 | 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/framework/spi/impl/DefaultNamedObject.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.framework.spi.impl; 2 | 3 | import com.perfma.xlab.xpocket.plugin.base.NamedObject; 4 | 5 | /** 6 | * 7 | * @author gongyu 8 | */ 9 | public class DefaultNamedObject implements NamedObject { 10 | 11 | private static final String NAME = "DEFAULT"; 12 | 13 | @Override 14 | public String name() { 15 | return NAME; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/framework/spi/impl/agent/AgentNamedObject.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.framework.spi.impl.agent; 2 | 3 | import com.perfma.xlab.xpocket.plugin.base.NamedObject; 4 | 5 | /** 6 | * 7 | * @author gongyu 8 | */ 9 | public class AgentNamedObject implements NamedObject { 10 | 11 | public static final String NAME = "AGENT"; 12 | 13 | @Override 14 | public String name() { 15 | return NAME; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/framework/spi/impl/agent/AgentUIEngineImpl.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.framework.spi.impl.agent; 2 | 3 | import com.perfma.xlab.xpocket.plugin.ui.UIEngine; 4 | import java.lang.instrument.Instrumentation; 5 | import org.jline.builtins.telnet.Telnet; 6 | import org.jline.terminal.Terminal; 7 | import org.jline.terminal.TerminalBuilder; 8 | 9 | /** 10 | * 11 | * @author gongyu 12 | */ 13 | public class AgentUIEngineImpl extends AgentNamedObject implements UIEngine { 14 | 15 | private static final String DEFAULT_TELNET_PORT = "9527"; 16 | 17 | @Override 18 | public void start(String[] def, String[] args, Instrumentation inst) { 19 | 20 | Telnet telnet; 21 | try { 22 | String port = DEFAULT_TELNET_PORT; 23 | boolean isOnLoad = false; 24 | for(int i=0;i 8 | */ 9 | public class AgentLauncherNamedObject implements NamedObject { 10 | 11 | private static final String NAME = "AGENT-LAUNCHER"; 12 | 13 | @Override 14 | public String name() { 15 | return NAME; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/framework/spi/impl/mxbean/MXBeanNamedObject.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.framework.spi.impl.mxbean; 2 | 3 | import com.perfma.xlab.xpocket.framework.spi.impl.telnet.*; 4 | import com.perfma.xlab.xpocket.plugin.base.NamedObject; 5 | 6 | /** 7 | * 8 | * @author gongyu 9 | */ 10 | public class MXBeanNamedObject implements NamedObject { 11 | 12 | private static final String NAME = "MXBEAN"; 13 | 14 | @Override 15 | public String name() { 16 | return NAME; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/framework/spi/impl/once/OnceExecutionExecutionEngineImpl.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.framework.spi.impl.once; 2 | 3 | import com.perfma.xlab.xpocket.console.EndOfInputException; 4 | import com.perfma.xlab.xpocket.framework.spi.execution.pipeline.ExecutionPipeLine; 5 | import com.perfma.xlab.xpocket.plugin.execution.ExecutionEngine; 6 | import com.perfma.xlab.xpocket.plugin.execution.Node; 7 | import com.perfma.xlab.xpocket.plugin.execution.XpocketProcessInfo; 8 | import org.jline.reader.LineReader; 9 | 10 | 11 | /** 12 | * @author gongyu 13 | */ 14 | public class OnceExecutionExecutionEngineImpl extends OnceNamedObject implements ExecutionEngine { 15 | 16 | @Override 17 | public void invoke(XpocketProcessInfo info, LineReader reader) throws Throwable { 18 | 19 | ExecutionPipeLine pipeline = new ExecutionPipeLine(info.finalOutput()); 20 | 21 | for (Node node : info.nodes()) { 22 | pipeline.appendProcess(node); 23 | } 24 | 25 | Thread mainThread = Thread.currentThread(); 26 | Throwable[] exs = new Throwable[1]; 27 | 28 | Thread executeThread = new Thread(() -> { 29 | try { 30 | pipeline.start(); 31 | } catch (InterruptedException | EndOfInputException ie) { 32 | return; 33 | } catch (Throwable ex) { 34 | exs[0] = ex; 35 | } 36 | }); 37 | executeThread.start(); 38 | 39 | executeThread.join(); 40 | 41 | if (exs[0] != null) { 42 | throw exs[0]; 43 | } 44 | } 45 | 46 | @Override 47 | public void invoke(XpocketProcessInfo info) throws Throwable { 48 | 49 | ExecutionPipeLine pipeline = new ExecutionPipeLine(info.finalOutput()); 50 | 51 | for (Node node : info.nodes()) { 52 | pipeline.appendProcess(node); 53 | } 54 | 55 | pipeline.start(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/framework/spi/impl/once/OnceNamedObject.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.framework.spi.impl.once; 2 | 3 | import com.perfma.xlab.xpocket.plugin.base.NamedObject; 4 | 5 | /** 6 | * 7 | * @author gongyu 8 | */ 9 | public class OnceNamedObject implements NamedObject { 10 | 11 | private static final String NAME = "ONCE"; 12 | 13 | @Override 14 | public String name() { 15 | return NAME; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/framework/spi/impl/telnet/TelnetNamedObject.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.framework.spi.impl.telnet; 2 | 3 | import com.perfma.xlab.xpocket.plugin.base.NamedObject; 4 | 5 | /** 6 | * 7 | * @author gongyu 8 | */ 9 | public class TelnetNamedObject implements NamedObject { 10 | 11 | private static final String NAME = "TELNET"; 12 | 13 | @Override 14 | public String name() { 15 | return NAME; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/framework/spi/impl/telnet/TelnetUIEngineImpl.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.framework.spi.impl.telnet; 2 | 3 | import com.perfma.xlab.xpocket.framework.spi.impl.agent.XPocketAgentShellProvider; 4 | import com.perfma.xlab.xpocket.plugin.ui.UIEngine; 5 | import java.lang.instrument.Instrumentation; 6 | import org.jline.builtins.telnet.Telnet; 7 | import org.jline.terminal.Terminal; 8 | import org.jline.terminal.TerminalBuilder; 9 | 10 | /** 11 | * 12 | * @author gongyu 13 | */ 14 | public class TelnetUIEngineImpl extends TelnetNamedObject implements UIEngine { 15 | 16 | private static final String DEFAULT_TELNET_PORT = "9528"; 17 | 18 | @Override 19 | public void start(String[] def, String[] args, Instrumentation inst) { 20 | 21 | Telnet telnet; 22 | try { 23 | String port = DEFAULT_TELNET_PORT; 24 | for(int i=0;i 10 | */ 11 | public class XPocketLauncher { 12 | 13 | public static void main(String[] args) { 14 | Constants.initSystemProperties(); 15 | 16 | List argsForCore = new ArrayList<>(); 17 | 18 | if(System.getProperty(Constants.RUN_MODE_KEY) == null) { 19 | System.setProperty(Constants.RUN_MODE_KEY, 20 | Constants.DEFAULT_RUN_MODE); 21 | } 22 | 23 | if(args != null && args.length >= 2) { 24 | for(int i=0;i 0) { 34 | shortCommand = command.substring(0, i); 35 | } else { 36 | shortCommand = command; 37 | } 38 | return pid + ":" + shortCommand; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "jvm(" + pid + ":" + command + ")"; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object o) { 48 | if (this == o) { 49 | return true; 50 | } 51 | if (o == null || getClass() != o.getClass()) { 52 | return false; 53 | } 54 | JvmPid jvmPid = (JvmPid) o; 55 | return Objects.equals(pid, jvmPid.pid) && 56 | Objects.equals(command, jvmPid.command); 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | return Objects.hash(pid, command); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/structure/Pair.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.structure; 2 | 3 | /** 4 | * @author: ZQF 5 | * @date: 2021-04-16 6 | * @description: desc 7 | */ 8 | public class Pair { 9 | private F first; 10 | 11 | private S second; 12 | 13 | public Pair(F first, S second){ 14 | this.first = first; 15 | this.second = second; 16 | } 17 | 18 | public F getFirst() { 19 | return first; 20 | } 21 | 22 | public S getSecond() { 23 | return second; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return "Pair{" + 29 | "first=" + first + 30 | ", second=" + second + 31 | '}'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/utils/JarUtils.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.utils; 2 | 3 | import java.io.IOException; 4 | import java.net.JarURLConnection; 5 | import java.net.URL; 6 | import java.util.ArrayList; 7 | import java.util.Enumeration; 8 | import java.util.List; 9 | import java.util.jar.JarEntry; 10 | import java.util.jar.JarFile; 11 | 12 | /** 13 | * 14 | * @author gongyu 15 | */ 16 | public class JarUtils { 17 | 18 | 19 | public static List findClassesInJarPackage(String packageName) 20 | throws IOException { 21 | 22 | packageName = packageName.replace(".", "/"); 23 | packageName = packageName.endsWith("/") ? packageName : packageName + "/"; 24 | 25 | ClassLoader loader = JarUtils.class.getClassLoader(); 26 | 27 | URL url = loader.getResource(packageName); 28 | 29 | JarURLConnection conn = (JarURLConnection)url.openConnection(); 30 | JarFile jarFile = conn.getJarFile(); 31 | Enumeration entries = jarFile.entries(); 32 | List classes = new ArrayList<>(); 33 | while(entries.hasMoreElements()) { 34 | JarEntry entry = entries.nextElement(); 35 | String name = entry.getName(); 36 | if(!entry.isDirectory() && !name.contains("$") ) { 37 | if(name.substring(0, name.lastIndexOf('/') + 1).equals(packageName)) { 38 | classes.add(name.replace(".class", "").replace("/", ".")); 39 | } 40 | } 41 | } 42 | 43 | return classes; 44 | } 45 | 46 | public static void main(String[] args) throws IOException { 47 | 48 | List classes = JarUtils.findClassesInJarPackage("org.apache.commons.io"); 49 | for(String clazz : classes) { 50 | System.out.println(clazz); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/utils/LogoPrinter.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.utils; 2 | 3 | import com.perfma.xlab.xpocket.spi.process.XPocketProcess; 4 | 5 | 6 | /** 7 | * @author xinxian 8 | * @create 2020-09-25 14:21 9 | **/ 10 | public class LogoPrinter { 11 | public static void print(XPocketProcess process) { 12 | process.output(XPocketBanner.welcome()); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/utils/ProcessUtil.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.utils; 2 | 3 | import java.lang.management.ManagementFactory; 4 | 5 | /** 6 | * 7 | * @author gongyu 8 | */ 9 | public class ProcessUtil { 10 | 11 | private static final String CURRENT_PID; 12 | 13 | static { 14 | String name = ManagementFactory.getRuntimeMXBean().getName(); 15 | CURRENT_PID = name.split("@")[0].trim(); 16 | } 17 | 18 | public static String getCurrentPid() { 19 | return CURRENT_PID; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/utils/RegexUtil.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.utils; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | /** 7 | * @author: ZQF 8 | * @date: 2021-04-16 9 | * @description: desc 10 | */ 11 | public class RegexUtil { 12 | private static final Pattern PRIMARY_KEY_PATTERN = Pattern.compile("^\\d+$"); 13 | 14 | public static boolean isPrimaryKey(String value){ 15 | if(value == null){ 16 | return false; 17 | } 18 | Matcher matcher = PRIMARY_KEY_PATTERN.matcher(value); 19 | return matcher.find(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/utils/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.utils; 2 | 3 | /** 4 | * 5 | * @author gongyu 6 | */ 7 | public class StringUtils { 8 | 9 | public static boolean isblank(String src) { 10 | return src == null || src.isEmpty(); 11 | } 12 | 13 | public static String fillWithSpace(String src,int length) { 14 | if(src.length() >= length) { 15 | return src; 16 | } 17 | 18 | char[] result = new char[length]; 19 | char[] srcArray = src.toCharArray(); 20 | 21 | System.arraycopy(srcArray, 0, result, 0, srcArray.length); 22 | 23 | int pos = src.length(); 24 | while(pos < length) { 25 | result[pos++] = ' '; 26 | } 27 | 28 | return new String(result); 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/utils/XPocketBanner.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.utils; 2 | 3 | import java.io.FileInputStream; 4 | import java.nio.charset.Charset; 5 | import java.util.Collections; 6 | import java.util.Map; 7 | import org.apache.commons.io.IOUtils; 8 | 9 | 10 | 11 | public class XPocketBanner { 12 | 13 | private static String LOGO_LOCATION = System.getProperty("XPOCKET_CONFIG_PATH") + "logo.txt"; 14 | 15 | private static String LOGO = ""; 16 | 17 | /* XPocket logo 颜色顺序 */ 18 | private static final String[] COLORS = {"red","magenta","yellow","green","magenta","yellow","cyan"}; 19 | 20 | static { 21 | try { 22 | String logoText = IOUtils.toString(new FileInputStream(LOGO_LOCATION),Charset.defaultCharset()); 23 | logoText = logoText.replaceAll("\r\n", "\n"); 24 | String[] elements = logoText.split("\n"); 25 | int /*高度*/h = 5,/*字符数*/c = 7,/*宽度*/w = 8; 26 | StringBuilder logoBuilder = new StringBuilder(logoText.length()); 27 | 28 | for(int i=0;iemptyMap()); 53 | } 54 | 55 | public static String welcome(Map infos) { 56 | return logo(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/com/perfma/xlab/xpocket/utils/XPocketConstants.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.utils; 2 | 3 | import com.perfma.xlab.xpocket.plugin.adaptor.JavaAgentCommandAdaptor; 4 | import java.io.File; 5 | 6 | /** 7 | * @author gongyu 8 | */ 9 | public class XPocketConstants { 10 | 11 | public static final JavaAgentCommandAdaptor DEFAULT_ADAPTOR = new JavaAgentCommandAdaptor(); 12 | 13 | public static final String JAVA_HOME = System.getProperty("java.home"); 14 | 15 | public static final String XPOCKET_HOME = System.getProperty("XPOCKET_HOME"); 16 | 17 | public static final String XPOCKET_PLUGIN_PATH = System.getProperty("XPOCKET_PLUGIN_PATH",XPOCKET_HOME+ "/plugins/"); 18 | 19 | public static final String XPOCKET_CONFIG_PATH = System.getProperty("XPOCKET_CONFIG_PATH",XPOCKET_HOME+ "/config/"); 20 | 21 | public static final String XPOCKET_SCROLL_PATH = System.getProperty("XPOCKET_SCROLL_PATH",XPOCKET_HOME+ "/scrolls/"); 22 | 23 | public static final String SYSTEM_PLUGIN_NAME = "system"; 24 | 25 | public static final String SYSTEM_PLUGIN_NS = "XPOCKET"; 26 | 27 | public static final String USER_HOME = System.getProperty("user.home"); 28 | 29 | public static final String PATH = USER_HOME + File.separator + ".xpocket" + File.separator + ".history" + File.separator; 30 | 31 | public static final String[] XPOCKET_COMMANDS = {"Echo","Attach","Detach","History", "Cd", "Help", "ListPlugins", "JPS", "Quit", "Session", "Sys", "Top", "Use", "Split", 32 | "Trim", "Grep", "Version", "Clear","Kill"}; 33 | 34 | public static final String XPOCKET_COMMAND_PACKAGE = "com.perfma.xlab.xpocket.command.impl"; 35 | 36 | public static final String VERSION = "2.1.2-alpha"; 37 | 38 | public static final String GITHUB = "https://github.com/PerfMa/xpocket"; 39 | 40 | public static final String CLUB = "https://xpocket.perfma.com/"; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/org/apache/commons/net/telnet/InvalidTelnetOptionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.telnet; 19 | 20 | /** 21 | * The InvalidTelnetOptionException is the exception that is 22 | * thrown whenever a TelnetOptionHandler with an invlaid 23 | * option code is registered in TelnetClient with addOptionHandler. 24 | */ 25 | public class InvalidTelnetOptionException extends Exception 26 | { 27 | 28 | private static final long serialVersionUID = -2516777155928793597L; 29 | 30 | /** 31 | * Option code 32 | */ 33 | private final int optionCode; 34 | 35 | /** 36 | * Error message 37 | */ 38 | private final String msg; 39 | 40 | /** 41 | * Constructor for the exception. 42 | *

43 | * @param message - Error message. 44 | * @param optcode - Option code. 45 | */ 46 | public InvalidTelnetOptionException(final String message, final int optcode) 47 | { 48 | optionCode = optcode; 49 | msg = message; 50 | } 51 | 52 | /** 53 | * Gets the error message of ths exception. 54 | *

55 | * @return the error message. 56 | */ 57 | @Override 58 | public String getMessage() 59 | { 60 | return msg + ": " + optionCode; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/java/org/apache/commons/net/telnet/TelnetInputListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.telnet; 19 | 20 | /** 21 | * Listener interface used for notification that incoming data is 22 | * available to be read. 23 | * 24 | * @see TelnetClient 25 | * @since 3.0 26 | */ 27 | public interface TelnetInputListener 28 | { 29 | 30 | /** 31 | * Callback method invoked when new incoming data is available on a 32 | * {@link TelnetClient}'s {@link TelnetClient#getInputStream input stream}. 33 | * 34 | * @see TelnetClient#registerInputListener 35 | */ 36 | void telnetInputAvailable(); 37 | } 38 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/resources/META-INF/services/com.perfma.xlab.xpocket.plugin.command.CommandLoader: -------------------------------------------------------------------------------- 1 | com.perfma.xlab.xpocket.framework.spi.impl.DefaultCommandLoader -------------------------------------------------------------------------------- /xpocket-runtime/src/main/resources/META-INF/services/com.perfma.xlab.xpocket.plugin.execution.ExecutionEngine: -------------------------------------------------------------------------------- 1 | com.perfma.xlab.xpocket.framework.spi.impl.DefaultExecutionEngine 2 | com.perfma.xlab.xpocket.framework.spi.impl.once.OnceExecutionExecutionEngineImpl 3 | -------------------------------------------------------------------------------- /xpocket-runtime/src/main/resources/META-INF/services/com.perfma.xlab.xpocket.plugin.loader.PluginLoader: -------------------------------------------------------------------------------- 1 | com.perfma.xlab.xpocket.framework.spi.impl.DefaultPluginLoader 2 | com.perfma.xlab.xpocket.framework.spi.impl.agent.AgentPluginLoaderImpl -------------------------------------------------------------------------------- /xpocket-runtime/src/main/resources/META-INF/services/com.perfma.xlab.xpocket.plugin.ui.UIEngine: -------------------------------------------------------------------------------- 1 | com.perfma.xlab.xpocket.framework.spi.impl.DefaultUIEngine 2 | com.perfma.xlab.xpocket.framework.spi.impl.once.OnceExecutionUIEngineImpl 3 | com.perfma.xlab.xpocket.framework.spi.impl.agentlauncher.AgentLauncherUIEngineImpl 4 | com.perfma.xlab.xpocket.framework.spi.impl.agent.AgentUIEngineImpl 5 | com.perfma.xlab.xpocket.framework.spi.impl.telnet.TelnetUIEngineImpl 6 | com.perfma.xlab.xpocket.framework.spi.impl.mxbean.MXBeanUIEngineImpl 7 | -------------------------------------------------------------------------------- /xpocket-scroll/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.perfma.xlab 7 | xpocket-parent 8 | 2.1.2-alpha 9 | ../pom.xml 10 | 11 | 4.0.0 12 | 13 | xpocket-scroll 14 | jar 15 | 16 | 17 | org.codehaus.groovy 18 | groovy 19 | 20 | 21 | 22 | true 23 | 24 | 25 | -------------------------------------------------------------------------------- /xpocket-scroll/src/main/java/com/perfma/xlab/xpocket/scroll/ScriptName.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.scroll; 2 | 3 | /** 4 | * 5 | * @author gongyu 6 | */ 7 | public interface ScriptName { 8 | 9 | /** 10 | * get script compiler name 11 | * @return 12 | */ 13 | String name(); 14 | } 15 | -------------------------------------------------------------------------------- /xpocket-scroll/src/main/java/com/perfma/xlab/xpocket/scroll/Scroll.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.scroll; 2 | 3 | import java.util.List; 4 | import java.util.Properties; 5 | 6 | /** 7 | * 8 | * @author gongyu 9 | */ 10 | public class Scroll { 11 | 12 | private long version; 13 | private String name; 14 | private String namespace; 15 | private Properties info = new Properties(); 16 | 17 | private String scriptName; 18 | private Properties scriptHeader = new Properties(); 19 | private List scripts; 20 | 21 | public long getVersion() { 22 | return version; 23 | } 24 | 25 | public void setVersion(long version) { 26 | this.version = version; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | public String getNamespace() { 38 | return namespace; 39 | } 40 | 41 | public void setNamespace(String namespace) { 42 | this.namespace = namespace; 43 | } 44 | 45 | public Properties getInfo() { 46 | return info; 47 | } 48 | 49 | public void setInfo(Properties info) { 50 | this.info = info; 51 | } 52 | 53 | public String getScriptName() { 54 | return scriptName; 55 | } 56 | 57 | public void setScriptName(String scriptName) { 58 | this.scriptName = scriptName; 59 | } 60 | 61 | public Properties getScriptHeader() { 62 | return scriptHeader; 63 | } 64 | 65 | public void setScriptHeader(Properties scriptHeader) { 66 | this.scriptHeader = scriptHeader; 67 | } 68 | 69 | public List getScripts() { 70 | return scripts; 71 | } 72 | 73 | public void setScripts(List scripts) { 74 | this.scripts = scripts; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /xpocket-scroll/src/main/java/com/perfma/xlab/xpocket/scroll/ScrollConstants.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.scroll; 2 | 3 | /** 4 | * 5 | * @author gongyu 6 | */ 7 | public class ScrollConstants { 8 | 9 | //ARCANE 10 | public static final byte[] MAGIC_CODE = new byte[]{'A','R','C','A','N','E'}; 11 | 12 | public static final long VERSION = 1L; 13 | 14 | public static final byte[] GAP_BYTES = new byte[8]; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /xpocket-scroll/src/main/java/com/perfma/xlab/xpocket/scroll/compile/ScrollScriptCompiler.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.scroll.compile; 2 | 3 | import com.perfma.xlab.xpocket.scroll.ScriptName; 4 | import java.util.List; 5 | 6 | /** 7 | * 8 | * @author gongyu 9 | */ 10 | public interface ScrollScriptCompiler extends ScriptName { 11 | 12 | /** 13 | * compile input script to byte array 14 | * @param name 15 | * @param script script content 16 | * @return byte array of compiled script. 17 | */ 18 | List compile(String name,String script); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /xpocket-scroll/src/main/java/com/perfma/xlab/xpocket/scroll/exception/ScrollParseException.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.scroll.exception; 2 | 3 | /** 4 | * 5 | * @author gongyu 6 | */ 7 | public class ScrollParseException extends Exception { 8 | 9 | public ScrollParseException(String string) { 10 | super(string); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /xpocket-scroll/src/main/java/com/perfma/xlab/xpocket/scroll/groovy/BytesOutputCompilationUnit.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.scroll.groovy; 2 | 3 | import groovy.lang.GroovyClassLoader; 4 | import java.lang.reflect.Field; 5 | import java.util.Deque; 6 | import org.codehaus.groovy.control.CompilationUnit; 7 | import org.codehaus.groovy.control.CompilerConfiguration; 8 | import org.codehaus.groovy.control.Phases; 9 | import sun.misc.Unsafe; 10 | 11 | 12 | 13 | public class BytesOutputCompilationUnit extends CompilationUnit { 14 | 15 | private static Unsafe theUnsafe; 16 | private static long PHASE_OPERATIONS_ADDRESS; 17 | 18 | static { 19 | try { 20 | Field f = Unsafe.class.getDeclaredField("theUnsafe"); 21 | f.setAccessible(true); 22 | theUnsafe = (Unsafe)f.get(null); 23 | f.setAccessible(false); 24 | PHASE_OPERATIONS_ADDRESS = theUnsafe.objectFieldOffset( 25 | CompilationUnit.class.getDeclaredField("phaseOperations")); 26 | } catch (Throwable ex) { 27 | ex.printStackTrace(); 28 | } 29 | } 30 | 31 | public BytesOutputCompilationUnit(CompilerConfiguration configuration, GroovyClassLoader loader) { 32 | super(configuration, null, loader, null); 33 | Deque[] OPS = (Deque[])theUnsafe.getObject(this, PHASE_OPERATIONS_ADDRESS); 34 | OPS[Phases.OUTPUT].clear(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /xpocket-scroll/src/main/java/com/perfma/xlab/xpocket/scroll/groovy/DynamicClassLoader.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.scroll.groovy; 2 | 3 | import java.net.URL; 4 | import java.net.URLClassLoader; 5 | 6 | /** 7 | * 8 | * @author gongyu 9 | */ 10 | public class DynamicClassLoader extends URLClassLoader { 11 | 12 | public DynamicClassLoader(URL[] urls) { 13 | super(urls); 14 | } 15 | 16 | public DynamicClassLoader(URL[] urls, ClassLoader cl) { 17 | super(urls, cl); 18 | } 19 | 20 | public Class loadClass(byte[] b, int off, int len) { 21 | return defineClass(null, b, off, len); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /xpocket-scroll/src/main/java/com/perfma/xlab/xpocket/scroll/groovy/GroovyName.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.scroll.groovy; 2 | 3 | import com.perfma.xlab.xpocket.scroll.ScriptName; 4 | 5 | /** 6 | * 7 | * @author gongyu 8 | */ 9 | public class GroovyName implements ScriptName { 10 | 11 | private static final String NAME = "GROOVY"; 12 | 13 | @Override 14 | public String name() { 15 | return NAME; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /xpocket-scroll/src/main/java/com/perfma/xlab/xpocket/scroll/groovy/GroovyScriptCompiler.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.scroll.groovy; 2 | 3 | import com.perfma.xlab.xpocket.scroll.compile.ScrollScriptCompiler; 4 | import java.util.List; 5 | import org.codehaus.groovy.control.CompilerConfiguration; 6 | 7 | /** 8 | * 9 | * @author gongyu 10 | */ 11 | public class GroovyScriptCompiler extends GroovyName implements ScrollScriptCompiler { 12 | 13 | public static final String SYS_FUNCS = "import com.perfma.xlab.xpocket.utils.XPocketCommandHelper;void exec(String cmd){XPocketCommandHelper.exec(cmd);};String execByResult(String cmd){return XPocketCommandHelper.execByResult(cmd);};void println(String content){XPocketCommandHelper.println(content);};"; 14 | 15 | private static final BytesOutputCompiler compiler; 16 | 17 | static { 18 | CompilerConfiguration config = new CompilerConfiguration(CompilerConfiguration.DEFAULT); 19 | config.getOptimizationOptions().put("asmResolving", Boolean.FALSE); 20 | config.getOptimizationOptions().put("classLoaderResolving", Boolean.TRUE); 21 | 22 | compiler = new BytesOutputCompiler(config, GroovyScriptCompiler.class.getClassLoader()); 23 | } 24 | 25 | 26 | @Override 27 | public List compile(String name,String script) { 28 | script = SYS_FUNCS + script; 29 | return compiler.compile(name, script); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /xpocket-scroll/src/main/java/com/perfma/xlab/xpocket/scroll/groovy/GroovyScriptRunner.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.scroll.groovy; 2 | 3 | import static com.perfma.xlab.xpocket.scroll.groovy.GroovyScriptCompiler.SYS_FUNCS; 4 | import com.perfma.xlab.xpocket.scroll.run.ScrollScriptRunner; 5 | import groovy.lang.GroovyShell; 6 | import java.lang.reflect.Method; 7 | import java.lang.reflect.Modifier; 8 | import java.net.URL; 9 | import java.util.List; 10 | import org.codehaus.groovy.control.CompilerConfiguration; 11 | 12 | /** 13 | * 14 | * @author gongyu 15 | */ 16 | public class GroovyScriptRunner extends GroovyName implements ScrollScriptRunner { 17 | 18 | private static final GroovyShell shell; 19 | 20 | private static final DynamicClassLoader loader = new DynamicClassLoader(new URL[0], GroovyScriptRunner.class.getClassLoader()); 21 | 22 | static { 23 | CompilerConfiguration config = new CompilerConfiguration(CompilerConfiguration.DEFAULT); 24 | config.getOptimizationOptions().put("asmResolving", Boolean.FALSE); 25 | config.getOptimizationOptions().put("classLoaderResolving", Boolean.TRUE); 26 | shell = new GroovyShell(GroovyScriptRunner.class.getClassLoader(), config); 27 | } 28 | 29 | @Override 30 | public void run(String script) { 31 | script = SYS_FUNCS + script; 32 | shell.evaluate(script); 33 | } 34 | 35 | @Override 36 | public void run(List script) { 37 | for (byte[] b : script) { 38 | try { 39 | Class clazz = loader.loadClass(b, 0, b.length); 40 | Method m = clazz.getMethod("main", String[].class); 41 | if(m != null && Modifier.isStatic(m.getModifiers())) { 42 | m.invoke(null, (Object) new String[0]); 43 | } 44 | } catch (Throwable ex) { 45 | throw new RuntimeException("Error in groovy script running.", ex); 46 | } 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /xpocket-scroll/src/main/java/com/perfma/xlab/xpocket/scroll/run/ScrollScriptRunner.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.scroll.run; 2 | 3 | import com.perfma.xlab.xpocket.scroll.ScriptName; 4 | import java.util.List; 5 | 6 | /** 7 | * 8 | * @author gongyu 9 | */ 10 | public interface ScrollScriptRunner extends ScriptName { 11 | 12 | /** 13 | * run string script. 14 | * @param script 15 | */ 16 | void run(String script); 17 | 18 | /** 19 | * run script with compiled stream 20 | * @param script 21 | */ 22 | void run(List script); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /xpocket-scroll/src/main/java/com/perfma/xlab/xpocket/scroll/utils/BytesUtils.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.xpocket.scroll.utils; 2 | 3 | /** 4 | * 5 | * @author gongyu 6 | */ 7 | public class BytesUtils { 8 | 9 | public static boolean isEquals(byte[] src, byte[] target, int offset, int length) { 10 | 11 | boolean result = true; 12 | 13 | offset = offset < 0 ? 0 : offset; 14 | length = length < 0 ? 0 : length; 15 | 16 | int pos = offset + length; 17 | if (src.length < pos || target.length < pos) { 18 | result = false; 19 | } else { 20 | for (int i = offset; i < pos; i++) { 21 | if (src[i] != target[i]) { 22 | result = false; 23 | break; 24 | } 25 | } 26 | } 27 | 28 | return result; 29 | } 30 | 31 | public static int paddingSize(int size) { 32 | int div = size % 8; 33 | return div == 0 ? 0 : 8 - div; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /xpocket-scroll/src/main/resources/META-INF/services/com.perfma.xlab.xpocket.scroll.compile.ScrollScriptCompiler: -------------------------------------------------------------------------------- 1 | com.perfma.xlab.xpocket.scroll.groovy.GroovyScriptCompiler 2 | -------------------------------------------------------------------------------- /xpocket-scroll/src/main/resources/META-INF/services/com.perfma.xlab.xpocket.scroll.run.ScrollScriptRunner: -------------------------------------------------------------------------------- 1 | com.perfma.xlab.xpocket.scroll.groovy.GroovyScriptRunner 2 | -------------------------------------------------------------------------------- /xpocket-sdk/src/main/resources/META-INF/services/com.perfma.xlab.xpocket.plugin.loader.PluginLoader: -------------------------------------------------------------------------------- 1 | com.perfma.xlab.xpocket.rumtime.spi.impl.DefaultPluginLoader -------------------------------------------------------------------------------- /xpocket-tools/src/main/java/com/perfma/xlab/tools/process/RunSystemTools.java: -------------------------------------------------------------------------------- 1 | package com.perfma.xlab.tools.process; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 执行系统命令的工具类 7 | * @author gongyu 8 | */ 9 | public class RunSystemTools { 10 | 11 | public static Process runCommand(boolean isInheritIO,String... cmds) 12 | throws IOException { 13 | ProcessBuilder builder = createBuilder(isInheritIO,cmds); 14 | return builder.start(); 15 | } 16 | 17 | private static ProcessBuilder createBuilder(boolean isInheritIO,String... cmds) { 18 | ProcessBuilder builder = new ProcessBuilder(cmds); 19 | if(isInheritIO) { 20 | builder.inheritIO(); 21 | } 22 | return builder; 23 | } 24 | 25 | public static void main(String[] args) { 26 | 27 | 28 | 29 | } 30 | 31 | } 32 | --------------------------------------------------------------------------------