Search in sources :

Example 1 with BarImpl

use of org.jboss.modules.test.BarImpl in project jboss-modules by jboss-modules.

the class ClassFilteringTest method testClassFilter.

@Test
public void testClassFilter() throws Exception {
    final ModuleIdentifier identifierA = ModuleIdentifier.create(getClass().getSimpleName());
    ModuleSpec.Builder specBuilderA = ModuleSpec.build(identifierA);
    // Export-Package: com.acme.foo; include:="Qux*,BarImpl";exclude:=QuxImpl
    String packagePath = QuxBar.class.getPackage().getName().replace('.', '/');
    PathFilter inA = PathFilters.match(packagePath + "/Qux*.class");
    PathFilter inB = PathFilters.match(packagePath + "/BarImpl.class");
    PathFilter exA = PathFilters.match(packagePath + "/QuxImpl.class");
    // A class is only visible if it is:
    // Matched with an entry in the included list, and
    // Not matched with an entry in the excluded list.
    PathFilter in = PathFilters.any(inA, inB);
    PathFilter ex = PathFilters.not(PathFilters.any(exA));
    final PathFilter filter = PathFilters.all(in, ex);
    ClassFilter classImportFilter = ClassFilters.acceptAll();
    ClassFilter classExportFilter = ClassFilters.fromResourcePathFilter(filter);
    specBuilderA.addResourceRoot(createResourceLoaderSpec(getTestResourceLoader()));
    PathFilter importFilter = PathFilters.acceptAll();
    PathFilter exportFilter = PathFilters.acceptAll();
    PathFilter resourceImportFilter = PathFilters.acceptAll();
    PathFilter resourceExportFilter = PathFilters.acceptAll();
    specBuilderA.addDependency(new LocalDependencySpecBuilder().setImportFilter(importFilter).setExportFilter(exportFilter).setResourceImportFilter(resourceImportFilter).setResourceExportFilter(resourceExportFilter).setClassImportFilter(classImportFilter).setClassExportFilter(classExportFilter).build());
    addModuleSpec(specBuilderA.create());
    ModuleIdentifier identifierB = ModuleIdentifier.create("moduleB");
    ModuleSpec.Builder specBuilderB = ModuleSpec.build(identifierB);
    specBuilderB.addDependency(new ModuleDependencySpecBuilder().setName(identifierA.toString()).build());
    addModuleSpec(specBuilderB.create());
    assertLoadClass(identifierA, QuxFoo.class.getName());
    assertLoadClass(identifierA, QuxBar.class.getName());
    assertLoadClass(identifierA, QuxImpl.class.getName());
    assertLoadClass(identifierA, BarImpl.class.getName());
    assertLoadClass(identifierB, QuxFoo.class.getName());
    assertLoadClass(identifierB, QuxBar.class.getName());
    assertLoadClassFail(identifierB, QuxImpl.class.getName());
    assertLoadClass(identifierB, BarImpl.class.getName());
}
Also used : PathFilter(org.jboss.modules.filter.PathFilter) QuxFoo(org.jboss.modules.test.QuxFoo) ClassFilter(org.jboss.modules.filter.ClassFilter) QuxImpl(org.jboss.modules.test.QuxImpl) BarImpl(org.jboss.modules.test.BarImpl) QuxBar(org.jboss.modules.test.QuxBar) Test(org.junit.Test)

Aggregations

ClassFilter (org.jboss.modules.filter.ClassFilter)1 PathFilter (org.jboss.modules.filter.PathFilter)1 BarImpl (org.jboss.modules.test.BarImpl)1 QuxBar (org.jboss.modules.test.QuxBar)1 QuxFoo (org.jboss.modules.test.QuxFoo)1 QuxImpl (org.jboss.modules.test.QuxImpl)1 Test (org.junit.Test)1