Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MODULES-111 - Fix various issues in class/resource filtering

  • Loading branch information...
commit b1413c6c541762437e20527e9badcc87a52d1974 1 parent 5c35791
@dmlloyd dmlloyd authored
View
46 src/main/java/org/jboss/modules/Module.java
@@ -857,9 +857,15 @@ long addPaths(Dependency[] dependencies, Map<String, List<LocalLoader>> map, Fas
}
final PathFilter importFilter = dependency.getImportFilter();
- filterStack.add(importFilter);
+ final FastCopyHashSet<PathFilter> nestedFilters;
final FastCopyHashSet<ClassFilter> nestedClassFilters;
final FastCopyHashSet<PathFilter> nestedResourceFilters;
+ if (filterStack.contains(importFilter)) {
+ nestedFilters = filterStack;
+ } else {
+ nestedFilters = filterStack.clone();
+ nestedFilters.add(importFilter);
+ }
final ClassFilter classImportFilter = dependency.getClassImportFilter();
if (classImportFilter == ClassFilters.acceptAll() || classFilterStack.contains(classImportFilter)) {
nestedClassFilters = classFilterStack;
@@ -874,18 +880,17 @@ long addPaths(Dependency[] dependencies, Map<String, List<LocalLoader>> map, Fas
nestedResourceFilters = resourceFilterStack.clone();
if (resourceImportFilter != PathFilters.acceptAll()) nestedResourceFilters.add(resourceImportFilter);
}
- subtract += module.addExportedPaths(module.getDependencies(), map, filterStack, nestedClassFilters, nestedResourceFilters, visited);
- filterStack.remove(importFilter);
+ subtract += module.addExportedPaths(module.getDependencies(), map, nestedFilters, nestedClassFilters, nestedResourceFilters, visited);
} else if (dependency instanceof ModuleClassLoaderDependency) {
final ModuleClassLoaderDependency classLoaderDependency = (ModuleClassLoaderDependency) dependency;
LocalLoader localLoader = classLoaderDependency.getLocalLoader();
for (Object filter : classFilterStack.getRawArray()) {
- if (filter != null) {
+ if (filter != null && filter != ClassFilters.acceptAll()) {
localLoader = LocalLoaders.createClassFilteredLocalLoader((ClassFilter) filter, localLoader);
}
}
for (Object filter : resourceFilterStack.getRawArray()) {
- if (filter != null) {
+ if (filter != null && filter != PathFilters.acceptAll()) {
localLoader = LocalLoaders.createPathFilteredLocalLoader((PathFilter) filter, localLoader);
}
}
@@ -914,12 +919,12 @@ long addPaths(Dependency[] dependencies, Map<String, List<LocalLoader>> map, Fas
final LocalDependency localDependency = (LocalDependency) dependency;
LocalLoader localLoader = localDependency.getLocalLoader();
for (Object filter : classFilterStack.getRawArray()) {
- if (filter != null) {
+ if (filter != null && filter != ClassFilters.acceptAll()) {
localLoader = LocalLoaders.createClassFilteredLocalLoader((ClassFilter) filter, localLoader);
}
}
for (Object filter : resourceFilterStack.getRawArray()) {
- if (filter != null) {
+ if (filter != null && filter != PathFilters.acceptAll()) {
localLoader = LocalLoaders.createPathFilteredLocalLoader((PathFilter) filter, localLoader);
}
}
@@ -1021,15 +1026,32 @@ long addExportedPaths(Dependency[] dependencies, Map<String, List<LocalLoader>>
final ModuleClassLoaderDependency classLoaderDependency = (ModuleClassLoaderDependency) dependency;
LocalLoader localLoader = classLoaderDependency.getLocalLoader();
for (Object filter : classFilterStack.getRawArray()) {
- if (filter != null) {
+ if (filter != null && filter != ClassFilters.acceptAll()) {
localLoader = LocalLoaders.createClassFilteredLocalLoader((ClassFilter) filter, localLoader);
}
}
for (Object filter : resourceFilterStack.getRawArray()) {
- if (filter != null) {
+ if (filter != null && filter != PathFilters.acceptAll()) {
localLoader = LocalLoaders.createPathFilteredLocalLoader((PathFilter) filter, localLoader);
}
}
+ ClassFilter classImportFilter = classLoaderDependency.getClassImportFilter();
+ if (classImportFilter != ClassFilters.acceptAll()) {
+ localLoader = LocalLoaders.createClassFilteredLocalLoader(classImportFilter, localLoader);
+ }
+ ClassFilter classExportFilter = classLoaderDependency.getClassExportFilter();
+ if (classExportFilter != ClassFilters.acceptAll()) {
+ localLoader = LocalLoaders.createClassFilteredLocalLoader(classExportFilter, localLoader);
+ }
+ PathFilter resourceImportFilter = classLoaderDependency.getResourceImportFilter();
+ if (resourceImportFilter != PathFilters.acceptAll()) {
+ localLoader = LocalLoaders.createPathFilteredLocalLoader(resourceImportFilter, localLoader);
+ }
+ PathFilter resourceExportFilter = classLoaderDependency.getResourceExportFilter();
+ if (resourceExportFilter != PathFilters.acceptAll()) {
+ localLoader = LocalLoaders.createPathFilteredLocalLoader(resourceExportFilter, localLoader);
+ }
+ final PathFilter importFilter = classLoaderDependency.getImportFilter();
final Set<String> paths = classLoaderDependency.getPaths();
for (String path : paths) {
boolean accept = true;
@@ -1038,7 +1060,7 @@ long addExportedPaths(Dependency[] dependencies, Map<String, List<LocalLoader>>
accept = false; break;
}
}
- if (accept && classLoaderDependency.getImportFilter().accept(path) && classLoaderDependency.getExportFilter().accept(path)) {
+ if (accept && importFilter.accept(path) && exportFilter.accept(path)) {
List<LocalLoader> list = map.get(path);
if (list == null) {
map.put(path, list = new ArrayList<LocalLoader>(1));
@@ -1052,12 +1074,12 @@ long addExportedPaths(Dependency[] dependencies, Map<String, List<LocalLoader>>
final LocalDependency localDependency = (LocalDependency) dependency;
LocalLoader localLoader = localDependency.getLocalLoader();
for (Object filter : classFilterStack.getRawArray()) {
- if (filter != null) {
+ if (filter != null && filter != ClassFilters.acceptAll()) {
localLoader = LocalLoaders.createClassFilteredLocalLoader((ClassFilter) filter, localLoader);
}
}
for (Object filter : resourceFilterStack.getRawArray()) {
- if (filter != null) {
+ if (filter != null && filter != PathFilters.acceptAll()) {
localLoader = LocalLoaders.createPathFilteredLocalLoader((PathFilter) filter, localLoader);
}
}
View
9 src/main/java/org/jboss/modules/filter/ClassFilters.java
@@ -50,4 +50,13 @@ public static ClassFilter rejectAll() {
return BooleanClassFilter.FALSE;
}
+ /**
+ * Get a class filter which uses a resource path filter to filter classes.
+ *
+ * @param resourcePathFilter the resource path filter
+ * @return the class filter
+ */
+ public static ClassFilter fromResourcePathFilter(final PathFilter resourcePathFilter) {
+ return resourcePathFilter == PathFilters.acceptAll() ? acceptAll() : new PathClassFilter(resourcePathFilter);
+ }
}
View
39 src/main/java/org/jboss/modules/filter/PathClassFilter.java
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.modules.filter;
+
+/**
+* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
+*/
+class PathClassFilter implements ClassFilter {
+
+ private final PathFilter resourcePathFilter;
+
+ public PathClassFilter(final PathFilter resourcePathFilter) {
+ this.resourcePathFilter = resourcePathFilter;
+ }
+
+ public boolean accept(final String className) {
+ return resourcePathFilter.accept(className.replace('.', '/').concat(".class"));
+ }
+}
View
30 src/test/java/org/jboss/modules/ClassFilteringTest.java
@@ -1,8 +1,8 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
@@ -22,6 +22,7 @@
package org.jboss.modules;
import org.jboss.modules.filter.ClassFilter;
+import org.jboss.modules.filter.ClassFilters;
import org.jboss.modules.filter.PathFilter;
import org.jboss.modules.filter.PathFilters;
import org.jboss.modules.test.BarImpl;
@@ -53,10 +54,10 @@ public void testClassFilter() throws Exception {
// Export-Package: com.acme.foo; include:="Qux*,BarImpl";exclude:=QuxImpl
- String packagePath = QuxBar.class.getPackage().getName();
- PathFilter inA = PathFilters.match(packagePath + ".Qux*");
- PathFilter inB = PathFilters.match(packagePath + ".BarImpl");
- PathFilter exA = PathFilters.match(packagePath + ".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
@@ -66,16 +67,9 @@ public void testClassFilter() throws Exception {
PathFilter ex = PathFilters.not(PathFilters.any(exA));
final PathFilter filter = PathFilters.all(in, ex);
- ClassFilter classImportFilter = new ClassFilter() {
- public boolean accept(String className) {
- return true;
- }
- };
- ClassFilter classExportFilter = new ClassFilter() {
- public boolean accept(String className) {
- return filter.accept(className);
- }
- };
+ ClassFilter classImportFilter = ClassFilters.acceptAll();
+ ClassFilter classExportFilter = ClassFilters.fromResourcePathFilter(filter);
+
specBuilderA.addResourceRoot(createResourceLoaderSpec(getTestResourceLoader()));
PathFilter importFilter = PathFilters.acceptAll();
PathFilter exportFilter = PathFilters.acceptAll();
View
8 src/test/java/org/jboss/modules/util/ModulesTestBase.java
@@ -1,8 +1,8 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
Please sign in to comment.
Something went wrong with that request. Please try again.