Skip to content

Commit

Permalink
Merge branch 'master' into ognl-property-get
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan-QLB authored Nov 27, 2024
2 parents 25992ae + 3bc5053 commit b49d35c
Show file tree
Hide file tree
Showing 33 changed files with 421 additions and 511 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/push-docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Push arthas images to Docker Hub

on:
workflow_dispatch:
inputs:
version:
description: "The version number to push (e.g., 4.0.3)"
required: true

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
# 步骤 1:检出 master 分支的代码
- name: Checkout gh-pages branch
uses: actions/checkout@v3
with:
ref: master

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build Docker image
run: |
VERSION="${{ github.event.inputs.version }}"
docker buildx build . --build-arg ARTHAS_VERSION=$VERSION --build-arg MIRROR=true -t hengyunabc/arthas:$VERSION -t hengyunabc/arthas:latest --platform=linux/arm64,linux/amd64 --push
docker buildx build . --build-arg ARTHAS_VERSION=$VERSION --build-arg MIRROR=true -f Dockerfile-No-Jdk -t hengyunabc/arthas:$VERSION-no-jdk --platform=linux/arm64,linux/amd64 --push
80 changes: 80 additions & 0 deletions .github/workflows/update-doc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Update docs on gh-pages

on:
workflow_dispatch:
inputs:
version:
description: "The version number to download and update (e.g., 4.0.3)"
required: true

jobs:
update-assets:
runs-on: ubuntu-latest

steps:
# 步骤 1:检出 gh-pages 分支的代码
- name: Checkout gh-pages branch
uses: actions/checkout@v3
with:
ref: gh-pages

# 步骤 2:下载指定版本的文档 ZIP 文件到 /tmp 目录
- name: Download documentation ZIP file
run: |
VERSION="${{ github.event.inputs.version }}"
DOC_DOWNLOAD_URL="https://repo1.maven.org/maven2/com/taobao/arthas/arthas-packaging/${VERSION}/arthas-packaging-${VERSION}-doc.zip"
echo "Downloading documentation from $DOC_DOWNLOAD_URL"
curl -L "$DOC_DOWNLOAD_URL" -o "/tmp/arthas-doc.zip"
# 步骤 3:解压文档 ZIP 文件
- name: Unzip documentation file
run: |
unzip -o /tmp/arthas-doc.zip -d /tmp/arthas-doc
# 步骤 4:删除仓库中的 assets 目录
- name: Remove assets directory
run: |
rm -rf assets
# 步骤 5:复制解压后的文档文件到仓库
- name: Copy documentation files to repository
run: |
cp -r /tmp/arthas-doc/* ./
# 步骤 6:下载指定版本的二进制 ZIP 文件到 /tmp 目录
- name: Download binary ZIP file
run: |
VERSION="${{ github.event.inputs.version }}"
BIN_DOWNLOAD_URL="https://repo1.maven.org/maven2/com/taobao/arthas/arthas-packaging/${VERSION}/arthas-packaging-${VERSION}-bin.zip"
echo "Downloading binary files from $BIN_DOWNLOAD_URL"
curl -L "$BIN_DOWNLOAD_URL" -o "/tmp/arthas-bin.zip"
# 步骤 7:解压二进制 ZIP 文件
- name: Unzip binary file
run: |
unzip -o /tmp/arthas-bin.zip -d /tmp/arthas-bin
# 步骤 8:复制指定文件到仓库目录
- name: Copy binary files to repository
run: |
cp /tmp/arthas-bin/as.sh ./
cp /tmp/arthas-bin/arthas-boot.jar ./
cp /tmp/arthas-bin/math-game.jar ./
# 步骤 9:赋予 as.sh 可执行权限
- name: Make as.sh executable
run: |
chmod +x as.sh
# 步骤 10:设置 Git 用户信息
- name: Set Git user
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
# 步骤 11:提交并推送更改到远程仓库
- name: Commit and push changes
run: |
git add .
git commit -m "Update docs to version ${{ github.event.inputs.version }}"
git push origin gh-pages
8 changes: 2 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,11 @@ Tip: you can use `--versions` to list all available versions.
版本号信息地址: https://maven.aliyun.com/repository/public/com/taobao/arthas/arthas-packaging/maven-metadata.xml

* 打上tag,push tag到仓库上
* 需要更新 gh-pages 分支下面的 arthas-boot.jar/math-game.jar/as.sh ,下载 doc.zip,解压覆盖掉文档的更新
* 需要更新 gh-pages 分支下面的 arthas-boot.jar/math-game.jar/as.sh ,下载 doc.zip,解压覆盖掉文档的更新,可以通过 github action 更新: https://github.com/alibaba/arthas/actions/workflows/update-doc.yaml
* 需要更新docker镜像,push新的tag:https://hub.docker.com/r/hengyunabc/arthas/tags?page=1&ordering=last_updated

以 3.6.5 版本为例:
```
docker buildx build . --build-arg ARTHAS_VERSION=3.6.5 --build-arg MIRROR=true -t hengyunabc/arthas:3.6.5 -t hengyunabc/arthas:latest --platform=linux/arm64,linux/amd64 --push
可以通过 github action push: https://github.com/alibaba/arthas/actions/workflows/push-docker.yaml

docker buildx build . --build-arg ARTHAS_VERSION=3.6.5 --build-arg MIRROR=true -f Dockerfile-No-Jdk -t hengyunabc/arthas:3.6.5-no-jdk --platform=linux/arm64,linux/amd64 --push
```
* 更新README.md,比如增加了新命令,要加上说明,更新wiki的链接
* 更新release页面的 issue信息,修改信息等
* 更新 https://arthas.aliyun.com/api/latest_version api
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM openjdk:8-jdk-alpine

ARG ARTHAS_VERSION="4.0.2"
ARG ARTHAS_VERSION="4.0.4"
ARG MIRROR=false

ENV MAVEN_HOST=https://repo1.maven.org/maven2 \
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-No-Jdk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Stage 1: Build
FROM openjdk:8-jdk-alpine AS builder

ARG ARTHAS_VERSION="4.0.2"
ARG ARTHAS_VERSION="4.0.4"
ARG MIRROR=false
ENV MAVEN_HOST=https://repo1.maven.org/maven2 \
MIRROR_MAVEN_HOST=https://maven.aliyun.com/repository/public
Expand Down
6 changes: 3 additions & 3 deletions bin/as.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

# program : Arthas
# author : Core Engine @ Taobao.com
# date : 2024-10-17
# date : 2024-11-13

# current arthas script version
ARTHAS_SCRIPT_VERSION=4.0.2
ARTHAS_SCRIPT_VERSION=4.0.4

# SYNOPSIS
# rreadlink <fileOrDirPath>
Expand Down Expand Up @@ -476,7 +476,7 @@ EXAMPLES:
./as.sh --stat-url 'http://192.168.10.11:8080/api/stat'
./as.sh -c 'sysprop; thread' <pid>
./as.sh -f batch.as <pid>
./as.sh --use-version 4.0.2
./as.sh --use-version 4.0.4
./as.sh --session-timeout 3600
./as.sh --attach-only
./as.sh --disabled-commands stop,dump
Expand Down
2 changes: 1 addition & 1 deletion boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
+ " java -jar arthas-boot.jar --stat-url 'http://192.168.10.11:8080/api/stat'\n"
+ " java -jar arthas-boot.jar -c 'sysprop; thread' <pid>\n"
+ " java -jar arthas-boot.jar -f batch.as <pid>\n"
+ " java -jar arthas-boot.jar --use-version 4.0.2\n"
+ " java -jar arthas-boot.jar --use-version 4.0.4\n"
+ " java -jar arthas-boot.jar --versions\n"
+ " java -jar arthas-boot.jar --select math-game\n"
+ " java -jar arthas-boot.jar --session-timeout 3600\n" + " java -jar arthas-boot.jar --attach-only\n"
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
24 changes: 23 additions & 1 deletion core/src/main/java/com/taobao/arthas/core/GlobalOptions.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.taobao.arthas.core;

import java.lang.reflect.Field;

import com.taobao.arthas.common.JavaVersionUtils;
import com.taobao.arthas.common.UnsafeUtils;

import ognl.OgnlRuntime;

/**
* 全局开关
Expand Down Expand Up @@ -128,12 +133,29 @@ public class GlobalOptions {
public static volatile boolean verbose = false;

/**
* 是否打开strict 开关
* 是否打开strict 开关。更新时注意 ognl 里的配置需要同步修改
* @see ognl.OgnlRuntime#getUseStricterInvocationValue()
*/
@Option(level = 1,
name = "strict",
summary = "Option to strict mode",
description = STRICT_MESSAGE
)
public static volatile boolean strict = true;

public static void updateOnglStrict(boolean strict) {
try {
Field field = OgnlRuntime.class.getDeclaredField("_useStricterInvocation");
field.setAccessible(true);
// 获取字段的内存偏移量和基址
Object staticFieldBase = UnsafeUtils.UNSAFE.staticFieldBase(field);
long staticFieldOffset = UnsafeUtils.UNSAFE.staticFieldOffset(field);

// 修改字段的值
UnsafeUtils.UNSAFE.putBoolean(staticFieldBase, staticFieldOffset, strict);
} catch (NoSuchFieldException | SecurityException e) {
// ignore
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ private ExitStatus processChangeNameValue(CommandProcess process) throws Illegal
return ExitStatus.failure(-1, format("Options[%s] type[%s] was unsupported.", optionName, type.getSimpleName()));
}

// FIXME hack for ongl strict
if (field.getName().equals("strict")) {
GlobalOptions.updateOnglStrict(Boolean.valueOf(optionValue));
logger.info("update ongl strict to: {}", optionValue);
}
} catch (Throwable t) {
return ExitStatus.failure(-1, format("Cannot cast option value[%s] to type[%s].", optionValue, type.getSimpleName()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.taobao.arthas.core.command.express;

import java.util.Map;

import com.taobao.arthas.core.GlobalOptions;

import ognl.ObjectPropertyAccessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.concurrent.ConcurrentHashMap;

import ognl.ClassResolver;
import ognl.OgnlContext;

/**
* @author hengyunabc 2018-10-18
Expand All @@ -20,9 +19,8 @@ public ClassLoaderClassResolver(ClassLoader classLoader) {
this.classLoader = classLoader;
}


@Override
public <T> Class<T> classForName(String className, OgnlContext ognlContext) throws ClassNotFoundException {
public Class classForName(String className, Map context) throws ClassNotFoundException {
Class<?> result = null;

if ((result = classes.get(className)) == null) {
Expand All @@ -39,6 +37,6 @@ public <T> Class<T> classForName(String className, OgnlContext ognlContext) thro
}
classes.put(className, result);
}
return (Class<T>) result;
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.taobao.arthas.core.command.express;

import ognl.ClassResolver;
import ognl.OgnlContext;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -21,7 +20,7 @@ private CustomClassResolver() {
}

@Override
public <T> Class<T> classForName(String className, OgnlContext ognlContext) throws ClassNotFoundException {
public Class classForName(String className, Map context) throws ClassNotFoundException {
Class<?> result = null;

if ((result = classes.get(className)) == null) {
Expand All @@ -40,6 +39,6 @@ public <T> Class<T> classForName(String className, OgnlContext ognlContext) thro
}
classes.put(className, result);
}
return (Class<T>) result;
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.taobao.arthas.core.command.express;

import ognl.MemberAccess;
import ognl.OgnlContext;

import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Member;
import java.lang.reflect.Modifier;
import java.util.Map;

/**
* ognl.DefaultMemberAccess (ognl:ognl:3.1.19)
Expand Down Expand Up @@ -58,7 +58,8 @@ public void setAllowPackageProtectedAccess(boolean value) {
allowPackageProtectedAccess = value;
}

public Object setup(OgnlContext context, Object target, Member member, String propertyName) {
@Override
public Object setup(Map context, Object target, Member member, String propertyName) {
Object result = null;

if (isAccessible(context, target, member, propertyName)) {
Expand All @@ -72,7 +73,8 @@ public Object setup(OgnlContext context, Object target, Member member, String pr
return result;
}

public void restore(OgnlContext context, Object target, Member member, String propertyName, Object state) {
@Override
public void restore(Map context, Object target, Member member, String propertyName, Object state) {
if (state != null) {
((AccessibleObject)member).setAccessible((Boolean)state);
}
Expand All @@ -88,7 +90,8 @@ public void restore(OgnlContext context, Object target, Member member, String pr
* @param propertyName the property to test accessibility for (not used).
* @return true if the member is accessible in the context, false otherwise.
*/
public boolean isAccessible(OgnlContext context, Object target, Member member, String propertyName) {
@Override
public boolean isAccessible(Map context, Object target, Member member, String propertyName) {
int modifiers = member.getModifiers();
boolean result = Modifier.isPublic(modifiers);

Expand Down
Loading

0 comments on commit b49d35c

Please sign in to comment.