org.jboss.jandex.IndexReader Java Examples
The following examples show how to use
org.jboss.jandex.IndexReader.
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: GenerateYamlSupport.java From camel-k-runtime with Apache License 2.0 | 6 votes |
protected static IndexView getCompositeIndexer(ClassLoader classLoader) { try { Enumeration<URL> elements = classLoader.getResources("META-INF/jandex.idx"); List<IndexView> allIndex = new ArrayList<>(); Set<URL> locations = new HashSet<>(); while (elements.hasMoreElements()) { URL url = elements.nextElement(); if (locations.add(url)) { try (InputStream is = url.openStream()) { allIndex.add(new IndexReader(is).read()); } } } return CompositeIndex.create(allIndex); } catch (Exception e) { throw new RuntimeException(e); } }
Example #2
Source File: ModuleIndexBuilder.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public static CompositeIndex buildCompositeIndex(Module module) { try { final Enumeration<URL> resources = module.getClassLoader().getResources(INDEX_LOCATION); if (!resources.hasMoreElements()) { return null; } final Set<Index> indexes = new HashSet<Index>(); while (resources.hasMoreElements()) { final URL url = resources.nextElement(); InputStream stream = url.openStream(); try { IndexReader reader = new IndexReader(stream); indexes.add(reader.read()); } finally { stream.close(); } } return new CompositeIndex(indexes); } catch (IOException e) { throw new RuntimeException(e); } }
Example #3
Source File: TestClassIndexer.java From quarkus with Apache License 2.0 | 5 votes |
public static Index readIndex(Class<?> testClass) { Path path = indexPath(testClass); if (path.toFile().exists()) { try (FileInputStream fis = new FileInputStream(path.toFile())) { return new IndexReader(fis).read(); } catch (IOException e) { // be lenient since the error is recoverable return indexTestClasses(testClass); } } else { return indexTestClasses(testClass); } }
Example #4
Source File: ApplicationArchiveBuildStep.java From quarkus with Apache License 2.0 | 5 votes |
private static Index handleFilePath(Path path) throws IOException { Path existing = path.resolve(JANDEX_INDEX); if (Files.exists(existing)) { try (FileInputStream in = new FileInputStream(existing.toFile())) { IndexReader reader = new IndexReader(in); if (reader.getIndexVersion() < REQUIRED_INDEX_VERSION) { LOGGER.warnf("Re-indexing %s - at least Jandex 2.1 must be used to index an application dependency", path); return indexFilePath(path); } else { return reader.read(); } } } return indexFilePath(path); }
Example #5
Source File: PiranhaBeanArchiveHandler.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
Index getIndex() { ClassLoader classLoader= Thread.currentThread().getContextClassLoader(); try (InputStream indexStream = classLoader.getResourceAsStream("META-INF/piranha.idx")) { return new IndexReader(indexStream).read(); } catch (IOException e) { throw new IllegalStateException(e); } }
Example #6
Source File: MicroInnerDeployer.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
Index getIndex() { ClassLoader classLoader= Thread.currentThread().getContextClassLoader(); try (InputStream indexStream = classLoader.getResourceAsStream("META-INF/piranha.idx")) { return new IndexReader(indexStream).read(); } catch (IOException e) { throw new IllegalStateException(e); } }
Example #7
Source File: FractionProducingExtension.java From thorntail with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private Set<Class<? extends Fraction>> uninstalledFractionClasses(Set<Type> installedClasses) throws ModuleLoadException, IOException, ClassNotFoundException { Set<String> installedClassNames = installedClasses.stream().map(Type::getTypeName).collect(Collectors.toSet()); List<String> moduleNames = ApplicationEnvironment.get().bootstrapModules(); ClassLoader cl = Module.getBootModuleLoader().loadModule("swarm.container").getClassLoader(); Set<Class<? extends Fraction>> fractionClasses = new HashSet<>(); for (String moduleName : moduleNames) { Module module = Module.getBootModuleLoader().loadModule(moduleName); InputStream indexStream = module.getClassLoader().getResourceAsStream("META-INF/jandex.idx"); if (indexStream != null) { IndexReader reader = new IndexReader(indexStream); Index index = reader.read(); Set<ClassInfo> impls = index.getAllKnownImplementors(DotName.createSimple(Fraction.class.getName())); for (ClassInfo impl : impls) { if (!installedClassNames.contains(impl.name().toString())) { Class<? extends Fraction> fractionClass = (Class<? extends Fraction>) cl.loadClass(impl.name().toString()); fractionClasses.add(fractionClass); } } } } return fractionClasses; }
Example #8
Source File: Main.java From hibernate-demos with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { try (InputStream input = Main.class.getResourceAsStream( "/META-INF/jandex.idx" ) ) { IndexReader reader = new IndexReader( input ); Index index = reader.read(); List<AnnotationInstance> entityInstances = index.getAnnotations( DotName.createSimple( "com.example.a.Entity" ) ); for (AnnotationInstance annotationInstance : entityInstances) { System.out.println( annotationInstance.target().asClass().name() ); } } }
Example #9
Source File: LiquibaseProcessor.java From quarkus with Apache License 2.0 | 4 votes |
/** * The default service loader is super slow * * As part of the extension build we index liquibase, then we use this index to find all implementations of services */ @BuildStep(onlyIfNot = NativeBuild.class) @Record(STATIC_INIT) public void fastServiceLoader(LiquibaseRecorder recorder, List<JdbcDataSourceBuildItem> jdbcDataSourceBuildItems) throws IOException { DotName liquibaseServiceName = DotName.createSimple(LiquibaseService.class.getName()); try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/liquibase.idx")) { IndexReader reader = new IndexReader(in); Index index = reader.read(); Map<String, List<String>> services = new HashMap<>(); for (Class<?> c : Arrays.asList(liquibase.diff.compare.DatabaseObjectComparator.class, liquibase.parser.NamespaceDetails.class, liquibase.precondition.Precondition.class, liquibase.database.Database.class, liquibase.parser.ChangeLogParser.class, liquibase.change.Change.class, liquibase.snapshot.SnapshotGenerator.class, liquibase.changelog.ChangeLogHistoryService.class, liquibase.datatype.LiquibaseDataType.class, liquibase.executor.Executor.class, liquibase.lockservice.LockService.class, liquibase.sqlgenerator.SqlGenerator.class, liquibase.license.LicenseService.class)) { List<String> impls = new ArrayList<>(); services.put(c.getName(), impls); Set<ClassInfo> classes = new HashSet<>(); if (c.isInterface()) { classes.addAll(index.getAllKnownImplementors(DotName.createSimple(c.getName()))); } else { classes.addAll(index.getAllKnownSubclasses(DotName.createSimple(c.getName()))); } for (ClassInfo found : classes) { if (Modifier.isAbstract(found.flags()) || Modifier.isInterface(found.flags()) || !found.hasNoArgsConstructor() || !Modifier.isPublic(found.flags())) { continue; } AnnotationInstance annotationInstance = found.classAnnotation(liquibaseServiceName); if (annotationInstance == null || !annotationInstance.value("skip").asBoolean()) { impls.add(found.name().toString()); } } } //if we know what DB types are in use we limit them //this gives a huge startup time boost //otherwise it generates SQL for every DB boolean allKnown = true; Set<String> databases = new HashSet<>(); for (JdbcDataSourceBuildItem i : jdbcDataSourceBuildItems) { String known = KIND_TO_IMPL.get(i.getDbKind()); if (known == null) { allKnown = false; } else { databases.add(known); } } if (allKnown) { services.put(Database.class.getName(), new ArrayList<>(databases)); } recorder.setJvmServiceImplementations(services); } }
Example #10
Source File: LiquibaseProcessor.java From keycloak with Apache License 2.0 | 4 votes |
@Record(ExecutionTime.STATIC_INIT) @BuildStep void configure(KeycloakRecorder recorder) { DotName liquibaseServiceName = DotName.createSimple(LiquibaseService.class.getName()); Map<String, List<String>> services = new HashMap<>(); try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/liquibase.idx")) { IndexReader reader = new IndexReader(in); Index index = reader.read(); for (Class<?> c : Arrays.asList(liquibase.diff.compare.DatabaseObjectComparator.class, liquibase.parser.NamespaceDetails.class, liquibase.precondition.Precondition.class, Database.class, ChangeLogParser.class, liquibase.change.Change.class, liquibase.snapshot.SnapshotGenerator.class, liquibase.changelog.ChangeLogHistoryService.class, liquibase.datatype.LiquibaseDataType.class, liquibase.executor.Executor.class, LockService.class, SqlGenerator.class)) { List<String> impls = new ArrayList<>(); services.put(c.getName(), impls); Set<ClassInfo> classes = new HashSet<>(); if (c.isInterface()) { classes.addAll(index.getAllKnownImplementors(DotName.createSimple(c.getName()))); } else { classes.addAll(index.getAllKnownSubclasses(DotName.createSimple(c.getName()))); } for (ClassInfo found : classes) { if (Modifier.isAbstract(found.flags()) || Modifier.isInterface(found.flags()) || !found.hasNoArgsConstructor() || !Modifier.isPublic(found.flags())) { continue; } AnnotationInstance annotationInstance = found.classAnnotation(liquibaseServiceName); if (annotationInstance == null || !annotationInstance.value("skip").asBoolean()) { impls.add(found.name().toString()); } } } } catch (IOException cause) { throw new RuntimeException("Failed to get liquibase jandex index", cause); } services.put(Logger.class.getName(), Arrays.asList(KeycloakLogger.class.getName())); services.put(LockService.class.getName(), Arrays.asList(DummyLockService.class.getName())); services.put(ChangeLogParser.class.getName(), Arrays.asList(XMLChangeLogSAXParser.class.getName())); services.get(SqlGenerator.class.getName()).add(CustomInsertLockRecordGenerator.class.getName()); services.get(SqlGenerator.class.getName()).add(CustomLockDatabaseChangeLogGenerator.class.getName()); recorder.configureLiquibase(services); }