Search in sources :

Example 31 with FilterBuilder

use of org.reflections.util.FilterBuilder in project reflections by ronmamo.

the class FilterBuilderTest method test_parsePackages_include.

//-----------------------------------------------------------------------
@Test
public void test_parsePackages_include() {
    FilterBuilder filter = FilterBuilder.parsePackages("+org.reflections");
    assertTrue(filter.apply("org.reflections.Reflections"));
    assertTrue(filter.apply("org.reflections.foo.Reflections"));
    assertFalse(filter.apply("org.foobar.Reflections"));
    assertFalse(filter.apply("org.reflectionsplus.Reflections"));
}
Also used : FilterBuilder(org.reflections.util.FilterBuilder) Test(org.junit.Test)

Example 32 with FilterBuilder

use of org.reflections.util.FilterBuilder in project reflections by ronmamo.

the class FilterBuilderTest method test_parse_exclude.

@Test
public void test_parse_exclude() {
    FilterBuilder filter = FilterBuilder.parse("-org.reflections.*");
    assertFalse(filter.apply("org.reflections.Reflections"));
    assertFalse(filter.apply("org.reflections.foo.Reflections"));
    assertTrue(filter.apply("org.foobar.Reflections"));
    assertFalse(filter.apply("org.reflectionsplus.Reflections"));
}
Also used : FilterBuilder(org.reflections.util.FilterBuilder) Test(org.junit.Test)

Example 33 with FilterBuilder

use of org.reflections.util.FilterBuilder in project reflections by ronmamo.

the class FilterBuilderTest method test_parse_include_exclude.

@Test
public void test_parse_include_exclude() {
    FilterBuilder filter = FilterBuilder.parse("+org.reflections.*, -org.reflections.foo.*");
    assertTrue(filter.apply("org.reflections.Reflections"));
    assertFalse(filter.apply("org.reflections.foo.Reflections"));
    assertFalse(filter.apply("org.foobar.Reflections"));
}
Also used : FilterBuilder(org.reflections.util.FilterBuilder) Test(org.junit.Test)

Example 34 with FilterBuilder

use of org.reflections.util.FilterBuilder in project reflections by ronmamo.

the class JavaCodeSerializerTest method generateAndSave.

@BeforeClass
public static void generateAndSave() {
    Predicate<String> filter = new FilterBuilder().include("org.reflections.TestModel\\$.*");
    Reflections reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(filter).setScanners(new TypeElementsScanner().includeFields().publicOnly(false)).setUrls(asList(ClasspathHelper.forClass(TestModel.class))));
    //save
    String filename = ReflectionsTest.getUserDir() + "/src/test/java/org.reflections.MyTestModelStore";
    reflections.save(filename, new JavaCodeSerializer());
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) JavaCodeSerializer(org.reflections.serializers.JavaCodeSerializer) FilterBuilder(org.reflections.util.FilterBuilder) TypeElementsScanner(org.reflections.scanners.TypeElementsScanner) BeforeClass(org.junit.BeforeClass)

Example 35 with FilterBuilder

use of org.reflections.util.FilterBuilder in project reflections by ronmamo.

the class ReflectionsCollectTest method init.

@BeforeClass
public static void init() {
    Reflections ref = new Reflections(new ConfigurationBuilder().addUrls(ClasspathHelper.forClass(TestModel.class)).filterInputsBy(TestModelFilter).setScanners(new SubTypesScanner(false), new TypeAnnotationsScanner(), new MethodAnnotationsScanner(), new MethodParameterNamesScanner(), new MemberUsageScanner()));
    ref.save(getUserDir() + "/target/test-classes" + "/META-INF/reflections/testModel-reflections.xml");
    ref = new Reflections(new ConfigurationBuilder().setUrls(asList(ClasspathHelper.forClass(TestModel.class))).filterInputsBy(TestModelFilter).setScanners(new MethodParameterScanner()));
    final JsonSerializer serializer = new JsonSerializer();
    ref.save(getUserDir() + "/target/test-classes" + "/META-INF/reflections/testModel-reflections.json", serializer);
    reflections = Reflections.collect().merge(Reflections.collect("META-INF/reflections", new FilterBuilder().include(".*-reflections.json"), serializer));
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) FilterBuilder(org.reflections.util.FilterBuilder) JsonSerializer(org.reflections.serializers.JsonSerializer) BeforeClass(org.junit.BeforeClass)

Aggregations

FilterBuilder (org.reflections.util.FilterBuilder)46 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)23 Reflections (org.reflections.Reflections)19 Test (org.junit.Test)17 SubTypesScanner (org.reflections.scanners.SubTypesScanner)9 ResourcesScanner (org.reflections.scanners.ResourcesScanner)8 Test (org.junit.jupiter.api.Test)7 ArrayList (java.util.ArrayList)6 URL (java.net.URL)4 lombok.val (lombok.val)4 Field (java.lang.reflect.Field)2 Collection (java.util.Collection)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Set (java.util.Set)2 BeforeClass (org.junit.BeforeClass)2 MethodAnnotationsScanner (org.reflections.scanners.MethodAnnotationsScanner)2 TypeAnnotationsScanner (org.reflections.scanners.TypeAnnotationsScanner)2 ClasspathHelper (org.reflections.util.ClasspathHelper)2 Stopwatch (com.google.common.base.Stopwatch)1