-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support ignore transform by configured type or classloader pref…
…ixes (#514) - Ignore types by setting system properties by -Darex.ignore.type.prefixes=xxx.type, separate multiple values with commas. - Ignore classloader by setting system properties by -Darex.ignore.classloader.prefixes=xxx.classloader, separate multiple values with commas. --------- Co-authored-by: mr3 <[email protected]>
- Loading branch information
1 parent
9f310d1
commit fd8501f
Showing
9 changed files
with
172 additions
and
17 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
29 changes: 29 additions & 0 deletions
29
arex-instrumentation-api/src/main/java/io/arex/inst/extension/matcher/IgnoredRawMatcher.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,29 @@ | ||
package io.arex.inst.extension.matcher; | ||
|
||
import net.bytebuddy.agent.builder.AgentBuilder; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import net.bytebuddy.utility.JavaModule; | ||
import net.bytebuddy.utility.nullability.MaybeNull; | ||
|
||
import java.security.ProtectionDomain; | ||
import java.util.List; | ||
|
||
public class IgnoredRawMatcher implements AgentBuilder.RawMatcher { | ||
private final ElementMatcher.Junction<TypeDescription> typeMatcher; | ||
private final ElementMatcher.Junction<ClassLoader> classLoaderMatcher; | ||
|
||
public IgnoredRawMatcher(List<String> ignoreTypePrefixes, List<String> ignoreClassLoaderPrefixes) { | ||
this.typeMatcher = new IgnoredTypesMatcher(ignoreTypePrefixes); | ||
this.classLoaderMatcher = new IgnoreClassloaderMatcher(ignoreClassLoaderPrefixes); | ||
} | ||
|
||
@Override | ||
public boolean matches(TypeDescription typeDescription, | ||
@MaybeNull ClassLoader classLoader, | ||
@MaybeNull JavaModule module, | ||
@MaybeNull Class<?> classBeingRedefined, | ||
ProtectionDomain protectionDomain) { | ||
return typeMatcher.matches(typeDescription) || classLoaderMatcher.matches(classLoader); | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
...strumentation-api/src/test/java/io/arex/inst/extension/matcher/IgnoredRawMatcherTest.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,48 @@ | ||
package io.arex.inst.extension.matcher; | ||
|
||
import net.bytebuddy.description.type.TypeDescription; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.security.ProtectionDomain; | ||
import java.util.Collections; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class IgnoredRawMatcherTest { | ||
|
||
@Test | ||
void matches() { | ||
ProtectionDomain protectionDomain = new ProtectionDomain(null, null); | ||
TypeDescription.ForLoadedType typeDescription = new TypeDescription.ForLoadedType(String.class); | ||
ClassLoader classLoader = IgnoredRawMatcherTest.class.getClassLoader(); | ||
|
||
// case 1 | ||
// ignore type: false (classloader is null) | ||
IgnoredRawMatcher matcher = new IgnoredRawMatcher(Collections.emptyList(), Collections.emptyList()); | ||
assertFalse(matcher.matches(typeDescription, null, null, null, protectionDomain)); | ||
|
||
// case 2 | ||
// ignore type: false | ||
// ignore classloader: false | ||
matcher = new IgnoredRawMatcher(Collections.emptyList(), Collections.emptyList()); | ||
assertFalse(matcher.matches(typeDescription, classLoader, null, null, protectionDomain)); | ||
|
||
// case 3 | ||
// ignore type: true | ||
// ignore classloader: false | ||
matcher = new IgnoredRawMatcher(Collections.singletonList(typeDescription.getActualName()), Collections.emptyList()); | ||
assertTrue(matcher.matches(typeDescription, classLoader, null, null, protectionDomain)); | ||
|
||
// case 4 | ||
// ignore type: false | ||
// ignore classloader: true | ||
matcher = new IgnoredRawMatcher(Collections.emptyList(), Collections.singletonList(classLoader.getClass().getName())); | ||
assertTrue(matcher.matches(typeDescription, classLoader, null, null, protectionDomain)); | ||
|
||
// case 3 | ||
// ignore type: true | ||
// ignore classloader: true | ||
assertTrue(matcher.matches(typeDescription, classLoader, null, null, protectionDomain)); | ||
} | ||
} |
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