Java Code Examples for org.jboss.jandex.IndexReader#read()
The following examples show how to use
org.jboss.jandex.IndexReader#read() .
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: 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 2
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 3
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 4
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 5
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); }