From 5715c7e29252ed230389cfce9c1a0376fec82813 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 31 Aug 2013 09:01:43 +0200 Subject: [PATCH] Fixed failure when target/classes does not exist when runnin mvn test phase Thanks to Stephen Johnson Details from the original email: --------- The following patch stops builds failing when target/classes (or no main java exists), and target/test-classes and src/tests exist. So for example calling mvn test -> invokes compiler:compile and if you have export bound to process-classes phase in executions it will fail. Maybe better to give info and carry on. Say for example they want to leave the executions in place that deal with process-classes and also process-test-classes but they do not want it to fail if there is no java to annotate in src/classes. The other way would be to comment out the executions bound to process-classes. What about export being bound to process-class by default? Could this also cause issues? In either case I think the plugin code did checks for src/classes directory existing, in which case even call "mvn test" would fail as src/classes would not exist as no java existed in src/main only in src/test. Have a look through the patch and see if its of any use. --- pom.xml | 4 +++ .../juplo/plugins/hibernate4/Hbm2DdlMojo.java | 25 ++++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 80516763..3868597a 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,10 @@ Eduard Szente eduard.szente@gmail.com + + Stephen Johnson + stejohns@redhat.com + diff --git a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java index 7077c9f4..24178c19 100644 --- a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java +++ b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java @@ -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 md5s; boolean modified = false; File saved = new File(buildDirectory + File.separator + MD5S); @@ -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 classNames = new HashSet(); -- 2.20.1