Package org.jboss.jandex

Examples of org.jboss.jandex.Indexer


  @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


    }
    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

     * @return
     * @deprecated Use a real implementation scanner
     */
    @Deprecated
    private static boolean containsEjbComponentClass(final VirtualFile file) {
        Indexer indexer = new Indexer();
        indexClasses(file, file, indexer);
        Index index = indexer.complete();
        for (Class<? extends Annotation> annotation : EJB_COMPONENT_ANNOTATIONS) {
            final DotName annotationName = DotName.createSimple(annotation.getName());
            final List<AnnotationInstance> classes = index.getAnnotations(annotationName);
            if (classes != null && !classes.isEmpty()) {
                return true;
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 index = indexer.complete();

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

    * {@inheritDoc}
    */
   @Override
   public AnnotationRepository scan(URL[] urls, ClassLoader cl)
   {
      Indexer indexer = new Indexer();

      if (urls != null && urls.length > 0)
      {
         for (URL url : urls)
         {
            String externalForm = url.toExternalForm();

            if (externalForm.endsWith(".class"))
            {
               InputStream is = null;
               try
               {
                  is = new FileInputStream(new File(url.toURI()));
                  indexer.index(is);
               }
               catch (Throwable t)
               {
                  log.error("Unable to process: " + externalForm, t);
               }
               finally
               {
                  if (is != null)
                  {
                     try
                     {
                        is.close();
                     }
                     catch (IOException ioe)
                     {
                        // Nothing
                     }
                  }
               }
            }
            else if (externalForm.endsWith(".jar"))
            {
               JarFile jarFile = null;
               try
               {
                  jarFile = new JarFile(new File(url.toURI()));
                  Enumeration<JarEntry> entries = jarFile.entries();
                  while (entries.hasMoreElements())
                  {
                     JarEntry jarEntry = entries.nextElement();
                     if (jarEntry.getName().endsWith(".class"))
                     {
                        InputStream is = null;
                        try
                        {
                           is = jarFile.getInputStream(jarEntry);
                           indexer.index(is);
                        }
                        catch (Throwable t)
                        {
                           log.error("Unable to process: " + jarEntry.getName(), t);
                        }
                        finally
                        {
                           if (is != null)
                           {
                              try
                              {
                                 is.close();
                              }
                              catch (IOException ioe)
                              {
                                 // Nothing
                              }
                           }
                        }
                     }
                  }
               }
               catch (Throwable t)
               {
                  log.error("Unable to process: " + externalForm, t);
               }
               finally
               {
                  if (jarFile != null)
                  {
                     try
                     {
                        jarFile.close();
                     }
                     catch (IOException ioe)
                     {
                        // Nothing
                     }
                  }
               }
            }
         }
      }

      return new AnnotationRepositoryImpl(indexer.complete(), cl);
   }
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

   * @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

  @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 index = indexer.complete();

    List<JaxbRoot<JaxbEntityMappings>> mappings = new ArrayList<JaxbRoot<JaxbEntityMappings>>();
    for ( JaxbRoot<?> root : sources.getJaxbRootList() ) {
      if ( root.getRoot() instanceof JaxbEntityMappings ) {
        mappings.add( (JaxbRoot<JaxbEntityMappings>) root );
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 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

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.