/**
* Target of execution:
* <ul>
- * <li><strong>NONE</strong> do nothing - just validate the configuration (forces excecution, signals skip)</li>
- * <li><strong>EXPORT</strong> create database (<strong>DEFAULT!</strong>. forces excecution, signals skip)</li>
- * <li><strong>SCRIPT</strong> export schema to SQL-script</li>
+ * <li><strong>NONE</strong> only export schema to SQL-script (forces excecution, signals skip)</li>
+ * <li><strong>EXPORT</strong> create database (<strong>DEFAULT!</strong>). forces excecution, signals skip)</li>
+ * <li><strong>SCRIPT</strong> export schema to SQL-script and print it to STDOUT</li>
* <li><strong>BOTH</strong></li>
* </ul>
*
+ * A databaseconnection is only needed for EXPORT and BOTH, but a
+ * Hibernate-Dialect must always be choosen.
+ *
* @parameter property="hibernate.export.target" default-value="EXPORT"
*/
private String target;
* <li><strong>BOTH</strong> (<strong>DEFAULT!</strong>)</li>
* </ul>
*
+ * If NONE is choosen, no databaseconnection is needed.
+ *
* @parameter property="hibernate.export.type" default-value="BOTH"
*/
private String type;
return;
}
- File dir = new File(outputDirectory);
- if (!dir.exists())
- throw new MojoExecutionException("Cannot scan for annotated classes in " + outputDirectory + ": directory does not exist!");
-
Map<String,String> md5s;
boolean modified = false;
File saved = new File(buildDirectory + File.separator + MD5S);
}
catch (IOException e)
{
- getLog().warn("Cannot create saved for timestamps: " + e);
+ getLog().debug("Cannot create file \"" + saved.getPath() + "\" for timestamps: " + e);
}
}
try
{
AnnotationDB db = new AnnotationDB();
- getLog().info("Scanning directory " + outputDirectory + " for annotated classes...");
- URL dirUrl = dir.toURI().toURL();
- db.scanArchives(dirUrl);
+ File dir = new File(outputDirectory);
+ if (dir.exists())
+ {
+ 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);
+ if (dir.exists())
+ {
+ getLog().info("Scanning directory " + testOutputDirectory + " for annotated classes...");
+ URL dirUrl = dir.toURI().toURL();
+ db.scanArchives(dirUrl);
+ }
}
Set<String> classNames = new HashSet<String>();
{
Class<?> annotatedClass = classLoader.loadClass(name);
classes.add(annotatedClass);
+ String resourceName = annotatedClass.getName();
+ resourceName = resourceName.substring(resourceName.lastIndexOf(".") + 1, resourceName.length()) + ".class";
InputStream is =
annotatedClass
- .getResourceAsStream(annotatedClass.getSimpleName() + ".class");
+ .getResourceAsStream(resourceName);
byte[] buffer = new byte[1024*4]; // copy data in 4MB-chunks
int i;
while((i = is.read(buffer)) > -1)
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
for (String filename : hibernateMapping.split("[\\s,]+"))
{
- File file = null;
- for (Resource resource : project.getResources())
+ // First try the filename as absolute/relative path
+ File file = new File(filename);
+ if (!file.exists())
{
- file = new File(resource.getDirectory() + File.separator + filename);
- if (file.exists())
- break;
+ // If the file was not found, search for it in the resource-directories
+ for (Resource resource : project.getResources())
+ {
+ file = new File(resource.getDirectory() + File.separator + filename);
+ if (file.exists())
+ break;
+ }
}
if (file != null && file.exists())
{
* hibernate does not use the context-classloader of the current
* thread and, hence, would not be able to resolve the driver-class!
*/
+ getLog().debug("Target: " + target + ", Type: " + type);
switch (target)
{
case EXPORT: