| 1 |  | package org.apache.torque.mojo; | 
            
  
    | 2 |  |  | 
            
  
    | 3 |  | import java.io.File; | 
            
  
    | 4 |  | import java.io.IOException; | 
            
  
    | 5 |  | import java.util.List; | 
            
  
    | 6 |  |  | 
            
  
    | 7 |  | import org.apache.commons.lang.StringUtils; | 
            
  
    | 8 |  | import org.apache.maven.plugin.MojoExecutionException; | 
            
  
    | 9 |  | import org.apache.tools.ant.types.FileSet; | 
            
  
    | 10 |  | import org.apache.torque.task.TorqueDataModelTask; | 
            
  
    | 11 |  | import org.apache.torque.util.JdbcConfigurer; | 
            
  
    | 12 |  | import org.apache.torque.util.SimpleScanner; | 
            
  
    | 13 |  | import org.kuali.core.db.torque.PropertyHandlingException; | 
            
  
    | 14 |  | import org.kuali.db.DatabaseType; | 
            
  
    | 15 |  |  | 
            
  
    | 16 |  |  | 
            
  
    | 17 |  |  | 
            
  
    | 18 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 95 (95) | Complexity: 34 | Complexity Density: 0.55 |  | 
  
  
    | 19 |  | public abstract class DataModelTaskMojo extends TexenTaskMojo { | 
            
  
    | 20 |  |  | 
            
  
    | 21 |  |  | 
            
  
    | 22 |  |  | 
            
  
    | 23 |  |  | 
            
  
    | 24 |  | public static final String TARGET_DATABASE_CONTEXT_PROPERTY = "targetDatabase"; | 
            
  
    | 25 |  |  | 
            
  
    | 26 |  |  | 
            
  
    | 27 |  |  | 
            
  
    | 28 |  |  | 
            
  
    | 29 |  |  | 
            
  
    | 30 |  |  | 
            
  
    | 31 |  | String url; | 
            
  
    | 32 |  |  | 
            
  
    | 33 |  |  | 
            
  
    | 34 |  |  | 
            
  
    | 35 |  |  | 
            
  
    | 36 |  | String suffix = ""; | 
            
  
    | 37 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 5 (5) | Complexity: 2 | Complexity Density: 0.4 |  | 
  
  
    | 38 | 0 |  protected File getCanonicalReportFile() throws MojoExecutionException {... | 
            
  
    | 39 | 0 | try { | 
            
  
    | 40 | 0 | String filename = getOutputDir() + FS + getReportFile(); | 
            
  
    | 41 | 0 | File file = new File(filename); | 
            
  
    | 42 | 0 | return file.getCanonicalFile(); | 
            
  
    | 43 |  | } catch (IOException e) { | 
            
  
    | 44 | 0 | throw new MojoExecutionException("Error with report file", e); | 
            
  
    | 45 |  | } | 
            
  
    | 46 |  | } | 
            
  
    | 47 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 5 (5) | Complexity: 1 | Complexity Density: 0.2 |  | 
  
  
    | 48 | 0 |  protected FileSet getAntFileSet(File baseDir, String includes, String excludes) {... | 
            
  
    | 49 | 0 | FileSet fileSet = new FileSet(); | 
            
  
    | 50 | 0 | fileSet.setDir(baseDir); | 
            
  
    | 51 | 0 | fileSet.setIncludes(includes); | 
            
  
    | 52 | 0 | fileSet.setExcludes(excludes); | 
            
  
    | 53 | 0 | return fileSet; | 
            
  
    | 54 |  | } | 
            
  
    | 55 |  |  | 
            
  
    | 56 |  |  | 
            
  
    | 57 |  |  | 
            
  
    | 58 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 3 (3) | Complexity: 2 | Complexity Density: 0.67 |  | 
  
  
    | 59 | 0 |  protected void updateConfiguration() throws MojoExecutionException {... | 
            
  
    | 60 | 0 | try { | 
            
  
    | 61 |  |  | 
            
  
    | 62 | 0 | new JdbcConfigurer().updateConfiguration(this); | 
            
  
    | 63 |  | } catch (PropertyHandlingException e) { | 
            
  
    | 64 | 0 | throw new MojoExecutionException("Error handling properties", e); | 
            
  
    | 65 |  | } | 
            
  
    | 66 |  | } | 
            
  
    | 67 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 7 (7) | Complexity: 1 | Complexity Density: 0.14 |  | 
  
  
    | 68 | 0 |  protected String getInvalidTargetDatabaseMessage() {... | 
            
  
    | 69 | 0 | StringBuffer sb = new StringBuffer(); | 
            
  
    | 70 | 0 | sb.append("\n\n"); | 
            
  
    | 71 | 0 | sb.append("Target database of '" + getTargetDatabase() + "' is invalid.\n\n"); | 
            
  
    | 72 | 0 | sb.append("Valid values are " + org.springframework.util.StringUtils.arrayToCommaDelimitedString(DatabaseType.values()) + ".\n\n"); | 
            
  
    | 73 | 0 | sb.append("Specify targetDatabase in the plugin configuration or as a system property.\n\n"); | 
            
  
    | 74 | 0 | sb.append("For example:\n-DtargetDatabase=oracle\n\n."); | 
            
  
    | 75 | 0 | return sb.toString(); | 
            
  
    | 76 |  | } | 
            
  
    | 77 |  |  | 
            
  
    | 78 |  |  | 
            
  
    | 79 |  |  | 
            
  
    | 80 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 7 (7) | Complexity: 3 | Complexity Density: 0.6 |  | 
  
  
    | 81 | 0 |  protected void validateConfiguration() throws MojoExecutionException {... | 
            
  
    | 82 | 0 | if (StringUtils.isEmpty(getTargetDatabase())) { | 
            
  
    | 83 | 0 | throw new MojoExecutionException(getInvalidTargetDatabaseMessage()); | 
            
  
    | 84 |  | } | 
            
  
    | 85 |  |  | 
            
  
    | 86 | 0 | try { | 
            
  
    | 87 | 0 | DatabaseType.valueOf(getTargetDatabase().toUpperCase()); | 
            
  
    | 88 |  | } catch (IllegalArgumentException e) { | 
            
  
    | 89 | 0 | throw new MojoExecutionException(getInvalidTargetDatabaseMessage()); | 
            
  
    | 90 |  | } | 
            
  
    | 91 |  | } | 
            
  
    | 92 |  |  | 
            
  
    | 93 |  |  | 
            
  
    | 94 |  |  | 
            
  
    | 95 |  |  | 
            
  
    | 96 |  |  | 
            
  
    | 97 |  |  | 
            
  
    | 98 |  |  | 
            
  
    | 99 |  | private String schemaDir; | 
            
  
    | 100 |  |  | 
            
  
    | 101 |  |  | 
            
  
    | 102 |  |  | 
            
  
    | 103 |  |  | 
            
  
    | 104 |  |  | 
            
  
    | 105 |  |  | 
            
  
    | 106 |  |  | 
            
  
    | 107 |  | private String schemaIncludes; | 
            
  
    | 108 |  |  | 
            
  
    | 109 |  |  | 
            
  
    | 110 |  |  | 
            
  
    | 111 |  |  | 
            
  
    | 112 |  | private String schemaExcludes; | 
            
  
    | 113 |  |  | 
            
  
    | 114 |  |  | 
            
  
    | 115 |  |  | 
            
  
    | 116 |  |  | 
            
  
    | 117 |  |  | 
            
  
    | 118 |  |  | 
            
  
    | 119 |  |  | 
            
  
    | 120 |  |  | 
            
  
    | 121 |  | private String targetDatabase; | 
            
  
    | 122 |  |  | 
            
  
    | 123 |  |  | 
            
  
    | 124 |  |  | 
            
  
    | 125 |  |  | 
            
  
    | 126 |  |  | 
            
  
    | 127 |  |  | 
            
  
    | 128 |  | private String targetPackage; | 
            
  
    | 129 |  |  | 
            
  
    | 130 |  |  | 
            
  
    | 131 |  |  | 
            
  
    | 132 |  |  | 
            
  
    | 133 |  |  | 
            
  
    | 134 |  |  | 
            
  
    | 135 |  | private String reportFile; | 
            
  
    | 136 |  |  | 
            
  
    | 137 |  |  | 
            
  
    | 138 |  |  | 
            
  
    | 139 |  |  | 
            
  
    | 140 |  |  | 
            
  
    | 141 |  |  | 
            
  
    | 142 |  | private boolean runOnlyOnSchemaChange; | 
            
  
    | 143 |  |  | 
            
  
    | 144 |  |  | 
            
  
    | 145 |  |  | 
            
  
    | 146 |  |  | 
            
  
    | 147 |  |  | 
            
  
    | 148 |  |  | 
            
  
    | 149 |  | private String sqlDbMap; | 
            
  
    | 150 |  |  | 
            
  
    | 151 |  |  | 
            
  
    | 152 |  |  | 
            
  
    | 153 |  |  | 
            
  
    | 154 |  | @return | 
            
  
    | 155 |  |  | 
            
  
    | 156 |  | protected abstract String getControlTemplate(); | 
            
  
    | 157 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 4 (4) | Complexity: 1 | Complexity Density: 0.25 |  | 
  
  
    | 158 | 0 |  protected void addTargetDatabaseToOutputDir() {... | 
            
  
    | 159 | 0 | TorqueDataModelTask task = (TorqueDataModelTask) super.getGeneratorTask(); | 
            
  
    | 160 | 0 | String newOutputDir = getOutputDir() + FS + getTargetDatabase(); | 
            
  
    | 161 | 0 | task.setOutputDirectory(new File(newOutputDir)); | 
            
  
    | 162 | 0 | setOutputDir(newOutputDir); | 
            
  
    | 163 |  | } | 
            
  
    | 164 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 4 (4) | Complexity: 1 | Complexity Density: 0.25 |  | 
  
  
    | 165 | 0 |  protected void addTargetDatabaseToReportFile() {... | 
            
  
    | 166 | 0 | TorqueDataModelTask task = (TorqueDataModelTask) super.getGeneratorTask(); | 
            
  
    | 167 | 0 | String newReportFile = getReportFile() + "." + getTargetDatabase(); | 
            
  
    | 168 | 0 | task.setOutputFile(newReportFile); | 
            
  
    | 169 | 0 | setReportFile(newReportFile); | 
            
  
    | 170 |  | } | 
            
  
    | 171 |  |  | 
            
  
    | 172 |  |  | 
            
  
    | 173 |  |  | 
            
  
    | 174 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 10 (10) | Complexity: 2 | Complexity Density: 0.25 |  | 
  
  
    | 175 | 0 |  protected void configureTask() throws MojoExecutionException {... | 
            
  
    | 176 | 0 | super.configureTask(); | 
            
  
    | 177 |  |  | 
            
  
    | 178 | 0 | TorqueDataModelTask task = (TorqueDataModelTask) super.getGeneratorTask(); | 
            
  
    | 179 | 0 | task.setControlTemplate(getControlTemplate()); | 
            
  
    | 180 | 0 | task.setOutputFile(getReportFile()); | 
            
  
    | 181 | 0 | task.setTargetDatabase(getTargetDatabase()); | 
            
  
    | 182 | 0 | task.setTargetPackage(getTargetPackage()); | 
            
  
    | 183 | 0 | if (getSqlDbMap() != null) { | 
            
  
    | 184 | 0 | task.setSqlDbMap(getSqlDbMap()); | 
            
  
    | 185 |  | } | 
            
  
    | 186 |  | } | 
            
  
    | 187 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 188 | 0 |  protected List<File> getSchemaFiles() {... | 
            
  
    | 189 | 0 | return new SimpleScanner(new File(getSchemaDir()), getSchemaIncludes(), getSchemaExcludes()).getFiles(); | 
            
  
    | 190 |  | } | 
            
  
    | 191 |  |  | 
            
  
    | 192 |  |  | 
            
  
    | 193 |  |  | 
            
  
    | 194 |  |  | 
            
  
    | 195 |  | @return | 
            
  
    | 196 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 197 | 0 |  public String getSchemaDir() {... | 
            
  
    | 198 | 0 | return schemaDir; | 
            
  
    | 199 |  | } | 
            
  
    | 200 |  |  | 
            
  
    | 201 |  |  | 
            
  
    | 202 |  |  | 
            
  
    | 203 |  |  | 
            
  
    | 204 |  | @param | 
            
  
    | 205 |  |  | 
            
  
    | 206 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 207 | 0 |  public void setSchemaDir(String schemaDir) {... | 
            
  
    | 208 | 0 | this.schemaDir = schemaDir; | 
            
  
    | 209 |  | } | 
            
  
    | 210 |  |  | 
            
  
    | 211 |  |  | 
            
  
    | 212 |  |  | 
            
  
    | 213 |  |  | 
            
  
    | 214 |  | @return | 
            
  
    | 215 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 216 | 0 |  public String getTargetDatabase() {... | 
            
  
    | 217 | 0 | return targetDatabase; | 
            
  
    | 218 |  | } | 
            
  
    | 219 |  |  | 
            
  
    | 220 |  |  | 
            
  
    | 221 |  |  | 
            
  
    | 222 |  |  | 
            
  
    | 223 |  | @param | 
            
  
    | 224 |  |  | 
            
  
    | 225 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 226 | 0 |  public void setTargetDatabase(String targetDatabase) {... | 
            
  
    | 227 | 0 | this.targetDatabase = targetDatabase; | 
            
  
    | 228 |  | } | 
            
  
    | 229 |  |  | 
            
  
    | 230 |  |  | 
            
  
    | 231 |  |  | 
            
  
    | 232 |  |  | 
            
  
    | 233 |  | @return | 
            
  
    | 234 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 235 | 0 |  public String getTargetPackage() {... | 
            
  
    | 236 | 0 | return targetPackage; | 
            
  
    | 237 |  | } | 
            
  
    | 238 |  |  | 
            
  
    | 239 |  |  | 
            
  
    | 240 |  |  | 
            
  
    | 241 |  |  | 
            
  
    | 242 |  |  | 
            
  
    | 243 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 244 | 0 |  public void setTargetPackage(String targetPackage) {... | 
            
  
    | 245 | 0 | this.targetPackage = targetPackage; | 
            
  
    | 246 |  | } | 
            
  
    | 247 |  |  | 
            
  
    | 248 |  |  | 
            
  
    | 249 |  |  | 
            
  
    | 250 |  |  | 
            
  
    | 251 |  | @return | 
            
  
    | 252 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 253 | 0 |  public String getReportFile() {... | 
            
  
    | 254 | 0 | return reportFile; | 
            
  
    | 255 |  | } | 
            
  
    | 256 |  |  | 
            
  
    | 257 |  |  | 
            
  
    | 258 |  |  | 
            
  
    | 259 |  |  | 
            
  
    | 260 |  | @param | 
            
  
    | 261 |  |  | 
            
  
    | 262 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 263 | 0 |  public void setReportFile(String reportFile) {... | 
            
  
    | 264 | 0 | this.reportFile = reportFile; | 
            
  
    | 265 |  | } | 
            
  
    | 266 |  |  | 
            
  
    | 267 |  |  | 
            
  
    | 268 |  |  | 
            
  
    | 269 |  |  | 
            
  
    | 270 |  | @return | 
            
  
    | 271 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 272 | 0 |  public boolean isRunOnlyOnSchemaChange() {... | 
            
  
    | 273 | 0 | return runOnlyOnSchemaChange; | 
            
  
    | 274 |  | } | 
            
  
    | 275 |  |  | 
            
  
    | 276 |  |  | 
            
  
    | 277 |  |  | 
            
  
    | 278 |  |  | 
            
  
    | 279 |  | @param | 
            
  
    | 280 |  |  | 
            
  
    | 281 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 282 | 0 |  public void setRunOnlyOnSchemaChange(boolean runOnlyOnSchemaChange) {... | 
            
  
    | 283 | 0 | this.runOnlyOnSchemaChange = runOnlyOnSchemaChange; | 
            
  
    | 284 |  | } | 
            
  
    | 285 |  |  | 
            
  
    | 286 |  |  | 
            
  
    | 287 |  |  | 
            
  
    | 288 |  |  | 
            
  
    | 289 |  | @return | 
            
  
    | 290 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 291 | 0 |  public String getSchemaExcludes() {... | 
            
  
    | 292 | 0 | return schemaExcludes; | 
            
  
    | 293 |  | } | 
            
  
    | 294 |  |  | 
            
  
    | 295 |  |  | 
            
  
    | 296 |  |  | 
            
  
    | 297 |  |  | 
            
  
    | 298 |  | @param | 
            
  
    | 299 |  |  | 
            
  
    | 300 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 301 | 0 |  public void setSchemaExcludes(String schemaExcludes) {... | 
            
  
    | 302 | 0 | this.schemaExcludes = schemaExcludes; | 
            
  
    | 303 |  | } | 
            
  
    | 304 |  |  | 
            
  
    | 305 |  |  | 
            
  
    | 306 |  |  | 
            
  
    | 307 |  |  | 
            
  
    | 308 |  | @return | 
            
  
    | 309 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 310 | 0 |  public String getSchemaIncludes() {... | 
            
  
    | 311 | 0 | return schemaIncludes; | 
            
  
    | 312 |  | } | 
            
  
    | 313 |  |  | 
            
  
    | 314 |  |  | 
            
  
    | 315 |  |  | 
            
  
    | 316 |  |  | 
            
  
    | 317 |  | @param | 
            
  
    | 318 |  |  | 
            
  
    | 319 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 320 | 0 |  public void setSchemaIncludes(String schemaIncludes) {... | 
            
  
    | 321 | 0 | this.schemaIncludes = schemaIncludes; | 
            
  
    | 322 |  | } | 
            
  
    | 323 |  |  | 
            
  
    | 324 |  |  | 
            
  
    | 325 |  |  | 
            
  
    | 326 |  |  | 
            
  
    | 327 |  | @return | 
            
  
    | 328 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 329 | 0 |  public String getSqlDbMap() {... | 
            
  
    | 330 | 0 | return sqlDbMap; | 
            
  
    | 331 |  | } | 
            
  
    | 332 |  |  | 
            
  
    | 333 |  |  | 
            
  
    | 334 |  |  | 
            
  
    | 335 |  |  | 
            
  
    | 336 |  | @param | 
            
  
    | 337 |  |  | 
            
  
    | 338 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 339 | 0 |  public void setSqlDbMap(String sqlDbMap) {... | 
            
  
    | 340 | 0 | this.sqlDbMap = sqlDbMap; | 
            
  
    | 341 |  | } | 
            
  
    | 342 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 343 | 0 |  public String getUrl() {... | 
            
  
    | 344 | 0 | return url; | 
            
  
    | 345 |  | } | 
            
  
    | 346 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 347 | 0 |  public void setUrl(String url) {... | 
            
  
    | 348 | 0 | this.url = url; | 
            
  
    | 349 |  | } | 
            
  
    | 350 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 351 | 0 |  public String getSuffix() {... | 
            
  
    | 352 | 0 | return suffix; | 
            
  
    | 353 |  | } | 
            
  
    | 354 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 355 | 0 |  public void setSuffix(String suffix) {... | 
            
  
    | 356 | 0 | this.suffix = suffix; | 
            
  
    | 357 |  | } | 
            
  
    | 358 |  |  | 
            
  
    | 359 |  | } |