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());
}
Aggregations