From: Joel Johnson Date: Thu, 26 Dec 2013 21:02:29 +0000 (-0700) Subject: Make output file handling more robust X-Git-Tag: hibernate4-maven-plugin-1.0.4~18 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=727d1a35bb213589270b097d04d5a1f480bffef6;p=hibernate-maven-plugin Make output file handling more robust * Ensure output file directory path exists * Anchor relative paths in build directory --- diff --git a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java index 97901818..18351f07 100644 --- a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java +++ b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java @@ -875,9 +875,34 @@ public class Hbm2DdlMojo extends AbstractMojo } SchemaExport export = new SchemaExport(config, connection); - export.setOutputFile(outputFile); export.setDelimiter(delimiter); export.setFormat(format); + + File outF = new File(outputFile); + + if (!outF.isAbsolute()) + { + // Interpret relative file path relative to build directory + outF = new File(buildDirectory, outputFile); + getLog().info("Adjusted relative path, resulting path is " + outF.getPath()); + } + + // Ensure that directory path for specified file exists + File outFileParentDir = outF.getParentFile(); + if (null != outFileParentDir && !outFileParentDir.exists()) + { + try + { + getLog().info("Creating directory path for output file:" + outFileParentDir.getPath()); + outFileParentDir.mkdirs(); + } + catch (Exception e) + { + getLog().error("Error creating directory path for output file: " + e.getLocalizedMessage()); + } + } + + export.setOutputFile(outF.getPath()); export.execute(target, type); for (Object exception : export.getExceptions())