-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Open
Labels
Milestone
Description
I plan to add a feature to identify the version in the plugin.
This feature can separate plugins for each version of lib.
It has the advantage of making compilation and maintenance easy.
e.g) mongo-db-plugin-2.x.jar, mongo-db-plugin-3.x.jar,
// pseudocode
public class MongoPlugin implements ProfilerPlugin, TransformTemplateAware {
context.addVerionMatcher(new VersionMatcher() {
@Override
public boolean isMatch(JarFile file) {
// Manifest base matcher
Manifest manifest = file.getManifest();
Attributes attributes = manifest.getAttributes("PATH");
String version = attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
if (version.endsWith("2.0.0")) {
//~~
return true;
}
// File name base matcher
if (file.getName().endsWith("2.0.0")) {
//~~
return true;
}
return true;
}
});
}Jarfile can be obtained from ProtectionDomain of Transform API.
// pseudocode
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
URL location = protectionDomain.getCodeSource().getLocation();
if (!location.getProtocol("jar")) {
//~~
}
JarFile jarFile = new JarFile(location.getFile());
if (versionMatcher.match(jarFile)) {
this.delegate.transform(...);
}
}