Package org.jboss.jandex

Examples of org.jboss.jandex.Indexer


   * @param classes the classes to index
   *
   * @return an annotation repository w/ all the annotation discovered in the specified classes
   */
  public static Index indexForClass(ClassLoaderService classLoaderService, Class<?>... classes) {
    Indexer indexer = new Indexer();
    for ( Class<?> clazz : classes ) {
      InputStream stream = classLoaderService.locateResourceStream(
          clazz.getName().replace( '.', '/' ) + ".class"
      );
      try {
        indexer.index( stream );
      }
      catch ( IOException e ) {
        StringBuilder builder = new StringBuilder();
        builder.append( "[" );
        int count = 0;
        for ( Class<?> c : classes ) {
          builder.append( c.getName() );
          if ( count < classes.length - 1 ) {
            builder.append( "," );
          }
          count++;
        }
        builder.append( "]" );
        throw new HibernateException( "Unable to create annotation index for " + builder.toString() );
      }
    }
    return indexer.complete();
  }
View Full Code Here


    }
    return jandexIndex;
  }

  private IndexView buildJandexIndex(DeploymentResources deploymentResources) {
    Indexer indexer = new Indexer();

    for ( ClassDescriptor classDescriptor : deploymentResources.getClassDescriptors() ) {
      indexStream( indexer, classDescriptor.getStreamAccess() );
    }

    for ( PackageDescriptor packageDescriptor : deploymentResources.getPackageDescriptors() ) {
      indexStream( indexer, packageDescriptor.getStreamAccess() );
    }

    // for now we just skip entities defined in (1) orm.xml files and (2) hbm.xml files.  this part really needs
    // metamodel branch...

    // for now, we also need to wrap this in a CompositeIndex until Jandex is updated to use a common interface
    // between the 2...
    return indexer.complete();
  }
View Full Code Here

        } else {
            indexIgnorePaths = null;
        }

        final VirtualFile virtualFile = resourceRoot.getRoot();
        final Indexer indexer = new Indexer();
        try {
            final VisitorAttributes visitorAttributes = new VisitorAttributes();
            visitorAttributes.setLeavesOnly(true);
            visitorAttributes.setRecurseFilter(new VirtualFileFilter() {
                public boolean accepts(VirtualFile file) {
                    return indexIgnorePaths == null || !indexIgnorePaths.contains(file.getPathNameRelativeTo(virtualFile));
                }
            });

            final List<VirtualFile> classChildren = virtualFile.getChildren(new SuffixMatchFilter(".class", visitorAttributes));
            for (VirtualFile classFile : classChildren) {
                InputStream inputStream = null;
                try {
                    inputStream = classFile.openStream();
                    indexer.index(inputStream);
                } catch (Exception e) {
                    ServerLogger.DEPLOYMENT_LOGGER.cannotIndexClass(classFile.getPathNameRelativeTo(virtualFile), virtualFile.getPathName(), e);
                } finally {
                    VFSUtils.safeClose(inputStream);
                }
            }
            final Index index = indexer.complete();
            resourceRoot.putAttachment(Attachments.ANNOTATION_INDEX, index);
            ServerLogger.DEPLOYMENT_LOGGER.tracef("Generated index for archive %s", virtualFile);
        } catch (Throwable t) {
            throw ServerMessages.MESSAGES.deploymentIndexingFailed(t);
        }
View Full Code Here

            } else {
                indexIgnorePaths = null;
            }

            final VirtualFile virtualFile = resourceRoot.getRoot();
            final Indexer indexer = new Indexer();
            try {
                final VisitorAttributes visitorAttributes = new VisitorAttributes();
                visitorAttributes.setLeavesOnly(true);
                visitorAttributes.setRecurseFilter(new VirtualFileFilter() {
                    public boolean accepts(VirtualFile file) {
                        return indexIgnorePaths == null || !indexIgnorePaths.contains(file.getPathNameRelativeTo(virtualFile));
                    }
                });

                final List<VirtualFile> classChildren = virtualFile.getChildren(new SuffixMatchFilter(".class", visitorAttributes));
                for (VirtualFile classFile : classChildren) {
                    InputStream inputStream = null;
                    try {
                        inputStream = classFile.openStream();
                        indexer.index(inputStream);
                    } finally {
                        VFSUtils.safeClose(inputStream);
                    }
                }
                final Index index = indexer.complete();
                resourceRoot.putAttachment(Attachments.ANNOTATION_INDEX, index);
            } catch (Throwable t) {
                throw new DeploymentUnitProcessingException("Failed to index deployment root for annotations", t);
            }
        }
View Full Code Here

  @Override
  @SuppressWarnings( {"unchecked"})
  public void prepare(MetadataSources sources) {
    // create a jandex index from the annotated classes
    Indexer indexer = new Indexer();
    for ( Class<?> clazz : sources.getAnnotatedClasses() ) {
      indexClass( indexer, clazz.getName().replace( '.', '/' ) + ".class" );
    }

    // add package-info from the configured packages
    for ( String packageName : sources.getAnnotatedPackages() ) {
      indexClass( indexer, packageName.replace( '.', '/' ) + "/package-info.class" );
    }

    index = indexer.complete();

    List<JaxbRoot<XMLEntityMappings>> mappings = new ArrayList<JaxbRoot<XMLEntityMappings>>();
    for ( JaxbRoot<?> root : sources.getJaxbRootList() ) {
      if ( root.getRoot() instanceof XMLEntityMappings ) {
        mappings.add( (JaxbRoot<XMLEntityMappings>) root );
View Full Code Here

   * @param classes the classes to index
   *
   * @return an annotation repository w/ all the annotation discovered in the specified classes
   */
  public static Index indexForClass(ClassLoaderService classLoaderService, Class<?>... classes) {
    Indexer indexer = new Indexer();
    for ( Class<?> clazz : classes ) {
      InputStream stream = classLoaderService.locateResourceStream(
          clazz.getName().replace( '.', '/' ) + ".class"
      );
      try {
        indexer.index( stream );
      }
      catch ( IOException e ) {
        StringBuilder builder = new StringBuilder();
        builder.append( "[" );
        int count = 0;
        for ( Class<?> c : classes ) {
          builder.append( c.getName() );
          if ( count < classes.length - 1 ) {
            builder.append( "," );
          }
          count++;
        }
        builder.append( "]" );
        throw new HibernateException( "Unable to create annotation index for " + builder.toString() );
      }
    }
    return indexer.complete();
  }
View Full Code Here

    }
    return jandexIndex;
  }

  private IndexView buildJandexIndex(DeploymentResources deploymentResources) {
    Indexer indexer = new Indexer();

    for ( ClassDescriptor classDescriptor : deploymentResources.getClassDescriptors() ) {
      indexStream( indexer, classDescriptor.getStreamAccess() );
    }

    for ( PackageDescriptor packageDescriptor : deploymentResources.getPackageDescriptors() ) {
      indexStream( indexer, packageDescriptor.getStreamAccess() );
    }

    // for now we just skip entities defined in (1) orm.xml files and (2) hbm.xml files.  this part really needs
    // metamodel branch...

    // for now, we also need to wrap this in a CompositeIndex until Jandex is updated to use a common interface
    // between the 2...
    return indexer.complete();
  }
View Full Code Here

        } else {
            indexIgnorePaths = null;
        }

        final VirtualFile virtualFile = resourceRoot.getRoot();
        final Indexer indexer = new Indexer();
        try {
            final VisitorAttributes visitorAttributes = new VisitorAttributes();
            visitorAttributes.setLeavesOnly(true);
            visitorAttributes.setRecurseFilter(new VirtualFileFilter() {
                public boolean accepts(VirtualFile file) {
                    return indexIgnorePaths == null || !indexIgnorePaths.contains(file.getPathNameRelativeTo(virtualFile));
                }
            });

            final List<VirtualFile> classChildren = virtualFile.getChildren(new SuffixMatchFilter(".class", visitorAttributes));
            for (VirtualFile classFile : classChildren) {
                InputStream inputStream = null;
                try {
                    inputStream = classFile.openStream();
                    indexer.index(inputStream);
                } catch (Exception e) {
                    ServerLogger.DEPLOYMENT_LOGGER.cannotIndexClass(classFile.getPathNameRelativeTo(virtualFile), virtualFile.getPathName(), e);
                } finally {
                    VFSUtils.safeClose(inputStream);
                }
            }
            final Index index = indexer.complete();
            resourceRoot.putAttachment(Attachments.ANNOTATION_INDEX, index);
            ServerLogger.DEPLOYMENT_LOGGER.tracef("Generated index for archive %s", virtualFile);
        } catch (Throwable t) {
            throw new DeploymentUnitProcessingException("Failed to index deployment root for annotations", t);
        }
View Full Code Here

        final VirtualFile webInfLib = deploymentRoot.getChild(WarStructureDeploymentProcessor.WEB_INF_LIB);
        if(webInfLib.exists()) {
            try {
                final List<VirtualFile> archives = webInfLib.getChildren(WarStructureDeploymentProcessor.DEFAULT_WEB_INF_LIB_FILTER);
                for(final VirtualFile archive : archives) {
                    final Indexer indexer = new Indexer();
                    final List<VirtualFile> classChildren = archive.getChildren(new SuffixMatchFilter(".class", VisitorAttributes.RECURSE_LEAVES_ONLY));
                    for(VirtualFile classFile : classChildren) {
                        InputStream inputStream = null;
                        try {
                            inputStream = classFile.openStream();
                            indexer.index(inputStream);
                        } finally {
                            VFSUtils.safeClose(inputStream);
                        }
                    }
                    indexes.put(archive.getName(), indexer.complete());
                }
            } catch (Exception e) {
                throw new DeploymentUnitProcessingException("Failed to index deployment root for annotations");
            }
        }
View Full Code Here

     * @throws DeploymentUnitProcessingException
     */
    static Index createRoot(final VirtualFile deploymentRoot) throws DeploymentUnitProcessingException {
        final VirtualFile classes = deploymentRoot.getChild(WarStructureDeploymentProcessor.WEB_INF_CLASSES);
        if(classes.exists()) {
            final Indexer indexer = new Indexer();
            try {
                final List<VirtualFile> classChildren = classes.getChildren(new SuffixMatchFilter(".class", VisitorAttributes.RECURSE_LEAVES_ONLY));
                for(VirtualFile classFile : classChildren) {
                    InputStream inputStream = null;
                    try {
                        inputStream = classFile.openStream();
                        indexer.index(inputStream);
                    } finally {
                        VFSUtils.safeClose(inputStream);
                    }
                }
                return indexer.complete();
            } catch(Throwable t) {
                throw new DeploymentUnitProcessingException("Failed to index deployment root for annotations", t);
            }
        }
        return null;
View Full Code Here

TOP

Related Classes of org.jboss.jandex.Indexer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.