public void coordinateScan( ManagedResourcesImpl managedResources, BootstrapContext bootstrapContext, XmlMappingBinderAccess xmlMappingBinderAccess) { if ( bootstrapContext.getScanEnvironment() == null ) { return; } final ClassLoaderService classLoaderService = bootstrapContext.getServiceRegistry().getService( ClassLoaderService.class ); final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl( bootstrapContext.getJpaTempClassLoader(), classLoaderService ); // NOTE : the idea with JandexInitializer/JandexInitManager was to allow adding classes // to the index as we discovered them via scanning and . Currently final Scanner scanner = buildScanner( bootstrapContext, classLoaderAccess ); final ScanResult scanResult = scanner.scan( bootstrapContext.getScanEnvironment(), bootstrapContext.getScanOptions(), StandardScanParameters.INSTANCE ); applyScanResultsToManagedResources( managedResources, scanResult, bootstrapContext, xmlMappingBinderAccess ); }
/** * First step of 2-phase for MetadataSources->Metadata process * * @param sources The MetadataSources * @param bootstrapContext The bootstrapContext * * @return Token/memento representing all known users resources (classes, packages, mapping files, etc). */ public static ManagedResources prepare( final MetadataSources sources, final BootstrapContext bootstrapContext) { final ManagedResourcesImpl managedResources = ManagedResourcesImpl.baseline( sources, bootstrapContext ); ScanningCoordinator.INSTANCE.coordinateScan( managedResources, bootstrapContext, sources.getXmlMappingBinderAccess() ); return managedResources; }
@Test public void testApplyScanResultsToManagedResourcesWithNotNullRootUrl() throws MalformedURLException { when( scanEnvironment.getRootUrl() ).thenReturn( new URL( "http://http://hibernate.org/" ) ); ScanningCoordinator.INSTANCE.applyScanResultsToManagedResources( managedResources, scanResult, bootstrapContext, xmlMappingBinderAccess ); assertEquals( "Unable to resolve class [a.b.C] named in persistence unit [http://http://hibernate.org/]", triggerable.triggerMessage() ); }
@Test public void testApplyScanResultsToManagedResourcesWithNullRootUrl() { ScanningCoordinator.INSTANCE.applyScanResultsToManagedResources( managedResources, scanResult, bootstrapContext, xmlMappingBinderAccess ); assertEquals( "Unable to resolve class [a.b.C] named in persistence unit [null]", triggerable.triggerMessage() ); }
public void coordinateScan( ManagedResourcesImpl managedResources, BootstrapContext bootstrapContext, XmlMappingBinderAccess xmlMappingBinderAccess) { if ( bootstrapContext.getScanEnvironment() == null ) { return; } final ClassLoaderService classLoaderService = bootstrapContext.getServiceRegistry().getService( ClassLoaderService.class ); final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl( bootstrapContext.getJpaTempClassLoader(), classLoaderService ); // NOTE : the idea with JandexInitializer/JandexInitManager was to allow adding classes // to the index as we discovered them via scanning and . Currently final Scanner scanner = buildScanner( bootstrapContext, classLoaderAccess ); final ScanResult scanResult = scanner.scan( bootstrapContext.getScanEnvironment(), bootstrapContext.getScanOptions(), StandardScanParameters.INSTANCE ); applyScanResultsToManagedResources( managedResources, scanResult, bootstrapContext, xmlMappingBinderAccess ); }
/** * Run coordinateScan() with the given Scanner and assert the emptiness * of ManagedResources. */ private void assertManagedResourcesAfterCoordinateScanWithScanner(final Scanner scanner, final boolean expectedIsManagedResourcesEmpty) { when( bootstrapContext.getScanner() ).thenReturn( scanner ); final ManagedResourcesImpl managedResources = ManagedResourcesImpl.baseline( new MetadataSources(), bootstrapContext ); ScanningCoordinator.INSTANCE.coordinateScan( managedResources, bootstrapContext, xmlMappingBinderAccess ); assertEquals( 1, scanEnvironment.getExplicitlyListedClassNames().size() ); assertEquals( "a.b.C", scanEnvironment.getExplicitlyListedClassNames().get(0) ); assertEquals( true, managedResources.getAttributeConverterDefinitions().isEmpty() ); assertEquals( true, managedResources.getAnnotatedClassReferences().isEmpty() ); assertEquals( expectedIsManagedResourcesEmpty, managedResources.getAnnotatedClassNames().isEmpty() ); assertEquals( expectedIsManagedResourcesEmpty, managedResources.getAnnotatedPackageNames().isEmpty() ); assertEquals( expectedIsManagedResourcesEmpty, managedResources.getXmlMappingBindings().isEmpty() ); } }
@Test @TestForIssue(jiraKey = "HHH-10778") public void testManagedResourcesAfterCoordinateScanWithConverterScanner() { when( classLoaderService.classForName( "converter" ) ).thenReturn( (Class) IntegerToVarcharConverter.class ); final Scanner scanner = (ScanEnvironment environment, ScanOptions options, ScanParameters parameters) -> { final InputStreamAccess dummyInputStreamAccess = new ByteArrayInputStreamAccess( "dummy", new byte[0] ); return new ScanResultImpl( Collections.singleton( new PackageDescriptorImpl( "dummy", dummyInputStreamAccess ) ), Collections.singleton( new ClassDescriptorImpl( "converter", ClassDescriptor.Categorization.CONVERTER, dummyInputStreamAccess ) ), Collections.singleton( new MappingFileDescriptorImpl( "dummy", dummyInputStreamAccess ) ) ); }; when( bootstrapContext.getScanner() ).thenReturn( scanner ); final ManagedResourcesImpl managedResources = ManagedResourcesImpl.baseline( new MetadataSources(), bootstrapContext ); ScanningCoordinator.INSTANCE.coordinateScan( managedResources, bootstrapContext, xmlMappingBinderAccess ); assertEquals( 1, scanEnvironment.getExplicitlyListedClassNames().size() ); assertEquals( "a.b.C", scanEnvironment.getExplicitlyListedClassNames().get( 0 ) ); assertEquals( 1, managedResources.getAttributeConverterDefinitions().size() ); AttributeConverterInfo attributeConverterInfo = managedResources.getAttributeConverterDefinitions() .iterator() .next(); assertEquals( IntegerToVarcharConverter.class, attributeConverterInfo.getConverterClass() ); }
/** * First step of 2-phase for MetadataSources->Metadata process * * @param sources The MetadataSources * @param bootstrapContext The bootstrapContext * * @return Token/memento representing all known users resources (classes, packages, mapping files, etc). */ public static ManagedResources prepare( final MetadataSources sources, final BootstrapContext bootstrapContext) { final ManagedResourcesImpl managedResources = ManagedResourcesImpl.baseline( sources, bootstrapContext ); ScanningCoordinator.INSTANCE.coordinateScan( managedResources, bootstrapContext, sources.getXmlMappingBinderAccess() ); return managedResources; }