| 1 | 
    
            
    
     | 
    
      package org.apache.torque.mojo;     | 
  
            
  
    | 2 | 
    
            
    
     | 
    
           | 
  
            
  
    | 3 | 
    
            
    
     | 
    
      import java.io.File;     | 
  
            
  
    | 4 | 
    
            
    
     | 
    
      import java.util.List;     | 
  
            
  
    | 5 | 
    
            
    
     | 
    
           | 
  
            
  
    | 6 | 
    
            
    
     | 
    
      import org.apache.commons.configuration.PropertiesConfiguration;     | 
  
            
  
    | 7 | 
    
            
    
     | 
    
      import org.apache.maven.plugin.MojoExecutionException;     | 
  
            
  
    | 8 | 
    
            
    
     | 
    
      import org.apache.torque.util.ChangeDetector;     | 
  
            
  
    | 9 | 
    
            
    
     | 
    
      import org.apache.torque.util.SimpleScanner;     | 
  
            
  
    | 10 | 
    
            
    
     | 
    
      import org.kuali.core.db.torque.KualiTorqueDataSQLTask;     | 
  
            
  
    | 11 | 
    
            
    
     | 
    
           | 
  
            
  
    | 12 | 
    
            
    
     | 
    
           | 
  
            
  
    | 13 | 
    
            
    
     | 
    
           | 
  
            
  
    | 14 | 
    
            
    
     | 
    
           | 
  
            
  
    | 15 | 
    
            
    
     | 
    
           | 
  
            
  
    | 16 | 
    
            
    
     | 
    
           | 
  
            
  
    | 17 | 
    
            
    
     | 
    
           | 
  
            
  
    | 18 | 
    
            
    
     | 
    
           | 
  
            
  
    | 19 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 60 (60) | 
           Complexity: 20 | 
           Complexity Density: 0.49 | 
                        
            
        | 
    
  
  
    | 20 | 
    
            
    
     | 
    
      public class DataSqlMojo extends DataModelTaskMojo {     | 
  
            
  
    | 21 | 
    
            
    
     | 
    
               | 
  
            
  
    | 22 | 
    
            
    
     | 
    
           | 
  
            
  
    | 23 | 
    
            
    
     | 
    
           | 
  
            
  
    | 24 | 
    
            
    
     | 
    
           | 
  
            
  
    | 25 | 
    
            
    
     | 
    
           | 
  
            
  
    | 26 | 
    
            
    
     | 
    
           | 
  
            
  
    | 27 | 
    
            
    
     | 
    
          @SuppressWarnings("unused")     | 
  
            
  
    | 28 | 
    
            
    
     | 
    
          private String dummy;     | 
  
            
  
    | 29 | 
    
            
    
     | 
    
           | 
  
            
  
    | 30 | 
    
            
    
     | 
    
               | 
  
            
  
    | 31 | 
    
            
    
     | 
    
           | 
  
            
  
    | 32 | 
    
            
    
     | 
    
           | 
  
            
  
    | 33 | 
    
            
    
     | 
    
           | 
  
            
  
    | 34 | 
    
            
    
     | 
    
           | 
  
            
  
    | 35 | 
    
            
    
     | 
    
           | 
  
            
  
    | 36 | 
    
            
    
     | 
    
          @SuppressWarnings("unused")     | 
  
            
  
    | 37 | 
    
            
    
     | 
    
          private String dummy2;     | 
  
            
  
    | 38 | 
    
            
    
     | 
    
           | 
  
            
  
    | 39 | 
    
            
    
     | 
    
               | 
  
            
  
    | 40 | 
    
            
    
     | 
    
           | 
  
            
  
    | 41 | 
    
            
    
     | 
    
           | 
  
            
  
    | 42 | 
    
            
    
     | 
    
           | 
  
            
  
    | 43 | 
    
            
    
     | 
    
           | 
  
            
  
    | 44 | 
    
            
    
     | 
    
           | 
  
            
  
    | 45 | 
    
            
    
     | 
    
          @SuppressWarnings("unused")     | 
  
            
  
    | 46 | 
    
            
    
     | 
    
          private String dummy3;     | 
  
            
  
    | 47 | 
    
            
    
     | 
    
           | 
  
            
  
    | 48 | 
    
            
    
     | 
    
               | 
  
            
  
    | 49 | 
    
            
    
     | 
    
           | 
  
            
  
    | 50 | 
    
            
    
     | 
    
           | 
  
            
  
    | 51 | 
    
            
    
     | 
    
           | 
  
            
  
    | 52 | 
    
            
    
     | 
    
           | 
  
            
  
    | 53 | 
    
            
    
     | 
    
           | 
  
            
  
    | 54 | 
    
            
    
     | 
    
          private boolean runOnlyOnChange;     | 
  
            
  
    | 55 | 
    
            
    
     | 
    
           | 
  
            
  
    | 56 | 
    
            
    
     | 
    
               | 
  
            
  
    | 57 | 
    
            
    
     | 
    
           | 
  
            
  
    | 58 | 
    
            
    
     | 
    
           | 
  
            
  
    | 59 | 
    
            
    
     | 
    
           | 
  
            
  
    | 60 | 
    
            
    
     | 
    
           | 
  
            
  
    | 61 | 
    
            
    
     | 
    
           | 
  
            
  
    | 62 | 
    
            
    
     | 
    
          private File schemaXMLFile;     | 
  
            
  
    | 63 | 
    
            
    
     | 
    
           | 
  
            
  
    | 64 | 
    
            
    
     | 
    
               | 
  
            
  
    | 65 | 
    
            
    
     | 
    
           | 
  
            
  
    | 66 | 
    
            
    
     | 
    
           | 
  
            
  
    | 67 | 
    
            
    
     | 
    
           | 
  
            
  
    | 68 | 
    
            
    
     | 
    
           | 
  
            
  
    | 69 | 
    
            
    
     | 
    
           | 
  
            
  
    | 70 | 
    
            
    
     | 
    
          private File dataXMLDir;     | 
  
            
  
    | 71 | 
    
            
    
     | 
    
           | 
  
            
  
    | 72 | 
    
            
    
     | 
    
               | 
  
            
  
    | 73 | 
    
            
    
     | 
    
           | 
  
            
  
    | 74 | 
    
            
    
     | 
    
           | 
  
            
  
    | 75 | 
    
            
    
     | 
    
           | 
  
            
  
    | 76 | 
    
            
    
     | 
    
           | 
  
            
  
    | 77 | 
    
            
    
     | 
    
           | 
  
            
  
    | 78 | 
    
            
    
     | 
    
          private String dataXMLIncludes;     | 
  
            
  
    | 79 | 
    
            
    
     | 
    
           | 
  
            
  
    | 80 | 
    
            
    
     | 
    
               | 
  
            
  
    | 81 | 
    
            
    
     | 
    
           | 
  
            
  
    | 82 | 
    
            
    
     | 
    
           | 
  
            
  
    | 83 | 
    
            
    
     | 
    
           | 
  
            
  
    | 84 | 
    
            
    
     | 
    
           | 
  
            
  
    | 85 | 
    
            
    
     | 
    
          private String dataXMLExcludes;     | 
  
            
  
    | 86 | 
    
            
    
     | 
    
           | 
  
            
  
    | 87 | 
    
            
    
     | 
    
               | 
  
            
  
    | 88 | 
    
            
    
     | 
    
           | 
  
            
  
    | 89 | 
    
            
    
     | 
    
           | 
  
            
  
    | 90 | 
    
            
    
     | 
    
           | 
  
            
  
    | 91 | 
    
            
    
     | 
    
           | 
  
            
  
    | 92 | 
    
            
    
     | 
    
           | 
  
            
  
    | 93 | 
    
            
    
     | 
    
           | 
  
            
  
    | 94 | 
    
            
    
     | 
    
          private File dataDTD;     | 
  
            
  
    | 95 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 19 (19) | 
           Complexity: 4 | 
           Complexity Density: 0.24 | 
                        
            
        | 
    
  
  
    | 96 | 
    
           0
    
     | 
    
           @Override...     | 
  
            
  
    | 97 | 
    
            
    
     | 
    
          public void executeMojo() throws MojoExecutionException {     | 
  
            
  
    | 98 | 
    
            
    
     | 
    
                   | 
  
            
  
    | 99 | 
    
           0
    
     | 
    
              updateConfiguration();     | 
  
            
  
    | 100 | 
    
           0
    
     | 
    
              validateConfiguration();     | 
  
            
  
    | 101 | 
    
           0
    
     | 
    
              generateContextProperties();     | 
  
            
  
    | 102 | 
    
           0
    
     | 
    
              configureTask();     | 
  
            
  
    | 103 | 
    
           0
    
     | 
    
              addTargetDatabaseToOutputDir();     | 
  
            
  
    | 104 | 
    
           0
    
     | 
    
              addTargetDatabaseToReportFile();     | 
  
            
  
    | 105 | 
    
           0
    
     | 
    
              ChangeDetector schema = new ChangeDetector(getCanonicalReportFile(), getSchemaFiles());     | 
  
            
  
    | 106 | 
    
           0
    
     | 
    
              ChangeDetector data = new ChangeDetector(getCanonicalReportFile(), getDataFiles());     | 
  
            
  
    | 107 | 
    
           0
    
     | 
    
              if (!schema.isChanged() && !data.isChanged() && isRunOnlyOnChange()) {     | 
  
            
  
    | 108 | 
    
           0
    
     | 
    
                  getLog().info("------------------------------------------------------------------------");     | 
  
            
  
    | 109 | 
    
           0
    
     | 
    
                  getLog().info("Data and schema are unchanged.  Skipping generation.");     | 
  
            
  
    | 110 | 
    
           0
    
     | 
    
                  getLog().info("------------------------------------------------------------------------");     | 
  
            
  
    | 111 | 
    
           0
    
     | 
    
                  return;     | 
  
            
  
    | 112 | 
    
            
    
     | 
    
              }     | 
  
            
  
    | 113 | 
    
           0
    
     | 
    
              getLog().info("------------------------------------------------------------------------");     | 
  
            
  
    | 114 | 
    
           0
    
     | 
    
              getLog().info("Generating SQL for " + getTargetDatabase() + " from data XML files");     | 
  
            
  
    | 115 | 
    
           0
    
     | 
    
              getLog().info("------------------------------------------------------------------------");     | 
  
            
  
    | 116 | 
    
           0
    
     | 
    
              getAntTask().execute();     | 
  
            
  
    | 117 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 118 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 1 (1) | 
           Complexity: 1 | 
           Complexity Density: 1 | 
                        
            
        | 
    
  
  
    | 119 | 
    
           0
    
     | 
    
           protected List<File> getDataFiles() {...     | 
  
            
  
    | 120 | 
    
           0
    
     | 
    
              return new SimpleScanner(getDataXMLDir(), getDataXMLIncludes(), getDataXMLExcludes()).getFiles();     | 
  
            
  
    | 121 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 122 | 
    
            
    
     | 
    
           | 
  
            
  
    | 123 | 
    
            
    
     | 
    
               | 
  
            
  
    | 124 | 
    
            
    
     | 
    
           | 
  
            
  
    | 125 | 
    
            
    
     | 
    
           | 
  
            
  
    | 126 | 
    
            
    
     | 
    
      @return     | 
  
            
  
    | 127 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 3 (3) | 
           Complexity: 1 | 
           Complexity Density: 0.33 | 
                        
            
        | 
    
  
  
    | 128 | 
    
           0
    
     | 
    
           protected PropertiesConfiguration getMojoContextProperties() {...     | 
  
            
  
    | 129 | 
    
           0
    
     | 
    
              PropertiesConfiguration configuration = new PropertiesConfiguration();     | 
  
            
  
    | 130 | 
    
           0
    
     | 
    
              configuration.addProperty(TARGET_DATABASE_CONTEXT_PROPERTY, super.getTargetDatabase());     | 
  
            
  
    | 131 | 
    
           0
    
     | 
    
              return configuration;     | 
  
            
  
    | 132 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 133 | 
    
            
    
     | 
    
           | 
  
            
  
    | 134 | 
    
            
    
     | 
    
               | 
  
            
  
    | 135 | 
    
            
    
     | 
    
           | 
  
            
  
    | 136 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 7 (7) | 
           Complexity: 1 | 
           Complexity Density: 0.14 | 
                        
            
        | 
    
  
  
    | 137 | 
    
           0
    
     | 
    
           protected void configureTask() throws MojoExecutionException {...     | 
  
            
  
    | 138 | 
    
           0
    
     | 
    
              KualiTorqueDataSQLTask task = new KualiTorqueDataSQLTask();     | 
  
            
  
    | 139 | 
    
           0
    
     | 
    
              setAntTask(task);     | 
  
            
  
    | 140 | 
    
           0
    
     | 
    
              super.configureTask();     | 
  
            
  
    | 141 | 
    
           0
    
     | 
    
              task.setDataDTD(getDataDTD());     | 
  
            
  
    | 142 | 
    
           0
    
     | 
    
              task.addFileset(getAntFileSet(getDataXMLDir(), getDataXMLIncludes(), getDataXMLExcludes()));     | 
  
            
  
    | 143 | 
    
           0
    
     | 
    
              task.setXmlFile(getSchemaXMLFile().getAbsolutePath());     | 
  
            
  
    | 144 | 
    
           0
    
     | 
    
              task.setTargetDatabase(getTargetDatabase());     | 
  
            
  
    | 145 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 146 | 
    
            
    
     | 
    
           | 
  
            
  
    | 147 | 
    
            
    
     | 
    
               | 
  
            
  
    | 148 | 
    
            
    
     | 
    
           | 
  
            
  
    | 149 | 
    
            
    
     | 
    
           | 
  
            
  
    | 150 | 
    
            
    
     | 
    
      @return     | 
  
            
  
    | 151 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 1 (1) | 
           Complexity: 1 | 
           Complexity Density: 1 | 
                        
            
        | 
    
  
  
    | 152 | 
    
           0
    
     | 
    
           protected String getControlTemplate() {...     | 
  
            
  
    | 153 | 
    
           0
    
     | 
    
              return "sql/load/Control.vm";     | 
  
            
  
    | 154 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 155 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 1 (1) | 
           Complexity: 1 | 
           Complexity Density: 1 | 
                        
            
        | 
    
  
  
    | 156 | 
    
           0
    
     | 
    
           public String getDataXMLIncludes() {...     | 
  
            
  
    | 157 | 
    
           0
    
     | 
    
              return dataXMLIncludes;     | 
  
            
  
    | 158 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 159 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 1 (1) | 
           Complexity: 1 | 
           Complexity Density: 1 | 
                        
            
        | 
    
  
  
    | 160 | 
    
           0
    
     | 
    
           public void setDataXMLIncludes(String dataXMLIncludes) {...     | 
  
            
  
    | 161 | 
    
           0
    
     | 
    
              this.dataXMLIncludes = dataXMLIncludes;     | 
  
            
  
    | 162 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 163 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 1 (1) | 
           Complexity: 1 | 
           Complexity Density: 1 | 
                        
            
        | 
    
  
  
    | 164 | 
    
           0
    
     | 
    
           public String getDataXMLExcludes() {...     | 
  
            
  
    | 165 | 
    
           0
    
     | 
    
              return dataXMLExcludes;     | 
  
            
  
    | 166 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 167 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 1 (1) | 
           Complexity: 1 | 
           Complexity Density: 1 | 
                        
            
        | 
    
  
  
    | 168 | 
    
           0
    
     | 
    
           public void setDataXMLExcludes(String dataXMLExcludes) {...     | 
  
            
  
    | 169 | 
    
           0
    
     | 
    
              this.dataXMLExcludes = dataXMLExcludes;     | 
  
            
  
    | 170 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 171 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 1 (1) | 
           Complexity: 1 | 
           Complexity Density: 1 | 
                        
            
        | 
    
  
  
    | 172 | 
    
           0
    
     | 
    
           public File getDataXMLDir() {...     | 
  
            
  
    | 173 | 
    
           0
    
     | 
    
              return dataXMLDir;     | 
  
            
  
    | 174 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 175 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 1 (1) | 
           Complexity: 1 | 
           Complexity Density: 1 | 
                        
            
        | 
    
  
  
    | 176 | 
    
           0
    
     | 
    
           public void setDataXMLDir(File dataXMLDir) {...     | 
  
            
  
    | 177 | 
    
           0
    
     | 
    
              this.dataXMLDir = dataXMLDir;     | 
  
            
  
    | 178 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 179 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 1 (1) | 
           Complexity: 1 | 
           Complexity Density: 1 | 
                        
            
        | 
    
  
  
    | 180 | 
    
           0
    
     | 
    
           public File getSchemaXMLFile() {...     | 
  
            
  
    | 181 | 
    
           0
    
     | 
    
              return schemaXMLFile;     | 
  
            
  
    | 182 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 183 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 1 (1) | 
           Complexity: 1 | 
           Complexity Density: 1 | 
                        
            
        | 
    
  
  
    | 184 | 
    
           0
    
     | 
    
           public void setSchemaXMLFile(File schemaXMLFile) {...     | 
  
            
  
    | 185 | 
    
           0
    
     | 
    
              this.schemaXMLFile = schemaXMLFile;     | 
  
            
  
    | 186 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 187 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 1 (1) | 
           Complexity: 1 | 
           Complexity Density: 1 | 
                        
            
        | 
    
  
  
    | 188 | 
    
           0
    
     | 
    
           public boolean isRunOnlyOnChange() {...     | 
  
            
  
    | 189 | 
    
           0
    
     | 
    
              return runOnlyOnChange;     | 
  
            
  
    | 190 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 191 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 1 (1) | 
           Complexity: 1 | 
           Complexity Density: 1 | 
                        
            
        | 
    
  
  
    | 192 | 
    
           0
    
     | 
    
           public void setRunOnlyOnChange(boolean runOnlyOnDataChange) {...     | 
  
            
  
    | 193 | 
    
           0
    
     | 
    
              this.runOnlyOnChange = runOnlyOnDataChange;     | 
  
            
  
    | 194 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 195 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 1 (1) | 
           Complexity: 1 | 
           Complexity Density: 1 | 
                        
            
        | 
    
  
  
    | 196 | 
    
           0
    
     | 
    
           public File getDataDTD() {...     | 
  
            
  
    | 197 | 
    
           0
    
     | 
    
              return dataDTD;     | 
  
            
  
    | 198 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 199 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 1 (1) | 
           Complexity: 1 | 
           Complexity Density: 1 | 
                        
            
        | 
    
  
  
    | 200 | 
    
           0
    
     | 
    
           public void setDataDTD(File dataDTD) {...     | 
  
            
  
    | 201 | 
    
           0
    
     | 
    
              this.dataDTD = dataDTD;     | 
  
            
  
    | 202 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 203 | 
    
            
    
     | 
    
           | 
  
            
  
    | 204 | 
    
            
    
     | 
    
      }     |