diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/AgentCoreEntrance.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/AgentCoreEntrance.java index c048519ff7..e7d93de004 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/AgentCoreEntrance.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/AgentCoreEntrance.java @@ -19,6 +19,7 @@ import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.AgentType; import io.sermant.core.common.BootArgsIndexer; +import io.sermant.core.common.CommonConstant; import io.sermant.core.common.LoggerFactory; import io.sermant.core.config.ConfigManager; import io.sermant.core.event.EventManager; @@ -35,6 +36,7 @@ import io.sermant.core.plugin.agent.info.EnhancementManager; import io.sermant.core.plugin.agent.template.DefaultAdviser; import io.sermant.core.service.ServiceManager; +import io.sermant.core.utils.FileUtils; import io.sermant.god.common.SermantManager; import java.lang.instrument.Instrumentation; @@ -90,6 +92,8 @@ public static void install(String artifact, Map argsMap, Instrum LoggerFactory.initDefaultLogger(artifact); adviserCache = new DefaultAdviser(); + FileUtils.setAgentPath((String) argsMap.get(CommonConstant.AGENT_PATH_KEY)); + // Initialize the classloader of framework ClassLoaderManager.init(argsMap); diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/common/CommonConstant.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/common/CommonConstant.java index e2aa2b06d0..7533d49b22 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/common/CommonConstant.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/common/CommonConstant.java @@ -127,6 +127,11 @@ public class CommonConstant { */ public static final String ARTIFACT_NAME_KEY = "artifact"; + /** + * The key of agent path + */ + public static final String AGENT_PATH_KEY = "agentPath"; + private CommonConstant() { } } diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/utils/FileUtils.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/utils/FileUtils.java index 9174a020ad..c5f6ba8bf5 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/utils/FileUtils.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/utils/FileUtils.java @@ -52,8 +52,7 @@ public class FileUtils { private static final String[] INVALID_SYMBOL = {"../", "..\\"}; - private static final String AGENT_PATH = new File(new File(FileUtils.class.getProtectionDomain().getCodeSource() - .getLocation().getPath()).getParent()).getParent(); + private static String agentPath; /** * file name of unmatched class name @@ -79,7 +78,7 @@ private FileUtils() { * @return path */ public static String getAgentPath() { - return AGENT_PATH; + return agentPath; } /** @@ -89,7 +88,7 @@ public static String getAgentPath() { * @return fixed path */ public static String validatePath(String path) { - if (!path.startsWith(AGENT_PATH)) { + if (!path.startsWith(agentPath)) { return ""; } @@ -288,7 +287,7 @@ private static String buildUnmatchedFileString() { AgentConfig config = ConfigManager.getConfig(AgentConfig.class); String preFilterPath = config.getPreFilterPath(); if (StringUtils.isEmpty(preFilterPath)) { - preFilterPath = AGENT_PATH; + preFilterPath = agentPath; } String preFilterFile = config.getPreFilterFile(); if (StringUtils.isEmpty(preFilterFile)) { @@ -296,4 +295,8 @@ private static String buildUnmatchedFileString() { } return preFilterPath + File.separatorChar + preFilterFile; } + + public static void setAgentPath(String path) { + agentPath = path; + } }