Search in sources :

Example 1 with ClassDescriptorImpl

use of org.hibernate.boot.archive.scan.internal.ClassDescriptorImpl 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 2 with ClassDescriptorImpl

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

the class ClassFileArchiveEntryHandler method toClassDescriptor.

private ClassDescriptor toClassDescriptor(ClassFile classFile, ArchiveEntry entry) {
    ClassDescriptor.Categorization categorization = ClassDescriptor.Categorization.OTHER;
    ;
    final AnnotationsAttribute visibleAnnotations = (AnnotationsAttribute) classFile.getAttribute(AnnotationsAttribute.visibleTag);
    if (visibleAnnotations != null) {
        if (visibleAnnotations.getAnnotation(Entity.class.getName()) != null || visibleAnnotations.getAnnotation(MappedSuperclass.class.getName()) != null || visibleAnnotations.getAnnotation(Embeddable.class.getName()) != null) {
            categorization = ClassDescriptor.Categorization.MODEL;
        } else if (visibleAnnotations.getAnnotation(Converter.class.getName()) != null) {
            categorization = ClassDescriptor.Categorization.CONVERTER;
        }
    }
    return new ClassDescriptorImpl(classFile.getName(), categorization, entry.getStreamAccess());
}
Also used : AnnotationsAttribute(javassist.bytecode.AnnotationsAttribute) ClassDescriptorImpl(org.hibernate.boot.archive.scan.internal.ClassDescriptorImpl) Converter(javax.persistence.Converter) Embeddable(javax.persistence.Embeddable)

Example 3 with ClassDescriptorImpl

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

the class JarVisitorTest method validateResults.

private void validateResults(ScanResult scanResult, Class... expectedClasses) throws IOException {
    assertEquals(3, scanResult.getLocatedClasses().size());
    for (Class expectedClass : expectedClasses) {
        assertTrue(scanResult.getLocatedClasses().contains(new ClassDescriptorImpl(expectedClass.getName(), ClassDescriptor.Categorization.MODEL, null)));
    }
    assertEquals(2, scanResult.getLocatedMappingFiles().size());
    for (MappingFileDescriptor mappingFileDescriptor : scanResult.getLocatedMappingFiles()) {
        assertNotNull(mappingFileDescriptor.getStreamAccess());
        final InputStream stream = mappingFileDescriptor.getStreamAccess().accessInputStream();
        assertNotNull(stream);
        stream.close();
    }
}
Also used : MappingFileDescriptor(org.hibernate.boot.archive.scan.spi.MappingFileDescriptor) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ClassDescriptorImpl(org.hibernate.boot.archive.scan.internal.ClassDescriptorImpl)

Aggregations

ClassDescriptorImpl (org.hibernate.boot.archive.scan.internal.ClassDescriptorImpl)3 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 MappingFileDescriptor (org.hibernate.boot.archive.scan.spi.MappingFileDescriptor)2 File (java.io.File)1 AnnotationsAttribute (javassist.bytecode.AnnotationsAttribute)1 Converter (javax.persistence.Converter)1 Embeddable (javax.persistence.Embeddable)1 ScanResult (org.hibernate.boot.archive.scan.spi.ScanResult)1 Carpet (org.hibernate.jpa.test.pack.explodedpar.Carpet)1 Test (org.junit.Test)1