Author: epbernard
Date: 2007-07-02 08:33:46 -0400 (Mon, 02 Jul 2007)
New Revision: 12660
Removed:
trunk/HibernateExt/entitymanager/lib/jboss-archive-browsing.jar
Modified:
trunk/HibernateExt/entitymanager/lib/README.txt
trunk/HibernateExt/entitymanager/src/java/org/hibernate/ejb/Ejb3Configuration.java
trunk/HibernateExt/entitymanager/src/java/org/hibernate/ejb/packaging/JarVisitor.java
Log:
EJB-302 get rid of JBoss Archive Browser
Modified: trunk/HibernateExt/entitymanager/lib/README.txt
===================================================================
--- trunk/HibernateExt/entitymanager/lib/README.txt 2007-06-30 04:37:28 UTC (rev 12659)
+++ trunk/HibernateExt/entitymanager/lib/README.txt 2007-07-02 12:33:46 UTC (rev 12660)
@@ -11,7 +11,6 @@
hibernate3.jar: required
hibernate core dependencies: required (see Hibernate Core for more information)
javassist.jar: required (part of Hibernate Core dependencies)
-jboss-archive-browsing (jboss-common-core 2.0.2.Alpha): required
Test
Deleted: trunk/HibernateExt/entitymanager/lib/jboss-archive-browsing.jar
===================================================================
(Binary files differ)
Modified:
trunk/HibernateExt/entitymanager/src/java/org/hibernate/ejb/Ejb3Configuration.java
===================================================================
---
trunk/HibernateExt/entitymanager/src/java/org/hibernate/ejb/Ejb3Configuration.java 2007-06-30
04:37:28 UTC (rev 12659)
+++
trunk/HibernateExt/entitymanager/src/java/org/hibernate/ejb/Ejb3Configuration.java 2007-07-02
12:33:46 UTC (rev 12660)
@@ -3,7 +3,6 @@
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -36,8 +35,6 @@
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.sql.DataSource;
-import javassist.bytecode.AnnotationsAttribute;
-import javassist.bytecode.ClassFile;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.DocumentException;
@@ -54,12 +51,13 @@
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.cfg.Settings;
import org.hibernate.cfg.SettingsFactory;
+import org.hibernate.cfg.annotations.reflection.XMLContext;
import org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider;
import org.hibernate.ejb.instrument.InterceptFieldClassFileTransformer;
import org.hibernate.ejb.packaging.JarVisitor;
+import org.hibernate.ejb.packaging.NamedInputStream;
import org.hibernate.ejb.packaging.PersistenceMetadata;
import org.hibernate.ejb.packaging.PersistenceXmlLoader;
-import org.hibernate.ejb.packaging.NamedInputStream;
import org.hibernate.ejb.transaction.JoinableCMTTransactionFactory;
import org.hibernate.ejb.util.ConfigurationHelper;
import org.hibernate.ejb.util.LogHelper;
@@ -69,14 +67,12 @@
import org.hibernate.mapping.AuxiliaryDatabaseObject;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.proxy.EntityNotFoundDelegate;
-import org.hibernate.cfg.annotations.reflection.XMLContext;
import org.hibernate.secure.JACCConfiguration;
import org.hibernate.transaction.JDBCTransactionFactory;
import org.hibernate.util.CollectionHelper;
import org.hibernate.util.ReflectHelper;
import org.hibernate.util.StringHelper;
import org.hibernate.util.XMLHelper;
-import org.jboss.util.file.ArchiveBrowser;
import org.xml.sax.EntityResolver;
import org.xml.sax.SAXException;
@@ -211,7 +207,7 @@
}
while ( xmls.hasMoreElements() ) {
URL url = xmls.nextElement();
- log.trace( "Analyse of persistence.xml: " + url );
+ log.trace( "Analysing persistence.xml: " + url );
List<PersistenceMetadata> metadataFiles = PersistenceXmlLoader.deploy(
url,
integration,
@@ -263,23 +259,25 @@
private JarVisitor getMainJarVisitor(URL url, PersistenceMetadata metadata, Map
integration) {
URL jarURL = JarVisitor.getJarURLFromURLEntry( url,
"/META-INF/persistence.xml" );
JarVisitor.Filter[] persistenceXmlFilter = getFilters( metadata, integration,
metadata.getExcludeUnlistedClasses() );
- JarVisitor visitor = JarVisitor.getVisitor( jarURL, persistenceXmlFilter );
- return visitor;
+ return JarVisitor.getVisitor( jarURL, persistenceXmlFilter );
}
private static void addMetadataFromVisitor(JarVisitor visitor, PersistenceMetadata
metadata) throws IOException {
- Set[] entries = visitor.getMatchingEntries();
- JarVisitor.Filter[] filters = visitor.getFilters();
- int size = filters.length;
List<String> classes = metadata.getClasses();
List<String> packages = metadata.getPackages();
List<NamedInputStream> hbmFiles = metadata.getHbmfiles();
+ List<String> mappingFiles = metadata.getMappingFiles();
+ addScannedEntries( visitor, classes, packages, hbmFiles, mappingFiles );
+ }
+
+ private static void addScannedEntries(JarVisitor visitor, List<String> classes,
List<String> packages, List<NamedInputStream> hbmFiles, List<String>
mappingFiles) throws IOException {
+ JarVisitor.Filter[] filters = visitor.getFilters();
+ Set[] entries = visitor.getMatchingEntries();
+ int size = filters.length;
for ( int index = 0; index < size ; index++ ) {
- Iterator homogeneousEntry = entries[index].iterator();
- while ( homogeneousEntry.hasNext() ) {
- JarVisitor.Entry entry = (JarVisitor.Entry) homogeneousEntry.next();
+ for (Object o : entries[index]) {
+ JarVisitor.Entry entry = (JarVisitor.Entry) o;
if ( filters[index] instanceof JarVisitor.ClassFilter ) {
- //TODO only add entry if there is annotations (Javassist)
classes.add( entry.getName() );
}
else if ( filters[index] instanceof JarVisitor.PackageFilter ) {
@@ -287,7 +285,7 @@
}
else if ( filters[index] instanceof JarVisitor.FileFilter ) {
hbmFiles.add( new NamedInputStream( entry.getName(), entry.getInputStream() ) );
- metadata.getMappingFiles().remove( entry.getName() );
+ if (mappingFiles != null) mappingFiles.remove( entry.getName() );
}
}
}
@@ -344,11 +342,9 @@
boolean[] detectArtifactForOtherJars = getDetectedArtifacts( info.getProperties(),
null, false );
boolean[] detectArtifactForMainJar = getDetectedArtifacts( info.getProperties(), null,
info.excludeUnlistedClasses() );
for ( URL jar : info.getJarFileUrls() ) {
- if ( detectArtifactForOtherJars[0] ) scanForClasses( jar, packages, entities );
- scanForXmlFiles( jar, hbmFiles, XML_SEARCH.getType( detectArtifactForOtherJars[1],
searchForORMFiles ) );
+ scanForClasses( jar, packages, entities, hbmFiles, detectArtifactForOtherJars,
searchForORMFiles );
}
- if ( detectArtifactForMainJar[0] ) scanForClasses( info.getPersistenceUnitRootUrl(),
packages, entities );
- scanForXmlFiles( info.getPersistenceUnitRootUrl(), hbmFiles, XML_SEARCH.getType(
detectArtifactForMainJar[1], searchForORMFiles ) );
+ scanForClasses( info.getPersistenceUnitRootUrl(), packages, entities, hbmFiles,
detectArtifactForMainJar, searchForORMFiles );
Properties properties = info.getProperties() != null ?
info.getProperties() :
@@ -557,11 +553,16 @@
private JarVisitor.Filter[] getFilters(PersistenceMetadata metadata, Map
overridenProperties, boolean excludeIfNotOverriden) {
Properties properties = metadata.getProps();
final List<String> mappingFiles = metadata.getMappingFiles();
- boolean[] result = getDetectedArtifacts( properties, overridenProperties,
excludeIfNotOverriden );
+ boolean[] detectedArtifacts = getDetectedArtifacts( properties, overridenProperties,
excludeIfNotOverriden );
- int size = ( result[0] ? 2 : 0 ) + 1; //class involves classes and packages, xml files
are always involved because of orm.xml
+ return getFilters( detectedArtifacts, true, mappingFiles );
+ }
+
+ private JarVisitor.Filter[] getFilters(final boolean[] detectedArtifacts, final boolean
searchORM, final List<String> mappingFiles) {
+ final int mappingFilesSize = mappingFiles != null ? mappingFiles.size() : 0;
+ int size = ( detectedArtifacts[0] ? 2 : 0 ) + ( (searchORM || detectedArtifacts[1] ||
mappingFilesSize > 0 ) ? 1 : 0);
JarVisitor.Filter[] filters = new JarVisitor.Filter[size];
- if ( result[0] ) {
+ if ( detectedArtifacts[0] ) {
filters[0] = new JarVisitor.PackageFilter( false, null ) {
public boolean accept(String javaElementName) {
return true;
@@ -578,107 +579,32 @@
}
};
}
- if ( result[1] ) {
+ if ( detectedArtifacts[1] || searchORM || mappingFilesSize > 0) {
filters[size - 1] = new JarVisitor.FileFilter( true ) {
public boolean accept(String javaElementName) {
- return javaElementName.endsWith( "hbm.xml" )
- || javaElementName.endsWith( META_INF_ORM_XML )
- || mappingFiles.contains( javaElementName );
+ return ( detectedArtifacts[1] && javaElementName.endsWith(
"hbm.xml" ) )
+ || ( searchORM && javaElementName.endsWith( META_INF_ORM_XML ) )
+ || ( mappingFilesSize > 0 && mappingFiles.contains( javaElementName )
);
}
};
}
- else {
- filters[size - 1] = new JarVisitor.FileFilter( true ) {
- public boolean accept(String javaElementName) {
- return javaElementName.endsWith( META_INF_ORM_XML )
- || mappingFiles.contains( javaElementName );
- }
- };
- }
return filters;
}
- private void scanForXmlFiles(URL jar, List<NamedInputStream> hbmxmls, final
XML_SEARCH searchType) {
- if (searchType == XML_SEARCH.NONE) return;
- if (jar == null) log.error( "Container is providing a null PersistenceUnitRootUrl:
discovery impossible");
- final boolean searchforORMFiles = searchType == XML_SEARCH.BOTH || searchType ==
XML_SEARCH.ORM_XML;
- final boolean searchforHBMFiles = searchType == XML_SEARCH.BOTH || searchType ==
XML_SEARCH.HBM;
- Iterator it = ArchiveBrowser.getBrowser(
- jar, new ArchiveBrowser.Filter() {
- public boolean accept(String filename) {
- return (searchforHBMFiles && filename.endsWith( ".hbm.xml" ) )
- || (searchforORMFiles && filename.endsWith( META_INF_ORM_XML ) )
- ;
- }
+ private void scanForClasses(URL jar, List<String> packages, List<String>
entities, List<NamedInputStream> hbmFiles, boolean[] detectedArtifacts, boolean
searchORM) {
+ if (jar == null) {
+ log.error( "Container is providing a null PersistenceUnitRootUrl: discovery
impossible");
+ return;
}
- );
-
- while ( it.hasNext() ) {
- InputStream stream = (InputStream) it.next();
- hbmxmls.add( new NamedInputStream("", stream) );
- }
- }
-
- private void scanForClasses(URL jar, List<String> packages, List<String>
entities) {
- if (jar == null) log.error( "Container is providing a null PersistenceUnitRootUrl:
discovery impossible");
- Iterator it = null;
try {
- it = ArchiveBrowser.getBrowser(
- jar, new ArchiveBrowser.Filter() {
- public boolean accept(String filename) {
- return filename.endsWith( ".class" );
- }
- }
- );
+ JarVisitor visitor = JarVisitor.getVisitor( jar, getFilters( detectedArtifacts,
searchORM, null ) );
+ addScannedEntries( visitor, entities, packages, hbmFiles, null );
}
catch (RuntimeException e) {
throw new RuntimeException( "error trying to scan <jar-file>: " +
jar.toString(), e );
}
-
- // need to look into every entry in the archive to see if anybody has tags
- // defined.
- while ( it.hasNext() ) {
- InputStream stream = (InputStream) it.next();
- DataInputStream dstream = new DataInputStream( new BufferedInputStream( stream ) );
- ClassFile cf = null;
- try {
- try {
- cf = new ClassFile( dstream );
- }
- finally {
- dstream.close();
- stream.close();
- }
- }
- catch (IOException e) {
- throw new RuntimeException( e );
- }
- if ( cf.getName().endsWith( ".package-info" ) ) {
- int idx = cf.getName().indexOf( ".package-info" );
- String pkgName = cf.getName().substring( 0, idx );
- log.info( "found package: " + pkgName );
- packages.add( pkgName );
- continue;
- }
-
- AnnotationsAttribute visible = (AnnotationsAttribute) cf.getAttribute(
AnnotationsAttribute.visibleTag );
- if ( visible != null ) {
- boolean isEntity = visible.getAnnotation( Entity.class.getName() ) != null;
- if ( isEntity ) {
- log.info( "found EJB3 Entity bean: " + cf.getName() );
- entities.add( cf.getName() );
- }
- boolean isEmbeddable = visible.getAnnotation( Embeddable.class.getName() ) != null;
- if ( isEmbeddable ) {
- log.info( "found EJB3 @Embeddable: " + cf.getName() );
- entities.add( cf.getName() );
- }
- boolean isEmbeddableSuperclass = visible.getAnnotation(
MappedSuperclass.class.getName() ) != null;
- if ( isEmbeddableSuperclass ) {
- log.info( "found EJB3 @MappedSuperclass: " + cf.getName() );
- entities.add( cf.getName() );
- }
- }
+ catch( IOException e ) {
+ throw new RuntimeException( "Error while reading " + jar.toString(), e );
}
}
Modified:
trunk/HibernateExt/entitymanager/src/java/org/hibernate/ejb/packaging/JarVisitor.java
===================================================================
---
trunk/HibernateExt/entitymanager/src/java/org/hibernate/ejb/packaging/JarVisitor.java 2007-06-30
04:37:28 UTC (rev 12659)
+++
trunk/HibernateExt/entitymanager/src/java/org/hibernate/ejb/packaging/JarVisitor.java 2007-07-02
12:33:46 UTC (rev 12660)
@@ -41,8 +41,8 @@
/**
* Get the JAR URL of the JAR containing the given entry
*
- * @param url
- * @param entry
+ * @param url URL pointing to the known file in the JAR
+ * @param entry file known to be in the JAR
* @return the JAR URL
* @throws IllegalArgumentException if none URL is found
*/
@@ -100,7 +100,6 @@
public static final JarVisitor getVisitor(URL jarUrl, Filter[] filters) throws
IllegalArgumentException {
String protocol = jarUrl.getProtocol();
if ( "jar".equals( protocol ) ) {
- //FIXME remove this code, this should not happen
return new InputStreamZippedJarVisitor( jarUrl, filters );
}
else if ( StringHelper.isEmpty( protocol ) || "file".equals( protocol ) ) {
@@ -110,7 +109,7 @@
}
catch (URISyntaxException e) {
throw new IllegalArgumentException(
- "Unable to visit JAR " + jarUrl + ". Cause: " + e.getMessage()
+ "Unable to visit JAR " + jarUrl + ". Cause: " + e.getMessage(),
e
);
}
if ( file.isDirectory() ) {