View Javadoc

1   package org.apache.torque.mojo;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.configuration.PropertiesConfiguration;
23  import org.apache.maven.plugin.MojoExecutionException;
24  import org.apache.torque.task.TorqueDataModelTask;
25  
26  /**
27   * Generates a data dtd from schema files.
28   *
29   * @author Raphael Pieroni (rafale_at_codehaus.org)
30   * @author <a href="fischer@seitenbau.de">Thomas Fischer</a>
31   *
32   * @goal datadtd
33   * @phase generate-sources
34   */
35  public class DataDtdMojo extends DataModelTaskMojo
36  {
37      /** The context property for the name of the project. */
38      public static final String PROJECT_CONTEXT_PROPERTY = "project";
39  
40      // The following dummies trick the Mojo Description Extractor
41      // into setting the correct default values for
42      // outputDir, reportFile, contextPropertiesPath, schemaExcludes
43      /**
44       * The directory in which the SQL will be generated.
45       *
46       * @parameter property="outputDir"
47       *            expression="${project.build.directory}/data/torque"
48       */
49      private String dummy;
50  
51      /**
52       * The location where the report file will be generated, 
53       * relative to outputDir.
54       *
55       * @parameter property="reportFile"
56       *            expression="../../torque/report.${project.artifact.artifactId}.datadtd.generation"
57       */
58      private String dummy2;
59  
60      /**
61       * The location where the context property file for velocity will be
62       * generated.
63       *
64       * @parameter property="contextPropertiesPath"
65       *            expression="${project.build.directory}/torque/context.datadtd.properties"
66       */
67      private String dummy3;
68  
69      /**
70       * The schema files which should be excluded in generation
71       * (in ant-style notation).
72       *
73       * @parameter property="schemaExcludes" expression="id-table-schema.xml"
74       */
75      private String dummy4;
76   
77      /**
78       * The name of the project, used as a prefix of the name of the datadtd.
79       *
80       * @parameter expression="torque"
81       */
82      private String projectName = null;
83  
84      /**
85       * The name of the xml file to process. Only one xml file can be processed
86       * at a time.
87       * Overrides the settings schemaIncludes and schemaExcludes
88       *
89       * @parameter
90       * @required
91       */
92      private String xmlFile = null;
93  
94      /**
95       * Creates a new SQLMojo object.
96       */
97      public DataDtdMojo()
98      {
99          super(new TorqueDataModelTask());
100     }
101 
102     /**
103      * Returns the context properties for the Texen task.
104      *
105      * @return The PropertiesConfiguration containing all context properties,
106      *         not null.
107      */
108     protected PropertiesConfiguration getMojoContextProperties()
109     {
110         PropertiesConfiguration configuration = new PropertiesConfiguration();
111         configuration.addProperty(PROJECT_CONTEXT_PROPERTY, projectName);
112         return configuration;
113     }
114 
115     /**
116      * Configures the Texen task which is wrapped by this mojo.
117      * In this implementation, the xml file is set in addition to the
118      * properties set by DataModelTaskMojo#configureTask().
119      *
120      * @throws MojoExecutionException if an error occurs when setting the Tasks
121      *         properties.
122      *
123      * @see DataModelTaskMojo#configureTask()
124      */
125     protected void configureTask() throws MojoExecutionException
126     {
127         super.configureTask();
128 
129         TorqueDataModelTask task
130                 = (TorqueDataModelTask) super.getGeneratorTask();
131 
132         task.setXmlFile(xmlFile);
133     }
134 
135     /**
136      * Returns the path to the control template.
137      *
138      * @return "sql/Control.vm"
139      */
140     protected String getControlTemplate()
141     {
142         return "data/Control.vm";
143     }
144 
145     /**
146      * Returns the name of the project, which is used as prefix for the name
147      * of the datadtd.
148      *
149      * @return the name of the project.
150      */
151     public String getProjectName()
152     {
153         return projectName;
154     }
155 
156     /**
157      * Sets the name of the project, which is used as prefix for the
158      * name of the datadtd.
159      *
160      * @param project the name of the project.
161      */
162     public void setProjectName(String projectName)
163     {
164         this.projectName = projectName;
165     }
166 
167     /**
168      * Returns the name of the xml file to process.
169      *
170      * @return the name of the xml file to process.
171      */
172     public String getXmlFile()
173     {
174         return xmlFile;
175     }
176 
177     /**
178      * Sets the name of the xml file to process.
179      *
180      * @param project the name of the xml file to process.
181      */
182     public void setXmlFile(String xmlFile)
183     {
184         this.xmlFile = xmlFile;
185     }
186 }