} else { Indexer indexer = new Indexer(); consumer = (name, classFile) -> { try (InputStream in = classFile.openStream()) {
private static IndexView createJarIndex(File indexFile, File jarFile) { try { return JarIndexer.createJarIndex(jarFile, new Indexer(), indexFile, false, false, false, System.out, System.err).getIndex(); } catch (Exception e) { log.error("Failed to index '" + jarFile + "'", e); return null; } }
/** * Creates an annotation index for the given entity type */ public synchronized static Index createIndex(Class<?> type) { Index index = indices.get(type); if (index == null) { try { Indexer indexer = new Indexer(); Class<?> currentType = type; while ( currentType != null ) { String className = currentType.getName().replace(".", "/") + ".class"; InputStream stream = type.getClassLoader() .getResourceAsStream(className); indexer.index(stream); currentType = currentType.getSuperclass(); } index = indexer.complete(); indices.put(type, index); } catch (IOException e) { throw new RuntimeException("Failed to initialize Indexer", e); } } return index; }
/** * Creates an annotation index for the given entity type */ public synchronized static Index createIndex(Class<?> type) { Index index = indices.get(type); if (index == null) { try { Indexer indexer = new Indexer(); Class<?> currentType = type; while ( currentType != null ) { String className = currentType.getName().replace(".", "/") + ".class"; InputStream stream = type.getClassLoader() .getResourceAsStream(className); indexer.index(stream); currentType = currentType.getSuperclass(); } index = indexer.complete(); indices.put(type, index); } catch (IOException e) { throw new RuntimeException("Failed to initialize Indexer", e); } } return index; }
@Override public void execute() throws BuildException { if (!run) { return; } if (modify && newJar) { throw new BuildException("Specifying both modify and newJar does not make sense."); } Indexer indexer = new Indexer(); for(FileSet fileset : filesets) { String[] files = fileset.getDirectoryScanner(getProject()).getIncludedFiles(); for(String file : files) { if (file.endsWith(".jar")) { try { JarIndexer.createJarIndex(new File(fileset.getDir().getAbsolutePath() + "/" +file), indexer, modify, newJar,verbose); } catch (IOException e) { throw new BuildException(e); } } } } }
private static IndexView indexFolder(File folder) { Indexer indexer = new Indexer(); for (Iterator<File> itr = com.google.common.io.Files.fileTreeTraverser().breadthFirstTraversal(folder) .iterator(); itr.hasNext();) { File file = itr.next(); if (file.isFile() && file.getName().endsWith(".class")) { try { final InputStream stream = new FileInputStream(file); try { indexer.index(stream); } finally { try { stream.close(); } catch (Exception ignore) { } } } catch (Exception e) { log.error("Failed to index file " + file, e); } } } return indexer.complete(); }
Indexer indexer = new Indexer(); for ( Class<?> clazz : classes ) { InputStream stream = classLoaderService.locateResourceStream(
Indexer indexer = new Indexer(); for ( Class<?> clazz : classes ) { InputStream stream = classLoaderService.locateResourceStream(
private void resolveRuntimeIndex(Module module, List<Index> indexes) throws ModuleLoadException { Indexer indexer = new Indexer(); Iterator<Resource> resources = module.iterateResources(PathFilters.acceptAll()); while (resources.hasNext()) { Resource each = resources.next(); if (each.getName().endsWith(".class")) { try { ClassInfo clsInfo = indexer.index(each.openStream()); } catch (IOException e) { //System.err.println("error: " + each.getName() + ": " + e.getMessage()); } } } indexes.add(indexer.complete()); }
private Index getIndex(long start) throws IOException { Indexer indexer = new Indexer(); Result result = (source.isDirectory()) ? indexDirectory(source, indexer) : JarIndexer.createJarIndex(source, indexer, outputFile, modify, jarFile, verbose); double time = (System.currentTimeMillis() - start) / 1000.00; System.out.printf("Wrote %s in %.4f seconds (%d classes, %d annotations, %d instances, %d bytes)\n", result.getName(), time, result.getClasses(), result.getAnnotations(), result.getInstances(), result.getBytes()); return result.getIndex(); }
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(); }
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(); }
String[] locations = classpath.split(System.getProperty("path.separator")); Indexer indexer = new Indexer();
protected List<Class<? extends ServerConfiguration>> findServerConfigurationImpls(Module module) throws ModuleLoadException, IOException, NoSuchFieldException, IllegalAccessException { Indexer indexer = new Indexer(); Iterator<Resource> resources = module.iterateResources(PathFilters.acceptAll()); while (resources.hasNext()) { Resource each = resources.next(); if (each.getName().endsWith(".class")) { try { ClassInfo clsInfo = indexer.index(each.openStream()); } catch (IOException e) { //System.err.println("error: " + each.getName() + ": " + e.getMessage()); } } } Index index = indexer.complete(); Set<ClassInfo> infos = index.getAllKnownImplementors(DotName.createSimple(ServerConfiguration.class.getName())); List<Class<? extends ServerConfiguration>> impls = new ArrayList<>(); for (ClassInfo info : infos) { try { Class<? extends ServerConfiguration> cls = (Class<? extends ServerConfiguration>) module.getClassLoader().loadClass(info.name().toString()); if (!Modifier.isAbstract(cls.getModifiers())) { impls.add(cls); } } catch (ClassNotFoundException e) { e.printStackTrace(); } } return impls; //List<AnnotationInstance> found = index.getAnnotations(DotName.createSimple(Configuration.class.getName())); //return found; }
@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 ); } } if ( !mappings.isEmpty() ) { index = parseAndUpdateIndex( mappings, index ); } if ( index.getAnnotations( PseudoJpaDotNames.DEFAULT_DELIMITED_IDENTIFIERS ) != null ) { // todo : this needs to move to AnnotationBindingContext // what happens right now is that specifying this in an orm.xml causes it to effect all orm.xmls metadata.setGloballyQuotedIdentifiers( true ); } bindingContext = new AnnotationBindingContextImpl( metadata, index ); }
@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 ); } } if ( !mappings.isEmpty() ) { index = parseAndUpdateIndex( mappings, index ); } if ( index.getAnnotations( PseudoJpaDotNames.DEFAULT_DELIMITED_IDENTIFIERS ) != null ) { // todo : this needs to move to AnnotationBindingContext // what happens right now is that specifying this in an orm.xml causes it to effect all orm.xmls metadata.setGloballyQuotedIdentifiers( true ); } bindingContext = new AnnotationBindingContextImpl( metadata, index ); }
private void initializeConfigFiltersFatJar() throws ModuleLoadException, IOException, ClassNotFoundException { Indexer indexer = new Indexer(); Module appModule = Module.getBootModuleLoader().loadModule(APPLICATION_MODULE_NAME); Iterator<Resource> iter = appModule.iterateResources(PathFilters.acceptAll()); while (iter.hasNext()) { Resource each = iter.next(); if (each.getName().endsWith(".class")) { if (!each.getName().equals("module-info.class")) { try (InputStream is = each.openStream()) { indexer.index(is); } catch (IOException e) { // ignore } } } } Index index = indexer.complete(); Set<ClassInfo> impls = index.getAllKnownImplementors(DotName.createSimple(ConfigurationFilter.class.getName())); for (ClassInfo each : impls) { String name = each.name().toString(); Class<? extends ConfigurationFilter> cls = (Class<? extends ConfigurationFilter>) appModule.getClassLoader().loadClass(name); try { ConfigurationFilter filter = cls.newInstance(); this.configView.withFilter(filter); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } } }
private void initializeConfigFiltersFatJar() throws ModuleLoadException, IOException, ClassNotFoundException { Indexer indexer = new Indexer(); Module appModule = Module.getBootModuleLoader().loadModule(APPLICATION_MODULE_NAME); Iterator<Resource> iter = appModule.iterateResources(PathFilters.acceptAll()); while (iter.hasNext()) { Resource each = iter.next(); if (each.getName().endsWith(".class")) { if (!each.getName().equals("module-info.class")) { try (InputStream is = each.openStream()) { indexer.index(is); } catch (IOException e) { // ignore } } } } Index index = indexer.complete(); Set<ClassInfo> impls = index.getAllKnownImplementors(DotName.createSimple(ConfigurationFilter.class.getName())); for (ClassInfo each : impls) { String name = each.name().toString(); Class<? extends ConfigurationFilter> cls = (Class<? extends ConfigurationFilter>) appModule.getClassLoader().loadClass(name); try { ConfigurationFilter filter = cls.newInstance(); this.configView.withFilter(filter); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } } }
private void initializeConfigFiltersFatJar() throws ModuleLoadException, IOException, ClassNotFoundException { Indexer indexer = new Indexer(); Module appModule = Module.getBootModuleLoader().loadModule(APPLICATION_MODULE_NAME); Iterator<Resource> iter = appModule.iterateResources(PathFilters.acceptAll()); while (iter.hasNext()) { Resource each = iter.next(); if (each.getName().endsWith(".class")) { if (!each.getName().equals("module-info.class")) { try (InputStream is = each.openStream()) { indexer.index(is); } catch (IOException e) { // ignore } } } } Index index = indexer.complete(); Set<ClassInfo> impls = index.getAllKnownImplementors(DotName.createSimple(ConfigurationFilter.class.getName())); for (ClassInfo each : impls) { String name = each.name().toString(); Class<? extends ConfigurationFilter> cls = (Class<? extends ConfigurationFilter>) appModule.getClassLoader().loadClass(name); try { ConfigurationFilter filter = cls.newInstance(); this.configView.withFilter(filter); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } } }
final Indexer indexer = new Indexer(); try { final List<VirtualFile> classChildren = virtualFile.getChildren(new SuffixMatchFilter(".class", VisitorAttributes.RECURSE_LEAVES_ONLY));