HHH-9143 - Build baseline Jandex as part of scanning

This commit is contained in:
Steve Ebersole 2014-05-05 12:39:14 -05:00
parent 20d3b62f12
commit f410417f25
71 changed files with 1621 additions and 1165 deletions

View File

@ -207,6 +207,28 @@ subprojects { subProject ->
]
}
compileJava {
File mainAptDir = mkdir( "${subProject.buildDir}/generated-src/apt/main" )
options.compilerArgs += [ "-s", "$mainAptDir.absolutePath" ]
doFirst {
if ( !mainAptDir.exists() ) {
mainAptDir.mkdirs();
}
}
}
compileTestJava {
File testAptDir = mkdir( "${subProject.buildDir}/generated-src/apt/test" );
options.compilerArgs += [ "-s", "$testAptDir.absolutePath" ]
doFirst {
if ( !testAptDir.exists() ) {
testAptDir.mkdirs();
}
}
}
jar {
manifest = osgiManifest {
// GRADLE-1411: Even if we override Imports and Exports

View File

@ -764,4 +764,49 @@ public interface AvailableSettings {
String AUTO_SESSION_EVENTS_LISTENER = "hibernate.session.events.auto";
/**
* Names a Jandex {@link org.jboss.jandex.Index} instance to use.
*/
String JANDEX_INDEX = "hibernate.jandex_index";
/**
* The deprecated name. Use {@link #SCANNER} instead.
*/
String SCANNER_DEPRECATED = "hibernate.ejb.resource_scanner";
/**
* Pass an implementation of {@link org.hibernate.metamodel.archive.scan.spi.Scanner}.
* Accepts either:<ul>
* <li>an actual instance</li>
* <li>a reference to a Class that implements Scanner</li>
* <li>a fully qualified name (String) of a Class that implements Scanner</li>
* </ul>
*/
String SCANNER = "hibernate.archive.scanner";
/**
* Pass {@link org.hibernate.metamodel.archive.spi.ArchiveDescriptorFactory} to use
* in the scanning process. Accepts either:<ul>
* <li>an ArchiveDescriptorFactory instance</li>
* <li>a reference to a Class that implements ArchiveDescriptorFactory</li>
* <li>a fully qualified name (String) of a Class that implements ArchiveDescriptorFactory</li>
* </ul>
* <p/>
* See information on {@link org.hibernate.metamodel.archive.scan.spi.Scanner}
* about expected constructor forms.
*
* @see #SCANNER
* @see org.hibernate.metamodel.archive.scan.spi.Scanner
* @see org.hibernate.metamodel.archive.scan.spi.AbstractScannerImpl
*/
String SCANNER_ARCHIVE_INTERPRETER = "hibernate.archive.interpreter";
/**
* Identifies a comma-separate list of values indicating the types of
* things we should auto-detect during scanning. Allowable values include:<ul>
* <li>"class" - discover classes - .class files are discovered as managed classes</li>
* <li>"hbm" - discover hbm mapping files - hbm.xml files are discovered as mapping files</li>
* </ul>
*/
String SCANNER_DISCOVERY = "hibernate.archive.autodetection";
}

View File

@ -0,0 +1,57 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.internal;
import org.jboss.logging.Logger;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageLogger;
import org.jboss.logging.annotations.ValidIdRange;
import static org.jboss.logging.Logger.Level.INFO;
/**
* Class to consolidate logging about usage of deprecated features.
*
* @author Steve Ebersole
*/
@MessageLogger( projectCode = "HHH" )
@ValidIdRange( min = 90000001, max = 90001000 )
public interface DeprecationLogger {
public static final DeprecationLogger DEPRECATION_LOGGER = Logger.getMessageLogger(
DeprecationLogger.class,
"org.hibernate.orm.deprecation"
);
/**
* Log about usage of deprecated Scanner setting
*/
@LogMessage( level = INFO )
@Message(
value = "Found usage of deprecated setting for specifying Scanner [hibernate.ejb.resource_scanner]; " +
"use [hibernate.archive.scanner] instead",
id = 90000001
)
public void logScannerDeprecation();
}

View File

@ -0,0 +1,111 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.internal;
import java.net.URISyntaxException;
import java.net.URL;
import org.jboss.logging.Logger;
import org.jboss.logging.annotations.Cause;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageBundle;
import org.jboss.logging.annotations.MessageLogger;
import static org.jboss.logging.Logger.Level.WARN;
/**
* Acts as the {@link org.jboss.logging.annotations.MessageLogger} and
* {@link org.jboss.logging.annotations.MessageBundle} for messages related to
* processing URLs.
*
* @author Steve Ebersole
*/
@MessageLogger( projectCode = "HHH" )
//@MessageBundle( projectCode = "HHH" )
public interface UrlMessageBundle {
public static final UrlMessageBundle URL_LOGGER = Logger.getMessageLogger(
UrlMessageBundle.class,
"org.hibernate.orm.url"
);
/**
* Logs a warning about a malformed URL, caused by a {@link URISyntaxException}
*
* @param jarUrl The URL that lead to the {@link URISyntaxException}
* @param e The underlying URISyntaxException
*/
@LogMessage( level = WARN )
@Message( value = "Malformed URL: %s", id = 100001 )
void logMalformedUrl(URL jarUrl, @Cause URISyntaxException e);
/**
* Logs a warning about not being able to find a file by a specified URL. This is different
* from {@link #logFileDoesNotExist}.
*
* @param url The URL is supposed to identify the file which we cannot locate
* @param e The underlying URISyntaxException
*/
@LogMessage( level = WARN )
@Message( value = "File or directory named by URL [%s] could not be found. URL will be ignored", id = 100002 )
void logUnableToFindFileByUrl(URL url, @Cause Exception e);
/**
* Logs a warning that the File (file/directory) to which the URL resolved
* reported that it did not exist.
*
* @param url The URL that named the file/directory
*
* @see java.io.File#exists()
*/
@LogMessage( level = WARN )
@Message( value = "File or directory named by URL [%s] did not exist. URL will be ignored", id = 100003 )
void logFileDoesNotExist(URL url);
/**
* Logs a warning indicating that the URL resolved to a File that we were expecting
* to be a directory, but {@link java.io.File#isDirectory()} reported it was not.
*
* @param url The URL that named the file/directory
*
* @see java.io.File#isDirectory()
*/
@LogMessage( level = WARN )
@Message( value = "Expecting resource named by URL [%s] to be a directory, but it was not. URL will be ignored", id = 100004 )
void logFileIsNotDirectory(URL url);
/**
* Access to the exception message used when a URL references names a file that does not exist.
* <p/>
* TODO : detail when this is a warning {@link #logFileDoesNotExist} versus an exception...
*
* @param filePart The "file part" that we gleaned from the URL
* @param url The given URL
*
* @return The message
*/
@Message( value = "File [%s] referenced by given URL [%s] does not exist", id = 100005 )
String fileDoesNotExist(String filePart, URL url);
}

View File

@ -28,6 +28,10 @@ import javax.persistence.SharedCacheMode;
import org.hibernate.boot.spi.CacheRegionDefinition;
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.metamodel.archive.scan.spi.ScanEnvironment;
import org.hibernate.metamodel.archive.scan.spi.ScanOptions;
import org.hibernate.metamodel.archive.scan.spi.Scanner;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.metamodel.spi.PersistentAttributeMemberResolver;
import org.hibernate.metamodel.spi.TypeContributor;
import org.hibernate.type.BasicType;
@ -109,6 +113,42 @@ public interface MetadataBuilder {
*/
public MetadataBuilder with(IndexView jandexView);
/**
* Specify the options to be used in performing scanning.
*
* @param scanOptions The scan options.
*
* @return {@code this}, for method chaining
*/
public MetadataBuilder with(ScanOptions scanOptions);
/**
* Consider this temporary as discussed on {@link ScanEnvironment}
*
* @param scanEnvironment The environment for scanning
*
* @return {@code this}, for method chaining
*/
public MetadataBuilder with(ScanEnvironment scanEnvironment);
/**
* Specify a particular Scanner instance to use.
*
* @param scanner The scanner to use.
*
* @return {@code this}, for method chaining
*/
public MetadataBuilder with(Scanner scanner);
/**
* Specify a particular ArchiveDescriptorFactory instance to use in scanning.
*
* @param factory The ArchiveDescriptorFactory to use.
*
* @return {@code this}, for method chaining
*/
public MetadataBuilder with(ArchiveDescriptorFactory factory);
/**
* Should the new (well "new" since 3.2) identifier generators be used for
* {@link javax.persistence.GenerationType#SEQUENCE},

View File

@ -33,28 +33,23 @@ import java.io.Serializable;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import javax.persistence.AttributeConverter;
import org.hibernate.HibernateException;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.SerializationHelper;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.internal.ClassLoaderAccessImpl;
import org.hibernate.metamodel.internal.JandexInitManager;
import org.hibernate.metamodel.internal.MetadataBuilderImpl;
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
import org.hibernate.metamodel.source.internal.jaxb.JaxbConverter;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbeddable;
import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity;
@ -64,11 +59,6 @@ import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityMappings;
import org.hibernate.metamodel.source.internal.jaxb.JaxbMappedSuperclass;
import org.hibernate.metamodel.source.internal.jaxb.JaxbPersistenceUnitDefaults;
import org.hibernate.metamodel.source.internal.jaxb.JaxbPersistenceUnitMetadata;
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbClassElement;
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbHibernateMapping;
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbJoinedSubclassElement;
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSubclassElement;
import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbUnionSubclassElement;
import org.hibernate.metamodel.source.spi.InvalidMappingException;
import org.hibernate.metamodel.source.spi.MappingException;
import org.hibernate.metamodel.source.spi.MappingNotFoundException;
@ -79,13 +69,8 @@ import org.hibernate.xml.spi.BindResult;
import org.hibernate.xml.spi.Origin;
import org.hibernate.xml.spi.SourceType;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import org.jboss.jandex.IndexView;
import org.jboss.jandex.Indexer;
import org.jboss.jandex.Type;
import org.jboss.logging.Logger;
import org.w3c.dom.Document;
@ -564,6 +549,10 @@ public class MetadataSources {
return this;
}
/**
* @deprecated Use {@link #indexKnownClasses} instead
*/
@Deprecated
public IndexView buildJandexView() {
return buildJandexView( false );
}
@ -573,46 +562,55 @@ public class MetadataSources {
*
* @param autoIndexMemberTypes Should the types of class members automatically be added to the built index?
*
* @return
* @return The built Jandex Index
*
* @deprecated Use {@link #indexKnownClasses} instead
*/
@Deprecated
public IndexView buildJandexView(boolean autoIndexMemberTypes) {
return JandexIndexBuilder.process( autoIndexMemberTypes, this );
JandexInitManager jandexInitManager = new JandexInitManager(
null,
new ClassLoaderAccessImpl(
null,
getServiceRegistry().getService( ClassLoaderService.class )
),
autoIndexMemberTypes
);
JandexIndexBuilder.process( jandexInitManager, this );
return jandexInitManager.buildIndex();
}
public void indexKnownClasses(JandexInitManager jandexInitManager) {
JandexIndexBuilder.process( jandexInitManager, this );
}
public static class JandexIndexBuilder {
private static final Logger log = Logger.getLogger( JandexIndexBuilder.class );
private final DotName OBJECT_DOT_NAME = DotName.createSimple( Object.class.getName() );
private final JandexInitManager jandexInitManager;
private final boolean autoIndexMemberTypes;
private final ClassLoaderService classLoaderService;
private final Indexer indexer = new Indexer();
private final Set<DotName> processedClassNames = new HashSet<DotName>();
private JandexIndexBuilder(boolean autoIndexMemberTypes, ServiceRegistry serviceRegistry) {
this.classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
this.autoIndexMemberTypes = autoIndexMemberTypes;
private JandexIndexBuilder(JandexInitManager jandexInitManager) {
this.jandexInitManager = jandexInitManager;
}
public static IndexView process(boolean autoIndexMemberTypes, MetadataSources sources) {
return new JandexIndexBuilder( autoIndexMemberTypes, sources.getServiceRegistry() ).process( sources );
public static void process(JandexInitManager jandexInitManager, MetadataSources sources) {
new JandexIndexBuilder( jandexInitManager ).process( sources );
}
private IndexView process(MetadataSources sources) {
private void process(MetadataSources sources) {
// start off with any already-loaded Class references...
for ( Class<?> clazz : sources.getAnnotatedClasses() ) {
indexLoadedClass( clazz );
jandexInitManager.indexLoadedClass( clazz );
}
if ( sources.converterClasses != null ) {
for ( Class<? extends AttributeConverter> converterClass : sources.converterClasses ) {
indexLoadedClass( converterClass );
jandexInitManager.indexLoadedClass( converterClass );
}
}
for ( String className : sources.getAnnotatedClassNames() ) {
indexClassName( DotName.createSimple( className ) );
jandexInitManager.indexClassName( DotName.createSimple( className ) );
}
// add package-info from the configured packages
@ -620,7 +618,7 @@ public class MetadataSources {
// older code seemed to simply ignore packages that did not have package-info,
// so do same
try {
indexResource( packageName.replace( '.', '/' ) + "/package-info.class" );
jandexInitManager.indexResource( packageName.replace( '.', '/' ) + "/package-info.class" );
}
catch (Exception e) {
log.debugf( "Skipping package [%s] which caused error indexing : %s", packageName, e.getMessage() );
@ -636,164 +634,6 @@ public class MetadataSources {
}
}
}
final Index jandexIndex = indexer.complete();
if ( log.isTraceEnabled() ) {
jandexIndex.printSubclasses();
jandexIndex.printAnnotations();
}
return jandexIndex;
}
private void indexLoadedClass(Class loadedClass) {
if ( loadedClass == null ) {
return;
}
final DotName classDotName = DotName.createSimple( loadedClass.getName() );
if ( !needsProcessing( classDotName ) ) {
return;
}
// index super type first
indexLoadedClass( loadedClass.getSuperclass() );
// index any inner classes
for ( Class innerClass : loadedClass.getDeclaredClasses() ) {
indexLoadedClass( innerClass );
}
// then index the class itself
ClassInfo classInfo = indexResource( loadedClass.getName().replace( '.', '/' ) + ".class" );
if ( !autoIndexMemberTypes ) {
return;
}
for ( Class<?> fieldType : ReflectHelper.getMemberTypes( loadedClass ) ) {
if ( !fieldType.isPrimitive() && fieldType != Object.class ) {
indexLoadedClass( fieldType );
}
}
// Also check for classes within a @Target annotation.
// [steve] - not so sure about this. target would name an entity, which should be
// known to us somehow
for ( AnnotationInstance targetAnnotation : JandexHelper.getAnnotations( classInfo, HibernateDotNames.TARGET ) ) {
String targetClassName = targetAnnotation.value().asClass().name().toString();
Class<?> targetClass = classLoaderService.classForName( targetClassName );
indexLoadedClass( targetClass );
}
}
private boolean needsProcessing(DotName classDotName) {
if ( classDotName == null || OBJECT_DOT_NAME.equals( classDotName ) ) {
return false;
}
if ( processedClassNames.contains( classDotName ) ) {
return false;
}
processedClassNames.add( classDotName );
return true;
}
private ClassInfo indexResource(String resourceName) {
final URL resourceUrl = classLoaderService.locateResource( resourceName );
if ( resourceUrl == null ) {
throw new IllegalArgumentException( "Could not locate resource [" + resourceName + "]" );
}
try {
final InputStream stream = resourceUrl.openStream();
try {
final ClassInfo classInfo = indexer.index( stream );
furtherProcess( classInfo );
return classInfo;
}
catch ( IOException e ) {
throw new HibernateException( "Unable to index from resource stream [" + resourceName + "]", e );
}
finally {
try {
stream.close();
}
catch ( IOException e ) {
log.debug( "Unable to close resource stream [" + resourceName + "] : " + e.getMessage() );
}
}
}
catch ( IOException e ) {
throw new HibernateException( "Unable to open input stream for resource [" + resourceName + "]", e );
}
}
private void furtherProcess(ClassInfo classInfo) {
final List<AnnotationInstance> entityListenerAnnotations = classInfo.annotations().get( JPADotNames.ENTITY_LISTENERS );
if ( entityListenerAnnotations != null ) {
for ( AnnotationInstance entityListenerAnnotation : entityListenerAnnotations ) {
final Type[] entityListenerClassTypes = entityListenerAnnotation.value().asClassArray();
for ( Type entityListenerClassType : entityListenerClassTypes ) {
indexClassName( entityListenerClassType.name() );
}
}
}
// todo : others?
}
private void indexClassName(DotName classDotName) {
if ( !needsProcessing( classDotName ) ) {
return;
}
ClassInfo classInfo = indexResource( classDotName.toString().replace( '.', '/' ) + ".class" );
if ( classInfo.superName() != null ) {
indexClassName( classInfo.superName() );
}
}
private void indexHbmReferences(JaxbHibernateMapping hbmRoot) {
final String packageName = hbmRoot.getPackage();
for ( JaxbClassElement hbmRootClass : hbmRoot.getClazz() ) {
if ( StringHelper.isNotEmpty( hbmRootClass.getName() ) ) {
indexClassName( toDotName( hbmRootClass.getName(), packageName ) );
for ( JaxbSubclassElement hbmSubclassElement : hbmRootClass.getSubclass() ) {
processHbmSubclass( hbmSubclassElement, packageName );
}
for ( JaxbJoinedSubclassElement hbmJoinedSubclass : hbmRootClass.getJoinedSubclass() ) {
processHbmJoinedSubclass( hbmJoinedSubclass, packageName );
}
for ( JaxbUnionSubclassElement hbmUnionSubclass : hbmRoot.getUnionSubclass() ) {
processHbmUnionSubclass( hbmUnionSubclass, packageName );
}
}
}
for ( JaxbSubclassElement hbmSubclassElement : hbmRoot.getSubclass() ) {
if ( StringHelper.isNotEmpty( hbmSubclassElement.getName() ) ) {
processHbmSubclass( hbmSubclassElement, packageName );
}
}
for ( JaxbJoinedSubclassElement hbmJoinedSubclass : hbmRoot.getJoinedSubclass() ) {
if ( StringHelper.isNotEmpty( hbmJoinedSubclass.getName() ) ) {
processHbmJoinedSubclass( hbmJoinedSubclass, packageName );
}
}
for ( JaxbUnionSubclassElement hbmUnionSubclass : hbmRoot.getUnionSubclass() ) {
if ( StringHelper.isNotEmpty( hbmUnionSubclass.getName() ) ) {
processHbmUnionSubclass( hbmUnionSubclass, packageName );
}
}
}
private DotName toDotName(String className, String packageName) {
@ -806,30 +646,6 @@ public class MetadataSources {
return DotName.createSimple( className );
}
private void processHbmSubclass(JaxbSubclassElement hbmSubclassElement, String packageName) {
indexClassName( toDotName( hbmSubclassElement.getName(), packageName ) );
for ( JaxbSubclassElement hbmSubclassElement2 : hbmSubclassElement.getSubclass() ) {
processHbmSubclass( hbmSubclassElement2, packageName );
}
}
private void processHbmJoinedSubclass(JaxbJoinedSubclassElement hbmJoinedSubclass, String packageName) {
indexClassName( toDotName( hbmJoinedSubclass.getName(), packageName ) );
for ( JaxbJoinedSubclassElement hbmJoinedSubclass2 : hbmJoinedSubclass.getJoinedSubclass() ) {
processHbmJoinedSubclass( hbmJoinedSubclass2, packageName );
}
}
private void processHbmUnionSubclass(JaxbUnionSubclassElement hbmUnionSubclass, String packageName) {
indexClassName( toDotName( hbmUnionSubclass.getName(), packageName ) );
for ( JaxbUnionSubclassElement hbmUnionSubclass2 : hbmUnionSubclass.getUnionSubclass() ) {
processHbmUnionSubclass( hbmUnionSubclass2, packageName );
}
}
private boolean isMappingMetadataComplete(JaxbEntityMappings ormXmlRoot) {
return ormXmlRoot.getPersistenceUnitMetadata() != null
&& ormXmlRoot.getPersistenceUnitMetadata().getXmlMappingMetadataComplete() != null;
@ -847,19 +663,19 @@ public class MetadataSources {
}
for ( JaxbConverter jaxbConverter : ormXmlRoot.getConverter() ) {
indexClassName( toDotName( jaxbConverter.getClazz(), packageName ) );
jandexInitManager.indexClassName( toDotName( jaxbConverter.getClazz(), packageName ) );
}
for ( JaxbEmbeddable jaxbEmbeddable : ormXmlRoot.getEmbeddable() ) {
indexClassName( toDotName( jaxbEmbeddable.getClazz(), packageName ) );
jandexInitManager.indexClassName( toDotName( jaxbEmbeddable.getClazz(), packageName ) );
}
for ( JaxbMappedSuperclass jaxbMappedSuperclass : ormXmlRoot.getMappedSuperclass() ) {
indexClassName( toDotName( jaxbMappedSuperclass.getClazz(), packageName ) );
jandexInitManager.indexClassName( toDotName( jaxbMappedSuperclass.getClazz(), packageName ) );
}
for ( JaxbEntity jaxbEntity : ormXmlRoot.getEntity() ) {
indexClassName( toDotName( jaxbEntity.getClazz(), packageName ) );
jandexInitManager.indexClassName( toDotName( jaxbEntity.getClazz(), packageName ) );
indexEntityListeners( jaxbEntity.getEntityListeners(), packageName );
}
}
@ -871,7 +687,7 @@ public class MetadataSources {
for ( JaxbEntityListener listener : listeners.getEntityListener() ) {
if ( StringHelper.isNotEmpty( listener.getClazz() ) ) {
indexClassName( toDotName( listener.getClazz(), packageName ) );
jandexInitManager.indexClassName( toDotName( listener.getClazz(), packageName ) );
}
}
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.archive.internal;
package org.hibernate.metamodel.archive.internal;
import java.io.File;
import java.io.IOException;
@ -31,7 +31,7 @@ import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import org.hibernate.jpa.boot.archive.spi.ArchiveException;
import org.hibernate.metamodel.archive.spi.ArchiveException;
import org.jboss.logging.Logger;
@ -143,7 +143,7 @@ public class ArchiveHelper {
/**
* Extracts the bytes out of an InputStream. This form is the same as {@link #getBytesFromInputStream}
* except that any {@link IOException} are wrapped as (runtime) {@link ArchiveException}
* except that any {@link java.io.IOException} are wrapped as (runtime) {@link ArchiveException}
*
* @param inputStream The stream from which to extract bytes.
*
@ -167,7 +167,7 @@ public class ArchiveHelper {
*
* @return The bytes
*
* @throws IOException Indicates a problem accessing the stream
* @throws java.io.IOException Indicates a problem accessing the stream
*
* @see #getBytesFromInputStreamSafely(java.io.InputStream)
*/

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,13 +21,12 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.internal;
package org.hibernate.metamodel.archive.internal;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.hibernate.jpa.boot.spi.InputStreamAccess;
import org.hibernate.jpa.boot.spi.NamedInputStream;
import org.hibernate.metamodel.archive.spi.InputStreamAccess;
/**
* An InputStreamAccess implementation based on a byte array
@ -52,9 +51,4 @@ public class ByteArrayInputStreamAccess implements InputStreamAccess {
public InputStream accessInputStream() {
return new ByteArrayInputStream( bytes );
}
@Override
public NamedInputStream asNamedInputStream() {
return new NamedInputStream( getStreamName(), accessInputStream() );
}
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.archive.internal;
package org.hibernate.metamodel.archive.internal;
import java.io.File;
import java.io.IOException;
@ -31,16 +31,14 @@ import java.util.Enumeration;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import org.hibernate.jpa.boot.archive.spi.AbstractArchiveDescriptor;
import org.hibernate.jpa.boot.archive.spi.ArchiveContext;
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.jpa.boot.archive.spi.ArchiveEntry;
import org.hibernate.jpa.boot.archive.spi.ArchiveException;
import org.hibernate.jpa.boot.internal.FileInputStreamAccess;
import org.hibernate.jpa.boot.spi.InputStreamAccess;
import org.hibernate.jpa.internal.EntityManagerMessageLogger;
import org.hibernate.metamodel.archive.spi.AbstractArchiveDescriptor;
import org.hibernate.metamodel.archive.spi.ArchiveContext;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.metamodel.archive.spi.ArchiveEntry;
import org.hibernate.metamodel.archive.spi.ArchiveException;
import org.hibernate.metamodel.archive.spi.InputStreamAccess;
import org.jboss.logging.Logger;
import static org.hibernate.internal.UrlMessageBundle.URL_LOGGER;
/**
* Descriptor for exploded (directory) archives
@ -48,11 +46,6 @@ import org.jboss.logging.Logger;
* @author Steve Ebersole
*/
public class ExplodedArchiveDescriptor extends AbstractArchiveDescriptor {
private static final EntityManagerMessageLogger LOG = Logger.getMessageLogger(
EntityManagerMessageLogger.class,
ExplodedArchiveDescriptor.class.getName()
);
/**
* Constructs an ExplodedArchiveDescriptor
*
@ -96,16 +89,16 @@ public class ExplodedArchiveDescriptor extends AbstractArchiveDescriptor {
}
}
catch (URISyntaxException e) {
LOG.malformedUrl( getArchiveUrl(), e );
URL_LOGGER.logMalformedUrl( getArchiveUrl(), e );
return null;
}
if ( !archiveUrlDirectory.exists() ) {
LOG.explodedJarDoesNotExist( getArchiveUrl() );
URL_LOGGER.logFileDoesNotExist( getArchiveUrl() );
return null;
}
if ( !archiveUrlDirectory.isDirectory() ) {
LOG.explodedJarNotDirectory( getArchiveUrl() );
URL_LOGGER.logFileIsNotDirectory( getArchiveUrl() );
return null;
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.internal;
package org.hibernate.metamodel.archive.internal;
import java.io.BufferedInputStream;
import java.io.File;
@ -30,9 +30,8 @@ import java.io.FileNotFoundException;
import java.io.InputStream;
import org.hibernate.HibernateException;
import org.hibernate.jpa.boot.archive.spi.ArchiveException;
import org.hibernate.jpa.boot.spi.InputStreamAccess;
import org.hibernate.jpa.boot.spi.NamedInputStream;
import org.hibernate.metamodel.archive.spi.ArchiveException;
import org.hibernate.metamodel.archive.spi.InputStreamAccess;
/**
* An InputStreamAccess implementation based on a File reference
@ -69,9 +68,4 @@ public class FileInputStreamAccess implements InputStreamAccess {
);
}
}
@Override
public NamedInputStream asNamedInputStream() {
return new NamedInputStream( getStreamName(), accessInputStream() );
}
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.archive.internal;
package org.hibernate.metamodel.archive.internal;
import java.io.BufferedInputStream;
import java.io.IOException;
@ -33,28 +33,22 @@ import java.util.jar.JarFile;
import java.util.jar.JarInputStream;
import java.util.zip.ZipEntry;
import org.hibernate.jpa.boot.archive.spi.AbstractArchiveDescriptor;
import org.hibernate.jpa.boot.archive.spi.ArchiveContext;
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.jpa.boot.archive.spi.ArchiveEntry;
import org.hibernate.jpa.boot.archive.spi.ArchiveEntryHandler;
import org.hibernate.jpa.boot.archive.spi.ArchiveException;
import org.hibernate.jpa.boot.spi.InputStreamAccess;
import org.hibernate.jpa.internal.EntityManagerMessageLogger;
import org.hibernate.metamodel.archive.spi.AbstractArchiveDescriptor;
import org.hibernate.metamodel.archive.spi.ArchiveContext;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.metamodel.archive.spi.ArchiveEntry;
import org.hibernate.metamodel.archive.spi.ArchiveEntryHandler;
import org.hibernate.metamodel.archive.spi.ArchiveException;
import org.hibernate.metamodel.archive.spi.InputStreamAccess;
import org.jboss.logging.Logger;
import static org.hibernate.internal.UrlMessageBundle.URL_LOGGER;
/**
* An ArchiveDescriptor implementation leveraging the {@link JarFile} API for processing.
* An ArchiveDescriptor implementation leveraging the {@link java.util.jar.JarFile} API for processing.
*
* @author Steve Ebersole
*/
public class JarFileBasedArchiveDescriptor extends AbstractArchiveDescriptor {
private static final EntityManagerMessageLogger LOG = Logger.getMessageLogger(
EntityManagerMessageLogger.class,
JarFileBasedArchiveDescriptor.class.getName()
);
/**
* Constructs a JarFileBasedArchiveDescriptor
*
@ -103,8 +97,7 @@ public class JarFileBasedArchiveDescriptor extends AbstractArchiveDescriptor {
final String name = extractName( subZipEntry );
final String relativeName = extractRelativeName( subZipEntry );
final InputStreamAccess inputStreamAccess
= buildByteBasedInputStreamAccess( name, jarInputStream );
final InputStreamAccess inputStreamAccess = buildByteBasedInputStreamAccess( name, jarInputStream );
final ArchiveEntry entry = new ArchiveEntry() {
@Override
@ -190,10 +183,10 @@ public class JarFileBasedArchiveDescriptor extends AbstractArchiveDescriptor {
}
}
catch (IOException e) {
LOG.unableToFindFile( getArchiveUrl(), e );
URL_LOGGER.logUnableToFindFileByUrl( getArchiveUrl(), e );
}
catch (URISyntaxException e) {
LOG.malformedUrlWarning( getArchiveUrl(), e );
URL_LOGGER.logMalformedUrl( getArchiveUrl(), e );
}
return null;
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.archive.internal;
package org.hibernate.metamodel.archive.internal;
import java.io.IOException;
import java.net.URL;
@ -29,15 +29,14 @@ import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
import java.util.zip.ZipEntry;
import org.hibernate.jpa.boot.archive.spi.AbstractArchiveDescriptor;
import org.hibernate.jpa.boot.archive.spi.ArchiveContext;
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.jpa.boot.archive.spi.ArchiveEntry;
import org.hibernate.jpa.boot.archive.spi.ArchiveException;
import org.hibernate.jpa.boot.spi.InputStreamAccess;
import org.hibernate.jpa.internal.EntityManagerMessageLogger;
import org.hibernate.metamodel.archive.spi.AbstractArchiveDescriptor;
import org.hibernate.metamodel.archive.spi.ArchiveContext;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.metamodel.archive.spi.ArchiveEntry;
import org.hibernate.metamodel.archive.spi.ArchiveException;
import org.hibernate.metamodel.archive.spi.InputStreamAccess;
import org.jboss.logging.Logger;
import static org.hibernate.internal.UrlMessageBundle.URL_LOGGER;
/**
* An ArchiveDescriptor implementation that works on archives accessible through a {@link java.util.jar.JarInputStream}.
@ -47,10 +46,6 @@ import org.jboss.logging.Logger;
* @author Steve Ebersole
*/
public class JarInputStreamBasedArchiveDescriptor extends AbstractArchiveDescriptor {
private static final EntityManagerMessageLogger LOG = Logger.getMessageLogger(
EntityManagerMessageLogger.class,
JarInputStreamBasedArchiveDescriptor.class.getName()
);
/**
* Constructs a JarInputStreamBasedArchiveDescriptor
@ -74,7 +69,7 @@ public class JarInputStreamBasedArchiveDescriptor extends AbstractArchiveDescrip
}
catch (Exception e) {
//really should catch IOException but Eclipse is buggy and raise NPE...
LOG.unableToFindFile( getArchiveUrl(), e );
URL_LOGGER.logUnableToFindFileByUrl( getArchiveUrl(), e );
return;
}
@ -102,8 +97,7 @@ public class JarInputStreamBasedArchiveDescriptor extends AbstractArchiveDescrip
while (subZipEntry != null) {
if ( ! subZipEntry.isDirectory() ) {
final String subName = extractName( subZipEntry );
final InputStreamAccess inputStreamAccess
= buildByteBasedInputStreamAccess( subName, subJarInputStream );
final InputStreamAccess inputStreamAccess = buildByteBasedInputStreamAccess( subName, subJarInputStream );
final ArchiveEntry entry = new ArchiveEntry() {
@Override

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,14 +21,14 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.archive.internal;
package org.hibernate.metamodel.archive.internal;
import java.net.URL;
import org.hibernate.annotations.common.AssertionFailure;
import org.hibernate.jpa.boot.archive.spi.ArchiveContext;
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor;
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.metamodel.archive.spi.ArchiveContext;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptor;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptorFactory;
/**
* An ArchiveDescriptor implementation for handling archives whose url reported a JAR protocol (i.e., jar://).

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,15 +21,18 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.archive.internal;
package org.hibernate.metamodel.archive.internal;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import org.hibernate.metamodel.archive.spi.AbstractArchiveDescriptorFactory;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptor;
import org.hibernate.metamodel.archive.spi.ArchiveException;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor;
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptorFactory;
import static org.hibernate.internal.UrlMessageBundle.URL_LOGGER;
/**
* Standard implementation of ArchiveDescriptorFactory
@ -37,17 +40,12 @@ import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptorFactory;
* @author Emmanuel Bernard
* @author Steve Ebersole
*/
public class StandardArchiveDescriptorFactory implements ArchiveDescriptorFactory {
public class StandardArchiveDescriptorFactory extends AbstractArchiveDescriptorFactory {
/**
* Singleton access
*/
public static final StandardArchiveDescriptorFactory INSTANCE = new StandardArchiveDescriptorFactory();
@Override
public ArchiveDescriptor buildArchiveDescriptor(URL url) {
return buildArchiveDescriptor( url, "" );
}
@Override
public ArchiveDescriptor buildArchiveDescriptor(URL url, String entry) {
final String protocol = url.getProtocol();
@ -70,19 +68,11 @@ public class StandardArchiveDescriptorFactory implements ArchiveDescriptorFactor
}
if ( ! file.exists() ) {
throw new IllegalArgumentException(
String.format(
"File [%s] referenced by given URL [%s] does not exist",
filePart,
url.toExternalForm()
)
);
throw new ArchiveException( URL_LOGGER.fileDoesNotExist( filePart, url ) );
}
}
catch (URISyntaxException e) {
throw new IllegalArgumentException(
"Unable to visit JAR " + url + ". Cause: " + e.getMessage(), e
);
throw new ArchiveException( "Unable to visit JAR : " + url, e );
}
if ( file.isDirectory() ) {
@ -97,14 +87,4 @@ public class StandardArchiveDescriptorFactory implements ArchiveDescriptorFactor
return new JarInputStreamBasedArchiveDescriptor( this, url, entry );
}
}
@Override
public URL getJarURLFromURLEntry(URL url, String entry) throws IllegalArgumentException {
return ArchiveHelper.getJarURLFromURLEntry( url, entry );
}
@Override
public URL getURLFromPath(String jarPath) {
return ArchiveHelper.getURLFromPath( jarPath );
}
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,14 +21,13 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.internal;
package org.hibernate.metamodel.archive.internal;
import java.io.InputStream;
import java.net.URL;
import org.hibernate.HibernateException;
import org.hibernate.jpa.boot.spi.InputStreamAccess;
import org.hibernate.jpa.boot.spi.NamedInputStream;
import org.hibernate.metamodel.archive.spi.ArchiveException;
import org.hibernate.metamodel.archive.spi.InputStreamAccess;
/**
* @author Steve Ebersole
@ -51,12 +50,7 @@ public class UrlInputStreamAccess implements InputStreamAccess {
return url.openStream();
}
catch (Exception e) {
throw new HibernateException( "Could not open url stream : " + url.toExternalForm() );
throw new ArchiveException( "Could not open url stream : " + url.toExternalForm() );
}
}
@Override
public NamedInputStream asNamedInputStream() {
return new NamedInputStream( getStreamName(), accessInputStream() );
}
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,12 +21,8 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.spi;
/**
* @author Steve Ebersole
* The internals of archive scanning support
*/
public interface MappingFileDescriptor {
public String getName();
public InputStreamAccess getStreamAccess();
}
package org.hibernate.metamodel.archive.internal;

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,10 +21,10 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.internal;
package org.hibernate.metamodel.archive.scan.internal;
import org.hibernate.jpa.boot.spi.ClassDescriptor;
import org.hibernate.jpa.boot.spi.InputStreamAccess;
import org.hibernate.metamodel.archive.scan.spi.ClassDescriptor;
import org.hibernate.metamodel.archive.spi.InputStreamAccess;
/**
* @author Steve Ebersole

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,33 +21,30 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.spi;
package org.hibernate.metamodel.archive.scan.internal;
import java.io.InputStream;
import org.hibernate.metamodel.archive.scan.spi.MappingFileDescriptor;
import org.hibernate.metamodel.archive.spi.InputStreamAccess;
/**
* Bundles together a stream and the name that was used to locate it. The name is often useful for logging.
*
* @deprecated Use {@link org.hibernate.jpa.boot.spi.InputStreamAccess} instead.
*
* @author Emmanuel Bernard
* @author Steve Ebersole
*/
@Deprecated
public class NamedInputStream {
public class MappingFileDescriptorImpl implements MappingFileDescriptor {
private final String name;
private final InputStream stream;
private final InputStreamAccess streamAccess;
public NamedInputStream(String name, InputStream stream) {
public MappingFileDescriptorImpl(String name, InputStreamAccess streamAccess) {
this.name = name;
this.stream = stream;
}
public InputStream getStream() {
return stream;
this.streamAccess = streamAccess;
}
@Override
public String getName() {
return name;
}
@Override
public InputStreamAccess getStreamAccess() {
return streamAccess;
}
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,10 +21,10 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.internal;
package org.hibernate.metamodel.archive.scan.internal;
import org.hibernate.jpa.boot.spi.InputStreamAccess;
import org.hibernate.jpa.boot.spi.PackageDescriptor;
import org.hibernate.metamodel.archive.scan.spi.PackageDescriptor;
import org.hibernate.metamodel.archive.spi.InputStreamAccess;
/**
* @author Steve Ebersole

View File

@ -21,13 +21,13 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.scan.internal;
package org.hibernate.metamodel.archive.scan.internal;
import org.hibernate.jpa.boot.archive.spi.ArchiveEntryHandler;
import org.hibernate.jpa.boot.scan.spi.ArchiveEntryHandlers;
import org.hibernate.jpa.boot.scan.spi.ClassFileArchiveEntryHandler;
import org.hibernate.jpa.boot.scan.spi.NonClassFileArchiveEntryHandler;
import org.hibernate.jpa.boot.scan.spi.PackageInfoArchiveEntryHandler;
import org.hibernate.metamodel.archive.scan.spi.ArchiveEntryHandlers;
import org.hibernate.metamodel.archive.scan.spi.ClassFileArchiveEntryHandler;
import org.hibernate.metamodel.archive.scan.spi.NonClassFileArchiveEntryHandler;
import org.hibernate.metamodel.archive.scan.spi.PackageInfoArchiveEntryHandler;
import org.hibernate.metamodel.archive.spi.ArchiveEntryHandler;
/**
* @author Steve Ebersole

View File

@ -21,25 +21,22 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.scan.internal;
package org.hibernate.metamodel.archive.scan.internal;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.PersistenceException;
import org.hibernate.jpa.boot.scan.spi.ScanEnvironment;
import org.hibernate.jpa.boot.scan.spi.ScanOptions;
import org.hibernate.jpa.boot.scan.spi.ScanResult;
import org.hibernate.jpa.boot.spi.ClassDescriptor;
import org.hibernate.jpa.boot.spi.MappingFileDescriptor;
import org.hibernate.jpa.boot.spi.PackageDescriptor;
import org.hibernate.metamodel.archive.scan.spi.ClassDescriptor;
import org.hibernate.metamodel.archive.scan.spi.MappingFileDescriptor;
import org.hibernate.metamodel.archive.scan.spi.PackageDescriptor;
import org.hibernate.metamodel.archive.scan.spi.ScanEnvironment;
import org.hibernate.metamodel.archive.scan.spi.ScanOptions;
import org.hibernate.metamodel.archive.scan.spi.ScanParameters;
import org.hibernate.metamodel.archive.scan.spi.ScanResult;
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.logging.Logger;
/**
@ -51,17 +48,17 @@ public class ScanResultCollector {
private final ScanEnvironment environment;
private final ScanOptions options;
private final ScanParameters scanParameters;
private final Set<ClassDescriptor> discoveredClasses;
private final Set<PackageDescriptor> discoveredPackages;
private final Set<MappingFileDescriptor> discoveredMappingFiles;
public ScanResultCollector(ScanEnvironment environment, ScanOptions options) {
public ScanResultCollector(ScanEnvironment environment, ScanOptions options, ScanParameters parameters) {
this.environment = environment;
this.options = options;
if ( options.getJandexIndexer() == null && options.getJandexView() == null ) {
throw new IllegalArgumentException( "Indexer and IndexView cannot both be null" );
}
this.scanParameters = parameters;
if ( environment.getExplicitlyListedClassNames() == null ) {
throw new IllegalArgumentException( "ScanEnvironment#getExplicitlyListedClassNames should not return null" );
@ -77,22 +74,7 @@ public class ScanResultCollector {
}
public void handleClass(ClassDescriptor classDescriptor, boolean rootUrl) {
// Always make sure the Jandex entry is created.
final ClassInfo classInfo;
if ( options.getJandexIndexer() != null ) {
classInfo = indexStream( classDescriptor );
}
else {
classInfo = options.getJandexView().getClassByName( DotName.createSimple( classDescriptor.getName() ) );
}
if ( classInfo == null ) {
log.debugf(
"Could not locate class [%s] in Jandex; this will most likely lead to problems later",
classDescriptor.getName()
);
return;
}
final ClassInfo classInfo = scanParameters.getJandexInitializer().handle( classDescriptor );
// see if "discovery" of this entry is allowed
@ -128,26 +110,6 @@ public class ScanResultCollector {
}
}
private ClassInfo indexStream(ClassDescriptor classDescriptor) {
InputStream stream = classDescriptor.getStreamAccess().accessInputStream();
try {
return options.getJandexIndexer().index( stream );
}
catch (IOException e) {
throw new PersistenceException(
"Could not add class [" + classDescriptor.getName() + "] to Jandex Indexer",
e
);
}
finally {
try {
stream.close();
}
catch (IOException ignore) {
}
}
}
@SuppressWarnings("SimplifiableIfStatement")
private boolean containsClassAnnotationsOfInterest(ClassInfo classInfo) {
if ( classInfo.annotations() == null ) {
@ -161,10 +123,7 @@ public class ScanResultCollector {
}
public void handlePackage(PackageDescriptor packageDescriptor, boolean rootUrl) {
// Always make sure the Jandex entry is created.
if ( options.getJandexIndexer() != null ) {
indexStream( packageDescriptor );
}
final ClassInfo classInfo = scanParameters.getJandexInitializer().handle( packageDescriptor );
if ( !isListedOrDetectable( packageDescriptor.getName(), rootUrl ) ) {
// not strictly needed, but helps cut down on the size of discoveredPackages
@ -174,26 +133,6 @@ public class ScanResultCollector {
discoveredPackages.add( packageDescriptor );
}
private ClassInfo indexStream(PackageDescriptor packageDescriptor) {
InputStream stream = packageDescriptor.getStreamAccess().accessInputStream();
try {
return options.getJandexIndexer().index( stream );
}
catch (IOException e) {
throw new PersistenceException(
"Could not add package [" + packageDescriptor.getName() + "] to Jandex Indexer",
e
);
}
finally {
try {
stream.close();
}
catch (IOException ignore) {
}
}
}
public void handleMappingFile(MappingFileDescriptor mappingFileDescriptor, boolean rootUrl) {
if ( acceptAsMappingFile( mappingFileDescriptor, rootUrl ) ) {
discoveredMappingFiles.add( mappingFileDescriptor );

View File

@ -21,14 +21,14 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.scan.internal;
package org.hibernate.metamodel.archive.scan.internal;
import java.util.Set;
import org.hibernate.jpa.boot.scan.spi.ScanResult;
import org.hibernate.jpa.boot.spi.ClassDescriptor;
import org.hibernate.jpa.boot.spi.MappingFileDescriptor;
import org.hibernate.jpa.boot.spi.PackageDescriptor;
import org.hibernate.metamodel.archive.scan.spi.ClassDescriptor;
import org.hibernate.metamodel.archive.scan.spi.MappingFileDescriptor;
import org.hibernate.metamodel.archive.scan.spi.PackageDescriptor;
import org.hibernate.metamodel.archive.scan.spi.ScanResult;
/**
* @author Steve Ebersole

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,31 +21,19 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.scan.internal;
package org.hibernate.metamodel.archive.scan.internal;
import org.hibernate.jpa.boot.scan.spi.ScanOptions;
import org.jboss.jandex.IndexView;
import org.jboss.jandex.Indexer;
import org.hibernate.metamodel.archive.scan.spi.ScanOptions;
/**
* @author Steve Ebersole
*/
public class StandardScanOptions implements ScanOptions {
private final Indexer jandexIndexer;
private final IndexView jandexView;
private final boolean detectClassesInRoot;
private final boolean detectClassesInNonRoot;
private final boolean detectHibernateMappingFiles;
public StandardScanOptions(
Indexer jandexIndexer,
IndexView jandexView,
String explicitDetectionSetting,
boolean persistenceUnitExcludeUnlistedClassesValue) {
this.jandexIndexer = jandexIndexer;
this.jandexView = jandexView;
public StandardScanOptions(String explicitDetectionSetting, boolean persistenceUnitExcludeUnlistedClassesValue) {
if ( explicitDetectionSetting == null ) {
this.detectHibernateMappingFiles = true;
this.detectClassesInRoot = ! persistenceUnitExcludeUnlistedClassesValue;
@ -65,25 +53,6 @@ public class StandardScanOptions implements ScanOptions {
this( "hbm,class", false );
}
/**
* INTENDED FOR TESTING ONLY
*/
public StandardScanOptions(
String explicitDetectionSetting,
boolean persistenceUnitExcludeUnlistedClassesValue) {
this( new Indexer(), null, explicitDetectionSetting, persistenceUnitExcludeUnlistedClassesValue );
}
@Override
public Indexer getJandexIndexer() {
return jandexIndexer;
}
@Override
public IndexView getJandexView() {
return jandexView;
}
@Override
public boolean canDetectUnlistedClassesInRoot() {
return detectClassesInRoot;

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,11 +21,11 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.scan.internal;
package org.hibernate.metamodel.archive.scan.internal;
import org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory;
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl;
import org.hibernate.metamodel.archive.internal.StandardArchiveDescriptorFactory;
import org.hibernate.metamodel.archive.scan.spi.AbstractScannerImpl;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptorFactory;
/**
* Standard implementation of the Scanner contract, supporting typical archive walking support where

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,17 +21,18 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.scan.spi;
package org.hibernate.metamodel.archive.scan.spi;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.jpa.boot.archive.spi.ArchiveContext;
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor;
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.jpa.boot.scan.internal.ResultCoordinator;
import org.hibernate.jpa.boot.scan.internal.ScanResultCollector;
import org.hibernate.metamodel.archive.scan.internal.ScanResultCollector;
import org.hibernate.metamodel.archive.spi.ArchiveContext;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptor;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.metamodel.archive.spi.ArchiveEntry;
import org.hibernate.metamodel.archive.spi.ArchiveEntryHandler;
/**
* @author Steve Ebersole
@ -45,12 +46,11 @@ public abstract class AbstractScannerImpl implements Scanner {
}
@Override
public ScanResult scan(ScanEnvironment environment, ScanOptions options) {
final ScanResultCollector collector = new ScanResultCollector( environment, options );
final ResultCoordinator resultCoordinator = new ResultCoordinator( collector );
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( environment, false, resultCoordinator );
final ArchiveContext context = new ArchiveContextImpl( false, collector );
for ( URL url : environment.getNonRootUrls() ) {
final ArchiveDescriptor descriptor = buildArchiveDescriptor( url, false );
descriptor.visitArchive( context );
@ -58,7 +58,7 @@ public abstract class AbstractScannerImpl implements Scanner {
}
if ( environment.getRootUrl() != null ) {
final ArchiveContext context = new ArchiveContextImpl( environment, true, resultCoordinator );
final ArchiveContext context = new ArchiveContextImpl( true, collector );
final ArchiveDescriptor descriptor = buildArchiveDescriptor( environment.getRootUrl(), true );
descriptor.visitArchive( context );
}
@ -103,4 +103,40 @@ public abstract class AbstractScannerImpl implements Scanner {
throw new IllegalStateException( "ArchiveDescriptor reused; can URLs be processed multiple times?" );
}
public static class ArchiveContextImpl implements ArchiveContext {
private final boolean isRootUrl;
private final ClassFileArchiveEntryHandler classEntryHandler;
private final PackageInfoArchiveEntryHandler packageEntryHandler;
private final ArchiveEntryHandler fileEntryHandler;
public ArchiveContextImpl(boolean isRootUrl, ScanResultCollector scanResultCollector) {
this.isRootUrl = isRootUrl;
this.classEntryHandler = new ClassFileArchiveEntryHandler( scanResultCollector );
this.packageEntryHandler = new PackageInfoArchiveEntryHandler( scanResultCollector );
this.fileEntryHandler = new NonClassFileArchiveEntryHandler( scanResultCollector );
}
@Override
public boolean isRootUrl() {
return isRootUrl;
}
@Override
public ArchiveEntryHandler obtainArchiveEntryHandler(ArchiveEntry entry) {
final String nameWithinArchive = entry.getNameWithinArchive();
if ( nameWithinArchive.endsWith( "package-info.class" ) ) {
return packageEntryHandler;
}
else if ( nameWithinArchive.endsWith( ".class" ) ) {
return classEntryHandler;
}
else {
return fileEntryHandler;
}
}
}
}

View File

@ -21,9 +21,9 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.scan.spi;
package org.hibernate.metamodel.archive.scan.spi;
import org.hibernate.jpa.boot.archive.spi.ArchiveEntryHandler;
import org.hibernate.metamodel.archive.spi.ArchiveEntryHandler;
/**
* Composite of the various types of ArchiveEntryHandlers

View File

@ -0,0 +1,47 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.archive.scan.spi;
import org.hibernate.metamodel.archive.spi.InputStreamAccess;
/**
* Descriptor for a class file.
*
* @author Steve Ebersole
*/
public interface ClassDescriptor {
/**
* Retrieves the class name, not the file name.
*
* @return The name (FQN) of the class
*/
public String getName();
/**
* Retrieves access to the InputStream for the class file.
*
* @return Access to the InputStream for the class file.
*/
public InputStreamAccess getStreamAccess();
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.scan.spi;
package org.hibernate.metamodel.archive.scan.spi;
import java.io.DataInputStream;
import java.io.IOException;
@ -29,13 +29,12 @@ import java.io.InputStream;
import javassist.bytecode.ClassFile;
import org.hibernate.jpa.boot.archive.spi.ArchiveContext;
import org.hibernate.jpa.boot.archive.spi.ArchiveEntry;
import org.hibernate.jpa.boot.archive.spi.ArchiveEntryHandler;
import org.hibernate.jpa.boot.archive.spi.ArchiveException;
import org.hibernate.jpa.boot.internal.ClassDescriptorImpl;
import org.hibernate.jpa.boot.scan.internal.ScanResultCollector;
import org.hibernate.jpa.boot.spi.ClassDescriptor;
import org.hibernate.metamodel.archive.scan.internal.ClassDescriptorImpl;
import org.hibernate.metamodel.archive.scan.internal.ScanResultCollector;
import org.hibernate.metamodel.archive.spi.ArchiveContext;
import org.hibernate.metamodel.archive.spi.ArchiveEntry;
import org.hibernate.metamodel.archive.spi.ArchiveEntryHandler;
import org.hibernate.metamodel.archive.spi.ArchiveException;
/**
* Defines handling and filtering for class file entries within an archive

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,14 +21,17 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.spi;
package org.hibernate.metamodel.archive.scan.spi;
import org.jboss.jandex.ClassInfo;
/**
* Defines the result of scanning a persistence unit for classes.
* Helper for preparing Jandex for later use..
*
* @author Steve Ebersole
*/
public interface ClassDescriptor {
public String getName();
public InputStreamAccess getStreamAccess();
public interface JandexInitializer {
ClassInfo handle(PackageDescriptor packageDescriptor);
ClassInfo handle(ClassDescriptor classDescriptor);
}

View File

@ -0,0 +1,49 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.archive.scan.spi;
import org.hibernate.metamodel.archive.spi.InputStreamAccess;
/**
* Descriptor for a mapping (XML) file.
*
* @author Steve Ebersole
*/
public interface MappingFileDescriptor {
/**
* The mapping file name. This is its name within the archive, the
* expectation being that most times this will equate to a "classpath
* lookup resource name".
*
* @return The mapping file resource name.
*/
public String getName();
/**
* Retrieves access to the InputStream for the mapping file.
*
* @return Access to the InputStream for the mapping file.
*/
public InputStreamAccess getStreamAccess();
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,13 +21,13 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.scan.spi;
package org.hibernate.metamodel.archive.scan.spi;
import org.hibernate.jpa.boot.archive.spi.ArchiveContext;
import org.hibernate.jpa.boot.archive.spi.ArchiveEntry;
import org.hibernate.jpa.boot.archive.spi.ArchiveEntryHandler;
import org.hibernate.jpa.boot.internal.MappingFileDescriptorImpl;
import org.hibernate.jpa.boot.scan.internal.ScanResultCollector;
import org.hibernate.metamodel.archive.scan.internal.MappingFileDescriptorImpl;
import org.hibernate.metamodel.archive.scan.internal.ScanResultCollector;
import org.hibernate.metamodel.archive.spi.ArchiveContext;
import org.hibernate.metamodel.archive.spi.ArchiveEntry;
import org.hibernate.metamodel.archive.spi.ArchiveEntryHandler;
/**
* Defines handling and filtering for all non-class file (package-info is also a class file...) entries within an archive

View File

@ -0,0 +1,47 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.archive.scan.spi;
import org.hibernate.metamodel.archive.spi.InputStreamAccess;
/**
* Descriptor for a package (as indicated by a package-info.class file).
*
* @author Steve Ebersole
*/
public interface PackageDescriptor {
/**
* Retrieves the package name.
*
* @return The package name
*/
public String getName();
/**
* Retrieves access to the InputStream for the {@code package-info.class} file.
*
* @return Access to the InputStream for the {@code package-info.class} file.
*/
public InputStreamAccess getStreamAccess();
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,14 +21,13 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.scan.spi;
package org.hibernate.metamodel.archive.scan.spi;
import org.hibernate.jpa.boot.archive.spi.ArchiveContext;
import org.hibernate.jpa.boot.archive.spi.ArchiveEntry;
import org.hibernate.jpa.boot.archive.spi.ArchiveEntryHandler;
import org.hibernate.jpa.boot.internal.PackageDescriptorImpl;
import org.hibernate.jpa.boot.scan.internal.ScanResultCollector;
import org.hibernate.jpa.boot.spi.PackageDescriptor;
import org.hibernate.metamodel.archive.scan.internal.PackageDescriptorImpl;
import org.hibernate.metamodel.archive.scan.internal.ScanResultCollector;
import org.hibernate.metamodel.archive.spi.ArchiveContext;
import org.hibernate.metamodel.archive.spi.ArchiveEntry;
import org.hibernate.metamodel.archive.spi.ArchiveEntryHandler;
/**
* Defines handling and filtering for package-info file entries within an archive

View File

@ -0,0 +1,81 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.archive.scan.spi;
import java.net.URL;
import java.util.List;
/**
* Describes the environment in which the scan will occur.
* <p/>
* Note that much of this comes from the PU in JPA sense. This is
* intended as an abstraction over the PU in JPA cases, as well as a
* delegate allowing usage in non-JPA cases. With the planned move
* to unify the cfg.xml and persistence.xml schemas (like we are doing
* with hbm.xml and orm.xml) this becomes less needed (at least parts
* of it).
* <p/>
* After unification, I think the biggest difference is that we will
* not need to pass ScanEnvironment into the MetadataSources/MetadataBuilder
* while for the time being we will need to.
*
* @author Steve Ebersole
*/
public interface ScanEnvironment {
/**
* Returns the root URL for scanning. Can be {@code null}, indicating that
* no root URL scanning should be done (aka, if maybe a root URL is not known).
*
* @return The root URL
*
* @see ScanOptions#canDetectUnlistedClassesInRoot()
*/
public URL getRootUrl();
/**
* Returns any non-root URLs for scanning. Can be null/empty to indicate
* that no non-root URL scanning should be done.
*
* @return The non-root URLs
*
* @see ScanOptions#canDetectUnlistedClassesInNonRoot()
*/
public List<URL> getNonRootUrls();
/**
* Returns any classes which are explicitly listed as part of the
* "persistence unit".
*
* @return The explicitly listed classes
*/
public List<String> getExplicitlyListedClassNames();
/**
* Returns the mapping files which are explicitly listed as part of the
* "persistence unit".
*
* @return The explicitly listed mapping files.
*/
public List<String> getExplicitlyListedMappingFiles();
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,10 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.scan.spi;
import org.jboss.jandex.IndexView;
import org.jboss.jandex.Indexer;
package org.hibernate.metamodel.archive.scan.spi;
/**
* Options for performing scanning
@ -32,24 +29,6 @@ import org.jboss.jandex.Indexer;
* @author Steve Ebersole
*/
public interface ScanOptions {
/**
* The Jandex Indexer to use.
* <p/>
* Note that either this or {@link #getJandexView()} must return non-null.
*
* @return The Jandex Indexer to use
*/
public Indexer getJandexIndexer();
/**
* The Jandex index to use.
* <p/>
* Note that either this or {@link #getJandexIndexer()} must return non-null.
*
* @return The Jandex index to use.
*/
public IndexView getJandexView();
/**
* Is detection of managed classes from root url allowed? In strict JPA
* sense, this would be controlled by the {@code <exclude-unlisted-classes/>}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,14 +21,14 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.spi;
package org.hibernate.metamodel.archive.scan.spi;
/**
* Defines the result of scanning a persistence unit for packages.
* A "parameter object" passed to {@link Scanner#scan} to help support future
* changes in terms of needing to pass additional stuff to scanning.
*
* @author Steve Ebersole
*/
public interface PackageDescriptor {
public String getName();
public InputStreamAccess getStreamAccess();
public interface ScanParameters {
public JandexInitializer getJandexInitializer();
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,21 +21,34 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.scan.spi;
package org.hibernate.metamodel.archive.scan.spi;
import java.util.Set;
import org.hibernate.jpa.boot.spi.ClassDescriptor;
import org.hibernate.jpa.boot.spi.MappingFileDescriptor;
import org.hibernate.jpa.boot.spi.PackageDescriptor;
/**
* Defines the result of scanning
*
* @author Steve Ebersole
*/
public interface ScanResult {
/**
* Returns descriptors for all packages discovered as part of the scan
*
* @return Descriptors for discovered packages
*/
public Set<PackageDescriptor> getLocatedPackages();
/**
* Returns descriptors for all classes discovered as part of the scan
*
* @return Descriptors for discovered classes
*/
public Set<ClassDescriptor> getLocatedClasses();
/**
* Returns descriptors for all mapping files discovered as part of the scan
*
* @return Descriptors for discovered mapping files
*/
public Set<MappingFileDescriptor> getLocatedMappingFiles();
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,11 +21,19 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.scan.spi;
package org.hibernate.metamodel.archive.scan.spi;
/**
* Defines the contract for Hibernate to be able to scan for classes, packages and resources inside a
* persistence unit.
* <p/>
* Constructors are expected in one of 2 forms:<ul>
* <li>no-arg</li>
* <li>single arg, of type {@link org.hibernate.metamodel.archive.spi.ArchiveDescriptorFactory}</li>
* </ul>
* <p/>
* If a ArchiveDescriptorFactory is specified in the configuration, but the Scanner
* to be used does not accept a ArchiveDescriptorFactory an exception will be thrown.
*
* @author Emmanuel Bernard
* @author Steve Ebersole
@ -35,8 +43,9 @@ public interface Scanner {
* Perform the scanning against the described environment using the
* defined options, and return the scan results.
*
* @param environment The scan environment
* @param options The options to control the scanning
* @param environment The scan environment.
* @param options The options to control the scanning.
* @param params The parameters for scanning
*/
public ScanResult scan(ScanEnvironment environment, ScanOptions options);
public ScanResult scan(ScanEnvironment environment, ScanOptions options, ScanParameters params);
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,16 +21,15 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.archive.spi;
package org.hibernate.metamodel.archive.spi;
import java.io.InputStream;
import java.net.URL;
import java.util.zip.ZipEntry;
import org.hibernate.metamodel.archive.internal.ByteArrayInputStreamAccess;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.jpa.boot.archive.internal.ArchiveHelper;
import org.hibernate.jpa.boot.internal.ByteArrayInputStreamAccess;
import org.hibernate.jpa.boot.spi.InputStreamAccess;
import org.hibernate.metamodel.archive.internal.ArchiveHelper;
/**
* Base support for ArchiveDescriptor implementors.
@ -74,7 +73,9 @@ public abstract class AbstractArchiveDescriptor implements ArchiveDescriptor {
protected String extractRelativeName(ZipEntry zipEntry) {
final String entryName = extractName( zipEntry );
return entryBasePrefix != null && entryName.contains( entryBasePrefix ) ? entryName.substring( entryBasePrefix.length() ) : entryName;
return entryBasePrefix != null && entryName.contains( entryBasePrefix )
? entryName.substring( entryBasePrefix.length() )
: entryName;
}
protected String extractName(ZipEntry zipEntry) {

View File

@ -21,28 +21,28 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.scan.spi;
package org.hibernate.metamodel.archive.spi;
import java.net.URL;
import java.util.List;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import org.hibernate.metamodel.archive.internal.ArchiveHelper;
/**
* @author Steve Ebersole
*/
public interface ScanEnvironment {
public URL getRootUrl();
public List<URL> getNonRootUrls();
public abstract class AbstractArchiveDescriptorFactory implements ArchiveDescriptorFactory {
@Override
public ArchiveDescriptor buildArchiveDescriptor(URL url) {
return buildArchiveDescriptor( url, "" );
}
public List<String> getExplicitlyListedClassNames();
public List<String> getExplicitlyListedMappingFiles();
@Override
public URL getJarURLFromURLEntry(URL url, String entry) throws IllegalArgumentException {
return ArchiveHelper.getJarURLFromURLEntry( url, entry );
}
/**
* @deprecated Added temporarily to support legacy
* {@link org.hibernate.jpa.boot.archive.spi.ArchiveContext#getPersistenceUnitDescriptor()}
* calls
*/
@Deprecated
public PersistenceUnitDescriptor getPersistenceUnitDescriptor();
@Override
public URL getURLFromPath(String jarPath) {
return ArchiveHelper.getURLFromPath( jarPath );
}
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,9 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.archive.spi;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
package org.hibernate.metamodel.archive.spi;
/**
* Describes the context for visiting the entries within an archive
@ -31,13 +29,6 @@ import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
* @author Steve Ebersole
*/
public interface ArchiveContext {
/**
* The persistence-unit descriptor which led to this archive being scanned.
*
* @return The persistence-unit descriptor
*/
public PersistenceUnitDescriptor getPersistenceUnitDescriptor();
/**
* Is the archive described (and being visited) the root url for the persistence-unit?
*

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.archive.spi;
package org.hibernate.metamodel.archive.spi;
/**
* Contract for visiting an archive, which might be a jar, a zip, an exploded directory, etc.

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.archive.spi;
package org.hibernate.metamodel.archive.spi;
import java.net.URL;

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,9 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.archive.spi;
import org.hibernate.jpa.boot.spi.InputStreamAccess;
package org.hibernate.metamodel.archive.spi;
/**
* Represent an entry in the archive.

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.archive.spi;
package org.hibernate.metamodel.archive.spi;
/**
* Handler for archive entries, based on the classified type of the entry

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.archive.spi;
package org.hibernate.metamodel.archive.spi;
import org.hibernate.HibernateException;

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.spi;
package org.hibernate.metamodel.archive.spi;
import java.io.InputStream;
@ -44,9 +44,4 @@ public interface InputStreamAccess {
* @return The stream
*/
public InputStream accessInputStream();
/**
* @deprecated Needed until we can remove NamedInputStream
*/
public NamedInputStream asNamedInputStream();
}

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2009, 2012, Red Hat Inc. or third-party contributors as
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
@ -21,11 +21,19 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.ejb.packaging;
/**
* @deprecated Use {@link org.hibernate.jpa.boot.scan.spi.Scanner} instead
* Defines the SPI for support of "scanning" of "archives".
* <p/>
* Scanning might mean:<ul>
* <li>searching for classes/packages that define certain interfaces</li>
* <li>locating named resources</li>
* </ul>
* And "archive" might mean:<ul>
* <li>a {@code .jar} file</li>
* <li>an exploded directory</li>
* <li>an OSGi bundle</li>
* <li>etc</li>
* </ul>
*/
@Deprecated
public interface Scanner extends org.hibernate.jpa.boot.scan.spi.Scanner {
}
package org.hibernate.metamodel.archive.spi;

View File

@ -23,6 +23,8 @@
*/
package org.hibernate.metamodel.internal;
import java.net.URL;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
@ -51,7 +53,8 @@ public class ClassLoaderAccessImpl implements ClassLoaderAccess {
}
@Override
public Class classForName(String name) {
@SuppressWarnings("unchecked")
public Class<?> classForName(String name) {
if ( isSafeClass( name ) ) {
return classLoaderService.classForName( name );
}
@ -87,4 +90,9 @@ public class ClassLoaderAccessImpl implements ClassLoaderAccess {
|| name.startsWith( "org.hibernate" );
}
@Override
public URL locateResource(String resourceName) {
return classLoaderService.locateResource( resourceName );
}
}

View File

@ -0,0 +1,309 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.internal;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.metamodel.archive.scan.spi.ClassDescriptor;
import org.hibernate.metamodel.archive.scan.spi.JandexInitializer;
import org.hibernate.metamodel.archive.scan.spi.PackageDescriptor;
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
import org.hibernate.metamodel.spi.ClassLoaderAccess;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import org.jboss.jandex.IndexView;
import org.jboss.jandex.Indexer;
import org.jboss.jandex.Type;
import org.jboss.logging.Logger;
/**
* Manages the steps needed to get Jandex properly initialized for later use.
*
* @author Steve Ebersole
*/
public class JandexInitManager implements JandexInitializer {
private static final Logger log = Logger.getLogger( JandexInitManager.class );
private final DotName OBJECT_DOT_NAME = DotName.createSimple( Object.class.getName() );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// supplied index
private final IndexView suppliedIndexView;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// indexer
private final Indexer indexer;
private final Map<DotName, ClassInfo> inflightClassInfoMap;
private final ClassLoaderAccess classLoaderAccess;
private final boolean autoIndexMembers;
public JandexInitManager(
IndexView suppliedIndexView,
ClassLoaderAccess classLoaderAccess,
boolean autoIndexMembers) {
this.suppliedIndexView = suppliedIndexView;
this.classLoaderAccess = classLoaderAccess;
this.autoIndexMembers = autoIndexMembers;
if ( suppliedIndexView == null ) {
this.indexer = new Indexer();
this.inflightClassInfoMap = new HashMap<DotName, ClassInfo>();
}
else {
this.indexer = null;
this.inflightClassInfoMap = null;
}
}
/**
* INTENDED FOR TESTING ONLY
*/
public JandexInitManager() {
this(
null,
new ClassLoaderAccess() {
@Override
@SuppressWarnings("unchecked")
public <T> Class<T> classForName(String name) {
try {
return (Class<T>) getClass().getClassLoader().loadClass( name );
}
catch ( Exception e ) {
throw new ClassLoadingException( "Could not load class by name : " + name );
}
}
@Override
public URL locateResource(String resourceName) {
return getClass().getClassLoader().getResource( resourceName );
}
},
false
);
}
public boolean wasIndexSupplied() {
return suppliedIndexView != null;
}
@Override
public ClassInfo handle(ClassDescriptor classFileDescriptor) {
if ( suppliedIndexView != null ) {
return suppliedIndexView.getClassByName( DotName.createSimple( classFileDescriptor.getName() ) );
}
else {
return index( classFileDescriptor );
}
}
private ClassInfo index(ClassDescriptor classDescriptor) {
InputStream stream = classDescriptor.getStreamAccess().accessInputStream();
try {
return index( stream, classDescriptor.getName() );
}
finally {
try {
stream.close();
}
catch (IOException ignore) {
}
}
}
protected ClassInfo index(InputStream stream, String name) {
try {
final ClassInfo classInfo = indexer.index( stream );
inflightClassInfoMap.put( classInfo.name(), classInfo );
furtherProcess( classInfo );
return classInfo;
}
catch ( IOException e ) {
throw new HibernateException( "Unable to index from resource stream [" + name + "]", e );
}
}
private void furtherProcess(ClassInfo classInfo) {
final List<AnnotationInstance> entityListenerAnnotations = classInfo.annotations().get( JPADotNames.ENTITY_LISTENERS );
if ( entityListenerAnnotations != null ) {
for ( AnnotationInstance entityListenerAnnotation : entityListenerAnnotations ) {
final Type[] entityListenerClassTypes = entityListenerAnnotation.value().asClassArray();
for ( Type entityListenerClassType : entityListenerClassTypes ) {
indexClassName( entityListenerClassType.name() );
}
}
}
// todo : others?
}
public void indexClassName(DotName classDotName) {
if ( !needsIndexing( classDotName ) ) {
return;
}
ClassInfo classInfo = indexResource( classDotName.toString().replace( '.', '/' ) + ".class" );
inflightClassInfoMap.put( classInfo.name(), classInfo );
if ( classInfo.superName() != null ) {
indexClassName( classInfo.superName() );
}
}
protected boolean needsIndexing(DotName classDotName) {
if ( classDotName == null || OBJECT_DOT_NAME.equals( classDotName ) ) {
return false;
}
if ( suppliedIndexView != null ) {
// we do not build an index if one is supplied to us.
return false;
}
// otherwise, return true if the map does not contain this class
return !inflightClassInfoMap.containsKey( classDotName );
}
public ClassInfo indexResource(String resourceName) {
final URL resourceUrl = classLoaderAccess.locateResource( resourceName );
if ( resourceUrl == null ) {
throw new IllegalArgumentException( "Could not locate resource [" + resourceName + "]" );
}
try {
final InputStream stream = resourceUrl.openStream();
try {
return index( stream, resourceName );
}
finally {
try {
stream.close();
}
catch ( IOException e ) {
log.debug( "Unable to close resource stream [" + resourceName + "] : " + e.getMessage() );
}
}
}
catch ( IOException e ) {
throw new HibernateException( "Unable to open input stream for resource [" + resourceName + "]", e );
}
}
@Override
public ClassInfo handle(PackageDescriptor packageInfoFileDescriptor) {
if ( suppliedIndexView != null ) {
return suppliedIndexView.getClassByName( DotName.createSimple( packageInfoFileDescriptor.getName() ) );
}
else {
return index( packageInfoFileDescriptor );
}
}
private ClassInfo index(PackageDescriptor packageDescriptor) {
InputStream stream = packageDescriptor.getStreamAccess().accessInputStream();
try {
return index( stream, packageDescriptor.getName() );
}
finally {
try {
stream.close();
}
catch (IOException ignore) {
}
}
}
public void indexLoadedClass(Class loadedClass) {
assert !wasIndexSupplied() : "We are not indexing";
if ( loadedClass == null ) {
return;
}
final DotName classDotName = DotName.createSimple( loadedClass.getName() );
if ( !needsIndexing( classDotName ) ) {
return;
}
// index super type first
indexLoadedClass( loadedClass.getSuperclass() );
// index any inner classes
for ( Class innerClass : loadedClass.getDeclaredClasses() ) {
indexLoadedClass( innerClass );
}
// then index the class itself
ClassInfo classInfo = indexResource( loadedClass.getName().replace( '.', '/' ) + ".class" );
inflightClassInfoMap.put( classDotName, classInfo );
if ( !autoIndexMembers ) {
return;
}
for ( Class<?> fieldType : ReflectHelper.getMemberTypes( loadedClass ) ) {
if ( !fieldType.isPrimitive() && fieldType != Object.class ) {
indexLoadedClass( fieldType );
}
}
// Also check for classes within a @Target annotation.
// [steve] - not so sure about this. target would name an entity, which should be
// known to us somehow
for ( AnnotationInstance targetAnnotation : JandexHelper.getAnnotations( classInfo, HibernateDotNames.TARGET ) ) {
String targetClassName = targetAnnotation.value().asClass().name().toString();
Class<?> targetClass = classLoaderAccess.classForName( targetClassName );
indexLoadedClass( targetClass );
}
}
public IndexView buildIndex() {
if ( suppliedIndexView != null ) {
return suppliedIndexView;
}
else {
final Index jandexIndex = indexer.complete();
if ( log.isTraceEnabled() ) {
jandexIndex.printSubclasses();
jandexIndex.printAnnotations();
}
return jandexIndex;
}
}
}

View File

@ -33,6 +33,7 @@ import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.boot.spi.CacheRegionDefinition;
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.AvailableSettings;
@ -44,6 +45,11 @@ import org.hibernate.engine.config.spi.StandardConverters;
import org.hibernate.metamodel.MetadataBuilder;
import org.hibernate.metamodel.MetadataSourceProcessingOrder;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.archive.scan.internal.StandardScanOptions;
import org.hibernate.metamodel.archive.scan.spi.ScanEnvironment;
import org.hibernate.metamodel.archive.scan.spi.ScanOptions;
import org.hibernate.metamodel.archive.scan.spi.Scanner;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.metamodel.spi.MetadataSourcesContributor;
import org.hibernate.metamodel.spi.PersistentAttributeMemberResolver;
import org.hibernate.metamodel.spi.StandardPersistentAttributeMemberResolver;
@ -62,6 +68,8 @@ import org.jboss.logging.Logger;
import org.xml.sax.EntityResolver;
import static org.hibernate.internal.DeprecationLogger.DEPRECATION_LOGGER;
/**
* The implementation of the {@link MetadataBuilder} contract.
*
@ -152,6 +160,30 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions {
return this;
}
@Override
public MetadataBuilder with(ScanOptions scanOptions) {
this.options.scanOptions = scanOptions;
return this;
}
@Override
public MetadataBuilder with(ScanEnvironment scanEnvironment) {
this.options.scanEnvironment = scanEnvironment;
return this;
}
@Override
public MetadataBuilder with(Scanner scanner) {
this.options.scannerSetting = scanner;
return this;
}
@Override
public MetadataBuilder with(ArchiveDescriptorFactory factory) {
this.options.archiveDescriptorFactory = factory;
return this;
}
@Override
public MetadataBuilder withNewIdentifierGeneratorsEnabled(boolean enabled) {
this.options.useNewIdentifierGenerators = enabled;
@ -287,6 +319,12 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions {
private IndexView jandexView;
private ClassLoader tempClassLoader;
private ScanOptions scanOptions;
private ScanEnvironment scanEnvironment;
private Object scannerSetting;
private ArchiveDescriptorFactory archiveDescriptorFactory;
private NamingStrategy namingStrategy = EJB3NamingStrategy.INSTANCE;
private SharedCacheMode sharedCacheMode = SharedCacheMode.ENABLE_SELECTIVE;
private AccessType defaultCacheAccessType;
@ -306,7 +344,9 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions {
public Options(StandardServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );
this.databaseDefaults = new DatabaseDefaults( configService );
// cache access type
@ -320,6 +360,25 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions {
}
);
jandexView = (IndexView) configService.getSettings().get( AvailableSettings.JANDEX_INDEX );
scanOptions = new StandardScanOptions(
(String) configService.getSettings().get( AvailableSettings.SCANNER_DISCOVERY ),
false
);
// ScanEnvironment must be set explicitly
scannerSetting = configService.getSettings().get( AvailableSettings.SCANNER );
if ( scannerSetting == null ) {
scannerSetting = configService.getSettings().get( AvailableSettings.SCANNER_DEPRECATED );
if ( scannerSetting != null ) {
DEPRECATION_LOGGER.logScannerDeprecation();
}
}
archiveDescriptorFactory = strategySelector.resolveStrategy(
ArchiveDescriptorFactory.class,
configService.getSettings().get( AvailableSettings.SCANNER_ARCHIVE_INTERPRETER )
);
useNewIdentifierGenerators = configService.getSetting(
AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS,
StandardConverters.BOOLEAN,
@ -361,6 +420,27 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions {
return jandexView;
}
@Override
public ScanOptions getScanOptions() {
return scanOptions;
}
@Override
public ScanEnvironment getScanEnvironment() {
return scanEnvironment;
}
@Override
public Object getScanner() {
return scannerSetting;
}
@Override
public ArchiveDescriptorFactory getArchiveDescriptorFactory() {
return archiveDescriptorFactory;
}
@Override
public ClassLoader getTempClassLoader() {
return tempClassLoader;

View File

@ -23,6 +23,9 @@
*/
package org.hibernate.metamodel.internal;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -41,14 +44,12 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.spi.CacheRegionDefinition;
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.cfg.ObjectNameNormalizer;
import org.hibernate.cfg.annotations.NamedEntityGraphDefinition;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.ResultSetMappingDefinition;
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.config.spi.StandardConverters;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.engine.spi.NamedQueryDefinition;
@ -58,10 +59,21 @@ import org.hibernate.id.EntityIdentifierNature;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.id.factory.spi.MutableIdentifierGeneratorFactory;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.metamodel.MetadataSourceProcessingOrder;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.NamedStoredProcedureQueryDefinition;
import org.hibernate.metamodel.SessionFactoryBuilder;
import org.hibernate.metamodel.archive.internal.StandardArchiveDescriptorFactory;
import org.hibernate.metamodel.archive.scan.internal.StandardScanner;
import org.hibernate.metamodel.archive.scan.spi.ClassDescriptor;
import org.hibernate.metamodel.archive.scan.spi.JandexInitializer;
import org.hibernate.metamodel.archive.scan.spi.MappingFileDescriptor;
import org.hibernate.metamodel.archive.scan.spi.PackageDescriptor;
import org.hibernate.metamodel.archive.scan.spi.ScanParameters;
import org.hibernate.metamodel.archive.scan.spi.ScanResult;
import org.hibernate.metamodel.archive.scan.spi.Scanner;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.metamodel.internal.binder.Binder;
import org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl;
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
@ -137,19 +149,53 @@ public class MetadataBuildingProcess {
private static final Logger log = Logger.getLogger( MetadataBuildingProcess.class );
public static MetadataImpl build(MetadataSources sources, final MetadataBuildingOptions options) {
final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl(
options.getTempClassLoader(),
options.getServiceRegistry()
);
final JandexInitManager jandexInitializer = buildJandexInitializer( options, classLoaderAccess );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// preliminary phases
final IndexView jandexView = handleJandex( options, sources );
// scanning - Jandex initialization and source discovery
if ( options.getScanEnvironment() != null ) {
final Scanner scanner = buildScanner( options, classLoaderAccess );
final ScanResult scanResult = scanner.scan(
options.getScanEnvironment(),
options.getScanOptions(),
new ScanParameters() {
@Override
public JandexInitializer getJandexInitializer() {
return jandexInitializer;
}
}
);
// Add to the MetadataSources any classes/packages/mappings discovered during scanning
addScanResultsToSources( scanResult, sources );
}
// todo : add options.getScanEnvironment().getExplicitlyListedClassNames() to jandex?
// ^^ - another option is to make sure that they are added to sources
if ( !jandexInitializer.wasIndexSupplied() ) {
// If the Jandex Index(View) was supplied, we consider that supplied
// one "complete".
// Here though we were NOT supplied an index; in this case we want to
// additionally ensure that any-and-all "known" classes are added to
// the index we are building
sources.indexKnownClasses( jandexInitializer );
}
final IndexView jandexView = augmentJandexFromMappings( jandexInitializer.buildIndex(), sources, options );
final BasicTypeRegistry basicTypeRegistry = handleTypes( options );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// prep to start handling binding in earnest
final MappingDefaultsImpl mappingDefaults = new MappingDefaultsImpl( options );
final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl(
options.getTempClassLoader(),
options.getServiceRegistry()
);
final JandexAccessImpl jandexAccess = new JandexAccessImpl(
jandexView,
classLoaderAccess
@ -229,22 +275,154 @@ public class MetadataBuildingProcess {
return metadataCollector.buildMetadataInstance();
}
private static IndexView handleJandex(MetadataBuildingOptions options, MetadataSources sources) {
final ConfigurationService configurationService = options.getServiceRegistry().getService( ConfigurationService.class );
private static JandexInitManager buildJandexInitializer(
MetadataBuildingOptions options,
ClassLoaderAccess classLoaderAccess) {
final boolean autoIndexMembers = ConfigurationHelper.getBoolean(
org.hibernate.cfg.AvailableSettings.ENABLE_AUTO_INDEX_MEMBER_TYPES,
options.getServiceRegistry().getService( ConfigurationService.class ).getSettings(),
false
);
final IndexView baseJandexIndex;
if ( options.getJandexView() != null ) {
baseJandexIndex = options.getJandexView();
return new JandexInitManager( options.getJandexView(), classLoaderAccess, autoIndexMembers );
}
private static final Class[] SINGLE_ARG = new Class[] { ArchiveDescriptorFactory.class };
private static Scanner buildScanner(MetadataBuildingOptions options, ClassLoaderAccess classLoaderAccess) {
final Object scannerSetting = options.getScanner();
final ArchiveDescriptorFactory archiveDescriptorFactory = options.getArchiveDescriptorFactory();
if ( scannerSetting == null ) {
// No custom Scanner specified, use the StandardScanner
if ( archiveDescriptorFactory == null ) {
return new StandardScanner();
}
else {
return new StandardScanner( archiveDescriptorFactory );
}
}
else {
final boolean autoIndexMemberTypes = configurationService.getSetting(
AvailableSettings.ENABLE_AUTO_INDEX_MEMBER_TYPES,
StandardConverters.BOOLEAN,
false
);
baseJandexIndex = sources.buildJandexView( autoIndexMemberTypes );
if ( Scanner.class.isInstance( scannerSetting ) ) {
if ( archiveDescriptorFactory != null ) {
throw new IllegalStateException(
"A Scanner instance and an ArchiveDescriptorFactory were both specified; please " +
"specify one or the other, or if you need to supply both, Scanner class to use " +
"(assuming it has a constructor accepting a ArchiveDescriptorFactory). " +
"Alternatively, just pass the ArchiveDescriptorFactory during your own " +
"Scanner constructor assuming it is statically known."
);
}
return (Scanner) scannerSetting;
}
final Class<? extends Scanner> scannerImplClass;
if ( Class.class.isInstance( scannerSetting ) ) {
scannerImplClass = (Class<? extends Scanner>) scannerSetting;
}
else {
scannerImplClass = classLoaderAccess.classForName( scannerSetting.toString() );
}
if ( archiveDescriptorFactory != null ) {
// find the single-arg constructor - its an error if none exists
try {
final Constructor<? extends Scanner> constructor = scannerImplClass.getConstructor( SINGLE_ARG );
try {
return constructor.newInstance( archiveDescriptorFactory );
}
catch (Exception e) {
throw new IllegalStateException(
"Error trying to instantiate custom specified Scanner [" +
scannerImplClass.getName() + "]",
e
);
}
}
catch (NoSuchMethodException e) {
throw new IllegalArgumentException(
"Configuration named a custom Scanner and a custom ArchiveDescriptorFactory, but " +
"Scanner impl did not define a constructor accepting ArchiveDescriptorFactory"
);
}
}
else {
// could be either ctor form...
// find the single-arg constructor - its an error if none exists
try {
final Constructor<? extends Scanner> constructor = scannerImplClass.getConstructor( SINGLE_ARG );
try {
return constructor.newInstance( StandardArchiveDescriptorFactory.INSTANCE );
}
catch (Exception e) {
throw new IllegalStateException(
"Error trying to instantiate custom specified Scanner [" +
scannerImplClass.getName() + "]",
e
);
}
}
catch (NoSuchMethodException e) {
try {
final Constructor<? extends Scanner> constructor = scannerImplClass.getConstructor();
try {
return constructor.newInstance();
}
catch (Exception e2) {
throw new IllegalStateException(
"Error trying to instantiate custom specified Scanner [" +
scannerImplClass.getName() + "]",
e2
);
}
}
catch (NoSuchMethodException ignore) {
throw new IllegalArgumentException(
"Configuration named a custom Scanner, but we were unable to locate " +
"an appropriate constructor"
);
}
}
}
}
}
private static void addScanResultsToSources(ScanResult scanResult, MetadataSources sources) {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Add mapping files found as a result of scanning
for ( MappingFileDescriptor mappingFileDescriptor : scanResult.getLocatedMappingFiles() ) {
final InputStream stream = mappingFileDescriptor.getStreamAccess().accessInputStream();
try {
sources.addInputStream( stream );
}
finally {
try {
stream.close();
}
catch ( IOException ignore ) {
log.trace( "Was unable to close input stream" );
}
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Add packages found as a result of scanning
for ( PackageDescriptor packageDescriptor : scanResult.getLocatedPackages() ) {
sources.addPackage( packageDescriptor.getName() );
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Add classes found as a result of scanning
for ( ClassDescriptor classDescriptor : scanResult.getLocatedClasses() ) {
sources.addAnnotatedClassName( classDescriptor.getName() );
}
}
private static IndexView augmentJandexFromMappings(
IndexView baseJandexIndex,
MetadataSources sources,
MetadataBuildingOptions options) {
final List<BindResult<JaxbEntityMappings>> jpaXmlBindings = new ArrayList<BindResult<JaxbEntityMappings>>();
for ( BindResult bindResult : sources.getBindResultList() ) {
if ( JaxbEntityMappings.class.isInstance( bindResult.getRoot() ) ) {

View File

@ -23,6 +23,8 @@
*/
package org.hibernate.metamodel.spi;
import java.net.URL;
/**
* During the process of building this metamodel, accessing the ClassLoader
* is very discouraged. However, sometimes it is needed. This contract helps
@ -39,4 +41,6 @@ public interface ClassLoaderAccess {
* @return The Class.
*/
public <T> Class<T> classForName(String name);
public URL locateResource(String resourceName);
}

View File

@ -32,6 +32,10 @@ import org.hibernate.boot.spi.CacheRegionDefinition;
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.metamodel.MetadataSourceProcessingOrder;
import org.hibernate.metamodel.archive.scan.spi.ScanEnvironment;
import org.hibernate.metamodel.archive.scan.spi.ScanOptions;
import org.hibernate.metamodel.archive.scan.spi.Scanner;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.metamodel.spi.relational.Database;
import org.hibernate.type.BasicType;
@ -80,6 +84,39 @@ public interface MetadataBuildingOptions {
*/
IndexView getJandexView();
/**
* Access to the options to be used for scanning
*
* @return The scan options
*/
ScanOptions getScanOptions();
/**
* Access to the environment for scanning. Consider this temporary; see discussion on
* {@link ScanEnvironment}
*
* @return The scan environment
*/
ScanEnvironment getScanEnvironment();
/**
* Access to the Scanner to be used for scanning. Can be:<ul>
* <li>A Scanner instance</li>
* <li>A Class reference to the Scanner implementor</li>
* <li>A String naming the Scanner implementor</li>
* </ul>
*
* @return The scanner
*/
Object getScanner();
/**
* Access to the ArchiveDescriptorFactory to be used for scanning
*
* @return The ArchiveDescriptorFactory
*/
ArchiveDescriptorFactory getArchiveDescriptorFactory();
/**
* Access the temporary ClassLoader passed to us as defined by
* {@link javax.persistence.spi.PersistenceUnitInfo#getNewTempClassLoader()}, if any.

View File

@ -1,38 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2009, 2012, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.ejb.packaging;
import java.io.InputStream;
/**
* @deprecated Doubly deprecated actually :) Moved to {@link org.hibernate.jpa.boot.spi.NamedInputStream}
* due to package renaming (org.hibernate.ejb -> org.hibernate.jpa). But also, the role fulfilled by this class
* was moved to the new {@link org.hibernate.jpa.boot.spi.InputStreamAccess} contract.
*/
@Deprecated
public class NamedInputStream extends org.hibernate.jpa.boot.spi.NamedInputStream {
public NamedInputStream(String name, InputStream stream) {
super( name, stream );
}
}

View File

@ -453,29 +453,7 @@ public interface AvailableSettings {
//Use the org.hibernate prefix. instead of hibernate. as it is a query hint se QueryHints
String FLUSH_MODE = "org.hibernate.flushMode";
/**
* Pass an implementation of {@link org.hibernate.jpa.boot.scan.spi.Scanner}
* (or the deprecated {@link org.hibernate.ejb.packaging.Scanner}). Accepts
* either:<ul>
* <li>an actual instance</li>
* <li>a reference to a Class that implements Scanner</li>
* <li>a fully qualified name of a Class that implements Scanner</li>
* </ul>
*/
String SCANNER = "hibernate.ejb.resource_scanner";
/**
* Pass {@link org.hibernate.jpa.boot.archive.spi.ArchiveDescriptorFactory} to use
* in the scanning process. Accepts either:<ul>
* <li>an ArchiveDescriptorFactory instance</li>
* <li>a reference to a Class that implements ArchiveDescriptorFactory</li>
* <li>a fully qualified name of a Class that implements ArchiveDescriptorFactory</li>
* </ul>
*
* @see #SCANNER
* @see org.hibernate.jpa.boot.scan.spi.Scanner
*/
String SCANNER_ARCHIVE_DELEGATE = "hibernate.jpa.scanner_archive_delegate";
String SCANNER = org.hibernate.cfg.AvailableSettings.SCANNER;
/**
* List of classes names

View File

@ -1,4 +0,0 @@
/**
* The internals of archive scanning support
*/
package org.hibernate.jpa.boot.archive.internal;

View File

@ -1,15 +0,0 @@
/**
* Defines the SPI for support of "scanning" of "archives".
* <p/>
* Scanning might mean:<ul>
* <li>searching for classes/packages that define certain interfaces</li>
* <li>locating named resources</li>
* </ul>
* And "archive" might mean:<ul>
* <li>a {@code .jar} file</li>
* <li>an exploded directory</li>
* <li>an OSGi bundle</li>
* <li>etc</li>
* </ul>
*/
package org.hibernate.jpa.boot.archive.spi;

View File

@ -24,8 +24,6 @@
package org.hibernate.jpa.boot.internal;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
@ -64,19 +62,8 @@ import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.ValueHolder;
import org.hibernate.jaxb.spi.cfg.JaxbHibernateConfiguration;
import org.hibernate.jpa.AvailableSettings;
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.jpa.boot.scan.internal.StandardJpaScanEnvironmentImpl;
import org.hibernate.jpa.boot.scan.internal.StandardScanOptions;
import org.hibernate.jpa.boot.scan.internal.StandardScanner;
import org.hibernate.jpa.boot.scan.spi.ScanEnvironment;
import org.hibernate.jpa.boot.scan.spi.ScanOptions;
import org.hibernate.jpa.boot.scan.spi.ScanResult;
import org.hibernate.jpa.boot.scan.spi.Scanner;
import org.hibernate.jpa.boot.spi.ClassDescriptor;
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
import org.hibernate.jpa.boot.spi.IntegratorProvider;
import org.hibernate.jpa.boot.spi.MappingFileDescriptor;
import org.hibernate.jpa.boot.spi.PackageDescriptor;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import org.hibernate.jpa.boot.spi.StrategyRegistrationProviderList;
import org.hibernate.jpa.boot.spi.TypeContributorList;
@ -90,6 +77,7 @@ import org.hibernate.jpa.spi.IdentifierGeneratorStrategyProvider;
import org.hibernate.metamodel.MetadataBuilder;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.SessionFactoryBuilder;
import org.hibernate.metamodel.archive.scan.internal.StandardScanOptions;
import org.hibernate.metamodel.spi.MetadataImplementor;
import org.hibernate.metamodel.spi.TypeContributor;
import org.hibernate.metamodel.spi.binding.EntityBinding;
@ -100,9 +88,6 @@ import org.hibernate.service.ConfigLoader;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.jboss.jandex.Index;
import org.jboss.jandex.IndexView;
import org.jboss.jandex.Indexer;
import org.jboss.logging.Logger;
import static org.hibernate.cfg.AvailableSettings.JACC_CONTEXT_ID;
@ -147,11 +132,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
* Names a {@link TypeContributorList}
*/
public static final String TYPE_CONTRIBUTORS = "hibernate.type_contributors";
/**
* Names a Jandex {@link Index} instance to use.
*/
public static final String JANDEX_INDEX = "hibernate.jandex_index";
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -202,13 +182,9 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
this.standardServiceRegistry = ssrBuilder.build();
configure( standardServiceRegistry, mergedSettings );
// Perform deployment scanning
final ScanResult scanResult = scanDeployment( bsr );
// Build the Metadata object
final MetadataSources metadataSources = new MetadataSources( bsr );
populate( metadataSources, scanResult, mergedSettings, standardServiceRegistry );
populate( metadataSources, mergedSettings, standardServiceRegistry );
final MetadataBuilder metamodelBuilder = metadataSources.getMetadataBuilder( standardServiceRegistry );
populate( metamodelBuilder, mergedSettings, standardServiceRegistry );
this.metadata = (MetadataImplementor) metamodelBuilder.build();
@ -691,135 +667,14 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
}
}
@SuppressWarnings("unchecked")
private ScanResult scanDeployment(BootstrapServiceRegistry bootstrapServiceRegistry) {
IndexView jandexIndex = (IndexView) configurationValues.remove( JANDEX_INDEX );
Indexer jandexIndexer = null;
if ( jandexIndex == null ) {
// If we don't have a Jandex index passed to us, we need to build one.
jandexIndexer = new Indexer();
}
final Scanner scanner = locateOrBuildScanner( bootstrapServiceRegistry );
final ScanEnvironment environment = new StandardJpaScanEnvironmentImpl( persistenceUnit );
final ScanOptions options = determineScanOptions( jandexIndexer, jandexIndex );
final ScanResult result = scanner.scan( environment, options );
if ( jandexIndexer != null ) {
jandexIndex = jandexIndexer.complete();
// if the indexer indexed anything use that index
//
// IMPL NOTE : (unfortunately?) Jandex has no way to see if an Indexer
// actually indexed anything. But, it also manages package-info.class
// as any other class, so this check should be fine
if ( !jandexIndex.getKnownClasses().isEmpty() ) {
configurationValues.put( JANDEX_INDEX, jandexIndex );
}
}
return result;
}
@SuppressWarnings("unchecked")
private Scanner locateOrBuildScanner(BootstrapServiceRegistry bootstrapServiceRegistry) {
final Object value = configurationValues.remove( AvailableSettings.SCANNER );
if ( value == null ) {
return createStandardScanner( bootstrapServiceRegistry );
}
if ( Scanner.class.isInstance( value ) ) {
return (Scanner) value;
}
Class<? extends Scanner> scannerClass;
if ( Class.class.isInstance( value ) ) {
try {
scannerClass = (Class<? extends Scanner>) value;
}
catch ( ClassCastException e ) {
throw persistenceException( "Expecting Scanner implementation, but found " + ((Class) value).getName() );
}
}
else {
final String scannerClassName = value.toString();
try {
scannerClass = bootstrapServiceRegistry.getService( ClassLoaderService.class ).classForName( scannerClassName );
}
catch ( ClassCastException e ) {
throw persistenceException( "Expecting Scanner implementation, but found " + scannerClassName );
}
}
try {
return scannerClass.newInstance();
}
catch ( Exception e ) {
throw persistenceException( "Unable to instantiate Scanner class: " + scannerClass, e );
}
}
@SuppressWarnings("unchecked")
private Scanner createStandardScanner(BootstrapServiceRegistry bootstrapServiceRegistry) {
final Object value = configurationValues.remove( AvailableSettings.SCANNER_ARCHIVE_DELEGATE );
if ( value == null ) {
return new StandardScanner();
}
if ( ArchiveDescriptorFactory.class.isInstance( value ) ) {
return new StandardScanner( (ArchiveDescriptorFactory) value );
}
final Class<? extends ArchiveDescriptorFactory> delegateClass;
if ( Class.class.isInstance( value ) ) {
try {
delegateClass = (Class<? extends ArchiveDescriptorFactory>) value;
}
catch ( ClassCastException e ) {
throw persistenceException(
"Expecting ArchiveDescriptorFactory implementation, but found " + ((Class) value).getName()
);
}
}
else {
final String delegateClassName = value.toString();
try {
delegateClass = bootstrapServiceRegistry.getService( ClassLoaderService.class ).classForName( delegateClassName );
}
catch ( ClassCastException e ) {
throw persistenceException(
"Expecting ArchiveDescriptorFactory implementation, but found " + delegateClassName
);
}
}
try {
final ArchiveDescriptorFactory delegate = delegateClass.newInstance();
return new StandardScanner( delegate );
}
catch (Exception e) {
throw persistenceException( "Unable to instantiate ArchiveDescriptorFactory class: " + delegateClass, e );
}
}
private ScanOptions determineScanOptions(Indexer indexer, IndexView jandexIndex) {
return new StandardScanOptions(
indexer,
jandexIndex,
(String) configurationValues.get( AvailableSettings.AUTODETECTION ),
persistenceUnit.isExcludeUnlistedClasses()
);
}
@SuppressWarnings("unchecked")
private void populate(
MetadataSources metadataSources,
ScanResult scanResult,
MergedSettings mergedSettings,
StandardServiceRegistry ssr) {
final ClassLoaderService classLoaderService = ssr.getService( ClassLoaderService.class );
// todo : make MetadataSources/Metadata capable of handling duplicates
// todo : make sure MetadataSources/Metadata are capable of handling duplicate sources
// explicit persistence unit mapping files listings
if ( persistenceUnit.getMappingFileNames() != null ) {
@ -904,35 +759,17 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
metadataSources.addResource( ormXml );
}
}
// Add mapping files found as a result of scanning
for ( MappingFileDescriptor mappingFileDescriptor : scanResult.getLocatedMappingFiles() ) {
final InputStream stream = mappingFileDescriptor.getStreamAccess().accessInputStream();
try {
metadataSources.addInputStream( stream );
}
finally {
try {
stream.close();
}
catch ( IOException ignore ) {
LOG.trace( "Was unable to close input stream" );
}
}
}
// Add packages found as a result of scanning
for ( PackageDescriptor packageDescriptor : scanResult.getLocatedPackages() ) {
metadataSources.addPackage( packageDescriptor.getName() );
}
// Add classes found as a result of scanning
for ( ClassDescriptor classDescriptor : scanResult.getLocatedClasses() ) {
metadataSources.addAnnotatedClassName( classDescriptor.getName() );
}
}
private void populate(MetadataBuilder metamodelBuilder, MergedSettings mergedSettings, StandardServiceRegistry ssr) {
metamodelBuilder.with( new StandardJpaScanEnvironmentImpl( persistenceUnit ) );
metamodelBuilder.with(
new StandardScanOptions(
(String) configurationValues.get( AvailableSettings.AUTODETECTION ),
persistenceUnit.isExcludeUnlistedClasses()
)
);
if ( mergedSettings.cacheRegionDefinitions != null ) {
for ( CacheRegionDefinition localCacheRegionDefinition : mergedSettings.cacheRegionDefinitions ) {
metamodelBuilder.with( localCacheRegionDefinition );
@ -953,11 +790,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
metamodelBuilder.with( typeContributor );
}
}
IndexView jandexIndex = (IndexView) configurationValues.remove( JANDEX_INDEX );
if ( jandexIndex != null ) {
metamodelBuilder.with( jandexIndex );
}
}
/**

View File

@ -1,73 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.internal;
import org.hibernate.jpa.boot.spi.InputStreamAccess;
import org.hibernate.jpa.boot.spi.MappingFileDescriptor;
/**
* @author Steve Ebersole
*/
public class MappingFileDescriptorImpl implements MappingFileDescriptor {
private final String name;
private final InputStreamAccess streamAccess;
public MappingFileDescriptorImpl(String name, InputStreamAccess streamAccess) {
this.name = name;
this.streamAccess = streamAccess;
}
@Override
public String getName() {
return name;
}
@Override
public InputStreamAccess getStreamAccess() {
return streamAccess;
}
// @Override
// public boolean equals(Object o) {
// if ( this == o ) {
// return true;
// }
// if ( o == null || getClass() != o.getClass() ) {
// return false;
// }
//
// MappingFileDescriptorImpl that = (MappingFileDescriptorImpl) o;
//
// return name.equals( that.name )
// && streamAccess.getStreamName().equals( that.streamAccess.getStreamName() );
//
// }
//
// @Override
// public int hashCode() {
// int result = name.hashCode();
// result = 31 * result + streamAccess.getStreamName().hashCode();
// return result;
// }
}

View File

@ -47,9 +47,9 @@ import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.jpa.AvailableSettings;
import org.hibernate.jpa.boot.archive.internal.ArchiveHelper;
import org.hibernate.jpa.internal.EntityManagerMessageLogger;
import org.hibernate.jpa.internal.util.ConfigurationHelper;
import org.hibernate.metamodel.archive.internal.ArchiveHelper;
import org.hibernate.metamodel.source.spi.XsdException;
import org.jboss.logging.Logger;

View File

@ -21,14 +21,14 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.scan.internal;
package org.hibernate.jpa.boot.internal;
import java.net.URL;
import java.util.Collections;
import java.util.List;
import org.hibernate.jpa.boot.scan.spi.ScanEnvironment;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import org.hibernate.metamodel.archive.scan.spi.ScanEnvironment;
/**
* Implementation of ScanEnvironment leveraging a JPA deployment descriptor.
@ -72,9 +72,4 @@ public class StandardJpaScanEnvironmentImpl implements ScanEnvironment {
public List<String> getExplicitlyListedMappingFiles() {
return explicitlyListedMappingFiles;
}
@Override
public PersistenceUnitDescriptor getPersistenceUnitDescriptor() {
return persistenceUnitDescriptor;
}
}

View File

@ -1,73 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.jpa.boot.scan.spi;
import org.hibernate.jpa.boot.archive.spi.ArchiveContext;
import org.hibernate.jpa.boot.archive.spi.ArchiveEntry;
import org.hibernate.jpa.boot.archive.spi.ArchiveEntryHandler;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
/**
* @author Steve Ebersole
*/
public class ArchiveContextImpl implements ArchiveContext {
private final ScanEnvironment environment;
private final boolean isRootUrl;
private final ArchiveEntryHandlers entryHandlers;
public ArchiveContextImpl(
ScanEnvironment environment,
boolean isRootUrl,
ArchiveEntryHandlers entryHandlers) {
this.environment = environment;
this.isRootUrl = isRootUrl;
this.entryHandlers = entryHandlers;
}
@Override
@SuppressWarnings("deprecation")
public PersistenceUnitDescriptor getPersistenceUnitDescriptor() {
return environment.getPersistenceUnitDescriptor();
}
@Override
public boolean isRootUrl() {
return isRootUrl;
}
@Override
public ArchiveEntryHandler obtainArchiveEntryHandler(ArchiveEntry entry) {
final String nameWithinArchive = entry.getNameWithinArchive();
if ( nameWithinArchive.endsWith( "package-info.class" ) ) {
return entryHandlers.getPackageInfoHandler();
}
else if ( nameWithinArchive.endsWith( ".class" ) ) {
return entryHandlers.getClassFileHandler();
}
else {
return entryHandlers.getFileHandler();
}
}
}

View File

@ -63,24 +63,49 @@ public interface EntityManagerMessageLogger extends CoreMessageLogger {
@Message( value = "An Ejb3Configuration was unbound from name: %s", id = 15004 )
void ejb3ConfigurationUnboundFromName( String name );
/**
* @deprecated Moved to the {@link org.hibernate.internal.UrlMessageBundle}
* contract
*/
@Deprecated
@LogMessage( level = WARN )
@Message( value = "Exploded jar file does not exist (ignored): %s", id = 15005 )
void explodedJarDoesNotExist( URL jarUrl );
/**
* @deprecated Moved to the {@link org.hibernate.internal.UrlMessageBundle}
* contract
*/
@Deprecated
@LogMessage( level = WARN )
@Message( value = "Exploded jar file not a directory (ignored): %s", id = 15006 )
void explodedJarNotDirectory( URL jarUrl );
/**
* @deprecated Moved to the {@link org.hibernate.internal.UrlMessageBundle}
* contract
*/
@Deprecated
@LogMessage( level = ERROR )
@Message( value = "Malformed URL: %s", id = 15008 )
void malformedUrl( URL jarUrl,
@Cause URISyntaxException e );
/**
* @deprecated Moved to the {@link org.hibernate.internal.UrlMessageBundle}
* contract
*/
@Deprecated
@LogMessage( level = WARN )
@Message( value = "Malformed URL: %s", id = 15009 )
void malformedUrlWarning( URL jarUrl,
@Cause URISyntaxException e );
/**
* @deprecated Moved to the {@link org.hibernate.internal.UrlMessageBundle}
* contract
*/
@Deprecated
@LogMessage( level = WARN )
@Message( value = "Unable to find file (ignored): %s", id = 15010 )
void unableToFindFile( URL jarUrl,

View File

@ -1,10 +1,10 @@
package org.hibernate.jpa.test.packaging;
import org.hibernate.jpa.boot.scan.internal.StandardScanner;
import org.hibernate.jpa.boot.scan.spi.ScanEnvironment;
import org.hibernate.jpa.boot.scan.spi.ScanOptions;
import org.hibernate.jpa.boot.scan.spi.ScanResult;
import org.hibernate.jpa.boot.scan.spi.Scanner;
import org.hibernate.metamodel.archive.scan.internal.StandardScanner;
import org.hibernate.metamodel.archive.scan.spi.ScanEnvironment;
import org.hibernate.metamodel.archive.scan.spi.ScanOptions;
import org.hibernate.metamodel.archive.scan.spi.ScanParameters;
import org.hibernate.metamodel.archive.scan.spi.Scanner;
/**
* @author Emmanuel Bernard
@ -22,8 +22,11 @@ public class CustomScanner implements Scanner {
}
@Override
public ScanResult scan(ScanEnvironment environment, ScanOptions options) {
public org.hibernate.metamodel.archive.scan.spi.ScanResult scan(
ScanEnvironment environment,
ScanOptions options,
ScanParameters parameters) {
isUsed = true;
return delegate.scan( environment, options );
return delegate.scan( environment, options, parameters );
}
}

View File

@ -36,25 +36,25 @@ import java.util.Collections;
import java.util.List;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.jpa.boot.archive.internal.ArchiveHelper;
import org.hibernate.jpa.boot.archive.internal.ExplodedArchiveDescriptor;
import org.hibernate.jpa.boot.archive.internal.JarFileBasedArchiveDescriptor;
import org.hibernate.jpa.boot.archive.internal.JarProtocolArchiveDescriptor;
import org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory;
import org.hibernate.jpa.boot.archive.spi.ArchiveContext;
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor;
import org.hibernate.jpa.boot.internal.ClassDescriptorImpl;
import org.hibernate.jpa.boot.scan.internal.ResultCoordinator;
import org.hibernate.jpa.boot.scan.internal.ScanResultCollector;
import org.hibernate.jpa.boot.scan.internal.StandardScanOptions;
import org.hibernate.jpa.boot.scan.internal.StandardScanner;
import org.hibernate.jpa.boot.scan.spi.ArchiveContextImpl;
import org.hibernate.jpa.boot.scan.spi.ScanEnvironment;
import org.hibernate.jpa.boot.scan.spi.ScanResult;
import org.hibernate.jpa.boot.spi.MappingFileDescriptor;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import org.hibernate.jpa.test.pack.defaultpar.Version;
import org.hibernate.jpa.test.pack.explodedpar.Carpet;
import org.hibernate.metamodel.archive.internal.ArchiveHelper;
import org.hibernate.metamodel.archive.internal.ExplodedArchiveDescriptor;
import org.hibernate.metamodel.archive.internal.JarFileBasedArchiveDescriptor;
import org.hibernate.metamodel.archive.internal.JarProtocolArchiveDescriptor;
import org.hibernate.metamodel.archive.internal.StandardArchiveDescriptorFactory;
import org.hibernate.metamodel.archive.scan.internal.ClassDescriptorImpl;
import org.hibernate.metamodel.archive.scan.internal.ScanResultCollector;
import org.hibernate.metamodel.archive.scan.internal.StandardScanOptions;
import org.hibernate.metamodel.archive.scan.internal.StandardScanner;
import org.hibernate.metamodel.archive.scan.spi.AbstractScannerImpl;
import org.hibernate.metamodel.archive.scan.spi.JandexInitializer;
import org.hibernate.metamodel.archive.scan.spi.MappingFileDescriptor;
import org.hibernate.metamodel.archive.scan.spi.ScanEnvironment;
import org.hibernate.metamodel.archive.scan.spi.ScanParameters;
import org.hibernate.metamodel.archive.scan.spi.ScanResult;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptor;
import org.hibernate.metamodel.internal.JandexInitManager;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
@ -97,7 +97,17 @@ public class JarVisitorTest extends PackagingTestCase {
private ScanResult standardScan(URL url) {
ScanEnvironment env = new ScanEnvironmentImpl( url );
return new StandardScanner().scan( env, new StandardScanOptions() );
return new StandardScanner().scan(
env,
new StandardScanOptions(),
new ScanParameters() {
private final JandexInitManager jandexInitManager = new JandexInitManager();
@Override
public JandexInitializer getJandexInitializer() {
return jandexInitManager;
}
}
);
}
private static class ScanEnvironmentImpl implements ScanEnvironment {
@ -126,11 +136,6 @@ public class JarVisitorTest extends PackagingTestCase {
public List<String> getExplicitlyListedMappingFiles() {
return Collections.emptyList();
}
@Override
public PersistenceUnitDescriptor getPersistenceUnitDescriptor() {
return null;
}
}
@Test
@ -178,14 +183,20 @@ public class JarVisitorTest extends PackagingTestCase {
);
ScanEnvironment environment = new ScanEnvironmentImpl( rootUrl );
ScanResultCollector collector = new ScanResultCollector( environment, new StandardScanOptions() );
ScanResultCollector collector = new ScanResultCollector(
environment,
new StandardScanOptions(),
new ScanParameters() {
private final JandexInitManager jandexInitManager = new JandexInitManager();
@Override
public JandexInitializer getJandexInitializer() {
return jandexInitManager;
}
}
);
archiveDescriptor.visitArchive(
new ArchiveContextImpl(
environment,
true,
new ResultCoordinator( collector )
)
new AbstractScannerImpl.ArchiveContextImpl( true, collector )
);
validateResults(
@ -203,14 +214,20 @@ public class JarVisitorTest extends PackagingTestCase {
);
environment = new ScanEnvironmentImpl( rootUrl );
collector = new ScanResultCollector( environment, new StandardScanOptions() );
collector = new ScanResultCollector(
environment,
new StandardScanOptions(),
new ScanParameters() {
private final JandexInitManager jandexInitManager = new JandexInitManager();
@Override
public JandexInitializer getJandexInitializer() {
return jandexInitManager;
}
}
);
archiveDescriptor.visitArchive(
new ArchiveContextImpl(
environment,
true,
new ResultCoordinator( collector )
)
new AbstractScannerImpl.ArchiveContextImpl( true, collector )
);
validateResults(
collector.toScanResult(),
@ -234,14 +251,20 @@ public class JarVisitorTest extends PackagingTestCase {
);
final ScanEnvironment environment = new ScanEnvironmentImpl( rootUrl );
final ScanResultCollector collector = new ScanResultCollector( environment, new StandardScanOptions() );
final ScanResultCollector collector = new ScanResultCollector(
environment,
new StandardScanOptions(),
new ScanParameters() {
private final JandexInitManager jandexInitManager = new JandexInitManager();
@Override
public JandexInitializer getJandexInitializer() {
return jandexInitManager;
}
}
);
archiveDescriptor.visitArchive(
new ArchiveContextImpl(
environment,
true,
new ResultCoordinator( collector )
)
new AbstractScannerImpl.ArchiveContextImpl( true, collector )
);
validateResults(

View File

@ -69,6 +69,7 @@ import org.hibernate.jpa.test.pack.various.Airplane;
import org.hibernate.jpa.test.pack.various.Seat;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.fail;
@ -76,7 +77,7 @@ import static org.junit.Assert.fail;
* @author Hardy Ferentschik
* @author Brett Meyer
*/
public abstract class PackagingTestCase extends BaseCoreFunctionalTestCase {
public abstract class PackagingTestCase extends BaseUnitTestCase {
protected static ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
protected static ClassLoader bundleClassLoader;
protected static File packageTargetDir;
@ -290,11 +291,7 @@ public abstract class PackagingTestCase extends BaseCoreFunctionalTestCase {
JavaArchive archive = ShrinkWrap.create( JavaArchive.class,fileName );
archive.addClasses(
Morito.class,
Item.class,
Distributor.class,
Cat.class,
Kitten.class,
LastUpdateListener.class
Item.class
);
ArchivePath path = ArchivePaths.create( "META-INF/persistence.xml" );

View File

@ -31,19 +31,21 @@ import java.util.HashMap;
import org.hibernate.jpa.AvailableSettings;
import org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor;
import org.hibernate.jpa.boot.scan.internal.StandardJpaScanEnvironmentImpl;
import org.hibernate.jpa.boot.scan.internal.StandardScanOptions;
import org.hibernate.jpa.boot.scan.spi.ScanEnvironment;
import org.hibernate.jpa.boot.scan.spi.ScanOptions;
import org.hibernate.jpa.boot.internal.StandardJpaScanEnvironmentImpl;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import org.hibernate.jpa.boot.scan.internal.StandardScanner;
import org.hibernate.jpa.boot.spi.ClassDescriptor;
import org.hibernate.jpa.boot.spi.MappingFileDescriptor;
import org.hibernate.jpa.boot.spi.NamedInputStream;
import org.hibernate.jpa.boot.scan.spi.ScanResult;
import org.hibernate.jpa.boot.scan.spi.Scanner;
import org.hibernate.jpa.test.pack.defaultpar.ApplicationServer;
import org.hibernate.jpa.test.pack.defaultpar.Version;
import org.hibernate.metamodel.archive.scan.internal.StandardScanOptions;
import org.hibernate.metamodel.archive.scan.internal.StandardScanner;
import org.hibernate.metamodel.archive.scan.spi.ClassDescriptor;
import org.hibernate.metamodel.archive.scan.spi.JandexInitializer;
import org.hibernate.metamodel.archive.scan.spi.MappingFileDescriptor;
import org.hibernate.metamodel.archive.scan.spi.ScanEnvironment;
import org.hibernate.metamodel.archive.scan.spi.ScanOptions;
import org.hibernate.metamodel.archive.scan.spi.ScanParameters;
import org.hibernate.metamodel.archive.scan.spi.ScanResult;
import org.hibernate.metamodel.archive.scan.spi.Scanner;
import org.hibernate.metamodel.internal.JandexInitManager;
import org.junit.Test;
@ -66,7 +68,17 @@ public class ScannerTest extends PackagingTestCase {
ScanEnvironment env = new StandardJpaScanEnvironmentImpl( descriptor );
ScanOptions options = new StandardScanOptions( "hbm,class", descriptor.isExcludeUnlistedClasses() );
Scanner scanner = new StandardScanner();
ScanResult scanResult = scanner.scan( env, options );
ScanResult scanResult = scanner.scan(
env,
options,
new ScanParameters() {
private final JandexInitManager jandexInitManager = new JandexInitManager();
@Override
public JandexInitializer getJandexInitializer() {
return jandexInitManager;
}
}
);
assertEquals( 3, scanResult.getLocatedClasses().size() );
assertClassesContained( scanResult, ApplicationServer.class );
@ -79,11 +91,6 @@ public class ScannerTest extends PackagingTestCase {
InputStream stream = mappingFileDescriptor.getStreamAccess().accessInputStream();
assertNotNull( stream );
stream.close();
NamedInputStream namedInputStream = mappingFileDescriptor.getStreamAccess().asNamedInputStream();
assertNotNull( namedInputStream );
stream = namedInputStream.getStream();
assertNotNull( stream );
stream.close();
}
}

View File

@ -27,11 +27,10 @@ import javax.persistence.PersistenceException;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.jpa.boot.archive.spi.ArchiveContext;
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor;
import org.hibernate.jpa.boot.archive.spi.ArchiveEntry;
import org.hibernate.jpa.boot.spi.InputStreamAccess;
import org.hibernate.jpa.boot.spi.NamedInputStream;
import org.hibernate.metamodel.archive.spi.ArchiveContext;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptor;
import org.hibernate.metamodel.archive.spi.ArchiveEntry;
import org.hibernate.metamodel.archive.spi.InputStreamAccess;
import org.osgi.framework.Bundle;
import org.osgi.framework.wiring.BundleWiring;
@ -77,11 +76,6 @@ public class OsgiArchiveDescriptor implements ArchiveDescriptor {
public InputStream accessInputStream() {
return openInputStream();
}
@Override
public NamedInputStream asNamedInputStream() {
return new NamedInputStream( resource, openInputStream() );
}
private InputStream openInputStream() {
try {

View File

@ -22,8 +22,8 @@ package org.hibernate.osgi;
import java.net.URL;
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor;
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptor;
import org.hibernate.metamodel.archive.spi.ArchiveDescriptorFactory;
import org.osgi.framework.Bundle;

View File

@ -20,7 +20,7 @@
*/
package org.hibernate.osgi;
import org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl;
import org.hibernate.metamodel.archive.scan.spi.AbstractScannerImpl;
import org.osgi.framework.Bundle;