Search in sources :

Example 1 with ArchiveDescriptor

use of org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor in project wildfly by wildfly.

the class ScannerTest method testZippedJar.

@Test
public void testZippedJar() throws Exception {
    File defaultPar = buildDefaultPar();
    addPackageToClasspath(defaultPar);
    final VirtualFile virtualFile = VFS.getChild(defaultPar.getAbsolutePath());
    Closeable closeable = VFS.mountZip(virtualFile, virtualFile, tempFileProvider);
    try {
        ArchiveDescriptor archiveDescriptor = VirtualFileSystemArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(virtualFile.toURL());
        AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector(new StandardScanOptions());
        archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(new PersistenceUnitDescriptorAdapter(), true, resultCollector));
        validateResults(resultCollector, ApplicationServer.class, Version.class);
    } finally {
        closeable.close();
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) AbstractScannerImpl(org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl) Closeable(java.io.Closeable) ArchiveDescriptor(org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File) StandardScanOptions(org.hibernate.jpa.boot.scan.internal.StandardScanOptions) Test(org.junit.Test)

Example 2 with ArchiveDescriptor

use of org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor in project wildfly by wildfly.

the class ScannerTest method testHttp.

@Test
public void testHttp() throws Exception {
    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;
    }
    ArchiveDescriptor archiveDescriptor = VirtualFileSystemArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(url);
    AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector(new StandardScanOptions());
    archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(new PersistenceUnitDescriptorAdapter(), true, resultCollector));
    assertEquals(0, resultCollector.getClassDescriptorSet().size());
    assertEquals(0, resultCollector.getPackageDescriptorSet().size());
    assertEquals(0, resultCollector.getMappingFileSet().size());
}
Also used : AbstractScannerImpl(org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl) ArchiveDescriptor(org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) StandardScanOptions(org.hibernate.jpa.boot.scan.internal.StandardScanOptions) Test(org.junit.Test)

Example 3 with ArchiveDescriptor

use of org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor in project wildfly by wildfly.

the class ScannerTest method testNestedJarProtocol.

@Test
public void testNestedJarProtocol() throws Exception {
    File defaultPar = buildDefaultPar();
    File nestedEar = buildNestedEar(defaultPar);
    addPackageToClasspath(nestedEar);
    final VirtualFile nestedEarVirtualFile = VFS.getChild(nestedEar.getAbsolutePath());
    Closeable closeable = VFS.mountZip(nestedEarVirtualFile, nestedEarVirtualFile, tempFileProvider);
    try {
        VirtualFile parVirtualFile = nestedEarVirtualFile.getChild("defaultpar.par");
        Closeable closeable2 = VFS.mountZip(parVirtualFile, parVirtualFile, tempFileProvider);
        try {
            ArchiveDescriptor archiveDescriptor = VirtualFileSystemArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(parVirtualFile.toURL());
            AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector(new StandardScanOptions());
            archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(new PersistenceUnitDescriptorAdapter(), true, resultCollector));
            validateResults(resultCollector, ApplicationServer.class, Version.class);
        } finally {
            closeable2.close();
        }
    } finally {
        closeable.close();
    }
    File nestedEarDir = buildNestedEarDir(defaultPar);
    final VirtualFile nestedEarDirVirtualFile = VFS.getChild(nestedEarDir.getAbsolutePath());
    try {
        VirtualFile parVirtualFile = nestedEarDirVirtualFile.getChild("defaultpar.par");
        closeable = VFS.mountZip(parVirtualFile, parVirtualFile, tempFileProvider);
        try {
            ArchiveDescriptor archiveDescriptor = VirtualFileSystemArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(parVirtualFile.toURL());
            AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector(new StandardScanOptions());
            archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(new PersistenceUnitDescriptorAdapter(), true, resultCollector));
            validateResults(resultCollector, ApplicationServer.class, Version.class);
        } finally {
            closeable.close();
        }
    } finally {
        closeable.close();
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) AbstractScannerImpl(org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl) Closeable(java.io.Closeable) ArchiveDescriptor(org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File) StandardScanOptions(org.hibernate.jpa.boot.scan.internal.StandardScanOptions) Test(org.junit.Test)

Example 4 with ArchiveDescriptor

use of org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor in project wildfly by wildfly.

the class ScannerTest method testExplodedJar.

@Test
public void testExplodedJar() throws Exception {
    File explodedPar = buildExplodedPar();
    addPackageToClasspath(explodedPar);
    String dirPath = explodedPar.getAbsolutePath();
    if (dirPath.endsWith("/")) {
        dirPath = dirPath.substring(0, dirPath.length() - 1);
    }
    final VirtualFile virtualFile = VFS.getChild(dirPath);
    ArchiveDescriptor archiveDescriptor = VirtualFileSystemArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(virtualFile.toURL());
    AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector(new StandardScanOptions());
    archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(new PersistenceUnitDescriptorAdapter(), true, resultCollector));
    assertEquals(1, resultCollector.getClassDescriptorSet().size());
    assertEquals(1, resultCollector.getPackageDescriptorSet().size());
    assertEquals(1, resultCollector.getMappingFileSet().size());
    assertTrue(resultCollector.getClassDescriptorSet().contains(new ClassDescriptorImpl(Carpet.class.getName(), null)));
    for (MappingFileDescriptor mappingFileDescriptor : resultCollector.getMappingFileSet()) {
        assertNotNull(mappingFileDescriptor.getStreamAccess());
        final InputStream stream = mappingFileDescriptor.getStreamAccess().accessInputStream();
        assertNotNull(stream);
        stream.close();
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) MappingFileDescriptor(org.hibernate.jpa.boot.spi.MappingFileDescriptor) AbstractScannerImpl(org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ClassDescriptorImpl(org.hibernate.jpa.boot.internal.ClassDescriptorImpl) ArchiveDescriptor(org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor) Carpet(org.hibernate.jpa.test.pack.explodedpar.Carpet) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File) StandardScanOptions(org.hibernate.jpa.boot.scan.internal.StandardScanOptions) Test(org.junit.Test)

Example 5 with ArchiveDescriptor

use of org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor in project wildfly by wildfly.

the class ScannerTest method testInputStreamZippedJar.

@Test
public void testInputStreamZippedJar() throws Exception {
    File defaultPar = buildDefaultPar();
    addPackageToClasspath(defaultPar);
    final VirtualFile virtualFile = VFS.getChild(defaultPar.getAbsolutePath());
    Closeable closeable = VFS.mountZip(virtualFile, virtualFile, tempFileProvider);
    try {
        ArchiveDescriptor archiveDescriptor = VirtualFileSystemArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(defaultPar.toURI().toURL());
        AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector(new StandardScanOptions());
        archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(new PersistenceUnitDescriptorAdapter(), true, resultCollector));
        validateResults(resultCollector, ApplicationServer.class, Version.class);
    } finally {
        closeable.close();
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) AbstractScannerImpl(org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl) Closeable(java.io.Closeable) ArchiveDescriptor(org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File) StandardScanOptions(org.hibernate.jpa.boot.scan.internal.StandardScanOptions) Test(org.junit.Test)

Aggregations

ArchiveDescriptor (org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor)6 StandardScanOptions (org.hibernate.jpa.boot.scan.internal.StandardScanOptions)6 AbstractScannerImpl (org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl)6 Test (org.junit.Test)6 File (java.io.File)5 VirtualFile (org.jboss.vfs.VirtualFile)5 Closeable (java.io.Closeable)4 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 ClassDescriptorImpl (org.hibernate.jpa.boot.internal.ClassDescriptorImpl)1 MappingFileDescriptor (org.hibernate.jpa.boot.spi.MappingFileDescriptor)1 Carpet (org.hibernate.jpa.test.pack.explodedpar.Carpet)1