Search in sources :

Example 1 with StandardScanOptions

use of org.hibernate.boot.archive.scan.internal.StandardScanOptions in project hibernate-orm by hibernate.

the class ScannerTest method testNativeScanner.

@Test
public void testNativeScanner() throws Exception {
    File defaultPar = buildDefaultPar();
    addPackageToClasspath(defaultPar);
    PersistenceUnitDescriptor descriptor = new ParsedPersistenceXmlDescriptor(defaultPar.toURL());
    ScanEnvironment env = new StandardJpaScanEnvironmentImpl(descriptor);
    ScanOptions options = new StandardScanOptions("hbm,class", descriptor.isExcludeUnlistedClasses());
    Scanner scanner = new StandardScanner();
    ScanResult scanResult = scanner.scan(env, options, StandardScanParameters.INSTANCE);
    assertEquals(3, scanResult.getLocatedClasses().size());
    assertClassesContained(scanResult, ApplicationServer.class);
    assertClassesContained(scanResult, Version.class);
    assertEquals(2, scanResult.getLocatedMappingFiles().size());
    for (MappingFileDescriptor mappingFileDescriptor : scanResult.getLocatedMappingFiles()) {
        assertNotNull(mappingFileDescriptor.getName());
        assertNotNull(mappingFileDescriptor.getStreamAccess());
        InputStream stream = mappingFileDescriptor.getStreamAccess().accessInputStream();
        assertNotNull(stream);
        stream.close();
    }
}
Also used : ParsedPersistenceXmlDescriptor(org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor) StandardScanner(org.hibernate.boot.archive.scan.internal.StandardScanner) Scanner(org.hibernate.boot.archive.scan.spi.Scanner) MappingFileDescriptor(org.hibernate.boot.archive.scan.spi.MappingFileDescriptor) ScanResult(org.hibernate.boot.archive.scan.spi.ScanResult) StandardJpaScanEnvironmentImpl(org.hibernate.jpa.boot.internal.StandardJpaScanEnvironmentImpl) StandardScanner(org.hibernate.boot.archive.scan.internal.StandardScanner) InputStream(java.io.InputStream) ScanOptions(org.hibernate.boot.archive.scan.spi.ScanOptions) StandardScanOptions(org.hibernate.boot.archive.scan.internal.StandardScanOptions) ScanEnvironment(org.hibernate.boot.archive.scan.spi.ScanEnvironment) File(java.io.File) StandardScanOptions(org.hibernate.boot.archive.scan.internal.StandardScanOptions) PersistenceUnitDescriptor(org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor) Test(org.junit.Test)

Example 2 with StandardScanOptions

use of org.hibernate.boot.archive.scan.internal.StandardScanOptions in project hibernate-orm by hibernate.

the class EntityManagerFactoryBuilderImpl method populate.

protected void populate(MetadataBuilder metamodelBuilder, MergedSettings mergedSettings, StandardServiceRegistry ssr, List<AttributeConverterDefinition> attributeConverterDefinitions) {
    if (persistenceUnit.getTempClassLoader() != null) {
        metamodelBuilder.applyTempClassLoader(persistenceUnit.getTempClassLoader());
    }
    metamodelBuilder.applyScanEnvironment(new StandardJpaScanEnvironmentImpl(persistenceUnit));
    metamodelBuilder.applyScanOptions(new StandardScanOptions((String) configurationValues.get(org.hibernate.cfg.AvailableSettings.SCANNER_DISCOVERY), persistenceUnit.isExcludeUnlistedClasses()));
    if (mergedSettings.cacheRegionDefinitions != null) {
        for (CacheRegionDefinition localCacheRegionDefinition : mergedSettings.cacheRegionDefinitions) {
            metamodelBuilder.applyCacheRegionDefinition(localCacheRegionDefinition);
        }
    }
    final TypeContributorList typeContributorList = (TypeContributorList) configurationValues.remove(TYPE_CONTRIBUTORS);
    if (typeContributorList != null) {
        for (TypeContributor typeContributor : typeContributorList.getTypeContributors()) {
            metamodelBuilder.applyTypes(typeContributor);
        }
    }
    if (attributeConverterDefinitions != null) {
        for (AttributeConverterDefinition attributeConverterDefinition : attributeConverterDefinitions) {
            metamodelBuilder.applyAttributeConverter(attributeConverterDefinition);
        }
    }
}
Also used : AttributeConverterDefinition(org.hibernate.cfg.AttributeConverterDefinition) CacheRegionDefinition(org.hibernate.boot.CacheRegionDefinition) TypeContributorList(org.hibernate.jpa.boot.spi.TypeContributorList) StandardScanOptions(org.hibernate.boot.archive.scan.internal.StandardScanOptions) TypeContributor(org.hibernate.boot.model.TypeContributor)

Example 3 with StandardScanOptions

use of org.hibernate.boot.archive.scan.internal.StandardScanOptions in project hibernate-orm by hibernate.

the class JarVisitorTest method testNestedJarProtocol.

@Test
public void testNestedJarProtocol() throws Exception {
    File defaultPar = buildDefaultPar();
    File nestedEar = buildNestedEar(defaultPar);
    File nestedEarDir = buildNestedEarDir(defaultPar);
    addPackageToClasspath(nestedEar);
    String jarFileName = nestedEar.toURL().toExternalForm() + "!/defaultpar.par";
    URL rootUrl = new URL(jarFileName);
    JarProtocolArchiveDescriptor archiveDescriptor = new JarProtocolArchiveDescriptor(StandardArchiveDescriptorFactory.INSTANCE, rootUrl, "");
    ScanEnvironment environment = new ScanEnvironmentImpl(rootUrl);
    ScanResultCollector collector = new ScanResultCollector(environment, new StandardScanOptions(), StandardScanParameters.INSTANCE);
    archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(true, collector));
    validateResults(collector.toScanResult(), org.hibernate.jpa.test.pack.defaultpar.ApplicationServer.class, Version.class);
    jarFileName = nestedEarDir.toURL().toExternalForm() + "!/defaultpar.par";
    rootUrl = new URL(jarFileName);
    archiveDescriptor = new JarProtocolArchiveDescriptor(StandardArchiveDescriptorFactory.INSTANCE, rootUrl, "");
    environment = new ScanEnvironmentImpl(rootUrl);
    collector = new ScanResultCollector(environment, new StandardScanOptions(), StandardScanParameters.INSTANCE);
    archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(true, collector));
    validateResults(collector.toScanResult(), org.hibernate.jpa.test.pack.defaultpar.ApplicationServer.class, Version.class);
}
Also used : JarProtocolArchiveDescriptor(org.hibernate.boot.archive.internal.JarProtocolArchiveDescriptor) AbstractScannerImpl(org.hibernate.boot.archive.scan.spi.AbstractScannerImpl) URL(java.net.URL) ScanResultCollector(org.hibernate.boot.archive.scan.internal.ScanResultCollector) ScanEnvironment(org.hibernate.boot.archive.scan.spi.ScanEnvironment) File(java.io.File) StandardScanOptions(org.hibernate.boot.archive.scan.internal.StandardScanOptions) Test(org.junit.Test)

Example 4 with StandardScanOptions

use of org.hibernate.boot.archive.scan.internal.StandardScanOptions in project hibernate-orm by hibernate.

the class JarVisitorTest method testJarProtocol.

@Test
public void testJarProtocol() throws Exception {
    File war = buildWar();
    addPackageToClasspath(war);
    String jarFileName = war.toURL().toExternalForm() + "!/WEB-INF/classes";
    URL rootUrl = new URL(jarFileName);
    JarProtocolArchiveDescriptor archiveDescriptor = new JarProtocolArchiveDescriptor(StandardArchiveDescriptorFactory.INSTANCE, rootUrl, "");
    final ScanEnvironment environment = new ScanEnvironmentImpl(rootUrl);
    final ScanResultCollector collector = new ScanResultCollector(environment, new StandardScanOptions(), StandardScanParameters.INSTANCE);
    archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(true, collector));
    validateResults(collector.toScanResult(), org.hibernate.jpa.test.pack.war.ApplicationServer.class, org.hibernate.jpa.test.pack.war.Version.class);
}
Also used : JarProtocolArchiveDescriptor(org.hibernate.boot.archive.internal.JarProtocolArchiveDescriptor) AbstractScannerImpl(org.hibernate.boot.archive.scan.spi.AbstractScannerImpl) URL(java.net.URL) ScanResultCollector(org.hibernate.boot.archive.scan.internal.ScanResultCollector) ScanEnvironment(org.hibernate.boot.archive.scan.spi.ScanEnvironment) File(java.io.File) StandardScanOptions(org.hibernate.boot.archive.scan.internal.StandardScanOptions) Test(org.junit.Test)

Aggregations

StandardScanOptions (org.hibernate.boot.archive.scan.internal.StandardScanOptions)4 File (java.io.File)3 ScanEnvironment (org.hibernate.boot.archive.scan.spi.ScanEnvironment)3 Test (org.junit.Test)3 URL (java.net.URL)2 JarProtocolArchiveDescriptor (org.hibernate.boot.archive.internal.JarProtocolArchiveDescriptor)2 ScanResultCollector (org.hibernate.boot.archive.scan.internal.ScanResultCollector)2 AbstractScannerImpl (org.hibernate.boot.archive.scan.spi.AbstractScannerImpl)2 InputStream (java.io.InputStream)1 CacheRegionDefinition (org.hibernate.boot.CacheRegionDefinition)1 StandardScanner (org.hibernate.boot.archive.scan.internal.StandardScanner)1 MappingFileDescriptor (org.hibernate.boot.archive.scan.spi.MappingFileDescriptor)1 ScanOptions (org.hibernate.boot.archive.scan.spi.ScanOptions)1 ScanResult (org.hibernate.boot.archive.scan.spi.ScanResult)1 Scanner (org.hibernate.boot.archive.scan.spi.Scanner)1 TypeContributor (org.hibernate.boot.model.TypeContributor)1 AttributeConverterDefinition (org.hibernate.cfg.AttributeConverterDefinition)1 ParsedPersistenceXmlDescriptor (org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor)1 StandardJpaScanEnvironmentImpl (org.hibernate.jpa.boot.internal.StandardJpaScanEnvironmentImpl)1 PersistenceUnitDescriptor (org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor)1