HHH-8160 Corrected OSGi scanner
This commit is contained in:
parent
cc4ef44670
commit
73891e06d5
|
@ -20,9 +20,12 @@
|
|||
*/
|
||||
package org.hibernate.osgi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.jpa.boot.archive.spi.ArchiveContext;
|
||||
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor;
|
||||
|
@ -55,9 +58,10 @@ public class OsgiArchiveDescriptor implements ArchiveDescriptor {
|
|||
public void visitArchive(ArchiveContext context) {
|
||||
Collection<String> resources = bundleWiring.listResources( "/", "*", BundleWiring.LISTRESOURCES_RECURSE );
|
||||
for ( final String resource : resources ) {
|
||||
// TODO: Is there a better way to check this? Karaf is including
|
||||
// directories.
|
||||
if ( !resource.endsWith( "/" ) ) {
|
||||
try {
|
||||
final InputStream inputStream = persistenceBundle.getResource( resource ).openStream();
|
||||
|
||||
// TODO: Is using resource as the names correct?
|
||||
|
||||
final InputStreamAccess inputStreamAccess = new InputStreamAccess() {
|
||||
|
@ -68,12 +72,23 @@ public class OsgiArchiveDescriptor implements ArchiveDescriptor {
|
|||
|
||||
@Override
|
||||
public InputStream accessInputStream() {
|
||||
return inputStream;
|
||||
return openInputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamedInputStream asNamedInputStream() {
|
||||
return new NamedInputStream( resource, inputStream );
|
||||
return new NamedInputStream( resource, openInputStream() );
|
||||
}
|
||||
|
||||
private InputStream openInputStream() {
|
||||
try {
|
||||
return persistenceBundle.getResource( resource ).openStream();
|
||||
}
|
||||
catch ( IOException e ) {
|
||||
throw new PersistenceException(
|
||||
"Unable to open an InputStream on the OSGi Bundle resource!",
|
||||
e );
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -102,5 +117,6 @@ public class OsgiArchiveDescriptor implements ArchiveDescriptor {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,15 +22,15 @@ package org.hibernate.osgi;
|
|||
|
||||
import java.net.URL;
|
||||
|
||||
import org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory;
|
||||
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor;
|
||||
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptorFactory;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
/**
|
||||
* @author Brett Meyer
|
||||
* @author Tim Ward
|
||||
*/
|
||||
public class OsgiArchiveDescriptorFactory extends StandardArchiveDescriptorFactory {
|
||||
public class OsgiArchiveDescriptorFactory implements ArchiveDescriptorFactory {
|
||||
|
||||
private Bundle persistenceBundle;
|
||||
|
||||
|
@ -38,12 +38,25 @@ public class OsgiArchiveDescriptorFactory extends StandardArchiveDescriptorFacto
|
|||
this.persistenceBundle = persistenceBundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArchiveDescriptor buildArchiveDescriptor(URL url) {
|
||||
return buildArchiveDescriptor( url, "" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArchiveDescriptor buildArchiveDescriptor(URL url, String entry) {
|
||||
final String protocol = url.getProtocol();
|
||||
if ( "bundle".equals( protocol ) ) {
|
||||
return new OsgiArchiveDescriptor( persistenceBundle );
|
||||
}
|
||||
return super.buildArchiveDescriptor( url, entry );
|
||||
|
||||
@Override
|
||||
public URL getJarURLFromURLEntry(URL url, String entry) throws IllegalArgumentException {
|
||||
// not used
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getURLFromPath(String jarPath) {
|
||||
// not used
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class OsgiPersistenceProvider extends HibernatePersistenceProvider {
|
|||
}
|
||||
properties.put( AvailableSettings.JTA_PLATFORM, osgiJtaPlatform );
|
||||
// TODO: This needs tested.
|
||||
properties.put( org.hibernate.ejb.AvailableSettings.SCANNER,
|
||||
properties.put( org.hibernate.jpa.AvailableSettings.SCANNER,
|
||||
new OsgiScanner( requestingBundle ) );
|
||||
|
||||
osgiClassLoader.addBundle( requestingBundle );
|
||||
|
@ -79,7 +79,7 @@ public class OsgiPersistenceProvider extends HibernatePersistenceProvider {
|
|||
}
|
||||
properties.put( AvailableSettings.JTA_PLATFORM, osgiJtaPlatform );
|
||||
// OSGi ClassLoaders must implement BundleReference
|
||||
properties.put( org.hibernate.ejb.AvailableSettings.SCANNER,
|
||||
properties.put( org.hibernate.jpa.AvailableSettings.SCANNER,
|
||||
new OsgiScanner( ( (BundleReference) info.getClassLoader() ).getBundle() ) );
|
||||
|
||||
osgiClassLoader.addClassLoader( info.getClassLoader() );
|
||||
|
|
Loading…
Reference in New Issue