1 package de.juplo.plugins.hibernate;
4 * Copyright 2001-2005 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
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;
27 * Goal which extracts the hibernate-mapping-configuration and
28 * exports an according SQL-database-schema.
31 * @phase process-classes
33 * @requiresDependencyResolution runtime
35 public class DropMojo extends AbstractSchemaMojo
40 * If the specified filename is not absolut, the file will be created
41 * relative to the project build directory
42 * (<code>project.build.directory</code>).
44 * @parameter property="hibernate.schema.export.drop" default-value="drop.sql"
47 private String outputFile;
51 public final void execute()
54 MojoExecutionException
56 super.execute(outputFile);
61 void build(MetadataImplementor metadata)
63 MojoExecutionException,
66 SchemaExport schemaExport = new SchemaExport(metadata, createNamespaces);
67 schemaExport.setDelimiter(delimiter);
68 schemaExport.setFormat(format);
70 File output = new File(outputFile);
72 if (!output.isAbsolute())
74 // Interpret relative file path relative to build directory
75 output = new File(buildDirectory, outputFile);
76 getLog().debug("Adjusted relative path, resulting path is " + output.getPath());
79 // Ensure that directory path for specified file exists
80 File outFileParentDir = output.getParentFile();
81 if (null != outFileParentDir && !outFileParentDir.exists())
85 getLog().info("Creating directory path for output file:" + outFileParentDir.getPath());
86 outFileParentDir.mkdirs();
90 getLog().error("Error creating directory path for output file: " + e.getLocalizedMessage());
94 schemaExport.setOutputFile(output.getPath());
95 schemaExport.execute(false, this.export, true, false);
97 for (Object exception : schemaExport.getExceptions())
98 getLog().error(exception.toString());