X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fplugins%2Fhibernate4%2FHbm2DdlMojo.java;h=83f53d3d56d05a048f40084fc3c3ab8b0a94c4e2;hb=221d977368ee1897377f80bfcdd50dcbcd1d4b83;hp=2174765fa97d21eb87146f2af5157c1b7150ad50;hpb=e88830c968c1aabc5c32df8a061a8b446c26505c;p=hibernate-maven-plugin diff --git a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java index 2174765f..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; @@ -83,9 +86,12 @@ public class Hbm2DdlMojo extends AbstractMojo public final static String PASSWORD = "hibernate.connection.password"; public final static String DIALECT = "hibernate.dialect"; public final static String NAMING_STRATEGY="hibernate.ejb.naming_strategy"; - public final static String ENVERS = "hibernate.envers"; + public final static String ENVERS = "hibernate.export.envers"; + + public final static String MD5S = "schema.md5s"; + + private final static Pattern split = Pattern.compile("[^,\\s]+"); - private final static String MD5S = "schema.md5s"; /** * 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. *
@@ -153,7 +174,7 @@ public class Hbm2DdlMojo extends AbstractMojo
* The excecution is skipped automatically, if no modified or newly added
* annotated classes are found and the dialect was not changed.
*
- * @parameter property="hibernate.export.skip" default-value="false"
+ * @parameter property="maven.test.skip" default-value="false"
*/
private boolean skip;
@@ -280,7 +301,7 @@ public class Hbm2DdlMojo extends AbstractMojo
/**
* Generate envers schema for auditing tables.
*
- * @parameter expression="${hibernate.envers}" default-value="false"
+ * @parameter property="hibernate.export.envers" default-value="false"
*/
private boolean envers;
@@ -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