Skip to content

Commit

Permalink
Merge pull request oldmanpushcart#118 from oldmanpushcart/develop-for…
Browse files Browse the repository at this point in the history
…-1.7.4.0

Develop for 1.7.4.0
  • Loading branch information
oldmanpushcart committed Feb 11, 2016
2 parents 32e9cc2 + ff8fcda commit 29e50b2
Show file tree
Hide file tree
Showing 25 changed files with 993 additions and 289 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@

## 最新版本

### **VERSION :** 1.7.3.6
### **VERSION :** 1.7.4.0

- 修复 #116 问题
- 修复 #112 问题
- 修复 #108 问题
- 增加`gs.sh``ga.sh`两个脚本
- 增加`js`命令,支持javascript脚本

### 版本号说明

Expand Down
60 changes: 60 additions & 0 deletions bin/ga.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

# program : greys-attach
# author : [email protected]
# date : 2016-02-05
# desc : write for july
# version : 1.7.4.0


# the usage
usage()
{
echo "
greys attach usage:
the format was [-s] <PID>
<PID> : the target Java Process ID
-s : attach jvm with silent
example:
./ga.sh <PID>
./ga.sh -s <PID>
"
}

# exit shell with err_code
# $1 : err_code
# $2 : err_msg
exit_on_err()
{
[[ ! -z "${2}" ]] && echo "${2}" 1>&2
exit ${1}
}


# the option to control ga.sh attach jvm with silent
OPTION_SILENT=0

while getopts "sh" ARG
do
case ${ARG} in
s) OPTION_SILENT=1;;
h) usage;exit 0;;
*) usage;exit 1;;
esac
done

shift $((OPTIND-1));

if [[ $# -lt 1 ]]; then
exit_on_err 1 "illegal arguments, the <PID> is required."
fi

if [[ ${OPTION_SILENT} -eq 1 ]]; then
./greys.sh -C "${@}" || exit 1
else
./greys.sh -C "${@}" \
&& echo "greys attach to target(${@}) success" \
|| exit_on_err 1 "greys attach to target(${@}) failed."
fi

5 changes: 4 additions & 1 deletion bin/greys-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ cp ../agent/target/greys-agent-jar-with-dependencies.jar ${GREYS_TARGET_DIR}/gre

# copy shell to TARGET_DIR
cat install-local.sh|sed "s/GREYS_VERSION=0.0.0.0/GREYS_VERSION=${GREYS_VERSION}/g" > ${GREYS_TARGET_DIR}/install-local.sh
chmod +x ${GREYS_TARGET_DIR}/install-local.sh
#chmod +x ${GREYS_TARGET_DIR}/install-local.sh
cp greys.sh ${GREYS_TARGET_DIR}/greys.sh
cp ga.sh ${GREYS_TARGET_DIR}/ga.sh
cp gs.sh ${GREYS_TARGET_DIR}/gs.sh
chmod +x ${GREYS_TARGET_DIR}/*.sh

# zip the greys
cd ../target/
Expand Down
57 changes: 44 additions & 13 deletions bin/greys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# author : [email protected]
# date : 2015-05-04
# desc : write for july
# version : 1.7.0.1
# version : 1.7.4.0

# define greys's home
GREYS_HOME=${HOME}/.greys
Expand All @@ -31,6 +31,17 @@ DEFAULT_TARGET_PORT="3658"
JVM_OPS="";


# the option to control greys.sh check the permission
OPTION_CHECK_PERMISSION=1

# the option to control greys.sh update version if necessary
OPTION_UPDATE_IF_NECESSARY=1

# the option to control greys.sh attach target jvm
OPTION_ATTACH_JVM=1

# the option to control greys.sh active greys-console
OPTION_ACTIVE_CONSOLE=1

# exit shell with err_code
# $1 : err_code
Expand Down Expand Up @@ -75,7 +86,7 @@ reset_for_env()
[ -z ${JAVA_HOME} ] && JAVA_HOME=/opt/taobao/java

# check the jvm version, we need 1.6+
local JAVA_VERSION=$(${JAVA_HOME}/bin/java -version 2>&1|awk -F '"' '/java version/&&$2>"1.5"{print $2}')
local JAVA_VERSION=$(${JAVA_HOME}/bin/java -version 2>&1|awk -F '"' '/version/&&$2>"1.5"{print $2}')
[[ ! -x ${JAVA_HOME} || -z ${JAVA_VERSION} ]] && exit_on_err 1 "illegal ENV, please set \$JAVA_HOME to JDK6+"

# reset BOOT_CLASSPATH
Expand Down Expand Up @@ -254,34 +265,54 @@ active_console()
fi
}




# the main
main()
{

check_permission
while getopts "PUJC" ARG
do
case ${ARG} in
P) OPTION_CHECK_PERMISSION=0;;
U) OPTION_UPDATE_IF_NECESSARY=0;;
J) OPTION_ATTACH_JVM=0;;
C) OPTION_ACTIVE_CONSOLE=0;;
?) usage;exit 1;;
esac
done

shift $((OPTIND-1));

if [[ ${OPTION_CHECK_PERMISSION} -eq 1 ]]; then
check_permission
fi

reset_for_env

parse_arguments "${@}" \
|| exit_on_err 1 "$(usage)"

update_if_necessary \
|| echo "update fail, ignore this update." 1>&2
if [[ ${OPTION_UPDATE_IF_NECESSARY} -eq 1 ]]; then
update_if_necessary \
|| echo "update fail, ignore this update." 1>&2
fi

local greys_local_version=$(default $(get_local_version) ${DEFAULT_VERSION})

if [[ ${greys_local_version} = ${DEFAULT_VERSION} ]]; then
exit_on_err 1 "greys not found, please check your network."
fi

attach_jvm ${greys_local_version}\
|| exit_on_err 1 "attach to target jvm(${TARGET_PID}) failed."
if [[ ${OPTION_ATTACH_JVM} -eq 1 ]]; then
attach_jvm ${greys_local_version}\
|| exit_on_err 1 "attach to target jvm(${TARGET_PID}) failed."
fi

if [[ ${OPTION_ACTIVE_CONSOLE} -eq 1 ]]; then
active_console ${greys_local_version}\
|| exit_on_err 1 "active console failed."
fi

active_console ${greys_local_version}
}



main "${@}"
main "${@}"
139 changes: 139 additions & 0 deletions bin/gs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/bin/bash

# program : greys-shell
# author : [email protected]
# date : 2016-02-05
# desc : write for july
# version : 1.7.4.0

# define greys's home
GREYS_HOME=${HOME}/.greys

# define greys's lib
GREYS_LIB_DIR=${GREYS_HOME}/lib

# last update greys version
DEFAULT_VERSION="0.0.0.0"

DEFAULT_TARGET_IP=127.0.0.1
DEFAULT_TARGET_PORT=3658

TARGET_IP=${DEFAULT_TARGET_IP}
TARGET_PORT=${DEFAULT_TARGET_PORT}

# reset greys work environment
# reset some options for env
reset_for_env()
{

# if env define the JAVA_HOME, use it first
# if is alibaba opts, use alibaba ops's default JAVA_HOME
[ -z ${JAVA_HOME} ] && JAVA_HOME=/opt/taobao/java

# check the jvm version, we need 1.6+
local JAVA_VERSION=$(${JAVA_HOME}/bin/java -version 2>&1|awk -F '"' '/version/&&$2>"1.5"{print $2}')
[[ ! -x ${JAVA_HOME} || -z ${JAVA_VERSION} ]] && exit_on_err 1 "illegal ENV, please set \$JAVA_HOME to JDK6+"

}

# parse the argument
parse_arguments()
{

TARGET_IP=$(echo ${1}|awk -F ":" '{print $1}');
TARGET_PORT=$(echo ${1}|awk -F ":" '{print $2}');

# reset ${ip} to default if empty
[ -z ${TARGET_IP} ] && TARGET_IP=${DEFAULT_TARGET_IP}

# reset ${port} to default if empty
[ -z ${TARGET_PORT} ] && TARGET_PORT=${DEFAULT_TARGET_PORT}

return 0

}


# get latest version from local
get_local_version()
{
ls ${GREYS_LIB_DIR}\
|awk -F "." '{printf("%03d.%03d.%03d.%03d\n",$1,$2,$3,$4)}'\
|sort\
|awk '/^[0-9][0-9][0-9].[0-9][0-9][0-9].[0-9][0-9][0-9].[0-9][0-9][0-9]$/'\
|tail -1\
|awk -F "." '{printf("%d.%d.%d.%d\n",$1,$2,$3,$4)}'
}

# get with default value
# $1 : target value
# $2 : default value
default()
{
[[ ! -z "${1}" ]] \
&& echo "${1}" \
|| echo "${2}"
}

# exit shell with err_code
# $1 : err_code
# $2 : err_msg
exit_on_err()
{
[[ ! -z "${2}" ]] && echo "${2}" 1>&2
exit ${1}
}


# greys netcat
greys_nc()
{
local greys_lib_dir=${GREYS_LIB_DIR}/${1}/greys
while read line;
do
echo ${line} \
| ${JAVA_HOME}/bin/java \
-cp ${greys_lib_dir}/greys-core.jar \
com.github.ompc.greys.core.util.GaNetCat \
${TARGET_IP} \
${TARGET_PORT}
done
}

# the usage
usage()
{
echo "
greys shell usage:
the format was [@IP:PORT]
[IP] : the target's IP, default ${DEFAULT_TARGET_IP}
[PORT] : the target's PORT, default ${DEFAULT_TARGET_PORT}
example:
echo help|./gs.sh [IP]
echo help|./gs.sh [IP:PORT]
"
}

main()
{

while getopts "h" ARG
do
case ${ARG} in
h) usage;exit 0;;
*) usage;exit 1;;
esac
done

reset_for_env

parse_arguments "${@}" \
|| exit_on_err 1 "$(usage)"

local greys_local_version=$(default $(get_local_version) ${DEFAULT_VERSION})
greys_nc ${greys_local_version}

}

main "${@}"
8 changes: 4 additions & 4 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@
<!--<groupId>org.springframework</groupId>-->
<!--<artifactId>spring-context</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</dependency>
<!--<dependency>-->
<!--<groupId>org.codehaus.groovy</groupId>-->
<!--<artifactId>groovy-all</artifactId>-->
<!--</dependency>-->
</dependencies>

</project>
25 changes: 15 additions & 10 deletions core/src/main/java/com/github/ompc/greys/core/Advice.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ public final class Advice {
public final Object returnObj;
public final Throwable throwExp;

public final static int ACCESS_BEFORE = 1;
public final static int ACCESS_AFTER_RETUNING = 1 << 1;
public final static int ACCESS_AFTER_THROWING = 1 << 2;
private final static int ACCESS_BEFORE = 1;
private final static int ACCESS_AFTER_RETUNING = 1 << 1;
private final static int ACCESS_AFTER_THROWING = 1 << 2;

public final boolean isBefore;
public final boolean isThrow;
public final boolean isReturn;
public final boolean isThrowing;
public final boolean isReturning;

// 回放过程processId
// use for TimeTunnelCommand.doPlay()
Expand All @@ -31,14 +33,14 @@ public final class Advice {
/**
* for finish
*
* @param loader 类加载器
* @param clazz 类
* @param method 方法
* @param target 目标类
* @param params 调用参数
* @param loader 类加载器
* @param clazz
* @param method 方法
* @param target 目标类
* @param params 调用参数
* @param returnObj 返回值
* @param throwExp 抛出异常
* @param access 进入场景
* @param throwExp 抛出异常
* @param access 进入场景
*/
private Advice(
ClassLoader loader,
Expand All @@ -60,6 +62,9 @@ private Advice(
isThrow = (access & ACCESS_AFTER_THROWING) == ACCESS_AFTER_THROWING;
isReturn = (access & ACCESS_AFTER_RETUNING) == ACCESS_AFTER_RETUNING;

this.isReturning = isReturn;
this.isThrowing = isThrow;

playIndex = PlayIndexHolder.getInstance().get();
}

Expand Down
Loading

0 comments on commit 29e50b2

Please sign in to comment.