From 00aeb9ae432e650b112be7ac5376f445fcbb82f3 Mon Sep 17 00:00:00 2001 From: hengyunabc Date: Wed, 28 Nov 2018 17:59:01 +0800 Subject: [PATCH] add ognl command doc. #240 --- .../core/command/klass100/OgnlCommand.java | 2 +- site/src/site/sphinx/commands.md | 2 +- site/src/site/sphinx/en/commands.md | 2 + site/src/site/sphinx/en/ognl.md | 60 ++++++++++++++++++ site/src/site/sphinx/ognl.md | 61 +++++++++++++++++++ 5 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 site/src/site/sphinx/en/ognl.md create mode 100644 site/src/site/sphinx/ognl.md diff --git a/core/src/main/java/com/taobao/arthas/core/command/klass100/OgnlCommand.java b/core/src/main/java/com/taobao/arthas/core/command/klass100/OgnlCommand.java index f15768cfb..86aec8fc1 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/klass100/OgnlCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/klass100/OgnlCommand.java @@ -27,7 +27,7 @@ import com.taobao.middleware.logger.Logger; @Summary("Execute ognl expression.") @Description(Constants.EXAMPLE + " ognl '@java.lang.System@out.println(\"hello\")' \n" - + " ognl -x 2 '@Singleton@getInstance() \n" + + " ognl -x 2 '@Singleton@getInstance()' \n" + " ognl '@Demo@staticFiled' \n" + " ognl '#value1=@System@getProperty(\"java.home\"), #value2=@System@getProperty(\"java.runtime.name\"), {#value1, #value2}'\n" + " ognl -c 5d113a51 '@com.taobao.arthas.core.GlobalOptions@isDump' \n" diff --git a/site/src/site/sphinx/commands.md b/site/src/site/sphinx/commands.md index 012b65902..9c33d14cc 100644 --- a/site/src/site/sphinx/commands.md +++ b/site/src/site/sphinx/commands.md @@ -7,7 +7,7 @@ * [sysprop](sysprop.md) * [getstatic](getstatic.md) - +* [ognl](ognl.md) * [sc](sc.md) * [sm](sm.md) diff --git a/site/src/site/sphinx/en/commands.md b/site/src/site/sphinx/en/commands.md index 48c4bb959..978666e55 100644 --- a/site/src/site/sphinx/en/commands.md +++ b/site/src/site/sphinx/en/commands.md @@ -7,6 +7,8 @@ All Commands * [sysprop](sysprop.md) * [getstatic](getstatic.md) +* [ognl](ognl.md) + * [sc](sc.md) * [sm](sm.md) * [dump](dump.md) diff --git a/site/src/site/sphinx/en/ognl.md b/site/src/site/sphinx/en/ognl.md new file mode 100644 index 000000000..81a80e7d3 --- /dev/null +++ b/site/src/site/sphinx/en/ognl.md @@ -0,0 +1,60 @@ +ognl +=== + +> Execute ognl expression. + +Since 3.0.5. + +### Parameters + +|Name|Specification| +|---:|:---| +|*express*|expression to be executed| +|`[c:]`| The hashcode of the ClassLoader that executes the expression, default ClassLoader is SystemClassLoader. | +|[x]|Expand level of object (1 by default).| + + +### Usage + +* [Special usages](https://github.com/alibaba/arthas/issues/71) +* [OGNL official guide](https://commons.apache.org/proper/commons-ognl/language-guide.html) + +Call static method: + +```bash +$ ognl '@java.lang.System@out.println("hello")' +null +``` + +Get static field: + +```bash +$ ognl '@demo.MathGame@random' +@Random[ + serialVersionUID=@Long[3905348978240129619], + seed=@AtomicLong[125451474443703], + multiplier=@Long[25214903917], + addend=@Long[11], + mask=@Long[281474976710655], + DOUBLE_UNIT=@Double[1.1102230246251565E-16], + BadBound=@String[bound must be positive], + BadRange=@String[bound must be greater than origin], + BadSize=@String[size must be non-negative], + seedUniquifier=@AtomicLong[-3282039941672302964], + nextNextGaussian=@Double[0.0], + haveNextNextGaussian=@Boolean[false], + serialPersistentFields=@ObjectStreamField[][isEmpty=false;size=3], + unsafe=@Unsafe[sun.misc.Unsafe@28ea5898], + seedOffset=@Long[24], +] +``` + +Execute a multi-line expression, and return a list: + +```bash +$ ognl '#value1=@System@getProperty("java.home"), #value2=@System@getProperty("java.runtime.name"), {#value1, #value2}' +@ArrayList[ + @String[/opt/java/8.0.181-zulu/jre], + @String[OpenJDK Runtime Environment], +] +``` \ No newline at end of file diff --git a/site/src/site/sphinx/ognl.md b/site/src/site/sphinx/ognl.md new file mode 100644 index 000000000..41e558def --- /dev/null +++ b/site/src/site/sphinx/ognl.md @@ -0,0 +1,61 @@ +ognl +=== + +> 执行ognl表达式 + +从3.0.5版本增加 + +### 参数说明 + +|参数名称|参数说明| +|---:|:---| +|*express*|执行的表达式| +|`[c:]`|执行表达式的 ClassLoader 的 hashcode,默认值是SystemClassLoader| +|[x]|结果对象的展开层次,默认值1| + + +### 使用参考 + +* OGNL特殊用法请参考:[https://github.com/alibaba/arthas/issues/71](https://github.com/alibaba/arthas/issues/71) +* OGNL表达式官方指南:[https://commons.apache.org/proper/commons-ognl/language-guide.html](https://commons.apache.org/proper/commons-ognl/language-guide.html) + + +调用静态函数: + +```bash +$ ognl '@java.lang.System@out.println("hello")' +null +``` + +获取静态类的静态字段: + +```bash +$ ognl '@demo.MathGame@random' +@Random[ + serialVersionUID=@Long[3905348978240129619], + seed=@AtomicLong[125451474443703], + multiplier=@Long[25214903917], + addend=@Long[11], + mask=@Long[281474976710655], + DOUBLE_UNIT=@Double[1.1102230246251565E-16], + BadBound=@String[bound must be positive], + BadRange=@String[bound must be greater than origin], + BadSize=@String[size must be non-negative], + seedUniquifier=@AtomicLong[-3282039941672302964], + nextNextGaussian=@Double[0.0], + haveNextNextGaussian=@Boolean[false], + serialPersistentFields=@ObjectStreamField[][isEmpty=false;size=3], + unsafe=@Unsafe[sun.misc.Unsafe@28ea5898], + seedOffset=@Long[24], +] +``` + +执行多行表达式,赋值给临时变量,返回一个List: + +```bash +$ ognl '#value1=@System@getProperty("java.home"), #value2=@System@getProperty("java.runtime.name"), {#value1, #value2}' +@ArrayList[ + @String[/opt/java/8.0.181-zulu/jre], + @String[OpenJDK Runtime Environment], +] +``` \ No newline at end of file