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


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

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

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

   * @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 Collections.emptySet();
        }
        // up to the archive root
        virtualFile = virtualFile.getParent().getParent();

        Indexer indexer = new Indexer();
        List<VirtualFile> classChildren;
        try {
            classChildren = virtualFile.getChildren(new SuffixMatchFilter(".class",
                VisitorAttributes.RECURSE_LEAVES_ONLY));
        } catch (IOException e) {
            LOG.warn(WARNING_MESSAGE_LOAD_CLASSES, e);
            return Collections.emptySet();
        }
        for (VirtualFile classFile : classChildren) {
            InputStream inputStream = null;
            try {
                inputStream = classFile.openStream();
                indexer.index(inputStream);
            } catch (IOException e) {
                LOG.warn(WARNING_MESSAGE_LOAD_CLASSES, e);
                return Collections.emptySet();
            } finally {
                VFSUtils.safeClose(inputStream);
            }
        }

        Index index = indexer.complete();
        Collection<ClassInfo> knownClasses = index.getKnownClasses();

        Set<String> domainPackagesNames = new HashSet<String>();
        for (ClassInfo knownClass : knownClasses) {
            if (AccessFlag.isPublic((knownClass.flags()))) {
View Full Code Here

    @Test
    public void testProcessConnector() throws Throwable {
        try {
            URI uri = getURI("/ra16inoutanno.rar");
            final VirtualFile virtualFile = VFS.getChild(uri);
            final Indexer indexer = new Indexer();
            final List<VirtualFile> classChildren = virtualFile.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);
                }
            }
            final Index index = indexer.complete();
            AnnotationRepository ar = new JandexAnnotationRepositoryImpl(index, Thread.currentThread().getContextClassLoader());

            annotations.process(ar, null, Thread.currentThread().getContextClassLoader());
        } catch (Throwable t) {
            t.printStackTrace();
View Full Code Here

    @Test
    public void testProcessConnectorFail() throws Throwable {
        try {
            URI uri = getURI("/rafail2connector.rar");
            final VirtualFile virtualFile = VFS.getChild(uri);
            final Indexer indexer = new Indexer();
            final List<VirtualFile> classChildren = virtualFile.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);
                }
            }
            final Index index = indexer.complete();
            AnnotationRepository ar = new JandexAnnotationRepositoryImpl(index, Thread.currentThread().getContextClassLoader());

            annotations.process(ar, null, Thread.currentThread().getContextClassLoader());

            fail("Success");
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.