This is an automated email from the ASF dual-hosted git repository.
xiaoyu 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 1399e19 Improvement classloader (#8750)
1399e19 is described below
commit 1399e19319d80ae5324635911510e01f0e5ea771
Author: Daming <[email protected]>
AuthorDate: Thu Dec 24 16:14:49 2020 +0800
Improvement classloader (#8750)
* Improvement classloader
* fix checkstyle
---
.../core/plugin/loader/AgentPluginLoader.java | 43 ++++++++++++++++------
.../shardingsphere-agent-tracing-jaeger/pom.xml | 11 ++++++
2 files changed, 43 insertions(+), 11 deletions(-)
diff --git
a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/loader/AgentPluginLoader.java
b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/loader/AgentPluginLoader.java
index 3aec8f3..35715dc 100644
---
a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/loader/AgentPluginLoader.java
+++
b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/loader/AgentPluginLoader.java
@@ -22,6 +22,18 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.io.ByteStreams;
+import lombok.RequiredArgsConstructor;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+import net.bytebuddy.matcher.ElementMatcher.Junction;
+import org.apache.shardingsphere.agent.core.cache.AgentObjectPool;
+import org.apache.shardingsphere.agent.core.config.AgentConfiguration;
+import org.apache.shardingsphere.agent.core.path.AgentPathBuilder;
+import org.apache.shardingsphere.agent.core.plugin.definition.PluginDefinition;
+import
org.apache.shardingsphere.agent.core.plugin.point.PluginInterceptorPoint;
+
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
@@ -39,18 +51,8 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
+import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
-import lombok.RequiredArgsConstructor;
-import lombok.SneakyThrows;
-import lombok.extern.slf4j.Slf4j;
-import net.bytebuddy.description.type.TypeDescription;
-import net.bytebuddy.matcher.ElementMatcher;
-import net.bytebuddy.matcher.ElementMatcher.Junction;
-import org.apache.shardingsphere.agent.core.cache.AgentObjectPool;
-import org.apache.shardingsphere.agent.core.config.AgentConfiguration;
-import org.apache.shardingsphere.agent.core.path.AgentPathBuilder;
-import org.apache.shardingsphere.agent.core.plugin.definition.PluginDefinition;
-import
org.apache.shardingsphere.agent.core.plugin.point.PluginInterceptorPoint;
/**
* Agent plugin loader.
@@ -211,6 +213,11 @@ public final class AgentPluginLoader extends ClassLoader
implements Closeable {
ZipEntry entry = each.jarFile.getEntry(path);
if (Objects.nonNull(entry)) {
try {
+ int i = name.lastIndexOf('.');
+ if (i != -1) {
+ String packageName = name.substring(0, i);
+ definePackageInternal(packageName,
each.jarFile.getManifest());
+ }
byte[] data =
ByteStreams.toByteArray(each.jarFile.getInputStream(entry));
return defineClass(name, data, 0, data.length);
} catch (final IOException ex) {
@@ -225,6 +232,20 @@ public final class AgentPluginLoader extends ClassLoader
implements Closeable {
return className.replace(".", "/") + ".class";
}
+ private void definePackageInternal(final String packageName, final
Manifest manifest) {
+ if (getPackage(packageName) != null) {
+ return;
+ }
+ Attributes attr = manifest.getMainAttributes();
+ String specTitle = attr.getValue(Attributes.Name.SPECIFICATION_TITLE);
+ String specVersion =
attr.getValue(Attributes.Name.SPECIFICATION_VERSION);
+ String specVendor =
attr.getValue(Attributes.Name.SPECIFICATION_VENDOR);
+ String implTitle = attr.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
+ String implVersion =
attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
+ String implVendor =
attr.getValue(Attributes.Name.IMPLEMENTATION_VENDOR);
+ super.definePackage(packageName, specTitle, specVersion, specVendor,
implTitle, implVersion, implVendor, null);
+ }
+
@Override
protected Enumeration<URL> findResources(final String name) {
List<URL> resources = Lists.newArrayList();
diff --git
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/pom.xml
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/pom.xml
index d70bf65..1db9076 100644
---
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/pom.xml
+++
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/pom.xml
@@ -31,6 +31,7 @@
<properties>
<jaeger-client.version>0.31.0</jaeger-client.version>
+ <opentracing.version>0.31.0</opentracing.version>
<entrypoint.class>org.apache.shardingsphere.agent.plugin.tracing.jaeger.definition.JaegerPluginDefinition</entrypoint.class>
</properties>
@@ -40,6 +41,16 @@
<artifactId>jaeger-client</artifactId>
<version>${jaeger-client.version}</version>
</dependency>
+ <dependency>
+ <groupId>io.opentracing</groupId>
+ <artifactId>opentracing-api</artifactId>
+ <version>${opentracing.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.opentracing</groupId>
+ <artifactId>opentracing-util</artifactId>
+ <version>${opentracing.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>