Skip to content

Commit

Permalink
Implement mechanism to disable individual rules re #135
Browse files Browse the repository at this point in the history
  • Loading branch information
safris committed Jul 24, 2019
1 parent 09716cc commit 77c50e6
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void premain(final String agentArgs, final Instrumentation inst) throws Exceptio
private final Set<String> loadedRules = new HashSet<>();

@Override
void loadRules(final ClassLoader allRulesClassLoader, final Map<File,Integer> ruleJarToIndex, final Event[] events, final Map<File,PluginManifest> fileeToPluginManifest) throws IOException {
void loadRules(final ClassLoader allRulesClassLoader, final Map<File,Integer> ruleJarToIndex, final Event[] events, final Map<File,PluginManifest> fileToPluginManifest) throws IOException {
AgentRule agentRule = null;
try {
// Load ClassLoader Agent
Expand Down Expand Up @@ -141,16 +141,25 @@ void loadRules(final ClassLoader allRulesClassLoader, final Map<File,Integer> ru
continue;
}

if (logger.isLoggable(Level.FINE))
logger.fine("Installing new rule: " + line);

final Class<?> agentClass = Class.forName(line, true, allRulesClassLoader);
if (!AgentRule.class.isAssignableFrom(agentClass)) {
logger.severe("Class " + agentClass.getName() + " does not implement " + AgentRule.class);
continue;
}

final PluginManifest pluginManifest = fileeToPluginManifest.get(ruleJar);
final PluginManifest pluginManifest = fileToPluginManifest.get(ruleJar);

final String simpleClassName = line.substring(line.lastIndexOf('.') + 1);
final String disableRule = System.getProperty("sa.instrumentation.plugin." + pluginManifest.name + "." + simpleClassName + ".disable");
if (!"false".equals(disableRule)) {
if (logger.isLoggable(Level.FINE))
logger.fine("Skipping disabled rule: " + line);

continue;
}

if (logger.isLoggable(Level.FINE))
logger.fine("Installing new rule: " + line);

AgentRule.classNameToName.put(agentClass.getName(), pluginManifest.name);

Expand Down

0 comments on commit 77c50e6

Please sign in to comment.