Skip to content

Commit

Permalink
Added ability to include/exclude paths/classes via real Regex
Browse files Browse the repository at this point in the history
(cherry picked from commit 076df6211d01a1a9904a741566d645e9ab36c118)
  • Loading branch information
Armaxis committed Jan 8, 2020
1 parent d831f65 commit 700b4ef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ class SimpleRelocator implements Relocator {
return this
}

SimpleRelocator includeRegex(String pattern) {
this.includes.add("%regex[$pattern]")
return this
}

SimpleRelocator excludeRegex(String pattern) {
this.excludes.add("%regex[$pattern]")
return this
}

private static Set<String> normalizePatterns(Collection<String> patterns) {
Set<String> normalized = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ class SimpleRelocatorTest extends TestCase {
assertEquals(false, relocator.canRelocatePath(pathContext("org/foo/PublicUtilStuff.class")))
}

void testCanRelocatePathWithRegex() {
SimpleRelocator relocator

relocator = new SimpleRelocator("org.foo", null, null, null)
relocator.includeRegex("org/foo/R(\\\$.*)?\$")
assertEquals(true, relocator.canRelocatePath("org/foo/R.class"))
assertEquals(true, relocator.canRelocatePath("org/foo/R\$string.class"))
assertEquals(true, relocator.canRelocatePath("org/foo/R\$layout.class"))
assertEquals(false, relocator.canRelocatePath("org/foo/Recording/R.class"))
assertEquals(false, relocator.canRelocatePath("org/foo/Recording.class"))
assertEquals(false, relocator.canRelocatePath("org/foo/bar/R\$string.class"))
assertEquals(false, relocator.canRelocatePath("org/R.class"))
assertEquals(false, relocator.canRelocatePath("org/R\$string.class"))

relocator = new SimpleRelocator("org.foo", null, null, null)
relocator.excludeRegex("org/foo/.*Factory[0-9].*")
assertEquals(true, relocator.canRelocatePath("org/foo/Factory.class"))
assertEquals(true, relocator.canRelocatePath("org/foo/FooFactoryMain.class"))
assertEquals(true, relocator.canRelocatePath("org/foo/BarFactory.class"))
assertEquals(false, relocator.canRelocatePath("org/foo/Factory0.class"))
assertEquals(false, relocator.canRelocatePath("org/foo/FooFactory1Main.class"))
assertEquals(false, relocator.canRelocatePath("org/foo/BarFactory2.class"))
}

void testCanRelocateClass() {
SimpleRelocator relocator

Expand Down

0 comments on commit 700b4ef

Please sign in to comment.