Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

scan Entities in multi jars. #35

Open
wants to merge 2 commits into from

2 participants

@hydra1983

Scan entities in multi jars when run hbm2ddl
A "basePackage" property must be set to search entities under the speicified package

<project default="build">
    <path id="toolslib">
        <fileset dir="toolslib">
            <include name="*.jar"/>
        </fileset>
        <pathelement path="D:\.opensource\hibernate-tools\git\target\hibernate-tools-3.6.0.CR1.jar"/> 
    </path>

    <taskdef name="hibernatetool"
        classname="org.hibernate.tool.ant.HibernateToolTask"
        classpathref="toolslib" />

    <target name="build">
        <hibernatetool destdir=".">
            <classpath>
                <path location="src"/>
            </classpath>
            <jpaconfiguration persistenceunit="default"
                propertyFile="toolslib/hibernate.properties" basePackage="com.wds.toolsuite"/>
            <hbm2ddl export="false" outputfilename="test-schema.sql"
                format="true" console="false"/>
        </hibernatetool>
    </target>
</project>
@maxandersen
Owner

sorry for not responding earlier but i'm not following what it is you are trying to here. Got an example of what is not working ?

Plus - the fix seem to change many other things (Formatting, dependencies,etc) that seems unrelated. Any chance you can rebase it and clean it up ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 25, 2012
  1. @hydra1983

    scan Entities in multi jars.

    hydra1983 authored
  2. @hydra1983
This page is out of date. Refresh to see the latest.
View
BIN  lib/reflections-0.9.8-uberjar.jar
Binary file not shown
View
265 pom.xml
@@ -24,9 +24,9 @@
</issueManagement>
<scm>
- <connection>scm:git:git://github.com/hibernate/hibernate-tools.git</connection>
- <developerConnection>scm:git:git@github.com:hibernate/hibernate-tools.git</developerConnection>
- <url>http://github.com/hibernate/hibernate-tools</url>
+ <connection>scm:git:git://github.com/hibernate/hibernate-tools.git</connection>
+ <developerConnection>scm:git:git@github.com:hibernate/hibernate-tools.git</developerConnection>
+ <url>http://github.com/hibernate/hibernate-tools</url>
</scm>
<organization>
@@ -51,26 +51,25 @@
</developers>
<properties>
- <hibernateversion>3.6.9.Final</hibernateversion>
+ <hibernateversion>3.6.10.Final</hibernateversion>
<hibernateJpaversion>1.0.1.Final</hibernateJpaversion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <!-- Default settings for Database connection; to be overridden in db specific profiles -->
+ <!-- Default settings for Database connection; to be overridden in db specific
+ profiles -->
<db.dialect>org.hibernate.dialect.HSQLDialect</db.dialect>
<jdbc.driver>org.hsqldb.jdbcDriver</jdbc.driver>
<jdbc.url>jdbc:hsqldb:testdb/hsqldb;shutdown=true</jdbc.url>
<jdbc.user>sa</jdbc.user>
- <jdbc.pass/>
+ <jdbc.pass />
<jdbc.driver.groupId>hsqldb</jdbc.driver.groupId>
- <jdbc.driver.artifactId>hsqldb</jdbc.driver.artifactId>
- <jdbc.driver.jdbc.driver.version>1.8.0.2</jdbc.driver.jdbc.driver.version>
- <!-- End of settings for Database connection -->
+ <jdbc.driver.artifactId>hsqldb</jdbc.driver.artifactId>
+ <jdbc.driver.jdbc.driver.version>1.8.0.2</jdbc.driver.jdbc.driver.version>
+ <!-- End of settings for Database connection -->
</properties>
-
- <!--
- Graphviz should be installed for junit tests and it's bin dir should
- be in classpath
- -->
+
+ <!-- Graphviz should be installed for junit tests and it's bin dir should
+ be in classpath -->
<!-- TODO: is it possible to automate this with maven? -->
<dependencies>
@@ -78,55 +77,73 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernateversion}</version>
- <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernateversion}</version>
- <scope>compile</scope>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>${hibernateJpaversion}</version>
- <scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
- <scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1</version>
- <scope>compile</scope>
</dependency>
<dependency>
- <groupId>cglib</groupId>
- <artifactId>cglib</artifactId>
- <version>2.2</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>javassist</groupId>
- <artifactId>javassist</artifactId>
- <version>3.12.0.GA</version>
- <scope>compile</scope>
+ <groupId>cglib</groupId>
+ <artifactId>cglib</artifactId>
+ <version>2.2</version>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <version>3.12.0.GA</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
<version>1.6.5</version>
- <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>freemarker</groupId>
+ <artifactId>freemarker</artifactId>
+ <version>2.3.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>jtidy</artifactId>
+ <version>r8-20060801</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>org.eclipse.jdt.core</artifactId>
+ <version>3.8.0.v_C03</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse</groupId>
+ <artifactId>text</artifactId>
+ <version>3.2.0-v20060605-1400</version>
+ </dependency>
+ <dependency>
+ <groupId>org.reflections</groupId>
+ <artifactId>reflections</artifactId>
+ <version>0.9.8</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>ant</groupId>
@@ -141,29 +158,18 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>freemarker</groupId>
- <artifactId>freemarker</artifactId>
- <version>2.3.8</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>jtidy</artifactId>
- <version>r8-20060801</version>
- <scope>compile</scope>
+ <groupId>jaxen</groupId>
+ <artifactId>jaxen</artifactId>
+ <version>1.1</version>
+ <scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.eclipse.tycho</groupId>
- <artifactId>org.eclipse.jdt.core</artifactId>
- <version>3.8.0.v_C03</version>
- <scope>compile</scope>
- </dependency>
<dependency>
- <groupId>org.eclipse</groupId>
- <artifactId>text</artifactId>
- <version>3.2.0-v20060605-1400</version>
- <scope>compile</scope>
+ <groupId>${jdbc.driver.groupId}</groupId>
+ <artifactId>${jdbc.driver.artifactId}</artifactId>
+ <version>${jdbc.driver.jdbc.driver.version}</version>
+ <scope>test</scope>
</dependency>
+
<dependency>
<groupId>org.eclipse.core</groupId>
<artifactId>runtime</artifactId>
@@ -176,26 +182,6 @@
<version>3.2.0-v20060603</version>
<scope>runtime</scope>
</dependency>
- <dependency>
- <groupId>jaxen</groupId>
- <artifactId>jaxen</artifactId>
- <version>1.1</version>
- <scope>test</scope>
- </dependency>
- <!-- <dependency>
- <groupId>com.sun</groupId>
- <artifactId>tools</artifactId>
- <version>1.5.0_12</version>
- <scope>system</scope>
- <systemPath>${java.home}/../lib/tools.jar</systemPath>
- </dependency> -->
-
- <dependency>
- <groupId>${jdbc.driver.groupId}</groupId>
- <artifactId>${jdbc.driver.artifactId}</artifactId>
- <version>${jdbc.driver.jdbc.driver.version}</version>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
@@ -238,10 +224,10 @@
<exclude>org/hibernate/tool/test/jdbc2cfg/identity/SQLServerIdentityTest.java</exclude>
<!-- HSQLDB 1.8.0.2 does not support multiple schemas -->
<exclude>org/hibernate/tool/test/jdbc2cfg/TernarySchemaTest.java</exclude>
- </excludes>
+ </excludes>
<includes>
<include>**/*Test.java</include>
- </includes>
+ </includes>
</configuration>
</plugin>
<plugin>
@@ -274,7 +260,7 @@
<configuration>
<outputFile>
${project.build.directory}/test-classes/hibernate.properties
- </outputFile>
+ </outputFile>
</configuration>
</execution>
</executions>
@@ -292,7 +278,9 @@
<configuration>
<tasks>
<echo></echo>
- <copy file="${project.build.directory}/test-classes/hibernate.properties" tofile="${project.build.directory}/test-classes/log4j.properties" />
+ <copy
+ file="${project.build.directory}/test-classes/hibernate.properties"
+ tofile="${project.build.directory}/test-classes/log4j.properties" />
</tasks>
</configuration>
</execution>
@@ -358,15 +346,10 @@
<version>2.2</version>
<configuration>
<archive>
- <!-- <manifestEntries>
- <Implementation-Title>${project.name}</Implementation-Title>
- <Implementation-version>${project.version}</Implementation-version>
- <Implementation-Vendor>hibernate.org</Implementation-Vendor>
- <Implementation-Vendor-Id>hibernate.org
- </Implementation-Vendor-Id>
- <Implementation-URL>http://www.hibernate.org/subprojects/tools.html
- </Implementation-URL>
- </manifestEntries> -->
+ <!-- <manifestEntries> <Implementation-Title>${project.name}</Implementation-Title>
+ <Implementation-version>${project.version}</Implementation-version> <Implementation-Vendor>hibernate.org</Implementation-Vendor>
+ <Implementation-Vendor-Id>hibernate.org </Implementation-Vendor-Id> <Implementation-URL>http://www.hibernate.org/subprojects/tools.html
+ </Implementation-URL> </manifestEntries> -->
</archive>
</configuration>
</plugin>
@@ -390,7 +373,7 @@
</plugins>
<pluginManagement>
<plugins>
- <!--TODO TEXT. This plugin's configuration is used in m2e only.-->
+ <!--TODO TEXT. This plugin's configuration is used in m2e only. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
@@ -468,33 +451,30 @@
</build>
<repositories>
- <!--
- To build Hibernate Tools Core you have to add the JBoss Maven
- repository to your settings.xml See also
- http://community.jboss.org/wiki/ContributingtoHibernateSearch
- -->
+ <!-- To build Hibernate Tools Core you have to add the JBoss Maven repository
+ to your settings.xml See also http://community.jboss.org/wiki/ContributingtoHibernateSearch -->
</repositories>
<profiles>
-
+
<!-- =============================== -->
- <!-- Database profiles -->
+ <!-- Database profiles -->
<!-- =============================== -->
<!-- HSQLDB is the default -->
<profile>
<id>hsqldb</id>
- <properties>
- <db.dialect>org.hibernate.dialect.HSQLDialect</db.dialect>
- <jdbc.driver>org.hsqldb.jdbcDriver</jdbc.driver>
- <jdbc.url>jdbc:hsqldb:testdb/hsqldb;shutdown=true</jdbc.url>
- <jdbc.user>sa</jdbc.user>
- <jdbc.pass />
- <jdbc.driver.groupId>hsqldb</jdbc.driver.groupId>
- <jdbc.driver.artifactId>hsqldb</jdbc.driver.artifactId>
- <jdbc.driver.jdbc.driver.version>1.8.0.2</jdbc.driver.jdbc.driver.version>
+ <properties>
+ <db.dialect>org.hibernate.dialect.HSQLDialect</db.dialect>
+ <jdbc.driver>org.hsqldb.jdbcDriver</jdbc.driver>
+ <jdbc.url>jdbc:hsqldb:testdb/hsqldb;shutdown=true</jdbc.url>
+ <jdbc.user>sa</jdbc.user>
+ <jdbc.pass />
+ <jdbc.driver.groupId>hsqldb</jdbc.driver.groupId>
+ <jdbc.driver.artifactId>hsqldb</jdbc.driver.artifactId>
+ <jdbc.driver.jdbc.driver.version>1.8.0.2</jdbc.driver.jdbc.driver.version>
- </properties>
+ </properties>
</profile>
<profile>
@@ -511,18 +491,15 @@
<jdbc.isolation />
</properties>
</profile>
-
- <!--
- ###################################################################
- Profiles naming db instances in the Red Hat QA/QE lab First, those
- with OSS drivers
- ###################################################################
- -->
+
+ <!-- ###################################################################
+ Profiles naming db instances in the Red Hat QA/QE lab First, those with OSS
+ drivers ################################################################### -->
<!-- The MySQL 5 test envionment -->
<profile>
<id>mysql50</id>
- <properties>
+ <properties>
<jdbc.driver.groupId>mysql</jdbc.driver.groupId>
<jdbc.driver.artifactId>mysql-connector-java</jdbc.driver.artifactId>
<jdbc.driver.jdbc.driver.version>5.0.5</jdbc.driver.jdbc.driver.version>
@@ -555,13 +532,13 @@
<profile>
<id>mysql51-cluster</id>
<properties>
- <jdbc.driver.groupId>mysql</jdbc.driver.groupId>
- <jdbc.driver.artifactId>mysql-connector-java</jdbc.driver.artifactId>
- <jdbc.driver.jdbc.driver.version>5.1.8</jdbc.driver.jdbc.driver.version>
+ <jdbc.driver.groupId>mysql</jdbc.driver.groupId>
+ <jdbc.driver.artifactId>mysql-connector-java</jdbc.driver.artifactId>
+ <jdbc.driver.jdbc.driver.version>5.1.8</jdbc.driver.jdbc.driver.version>
<db.dialect>org.hibernate.dialect.MySQL5Dialect</db.dialect>
<jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
<jdbc.url>jdbc:mysql:loadbalance://dev61.qa.atl2.redhat.com:3306,dev62.qa.atl2.redhat.com:3306/hibbrtru
- </jdbc.url>
+ </jdbc.url>
<jdbc.user>hibbrtru</jdbc.user>
<jdbc.pass>hibbrtru</jdbc.pass>
<jdbc.isolation />
@@ -572,9 +549,9 @@
<profile>
<id>postgresql82</id>
<properties>
- <jdbc.driver.groupId>postgresql</jdbc.driver.groupId>
- <jdbc.driver.artifactId>postgresql</jdbc.driver.artifactId>
- <jdbc.driver.jdbc.driver.version>8.2-504.jdbc3</jdbc.driver.jdbc.driver.version>
+ <jdbc.driver.groupId>postgresql</jdbc.driver.groupId>
+ <jdbc.driver.artifactId>postgresql</jdbc.driver.artifactId>
+ <jdbc.driver.jdbc.driver.version>8.2-504.jdbc3</jdbc.driver.jdbc.driver.version>
<db.dialect>org.hibernate.dialect.PostgreSQLDialect</db.dialect>
<jdbc.driver>org.postgresql.Driver</jdbc.driver>
<jdbc.url>jdbc:postgresql://vmg01.mw.lab.eng.bos.redhat.com:5432:hibbrtru</jdbc.url>
@@ -587,10 +564,10 @@
<!-- The PostgreSQL 8.3.7 test envionment -->
<profile>
<id>postgresql83</id>
- <properties>
- <jdbc.driver.groupId>postgresql</jdbc.driver.groupId>
- <jdbc.driver.artifactId>postgresql</jdbc.driver.artifactId>
- <jdbc.driver.jdbc.driver.version>8.2-504.jdbc3</jdbc.driver.jdbc.driver.version>
+ <properties>
+ <jdbc.driver.groupId>postgresql</jdbc.driver.groupId>
+ <jdbc.driver.artifactId>postgresql</jdbc.driver.artifactId>
+ <jdbc.driver.jdbc.driver.version>8.2-504.jdbc3</jdbc.driver.jdbc.driver.version>
<db.dialect>org.hibernate.dialect.PostgreSQLDialect</db.dialect>
<jdbc.driver>org.postgresql.Driver</jdbc.driver>
<jdbc.url>jdbc:postgresql://vmg03.mw.lab.eng.bos.redhat.com:5432:hibbrtru</jdbc.url>
@@ -600,13 +577,10 @@
</properties>
</profile>
- <!--
- ###################################################################
- Then, those with commercial drivers
- ###################################################################
- -->
+ <!-- ###################################################################
+ Then, those with commercial drivers ################################################################### -->
- <!-- The DB2 8.x test envionment (using 9x drivers)-->
+ <!-- The DB2 8.x test envionment (using 9x drivers) -->
<profile>
<id>db2v82</id>
<dependencies>
@@ -618,19 +592,19 @@
</dependency>
</dependencies>
<properties>
- <jdbc.driver.groupId>com.ibm</jdbc.driver.groupId>
- <jdbc.driver.artifactId>db2jcc</jdbc.driver.artifactId>
- <jdbc.driver.jdbc.driver.version>3.1.57</jdbc.driver.jdbc.driver.version>
- <db.dialect>org.hibernate.dialect.DB2Dialect</db.dialect>
- <jdbc.driver>com.ibm.db2.jcc.DB2Driver</jdbc.driver>
- <jdbc.url>jdbc:db2://dev32.qa.atl.jboss.com:50000/jbossqa</jdbc.url>
- <jdbc.user>hibbrtru</jdbc.user>
- <jdbc.pass>hibbrtru</jdbc.pass>
- <jdbc.isolation />
+ <jdbc.driver.groupId>com.ibm</jdbc.driver.groupId>
+ <jdbc.driver.artifactId>db2jcc</jdbc.driver.artifactId>
+ <jdbc.driver.jdbc.driver.version>3.1.57</jdbc.driver.jdbc.driver.version>
+ <db.dialect>org.hibernate.dialect.DB2Dialect</db.dialect>
+ <jdbc.driver>com.ibm.db2.jcc.DB2Driver</jdbc.driver>
+ <jdbc.url>jdbc:db2://dev32.qa.atl.jboss.com:50000/jbossqa</jdbc.url>
+ <jdbc.user>hibbrtru</jdbc.user>
+ <jdbc.pass>hibbrtru</jdbc.pass>
+ <jdbc.isolation />
</properties>
</profile>
- <!-- The DB2 9.1 test envionment (using 9x drivers)-->
+ <!-- The DB2 9.1 test envionment (using 9x drivers) -->
<profile>
<id>db2-91</id>
<dependencies>
@@ -654,7 +628,7 @@
</properties>
</profile>
- <!-- The DB2 9.7 test envionment (using 9x drivers)-->
+ <!-- The DB2 9.7 test envionment (using 9x drivers) -->
<profile>
<id>db2-97</id>
<dependencies>
@@ -740,7 +714,7 @@
<jdbc.driver>oracle.jdbc.driver.OracleDriver</jdbc.driver>
<jdbc.url>
jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=ON)(ADDRESS=(PROTOCOL=TCP)(HOST=vmg24-vip.mw.lab.eng.bos.redhat.com)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=vmg25-vip.mw.lab.eng.bos.redhat.com)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=qarac.jboss)))
- </jdbc.url>
+ </jdbc.url>
<jdbc.user>hibbrtru</jdbc.user>
<jdbc.pass>hibbrtru</jdbc.pass>
<jdbc.isolation />
@@ -778,14 +752,15 @@
<jdbc.isolation>4096</jdbc.isolation>
</properties>
</profile>
-
+
<!-- The SQLServer2005 (MS JDBC) test envionment -->
<profile>
<id>mssql2005_jtds</id>
<properties>
<jdbc.driver.groupId>net.sourceforge.jtds</jdbc.driver.groupId>
<jdbc.driver.artifactId>jtds</jdbc.driver.artifactId>
- <jdbc.driver.jdbc.driver.version>1.2.4</jdbc.driver.jdbc.driver.version><!-- newest is 1.2.5 but not in repo -->
+ <jdbc.driver.jdbc.driver.version>1.2.4</jdbc.driver.jdbc.driver.version><!--
+ newest is 1.2.5 but not in repo -->
<db.dialect>org.hibernate.dialect.SQLServerDialect</db.dialect>
<jdbc.driver>net.sourceforge.jtds.jdbc.Driver</jdbc.driver>
<jdbc.url>jdbc:jtds:sqlserver://dev30.qa.atl.jboss.com:3918</jdbc.url>
View
134 src/java/org/hibernate/tool/ant/JPAConfigurationTask.java
@@ -2,85 +2,153 @@
import java.io.File;
import java.lang.reflect.Method;
+import java.text.MessageFormat;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
import org.hibernate.util.ReflectHelper;
+import org.reflections.Reflections;
+import org.reflections.scanners.Scanner;
+import org.reflections.scanners.SubTypesScanner;
+import org.reflections.scanners.TypeAnnotationsScanner;
+import org.reflections.util.ClasspathHelper;
+import org.reflections.util.ConfigurationBuilder;
import org.xml.sax.EntityResolver;
public class JPAConfigurationTask extends ConfigurationTask {
-
+
private String persistenceUnit = null;
+ private String basePackage = null;
+
public JPAConfigurationTask() {
setDescription("JPA Configuration");
}
-
+
protected Configuration createConfiguration() {
try {
Map overrides = new HashMap();
Properties p = getProperties();
-
- if(p!=null) {
- overrides.putAll( p );
+
+ if (p != null) {
+ overrides.putAll(p);
}
- Class clazz = ReflectHelper.classForName("org.hibernate.ejb.Ejb3Configuration", JPAConfigurationTask.class);
+ Class clazz = ReflectHelper.classForName(
+ "org.hibernate.ejb.Ejb3Configuration",
+ JPAConfigurationTask.class);
Object ejb3cfg = clazz.newInstance();
-
- if(entityResolver!=null) {
- Class resolver = ReflectHelper.classForName(entityResolver, this.getClass());
+
+ if (entityResolver != null) {
+ Class resolver = ReflectHelper.classForName(entityResolver,
+ this.getClass());
Object object = resolver.newInstance();
- Method method = clazz.getMethod("setEntityResolver", new Class[] { EntityResolver.class });
- method.invoke(ejb3cfg, new Object[] { object } );
+ Method method = clazz.getMethod("setEntityResolver",
+ new Class[] { EntityResolver.class });
+ method.invoke(ejb3cfg, new Object[] { object });
}
-
- Method method = clazz.getMethod("configure", new Class[] { String.class, Map.class });
- if ( method.invoke(ejb3cfg, new Object[] { persistenceUnit, overrides } ) == null ) {
- throw new BuildException("Persistence unit not found: '" + persistenceUnit + "'.");
+
+ Method method = clazz.getMethod("configure", new Class[] {
+ String.class, Map.class });
+ if (method.invoke(ejb3cfg, new Object[] { persistenceUnit,
+ overrides }) == null) {
+ throw new BuildException("Persistence unit not found: '"
+ + persistenceUnit + "'.");
}
-
+
+ if (basePackage != null) {
+ Class entity = ReflectHelper.classForName(
+ "javax.persistence.Entity", JPAConfigurationTask.class);
+ Collection urls = ClasspathHelper.forPackage(basePackage, null);
+ Scanner[] scanners = new Scanner[] { new SubTypesScanner(),
+ new TypeAnnotationsScanner() };
+ Reflections reflections = new Reflections(
+ new ConfigurationBuilder().addUrls(urls).addScanners(
+ scanners));
+
+ Set jpaEntities = reflections.getTypesAnnotatedWith(entity);
+ if (jpaEntities != null && jpaEntities.size() > 0) {
+ log(MessageFormat.format(
+ "Found {0} entities under package {1}",
+ new Object[] { new Integer(jpaEntities.size()),
+ basePackage }), Project.MSG_DEBUG);
+
+ Method addAnnotatedClass = clazz.getMethod(
+ "addAnnotatedClass", new Class[] { Class.class });
+ Iterator i = jpaEntities.iterator();
+ while (i.hasNext()) {
+ Object entityClass = i.next();
+ if (entityClass != null) {
+ addAnnotatedClass.invoke(ejb3cfg,
+ new Object[] { entityClass });
+ log(MessageFormat.format(
+ "Add annotated entity {0}.",
+ new Object[] { entityClass }),
+ Project.MSG_DEBUG);
+ }
+ }
+ } else {
+ log(MessageFormat.format(
+ "No entities found for package \"{0}\"",
+ new Object[] { basePackage }), Project.MSG_INFO);
+ }
+ }
+
method = clazz.getMethod("getHibernateConfiguration", new Class[0]);
return (Configuration) method.invoke(ejb3cfg, null);
- }
- catch(HibernateException he) {
+ } catch (HibernateException he) {
throw new BuildException(he);
- }
- catch(BuildException be) {
+ } catch (BuildException be) {
throw be;
+ } catch (Exception t) {
+ throw new BuildException(
+ "Problems in creating a configuration for JPA. Have you remembered to add hibernate EntityManager jars to the classpath ?",
+ t);
}
- catch(Exception t) {
- throw new BuildException("Problems in creating a configuration for JPA. Have you remembered to add hibernate EntityManager jars to the classpath ?",t);
- }
-
+
}
-
+
protected void doConfiguration(Configuration configuration) {
}
-
+
protected void validateParameters() throws BuildException {
-
+
}
-
+
public String getPersistenceUnit() {
return persistenceUnit;
}
-
+
public void setPersistenceUnit(String persistenceUnit) {
this.persistenceUnit = persistenceUnit;
}
-
+
public void setConfigurationFile(File configurationFile) {
complain("configurationfile");
}
+ public void setBasePackage(String basePackage) {
+ this.basePackage = basePackage;
+ }
+
+ public String getBasePackage() {
+ return basePackage;
+ }
+
private void complain(String param) {
- throw new BuildException("<" + getTaskName() + "> currently only support autodiscovery from META-INF/persistence.xml. Thus setting the " + param + " attribute is not allowed");
+ throw new BuildException(
+ "<"
+ + getTaskName()
+ + "> currently only support autodiscovery from META-INF/persistence.xml. Thus setting the "
+ + param + " attribute is not allowed");
}
-
-
+
}
Something went wrong with that request. Please try again.