From: Kai Moritz Date: Tue, 15 Oct 2013 23:18:53 +0000 (+0200) Subject: The plugin now scans for annotated classes in dependencies too X-Git-Tag: hibernate4-maven-plugin-1.0.3~3 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=221d977368ee1897377f80bfcdd50dcbcd1d4b83;p=hibernate-maven-plugin The plugin now scans for annotated classes in dependencies too --- diff --git a/pom.xml b/pom.xml index f4e0eefe..bfd2c27c 100644 --- a/pom.xml +++ b/pom.xml @@ -69,6 +69,10 @@ Erik-Berndt Scheper erik.berndt.scheper@gmail.com + + Guido Wimmel + Wimmel.Guido@swm.de + diff --git a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java index 2e232bf1..83f53d3d 100644 --- a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java +++ b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java @@ -47,9 +47,12 @@ import java.util.Properties; import java.util.Set; import java.util.TreeSet; import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.persistence.Embeddable; import javax.persistence.Entity; import javax.persistence.MappedSuperclass; +import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Resource; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -85,7 +88,10 @@ public class Hbm2DdlMojo extends AbstractMojo public final static String NAMING_STRATEGY="hibernate.ejb.naming_strategy"; public final static String ENVERS = "hibernate.export.envers"; - private final static String MD5S = "schema.md5s"; + public final static String MD5S = "schema.md5s"; + + private final static Pattern split = Pattern.compile("[^,\\s]+"); + /** * The maven project. @@ -129,6 +135,21 @@ public class Hbm2DdlMojo extends AbstractMojo */ private boolean scanTestClasses; + /** + * Dependency-Scopes, that should be scanned for annotated classes. + *

+ * By default, only dependencies in the scope compile are + * scanned for annotated classes. Multiple scopes can be seperated by + * white space or commas. + *

+ * The plugin does not scan for annotated classes in transitive + * dependencies. If some of your annotated classes are hidden in a + * transitive dependency, you can simply add that dependency explicitly. + * + * @parameter property="hibernate.export.scan_dependencies" default-value="compile" + */ + private String scanDependencies; + /** * Test-Classes-Directory to scan. *

@@ -381,6 +402,34 @@ public class Hbm2DdlMojo extends AbstractMojo db.scanArchives(dirUrl); } } + if (scanDependencies != null) + { + Matcher matcher = split.matcher(scanDependencies); + while (matcher.find()) + { + getLog().info("Scanning dependencies for scope " + matcher.group()); + for (Artifact artifact : project.getDependencyArtifacts()) + { + if (!artifact.getScope().equalsIgnoreCase(matcher.group())) + continue; + if (artifact.getFile() == null) + { + getLog().warn( + "Cannot scan dependency " + + artifact.getId() + + ": no JAR-file available!" + ); + continue; + } + getLog().info( + "Scanning dependency " + + artifact.getId() + + " for annotated classes..." + ); + db.scanArchives(artifact.getFile().toURI().toURL()); + } + } + } Set classNames = new HashSet(); if (db.getAnnotationIndex().containsKey(Entity.class.getName())) diff --git a/src/site/apt/pitfalls.apt b/src/site/apt/pitfalls.apt index 33c40cfa..a25abcd7 100644 --- a/src/site/apt/pitfalls.apt +++ b/src/site/apt/pitfalls.apt @@ -4,6 +4,12 @@ Kai Moritz --- +Annotated classes in dependencies are not found. + + hibernate4-maven-plugin does not scan transitive dependencies for + annotated classes. If some of your annotated classes are hidden in a + transitive dependency, you can simply add that dependency explicitly. + hibernate4-maven-plugin always needs a database-connection The default-configuration uses the EXPORT-target of the SchemaExport-Tool.