return 0L;
}
long subtract = 0L;
moduleLoader.incScanCount();
for (Dependency dependency : dependencies) {
final PathFilter exportFilter = dependency.getExportFilter();
// skip non-exported dependencies altogether
if (exportFilter != PathFilters.rejectAll()) {
if (dependency instanceof ModuleDependency) {
final ModuleDependency moduleDependency = (ModuleDependency) dependency;
final ModuleLoader moduleLoader = moduleDependency.getModuleLoader();
final ModuleIdentifier id = moduleDependency.getIdentifier();
final Module module;
try {
long pauseStart = Metrics.getCurrentCPUTime();
try {
module = moduleLoader.preloadModule(id);
} finally {
subtract += Metrics.getCurrentCPUTime() - pauseStart;
}
} catch (ModuleLoadException ex) {
if (moduleDependency.isOptional()) {
continue;
} else {
log.trace("Module %s, dependency %s preload failed: %s", getIdentifier(), moduleDependency.getIdentifier(), ex);
throw ex;
}
}
if (module == null) {
if (!moduleDependency.isOptional()) {
throw new ModuleNotFoundException(id.toString());
}
continue;
}
final PathFilter importFilter = dependency.getImportFilter();
final FastCopyHashSet<PathFilter> nestedFilters;
final FastCopyHashSet<ClassFilter> nestedClassFilters;
final FastCopyHashSet<PathFilter> nestedResourceFilters;
if (filterStack.contains(importFilter) && filterStack.contains(exportFilter)) {
nestedFilters = filterStack;
} else {
nestedFilters = filterStack.clone();
nestedFilters.add(importFilter);
nestedFilters.add(exportFilter);
}
final ClassFilter classImportFilter = dependency.getClassImportFilter();
final ClassFilter classExportFilter = dependency.getClassExportFilter();
if ((classImportFilter == ClassFilters.acceptAll() || classFilterStack.contains(classImportFilter)) && (classExportFilter == ClassFilters.acceptAll() || classFilterStack.contains(classExportFilter))) {
nestedClassFilters = classFilterStack;
} else {
nestedClassFilters = classFilterStack.clone();
if (classImportFilter != ClassFilters.acceptAll()) nestedClassFilters.add(classImportFilter);
if (classExportFilter != ClassFilters.acceptAll()) nestedClassFilters.add(classExportFilter);
}
final PathFilter resourceImportFilter = dependency.getResourceImportFilter();
final PathFilter resourceExportFilter = dependency.getResourceExportFilter();
if ((resourceImportFilter == PathFilters.acceptAll() || resourceFilterStack.contains(resourceImportFilter)) && (resourceExportFilter == PathFilters.acceptAll() || resourceFilterStack.contains(resourceExportFilter))) {
nestedResourceFilters = resourceFilterStack;
} else {
nestedResourceFilters = resourceFilterStack.clone();
if (resourceImportFilter != PathFilters.acceptAll()) nestedResourceFilters.add(resourceImportFilter);
if (resourceExportFilter != PathFilters.acceptAll()) nestedResourceFilters.add(resourceExportFilter);
}
subtract += module.addExportedPaths(module.getDependenciesInternal(), 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 && filter != ClassFilters.acceptAll()) {
localLoader = createClassFilteredLocalLoader((ClassFilter) filter, localLoader);
}
}
for (Object filter : resourceFilterStack.getRawArray()) {
if (filter != null && filter != PathFilters.acceptAll()) {
localLoader = createPathFilteredLocalLoader((PathFilter) filter, localLoader);
}
}
ClassFilter classImportFilter = classLoaderDependency.getClassImportFilter();
if (classImportFilter != ClassFilters.acceptAll()) {
localLoader = createClassFilteredLocalLoader(classImportFilter, localLoader);
}
ClassFilter classExportFilter = classLoaderDependency.getClassExportFilter();
if (classExportFilter != ClassFilters.acceptAll()) {
localLoader = createClassFilteredLocalLoader(classExportFilter, localLoader);
}
PathFilter resourceImportFilter = classLoaderDependency.getResourceImportFilter();
if (resourceImportFilter != PathFilters.acceptAll()) {
localLoader = createPathFilteredLocalLoader(resourceImportFilter, localLoader);
}
PathFilter resourceExportFilter = classLoaderDependency.getResourceExportFilter();
if (resourceExportFilter != PathFilters.acceptAll()) {
localLoader = createPathFilteredLocalLoader(resourceExportFilter, localLoader);
}
final PathFilter importFilter = classLoaderDependency.getImportFilter();
final Set<String> paths = classLoaderDependency.getPaths();
for (String path : paths) {
boolean accept = ! "_private".equals(path);
if (accept) for (Object filter : filterStack.getRawArray()) {
if (filter != null && ! ((PathFilter)filter).accept(path)) {
accept = false; break;
}
}
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));
list.add(localLoader);
} else if (! list.contains(localLoader)) {
list.add(localLoader);
}
}
}
} else if (dependency instanceof LocalDependency) {
final LocalDependency localDependency = (LocalDependency) dependency;
LocalLoader localLoader = localDependency.getLocalLoader();
for (Object filter : classFilterStack.getRawArray()) {
if (filter != null && filter != ClassFilters.acceptAll()) {
localLoader = createClassFilteredLocalLoader((ClassFilter) filter, localLoader);
}
}
for (Object filter : resourceFilterStack.getRawArray()) {
if (filter != null && filter != PathFilters.acceptAll()) {
localLoader = createPathFilteredLocalLoader((PathFilter) filter, localLoader);
}
}
ClassFilter classFilter = localDependency.getClassExportFilter();
if (classFilter != ClassFilters.acceptAll()) {
localLoader = createClassFilteredLocalLoader(classFilter, localLoader);
}
classFilter = localDependency.getClassImportFilter();
if (classFilter != ClassFilters.acceptAll()) {
localLoader = createClassFilteredLocalLoader(classFilter, localLoader);
}
PathFilter resourceFilter = localDependency.getResourceExportFilter();
if (resourceFilter != PathFilters.acceptAll()) {
localLoader = createPathFilteredLocalLoader(resourceFilter, localLoader);
}
resourceFilter = localDependency.getResourceImportFilter();
if (resourceFilter != PathFilters.acceptAll()) {