This is an automated email from the ASF dual-hosted git repository.
zhaojinchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 1dcc070c80c Remove useless code for AgentPath (#23383)
1dcc070c80c is described below
commit 1dcc070c80ce13067d000ee139ee6a6773922a45
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Jan 7 00:24:25 2023 +0800
Remove useless code for AgentPath (#23383)
* Remove useless code for AgentPath
* Remove useless code for AgentPath
* Remove useless code for AgentPath
* Remove useless code for AgentPath
---
.../shardingsphere/agent/core/path/AgentPath.java | 20 +++++---------------
1 file changed, 5 insertions(+), 15 deletions(-)
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/path/AgentPath.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/path/AgentPath.java
index c9a40132000..23f6e38ac20 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/path/AgentPath.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/path/AgentPath.java
@@ -41,26 +41,16 @@ public final class AgentPath {
public static File getRootPath() {
String classResourcePath = String.join("",
AgentPath.class.getName().replaceAll("\\.", "/"), ".class");
URL resource =
Objects.requireNonNull(ClassLoader.getSystemClassLoader().getResource(classResourcePath),
"Can not locate agent jar file.");
- String url = resource.toString();
- int existFileInJarIndex = url.indexOf('!');
- boolean isInJar = existFileInJarIndex > -1;
- return isInJar ? getFileInJar(url, existFileInJarIndex) :
getFileInResource(url, classResourcePath);
+ return getJarFile(resource.toString()).getParentFile();
}
- private static File getFileInJar(final String url, final int
fileInJarIndex) {
- String realUrl = url.substring(url.indexOf("file:"), fileInJarIndex);
+ private static File getJarFile(final String url) {
try {
- File agentJarFile = new File(new URL(realUrl).toURI());
- Preconditions.checkState(agentJarFile.exists(), "Can not locate
agent jar file by URL `%s`.", url);
- return agentJarFile.getParentFile();
+ File result = new File(new URL(url.substring(url.indexOf("file:"),
url.indexOf('!'))).toURI());
+ Preconditions.checkState(result.exists(), "Can not locate agent
jar file by URL `%s`.", url);
+ return result;
} catch (final MalformedURLException | URISyntaxException ex) {
throw new IllegalStateException(String.format("Can not locate
agent jar file by URL `%s`.", url));
}
}
-
- private static File getFileInResource(final String url, final String
classResourcePath) {
- int prefixLength = "file:".length();
- String classLocation = url.substring(prefixLength, url.length() -
classResourcePath.length());
- return new File(classLocation);
- }
}