use of org.jboss.jandex.IndexView in project hibernate-orm by hibernate.
the class MetadataBuildingProcess method complete.
/**
* Second step of 2-phase for MetadataSources->Metadata process
*
* @param managedResources The token/memento from 1st phase
* @param options The building options
*
* @return Token/memento representing all known users resources (classes, packages, mapping files, etc).
*/
public static MetadataImplementor complete(final ManagedResources managedResources, final MetadataBuildingOptions options) {
final BasicTypeRegistry basicTypeRegistry = handleTypes(options);
final InFlightMetadataCollectorImpl metadataCollector = new InFlightMetadataCollectorImpl(options, new TypeResolver(basicTypeRegistry, new TypeFactory()));
for (AttributeConverterDefinition attributeConverterDefinition : managedResources.getAttributeConverterDefinitions()) {
metadataCollector.addAttributeConverter(attributeConverterDefinition);
}
final ClassLoaderService classLoaderService = options.getServiceRegistry().getService(ClassLoaderService.class);
final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl(options.getTempClassLoader(), classLoaderService);
final MetadataBuildingContextRootImpl rootMetadataBuildingContext = new MetadataBuildingContextRootImpl(options, classLoaderAccess, metadataCollector);
final IndexView jandexView = options.getJandexView();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Set up the processors and start binding
// NOTE : this becomes even more simplified afterQuery we move purely
// to unified model
final MetadataSourceProcessor processor = new MetadataSourceProcessor() {
private final HbmMetadataSourceProcessorImpl hbmProcessor = new HbmMetadataSourceProcessorImpl(managedResources, rootMetadataBuildingContext);
private final AnnotationMetadataSourceProcessorImpl annotationProcessor = new AnnotationMetadataSourceProcessorImpl(managedResources, rootMetadataBuildingContext, jandexView);
@Override
public void prepare() {
hbmProcessor.prepare();
annotationProcessor.prepare();
}
@Override
public void processTypeDefinitions() {
hbmProcessor.processTypeDefinitions();
annotationProcessor.processTypeDefinitions();
}
@Override
public void processQueryRenames() {
hbmProcessor.processQueryRenames();
annotationProcessor.processQueryRenames();
}
@Override
public void processNamedQueries() {
hbmProcessor.processNamedQueries();
annotationProcessor.processNamedQueries();
}
@Override
public void processAuxiliaryDatabaseObjectDefinitions() {
hbmProcessor.processAuxiliaryDatabaseObjectDefinitions();
annotationProcessor.processAuxiliaryDatabaseObjectDefinitions();
}
@Override
public void processIdentifierGenerators() {
hbmProcessor.processIdentifierGenerators();
annotationProcessor.processIdentifierGenerators();
}
@Override
public void processFilterDefinitions() {
hbmProcessor.processFilterDefinitions();
annotationProcessor.processFilterDefinitions();
}
@Override
public void processFetchProfiles() {
hbmProcessor.processFetchProfiles();
annotationProcessor.processFetchProfiles();
}
@Override
public void prepareForEntityHierarchyProcessing() {
for (MetadataSourceType metadataSourceType : options.getSourceProcessOrdering()) {
if (metadataSourceType == MetadataSourceType.HBM) {
hbmProcessor.prepareForEntityHierarchyProcessing();
}
if (metadataSourceType == MetadataSourceType.CLASS) {
annotationProcessor.prepareForEntityHierarchyProcessing();
}
}
}
@Override
public void processEntityHierarchies(Set<String> processedEntityNames) {
for (MetadataSourceType metadataSourceType : options.getSourceProcessOrdering()) {
if (metadataSourceType == MetadataSourceType.HBM) {
hbmProcessor.processEntityHierarchies(processedEntityNames);
}
if (metadataSourceType == MetadataSourceType.CLASS) {
annotationProcessor.processEntityHierarchies(processedEntityNames);
}
}
}
@Override
public void postProcessEntityHierarchies() {
for (MetadataSourceType metadataSourceType : options.getSourceProcessOrdering()) {
if (metadataSourceType == MetadataSourceType.HBM) {
hbmProcessor.postProcessEntityHierarchies();
}
if (metadataSourceType == MetadataSourceType.CLASS) {
annotationProcessor.postProcessEntityHierarchies();
}
}
}
@Override
public void processResultSetMappings() {
hbmProcessor.processResultSetMappings();
annotationProcessor.processResultSetMappings();
}
@Override
public void finishUp() {
hbmProcessor.finishUp();
annotationProcessor.finishUp();
}
};
processor.prepare();
processor.processTypeDefinitions();
processor.processQueryRenames();
processor.processAuxiliaryDatabaseObjectDefinitions();
processor.processIdentifierGenerators();
processor.processFilterDefinitions();
processor.processFetchProfiles();
final Set<String> processedEntityNames = new HashSet<String>();
processor.prepareForEntityHierarchyProcessing();
processor.processEntityHierarchies(processedEntityNames);
processor.postProcessEntityHierarchies();
processor.processResultSetMappings();
processor.processNamedQueries();
processor.finishUp();
for (MetadataContributor contributor : classLoaderService.loadJavaServices(MetadataContributor.class)) {
log.tracef("Calling MetadataContributor : %s", contributor);
contributor.contribute(metadataCollector, jandexView);
}
metadataCollector.processSecondPasses(rootMetadataBuildingContext);
Iterable<AdditionalJaxbMappingProducer> producers = classLoaderService.loadJavaServices(AdditionalJaxbMappingProducer.class);
if (producers != null) {
final EntityHierarchyBuilder hierarchyBuilder = new EntityHierarchyBuilder();
// final MappingBinder mappingBinder = new MappingBinder( true );
// We need to disable validation here. It seems Envers is not producing valid (according to schema) XML
final MappingBinder mappingBinder = new MappingBinder(classLoaderService, false);
for (AdditionalJaxbMappingProducer producer : producers) {
log.tracef("Calling AdditionalJaxbMappingProducer : %s", producer);
Collection<MappingDocument> additionalMappings = producer.produceAdditionalMappings(metadataCollector, jandexView, mappingBinder, rootMetadataBuildingContext);
for (MappingDocument mappingDocument : additionalMappings) {
hierarchyBuilder.indexMappingDocument(mappingDocument);
}
}
ModelBinder binder = ModelBinder.prepare(rootMetadataBuildingContext);
for (EntityHierarchySourceImpl entityHierarchySource : hierarchyBuilder.buildHierarchies()) {
binder.bindEntityHierarchy(entityHierarchySource);
}
}
return metadataCollector.buildMetadataInstance(rootMetadataBuildingContext);
}
use of org.jboss.jandex.IndexView in project wildfly-swarm by wildfly-swarm.
the class DeploymentIndexTest method testIndexBuilt.
@Test
public void testIndexBuilt() {
WebArchive war = ShrinkWrap.create(WebArchive.class);
war.addClass(Foo.class);
JavaArchive lib1 = ShrinkWrap.create(JavaArchive.class).addClass(Bar.class);
war.addAsLibraries(lib1);
IndexView index = new DeploymentProducer().createDeploymentIndex(war);
assertContains(index, Foo.class);
assertDoesNotContain(index, Baz.class);
assertContains(index, Bar.class);
assertDoesNotContain(index, Delta.class);
}
use of org.jboss.jandex.IndexView in project wildfly-swarm by wildfly-swarm.
the class DeploymentIndexTest method testIndexAttached.
@Test
public void testIndexAttached() throws IOException {
WebArchive war = ShrinkWrap.create(WebArchive.class);
war.addClass(Foo.class);
war.add(createIndexAsset(Foo.class, Baz.class), DeploymentProducer.INDEX_LOCATION);
JavaArchive lib1 = ShrinkWrap.create(JavaArchive.class).addClass(Bar.class);
lib1.add(createIndexAsset(Delta.class), DeploymentProducer.INDEX_LOCATION);
war.addAsLibraries(lib1);
IndexView index = new DeploymentProducer().createDeploymentIndex(war);
assertContains(index, Foo.class);
// Baz should be found in the attached index
assertContains(index, Baz.class);
assertContains(index, Delta.class);
// Bar is not in the attached index
assertDoesNotContain(index, Bar.class);
}
use of org.jboss.jandex.IndexView in project wildfly-swarm by wildfly-swarm.
the class DeploymentProducer method index.
private void index(Archive<?> archive, List<IndexView> indexes) throws IOException {
LOGGER.debugv("Indexing archive: {0}", archive.getName());
// First try to load attached index
Node indexNode = archive.get(ArchivePaths.create(INDEX_LOCATION));
if (indexNode != null) {
try (InputStream indexStream = indexNode.getAsset().openStream()) {
LOGGER.debugv("Loading attached index from archive: {0}", archive.getName());
indexes.add(new IndexReader(indexStream).read());
}
} else {
// No index found - index all classes found
Indexer indexer = new Indexer();
for (Map.Entry<ArchivePath, Node> entry : archive.getContent(this::isClass).entrySet()) {
try (InputStream contentStream = entry.getValue().getAsset().openStream()) {
LOGGER.debugv("Indexing asset: {0} from archive: {1}", entry.getKey().get(), archive.getName());
indexer.index(contentStream);
} catch (IOException indexerIOException) {
LOGGER.warnv(indexerIOException, "Failed parsing: {0} from archive: {1}", entry.getKey().get(), archive.getName());
}
}
Index index = indexer.complete();
indexes.add(index);
}
if (archive instanceof LibraryContainer) {
for (Map.Entry<ArchivePath, Node> entry : archive.getContent(a -> a.get().endsWith(JAR_SUFFIX)).entrySet()) {
if (entry.getValue().getAsset() instanceof ArchiveAsset) {
ArchiveAsset archiveAsset = (ArchiveAsset) entry.getValue().getAsset();
index(archiveAsset.getArchive(), indexes);
} else {
try (InputStream contentStream = entry.getValue().getAsset().openStream()) {
JARArchive jarArchive = ShrinkWrap.create(JARArchive.class, entry.getKey().get()).as(ZipImporter.class).importFrom(contentStream).as(JARArchive.class);
index(jarArchive, indexes);
}
}
}
}
}
use of org.jboss.jandex.IndexView in project sts4 by spring-projects.
the class JandexIndex method findMatch.
private Optional<Tuple2<File, ClassInfo>> findMatch(DotName fqName) {
return (baseIndex == null ? Stream.<Optional<Tuple2<File, ClassInfo>>>empty() : Arrays.stream(baseIndex).filter(jandexIndex -> jandexIndex != null).map(jandexIndex -> jandexIndex.findMatch(fqName))).filter(o -> o.isPresent()).findFirst().orElseGet(() -> streamOfIndices().map(e -> {
IndexView view = e.getT2();
ClassInfo info = view.getClassByName(fqName);
return Tuples.of(e.getT1(), Optional.ofNullable(info));
// return Tuples.of(e.getT1(), Optional.ofNullable(e.getT2().getClassByName(fqName)));
}).filter(t -> t.getT2().isPresent()).map(e -> Tuples.of(e.getT1(), e.getT2().get())).findFirst());
}
Aggregations