diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/ArchiveHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/ArchiveHelper.java similarity index 98% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/ArchiveHelper.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/internal/ArchiveHelper.java index 2a31b9357a..b3fffc57cb 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/ArchiveHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/ArchiveHelper.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.archive.internal; +package org.hibernate.boot.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.boot.archive.spi.ArchiveException; import org.jboss.logging.Logger; diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/ByteArrayInputStreamAccess.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/ByteArrayInputStreamAccess.java similarity index 85% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/ByteArrayInputStreamAccess.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/internal/ByteArrayInputStreamAccess.java index 8b949206ce..76c148ace5 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/ByteArrayInputStreamAccess.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/ByteArrayInputStreamAccess.java @@ -21,13 +21,12 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.internal; +package org.hibernate.boot.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.boot.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() ); - } } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/ExplodedArchiveDescriptor.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/ExplodedArchiveDescriptor.java similarity index 86% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/ExplodedArchiveDescriptor.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/internal/ExplodedArchiveDescriptor.java index 6633e870a8..172ca7ba99 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/ExplodedArchiveDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/ExplodedArchiveDescriptor.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.archive.internal; +package org.hibernate.boot.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.boot.archive.spi.AbstractArchiveDescriptor; +import org.hibernate.boot.archive.spi.ArchiveContext; +import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory; +import org.hibernate.boot.archive.spi.ArchiveEntry; +import org.hibernate.boot.archive.spi.ArchiveException; +import org.hibernate.boot.archive.spi.InputStreamAccess; -import org.jboss.logging.Logger; +import static org.hibernate.internal.log.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; } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/FileInputStreamAccess.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/FileInputStreamAccess.java similarity index 86% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/FileInputStreamAccess.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/internal/FileInputStreamAccess.java index 7d9294364a..b8714ff902 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/FileInputStreamAccess.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/FileInputStreamAccess.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.internal; +package org.hibernate.boot.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.boot.archive.spi.ArchiveException; +import org.hibernate.boot.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() ); - } } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/JarFileBasedArchiveDescriptor.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/JarFileBasedArchiveDescriptor.java similarity index 83% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/JarFileBasedArchiveDescriptor.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/internal/JarFileBasedArchiveDescriptor.java index 66df6c1dc3..3d356508e0 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/JarFileBasedArchiveDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/JarFileBasedArchiveDescriptor.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.archive.internal; +package org.hibernate.boot.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.boot.archive.spi.AbstractArchiveDescriptor; +import org.hibernate.boot.archive.spi.ArchiveContext; +import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory; +import org.hibernate.boot.archive.spi.ArchiveEntry; +import org.hibernate.boot.archive.spi.ArchiveEntryHandler; +import org.hibernate.boot.archive.spi.ArchiveException; +import org.hibernate.boot.archive.spi.InputStreamAccess; -import org.jboss.logging.Logger; +import static org.hibernate.internal.log.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; } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/JarInputStreamBasedArchiveDescriptor.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/JarInputStreamBasedArchiveDescriptor.java similarity index 84% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/JarInputStreamBasedArchiveDescriptor.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/internal/JarInputStreamBasedArchiveDescriptor.java index 40dd37b06c..8998c115d5 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/JarInputStreamBasedArchiveDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/JarInputStreamBasedArchiveDescriptor.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.archive.internal; +package org.hibernate.boot.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.boot.archive.spi.AbstractArchiveDescriptor; +import org.hibernate.boot.archive.spi.ArchiveContext; +import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory; +import org.hibernate.boot.archive.spi.ArchiveEntry; +import org.hibernate.boot.archive.spi.ArchiveException; +import org.hibernate.boot.archive.spi.InputStreamAccess; -import org.jboss.logging.Logger; +import static org.hibernate.internal.log.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 diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/JarProtocolArchiveDescriptor.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/JarProtocolArchiveDescriptor.java similarity index 91% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/JarProtocolArchiveDescriptor.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/internal/JarProtocolArchiveDescriptor.java index d25c981308..3576d9deb7 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/JarProtocolArchiveDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/JarProtocolArchiveDescriptor.java @@ -21,14 +21,14 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.archive.internal; +package org.hibernate.boot.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.boot.archive.spi.ArchiveContext; +import org.hibernate.boot.archive.spi.ArchiveDescriptor; +import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory; /** * An ArchiveDescriptor implementation for handling archives whose url reported a JAR protocol (i.e., jar://). diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/StandardArchiveDescriptorFactory.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/StandardArchiveDescriptorFactory.java similarity index 94% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/StandardArchiveDescriptorFactory.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/internal/StandardArchiveDescriptorFactory.java index 5b974c2a12..c2a55d1653 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/StandardArchiveDescriptorFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/StandardArchiveDescriptorFactory.java @@ -21,15 +21,15 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.archive.internal; +package org.hibernate.boot.archive.internal; import java.io.File; import java.net.URISyntaxException; import java.net.URL; import org.hibernate.internal.util.StringHelper; -import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor; -import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptorFactory; +import org.hibernate.boot.archive.spi.ArchiveDescriptor; +import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory; /** * Standard implementation of ArchiveDescriptorFactory diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/UrlInputStreamAccess.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/UrlInputStreamAccess.java similarity index 85% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/UrlInputStreamAccess.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/internal/UrlInputStreamAccess.java index 4281201381..f038396fff 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/UrlInputStreamAccess.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/UrlInputStreamAccess.java @@ -21,14 +21,13 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.internal; +package org.hibernate.boot.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.boot.archive.spi.InputStreamAccess; /** * @author Steve Ebersole @@ -54,9 +53,4 @@ public class UrlInputStreamAccess implements InputStreamAccess { throw new HibernateException( "Could not open url stream : " + url.toExternalForm() ); } } - - @Override - public NamedInputStream asNamedInputStream() { - return new NamedInputStream( getStreamName(), accessInputStream() ); - } } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/package-info.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/package-info.java similarity index 51% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/package-info.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/internal/package-info.java index 7fe8de9a17..94f5ff16f2 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/package-info.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/package-info.java @@ -1,4 +1,4 @@ /** * The internals of archive scanning support */ -package org.hibernate.jpa.boot.archive.internal; +package org.hibernate.boot.archive.internal; diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/ClassDescriptorImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/ClassDescriptorImpl.java similarity index 91% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/ClassDescriptorImpl.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/ClassDescriptorImpl.java index f8d15c1419..eeca071dfd 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/ClassDescriptorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/ClassDescriptorImpl.java @@ -21,10 +21,10 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.internal; +package org.hibernate.boot.archive.scan.internal; -import org.hibernate.jpa.boot.spi.ClassDescriptor; -import org.hibernate.jpa.boot.spi.InputStreamAccess; +import org.hibernate.boot.archive.scan.spi.ClassDescriptor; +import org.hibernate.boot.archive.spi.InputStreamAccess; /** * @author Steve Ebersole diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/MappingFileDescriptorImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/MappingFileDescriptorImpl.java similarity index 92% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/MappingFileDescriptorImpl.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/MappingFileDescriptorImpl.java index 1a073c4002..671d82b9b9 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/MappingFileDescriptorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/MappingFileDescriptorImpl.java @@ -21,10 +21,10 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.internal; +package org.hibernate.boot.archive.scan.internal; -import org.hibernate.jpa.boot.spi.InputStreamAccess; -import org.hibernate.jpa.boot.spi.MappingFileDescriptor; +import org.hibernate.boot.archive.spi.InputStreamAccess; +import org.hibernate.boot.archive.scan.spi.MappingFileDescriptor; /** * @author Steve Ebersole diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/PackageDescriptorImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/PackageDescriptorImpl.java similarity index 91% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/PackageDescriptorImpl.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/PackageDescriptorImpl.java index c40eb48786..7160dd7969 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/PackageDescriptorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/PackageDescriptorImpl.java @@ -21,10 +21,10 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.internal; +package org.hibernate.boot.archive.scan.internal; -import org.hibernate.jpa.boot.spi.InputStreamAccess; -import org.hibernate.jpa.boot.spi.PackageDescriptor; +import org.hibernate.boot.archive.spi.InputStreamAccess; +import org.hibernate.boot.archive.scan.spi.PackageDescriptor; /** * @author Steve Ebersole diff --git a/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/ScanResultCollector.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/ScanResultCollector.java new file mode 100644 index 0000000000..733be9f054 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/ScanResultCollector.java @@ -0,0 +1,171 @@ +/* + * 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.boot.archive.scan.internal; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.hibernate.boot.archive.scan.spi.ClassDescriptor; +import org.hibernate.boot.archive.scan.spi.MappingFileDescriptor; +import org.hibernate.boot.archive.scan.spi.PackageDescriptor; +import org.hibernate.boot.archive.scan.spi.ScanEnvironment; +import org.hibernate.boot.archive.scan.spi.ScanOptions; +import org.hibernate.boot.archive.scan.spi.ScanParameters; +import org.hibernate.boot.archive.scan.spi.ScanResult; + +import org.jboss.jandex.ClassInfo; +import org.jboss.logging.Logger; + +/** + * @author Steve Ebersole + */ +public class ScanResultCollector { + private static final Logger log = Logger.getLogger( ScanResultCollector.class ); + + private final ScanEnvironment environment; + private final ScanOptions options; + + private final ScanParameters scanParameters; + + private final Set discoveredClasses; + private final Set discoveredPackages; + private final Set discoveredMappingFiles; + + public ScanResultCollector(ScanEnvironment environment, ScanOptions options, ScanParameters parameters) { + this.environment = environment; + this.options = options; + + this.scanParameters = parameters; + + if ( environment.getExplicitlyListedClassNames() == null ) { + throw new IllegalArgumentException( "ScanEnvironment#getExplicitlyListedClassNames should not return null" ); + } + + if ( environment.getExplicitlyListedMappingFiles() == null ) { + throw new IllegalArgumentException( "ScanEnvironment#getExplicitlyListedMappingFiles should not return null" ); + } + + this.discoveredPackages = new HashSet(); + this.discoveredClasses = new HashSet(); + this.discoveredMappingFiles = new HashSet(); + } + + public void handleClass(ClassDescriptor classDescriptor, boolean rootUrl) { + // see if "discovery" of this entry is allowed + +// final ClassInfo classInfo = scanParameters.getJandexInitializer().handle( classDescriptor ); +// +// if ( !isListedOrDetectable( classInfo.name().toString(), rootUrl ) ) { +// return; +// } +// +// if ( !containsClassAnnotationsOfInterest( classInfo ) ) { +// // not strictly needed, but helps cut down on the size of discoveredClasses +// return; +// } + + if ( !isListedOrDetectable( classDescriptor.getName(), rootUrl ) ) { + return; + } + + discoveredClasses.add( classDescriptor ); + } + + @SuppressWarnings("SimplifiableIfStatement") + protected boolean isListedOrDetectable(String name, boolean rootUrl) { + // IMPL NOTE : protect the calls to getExplicitlyListedClassNames unless needed, + // since it can take time with lots of listed classes. + if ( rootUrl ) { + // The entry comes from the root url. Allow it if either: + // 1) we are allowed to discover classes/packages in the root url + // 2) the entry was explicitly listed + return options.canDetectUnlistedClassesInRoot() + || environment.getExplicitlyListedClassNames().contains( name ); + } + else { + // The entry comes from a non-root url. Allow it if either: + // 1) we are allowed to discover classes/packages in non-root urls + // 2) the entry was explicitly listed + return options.canDetectUnlistedClassesInNonRoot() + || environment.getExplicitlyListedClassNames().contains( name ); + } + } + +// @SuppressWarnings("SimplifiableIfStatement") +// private boolean containsClassAnnotationsOfInterest(ClassInfo classInfo) { +// if ( classInfo.annotations() == null ) { +// return false; +// } +// +// return classInfo.annotations().containsKey( JPADotNames.ENTITY ) +// || classInfo.annotations().containsKey( JPADotNames.MAPPED_SUPERCLASS ) +// || classInfo.annotations().containsKey( JPADotNames.EMBEDDABLE ) +// || classInfo.annotations().containsKey( JPADotNames.CONVERTER ); +// } + + public void handlePackage(PackageDescriptor packageDescriptor, boolean rootUrl) { +// final ClassInfo classInfo = scanParameters.getJandexInitializer().handle( packageDescriptor ); + + if ( !isListedOrDetectable( packageDescriptor.getName(), rootUrl ) ) { + // not strictly needed, but helps cut down on the size of discoveredPackages + return; + } + + discoveredPackages.add( packageDescriptor ); + } + + public void handleMappingFile(MappingFileDescriptor mappingFileDescriptor, boolean rootUrl) { + if ( acceptAsMappingFile( mappingFileDescriptor, rootUrl ) ) { + discoveredMappingFiles.add( mappingFileDescriptor ); + } + } + + @SuppressWarnings("SimplifiableIfStatement") + private boolean acceptAsMappingFile(MappingFileDescriptor mappingFileDescriptor, boolean rootUrl) { + if ( mappingFileDescriptor.getName().endsWith( "hbm.xml" ) ) { + return options.canDetectHibernateMappingFiles(); + } + + if ( mappingFileDescriptor.getName().endsWith( "META-INF/orm.xml" ) ) { + if ( environment.getExplicitlyListedMappingFiles().contains( "META-INF/orm.xml" ) ) { + // if the user explicitly listed META-INF/orm.xml, only except the root one + // + // not sure why exactly, but this is what the old code does + return rootUrl; + } + return true; + } + + return environment.getExplicitlyListedMappingFiles().contains( mappingFileDescriptor.getName() ); + } + + public ScanResult toScanResult() { + return new ScanResultImpl( + Collections.unmodifiableSet( discoveredPackages ), + Collections.unmodifiableSet( discoveredClasses ), + Collections.unmodifiableSet( discoveredMappingFiles ) + ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/ScanResultImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/ScanResultImpl.java new file mode 100644 index 0000000000..0aec037451 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/ScanResultImpl.java @@ -0,0 +1,65 @@ +/* + * 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.boot.archive.scan.internal; + +import java.util.Set; + +import org.hibernate.boot.archive.scan.spi.ClassDescriptor; +import org.hibernate.boot.archive.scan.spi.MappingFileDescriptor; +import org.hibernate.boot.archive.scan.spi.PackageDescriptor; +import org.hibernate.boot.archive.scan.spi.ScanResult; + + +/** +* @author Steve Ebersole +*/ +public class ScanResultImpl implements ScanResult { + private final Set packageDescriptorSet; + private final Set classDescriptorSet; + private final Set mappingFileSet; + + public ScanResultImpl( + Set packageDescriptorSet, + Set classDescriptorSet, + Set mappingFileSet) { + this.packageDescriptorSet = packageDescriptorSet; + this.classDescriptorSet = classDescriptorSet; + this.mappingFileSet = mappingFileSet; + } + + @Override + public Set getLocatedPackages() { + return packageDescriptorSet; + } + + @Override + public Set getLocatedClasses() { + return classDescriptorSet; + } + + @Override + public Set getLocatedMappingFiles() { + return mappingFileSet; + } +} diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/internal/StandardScanOptions.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/StandardScanOptions.java similarity index 95% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/internal/StandardScanOptions.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/StandardScanOptions.java index e2dcf9e154..0ad3c8be6f 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/internal/StandardScanOptions.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/StandardScanOptions.java @@ -21,9 +21,9 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.scan.internal; +package org.hibernate.boot.archive.scan.internal; -import org.hibernate.jpa.boot.scan.spi.ScanOptions; +import org.hibernate.boot.archive.scan.spi.ScanOptions; /** * @author Steve Ebersole diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/internal/StandardScanner.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/StandardScanner.java similarity index 77% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/internal/StandardScanner.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/StandardScanner.java index 6db4050a0e..b91fb77ee9 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/internal/StandardScanner.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/StandardScanner.java @@ -21,10 +21,11 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.scan.internal; +package org.hibernate.boot.archive.scan.internal; -import org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory; -import org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl; +import org.hibernate.boot.archive.internal.StandardArchiveDescriptorFactory; +import org.hibernate.boot.archive.scan.spi.AbstractScannerImpl; +import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory; /** * Standard implementation of the Scanner contract, supporting typical archive walking support where @@ -35,6 +36,10 @@ import org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl; */ public class StandardScanner extends AbstractScannerImpl { public StandardScanner() { - super( StandardArchiveDescriptorFactory.INSTANCE ); + this( StandardArchiveDescriptorFactory.INSTANCE ); + } + + public StandardScanner(ArchiveDescriptorFactory value) { + super( value ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/AbstractScannerImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/AbstractScannerImpl.java new file mode 100644 index 0000000000..c644bde6fe --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/AbstractScannerImpl.java @@ -0,0 +1,142 @@ +/* + * 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.boot.archive.scan.spi; + +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import org.hibernate.boot.archive.scan.internal.ScanResultCollector; +import org.hibernate.boot.archive.spi.ArchiveContext; +import org.hibernate.boot.archive.spi.ArchiveDescriptor; +import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory; +import org.hibernate.boot.archive.spi.ArchiveEntry; +import org.hibernate.boot.archive.spi.ArchiveEntryHandler; + +/** + * @author Steve Ebersole + */ +public abstract class AbstractScannerImpl implements Scanner { + private final ArchiveDescriptorFactory archiveDescriptorFactory; + private final Map archiveDescriptorCache = new HashMap(); + + protected AbstractScannerImpl(ArchiveDescriptorFactory archiveDescriptorFactory) { + this.archiveDescriptorFactory = archiveDescriptorFactory; + } + + @Override + public ScanResult scan(ScanEnvironment environment, ScanOptions options, ScanParameters parameters) { + final ScanResultCollector collector = new ScanResultCollector( environment, options, parameters ); + + if ( environment.getNonRootUrls() != null ) { + final ArchiveContext context = new ArchiveContextImpl( false, collector ); + for ( URL url : environment.getNonRootUrls() ) { + final ArchiveDescriptor descriptor = buildArchiveDescriptor( url, false ); + descriptor.visitArchive( context ); + } + } + + if ( environment.getRootUrl() != null ) { + final ArchiveContext context = new ArchiveContextImpl( true, collector ); + final ArchiveDescriptor descriptor = buildArchiveDescriptor( environment.getRootUrl(), true ); + descriptor.visitArchive( context ); + } + + return collector.toScanResult(); + } + + + private ArchiveDescriptor buildArchiveDescriptor(URL url, boolean isRootUrl) { + final ArchiveDescriptor descriptor; + final ArchiveDescriptorInfo descriptorInfo = archiveDescriptorCache.get( url ); + if ( descriptorInfo == null ) { + descriptor = archiveDescriptorFactory.buildArchiveDescriptor( url ); + archiveDescriptorCache.put( + url, + new ArchiveDescriptorInfo( descriptor, isRootUrl ) + ); + } + else { + validateReuse( descriptorInfo, isRootUrl ); + descriptor = descriptorInfo.archiveDescriptor; + } + return descriptor; + } + + // This needs to be protected and attributes/constructor visible in case + // a custom scanner needs to override validateReuse. + protected static class ArchiveDescriptorInfo { + public final ArchiveDescriptor archiveDescriptor; + public final boolean isRoot; + + public ArchiveDescriptorInfo(ArchiveDescriptor archiveDescriptor, boolean isRoot) { + this.archiveDescriptor = archiveDescriptor; + this.isRoot = isRoot; + } + } + + @SuppressWarnings("UnusedParameters") + protected void validateReuse(ArchiveDescriptorInfo descriptor, boolean root) { + // is it really reasonable that a single url be processed multiple times? + // for now, throw an exception, mainly because I am interested in situations where this might happen + 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; + } + } + } +} diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/ClassDescriptor.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ClassDescriptor.java similarity index 76% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/ClassDescriptor.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ClassDescriptor.java index c04e57d9c0..1d44638acf 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/ClassDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ClassDescriptor.java @@ -21,14 +21,27 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.spi; +package org.hibernate.boot.archive.scan.spi; + +import org.hibernate.boot.archive.spi.InputStreamAccess; /** - * Defines the result of scanning a persistence unit for classes. + * 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(); } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/ClassFileArchiveEntryHandler.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ClassFileArchiveEntryHandler.java similarity index 70% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/ClassFileArchiveEntryHandler.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ClassFileArchiveEntryHandler.java index 6df5baa5d8..cdcb2b18d2 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/ClassFileArchiveEntryHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ClassFileArchiveEntryHandler.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.scan.spi; +package org.hibernate.boot.archive.scan.spi; import java.io.DataInputStream; import java.io.IOException; @@ -34,30 +34,23 @@ import javax.persistence.MappedSuperclass; import javassist.bytecode.AnnotationsAttribute; 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.ArchiveException; -import org.hibernate.jpa.boot.internal.ClassDescriptorImpl; -import org.hibernate.jpa.boot.spi.ClassDescriptor; +import org.hibernate.boot.archive.scan.internal.ClassDescriptorImpl; +import org.hibernate.boot.archive.scan.internal.ScanResultCollector; +import org.hibernate.boot.archive.spi.ArchiveContext; +import org.hibernate.boot.archive.spi.ArchiveEntry; +import org.hibernate.boot.archive.spi.ArchiveEntryHandler; +import org.hibernate.boot.archive.spi.ArchiveException; /** * Defines handling and filtering for class file entries within an archive * * @author Steve Ebersole */ -public class ClassFileArchiveEntryHandler extends AbstractJavaArtifactArchiveEntryHandler { - private final Callback callback; +public class ClassFileArchiveEntryHandler implements ArchiveEntryHandler { + private final ScanResultCollector resultCollector; - /** - * Contract for the thing interested in being notified about accepted class descriptors. - */ - public static interface Callback { - public void locatedClass(ClassDescriptor classDescriptor); - } - - public ClassFileArchiveEntryHandler(ScanOptions scanOptions, Callback callback) { - super( scanOptions ); - this.callback = callback; + public ClassFileArchiveEntryHandler(ScanResultCollector resultCollector) { + this.resultCollector = resultCollector; } @Override @@ -65,17 +58,14 @@ public class ClassFileArchiveEntryHandler extends AbstractJavaArtifactArchiveEnt final ClassFile classFile = toClassFile( entry ); final ClassDescriptor classDescriptor = toClassDescriptor( classFile, entry ); - if ( ! isListedOrDetectable( context, classDescriptor.getName() ) ) { - return; - } - - // we are only interested in classes with certain annotations, so see if the ClassDescriptor - // represents a class which contains any of those annotations + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // temporary until HHH-9489 is addressed if ( ! containsClassAnnotationsOfInterest( classFile ) ) { return; } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - notifyMatchedClass( classDescriptor ); + resultCollector.handleClass( toClassDescriptor( toClassFile( entry ), entry ), context.isRootUrl() ); } private ClassFile toClassFile(ArchiveEntry entry) { @@ -102,6 +92,7 @@ public class ClassFileArchiveEntryHandler extends AbstractJavaArtifactArchiveEnt } } + @SuppressWarnings("SimplifiableIfStatement") private boolean containsClassAnnotationsOfInterest(ClassFile cf) { final AnnotationsAttribute visibleAnnotations = (AnnotationsAttribute) cf.getAttribute( AnnotationsAttribute.visibleTag ); @@ -115,11 +106,7 @@ public class ClassFileArchiveEntryHandler extends AbstractJavaArtifactArchiveEnt || visibleAnnotations.getAnnotation( Converter.class.getName() ) != null; } - protected ClassDescriptor toClassDescriptor(ClassFile classFile, ArchiveEntry entry) { + private ClassDescriptor toClassDescriptor(ClassFile classFile, ArchiveEntry entry) { return new ClassDescriptorImpl( classFile.getName(), entry.getStreamAccess() ); } - - protected final void notifyMatchedClass(ClassDescriptor classDescriptor) { - callback.locatedClass( classDescriptor ); - } } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/ScanOptions.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/JandexInitializer.java similarity index 70% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/ScanOptions.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/JandexInitializer.java index a5ec564a8d..24cc04b542 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/ScanOptions.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/JandexInitializer.java @@ -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,19 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.scan.spi; +package org.hibernate.boot.archive.scan.spi; + +import org.jboss.jandex.ClassInfo; /** + * Helper for preparing Jandex for later use.. + * + * Not currently used. See https://hibernate.atlassian.net/browse/HHH-9489 + * * @author Steve Ebersole */ -public interface ScanOptions { - public boolean canDetectUnlistedClassesInRoot(); - public boolean canDetectUnlistedClassesInNonRoot(); +public interface JandexInitializer { + ClassInfo handle(PackageDescriptor packageDescriptor); - public boolean canDetectHibernateMappingFiles(); + ClassInfo handle(ClassDescriptor classDescriptor); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/MappingFileDescriptor.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/MappingFileDescriptor.java new file mode 100644 index 0000000000..253b4dcc41 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/MappingFileDescriptor.java @@ -0,0 +1,49 @@ +/* + * 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.boot.archive.scan.spi; + +import org.hibernate.boot.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(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/NonClassFileArchiveEntryHandler.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/NonClassFileArchiveEntryHandler.java new file mode 100644 index 0000000000..b6d36b5176 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/NonClassFileArchiveEntryHandler.java @@ -0,0 +1,51 @@ +/* + * 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.boot.archive.scan.spi; + +import org.hibernate.boot.archive.scan.internal.MappingFileDescriptorImpl; +import org.hibernate.boot.archive.scan.internal.ScanResultCollector; +import org.hibernate.boot.archive.spi.ArchiveContext; +import org.hibernate.boot.archive.spi.ArchiveEntry; +import org.hibernate.boot.archive.spi.ArchiveEntryHandler; + +/** + * Defines handling and filtering for all non-class file (package-info is also a class file...) entries within an archive + * + * @author Steve Ebersole + */ +public class NonClassFileArchiveEntryHandler implements ArchiveEntryHandler { + private final ScanResultCollector resultCollector; + + public NonClassFileArchiveEntryHandler(ScanResultCollector resultCollector) { + this.resultCollector = resultCollector; + } + + @Override + public void handleEntry(ArchiveEntry entry, ArchiveContext context) { + resultCollector.handleMappingFile( + new MappingFileDescriptorImpl( entry.getNameWithinArchive(), entry.getStreamAccess() ), + context.isRootUrl() + ); + } +} diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/MappingFileDescriptor.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/PackageDescriptor.java similarity index 71% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/MappingFileDescriptor.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/PackageDescriptor.java index 5dfec7b9cb..f2c8536fe2 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/MappingFileDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/PackageDescriptor.java @@ -21,12 +21,27 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.spi; +package org.hibernate.boot.archive.scan.spi; + +import org.hibernate.boot.archive.spi.InputStreamAccess; /** + * Descriptor for a package (as indicated by a package-info.class file). + * * @author Steve Ebersole */ -public interface MappingFileDescriptor { +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(); } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/PackageInfoArchiveEntryHandler.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/PackageInfoArchiveEntryHandler.java similarity index 61% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/PackageInfoArchiveEntryHandler.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/PackageInfoArchiveEntryHandler.java index 1306be3e74..6f844bc358 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/PackageInfoArchiveEntryHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/PackageInfoArchiveEntryHandler.java @@ -21,31 +21,24 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.scan.spi; +package org.hibernate.boot.archive.scan.spi; -import org.hibernate.jpa.boot.archive.spi.ArchiveContext; -import org.hibernate.jpa.boot.archive.spi.ArchiveEntry; -import org.hibernate.jpa.boot.internal.PackageDescriptorImpl; -import org.hibernate.jpa.boot.spi.PackageDescriptor; +import org.hibernate.boot.archive.scan.internal.PackageDescriptorImpl; +import org.hibernate.boot.archive.scan.internal.ScanResultCollector; +import org.hibernate.boot.archive.spi.ArchiveContext; +import org.hibernate.boot.archive.spi.ArchiveEntry; +import org.hibernate.boot.archive.spi.ArchiveEntryHandler; /** * Defines handling and filtering for package-info file entries within an archive * * @author Steve Ebersole */ -public class PackageInfoArchiveEntryHandler extends AbstractJavaArtifactArchiveEntryHandler { - private final Callback callback; +public class PackageInfoArchiveEntryHandler implements ArchiveEntryHandler { + private final ScanResultCollector resultCollector; - /** - * Contract for the thing interested in being notified about accepted package-info descriptors. - */ - public static interface Callback { - public void locatedPackage(PackageDescriptor packageDescriptor); - } - - public PackageInfoArchiveEntryHandler(ScanOptions scanOptions, Callback callback) { - super( scanOptions ); - this.callback = callback; + public PackageInfoArchiveEntryHandler(ScanResultCollector resultCollector) { + this.resultCollector = resultCollector; } @Override @@ -55,12 +48,7 @@ public class PackageInfoArchiveEntryHandler extends AbstractJavaArtifactArchiveE return; } - if ( ! isListedOrDetectable( context, entry.getName() ) ) { - // the package is not explicitly listed, and we are not allowed to detect it. - return; - } - - notifyMatchedPackage( toPackageDescriptor( entry ) ); + resultCollector.handlePackage( toPackageDescriptor( entry ), context.isRootUrl() ); } protected PackageDescriptor toPackageDescriptor(ArchiveEntry entry) { @@ -70,8 +58,4 @@ public class PackageInfoArchiveEntryHandler extends AbstractJavaArtifactArchiveE return new PackageDescriptorImpl( packageName, entry.getStreamAccess() ); } - - protected final void notifyMatchedPackage(PackageDescriptor packageDescriptor) { - callback.locatedPackage( packageDescriptor ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ScanEnvironment.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ScanEnvironment.java new file mode 100644 index 0000000000..5f052bef0d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ScanEnvironment.java @@ -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.boot.archive.scan.spi; + +import java.net.URL; +import java.util.List; + +/** + * Describes the environment in which the scan will occur. + *

+ * 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). + *

+ * 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 getNonRootUrls(); + + /** + * Returns any classes which are explicitly listed as part of the + * "persistence unit". + * + * @return The explicitly listed classes + */ + public List getExplicitlyListedClassNames(); + + /** + * Returns the mapping files which are explicitly listed as part of the + * "persistence unit". + * + * @return The explicitly listed mapping files. + */ + public List getExplicitlyListedMappingFiles(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ScanOptions.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ScanOptions.java new file mode 100644 index 0000000000..2c13a98a1f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ScanOptions.java @@ -0,0 +1,59 @@ +/* + * 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.boot.archive.scan.spi; + +/** + * Options for performing scanning + * + * @author Steve Ebersole + */ +public interface ScanOptions { + /** + * Is detection of managed classes from root url allowed? In strict JPA + * sense, this would be controlled by the {@code } + * element. + * + * @return Whether detection of classes from root url is allowed + */ + public boolean canDetectUnlistedClassesInRoot(); + + /** + * Is detection of managed classes from non-root urls allowed? In strict JPA + * sense, this would always be allowed. + * + * @return Whether detection of classes from non-root urls is allowed + */ + public boolean canDetectUnlistedClassesInNonRoot(); + + /** + * Is detection of Hibernate Mapping files allowed? + * + * @return Whether detection of Mapping files is allowed. + * + * @deprecated With move to unified schema, this setting is now deprecated and will + * be removed once support for reading {@code hbm.xml} files is fully removed. + */ + @Deprecated + public boolean canDetectHibernateMappingFiles(); +} diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/PackageDescriptor.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ScanParameters.java similarity index 74% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/PackageDescriptor.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ScanParameters.java index 101e516575..aefa94f326 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/PackageDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ScanParameters.java @@ -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.boot.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(); } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/ScanResult.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ScanResult.java similarity index 74% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/ScanResult.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ScanResult.java index 13e0fa02f9..9484c30eed 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/ScanResult.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/ScanResult.java @@ -21,21 +21,34 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.scan.spi; +package org.hibernate.boot.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 getLocatedPackages(); + + /** + * Returns descriptors for all classes discovered as part of the scan + * + * @return Descriptors for discovered classes + */ public Set getLocatedClasses(); + + /** + * Returns descriptors for all mapping files discovered as part of the scan + * + * @return Descriptors for discovered mapping files + */ public Set getLocatedMappingFiles(); } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/Scanner.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/Scanner.java similarity index 62% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/Scanner.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/Scanner.java index d57b54cb76..a1faad1681 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/Scanner.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/spi/Scanner.java @@ -21,26 +21,31 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.scan.spi; - -import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor; +package org.hibernate.boot.archive.scan.spi; /** * Defines the contract for Hibernate to be able to scan for classes, packages and resources inside a * persistence unit. + *

+ * Constructors are expected in one of 2 forms:

    + *
  • no-arg
  • + *
  • single arg, of type {@link org.hibernate.boot.archive.spi.ArchiveDescriptorFactory}
  • + *
+ *

+ * 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 */ public interface Scanner { /** - * Perform the scanning against the described persistence unit using the defined options, and return the scan - * results. + * Perform the scanning against the described environment using the + * defined options, and return the scan results. * - * @param persistenceUnit THe description of the persistence unit. - * @param options The scan options - * - * @return The scan results. + * @param environment The scan environment. + * @param options The options to control the scanning. + * @param params The parameters for scanning */ - public ScanResult scan(PersistenceUnitDescriptor persistenceUnit, ScanOptions options); + public ScanResult scan(ScanEnvironment environment, ScanOptions options, ScanParameters params); } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/AbstractArchiveDescriptor.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/AbstractArchiveDescriptor.java similarity index 91% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/AbstractArchiveDescriptor.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/spi/AbstractArchiveDescriptor.java index 1870ebd05a..5f9882cb7c 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/AbstractArchiveDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/AbstractArchiveDescriptor.java @@ -21,16 +21,15 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.archive.spi; +package org.hibernate.boot.archive.spi; import java.io.InputStream; import java.net.URL; import java.util.zip.ZipEntry; +import org.hibernate.boot.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.boot.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) { diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/NamedInputStream.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/AbstractArchiveDescriptorFactory.java similarity index 60% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/NamedInputStream.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/spi/AbstractArchiveDescriptorFactory.java index fd6abed28f..ab57d12086 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/NamedInputStream.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/AbstractArchiveDescriptorFactory.java @@ -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,28 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.spi; +package org.hibernate.boot.archive.spi; -import java.io.InputStream; +import java.net.URL; + +import org.hibernate.boot.archive.internal.ArchiveHelper; /** - * 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 { - private final String name; - private final InputStream stream; - - public NamedInputStream(String name, InputStream stream) { - this.name = name; - this.stream = stream; +public abstract class AbstractArchiveDescriptorFactory implements ArchiveDescriptorFactory { + @Override + public ArchiveDescriptor buildArchiveDescriptor(URL url) { + return buildArchiveDescriptor( url, "" ); } - public InputStream getStream() { - return stream; + @Override + public URL getJarURLFromURLEntry(URL url, String entry) throws IllegalArgumentException { + return ArchiveHelper.getJarURLFromURLEntry( url, entry ); } - public String getName() { - return name; + @Override + public URL getURLFromPath(String jarPath) { + return ArchiveHelper.getURLFromPath( jarPath ); } } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveContext.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveContext.java similarity index 83% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveContext.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveContext.java index eeea27eca4..13b7f02a85 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveContext.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveContext.java @@ -21,23 +21,14 @@ * 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.boot.archive.spi; /** * Describes the context for visiting the entries within an archive * -* @author Steve Ebersole -*/ + * @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? * diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveDescriptor.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveDescriptor.java similarity index 96% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveDescriptor.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveDescriptor.java index 8cd12792b2..6bd2456bdd 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveDescriptor.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.archive.spi; +package org.hibernate.boot.archive.spi; /** * Contract for visiting an archive, which might be a jar, a zip, an exploded directory, etc. diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveDescriptorFactory.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveDescriptorFactory.java similarity index 98% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveDescriptorFactory.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveDescriptorFactory.java index 937a34d546..e094245b37 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveDescriptorFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveDescriptorFactory.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.archive.spi; +package org.hibernate.boot.archive.spi; import java.net.URL; diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveEntry.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveEntry.java similarity index 94% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveEntry.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveEntry.java index eeaaf85f79..97eea0936f 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveEntry.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveEntry.java @@ -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.boot.archive.spi; /** * Represent an entry in the archive. diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveEntryHandler.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveEntryHandler.java similarity index 96% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveEntryHandler.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveEntryHandler.java index 3110b78c87..e8d28103c1 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveEntryHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveEntryHandler.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.archive.spi; +package org.hibernate.boot.archive.spi; /** * Handler for archive entries, based on the classified type of the entry diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveException.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveException.java similarity index 97% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveException.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveException.java index 204ac79b00..9a445c4db5 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveException.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/ArchiveException.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.archive.spi; +package org.hibernate.boot.archive.spi; import org.hibernate.HibernateException; diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/InputStreamAccess.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/InputStreamAccess.java similarity index 90% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/InputStreamAccess.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/spi/InputStreamAccess.java index cb51b1ada5..8c23de5fbc 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/InputStreamAccess.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/InputStreamAccess.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.jpa.boot.spi; +package org.hibernate.boot.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(); } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/package-info.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/package-info.java similarity index 90% rename from hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/package-info.java rename to hibernate-core/src/main/java/org/hibernate/boot/archive/spi/package-info.java index 0f7106647d..8f2a0165aa 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/package-info.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/spi/package-info.java @@ -12,4 +12,4 @@ *

  • etc
  • * */ -package org.hibernate.jpa.boot.archive.spi; +package org.hibernate.boot.archive.spi; diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java index 00813f5544..1e3d570936 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java @@ -724,4 +724,46 @@ public interface AvailableSettings { String AUTO_SESSION_EVENTS_LISTENER = "hibernate.session.events.auto"; + + /** + * The deprecated name. Use {@link #SCANNER} or {@link #SCANNER_ARCHIVE_INTERPRETER} instead. + */ + String SCANNER_DEPRECATED = "hibernate.ejb.resource_scanner"; + + /** + * Pass an implementation of {@link org.hibernate.boot.archive.scan.spi.Scanner}. + * Accepts either:
      + *
    • an actual instance
    • + *
    • a reference to a Class that implements Scanner
    • + *
    • a fully qualified name (String) of a Class that implements Scanner
    • + *
    + */ + String SCANNER = "hibernate.archive.scanner"; + + /** + * Pass {@link org.hibernate.boot.archive.spi.ArchiveDescriptorFactory} to use + * in the scanning process. Accepts either:
      + *
    • an ArchiveDescriptorFactory instance
    • + *
    • a reference to a Class that implements ArchiveDescriptorFactory
    • + *
    • a fully qualified name (String) of a Class that implements ArchiveDescriptorFactory
    • + *
    + *

    + * See information on {@link org.hibernate.boot.archive.scan.spi.Scanner} + * about expected constructor forms. + * + * @see #SCANNER + * @see org.hibernate.boot.archive.scan.spi.Scanner + * @see org.hibernate.boot.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:

      + *
    • "class" - discover classes - .class files are discovered as managed classes
    • + *
    • "hbm" - discover hbm mapping files - hbm.xml files are discovered as mapping files
    • + *
    + */ + String SCANNER_DISCOVERY = "hibernate.archive.autodetection"; + } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/log/DeprecationLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/log/DeprecationLogger.java new file mode 100644 index 0000000000..048602cc80 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/internal/log/DeprecationLogger.java @@ -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.log; + +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 logDeprecatedScannerSetting(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/log/UrlMessageBundle.java b/hibernate-core/src/main/java/org/hibernate/internal/log/UrlMessageBundle.java new file mode 100644 index 0000000000..f5397892ae --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/internal/log/UrlMessageBundle.java @@ -0,0 +1,110 @@ +/* + * 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.log; + +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.MessageLogger; +import org.jboss.logging.annotations.ValidIdRange; + +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" ) +@ValidIdRange( min = 10000001, max = 10001000 ) +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 java.net.URISyntaxException} + * + * @param jarUrl The URL that lead to the {@link java.net.URISyntaxException} + * @param e The underlying URISyntaxException + */ + @LogMessage( level = WARN ) + @Message( value = "Malformed URL: %s", id = 10000001 ) + 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 = 10000002 ) + 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 = 10000003 ) + 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 = 10000004 ) + void logFileIsNotDirectory(URL url); + + /** + * Access to the exception message used when a URL references names a file that does not exist. + *

    + * 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 = 10000005 ) + String fileDoesNotExist(String filePart, URL url); +} diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/packaging/NamedInputStream.java b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/packaging/NamedInputStream.java deleted file mode 100644 index 733455bf7e..0000000000 --- a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/packaging/NamedInputStream.java +++ /dev/null @@ -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 ); - } -} diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/packaging/Scanner.java b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/packaging/Scanner.java index a452e66495..2893d7c0c6 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/packaging/Scanner.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/packaging/Scanner.java @@ -24,8 +24,8 @@ package org.hibernate.ejb.packaging; /** - * @deprecated Use {@link org.hibernate.jpa.boot.scan.spi.Scanner} instead + * @deprecated Use {@link org.hibernate.boot.archive.scan.spi.Scanner} instead */ @Deprecated -public interface Scanner extends org.hibernate.jpa.boot.scan.spi.Scanner { +public interface Scanner extends org.hibernate.boot.archive.scan.spi.Scanner { } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/AvailableSettings.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/AvailableSettings.java index 697c4a2f7e..e7797fd130 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/AvailableSettings.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/AvailableSettings.java @@ -371,8 +371,11 @@ public interface AvailableSettings { /** * JAR autodetection artifacts class, hbm + * + * @deprecated Use {@link org.hibernate.cfg.AvailableSettings#SCANNER_DISCOVERY} instead */ - String AUTODETECTION = "hibernate.archive.autodetection"; + @Deprecated + String AUTODETECTION = org.hibernate.cfg.AvailableSettings.SCANNER_DISCOVERY; /** * cfg.xml configuration file used @@ -459,11 +462,11 @@ public interface AvailableSettings { String FLUSH_MODE = "org.hibernate.flushMode"; /** - * Pass an implementation of {@link org.hibernate.ejb.packaging.Scanner}: - * - preferably an actual instance - * - or a class name with a no-arg constructor + * @deprecated Prefer {@link org.hibernate.cfg.AvailableSettings#SCANNER} instead */ - String SCANNER = "hibernate.ejb.resource_scanner"; + @Deprecated + @SuppressWarnings("UnusedDeclaration") + String SCANNER = org.hibernate.cfg.AvailableSettings.SCANNER_DEPRECATED; /** * List of classes names diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java index 368da0a42a..bf082db427 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java @@ -28,6 +28,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.Serializable; +import java.lang.reflect.Constructor; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; @@ -55,6 +56,14 @@ import org.hibernate.MappingException; import org.hibernate.MappingNotFoundException; import org.hibernate.SessionFactory; import org.hibernate.SessionFactoryObserver; +import org.hibernate.boot.archive.internal.StandardArchiveDescriptorFactory; +import org.hibernate.boot.archive.internal.UrlInputStreamAccess; +import org.hibernate.boot.archive.scan.internal.ClassDescriptorImpl; +import org.hibernate.boot.archive.scan.internal.MappingFileDescriptorImpl; +import org.hibernate.boot.archive.scan.internal.PackageDescriptorImpl; +import org.hibernate.boot.archive.scan.spi.JandexInitializer; +import org.hibernate.boot.archive.scan.spi.ScanParameters; +import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory; import org.hibernate.boot.registry.BootstrapServiceRegistry; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; @@ -76,18 +85,17 @@ import org.hibernate.internal.jaxb.cfg.JaxbHibernateConfiguration; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.ValueHolder; import org.hibernate.jpa.AvailableSettings; -import org.hibernate.jpa.boot.scan.internal.StandardScanOptions; -import org.hibernate.jpa.boot.scan.internal.StandardScanner; -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.boot.archive.scan.internal.StandardScanOptions; +import org.hibernate.boot.archive.scan.internal.StandardScanner; +import org.hibernate.boot.archive.scan.spi.ScanOptions; +import org.hibernate.boot.archive.scan.spi.ScanResult; +import org.hibernate.boot.archive.scan.spi.Scanner; +import org.hibernate.boot.archive.scan.spi.ClassDescriptor; import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder; -import org.hibernate.jpa.boot.spi.InputStreamAccess; +import org.hibernate.boot.archive.spi.InputStreamAccess; import org.hibernate.jpa.boot.spi.IntegratorProvider; -import org.hibernate.jpa.boot.spi.MappingFileDescriptor; -import org.hibernate.jpa.boot.spi.NamedInputStream; -import org.hibernate.jpa.boot.spi.PackageDescriptor; +import org.hibernate.boot.archive.scan.spi.MappingFileDescriptor; +import org.hibernate.boot.archive.scan.spi.PackageDescriptor; import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor; import org.hibernate.jpa.boot.spi.StrategyRegistrationProviderList; import org.hibernate.jpa.boot.spi.TypeContributorList; @@ -115,6 +123,8 @@ import org.jboss.jandex.IndexView; import org.jboss.jandex.Indexer; import org.jboss.logging.Logger; +import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER; + /** * @author Steve Ebersole */ @@ -410,7 +420,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } for ( MappingFileDescriptor mappingFileDescriptor : deploymentResources.getMappingFileDescriptors() ) { - metadataSources.namedMappingFileInputStreams.add( mappingFileDescriptor.getStreamAccess().asNamedInputStream() ); + metadataSources.mappingFileInputStreamAccessList.add( mappingFileDescriptor.getStreamAccess() ); } final String explicitHbmXmls = (String) configurationValues.remove( AvailableSettings.HBXML_FILES ); @@ -749,51 +759,137 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil final Scanner scanner = locateOrBuildScanner( bootstrapServiceRegistry ); final ScanOptions scanOptions = determineScanOptions(); - return scanner.scan( persistenceUnit, scanOptions ); + return scanner.scan( + new StandardJpaScanEnvironmentImpl( persistenceUnit ), + scanOptions, + new ScanParameters() { + @Override + public JandexInitializer getJandexInitializer() { + return null; + } + } + ); } private ScanOptions determineScanOptions() { return new StandardScanOptions( - (String) configurationValues.get( AvailableSettings.AUTODETECTION ), + (String) configurationValues.get( org.hibernate.cfg.AvailableSettings.SCANNER_DISCOVERY ), persistenceUnit.isExcludeUnlistedClasses() ); } @SuppressWarnings("unchecked") private Scanner locateOrBuildScanner(BootstrapServiceRegistry bootstrapServiceRegistry) { - final Object value = configurationValues.remove( AvailableSettings.SCANNER ); - if ( value == null ) { - return new StandardScanner(); - } - - if ( Scanner.class.isInstance( value ) ) { - return (Scanner) value; - } - - Class scannerClass; - if ( Class.class.isInstance( value ) ) { - try { - scannerClass = (Class) value; + Object scannerSetting = configurationValues.remove( org.hibernate.cfg.AvailableSettings.SCANNER ); + if ( scannerSetting == null ) { + scannerSetting = configurationValues.remove( org.hibernate.cfg.AvailableSettings.SCANNER_DEPRECATED ); + if ( scannerSetting != null ) { + DEPRECATION_LOGGER.logDeprecatedScannerSetting(); } - catch ( ClassCastException e ) { - throw persistenceException( "Expecting Scanner implementation, but found " + ((Class) value).getName() ); + } + + final StrategySelector strategySelector = bootstrapServiceRegistry.getService( StrategySelector.class ); + ArchiveDescriptorFactory archiveDescriptorFactory = strategySelector.resolveStrategy( + ArchiveDescriptorFactory.class, + configurationValues.remove( org.hibernate.cfg.AvailableSettings.SCANNER_ARCHIVE_INTERPRETER ) + ); + + if ( scannerSetting == null ) { + // No custom Scanner specified, use the StandardScanner + if ( archiveDescriptorFactory == null ) { + return new StandardScanner(); + } + else { + return new StandardScanner( archiveDescriptorFactory ); } } else { - final String scannerClassName = value.toString(); - try { - scannerClass = bootstrapServiceRegistry.getService( ClassLoaderService.class ).classForName( scannerClassName ); + 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, name a 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; } - 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 ); + final Class scannerImplClass; + if ( Class.class.isInstance( scannerSetting ) ) { + scannerImplClass = (Class) scannerSetting; + } + else { + final String scannerClassName = scannerSetting.toString(); + scannerImplClass = bootstrapServiceRegistry.getService( ClassLoaderService.class ).classForName( + scannerClassName + ); + } + + final Class[] SINGLE_ARG = new Class[] { ArchiveDescriptorFactory.class }; + + if ( archiveDescriptorFactory != null ) { + // find the single-arg constructor - its an error if none exists + try { + final Constructor 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 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 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" + ); + } + } + } } } @@ -1198,16 +1294,17 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil LOG.exceptionHeaderNotFound( getExceptionHeader(), META_INF_ORM_XML ); } } - for ( NamedInputStream namedInputStream : metadataSources.namedMappingFileInputStreams ) { + + for ( InputStreamAccess streamAccess : metadataSources.mappingFileInputStreamAccessList ) { try { //addInputStream has the responsibility to close the stream - cfg.addInputStream( new BufferedInputStream( namedInputStream.getStream() ) ); + cfg.addInputStream( new BufferedInputStream( streamAccess.accessInputStream() ) ); } catch ( InvalidMappingException e ) { // try our best to give the file name - if ( StringHelper.isNotEmpty( namedInputStream.getName() ) ) { + if ( StringHelper.isNotEmpty( streamAccess.getStreamName() ) ) { throw new InvalidMappingException( - "Error while parsing file: " + namedInputStream.getName(), + "Error while parsing file: " + streamAccess.getStreamName(), e.getType(), e.getPath(), e @@ -1219,8 +1316,8 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } catch (MappingException me) { // try our best to give the file name - if ( StringHelper.isNotEmpty( namedInputStream.getName() ) ) { - throw new MappingException("Error while parsing file: " + namedInputStream.getName(), me ); + if ( StringHelper.isNotEmpty( streamAccess.getStreamName() ) ) { + throw new MappingException("Error while parsing file: " + streamAccess.getStreamName(), me ); } else { throw me; @@ -1312,7 +1409,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil public static class MetadataSources { private final List annotatedMappingClassNames = new ArrayList(); private final List converterDescriptors = new ArrayList(); - private final List namedMappingFileInputStreams = new ArrayList(); + private final List mappingFileInputStreamAccessList = new ArrayList(); private final List mappingFileResources = new ArrayList(); private final List packageNames = new ArrayList(); @@ -1324,8 +1421,8 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil return converterDescriptors; } - public List getNamedMappingFileInputStreams() { - return namedMappingFileInputStreams; + public List getMappingFileInputStreamAccessList() { + return mappingFileInputStreamAccessList; } public List getPackageNames() { diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/PersistenceXmlParser.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/PersistenceXmlParser.java index f758785a33..348f2593a7 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/PersistenceXmlParser.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/PersistenceXmlParser.java @@ -47,7 +47,7 @@ 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.boot.archive.internal.ArchiveHelper; import org.hibernate.jpa.internal.EntityManagerMessageLogger; import org.hibernate.jpa.internal.util.ConfigurationHelper; import org.hibernate.internal.util.xml.XsdException; diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/StandardJpaScanEnvironmentImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/StandardJpaScanEnvironmentImpl.java new file mode 100644 index 0000000000..c792d05ee7 --- /dev/null +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/StandardJpaScanEnvironmentImpl.java @@ -0,0 +1,75 @@ +/* + * 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.internal; + +import java.net.URL; +import java.util.Collections; +import java.util.List; + +import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor; +import org.hibernate.boot.archive.scan.spi.ScanEnvironment; + +/** + * Implementation of ScanEnvironment leveraging a JPA deployment descriptor. + * + * @author Steve Ebersole + */ +public class StandardJpaScanEnvironmentImpl implements ScanEnvironment { + private final PersistenceUnitDescriptor persistenceUnitDescriptor; + + private final List explicitlyListedClassNames; + private final List explicitlyListedMappingFiles; + + + public StandardJpaScanEnvironmentImpl(PersistenceUnitDescriptor persistenceUnitDescriptor) { + this.persistenceUnitDescriptor = persistenceUnitDescriptor; + + this.explicitlyListedClassNames = persistenceUnitDescriptor.getManagedClassNames() == null + ? Collections.emptyList() + : persistenceUnitDescriptor.getManagedClassNames(); + this.explicitlyListedMappingFiles = persistenceUnitDescriptor.getMappingFileNames() == null + ? Collections.emptyList() + : persistenceUnitDescriptor.getMappingFileNames(); + } + + @Override + public URL getRootUrl() { + return persistenceUnitDescriptor.getPersistenceUnitRootUrl(); + } + + @Override + public List getNonRootUrls() { + return persistenceUnitDescriptor.getJarFileUrls(); + } + + @Override + public List getExplicitlyListedClassNames() { + return explicitlyListedClassNames; + } + + @Override + public List getExplicitlyListedMappingFiles() { + return explicitlyListedMappingFiles; + } +} diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/AbstractJavaArtifactArchiveEntryHandler.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/AbstractJavaArtifactArchiveEntryHandler.java deleted file mode 100644 index c8547ebf14..0000000000 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/AbstractJavaArtifactArchiveEntryHandler.java +++ /dev/null @@ -1,67 +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.scan.spi; - -import org.hibernate.jpa.boot.archive.spi.ArchiveContext; -import org.hibernate.jpa.boot.archive.spi.ArchiveEntryHandler; - -/** - * Base class for commonality between handling class file entries and handling package-info file entries. - * - * @author Steve Ebersole - */ -public abstract class AbstractJavaArtifactArchiveEntryHandler implements ArchiveEntryHandler { - private final ScanOptions scanOptions; - - protected AbstractJavaArtifactArchiveEntryHandler(ScanOptions scanOptions) { - this.scanOptions = scanOptions; - } - - /** - * Check to see if the incoming name (class/package name) is either:

      - *
    • explicitly listed in a {@code } entry within the {@code }
    • - *
    • whether the scan options indicate that we are allowed to detect this entry
    • - *
    - * - * @param context Information about the archive. Mainly whether it is the root of the PU - * @param name The class/package name - * - * @return {@code true} if the named class/package is either detectable or explicitly listed; {@code false} - * otherwise. - */ - protected boolean isListedOrDetectable(ArchiveContext context, String name) { - // IMPL NOTE : protect the isExplicitlyListed call unless needed, since it can take time in a PU - // with lots of listed classes. The other conditions are simple boolean flag checks. - if ( context.isRootUrl() ) { - return scanOptions.canDetectUnlistedClassesInRoot() || isExplicitlyListed( context, name ); - } - else { - return scanOptions.canDetectUnlistedClassesInNonRoot() || isExplicitlyListed( context, name ); - } - } - - private boolean isExplicitlyListed(ArchiveContext context, String name) { - return context.getPersistenceUnitDescriptor().getManagedClassNames().contains( name ); - } -} diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/AbstractScannerImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/AbstractScannerImpl.java deleted file mode 100644 index 985d453658..0000000000 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/AbstractScannerImpl.java +++ /dev/null @@ -1,304 +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.scan.spi; - -import java.net.URL; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -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.archive.spi.ArchiveEntry; -import org.hibernate.jpa.boot.archive.spi.ArchiveEntryHandler; -import org.hibernate.jpa.boot.internal.ClassDescriptorImpl; -import org.hibernate.jpa.boot.internal.MappingFileDescriptorImpl; -import org.hibernate.jpa.boot.internal.PackageDescriptorImpl; -import org.hibernate.jpa.boot.spi.ClassDescriptor; -import org.hibernate.jpa.boot.spi.MappingFileDescriptor; -import org.hibernate.jpa.boot.spi.PackageDescriptor; -import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor; - -/** - * @author Steve Ebersole - */ -public abstract class AbstractScannerImpl implements Scanner { - private final ArchiveDescriptorFactory archiveDescriptorFactory; - private final Map archiveDescriptorCache = new HashMap(); - - protected AbstractScannerImpl(ArchiveDescriptorFactory archiveDescriptorFactory) { - this.archiveDescriptorFactory = archiveDescriptorFactory; - } - - @Override - public ScanResult scan(PersistenceUnitDescriptor persistenceUnit, ScanOptions scanOptions) { - final ResultCollector resultCollector = new ResultCollector( scanOptions ); - - if ( persistenceUnit.getJarFileUrls() != null ) { - for ( URL url : persistenceUnit.getJarFileUrls() ) { - final ArchiveDescriptor descriptor = buildArchiveDescriptor( url, false, scanOptions ); - final ArchiveContext context = buildArchiveContext( persistenceUnit, false, resultCollector ); - descriptor.visitArchive( context ); - } - } - - if ( persistenceUnit.getPersistenceUnitRootUrl() != null ) { - final ArchiveDescriptor descriptor = buildArchiveDescriptor( persistenceUnit.getPersistenceUnitRootUrl(), true, scanOptions ); - final ArchiveContext context = buildArchiveContext( persistenceUnit, true, resultCollector ); - descriptor.visitArchive( context ); - } - - return ScanResultImpl.from( resultCollector ); - } - - private ArchiveContext buildArchiveContext( - PersistenceUnitDescriptor persistenceUnit, - boolean isRoot, - ArchiveEntryHandlers entryHandlers) { - return new ArchiveContextImpl( persistenceUnit, isRoot, entryHandlers ); - } - - protected static interface ArchiveEntryHandlers { - public ArchiveEntryHandler getClassFileHandler(); - public ArchiveEntryHandler getPackageInfoHandler(); - public ArchiveEntryHandler getFileHandler(); - } - - private ArchiveDescriptor buildArchiveDescriptor(URL url, boolean isRootUrl, ScanOptions scanOptions) { - final ArchiveDescriptor descriptor; - final ArchiveDescriptorInfo descriptorInfo = archiveDescriptorCache.get( url ); - if ( descriptorInfo == null ) { - descriptor = archiveDescriptorFactory.buildArchiveDescriptor( url ); - archiveDescriptorCache.put( - url, - new ArchiveDescriptorInfo( descriptor, isRootUrl, scanOptions ) - ); - } - else { - validateReuse( descriptorInfo, isRootUrl, scanOptions ); - descriptor = descriptorInfo.archiveDescriptor; - } - return descriptor; - } - - public static class ResultCollector - implements ArchiveEntryHandlers, - PackageInfoArchiveEntryHandler.Callback, - ClassFileArchiveEntryHandler.Callback, - NonClassFileArchiveEntryHandler.Callback { - private final ClassFileArchiveEntryHandler classFileHandler; - private final PackageInfoArchiveEntryHandler packageInfoHandler; - private final NonClassFileArchiveEntryHandler fileHandler; - - private final Set packageDescriptorSet = new HashSet(); - private final Set classDescriptorSet = new HashSet(); - private final Set mappingFileSet = new HashSet(); - - public ResultCollector(ScanOptions scanOptions) { - this.classFileHandler = new ClassFileArchiveEntryHandler( scanOptions, this ); - this.packageInfoHandler = new PackageInfoArchiveEntryHandler( scanOptions, this ); - this.fileHandler = new NonClassFileArchiveEntryHandler( scanOptions, this ); - } - - @Override - public ArchiveEntryHandler getClassFileHandler() { - return classFileHandler; - } - - @Override - public ArchiveEntryHandler getPackageInfoHandler() { - return packageInfoHandler; - } - - @Override - public ArchiveEntryHandler getFileHandler() { - return fileHandler; - } - - @Override - public void locatedPackage(PackageDescriptor packageDescriptor) { - if ( PackageDescriptorImpl.class.isInstance( packageDescriptor ) ) { - packageDescriptorSet.add( packageDescriptor ); - } - else { - // to make sure we have proper equals/hashcode - packageDescriptorSet.add( - new PackageDescriptorImpl( - packageDescriptor.getName(), - packageDescriptor.getStreamAccess() - ) - ); - } - } - - @Override - public void locatedClass(ClassDescriptor classDescriptor) { - if ( ClassDescriptorImpl.class.isInstance( classDescriptor ) ) { - classDescriptorSet.add( classDescriptor ); - } - else { - // to make sure we have proper equals/hashcode - classDescriptorSet.add( - new ClassDescriptorImpl( - classDescriptor.getName(), - classDescriptor.getStreamAccess() - ) - ); - } - } - - @Override - public void locatedMappingFile(MappingFileDescriptor mappingFileDescriptor) { - if ( MappingFileDescriptorImpl.class.isInstance( mappingFileDescriptor ) ) { - mappingFileSet.add( mappingFileDescriptor ); - } - else { - // to make sure we have proper equals/hashcode - mappingFileSet.add( - new MappingFileDescriptorImpl( - mappingFileDescriptor.getName(), - mappingFileDescriptor.getStreamAccess() - ) - ); - } - } - - public Set getPackageDescriptorSet() { - return packageDescriptorSet; - } - - public Set getClassDescriptorSet() { - return classDescriptorSet; - } - - public Set getMappingFileSet() { - return mappingFileSet; - } - } - - // This needs to be protected and attributes/constructor visible in case - // a custom scanner needs to override validateReuse. - protected static class ArchiveDescriptorInfo { - public final ArchiveDescriptor archiveDescriptor; - public final boolean isRoot; - public final ScanOptions scanOptions; - - public ArchiveDescriptorInfo( - ArchiveDescriptor archiveDescriptor, - boolean isRoot, - ScanOptions scanOptions) { - this.archiveDescriptor = archiveDescriptor; - this.isRoot = isRoot; - this.scanOptions = scanOptions; - } - } - - protected void validateReuse(ArchiveDescriptorInfo descriptor, boolean root, ScanOptions options) { - // is it really reasonable that a single url be processed multiple times? - // for now, throw an exception, mainly because I am interested in situations where this might happen - throw new IllegalStateException( "ArchiveDescriptor reused; can URLs be processed multiple times?" ); - } - - public static class ArchiveContextImpl implements ArchiveContext { - private final PersistenceUnitDescriptor persistenceUnitDescriptor; - private final boolean isRootUrl; - private final ArchiveEntryHandlers entryHandlers; - - public ArchiveContextImpl( - PersistenceUnitDescriptor persistenceUnitDescriptor, - boolean isRootUrl, - ArchiveEntryHandlers entryHandlers) { - this.persistenceUnitDescriptor = persistenceUnitDescriptor; - this.isRootUrl = isRootUrl; - this.entryHandlers = entryHandlers; - } - - @Override - public PersistenceUnitDescriptor getPersistenceUnitDescriptor() { - return persistenceUnitDescriptor; - } - - @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(); - } - } - } - - private static class ScanResultImpl implements ScanResult { - private final Set packageDescriptorSet; - private final Set classDescriptorSet; - private final Set mappingFileSet; - - private ScanResultImpl( - Set packageDescriptorSet, - Set classDescriptorSet, - Set mappingFileSet) { - this.packageDescriptorSet = packageDescriptorSet; - this.classDescriptorSet = classDescriptorSet; - this.mappingFileSet = mappingFileSet; - } - - private static ScanResult from(ResultCollector resultCollector) { - return new ScanResultImpl( - Collections.unmodifiableSet( resultCollector.packageDescriptorSet ), - Collections.unmodifiableSet( resultCollector.classDescriptorSet ), - Collections.unmodifiableSet( resultCollector.mappingFileSet ) - ); - } - - @Override - public Set getLocatedPackages() { - return packageDescriptorSet; - } - - @Override - public Set getLocatedClasses() { - return classDescriptorSet; - } - - @Override - public Set getLocatedMappingFiles() { - return mappingFileSet; - } - } - -} diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/NonClassFileArchiveEntryHandler.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/NonClassFileArchiveEntryHandler.java deleted file mode 100644 index c79d3e3e99..0000000000 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/NonClassFileArchiveEntryHandler.java +++ /dev/null @@ -1,88 +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.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.spi.MappingFileDescriptor; - -/** - * Defines handling and filtering for all non-class file (package-info is also a class file...) entries within an archive - * - * @author Steve Ebersole - */ -public class NonClassFileArchiveEntryHandler implements ArchiveEntryHandler { - private final ScanOptions scanOptions; - private final Callback callback; - - /** - * Contract for the thing interested in being notified about accepted mapping file descriptors. - */ - public static interface Callback { - public void locatedMappingFile(MappingFileDescriptor mappingFileDescriptor); - } - - public NonClassFileArchiveEntryHandler(ScanOptions scanOptions, Callback callback) { - this.scanOptions = scanOptions; - this.callback = callback; - } - - @Override - public void handleEntry(ArchiveEntry entry, ArchiveContext context) { - if ( acceptAsMappingFile( entry, context) ) { - notifyMatchedMappingFile( entry ); - } - } - - @SuppressWarnings("SimplifiableIfStatement") - private boolean acceptAsMappingFile(ArchiveEntry entry, ArchiveContext context) { - if ( entry.getNameWithinArchive().endsWith( "hbm.xml" ) ) { - return scanOptions.canDetectHibernateMappingFiles(); - } - - // todo : should really do this case-insensitively - // use getNameWithinArchive, not getName -- ensure paths are normalized (Windows, etc.) - if ( entry.getNameWithinArchive().endsWith( "META-INF/orm.xml" ) ) { - if ( context.getPersistenceUnitDescriptor().getMappingFileNames().contains( "META-INF/orm.xml" ) ) { - // if the user explicitly listed META-INF/orm.xml, only except the root one - // - // not sure why exactly, but this is what the old code does - return context.isRootUrl(); - } - return true; - } - - return context.getPersistenceUnitDescriptor().getMappingFileNames().contains( entry.getNameWithinArchive() ); - } - - protected final void notifyMatchedMappingFile(ArchiveEntry entry) { - callback.locatedMappingFile( toMappingFileDescriptor( entry ) ); - } - - protected MappingFileDescriptor toMappingFileDescriptor(ArchiveEntry entry) { - return new MappingFileDescriptorImpl( entry.getNameWithinArchive(), entry.getStreamAccess() ); - } -} diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/CustomScanner.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/CustomScanner.java index 71a6d5e72b..cf02bf188a 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/CustomScanner.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/CustomScanner.java @@ -1,10 +1,11 @@ package org.hibernate.jpa.test.packaging; -import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor; -import org.hibernate.jpa.boot.scan.internal.StandardScanner; -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.boot.archive.scan.internal.StandardScanner; +import org.hibernate.boot.archive.scan.spi.ScanEnvironment; +import org.hibernate.boot.archive.scan.spi.ScanOptions; +import org.hibernate.boot.archive.scan.spi.ScanParameters; +import org.hibernate.boot.archive.scan.spi.ScanResult; +import org.hibernate.boot.archive.scan.spi.Scanner; /** * @author Emmanuel Bernard @@ -22,8 +23,12 @@ public class CustomScanner implements Scanner { } @Override - public ScanResult scan(PersistenceUnitDescriptor persistenceUnit, ScanOptions options) { + public ScanResult scan( + ScanEnvironment environment, + ScanOptions options, + ScanParameters parameters) { isUsed = true; - return delegate.scan( persistenceUnit, options ); + return delegate.scan( environment, options, parameters ); } } + diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/JarVisitorTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/JarVisitorTest.java index e4ed5d1ef4..8b405dffb2 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/JarVisitorTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/JarVisitorTest.java @@ -32,32 +32,36 @@ import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; +import java.util.Collections; +import java.util.List; +import org.hibernate.boot.archive.internal.ArchiveHelper; +import org.hibernate.boot.archive.internal.ExplodedArchiveDescriptor; +import org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor; +import org.hibernate.boot.archive.internal.JarProtocolArchiveDescriptor; +import org.hibernate.boot.archive.internal.StandardArchiveDescriptorFactory; +import org.hibernate.boot.archive.scan.internal.ClassDescriptorImpl; +import org.hibernate.boot.archive.scan.internal.ScanResultCollector; +import org.hibernate.boot.archive.scan.internal.StandardScanOptions; +import org.hibernate.boot.archive.scan.internal.StandardScanner; +import org.hibernate.boot.archive.scan.spi.AbstractScannerImpl; +import org.hibernate.boot.archive.scan.spi.JandexInitializer; +import org.hibernate.boot.archive.scan.spi.MappingFileDescriptor; +import org.hibernate.boot.archive.scan.spi.ScanEnvironment; +import org.hibernate.boot.archive.scan.spi.ScanParameters; +import org.hibernate.boot.archive.scan.spi.ScanResult; +import org.hibernate.boot.archive.spi.ArchiveDescriptor; 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.JarInputStreamBasedArchiveDescriptor; -import org.hibernate.jpa.boot.archive.internal.JarProtocolArchiveDescriptor; -import org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory; -import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor; -import org.hibernate.jpa.boot.internal.ClassDescriptorImpl; -import org.hibernate.jpa.boot.scan.internal.StandardScanOptions; -import org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl; -import org.hibernate.jpa.boot.spi.MappingFileDescriptor; -import org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter; import org.hibernate.jpa.test.pack.defaultpar.Version; import org.hibernate.jpa.test.pack.explodedpar.Carpet; -import org.junit.Test; - import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; +import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; /** * @author Emmanuel Bernard @@ -69,7 +73,7 @@ import static org.junit.Assert.fail; public class JarVisitorTest extends PackagingTestCase { @Test public void testHttp() throws Exception { - URL url = ArchiveHelper.getJarURLFromURLEntry( + final URL url = ArchiveHelper.getJarURLFromURLEntry( new URL( "jar:http://www.ibiblio.org/maven/hibernate/jars/hibernate-annotations-3.0beta1.jar!/META-INF/persistence.xml" ), @@ -83,18 +87,55 @@ public class JarVisitorTest extends PackagingTestCase { //fail silently return; } - ArchiveDescriptor archiveDescriptor = StandardArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor( url ); - AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector( new StandardScanOptions() ); - archiveDescriptor.visitArchive( - new AbstractScannerImpl.ArchiveContextImpl( - new PersistenceUnitDescriptorAdapter(), - true, - resultCollector - ) + + ScanResult result = standardScan( url ); + assertEquals( 0, result.getLocatedClasses().size() ); + assertEquals( 0, result.getLocatedPackages().size() ); + assertEquals( 0, result.getLocatedMappingFiles().size() ); + } + + private ScanResult standardScan(URL url) { + ScanEnvironment env = new ScanEnvironmentImpl( url ); + return new StandardScanner().scan( + env, + new StandardScanOptions(), + new ScanParameters() { +// private final JandexInitManager jandexInitManager = new JandexInitManager(); + @Override + public JandexInitializer getJandexInitializer() { +// return jandexInitManager; + return null; + } + } ); - assertEquals( 0, resultCollector.getClassDescriptorSet().size() ); - assertEquals( 0, resultCollector.getPackageDescriptorSet().size() ); - assertEquals( 0, resultCollector.getMappingFileSet().size() ); + } + + private static class ScanEnvironmentImpl implements ScanEnvironment { + private final URL rootUrl; + + private ScanEnvironmentImpl(URL rootUrl) { + this.rootUrl = rootUrl; + } + + @Override + public URL getRootUrl() { + return rootUrl; + } + + @Override + public List getNonRootUrls() { + return Collections.emptyList(); + } + + @Override + public List getExplicitlyListedClassNames() { + return Collections.emptyList(); + } + + @Override + public List getExplicitlyListedMappingFiles() { + return Collections.emptyList(); + } } @Test @@ -102,36 +143,22 @@ public class JarVisitorTest extends PackagingTestCase { File defaultPar = buildDefaultPar(); addPackageToClasspath( defaultPar ); - ArchiveDescriptor archiveDescriptor = new JarInputStreamBasedArchiveDescriptor( - StandardArchiveDescriptorFactory.INSTANCE, - defaultPar.toURL(), - "" - ); - - AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector( new StandardScanOptions() ); - archiveDescriptor.visitArchive( - new AbstractScannerImpl.ArchiveContextImpl( - new PersistenceUnitDescriptorAdapter(), - true, - resultCollector - ) - ); - - validateResults( resultCollector, org.hibernate.jpa.test.pack.defaultpar.ApplicationServer.class, Version.class ); + ScanResult result = standardScan( defaultPar.toURL() ); + validateResults( result, org.hibernate.jpa.test.pack.defaultpar.ApplicationServer.class, Version.class ); } - private void validateResults(AbstractScannerImpl.ResultCollector resultCollector, Class... expectedClasses) throws IOException { - assertEquals( 3, resultCollector.getClassDescriptorSet().size() ); + private void validateResults(ScanResult scanResult, Class... expectedClasses) throws IOException { + assertEquals( 3, scanResult.getLocatedClasses().size() ); for ( Class expectedClass : expectedClasses ) { assertTrue( - resultCollector.getClassDescriptorSet().contains( + scanResult.getLocatedClasses().contains( new ClassDescriptorImpl( expectedClass.getName(), null ) ) ); } - assertEquals( 2, resultCollector.getMappingFileSet().size() ); - for ( MappingFileDescriptor mappingFileDescriptor : resultCollector.getMappingFileSet() ) { + assertEquals( 2, scanResult.getLocatedMappingFiles().size() ); + for ( MappingFileDescriptor mappingFileDescriptor : scanResult.getLocatedMappingFiles() ) { assertNotNull( mappingFileDescriptor.getStreamAccess() ); final InputStream stream = mappingFileDescriptor.getStreamAccess().accessInputStream(); assertNotNull( stream ); @@ -147,39 +174,68 @@ public class JarVisitorTest extends PackagingTestCase { addPackageToClasspath( nestedEar ); String jarFileName = nestedEar.toURL().toExternalForm() + "!/defaultpar.par"; + URL rootUrl = new URL( jarFileName ); JarProtocolArchiveDescriptor archiveDescriptor = new JarProtocolArchiveDescriptor( StandardArchiveDescriptorFactory.INSTANCE, - new URL( jarFileName ), + rootUrl, "" ); - AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector( new StandardScanOptions() ); - archiveDescriptor.visitArchive( - new AbstractScannerImpl.ArchiveContextImpl( - new PersistenceUnitDescriptorAdapter(), - true, - resultCollector - ) + + ScanEnvironment environment = new ScanEnvironmentImpl( rootUrl ); + ScanResultCollector collector = new ScanResultCollector( + environment, + new StandardScanOptions(), + new ScanParameters() { +// private final JandexInitManager jandexInitManager = new JandexInitManager(); + @Override + public JandexInitializer getJandexInitializer() { +// return jandexInitManager; + return null; + } + } ); - validateResults( resultCollector, org.hibernate.jpa.test.pack.defaultpar.ApplicationServer.class, Version.class ); + archiveDescriptor.visitArchive( + new AbstractScannerImpl.ArchiveContextImpl( true, collector ) + ); + + validateResults( + collector.toScanResult(), + org.hibernate.jpa.test.pack.defaultpar.ApplicationServer.class, + Version.class + ); jarFileName = nestedEarDir.toURL().toExternalForm() + "!/defaultpar.par"; + rootUrl = new URL( jarFileName ); archiveDescriptor = new JarProtocolArchiveDescriptor( StandardArchiveDescriptorFactory.INSTANCE, - new URL( jarFileName ), + rootUrl, "" ); - resultCollector = new AbstractScannerImpl.ResultCollector( new StandardScanOptions() ); - archiveDescriptor.visitArchive( - new AbstractScannerImpl.ArchiveContextImpl( - new PersistenceUnitDescriptorAdapter(), - true, - resultCollector - ) + + environment = new ScanEnvironmentImpl( rootUrl ); + collector = new ScanResultCollector( + environment, + new StandardScanOptions(), + new ScanParameters() { +// private final JandexInitManager jandexInitManager = new JandexInitManager(); + @Override + public JandexInitializer getJandexInitializer() { +// return jandexInitManager; + return null; + } + } ); - validateResults( resultCollector, org.hibernate.jpa.test.pack.defaultpar.ApplicationServer.class, Version.class ); + archiveDescriptor.visitArchive( + new AbstractScannerImpl.ArchiveContextImpl( true, collector ) + ); + validateResults( + collector.toScanResult(), + org.hibernate.jpa.test.pack.defaultpar.ApplicationServer.class, + Version.class + ); } @Test @@ -188,23 +244,34 @@ public class JarVisitorTest extends PackagingTestCase { addPackageToClasspath( war ); String jarFileName = war.toURL().toExternalForm() + "!/WEB-INF/classes"; + URL rootUrl = new URL( jarFileName ); + JarProtocolArchiveDescriptor archiveDescriptor = new JarProtocolArchiveDescriptor( StandardArchiveDescriptorFactory.INSTANCE, - new URL( jarFileName ), + rootUrl, "" ); - AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector( new StandardScanOptions() ); + final ScanEnvironment environment = new ScanEnvironmentImpl( rootUrl ); + final ScanResultCollector collector = new ScanResultCollector( + environment, + new StandardScanOptions(), + new ScanParameters() { +// private final JandexInitManager jandexInitManager = new JandexInitManager(); + @Override + public JandexInitializer getJandexInitializer() { +// return jandexInitManager; + return null; + } + } + ); + archiveDescriptor.visitArchive( - new AbstractScannerImpl.ArchiveContextImpl( - new PersistenceUnitDescriptorAdapter(), - true, - resultCollector - ) + new AbstractScannerImpl.ArchiveContextImpl( true, collector ) ); validateResults( - resultCollector, + collector.toScanResult(), org.hibernate.jpa.test.pack.war.ApplicationServer.class, org.hibernate.jpa.test.pack.war.Version.class ); @@ -215,21 +282,12 @@ public class JarVisitorTest extends PackagingTestCase { File defaultPar = buildDefaultPar(); addPackageToClasspath( defaultPar ); - JarFileBasedArchiveDescriptor archiveDescriptor = new JarFileBasedArchiveDescriptor( - StandardArchiveDescriptorFactory.INSTANCE, - defaultPar.toURL(), - "" + ScanResult result = standardScan( defaultPar.toURL() ); + validateResults( + result, + org.hibernate.jpa.test.pack.defaultpar.ApplicationServer.class, + Version.class ); - AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector( new StandardScanOptions() ); - archiveDescriptor.visitArchive( - new AbstractScannerImpl.ArchiveContextImpl( - new PersistenceUnitDescriptorAdapter(), - true, - resultCollector - ) - ); - - validateResults( resultCollector, org.hibernate.jpa.test.pack.defaultpar.ApplicationServer.class, Version.class ); } @Test @@ -243,59 +301,46 @@ public class JarVisitorTest extends PackagingTestCase { dirPath = dirPath.substring( 0, dirPath.length() - 1 ); } - ExplodedArchiveDescriptor archiveDescriptor = new ExplodedArchiveDescriptor( - StandardArchiveDescriptorFactory.INSTANCE, - ArchiveHelper.getURLFromPath( dirPath ), - "" - ); - AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector( new StandardScanOptions() ); - archiveDescriptor.visitArchive( - new AbstractScannerImpl.ArchiveContextImpl( - new PersistenceUnitDescriptorAdapter(), - true, - resultCollector - ) - ); - - assertEquals( 1, resultCollector.getClassDescriptorSet().size() ); - assertEquals( 1, resultCollector.getPackageDescriptorSet().size() ); - assertEquals( 1, resultCollector.getMappingFileSet().size() ); + ScanResult result = standardScan( ArchiveHelper.getURLFromPath( dirPath ) ); + assertEquals( 1, result.getLocatedClasses().size() ); + assertEquals( 1, result.getLocatedPackages().size() ); + assertEquals( 1, result.getLocatedMappingFiles().size() ); assertTrue( - resultCollector.getClassDescriptorSet().contains( + result.getLocatedClasses().contains( new ClassDescriptorImpl( Carpet.class.getName(), null ) ) ); - for ( MappingFileDescriptor mappingFileDescriptor : resultCollector.getMappingFileSet() ) { + for ( MappingFileDescriptor mappingFileDescriptor : result.getLocatedMappingFiles() ) { assertNotNull( mappingFileDescriptor.getStreamAccess() ); final InputStream stream = mappingFileDescriptor.getStreamAccess().accessInputStream(); assertNotNull( stream ); stream.close(); } } - + @Test @TestForIssue(jiraKey = "HHH-6806") public void testJarVisitorFactory() throws Exception { final File explodedPar = buildExplodedPar(); final File defaultPar = buildDefaultPar(); addPackageToClasspath( explodedPar, defaultPar ); - - //setting URL to accept vfs based protocol + + //setting URL to accept vfs based protocol URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() { - public URLStreamHandler createURLStreamHandler(String protocol) { - if("vfszip".equals(protocol) || "vfsfile".equals(protocol) ) - return new URLStreamHandler() { - protected URLConnection openConnection(URL u) - throws IOException { - return null; - } - }; - return null; - } - }); - + public URLStreamHandler createURLStreamHandler(String protocol) { + if("vfszip".equals(protocol) || "vfsfile".equals(protocol) ) + return new URLStreamHandler() { + protected URLConnection openConnection(URL u) + throws IOException { + return null; + } + }; + return null; + } + }); + URL jarUrl = defaultPar.toURL(); ArchiveDescriptor descriptor = StandardArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor( jarUrl ); assertEquals( JarFileBasedArchiveDescriptor.class.getName(), descriptor.getClass().getName() ); @@ -358,7 +403,7 @@ public class JarVisitorTest extends PackagingTestCase { // Entry entry = new Entry( Carpet.class.getName(), null ); // assertTrue( entries[1].contains( entry ) ); } - + @Test @TestForIssue(jiraKey = "HHH-7835") public void testGetBytesFromInputStream() throws Exception { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/ScannerTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/ScannerTest.java index 28ed10ab8e..fbd3177112 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/ScannerTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/ScannerTest.java @@ -29,17 +29,20 @@ import java.io.File; import java.io.InputStream; import java.util.HashMap; -import org.hibernate.jpa.AvailableSettings; +import org.hibernate.boot.archive.scan.spi.JandexInitializer; +import org.hibernate.boot.archive.scan.spi.ScanEnvironment; +import org.hibernate.boot.archive.scan.spi.ScanParameters; +import org.hibernate.cfg.AvailableSettings; import org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor; +import org.hibernate.jpa.boot.internal.StandardJpaScanEnvironmentImpl; import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor; -import org.hibernate.jpa.boot.scan.internal.StandardScanOptions; -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.ScanOptions; -import org.hibernate.jpa.boot.scan.spi.ScanResult; -import org.hibernate.jpa.boot.scan.spi.Scanner; +import org.hibernate.boot.archive.scan.internal.StandardScanOptions; +import org.hibernate.boot.archive.scan.internal.StandardScanner; +import org.hibernate.boot.archive.scan.spi.ClassDescriptor; +import org.hibernate.boot.archive.scan.spi.MappingFileDescriptor; +import org.hibernate.boot.archive.scan.spi.ScanOptions; +import org.hibernate.boot.archive.scan.spi.ScanResult; +import org.hibernate.boot.archive.scan.spi.Scanner; import org.hibernate.jpa.test.pack.defaultpar.ApplicationServer; import org.hibernate.jpa.test.pack.defaultpar.Version; @@ -61,9 +64,21 @@ public class ScannerTest extends PackagingTestCase { addPackageToClasspath( defaultPar ); PersistenceUnitDescriptor descriptor = new ParsedPersistenceXmlDescriptor( defaultPar.toURL() ); + ScanEnvironment env = new StandardJpaScanEnvironmentImpl( descriptor ); ScanOptions options = new StandardScanOptions( "hbm,class", descriptor.isExcludeUnlistedClasses() ); Scanner scanner = new StandardScanner(); - ScanResult scanResult = scanner.scan( descriptor, options ); + ScanResult scanResult = scanner.scan( + env, + options, + new ScanParameters() { +// private final JandexInitManager jandexInitManager = new JandexInitManager(); + @Override + public JandexInitializer getJandexInitializer() { +// return jandexInitManager; + return null; + } + } + ); assertEquals( 3, scanResult.getLocatedClasses().size() ); assertClassesContained( scanResult, ApplicationServer.class ); @@ -76,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(); } } diff --git a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiArchiveDescriptor.java b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiArchiveDescriptor.java index 2a5c7c1175..41fa02d628 100644 --- a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiArchiveDescriptor.java +++ b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiArchiveDescriptor.java @@ -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.boot.archive.spi.ArchiveContext; +import org.hibernate.boot.archive.spi.ArchiveDescriptor; +import org.hibernate.boot.archive.spi.ArchiveEntry; +import org.hibernate.boot.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 { diff --git a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiArchiveDescriptorFactory.java b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiArchiveDescriptorFactory.java index 74b08c8b41..f7f601a27f 100644 --- a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiArchiveDescriptorFactory.java +++ b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiArchiveDescriptorFactory.java @@ -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.boot.archive.spi.ArchiveDescriptor; +import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory; import org.osgi.framework.Bundle; diff --git a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiPersistenceProvider.java b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiPersistenceProvider.java index 83dc6057c7..43ab26b11f 100644 --- a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiPersistenceProvider.java +++ b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiPersistenceProvider.java @@ -85,7 +85,7 @@ public class OsgiPersistenceProvider extends HibernatePersistenceProvider { final Map settings = generateSettings( properties ); // TODO: This needs tested. - settings.put( org.hibernate.jpa.AvailableSettings.SCANNER, new OsgiScanner( requestingBundle ) ); + settings.put( org.hibernate.cfg.AvailableSettings.SCANNER, new OsgiScanner( requestingBundle ) ); // TODO: This is temporary -- for PersistenceXmlParser's use of // ClassLoaderServiceImpl#fromConfigSettings settings.put( AvailableSettings.ENVIRONMENT_CLASSLOADER, osgiClassLoader ); @@ -103,7 +103,7 @@ public class OsgiPersistenceProvider extends HibernatePersistenceProvider { // OSGi ClassLoaders must implement BundleReference settings.put( - org.hibernate.jpa.AvailableSettings.SCANNER, + org.hibernate.cfg.AvailableSettings.SCANNER, new OsgiScanner( ( (BundleReference) info.getClassLoader() ).getBundle() ) ); diff --git a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiScanner.java b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiScanner.java index dc28e4bb1c..64303c8ec2 100644 --- a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiScanner.java +++ b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiScanner.java @@ -20,7 +20,7 @@ */ package org.hibernate.osgi; -import org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl; +import org.hibernate.boot.archive.scan.spi.AbstractScannerImpl; import org.osgi.framework.Bundle;