-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#9653] Add plugin package class requirement filter
- Loading branch information
1 parent
1ffb662
commit 882c3be
Showing
11 changed files
with
135 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...main/java/com/navercorp/pinpoint/profiler/plugin/PluginPackageClassRequirementFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.navercorp.pinpoint.profiler.plugin; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class PluginPackageClassRequirementFilter implements ClassNameFilter { | ||
|
||
private final String[] packages; | ||
private final String[] requirements; | ||
private final Logger logger = LogManager.getLogger(this.getClass()); | ||
|
||
public PluginPackageClassRequirementFilter(List<String> packageRequirementList) { | ||
Objects.requireNonNull(packageRequirementList, "packageRequirementList"); | ||
|
||
final List<String> packageList = new ArrayList<>(); | ||
final List<String> requirementList = new ArrayList<>(); | ||
for (String packageWithRequirement : packageRequirementList) { | ||
String[] split = packageWithRequirement.split(":"); | ||
packageList.add(split[0]); | ||
requirementList.add(split[1]); | ||
} | ||
|
||
packages = packageList.toArray(new String[0]); | ||
requirements = requirementList.toArray(new String[0]); | ||
} | ||
|
||
@Override | ||
public boolean accept(String className) { | ||
ClassLoader cl = ClassLoader.getSystemClassLoader(); | ||
for (int i = 0; i < packages.length; i++) { | ||
if (className.startsWith(packages[i])) { | ||
if (!isLoadedClass(requirements[i], cl)) { | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("reject class:{}, packageName:{}, requirement:{}, classloader:{}", className, packages[i], requirements[i], cl); | ||
} | ||
return REJECT; | ||
} | ||
} | ||
} | ||
return ACCEPT; | ||
} | ||
|
||
private boolean isLoadedClass(String classname, ClassLoader cl) { | ||
try { | ||
Class.forName(classname, false, cl); | ||
return true; | ||
} catch (ClassNotFoundException ignored) { | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "PluginPackageRequirementFilter{" + | ||
"packages=" + Arrays.toString(packages) + | ||
", requirements=" + Arrays.toString(requirements) + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.