提交 43cf0627 编写于 作者: wu-sheng's avatar wu-sheng

Finish plugin initialization codes and fix package issues.

上级 83f8714f
......@@ -34,6 +34,7 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
import org.skywalking.apm.agent.core.boot.AgentPackagePath;
import org.skywalking.apm.agent.core.plugin.PluginBootstrap;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
......@@ -50,14 +51,13 @@ public class AgentClassLoader extends ClassLoader {
private List<File> classpath;
private List<Jar> allJars;
private ReentrantLock jarScanLock = new ReentrantLock();
private ReentrantLock loadClassLock = new ReentrantLock();
public static AgentClassLoader getDefault() {
return LOADER;
}
public static AgentClassLoader initDefaultLoader() throws AgentPackageNotFoundException {
LOADER = new AgentClassLoader(AgentClassLoader.class.getClassLoader());
LOADER = new AgentClassLoader(PluginBootstrap.class.getClassLoader());
return getDefault();
}
......@@ -69,44 +69,15 @@ public class AgentClassLoader extends ClassLoader {
classpath.add(new File(agentDictionary, "activations"));
}
protected Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException {
loadClassLock.lock();
try {
// First, check if the class has already been loaded
Class<?> c = findLoadedClass(name);
if (c == null) {
try {
super.loadClass(name, resolve);
} catch (ClassNotFoundException e) {
// ClassNotFoundException thrown if class not found
// from the non-null parent class loader
}
if (c == null) {
// If still not found, then invoke findClass in order
// to find the class.
c = findClass(name);
}
}
if (resolve) {
resolveClass(c);
}
return c;
} finally {
loadClassLock.unlock();
}
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
List<Jar> allJars = getAllJars();
String path = "/" + name.replace('.', '/').concat(".class");
String path = name.replace('.', '/').concat(".class");
for (Jar jar : allJars) {
JarEntry entry = jar.jarFile.getJarEntry(path);
if (entry != null) {
try {
URL classFileUrl = new URL("jar:file:" + jar.sourceFile.getAbsolutePath() + "!/" + name);
URL classFileUrl = new URL("jar:file:" + jar.sourceFile.getAbsolutePath() + "!/" + path);
byte[] data = null;
BufferedInputStream is = null;
ByteArrayOutputStream baos = null;
......
......@@ -66,20 +66,16 @@ public class InterceptorInstanceLoader {
String instanceKey = className + "_OF_" + targetClassLoader.getClass().getName() + "@" + Integer.toHexString(targetClassLoader.hashCode());
Object inst = INSTANCE_CACHE.get(instanceKey);
if (inst == null) {
if (InterceptorInstanceLoader.class.getClassLoader().equals(targetClassLoader)) {
inst = targetClassLoader.loadClass(className).newInstance();
} else {
INSTANCE_LOAD_LOCK.lock();
try {
ClassLoader pluginLoader = EXTEND_PLUGIN_CLASSLOADERS.get(targetClassLoader);
if (pluginLoader == null) {
pluginLoader = new AgentClassLoader(targetClassLoader);
EXTEND_PLUGIN_CLASSLOADERS.put(targetClassLoader, pluginLoader);
}
inst = Class.forName(className, true, pluginLoader).newInstance();
} finally {
INSTANCE_LOAD_LOCK.unlock();
INSTANCE_LOAD_LOCK.lock();
try {
ClassLoader pluginLoader = EXTEND_PLUGIN_CLASSLOADERS.get(targetClassLoader);
if (pluginLoader == null) {
pluginLoader = new AgentClassLoader(targetClassLoader);
EXTEND_PLUGIN_CLASSLOADERS.put(targetClassLoader, pluginLoader);
}
inst = Class.forName(className, true, pluginLoader).newInstance();
} finally {
INSTANCE_LOAD_LOCK.unlock();
}
if (inst != null) {
INSTANCE_CACHE.put(instanceKey, inst);
......
......@@ -35,8 +35,6 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<premain.class>org.skywalking.apm.agent.SkyWalkingAgent</premain.class>
<shade.package>org.skywalking.apm.dependencies</shade.package>
<shade.net.bytebuddy.source>net.bytebuddy</shade.net.bytebuddy.source>
<shade.net.bytebuddy.target>${shade.package}.${shade.net.bytebuddy.source}</shade.net.bytebuddy.target>
</properties>
......
......@@ -55,6 +55,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sdk.plugin.related.dir></sdk.plugin.related.dir>
<shade.net.bytebuddy.source>net.bytebuddy</shade.net.bytebuddy.source>
<shade.net.bytebuddy.target>${shade.package}.${shade.net.bytebuddy.source}</shade.net.bytebuddy.target>
</properties>
<dependencies>
......@@ -62,6 +64,13 @@
<groupId>org.skywalking</groupId>
<artifactId>apm-agent-core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-util</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.skywalking</groupId>
......@@ -73,6 +82,44 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<shadeSourcesContent>true</shadeSourcesContent>
<artifactSet>
<excludes>
<exclude>com.lmax:*</exclude>
<exclude>org.apache.httpcomponents:*</exclude>
<exclude>commons-logging:*</exclude>
<exclude>commons-codec:*</exclude>
<exclude>*:gson</exclude>
<exclude>io.grpc:*</exclude>
<exclude>io.netty:*</exclude>
<exclude>com.google.*:*</exclude>
<exclude>com.google.guava:guava</exclude>
</excludes>
</artifactSet>
<relocations>
<relocation>
<pattern>${shade.net.bytebuddy.source}</pattern>
<shadedPattern>${shade.net.bytebuddy.target}</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
......
......@@ -37,8 +37,73 @@
<artifactId>apm-toolkit-activation</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<shade.net.bytebuddy.source>net.bytebuddy</shade.net.bytebuddy.source>
<shade.net.bytebuddy.target>${shade.package}.${shade.net.bytebuddy.source}</shade.net.bytebuddy.target>
</properties>
<dependencies>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-agent-core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-util</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-test-tools</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<shadeSourcesContent>true</shadeSourcesContent>
<artifactSet>
<excludes>
<exclude>com.lmax:*</exclude>
<exclude>org.apache.httpcomponents:*</exclude>
<exclude>commons-logging:*</exclude>
<exclude>commons-codec:*</exclude>
<exclude>*:gson</exclude>
<exclude>io.grpc:*</exclude>
<exclude>io.netty:*</exclude>
<exclude>com.google.*:*</exclude>
<exclude>com.google.guava:guava</exclude>
</excludes>
</artifactSet>
<relocations>
<relocation>
<pattern>${shade.net.bytebuddy.source}</pattern>
<shadedPattern>${shade.net.bytebuddy.target}</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
......@@ -86,17 +151,4 @@
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-agent-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-test-tools</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
......@@ -40,13 +40,14 @@
<properties>
<compiler.version>1.6</compiler.version>
<shade.package>org.skywalking.apm.dependencies</shade.package>
</properties>
<dependencies>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-util</artifactId>
<version>3.2.3-2017</version>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册