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