Permalink
Browse files

HHH-8088 - Redesign Scanner contract

  • Loading branch information...
1 parent a1afa0c commit eeca84460ef36f93339f98fed3ab4b7047625da2 @sebersole sebersole committed Mar 21, 2013
Showing with 2,884 additions and 1,782 deletions.
  1. +4 −2 hibernate-entitymanager/src/main/java/org/hibernate/ejb/packaging/NamedInputStream.java
  2. +2 −2 hibernate-entitymanager/src/main/java/org/hibernate/ejb/packaging/Scanner.java
  3. +35 −68 ...ernate/jpa/{packaging/internal/JarVisitorFactory.java → boot/archive/internal/ArchiveHelper.java}
  4. +212 −0 ...ntitymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/ExplodedArchiveDescriptor.java
  5. +193 −0 ...ymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/JarFileBasedArchiveDescriptor.java
  6. +168 −0 ...r/src/main/java/org/hibernate/jpa/boot/archive/internal/JarInputStreamBasedArchiveDescriptor.java
  7. +71 −0 ...tymanager/src/main/java/org/hibernate/jpa/boot/archive/internal/JarProtocolArchiveDescriptor.java
  8. +105 −0 ...nager/src/main/java/org/hibernate/jpa/boot/archive/internal/StandardArchiveDescriptorFactory.java
  9. +92 −0 ...ate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/AbstractArchiveDescriptor.java
  10. +37 −0 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveContext.java
  11. +9 −15 ...java/org/hibernate/jpa/{packaging/internal/Filter.java → boot/archive/spi/ArchiveDescriptor.java}
  12. +14 −18 ...bernate/jpa/{packaging/internal/FileFilter.java → boot/archive/spi/ArchiveDescriptorFactory.java}
  13. +24 −15 .../java/org/hibernate/jpa/{packaging/internal/JarVisitor.java → boot/archive/spi/ArchiveEntry.java}
  14. +33 −0 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/archive/spi/ArchiveEntryHandler.java
  15. +15 −14 .../org/hibernate/jpa/{packaging/internal/ClassFilter.java → boot/archive/spi/ArchiveException.java}
  16. +60 −0 ...rnate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/ByteArrayInputStreamAccess.java
  17. +29 −23 ...n/java/org/hibernate/jpa/{packaging/internal/Entry.java → boot/internal/ClassDescriptorImpl.java}
  18. +206 −234 ...-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java
  19. +77 −0 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/FileInputStreamAccess.java
  20. +73 −0 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/MappingFileDescriptorImpl.java
  21. +68 −0 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/PackageDescriptorImpl.java
  22. +3 −3 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/PersistenceXmlParser.java
  23. +62 −0 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/UrlInputStreamAccess.java
  24. +67 −0 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/internal/StandardScanOptions.java
  25. +40 −0 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/internal/StandardScanner.java
  26. +302 −0 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/AbstractScannerImpl.java
  27. +132 −0 ...ate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/ClassFileArchiveEntryHandler.java
  28. +82 −0 ...-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/NonClassFileArchiveEntryHandler.java
  29. +71 −0 ...e-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/PackageInfoArchiveEntryHandler.java
  30. +12 −16 ...n/java/org/hibernate/jpa/{packaging/internal/PackageFilter.java → boot/scan/spi/ScanOptions.java}
  31. +41 −0 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/ScanResult.java
  32. +46 −0 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/scan/spi/Scanner.java
  33. +34 −0 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/ClassDescriptor.java
  34. +52 −0 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/InputStreamAccess.java
  35. +32 −0 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/MappingFileDescriptor.java
  36. +11 −12 hibernate-entitymanager/src/main/java/org/hibernate/jpa/{packaging → boot}/spi/NamedInputStream.java
  37. +34 −0 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/PackageDescriptor.java
  38. +0 −262 hibernate-entitymanager/src/main/java/org/hibernate/jpa/packaging/internal/AbstractJarVisitor.java
  39. +0 −138 hibernate-entitymanager/src/main/java/org/hibernate/jpa/packaging/internal/ExplodedJarVisitor.java
  40. +0 −133 hibernate-entitymanager/src/main/java/org/hibernate/jpa/packaging/internal/FileZippedJarVisitor.java
  41. +0 −121 ...entitymanager/src/main/java/org/hibernate/jpa/packaging/internal/InputStreamZippedJarVisitor.java
  42. +0 −73 hibernate-entitymanager/src/main/java/org/hibernate/jpa/packaging/internal/JarProtocolVisitor.java
  43. +0 −52 hibernate-entitymanager/src/main/java/org/hibernate/jpa/packaging/internal/JavaElementFilter.java
  44. +0 −248 hibernate-entitymanager/src/main/java/org/hibernate/jpa/packaging/internal/NativeScanner.java
  45. +0 −67 hibernate-entitymanager/src/main/java/org/hibernate/jpa/packaging/spi/Scanner.java
  46. +67 −0 hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/TestHelper.java
  47. +9 −30 hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/CustomScanner.java
  48. +208 −199 hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/JarVisitorTest.java
  49. +9 −2 hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagingTestCase.java
  50. +43 −35 hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/ScannerTest.java
@@ -26,10 +26,12 @@
import java.io.InputStream;
/**
- * @deprecated Use {@link org.hibernate.jpa.packaging.spi.NamedInputStream} instead
+ * @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.packaging.spi.NamedInputStream {
+public class NamedInputStream extends org.hibernate.jpa.boot.spi.NamedInputStream {
public NamedInputStream(String name, InputStream stream) {
super( name, stream );
}
@@ -24,8 +24,8 @@
package org.hibernate.ejb.packaging;
/**
- * @deprecated Use {@link org.hibernate.jpa.packaging.spi.Scanner} instead
+ * @deprecated Use {@link org.hibernate.jpa.boot.scan.spi.Scanner} instead
*/
@Deprecated
-public interface Scanner extends org.hibernate.jpa.packaging.spi.Scanner {
+public interface Scanner extends org.hibernate.jpa.boot.scan.spi.Scanner {
}
@@ -1,8 +1,10 @@
/*
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * 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 Middleware LLC.
+ * 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
@@ -19,29 +21,26 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
-package org.hibernate.jpa.packaging.internal;
+package org.hibernate.jpa.boot.archive.internal;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
-import java.net.URISyntaxException;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
-import org.hibernate.internal.util.StringHelper;
-import org.hibernate.jpa.internal.EntityManagerMessageLogger;
import org.jboss.logging.Logger;
+import org.hibernate.jpa.boot.archive.spi.ArchiveException;
+
/**
* @author Emmanuel Bernard
- * @author Brett Meyer
+ * @author Steve Ebersole
*/
-public class JarVisitorFactory {
-
- private static final EntityManagerMessageLogger LOG = Logger.getMessageLogger(EntityManagerMessageLogger.class,
- JarVisitorFactory.class.getName());
+public class ArchiveHelper {
+ private static final Logger log = Logger.getLogger( ArchiveHelper.class );
/**
* Get the JAR URL of the JAR containing the given entry
@@ -51,7 +50,6 @@
* @param entry file known to be in the JAR
* @return the JAR URL
* @throws IllegalArgumentException if none URL is found
- * TODO move to a ScannerHelper service?
*/
public static URL getJarURLFromURLEntry(URL url, String entry) throws IllegalArgumentException {
URL jarUrl;
@@ -106,15 +104,14 @@ else if ( "zip".equals( protocol ) //Weblogic has it's own way
"Unable to determine JAR Url from " + url + ". Cause: " + e.getMessage()
);
}
- LOG.trace("JAR URL from URL Entry: " + url + " >> " + jarUrl);
+ log.trace("JAR URL from URL Entry: " + url + " >> " + jarUrl);
return jarUrl;
}
/**
* get the URL from a given path string
*
* @throws IllegalArgumentException is something goes wrong
- * TODO move to a ScannerHelper service?
*/
public static URL getURLFromPath(String jarPath) {
URL jarUrl;
@@ -134,70 +131,40 @@ public static URL getURLFromPath(String jarPath) {
return jarUrl;
}
- /**
- * Get a JarVisitor to the jar <code>jarPath</code> applying the given filters
- *
- * Method used in a non-managed environment
- *
- * @throws IllegalArgumentException if the jarPath is incorrect
- */
- public static JarVisitor getVisitor(String jarPath, Filter[] filters) throws IllegalArgumentException {
- File file = new File( jarPath );
- if ( file.isFile() ) {
- return new InputStreamZippedJarVisitor( jarPath, filters );
+ public static String unqualifiedJarFileName(URL jarUrl) {
+ // todo : weak algorithm subject to AOOBE
+ String fileName = jarUrl.getFile();
+ int exclamation = fileName.lastIndexOf( "!" );
+ if (exclamation != -1) {
+ fileName = fileName.substring( 0, exclamation );
}
- else {
- return new ExplodedJarVisitor( jarPath, filters );
- }
- }
- /**
- * Build a JarVisitor on the given JAR URL applying the given filters
- *
- * @throws IllegalArgumentException if the URL is malformed
- */
- public static JarVisitor getVisitor(URL jarUrl, Filter[] filters) throws IllegalArgumentException {
- return getVisitor( jarUrl, filters, "" );
- }
+ int slash = fileName.lastIndexOf( "/" );
+ if ( slash != -1 ) {
+ fileName = fileName.substring(
+ fileName.lastIndexOf( "/" ) + 1,
+ fileName.length()
+ );
+ }
- public static JarVisitor getVisitor(URL jarUrl, Filter[] filters, String entry) throws IllegalArgumentException {
- String protocol = jarUrl.getProtocol();
- if ( "jar".equals( protocol ) ) {
- return new JarProtocolVisitor( jarUrl, filters, entry );
+ if ( fileName.length() > 4 && fileName.endsWith( "ar" ) && fileName.charAt( fileName.length() - 4 ) == '.' ) {
+ fileName = fileName.substring( 0, fileName.length() - 4 );
}
- else if ( StringHelper.isEmpty( protocol ) || "file".equals( protocol ) || "vfszip".equals( protocol ) || "vfsfile".equals( protocol ) ) {
- File file;
- try {
- final String filePart = jarUrl.getFile();
- if ( filePart != null && filePart.indexOf( ' ' ) != -1 ) {
- //unescaped (from the container), keep as is
- file = new File( jarUrl.getFile() );
- }
- else {
- file = new File( jarUrl.toURI().getSchemeSpecificPart() );
- }
- }
- catch (URISyntaxException e) {
- throw new IllegalArgumentException(
- "Unable to visit JAR " + jarUrl + ". Cause: " + e.getMessage(), e
- );
- }
- if ( file.isDirectory() ) {
- return new ExplodedJarVisitor( jarUrl, filters, entry );
- }
- else {
- return new FileZippedJarVisitor( jarUrl, filters, entry );
- }
+ return fileName;
+ }
+
+ public static byte[] getBytesFromInputStreamSafely(InputStream inputStream) {
+ try {
+ return getBytesFromInputStream( inputStream );
}
- else {
- //let's assume the url can return the jar as a zip stream
- return new InputStreamZippedJarVisitor( jarUrl, filters, entry );
+ catch (IOException e) {
+ throw new ArchiveException( "Unable to extract bytes from InputStream", e );
}
}
- // Optimized by HHH-7835
public static byte[] getBytesFromInputStream(InputStream inputStream) throws IOException {
+ // Optimized by HHH-7835
int size;
List<byte[]> data = new LinkedList<byte[]>();
int bufferSize = 4096;
Oops, something went wrong.

0 comments on commit eeca844

Please sign in to comment.