Execution is only skipped, if explicitly told so
[hibernate4-maven-plugin] / src / main / java / de / juplo / plugins / hibernate4 / Hbm2DdlMojo.java
index f66f524..96848ed 100644 (file)
@@ -151,7 +151,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="maven.test.skip" default-value="false"
+   * @parameter property="hibernate.export.skip" default-value="false"
    */
   private boolean skip;
 
@@ -289,10 +289,6 @@ public class Hbm2DdlMojo extends AbstractMojo
       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);
@@ -321,7 +317,7 @@ public class Hbm2DdlMojo extends AbstractMojo
       }
       catch (IOException e)
       {
-        getLog().warn("Cannot create saved for timestamps: " + e);
+        getLog().debug("Cannot create file \"" + saved.getPath() + "\" for timestamps: " + e);
       }
     }
 
@@ -360,17 +356,22 @@ public class Hbm2DdlMojo extends AbstractMojo
     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>();
@@ -386,9 +387,11 @@ public class Hbm2DdlMojo extends AbstractMojo
       {
         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)