HHH-7514 - Upgrade to Jandex 1.1

This commit is contained in:
Steve Ebersole 2012-08-22 13:41:16 -05:00
parent 4282e23caa
commit fd8a45b2b2
6 changed files with 108 additions and 324 deletions

View File

@ -1,6 +1,7 @@
apply plugin: 'eclipse' apply plugin: 'eclipse'
apply plugin: 'idea' apply plugin: 'idea'
apply from: "./libraries.gradle" apply from: "./libraries.gradle"
allprojects { allprojects {
repositories { repositories {
mavenCentral() mavenCentral()

View File

@ -56,19 +56,20 @@ idea {
task jaxb { task jaxb {
ext { ext {
// output directory // output directory
jaxbTargetDir = file( "${buildDir}/generated-src/jaxb/main" ) jaxbTargetDir = file( "${buildDir}/generated-src/jaxb/main" )
// input schemas // input schemas
cfgXsd = file( 'src/main/resources/org/hibernate/hibernate-configuration-4.0.xsd') cfgXsd = file( 'src/main/resources/org/hibernate/hibernate-configuration-4.0.xsd')
hbmXsd = file( 'src/main/resources/org/hibernate/hibernate-mapping-4.0.xsd' ) hbmXsd = file( 'src/main/resources/org/hibernate/hibernate-mapping-4.0.xsd' )
ormXsd = file( 'src/main/resources/org/hibernate/ejb/orm_2_0.xsd' ) ormXsd = file( 'src/main/resources/org/hibernate/ejb/orm_2_0.xsd' )
// input bindings
cfgXjb = file( 'src/main/xjb/hbm-configuration-bindings.xjb' )
hbmXjb = file( 'src/main/xjb/hbm-mapping-bindings.xjb' )
ormXjb = file( 'src/main/xjb/orm-bindings.xjb' )
}
// input bindings
cfgXjb = file( 'src/main/xjb/hbm-configuration-bindings.xjb' )
hbmXjb = file( 'src/main/xjb/hbm-mapping-bindings.xjb' )
ormXjb = file( 'src/main/xjb/orm-bindings.xjb' )
}
// configure Gradle up-to-date checking // configure Gradle up-to-date checking
inputs.files( [cfgXsd, hbmXsd, ormXsd, cfgXjb, hbmXjb, ormXjb] ) inputs.files( [cfgXsd, hbmXsd, ormXsd, cfgXjb, hbmXjb, ormXjb] )
outputs.dir( jaxbTargetDir ) outputs.dir( jaxbTargetDir )

View File

@ -1,186 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 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.jboss.jandex;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* Aggregates information from multiple {@link Index} instances.
*
* @author John Bailey
* @author Steve Ebersole
*/
public class CompositeIndex implements IndexResult {
private final List<Index> indexes;
public CompositeIndex(Index... indexes) {
this( Arrays.asList( indexes ) );
}
public CompositeIndex(List<Index> indexes) {
this.indexes = indexes;
}
@Override
public Collection<AnnotationInstance> getAnnotations(DotName annotationName) {
final Set<AnnotationInstance> allInstances = new HashSet<AnnotationInstance>();
for (Index index : indexes) {
copy( index.getAnnotations( annotationName ), allInstances );
}
return Collections.unmodifiableSet( allInstances );
}
private <T> void copy(Collection<T> source, Collection<T> target) {
if ( source != null ) {
target.addAll( source );
}
}
@Override
public Collection<ClassInfo> getKnownClasses() {
final List<ClassInfo> allKnown = new ArrayList<ClassInfo>();
for ( Index index : indexes ) {
copy( index.getKnownClasses(), allKnown );
}
return Collections.unmodifiableCollection( allKnown );
}
@Override
public ClassInfo getClassByName(DotName className) {
for ( Index index : indexes ) {
final ClassInfo info = index.getClassByName( className );
if ( info != null ) {
return info;
}
}
return null;
}
@Override
public Collection<ClassInfo> getKnownDirectSubclasses(DotName className) {
final Set<ClassInfo> allKnown = new HashSet<ClassInfo>();
for ( Index index : indexes ) {
copy( index.getKnownDirectSubclasses( className ), allKnown );
}
return Collections.unmodifiableSet( allKnown );
}
@Override
public Set<ClassInfo> getAllKnownSubclasses(final DotName className) {
final Set<ClassInfo> allKnown = new HashSet<ClassInfo>();
final Set<DotName> processedClasses = new HashSet<DotName>();
getAllKnownSubClasses(className, allKnown, processedClasses);
return allKnown;
}
private void getAllKnownSubClasses(DotName className, Set<ClassInfo> allKnown, Set<DotName> processedClasses) {
final Set<DotName> subClassesToProcess = new HashSet<DotName>();
subClassesToProcess.add(className);
while (!subClassesToProcess.isEmpty()) {
final Iterator<DotName> toProcess = subClassesToProcess.iterator();
DotName name = toProcess.next();
toProcess.remove();
processedClasses.add(name);
getAllKnownSubClasses(name, allKnown, subClassesToProcess, processedClasses);
}
}
private void getAllKnownSubClasses(
DotName name,
Set<ClassInfo> allKnown,
Set<DotName> subClassesToProcess,
Set<DotName> processedClasses) {
for ( Index index : indexes ) {
final Collection<ClassInfo> list = index.getKnownDirectSubclasses( name );
if ( list != null ) {
for ( final ClassInfo clazz : list ) {
final DotName className = clazz.name();
if ( !processedClasses.contains( className ) ) {
allKnown.add( clazz );
subClassesToProcess.add( className );
}
}
}
}
}
@Override
public Collection<ClassInfo> getKnownDirectImplementors(DotName className) {
final Set<ClassInfo> allKnown = new HashSet<ClassInfo>();
for ( Index index : indexes ) {
copy( index.getKnownDirectImplementors( className ), allKnown );
}
return Collections.unmodifiableSet(allKnown); }
@Override
public Collection<ClassInfo> getAllKnownImplementors(DotName interfaceName) {
final Set<ClassInfo> allKnown = new HashSet<ClassInfo>();
final Set<DotName> subInterfacesToProcess = new HashSet<DotName>();
final Set<DotName> processedClasses = new HashSet<DotName>();
subInterfacesToProcess.add( interfaceName );
while ( !subInterfacesToProcess.isEmpty() ) {
final Iterator<DotName> toProcess = subInterfacesToProcess.iterator();
DotName name = toProcess.next();
toProcess.remove();
processedClasses.add( name );
getKnownImplementors( name, allKnown, subInterfacesToProcess, processedClasses );
}
return allKnown;
}
private void getKnownImplementors(
DotName name,
Set<ClassInfo> allKnown,
Set<DotName> subInterfacesToProcess,
Set<DotName> processedClasses) {
for (Index index : indexes) {
final List<ClassInfo> list = index.getKnownDirectImplementors(name);
if (list != null) {
for (final ClassInfo clazz : list) {
final DotName className = clazz.name();
if (!processedClasses.contains(className)) {
if ( Modifier.isInterface( clazz.flags() )) {
subInterfacesToProcess.add(className);
}
else {
if (!allKnown.contains(clazz)) {
allKnown.add(clazz);
processedClasses.add(className);
getAllKnownSubClasses(className, allKnown, processedClasses);
}
}
}
}
}
}
}
}

View File

@ -1,56 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 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.jboss.jandex;
import java.util.Collection;
/**
* The basic contract for accessing Jandex indexed information.
*
* @author Jason Greene
* @author Steve Ebersole
*/
public interface IndexResult {
public Collection<ClassInfo> getKnownClasses();
public ClassInfo getClassByName(DotName className);
public Collection<ClassInfo> getKnownDirectSubclasses(DotName className);
/**
* Returns all known (including non-direct) sub classes of the given class. I.e., returns all known classes
* that are assignable to the given class.
*
* @param className The class
*
* @return All known subclasses
*/
public Collection<ClassInfo> getAllKnownSubclasses(final DotName className);
public Collection<ClassInfo> getKnownDirectImplementors(DotName className);
public Collection<ClassInfo> getAllKnownImplementors(final DotName interfaceName);
public Collection<AnnotationInstance> getAnnotations(DotName annotationName);
}

View File

@ -56,7 +56,7 @@ import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.CompositeIndex; import org.jboss.jandex.CompositeIndex;
import org.jboss.jandex.DotName; import org.jboss.jandex.DotName;
import org.jboss.jandex.Index; import org.jboss.jandex.Index;
import org.jboss.jandex.IndexResult; import org.jboss.jandex.IndexView;
import org.jboss.jandex.Indexer; import org.jboss.jandex.Indexer;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -183,7 +183,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
ScanResult scanResult = scan( bootstrapServiceRegistry ); ScanResult scanResult = scan( bootstrapServiceRegistry );
// 2) building a Jandex index // 2) building a Jandex index
Set<String> collectedManagedClassNames = collectManagedClassNames( scanResult ); Set<String> collectedManagedClassNames = collectManagedClassNames( scanResult );
IndexResult jandexIndex = locateOrBuildJandexIndex( collectedManagedClassNames, scanResult.getPackageNames(), bootstrapServiceRegistry ); IndexView jandexIndex = locateOrBuildJandexIndex( collectedManagedClassNames, scanResult.getPackageNames(), bootstrapServiceRegistry );
// 3) building "metadata sources" to keep for later to use in building the SessionFactory // 3) building "metadata sources" to keep for later to use in building the SessionFactory
metadataSources = prepareMetadataSources( jandexIndex, collectedManagedClassNames, scanResult, bootstrapServiceRegistry ); metadataSources = prepareMetadataSources( jandexIndex, collectedManagedClassNames, scanResult, bootstrapServiceRegistry );
@ -210,7 +210,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private MetadataSources prepareMetadataSources( private MetadataSources prepareMetadataSources(
IndexResult jandexIndex, IndexView jandexIndex,
Set<String> collectedManagedClassNames, Set<String> collectedManagedClassNames,
ScanResult scanResult, ScanResult scanResult,
BootstrapServiceRegistry bootstrapServiceRegistry) { BootstrapServiceRegistry bootstrapServiceRegistry) {
@ -270,7 +270,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
return collectedNames; return collectedNames;
} }
private IndexResult locateOrBuildJandexIndex( private IndexView locateOrBuildJandexIndex(
Set<String> collectedManagedClassNames, Set<String> collectedManagedClassNames,
List<String> packageNames, List<String> packageNames,
BootstrapServiceRegistry bootstrapServiceRegistry) { BootstrapServiceRegistry bootstrapServiceRegistry) {
@ -279,14 +279,14 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
// 2) pass that Index along to the metamodel code... // 2) pass that Index along to the metamodel code...
// //
// (1) is mocked up here, but JBoss AS does not currently pass in any Index to use... // (1) is mocked up here, but JBoss AS does not currently pass in any Index to use...
IndexResult jandexIndex = (IndexResult) configurationValues.get( JANDEX_INDEX ); IndexView jandexIndex = (IndexView) configurationValues.get( JANDEX_INDEX );
if ( jandexIndex == null ) { if ( jandexIndex == null ) {
jandexIndex = buildJandexIndex( collectedManagedClassNames, packageNames, bootstrapServiceRegistry ); jandexIndex = buildJandexIndex( collectedManagedClassNames, packageNames, bootstrapServiceRegistry );
} }
return jandexIndex; return jandexIndex;
} }
private IndexResult buildJandexIndex(Set<String> classNamesSource, List<String> packageNames, BootstrapServiceRegistry bootstrapServiceRegistry) { private IndexView buildJandexIndex(Set<String> classNamesSource, List<String> packageNames, BootstrapServiceRegistry bootstrapServiceRegistry) {
Indexer indexer = new Indexer(); Indexer indexer = new Indexer();
for ( String className : classNamesSource ) { for ( String className : classNamesSource ) {

View File

@ -1,84 +1,108 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 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
*/
// build a map of the dependency artifacts to use. Allows centralized definition of the version of artifacts to // build a map of the dependency artifacts to use. Allows centralized definition of the version of artifacts to
// use. In that respect it serves a role similar to <dependencyManagement> in Maven // use. In that respect it serves a role similar to <dependencyManagement> in Maven
ext { ext {
slf4jVersion = '1.6.1'
junitVersion = '4.10'
h2Version = '1.2.145'
bytemanVersion = '1.5.2'
infinispanVersion = '5.1.6.FINAL'
jnpVersion = '5.0.6.CR1'
libraries = [ slf4jVersion = '1.6.1'
// Ant junitVersion = '4.10'
ant: 'org.apache.ant:ant:1.8.2', h2Version = '1.2.145'
bytemanVersion = '1.5.2'
infinispanVersion = '5.1.6.FINAL'
jnpVersion = '5.0.6.CR1'
// Antlr libraries = [
antlr: 'antlr:antlr:2.7.7', // Ant
ant: 'org.apache.ant:ant:1.8.2',
// Annotations // Antlr
commons_annotations: antlr: 'antlr:antlr:2.7.7',
'org.hibernate.common:hibernate-commons-annotations:4.0.1.Final@jar',
jandex: 'org.jboss:jandex:1.0.3.Final',
classmate: 'com.fasterxml:classmate:0.5.4',
// Dom4J // Annotations
dom4j: 'dom4j:dom4j:1.6.1@jar', commons_annotations:
'org.hibernate.common:hibernate-commons-annotations:4.0.1.Final@jar',
jandex: 'org.jboss:jandex:1.1.0.Alpha1',
classmate: 'com.fasterxml:classmate:0.5.4',
// Javassist // Dom4J
javassist: 'org.javassist:javassist:3.15.0-GA', dom4j: 'dom4j:dom4j:1.6.1@jar',
// javax // Javassist
jpa: 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Draft-7plus', javassist: 'org.javassist:javassist:3.15.0-GA',
jta: 'org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:1.0.0.Final',
validation: 'javax.validation:validation-api:1.0.0.GA',
jacc: 'org.jboss.spec.javax.security.jacc:jboss-jacc-api_1.4_spec:1.0.0.Final',
// logging // javax
logging: 'org.jboss.logging:jboss-logging:3.1.0.GA', jpa: 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Draft-7plus',
logging_processor: 'org.jboss.logging:jboss-logging-processor:1.0.0.Final', jta: 'org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:1.0.0.Final',
validation: 'javax.validation:validation-api:1.0.0.GA',
jacc: 'org.jboss.spec.javax.security.jacc:jboss-jacc-api_1.4_spec:1.0.0.Final',
// jaxb task // logging
jaxb: 'com.sun.xml.bind:jaxb-xjc:2.1.6', logging: 'org.jboss.logging:jboss-logging:3.1.0.GA',
jaxb2_basics: 'org.jvnet.jaxb2_commons:jaxb2-basics:0.6.0', logging_processor: 'org.jboss.logging:jboss-logging-processor:1.0.0.Final',
jaxb2_ant: 'org.jvnet.jaxb2_commons:jaxb2-basics-ant:0.6.0',
// ~~~~~~~~~~~~~~~~~~~~~~~~~~ testing
// logging for testing // jaxb task
slf4j_api: "org.slf4j:slf4j-api:${slf4jVersion}", jaxb: 'com.sun.xml.bind:jaxb-xjc:2.1.6',
slf4j_log4j12: "org.slf4j:slf4j-log4j12:${slf4jVersion}", jaxb2_basics: 'org.jvnet.jaxb2_commons:jaxb2-basics:0.6.0',
jcl_slf4j: "org.slf4j:jcl-over-slf4j:${slf4jVersion}", jaxb2_ant: 'org.jvnet.jaxb2_commons:jaxb2-basics-ant:0.6.0',
jcl_api: 'commons-logging:commons-logging-api:99.0-does-not-exist', // ~~~~~~~~~~~~~~~~~~~~~~~~~~ testing
jcl: 'commons-logging:commons-logging:99.0-does-not-exist',
// logging for testing
slf4j_api: "org.slf4j:slf4j-api:${slf4jVersion}",
slf4j_log4j12: "org.slf4j:slf4j-log4j12:${slf4jVersion}",
jcl_slf4j: "org.slf4j:jcl-over-slf4j:${slf4jVersion}",
jcl_api: 'commons-logging:commons-logging-api:99.0-does-not-exist',
jcl: 'commons-logging:commons-logging:99.0-does-not-exist',
junit: "junit:junit:${junitVersion}", junit: "junit:junit:${junitVersion}",
byteman: "org.jboss.byteman:byteman:${bytemanVersion}", byteman: "org.jboss.byteman:byteman:${bytemanVersion}",
byteman_install: "org.jboss.byteman:byteman-install:${bytemanVersion}", byteman_install: "org.jboss.byteman:byteman-install:${bytemanVersion}",
byteman_bmunit: "org.jboss.byteman:byteman-bmunit:${bytemanVersion}", byteman_bmunit: "org.jboss.byteman:byteman-bmunit:${bytemanVersion}",
jpa_modelgen: 'org.hibernate:hibernate-jpamodelgen:1.1.1.Final', jpa_modelgen: 'org.hibernate:hibernate-jpamodelgen:1.1.1.Final',
shrinkwrap_api: 'org.jboss.shrinkwrap:shrinkwrap-api:1.0.0-beta-6', shrinkwrap_api: 'org.jboss.shrinkwrap:shrinkwrap-api:1.0.0-beta-6',
shrinkwrap: 'org.jboss.shrinkwrap:shrinkwrap-impl-base:1.0.0-beta-6', shrinkwrap: 'org.jboss.shrinkwrap:shrinkwrap-impl-base:1.0.0-beta-6',
validator: 'org.hibernate:hibernate-validator:4.2.0.Final', validator: 'org.hibernate:hibernate-validator:4.2.0.Final',
h2: "com.h2database:h2:${h2Version}", h2: "com.h2database:h2:${h2Version}",
jboss_jta: "org.jboss.jbossts:jbossjta:4.16.4.Final", jboss_jta: "org.jboss.jbossts:jbossjta:4.16.4.Final",
xapool: "com.experlog:xapool:1.5.0", xapool: "com.experlog:xapool:1.5.0",
mockito: 'org.mockito:mockito-core:1.9.0', mockito: 'org.mockito:mockito-core:1.9.0',
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ infinsipan
infinispan: "org.infinispan:infinispan-core:${infinispanVersion}",
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ infinispan test
infinispan_test: "org.infinispan:infinispan-core:${infinispanVersion}:tests@jar",
rhq: "org.rhq.helpers:rhq-pluginAnnotations:3.0.4",
jboss_common_core: "org.jboss:jboss-common-core:2.2.16.GA@jar",
jnp_client: "org.jboss.naming:jnp-client:${jnpVersion}",
jnp_server: "org.jboss.naming:jnpserver:${jnpVersion}",
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ c3p0 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ infinsipan
c3p0: "c3p0:c3p0:0.9.1", infinispan: "org.infinispan:infinispan-core:${infinispanVersion}",
ehcache: "net.sf.ehcache:ehcache-core:2.4.3", // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ infinispan test
proxool: "proxool:proxool:0.8.3", infinispan_test: "org.infinispan:infinispan-core:${infinispanVersion}:tests@jar",
rhq: "org.rhq.helpers:rhq-pluginAnnotations:3.0.4",
jboss_common_core: "org.jboss:jboss-common-core:2.2.16.GA@jar",
jnp_client: "org.jboss.naming:jnp-client:${jnpVersion}",
jnp_server: "org.jboss.naming:jnpserver:${jnpVersion}",
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ c3p0
c3p0: "c3p0:c3p0:0.9.1",
ehcache: "net.sf.ehcache:ehcache-core:2.4.3",
proxool: "proxool:proxool:0.8.3",
] ]
} }