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;
}
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();
}
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());
}
Aggregations