Search in sources :

Example 1 with ScanResult

use of org.hibernate.boot.archive.scan.spi.ScanResult in project hibernate-orm by hibernate.

the class ScanningCoordinator method coordinateScan.

public void coordinateScan(ManagedResourcesImpl managedResources, MetadataBuildingOptions options, XmlMappingBinderAccess xmlMappingBinderAccess) {
    if (options.getScanEnvironment() == null) {
        return;
    }
    final ClassLoaderService classLoaderService = options.getServiceRegistry().getService(ClassLoaderService.class);
    final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl(options.getTempClassLoader(), 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(options, classLoaderAccess);
    final ScanResult scanResult = scanner.scan(options.getScanEnvironment(), options.getScanOptions(), StandardScanParameters.INSTANCE);
    applyScanResultsToManagedResources(managedResources, scanResult, options, xmlMappingBinderAccess);
}
Also used : ClassLoaderAccess(org.hibernate.boot.spi.ClassLoaderAccess) StandardScanner(org.hibernate.boot.archive.scan.internal.StandardScanner) Scanner(org.hibernate.boot.archive.scan.spi.Scanner) ScanResult(org.hibernate.boot.archive.scan.spi.ScanResult) ClassLoaderAccessImpl(org.hibernate.boot.internal.ClassLoaderAccessImpl) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 2 with ScanResult

use of org.hibernate.boot.archive.scan.spi.ScanResult in project hibernate-orm by hibernate.

the class JarVisitorTest method testExplodedJar.

@Test
public void testExplodedJar() throws Exception {
    File explodedPar = buildExplodedPar();
    addPackageToClasspath(explodedPar);
    String dirPath = explodedPar.toURL().toExternalForm();
    // TODO - shouldn't  ExplodedJarVisitor take care of a trailing slash?
    if (dirPath.endsWith("/")) {
        dirPath = dirPath.substring(0, dirPath.length() - 1);
    }
    ScanResult result = standardScan(ArchiveHelper.getURLFromPath(dirPath));
    assertEquals(1, result.getLocatedClasses().size());
    assertEquals(1, result.getLocatedPackages().size());
    assertEquals(1, result.getLocatedMappingFiles().size());
    assertTrue(result.getLocatedClasses().contains(new ClassDescriptorImpl(Carpet.class.getName(), ClassDescriptor.Categorization.MODEL, null)));
    for (MappingFileDescriptor mappingFileDescriptor : result.getLocatedMappingFiles()) {
        assertNotNull(mappingFileDescriptor.getStreamAccess());
        final InputStream stream = mappingFileDescriptor.getStreamAccess().accessInputStream();
        assertNotNull(stream);
        stream.close();
    }
}
Also used : MappingFileDescriptor(org.hibernate.boot.archive.scan.spi.MappingFileDescriptor) ScanResult(org.hibernate.boot.archive.scan.spi.ScanResult) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ClassDescriptorImpl(org.hibernate.boot.archive.scan.internal.ClassDescriptorImpl) Carpet(org.hibernate.jpa.test.pack.explodedpar.Carpet) File(java.io.File) Test(org.junit.Test)

Example 3 with ScanResult

use of org.hibernate.boot.archive.scan.spi.ScanResult in project hibernate-orm by hibernate.

the class JarVisitorTest method testInputStreamZippedJar.

@Test
public void testInputStreamZippedJar() throws Exception {
    File defaultPar = buildDefaultPar();
    addPackageToClasspath(defaultPar);
    ScanResult result = standardScan(defaultPar.toURL());
    validateResults(result, org.hibernate.jpa.test.pack.defaultpar.ApplicationServer.class, Version.class);
}
Also used : ScanResult(org.hibernate.boot.archive.scan.spi.ScanResult) File(java.io.File) Test(org.junit.Test)

Example 4 with ScanResult

use of org.hibernate.boot.archive.scan.spi.ScanResult 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 5 with ScanResult

use of org.hibernate.boot.archive.scan.spi.ScanResult in project hibernate-orm by hibernate.

the class JarVisitorTest method testHttp.

@Test
public void testHttp() throws Exception {
    final URL url = ArchiveHelper.getJarURLFromURLEntry(new URL("jar:http://www.ibiblio.org/maven/hibernate/jars/hibernate-annotations-3.0beta1.jar!/META-INF/persistence.xml"), "/META-INF/persistence.xml");
    try {
        URLConnection urlConnection = url.openConnection();
        urlConnection.connect();
    } catch (IOException ie) {
        //fail silently
        return;
    }
    ScanResult result = standardScan(url);
    assertEquals(0, result.getLocatedClasses().size());
    assertEquals(0, result.getLocatedPackages().size());
    assertEquals(0, result.getLocatedMappingFiles().size());
}
Also used : ScanResult(org.hibernate.boot.archive.scan.spi.ScanResult) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) Test(org.junit.Test)

Aggregations

ScanResult (org.hibernate.boot.archive.scan.spi.ScanResult)6 Test (org.junit.Test)5 File (java.io.File)4 InputStream (java.io.InputStream)2 StandardScanner (org.hibernate.boot.archive.scan.internal.StandardScanner)2 MappingFileDescriptor (org.hibernate.boot.archive.scan.spi.MappingFileDescriptor)2 Scanner (org.hibernate.boot.archive.scan.spi.Scanner)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 ClassDescriptorImpl (org.hibernate.boot.archive.scan.internal.ClassDescriptorImpl)1 StandardScanOptions (org.hibernate.boot.archive.scan.internal.StandardScanOptions)1 ScanEnvironment (org.hibernate.boot.archive.scan.spi.ScanEnvironment)1 ScanOptions (org.hibernate.boot.archive.scan.spi.ScanOptions)1 ClassLoaderAccessImpl (org.hibernate.boot.internal.ClassLoaderAccessImpl)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 ClassLoaderAccess (org.hibernate.boot.spi.ClassLoaderAccess)1 ParsedPersistenceXmlDescriptor (org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor)1