Fixed bug: the execution is no more skipped after a failed build
[hibernate4-maven-plugin] / src / main / java / de / juplo / plugins / hibernate / AbstractSchemaMojo.java
index 09bd83d..1eb54e5 100644 (file)
@@ -542,6 +542,34 @@ public abstract class AbstractSchemaMojo extends AbstractMojo
         classes = scanUrls(urls);
         for (String className : unit.getManagedClassNames())
           classes.add(className);
+        /**
+         * Add mappings from the default mapping-file
+         * <code>META-INF/orm.xml</code>, if present
+         */
+        try
+        {
+          InputStream is = classLoader.getResourceAsStream("META-INF/orm.xml");
+          if (is != null)
+          {
+            getLog().info("Adding default JPA-XML-mapping from META-INF/orm.xml");
+            tracker.track("META-INF/orm.xml", is);
+            sources.addResource("META-INF/orm.xml");
+          }
+          /**
+           * Add mappings from files, that are explicitly configured in the
+           * persistence unit
+           */
+          for (String mapping : unit.getMappingFileNames())
+          {
+            getLog().info("Adding explicitly configured mapping from " + mapping);
+            tracker.track(mapping, classLoader.getResourceAsStream(mapping));
+            sources.addResource(mapping);
+          }
+        }
+        catch (IOException e)
+        {
+          throw new MojoFailureException("Error reading XML-mappings", e);
+        }
       }
 
       /** Add the configured/collected annotated classes */
@@ -613,6 +641,21 @@ public abstract class AbstractSchemaMojo extends AbstractMojo
         thread.setContextClassLoader(contextClassLoader);
       }
     }
+    catch (MojoExecutionException e)
+    {
+      tracker.failed();
+      throw e;
+    }
+    catch (MojoFailureException e)
+    {
+      tracker.failed();
+      throw e;
+    }
+    catch (RuntimeException e)
+    {
+      tracker.failed();
+      throw e;
+    }
     finally
     {
       /** Remember mappings and configuration */
@@ -1053,7 +1096,7 @@ public abstract class AbstractSchemaMojo extends AbstractMojo
             getLog().debug("New or modified package: " + packageName);
           else
            getLog().debug("Unchanged package: " + packageName);
-          getLog().info("Adding annotated package " + packageName);
+          getLog().info("Adding annotations from package " + packageName);
           sources.addPackage(packageName);
         }
         packages.add(packageName);