1 package de.juplo.plugins.hibernate;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.File;
20 import org.apache.maven.plugin.MojoExecutionException;
21 import org.apache.maven.plugin.MojoFailureException;
22 import org.hibernate.boot.spi.MetadataImplementor;
23 import org.hibernate.tool.hbm2ddl.SchemaExport;
24
25
26
27
28
29
30
31
32
33
34
35 public class DropMojo extends AbstractSchemaMojo
36 {
37
38
39
40
41
42
43
44
45
46
47 private String outputFile;
48
49
50 @Override
51 public final void execute()
52 throws
53 MojoFailureException,
54 MojoExecutionException
55 {
56 super.execute(outputFile);
57 }
58
59
60 @Override
61 void build(MetadataImplementor metadata)
62 throws
63 MojoExecutionException,
64 MojoFailureException
65 {
66 SchemaExport schemaExport = new SchemaExport(metadata, createNamespaces);
67 schemaExport.setDelimiter(delimiter);
68 schemaExport.setFormat(format);
69
70 File output = new File(outputFile);
71
72 if (!output.isAbsolute())
73 {
74
75 output = new File(buildDirectory, outputFile);
76 getLog().debug("Adjusted relative path, resulting path is " + output.getPath());
77 }
78
79
80 File outFileParentDir = output.getParentFile();
81 if (null != outFileParentDir && !outFileParentDir.exists())
82 {
83 try
84 {
85 getLog().info("Creating directory path for output file:" + outFileParentDir.getPath());
86 outFileParentDir.mkdirs();
87 }
88 catch (Exception e)
89 {
90 getLog().error("Error creating directory path for output file: " + e.getLocalizedMessage());
91 }
92 }
93
94 schemaExport.setOutputFile(output.getPath());
95 schemaExport.execute(false, this.export, true, false);
96
97 for (Object exception : schemaExport.getExceptions())
98 getLog().error(exception.toString());
99 }
100 }