Search in sources :

Example 1 with ArchiveDescriptor

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

the class AbstractScannerImpl method buildArchiveDescriptor.

private ArchiveDescriptor buildArchiveDescriptor(URL url, ScanEnvironment environment, boolean isRootUrl) {
    final ArchiveDescriptor descriptor;
    final ArchiveDescriptorInfo descriptorInfo = archiveDescriptorCache.get(url);
    if (descriptorInfo == null) {
        if (!isRootUrl && archiveDescriptorFactory instanceof JarFileEntryUrlAdjuster) {
            url = ((JarFileEntryUrlAdjuster) archiveDescriptorFactory).adjustJarFileEntryUrl(url, environment.getRootUrl());
        }
        descriptor = archiveDescriptorFactory.buildArchiveDescriptor(url);
        archiveDescriptorCache.put(url, new ArchiveDescriptorInfo(descriptor, isRootUrl));
    } else {
        validateReuse(descriptorInfo, isRootUrl);
        descriptor = descriptorInfo.archiveDescriptor;
    }
    return descriptor;
}
Also used : JarFileEntryUrlAdjuster(org.hibernate.boot.archive.spi.JarFileEntryUrlAdjuster) ArchiveDescriptor(org.hibernate.boot.archive.spi.ArchiveDescriptor)

Example 2 with ArchiveDescriptor

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

the class AbstractScannerImpl method scan.

@Override
public ScanResult scan(ScanEnvironment environment, ScanOptions options, ScanParameters parameters) {
    final ScanResultCollector collector = new ScanResultCollector(environment, options, parameters);
    if (environment.getNonRootUrls() != null) {
        final ArchiveContext context = new ArchiveContextImpl(false, collector);
        for (URL url : environment.getNonRootUrls()) {
            final ArchiveDescriptor descriptor = buildArchiveDescriptor(url, environment, false);
            descriptor.visitArchive(context);
        }
    }
    if (environment.getRootUrl() != null) {
        final ArchiveContext context = new ArchiveContextImpl(true, collector);
        final ArchiveDescriptor descriptor = buildArchiveDescriptor(environment.getRootUrl(), environment, true);
        descriptor.visitArchive(context);
    }
    return collector.toScanResult();
}
Also used : ScanResultCollector(org.hibernate.boot.archive.scan.internal.ScanResultCollector) ArchiveContext(org.hibernate.boot.archive.spi.ArchiveContext) ArchiveDescriptor(org.hibernate.boot.archive.spi.ArchiveDescriptor) URL(java.net.URL)

Example 3 with ArchiveDescriptor

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

the class JarVisitorTest method testJarVisitorFactory.

@Test
@TestForIssue(jiraKey = "HHH-6806")
public void testJarVisitorFactory() throws Exception {
    final File explodedPar = buildExplodedPar();
    final File defaultPar = buildDefaultPar();
    addPackageToClasspath(explodedPar, defaultPar);
    //setting URL to accept vfs based protocol
    URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {

        public URLStreamHandler createURLStreamHandler(String protocol) {
            if ("vfszip".equals(protocol) || "vfsfile".equals(protocol))
                return new URLStreamHandler() {

                    protected URLConnection openConnection(URL u) throws IOException {
                        return null;
                    }
                };
            return null;
        }
    });
    URL jarUrl = defaultPar.toURL();
    ArchiveDescriptor descriptor = StandardArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(jarUrl);
    assertEquals(JarFileBasedArchiveDescriptor.class.getName(), descriptor.getClass().getName());
    jarUrl = explodedPar.toURL();
    descriptor = StandardArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(jarUrl);
    assertEquals(ExplodedArchiveDescriptor.class.getName(), descriptor.getClass().getName());
    jarUrl = new URL(defaultPar.toURL().toExternalForm().replace("file:", "vfszip:"));
    descriptor = StandardArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(jarUrl);
    assertEquals(JarFileBasedArchiveDescriptor.class.getName(), descriptor.getClass().getName());
    jarUrl = new URL(explodedPar.toURL().toExternalForm().replace("file:", "vfsfile:"));
    descriptor = StandardArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(jarUrl);
    assertEquals(ExplodedArchiveDescriptor.class.getName(), descriptor.getClass().getName());
}
Also used : URLStreamHandler(java.net.URLStreamHandler) JarFileBasedArchiveDescriptor(org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor) URLStreamHandlerFactory(java.net.URLStreamHandlerFactory) ExplodedArchiveDescriptor(org.hibernate.boot.archive.internal.ExplodedArchiveDescriptor) JarFileBasedArchiveDescriptor(org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor) JarProtocolArchiveDescriptor(org.hibernate.boot.archive.internal.JarProtocolArchiveDescriptor) ExplodedArchiveDescriptor(org.hibernate.boot.archive.internal.ExplodedArchiveDescriptor) ArchiveDescriptor(org.hibernate.boot.archive.spi.ArchiveDescriptor) File(java.io.File) URL(java.net.URL) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

ArchiveDescriptor (org.hibernate.boot.archive.spi.ArchiveDescriptor)3 URL (java.net.URL)2 File (java.io.File)1 URLStreamHandler (java.net.URLStreamHandler)1 URLStreamHandlerFactory (java.net.URLStreamHandlerFactory)1 ExplodedArchiveDescriptor (org.hibernate.boot.archive.internal.ExplodedArchiveDescriptor)1 JarFileBasedArchiveDescriptor (org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor)1 JarProtocolArchiveDescriptor (org.hibernate.boot.archive.internal.JarProtocolArchiveDescriptor)1 ScanResultCollector (org.hibernate.boot.archive.scan.internal.ScanResultCollector)1 ArchiveContext (org.hibernate.boot.archive.spi.ArchiveContext)1 JarFileEntryUrlAdjuster (org.hibernate.boot.archive.spi.JarFileEntryUrlAdjuster)1 TestForIssue (org.hibernate.testing.TestForIssue)1 Test (org.junit.Test)1