org.jboss.modules.filter.PathFilters Java Examples

The following examples show how to use org.jboss.modules.filter.PathFilters. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompositeIndexProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Index calculateModuleIndex(final Module module) throws ModuleLoadException, IOException {
    final Indexer indexer = new Indexer();
    final PathFilter filter = PathFilters.getDefaultImportFilter();
    final Iterator<Resource> iterator = module.iterateResources(filter);
    while (iterator.hasNext()) {
        Resource resource = iterator.next();
        if(resource.getName().endsWith(".class")) {
            try (InputStream in = resource.openStream()) {
                indexer.index(in);
            } catch (Exception e) {
                ServerLogger.DEPLOYMENT_LOGGER.cannotIndexClass(resource.getName(), resource.getURL().toExternalForm(), e);
            }
        }
    }
    return indexer.complete();
}
 
Example #2
Source File: AddonModuleLoader.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
private void addAddonDependency(Set<AddonView> views, AddonId found, Builder builder,
         AddonDependencyEntry dependency)
{
   AddonId addonId = stateManager.resolveAddonId(views, dependency.getName());
   ModuleIdentifier moduleId = null;
   if (addonId != null)
   {
      Addon addon = lifecycleManager.getAddon(views, addonId);
      moduleId = findCompatibleInstalledModule(addonId);
      if (moduleId != null)
      {
         builder.addDependency(DependencySpec.createModuleDependencySpec(
                  PathFilters.not(PathFilters.getMetaInfFilter()),
                  dependency.isExported() ? PathFilters.acceptAll() : PathFilters.rejectAll(),
                  this,
                  moduleCache.getModuleId(addon),
                  dependency.isOptional()));
      }
   }

   if (!dependency.isOptional() && (addonId == null || moduleId == null))
      throw new ContainerException("Dependency [" + dependency + "] could not be loaded for addon [" + found
               + "]");
}
 
Example #3
Source File: JBossDeploymentStructureParser10.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void parseSet(final XMLStreamReader reader, final boolean include, final List<FilterSpecification> filters)
        throws XMLStreamException {
    final Set<String> set = new HashSet<String>();
    // xsd:choice
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                filters.add(new FilterSpecification(PathFilters.in(set), include));
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                switch (Element.of(reader.getName())) {
                    case PATH:
                        parsePathName(reader, set);
                        break;
                }
            }
        }
    }
}
 
Example #4
Source File: AbstractModuleSpecProvider.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public ModuleSpec get(ModuleLoader loader, ModuleIdentifier id)
{
   if (getId().equals(id))
   {
      Builder builder = ModuleSpec.build(id);
      builder.addDependency(DependencySpec.createClassLoaderDependencySpec(PathFilters.acceptAll(),
               PathFilters.acceptAll(), AbstractModuleSpecProvider.class.getClassLoader(), getPaths()));
      builder.addDependency(DependencySpec.createClassLoaderDependencySpec(PathFilters.acceptAll(),
               PathFilters.acceptAll(), ClassLoader.getSystemClassLoader(), getPaths()));

      configure(loader, builder);

      return builder.create();
   }
   return null;
}
 
Example #5
Source File: ModuleSpecProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void addResourceRoot(final ModuleSpec.Builder specBuilder, final ResourceRoot resource, final List<PermissionFactory> permFactories)
        throws DeploymentUnitProcessingException {
    try {
        final VirtualFile root = resource.getRoot();
        if (resource.getExportFilters().isEmpty()) {
            specBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(new VFSResourceLoader(resource
                    .getRootName(), root, resource.isUsePhysicalCodeSource())));
        } else {
            final MultiplePathFilterBuilder filterBuilder = PathFilters.multiplePathFilterBuilder(true);
            for (final FilterSpecification filter : resource.getExportFilters()) {
                filterBuilder.addFilter(filter.getPathFilter(), filter.isInclude());
            }
            specBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(new VFSResourceLoader(resource
                    .getRootName(), root, resource.isUsePhysicalCodeSource()), filterBuilder.create()));
        }
        // start with the root
        permFactories.add(new ImmediatePermissionFactory(
                new VirtualFilePermission(root.getPathName(), VirtualFilePermission.FLAG_READ)));
        // also include all children, recursively
        permFactories.add(new ImmediatePermissionFactory(
                new VirtualFilePermission(root.getChild("-").getPathName(), VirtualFilePermission.FLAG_READ)));
    } catch (IOException e) {
        throw ServerLogger.ROOT_LOGGER.failedToCreateVFSResourceLoader(resource.getRootName(), e);
    }
}
 
Example #6
Source File: JBossDeploymentStructureParser12.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void parseSet(final XMLStreamReader reader, final boolean include, final List<FilterSpecification> filters)
        throws XMLStreamException {
    final Set<String> set = new HashSet<String>();
    // xsd:choice
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                filters.add(new FilterSpecification(PathFilters.in(set), include));
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                switch (Element.of(reader.getName())) {
                    case PATH:
                        parsePathName(reader, set);
                        break;
                }
            }
        }
    }
}
 
Example #7
Source File: JBossDeploymentStructureParser13.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void parseSet(final XMLStreamReader reader, final boolean include, final List<FilterSpecification> filters)
        throws XMLStreamException {
    final Set<String> set = new HashSet<String>();
    // xsd:choice
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                filters.add(new FilterSpecification(PathFilters.in(set), include));
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                switch (Element.of(reader.getName())) {
                    case PATH:
                        parsePathName(reader, set);
                        break;
                }
            }
        }
    }
}
 
Example #8
Source File: JBossDeploymentStructureParser11.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void parseSet(final XMLStreamReader reader, final boolean include, final List<FilterSpecification> filters)
        throws XMLStreamException {
    final Set<String> set = new HashSet<String>();
    // xsd:choice
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                filters.add(new FilterSpecification(PathFilters.in(set), include));
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                switch (Element.of(reader.getName())) {
                    case PATH:
                        parsePathName(reader, set);
                        break;
                }
            }
        }
    }
}
 
Example #9
Source File: JBossModuleUtils.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
/**
 * Build a PathFilter for a set of filter paths
 *
 * @param filterPaths the set of paths to filter on.
 *        Can be null to indicate that no filters should be applied (accept all),
 *        can be empty to indicate that everything should be filtered (reject all).
 * @param failedMatchValue the value the PathFilter returns when a path does not match.
 * @return a PathFilter.
 */
private static PathFilter buildFilters(Set<String> filterPaths, boolean failedMatchValue) {
    if (filterPaths == null)
        return PathFilters.acceptAll();
    else if (filterPaths.isEmpty()) {
        return PathFilters.rejectAll();
    } else {
        MultiplePathFilterBuilder builder = PathFilters.multiplePathFilterBuilder(failedMatchValue);
        for (String importPathGlob : filterPaths)
            builder.addFilter(PathFilters.match(importPathGlob), !failedMatchValue);
        return builder.create();
    }
}
 
Example #10
Source File: WildFlySwarmApplicationConf.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
void apply(ModuleSpec.Builder builder) {
    builder.addDependency(
            DependencySpec.createModuleDependencySpec(
                    PathFilters.acceptAll(),
                    PathFilters.acceptAll(),
                    PathFilters.acceptAll(),
                    PathFilters.acceptAll(),
                    ClassFilters.acceptAll(),
                    ClassFilters.acceptAll(),
                    null,
                    ModuleIdentifier.create(this.name, this.slot), false));
}
 
Example #11
Source File: JBossModuleUtils.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
/**
 * Populate a module spec builder with a dependencies on other modules.
 * @param moduleSpecBuilder builder to populate
 * @param moduleImportFilterPaths paths valid for importing into the module being built.
 *                                Can be null or empty to indicate that no filters should be applied.
 * @param dependencyExportFilterPaths export paths for the dependency being linked
 * @param dependentModuleIdentifier used to lookup the latest dependencies. see {@link JBossModuleLoader#getLatestRevisionIds()}
 */
public static void populateModuleSpecWithModuleDependency(ModuleSpec.Builder moduleSpecBuilder,
        @Nullable Set<String> moduleImportFilterPaths,
        @Nullable Set<String> dependencyExportFilterPaths,
        ModuleIdentifier dependentModuleIdentifier) {
    Objects.requireNonNull(moduleSpecBuilder, "moduleSpecBuilder");
    PathFilter moduleImportFilters = buildFilters(moduleImportFilterPaths, false);
    PathFilter dependencyExportFilters = buildFilters(dependencyExportFilterPaths, false);
    PathFilter importFilters = PathFilters.all(dependencyExportFilters, moduleImportFilters);
    moduleSpecBuilder.addDependency(DependencySpec.createModuleDependencySpec(importFilters, dependencyExportFilters, null, dependentModuleIdentifier, false));
}
 
Example #12
Source File: AddonModuleLoader.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
private void addLocalResources(AddonRepository repository, AddonId found, Builder builder, ModuleIdentifier id)
{
   List<File> resources = repository.getAddonResources(found);
   for (File file : resources)
   {
      try
      {
         if (file.isDirectory())
         {
            builder.addResourceRoot(
                     ResourceLoaderSpec.createResourceLoaderSpec(
                              ResourceLoaders.createFileResourceLoader(file.getName(), file),
                              PathFilters.acceptAll()));
         }
         else if (file.length() > 0)
         {
            JarFile jarFile = new JarFile(file);
            moduleJarFileCache.addJarFileReference(id, jarFile);
            builder.addResourceRoot(
                     ResourceLoaderSpec.createResourceLoaderSpec(
                              ResourceLoaders.createJarResourceLoader(file.getName(), jarFile),
                              PathFilters.acceptAll()));
         }
      }
      catch (IOException e)
      {
         throw new ContainerException("Could not load resources from [" + file.getAbsolutePath() + "]", e);
      }
   }
}
 
Example #13
Source File: FurnaceContainerSpec.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void configure(ModuleLoader loader, Builder builder)
{
   builder.addDependency(DependencySpec.createSystemDependencySpec(
            PathFilters.acceptAll(),
            PathFilters.all(
                     PathFilters.not(PathFilters.any(
                              PathFilters.is("org/jboss/forge/furnace/impl"),
                              PathFilters.isChildOf("org/jboss/forge/furnace/impl"))),

                     PathFilters.any(Arrays.asList(
                              PathFilters.is("org/jboss/forge/furnace/proxy/javassist"),
                              PathFilters.isChildOf("org/jboss/forge/furnace/proxy/javassist"),
                              PathFilters.is("META-INF/services"),
                              PathFilters.is("org/jboss/forge/furnace"),
                              PathFilters.is("org/jboss/forge/furnace/addons"),
                              PathFilters.is("org/jboss/forge/furnace/event"),
                              PathFilters.is("org/jboss/forge/furnace/exception"),
                              PathFilters.is("org/jboss/forge/furnace/lifecycle"),
                              PathFilters.is("org/jboss/forge/furnace/lock"),
                              PathFilters.is("org/jboss/forge/furnace/repositories"),
                              PathFilters.is("org/jboss/forge/furnace/services"),
                              PathFilters.is("org/jboss/forge/furnace/spi"),
                              PathFilters.is("org/jboss/forge/furnace/util"),
                              PathFilters.is("org/jboss/forge/furnace/versions"),
                              PathFilters.is("org/jboss/forge/furnace/proxy")
                     ))),
            getPaths()));
}
 
Example #14
Source File: JBossDeploymentStructureParser12.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parsePath(final XMLStreamReader reader, final boolean include, final List<FilterSpecification> filters)
        throws XMLStreamException {
    String path = null;
    final Set<Attribute> required = EnumSet.of(Attribute.PATH);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        required.remove(attribute);
        switch (attribute) {
            case PATH:
                path = reader.getAttributeValue(i);
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }

    final boolean literal = path.indexOf('*') == -1 && path.indexOf('?') == -1;
    if (literal) {
        if (path.charAt(path.length() - 1) == '/') {
            filters.add(new FilterSpecification(PathFilters.isChildOf(path), include));
        } else {
            filters.add(new FilterSpecification(PathFilters.is(path), include));
        }
    } else {
        filters.add(new FilterSpecification(PathFilters.match(path), include));
    }

    // consume remainder of element
    parseNoContent(reader);
}
 
Example #15
Source File: JBossDeploymentStructureParser12.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parsePath(final XMLStreamReader reader, final boolean include, final MultiplePathFilterBuilder builder) throws XMLStreamException {
    String path = null;
    final Set<Attribute> required = EnumSet.of(Attribute.PATH);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        required.remove(attribute);
        switch (attribute) {
            case PATH:
                path = reader.getAttributeValue(i);
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }

    final boolean literal = path.indexOf('*') == -1 && path.indexOf('?') == -1;
    if (literal) {
        if (path.charAt(path.length() - 1) == '/') {
            builder.addFilter(PathFilters.isChildOf(path), include);
        } else {
            builder.addFilter(PathFilters.is(path), include);
        }
    } else {
        builder.addFilter(PathFilters.match(path), include);
    }

    // consume remainder of element
    parseNoContent(reader);
}
 
Example #16
Source File: JBossDeploymentStructureParser11.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parsePath(final XMLStreamReader reader, final boolean include, final List<FilterSpecification> filters)
        throws XMLStreamException {
    String path = null;
    final Set<Attribute> required = EnumSet.of(Attribute.PATH);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        required.remove(attribute);
        switch (attribute) {
            case PATH:
                path = reader.getAttributeValue(i);
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }

    final boolean literal = path.indexOf('*') == -1 && path.indexOf('?') == -1;
    if (literal) {
        if (path.charAt(path.length() - 1) == '/') {
            filters.add(new FilterSpecification(PathFilters.isChildOf(path), include));
        } else {
            filters.add(new FilterSpecification(PathFilters.is(path), include));
        }
    } else {
        filters.add(new FilterSpecification(PathFilters.match(path), include));
    }

    // consume remainder of element
    parseNoContent(reader);
}
 
Example #17
Source File: JBossDeploymentStructureParser11.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parsePath(final XMLStreamReader reader, final boolean include, final MultiplePathFilterBuilder builder) throws XMLStreamException {
    String path = null;
    final Set<Attribute> required = EnumSet.of(Attribute.PATH);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        required.remove(attribute);
        switch (attribute) {
            case PATH:
                path = reader.getAttributeValue(i);
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }

    final boolean literal = path.indexOf('*') == -1 && path.indexOf('?') == -1;
    if (literal) {
        if (path.charAt(path.length() - 1) == '/') {
            builder.addFilter(PathFilters.isChildOf(path), include);
        } else {
            builder.addFilter(PathFilters.is(path), include);
        }
    } else {
        builder.addFilter(PathFilters.match(path), include);
    }

    // consume remainder of element
    parseNoContent(reader);
}
 
Example #18
Source File: JBossDeploymentStructureParser13.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parsePath(final XMLStreamReader reader, final boolean include, final List<FilterSpecification> filters)
        throws XMLStreamException {
    String path = null;
    final Set<Attribute> required = EnumSet.of(Attribute.PATH);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        required.remove(attribute);
        switch (attribute) {
            case PATH:
                path = reader.getAttributeValue(i);
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }

    final boolean literal = path.indexOf('*') == -1 && path.indexOf('?') == -1;
    if (literal) {
        if (path.charAt(path.length() - 1) == '/') {
            filters.add(new FilterSpecification(PathFilters.isChildOf(path), include));
        } else {
            filters.add(new FilterSpecification(PathFilters.is(path), include));
        }
    } else {
        filters.add(new FilterSpecification(PathFilters.match(path), include));
    }

    // consume remainder of element
    parseNoContent(reader);
}
 
Example #19
Source File: JBossDeploymentStructureParser13.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parsePath(final XMLStreamReader reader, final boolean include, final MultiplePathFilterBuilder builder) throws XMLStreamException {
    String path = null;
    final Set<Attribute> required = EnumSet.of(Attribute.PATH);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        required.remove(attribute);
        switch (attribute) {
            case PATH:
                path = reader.getAttributeValue(i);
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }

    final boolean literal = path.indexOf('*') == -1 && path.indexOf('?') == -1;
    if (literal) {
        if (path.charAt(path.length() - 1) == '/') {
            builder.addFilter(PathFilters.isChildOf(path), include);
        } else {
            builder.addFilter(PathFilters.is(path), include);
        }
    } else {
        builder.addFilter(PathFilters.match(path), include);
    }

    // consume remainder of element
    parseNoContent(reader);
}
 
Example #20
Source File: JBossDeploymentStructureParser10.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parsePath(final XMLStreamReader reader, final boolean include, final List<FilterSpecification> filters)
        throws XMLStreamException {
    String path = null;
    final Set<Attribute> required = EnumSet.of(Attribute.PATH);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        required.remove(attribute);
        switch (attribute) {
            case PATH:
                path = reader.getAttributeValue(i);
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }

    final boolean literal = path.indexOf('*') == -1 && path.indexOf('?') == -1;
    if (literal) {
        if (path.charAt(path.length() - 1) == '/') {
            filters.add(new FilterSpecification(PathFilters.isChildOf(path), include));
        } else {
            filters.add(new FilterSpecification(PathFilters.is(path), include));
        }
    } else {
        filters.add(new FilterSpecification(PathFilters.match(path), include));
    }

    // consume remainder of element
    parseNoContent(reader);
}
 
Example #21
Source File: JBossDeploymentStructureParser12.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void parseSystemDependency(final XMLStreamReader reader, final ModuleStructureSpec specBuilder) throws XMLStreamException {
    boolean export = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        switch (attribute) {
            case EXPORT:
                export = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    Set<String> paths = Collections.emptySet();
    final MultiplePathFilterBuilder exportBuilder = PathFilters.multiplePathFilterBuilder(export);
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case END_ELEMENT: {
                if (export) {
                    // If re-exported, add META-INF/** -> false at the end of the list (require explicit override)
                    exportBuilder.addFilter(PathFilters.getMetaInfSubdirectoriesFilter(), false);
                    exportBuilder.addFilter(PathFilters.getMetaInfFilter(), false);
                }
                final PathFilter exportFilter = exportBuilder.create();
                specBuilder.addSystemDependency(DependencySpec.createSystemDependencySpec(PathFilters.getDefaultImportFilter(), exportFilter, paths));
                return;
            }
            case START_ELEMENT: {
                switch (Element.of(reader.getName())) {
                    case PATHS: {
                        paths = parseSet(reader);
                        break;
                    }
                    case EXPORTS: {
                        parseFilterList(reader, exportBuilder);
                        break;
                    }
                    default: {
                        throw unexpectedContent(reader);
                    }
                }
            }
        }
    }
}
 
Example #22
Source File: JBossDeploymentStructureParser12.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void parseSet(final XMLStreamReader reader, final boolean include, final MultiplePathFilterBuilder builder) throws XMLStreamException {
    builder.addFilter(PathFilters.in(parseSet(reader)), include);
}
 
Example #23
Source File: JBossDeploymentStructureParser11.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void parseSet(final XMLStreamReader reader, final boolean include, final MultiplePathFilterBuilder builder) throws XMLStreamException {
    builder.addFilter(PathFilters.in(parseSet(reader)), include);
}
 
Example #24
Source File: JBossDeploymentStructureParser11.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void parseSystemDependency(final XMLStreamReader reader, final ModuleStructureSpec specBuilder) throws XMLStreamException {
    boolean export = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        switch (attribute) {
            case EXPORT:
                export = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    Set<String> paths = Collections.emptySet();
    final MultiplePathFilterBuilder exportBuilder = PathFilters.multiplePathFilterBuilder(export);
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case END_ELEMENT: {
                if (export) {
                    // If re-exported, add META-INF/** -> false at the end of the list (require explicit override)
                    exportBuilder.addFilter(PathFilters.getMetaInfSubdirectoriesFilter(), false);
                    exportBuilder.addFilter(PathFilters.getMetaInfFilter(), false);
                }
                final PathFilter exportFilter = exportBuilder.create();
                specBuilder.addSystemDependency(DependencySpec.createSystemDependencySpec(PathFilters.getDefaultImportFilter(), exportFilter, paths));
                return;
            }
            case START_ELEMENT: {
                switch (Element.of(reader.getName())) {
                    case PATHS: {
                        paths = parseSet(reader);
                        break;
                    }
                    case EXPORTS: {
                        parseFilterList(reader, exportBuilder);
                        break;
                    }
                    default: {
                        throw unexpectedContent(reader);
                    }
                }
            }
        }
    }
}
 
Example #25
Source File: JBossDeploymentStructureParser13.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void parseSet(final XMLStreamReader reader, final boolean include, final MultiplePathFilterBuilder builder) throws XMLStreamException {
    builder.addFilter(PathFilters.in(parseSet(reader)), include);
}
 
Example #26
Source File: JBossDeploymentStructureParser13.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void parseSystemDependency(final XMLStreamReader reader, final ModuleStructureSpec specBuilder) throws XMLStreamException {
    boolean export = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        switch (attribute) {
            case EXPORT:
                export = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    Set<String> paths = Collections.emptySet();
    final MultiplePathFilterBuilder exportBuilder = PathFilters.multiplePathFilterBuilder(export);
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case END_ELEMENT: {
                if (export) {
                    // If re-exported, add META-INF/** -> false at the end of the list (require explicit override)
                    exportBuilder.addFilter(PathFilters.getMetaInfSubdirectoriesFilter(), false);
                    exportBuilder.addFilter(PathFilters.getMetaInfFilter(), false);
                }
                final PathFilter exportFilter = exportBuilder.create();
                specBuilder.addSystemDependency(DependencySpec.createSystemDependencySpec(PathFilters.getDefaultImportFilter(), exportFilter, paths));
                return;
            }
            case START_ELEMENT: {
                switch (Element.of(reader.getName())) {
                    case PATHS: {
                        paths = parseSet(reader);
                        break;
                    }
                    case EXPORTS: {
                        parseFilterList(reader, exportBuilder);
                        break;
                    }
                    default: {
                        throw unexpectedContent(reader);
                    }
                }
            }
        }
    }
}
 
Example #27
Source File: JBossDeploymentStructureParser10.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void parseModuleDependency(final XMLStreamReader reader, final ModuleStructureSpec specBuilder,
                                          ModuleLoader moduleLoader) throws XMLStreamException {
    String name = null;
    String slot = null;
    boolean export = false;
    boolean optional = false;
    Disposition services = Disposition.NONE;
    final Set<Attribute> required = EnumSet.of(Attribute.NAME);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        required.remove(attribute);
        switch (attribute) {
            case NAME:
                name = reader.getAttributeValue(i);
                break;
            case SLOT:
                slot = reader.getAttributeValue(i);
                break;
            case EXPORT:
                export = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            case SERVICES:
                services = Disposition.of(reader.getAttributeValue(i));
                break;
            case OPTIONAL:
                optional = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            default:
                throw unexpectedContent(reader);
        }
    }
    if (!required.isEmpty()) {
        throw missingAttributes(reader.getLocation(), required);
    }
    ModuleDependency dependency = new ModuleDependency(moduleLoader, ModuleIdentifier.create(name, slot), optional, export,
            services == Disposition.IMPORT, true);
    specBuilder.addModuleDependency(dependency);
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                if (services == Disposition.EXPORT) {
                    // If services are to be re-exported, add META-INF/services -> true near the end of the list
                    dependency.addExportFilter(PathFilters.getMetaInfServicesFilter(), true);
                }
                if (export) {
                    // If re-exported, add META-INF/** -> false at the end of the list (require explicit override)
                    dependency.addExportFilter(PathFilters.getMetaInfSubdirectoriesFilter(), false);
                    dependency.addExportFilter(PathFilters.getMetaInfFilter(), false);
                }
                if (dependency.getImportFilters().isEmpty()) {
                    dependency.addImportFilter(services == Disposition.NONE ? PathFilters.getDefaultImportFilter()
                            : PathFilters.getDefaultImportFilterWithServices(), true);
                } else {
                    if (services != Disposition.NONE) {
                        dependency.addImportFilter(PathFilters.getMetaInfServicesFilter(), true);
                    }
                    dependency.addImportFilter(PathFilters.getMetaInfSubdirectoriesFilter(), false);
                    dependency.addImportFilter(PathFilters.getMetaInfFilter(), false);
                }
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                switch (Element.of(reader.getName())) {
                    case EXPORTS:
                        parseFilterList(reader, dependency.getExportFilters());
                        break;
                    case IMPORTS:
                        parseFilterList(reader, dependency.getImportFilters());
                        break;
                    default:
                        throw unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw unexpectedContent(reader);
            }
        }
    }
}
 
Example #28
Source File: ManifestDependencyProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Process the deployment root for module dependency information.
 *
 * @param phaseContext the deployment unit context
 * @throws org.jboss.as.server.deployment.DeploymentUnitProcessingException
 */
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ServiceModuleLoader deploymentModuleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
    final List<ResourceRoot> allResourceRoots = DeploymentUtils.allResourceRoots(deploymentUnit);
    DeploymentUnit top = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();

    final Set<ModuleIdentifier> additionalModules = new HashSet<>();
    final List<AdditionalModuleSpecification> additionalModuleList = top.getAttachmentList(Attachments.ADDITIONAL_MODULES);
    // Must synchronize on list as subdeployments executing Phase.STRUCTURE may be concurrently modifying it
    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (additionalModuleList) {
        for (AdditionalModuleSpecification i : additionalModuleList) {
            additionalModules.add(i.getModuleIdentifier());
        }
    }
    for (final ResourceRoot resourceRoot : allResourceRoots) {
        final Manifest manifest = resourceRoot.getAttachment(Attachments.MANIFEST);
        if (manifest == null)
            continue;

        final String dependencyString = ManifestHelper.getMainAttributeValue(manifest, DEPENDENCIES_ATTR);
        if (dependencyString == null)
            continue;

        if(deploymentUnit.getParent() == null &&
                SubDeploymentMarker.isSubDeployment(resourceRoot)) {
            //we do not want ears reading sub deployments manifests
            continue;
        }

        final String[] dependencyDefs = dependencyString.split(",");
        for (final String dependencyDef : dependencyDefs) {
            final String trimmed = dependencyDef.trim();
            if(trimmed.isEmpty()) {
                continue;
            }
            final String[] dependencyParts = trimmed.split(" ");

            final ModuleIdentifier dependencyId = ModuleIdentifier.fromString(dependencyParts[0]);
            final boolean export = containsParam(dependencyParts, EXPORT_PARAM);
            final boolean optional = containsParam(dependencyParts, OPTIONAL_PARAM);
            final boolean services = containsParam(dependencyParts, SERVICES_PARAM);
            final boolean annotations = containsParam(dependencyParts, ANNOTATIONS_PARAM);
            final boolean metaInf = containsParam(dependencyParts, META_INF);
            final ModuleLoader dependencyLoader;
            if (dependencyId.getName().startsWith(ServiceModuleLoader.MODULE_PREFIX)) {
                dependencyLoader = deploymentModuleLoader;
            } else {
                dependencyLoader = Module.getBootModuleLoader();
            }
            if(annotations) {
                deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES, dependencyId);
                if(dependencyLoader == deploymentModuleLoader && !additionalModules.contains(dependencyId)) {
                    //additional modules will not be created till much later, a dep on them would fail
                    phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, ServiceModuleLoader.moduleServiceName(dependencyId));
                }
            }

            final ModuleDependency dependency = new ModuleDependency(dependencyLoader, dependencyId, optional, export, services, true);
            if(metaInf) {
                dependency.addImportFilter(PathFilters.getMetaInfSubdirectoriesFilter(), true);
                dependency.addImportFilter(PathFilters.getMetaInfFilter(), true);
            }
            deploymentUnit.addToAttachmentList(Attachments.MANIFEST_DEPENDENCIES, dependency);
        }
    }

}
 
Example #29
Source File: VFSResourceLoader.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/** {@inheritDoc} */
public PathFilter getExportFilter() {
    return PathFilters.acceptAll();
}