Coverage Report - org.apache.torque.mojo.ExportMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
ExportMojo
0%
0/64
0%
0/6
1.214
 
 1  
 package org.apache.torque.mojo;
 2  
 
 3  
 import java.util.Properties;
 4  
 
 5  
 import org.apache.cxf.common.util.StringUtils;
 6  
 import org.apache.maven.plugin.MojoExecutionException;
 7  
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
 8  
 import org.apache.torque.util.JdbcConfigurer;
 9  
 import org.kuali.core.db.torque.DumpTask;
 10  
 import org.kuali.core.db.torque.PropertyHandlingException;
 11  
 import org.kuali.core.db.torque.StringFilter;
 12  
 
 13  
 /**
 14  
  * Base Mojo for export related functionality
 15  
  */
 16  0
 public abstract class ExportMojo extends AntTaskMojo {
 17  
 
 18  
     /**
 19  
      * Additional properties for the JDBC driver
 20  
      *
 21  
      * @parameter
 22  
      */
 23  
     private Properties driverProperties;
 24  
 
 25  
     /**
 26  
      * If true, files will be exported in a format that the Ant impex tasks can understand
 27  
      *
 28  
      * @parameter expression="${antCompatibilityMode}" default-value="false"
 29  
      */
 30  
     private boolean antCompatibilityMode;
 31  
 
 32  
     /**
 33  
      * The Maven artifactId. Included here as a simple property of the mojo itself to facilitate usage of
 34  
      * <code>BeanUtils.copyProperties()</code> to copy properties between Mojo's and Ant tasks
 35  
      *
 36  
      * @parameter expression="${artifactId}" default-value="${project.artifactId}"
 37  
      * @required
 38  
      */
 39  
     private String artifactId;
 40  
 
 41  
     /**
 42  
      * By default the version of the maven plugin being used during the build will be included as part of a comment in
 43  
      * the XML. Set this to false to prevent this. Useful if you are committing files to SCM and don't want a change in
 44  
      * the version of the plugin to show up as a change to the data.
 45  
      *
 46  
      * @parameter expression="${includeVersionInComment}" default-value="true"
 47  
      * @required
 48  
      */
 49  
     private boolean includeVersionInComment;
 50  
 
 51  
     /**
 52  
      * Additional comment that gets placed into the generated XML document. Anything included here gets appended to the
 53  
      * default value <br>
 54  
      * <b>Default value is:</b> Auto-generated by the maven-impex-plugin v1.0.2<br>
 55  
      *
 56  
      * @parameter expression="${comment}"
 57  
      */
 58  
     private String comment;
 59  
 
 60  
     /**
 61  
      * Comma separated list of regular expressions for tables to include in the export
 62  
      *
 63  
      * @parameter expression="${includes}"
 64  
      */
 65  
     private String includes;
 66  
 
 67  
     /**
 68  
      * Comma separated list of regular expressions for tables to exclude from the export
 69  
      *
 70  
      * @parameter expression="${excludes}"
 71  
      */
 72  
     private String excludes;
 73  
 
 74  
     /**
 75  
      * The type of database we are targeting (eg oracle, mysql). This is optional if <code>url</code> is supplied as the
 76  
      * database type will be automatically detected based on the <code>url</code>. If targetDatabase is explicitly
 77  
      * supplied it will override the type selected by the automatic detection logic.
 78  
      *
 79  
      * @parameter expression="${targetDatabase}"
 80  
      */
 81  
     private String targetDatabase;
 82  
 
 83  
     /**
 84  
      * The schema to export. This parameter is optional, as the schema to export is automatically derived from platform
 85  
      * specific logic that converts the artifactId.<br>
 86  
      * <br>
 87  
      * For example:<br>
 88  
      * ks-embedded-db becomes KSEMBEDDED for Oracle, and ksembedded for MySQL If <code>schema</code> is supplied, the
 89  
      * supplied value will be used instead of the value derived from the artifactId
 90  
      *
 91  
      * @parameter expression="${schema}"
 92  
      */
 93  
     private String schema;
 94  
 
 95  
     /**
 96  
      * Database driver classname. This parameter is optional, as the correct JDBC driver to use is detected from the
 97  
      * <code>url</code> in almost all cases (works for Oracle, MySQL, Derby, PostGresSQL, DB2, H2, HSQL, SQL Server). If
 98  
      * a driver is explicitly supplied, it will be used in place of the JDBC driver the automatic detection logic would
 99  
      * have chosen.
 100  
      *
 101  
      * @parameter expression="${driver}"
 102  
      */
 103  
     private String driver;
 104  
 
 105  
     /**
 106  
      * The connect URL of the database.
 107  
      *
 108  
      * @parameter expression="${url}"
 109  
      * @required
 110  
      */
 111  
     private String url;
 112  
 
 113  
     /**
 114  
      * The user name to connect to the database. If not specified this is automatically generated by platform specific
 115  
      * logic for converting the artifact id.<br>
 116  
      * <br>
 117  
      * For example:<br>
 118  
      * ks-embedded-db becomes KSEMBEDDED for Oracle and ksembedded for MySQL
 119  
      *
 120  
      * @parameter expression="${username}"
 121  
      */
 122  
     private String username;
 123  
 
 124  
     /**
 125  
      * The password for the database user. If not specified this is automatically generated by platform specific logic
 126  
      * for converting the artifact id.<br>
 127  
      * <br>
 128  
      * For example:<br>
 129  
      * ks-embedded-db becomes KSEMBEDDED for Oracle and ksembedded for MySQL
 130  
      *
 131  
      * @parameter expression="${password}"
 132  
      */
 133  
     private String password;
 134  
 
 135  
     /**
 136  
      * Returns the fully qualified class name of the database driver.
 137  
      */
 138  
     public String getDriver() {
 139  0
         return driver;
 140  
     }
 141  
 
 142  
     /**
 143  
      * Sets the fully qualified class name of the database driver.
 144  
      *
 145  
      * @param driver
 146  
      *            the fully qualified class name of the database driver.
 147  
      */
 148  
     public void setDriver(final String driver) {
 149  0
         this.driver = driver;
 150  0
     }
 151  
 
 152  
     /**
 153  
      * Returns the password of the database user.
 154  
      *
 155  
      * @return the password of the database user.
 156  
      */
 157  
     public String getPassword() {
 158  0
         return password;
 159  
     }
 160  
 
 161  
     /**
 162  
      * Sets the password of the database user.
 163  
      *
 164  
      * @param password
 165  
      *            the password of the database user.
 166  
      */
 167  
     public void setPassword(final String password) {
 168  0
         this.password = password;
 169  0
     }
 170  
 
 171  
     /**
 172  
      * Returns the connect URL to the database.
 173  
      *
 174  
      * @return the connect URL to the database.
 175  
      */
 176  
     public String getUrl() {
 177  0
         return url;
 178  
     }
 179  
 
 180  
     /**
 181  
      * Sets the connect URL to the database.
 182  
      *
 183  
      * @param url
 184  
      *            the connect URL to the database.
 185  
      */
 186  
     public void setUrl(final String url) {
 187  0
         this.url = url;
 188  0
     }
 189  
 
 190  
     public String getUsername() {
 191  0
         return username;
 192  
     }
 193  
 
 194  
     public void setUsername(final String username) {
 195  0
         this.username = username;
 196  0
     }
 197  
 
 198  
     public String getSchema() {
 199  0
         return schema;
 200  
     }
 201  
 
 202  
     public void setSchema(final String schema) {
 203  0
         this.schema = schema;
 204  0
     }
 205  
 
 206  
     public String getTargetDatabase() {
 207  0
         return targetDatabase;
 208  
     }
 209  
 
 210  
     public void setTargetDatabase(final String targetDatabase) {
 211  0
         this.targetDatabase = targetDatabase;
 212  0
     }
 213  
 
 214  
     public String getIncludes() {
 215  0
         return includes;
 216  
     }
 217  
 
 218  
     public void setIncludes(final String includePatterns) {
 219  0
         this.includes = includePatterns;
 220  0
     }
 221  
 
 222  
     public String getExcludes() {
 223  0
         return excludes;
 224  
     }
 225  
 
 226  
     public void setExcludes(final String excludePatterns) {
 227  0
         this.excludes = excludePatterns;
 228  0
     }
 229  
 
 230  
     public String getComment() {
 231  0
         return comment;
 232  
     }
 233  
 
 234  
     public void setComment(final String comment) {
 235  0
         this.comment = comment;
 236  0
     }
 237  
 
 238  
     protected String getUpdatedComment() {
 239  0
         PluginDescriptor descriptor = (PluginDescriptor) this.getPluginContext().get("pluginDescriptor");
 240  0
         if (descriptor == null) {
 241  
             // This is null for Maven 2.x
 242  0
             return " Auto-generated by the maven-impex-plugin " + getComment();
 243  
         }
 244  0
         String name = descriptor.getName();
 245  0
         String version = descriptor.getVersion();
 246  0
         String comment = " Auto-generated by the " + name;
 247  0
         if (isIncludeVersionInComment()) {
 248  0
             comment += " v" + version + " ";
 249  
         }
 250  0
         if (!StringUtils.isEmpty(getComment())) {
 251  0
             comment += getComment();
 252  
         }
 253  0
         return comment;
 254  
     }
 255  
 
 256  
     @Override
 257  
     protected void configureTask() throws MojoExecutionException {
 258  0
         setComment(getUpdatedComment());
 259  
         try {
 260  0
             JdbcConfigurer configurer = new JdbcConfigurer();
 261  0
             configurer.updateConfiguration(this);
 262  0
             configurer.validateConfiguration(this);
 263  0
         } catch (PropertyHandlingException e) {
 264  0
             throw new MojoExecutionException("Error handling properties", e);
 265  0
         }
 266  0
         super.configureTask();
 267  0
         DumpTask task = (DumpTask) super.getAntTask();
 268  0
         task.setIncludePatterns(StringFilter.getListFromCSV(getIncludes()));
 269  0
         task.setExcludePatterns(StringFilter.getListFromCSV(getExcludes()));
 270  0
         task.setDriverProperties(driverProperties);
 271  0
     }
 272  
 
 273  
     public String getArtifactId() {
 274  0
         return artifactId;
 275  
     }
 276  
 
 277  
     public void setArtifactId(final String artifactId) {
 278  0
         this.artifactId = artifactId;
 279  0
     }
 280  
 
 281  
     public boolean isAntCompatibilityMode() {
 282  0
         return antCompatibilityMode;
 283  
     }
 284  
 
 285  
     public void setAntCompatibilityMode(final boolean antCompatibilityMode) {
 286  0
         this.antCompatibilityMode = antCompatibilityMode;
 287  0
     }
 288  
 
 289  
     /**
 290  
      * @return the includeVersionInComment
 291  
      */
 292  
     public boolean isIncludeVersionInComment() {
 293  0
         return includeVersionInComment;
 294  
     }
 295  
 
 296  
     /**
 297  
      * @param includeVersionInComment
 298  
      *            the includeVersionInComment to set
 299  
      */
 300  
     public void setIncludeVersionInComment(final boolean includeVersionInComment) {
 301  0
         this.includeVersionInComment = includeVersionInComment;
 302  0
     }
 303  
 
 304  
     public Properties getDriverProperties() {
 305  0
         return driverProperties;
 306  
     }
 307  
 
 308  
     public void setDriverProperties(Properties driverProperties) {
 309  0
         this.driverProperties = driverProperties;
 310  0
     }
 311  
 }