From: Kai Moritz Date: Tue, 15 Jan 2013 09:40:09 +0000 (+0100) Subject: Test-Classes can now be included into the scanning for Hibernate-Annotations X-Git-Tag: hibernate4-maven-plugin-1.0.1~6 X-Git-Url: http://juplo.de/gitweb/?p=hibernate4-maven-plugin;a=commitdiff_plain;h=36af74be42d47438284677134037ce399ea0b58e Test-Classes can now be included into the scanning for Hibernate-Annotations --- diff --git a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java index 7cae92f8..91b589d8 100644 --- a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java +++ b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java @@ -97,12 +97,38 @@ public class Hbm2DdlMojo extends AbstractMojo private String buildDirectory; /** - * Class-directory to scan. + * Classes-Directory to scan. + *

+ * This parameter defaults to the maven build-output-directory for classes. + * Additonally, all dependencies are scanned for annotated classes. * * @parameter expression="${project.build.outputDirectory}" */ private String outputDirectory; + /** + * Wether to scan test-classes too, or not. + *

+ * If this parameter is set to true the test-classes of the + * artifact will be scanned for hibernate-annotated classes additionally. + * + * @parameter expression="${hibernate.export.scann_testclasses}" default-value="false" + */ + private boolean scanTestClasses; + + /** + * Test-Classes-Directory to scan. + *

+ * This parameter defaults to the maven build-output-directory for + * test-classes. + *

+ * This parameter is only used, when scanTestClasses is set + * to true! + * + * @parameter expression="${project.build.testOutputDirectory}" + */ + private String testOutputDirectory; + /** * Skip execution * @@ -262,6 +288,8 @@ public class Hbm2DdlMojo extends AbstractMojo { getLog().debug("Creating ClassLoader for project-dependencies..."); List classpathFiles = project.getCompileClasspathElements(); + if (scanTestClasses) + classpathFiles.addAll(project.getTestClasspathElements()); URL[] urls = new URL[classpathFiles.size()]; for (int i = 0; i < classpathFiles.size(); ++i) { @@ -293,6 +321,15 @@ public class Hbm2DdlMojo extends AbstractMojo getLog().info("Scanning directory " + outputDirectory + " for annotated classes..."); URL dirUrl = dir.toURI().toURL(); db.scanArchives(dirUrl); + if (scanTestClasses) + { + dir = new File(testOutputDirectory); + if (!dir.exists()) + throw new MojoExecutionException("Cannot scan for annotated test-classes in " + testOutputDirectory + ": directory does not exist!"); + getLog().info("Scanning directory " + testOutputDirectory + " for annotated classes..."); + dirUrl = dir.toURI().toURL(); + db.scanArchives(dirUrl); + } Set classNames = new HashSet(); if (db.getAnnotationIndex().containsKey(Entity.class.getName()))