| 1 |  | package org.apache.torque.mojo; | 
            
  
    | 2 |  |  | 
            
  
    | 3 |  | import java.util.Properties; | 
            
  
    | 4 |  |  | 
            
  
    | 5 |  | import org.apache.maven.plugin.MojoExecutionException; | 
            
  
    | 6 |  | import org.apache.maven.settings.Server; | 
            
  
    | 7 |  | import org.kuali.db.DatabaseCommand; | 
            
  
    | 8 |  |  | 
            
  
    | 9 |  | import static org.apache.commons.lang.StringUtils.*; | 
            
  
    | 10 |  |  | 
            
  
    | 11 |  |  | 
            
  
    | 12 |  |  | 
            
  
    | 13 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 82 (82) | Complexity: 27 | Complexity Density: 0.6 |  | 
  
  
    | 14 |  | public abstract class AbstractDBACommandMojo extends AbstractSQLExecutorMojo { | 
            
  
    | 15 |  | public static final String DATABASE_PROPERTY = "database"; | 
            
  
    | 16 |  | public static final String DATABASE_PW_PROPERTY = "databasePassword"; | 
            
  
    | 17 |  | public static final String DATABASE_USERNAME_PROPERTY = "databaseUsername"; | 
            
  
    | 18 |  |  | 
            
  
    | 19 |  |  | 
            
  
    | 20 |  |  | 
            
  
    | 21 |  |  | 
            
  
    | 22 |  |  | 
            
  
    | 23 |  |  | 
            
  
    | 24 |  |  | 
            
  
    | 25 |  |  | 
            
  
    | 26 |  | String serverUrl; | 
            
  
    | 27 |  |  | 
            
  
    | 28 |  |  | 
            
  
    | 29 |  |  | 
            
  
    | 30 |  |  | 
            
  
    | 31 |  |  | 
            
  
    | 32 |  |  | 
            
  
    | 33 |  |  | 
            
  
    | 34 |  |  | 
            
  
    | 35 |  |  | 
            
  
    | 36 |  |  | 
            
  
    | 37 |  |  | 
            
  
    | 38 |  | String database; | 
            
  
    | 39 |  |  | 
            
  
    | 40 |  |  | 
            
  
    | 41 |  |  | 
            
  
    | 42 |  |  | 
            
  
    | 43 |  |  | 
            
  
    | 44 |  |  | 
            
  
    | 45 |  |  | 
            
  
    | 46 |  |  | 
            
  
    | 47 |  |  | 
            
  
    | 48 |  |  | 
            
  
    | 49 |  |  | 
            
  
    | 50 |  |  | 
            
  
    | 51 |  | String databaseUser; | 
            
  
    | 52 |  |  | 
            
  
    | 53 |  |  | 
            
  
    | 54 |  |  | 
            
  
    | 55 |  |  | 
            
  
    | 56 |  |  | 
            
  
    | 57 |  |  | 
            
  
    | 58 |  |  | 
            
  
    | 59 |  |  | 
            
  
    | 60 |  |  | 
            
  
    | 61 |  |  | 
            
  
    | 62 |  |  | 
            
  
    | 63 |  | String databasePassword; | 
            
  
    | 64 |  |  | 
            
  
    | 65 |  |  | 
            
  
    | 66 |  |  | 
            
  
    | 67 |  |  | 
            
  
    | 68 |  |  | 
            
  
    | 69 |  |  | 
            
  
    | 70 |  |  | 
            
  
    | 71 |  |  | 
            
  
    | 72 |  | String dbaSettingsKey; | 
            
  
    | 73 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 74 | 0 |  protected String getTransactionDescription(DatabaseCommand command) {... | 
            
  
    | 75 | 0 | return command + " " + getDatabase(); | 
            
  
    | 76 |  | } | 
            
  
    | 77 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 17 (17) | Complexity: 5 | Complexity Density: 0.56 |  | 
  
  
    | 78 | 0 |  protected void updateConfiguration() throws MojoExecutionException {... | 
            
  
    | 79 | 0 | super.updateConfiguration(); | 
            
  
    | 80 | 0 | if (isEmpty(database)) { | 
            
  
    | 81 | 0 | database = platform.getSchemaName(getProject().getArtifactId()); | 
            
  
    | 82 |  | } | 
            
  
    | 83 | 0 | if (isEmpty(databasePassword)) { | 
            
  
    | 84 | 0 | databasePassword = platform.getSchemaName(getProject().getArtifactId()); | 
            
  
    | 85 |  | } | 
            
  
    | 86 | 0 | if (isEmpty(databaseUser)) { | 
            
  
    | 87 | 0 | databaseUser = platform.getSchemaName(getProject().getArtifactId()); | 
            
  
    | 88 |  | } | 
            
  
    | 89 | 0 | if (isEmpty(serverUrl)) { | 
            
  
    | 90 | 0 | serverUrl = platform.getServerUrl(url); | 
            
  
    | 91 |  | } | 
            
  
    | 92 |  | } | 
            
  
    | 93 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 10 (10) | Complexity: 3 | Complexity Density: 0.5 |  | 
  
  
    | 94 | 0 |  @Override... | 
            
  
    | 95 |  | protected String getUpdatedPassword(Server server, String password) { | 
            
  
    | 96 |  |  | 
            
  
    | 97 | 0 | if (!isEmpty(password)) { | 
            
  
    | 98 | 0 | return password; | 
            
  
    | 99 |  | } | 
            
  
    | 100 | 0 | if (server != null) { | 
            
  
    | 101 |  |  | 
            
  
    | 102 | 0 | getLog().info("Located a password in settings.xml under the server id '" + server.getId() + "' Password: " + getDisplayPassword(server.getPassword())); | 
            
  
    | 103 | 0 | return server.getPassword(); | 
            
  
    | 104 |  | } | 
            
  
    | 105 |  |  | 
            
  
    | 106 | 0 | return null; | 
            
  
    | 107 |  | } | 
            
  
    | 108 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 10 (10) | Complexity: 3 | Complexity Density: 0.5 |  | 
  
  
    | 109 | 0 |  @Override... | 
            
  
    | 110 |  | protected String getUpdatedUsername(Server server, String username) { | 
            
  
    | 111 |  |  | 
            
  
    | 112 | 0 | if (!isEmpty(username)) { | 
            
  
    | 113 | 0 | return username; | 
            
  
    | 114 |  | } | 
            
  
    | 115 | 0 | if (server != null) { | 
            
  
    | 116 |  |  | 
            
  
    | 117 | 0 | getLog().info("Located a username in settings.xml under the server id '" + server.getId() + "' Username: " + server.getUsername()); | 
            
  
    | 118 | 0 | return server.getUsername(); | 
            
  
    | 119 |  | } | 
            
  
    | 120 |  |  | 
            
  
    | 121 | 0 | return null; | 
            
  
    | 122 |  | } | 
            
  
    | 123 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 5 (5) | Complexity: 1 | Complexity Density: 0.2 |  | 
  
  
    | 124 | 0 |  @Override... | 
            
  
    | 125 |  | protected Properties getContextProperties() { | 
            
  
    | 126 | 0 | Properties properties = super.getContextProperties(); | 
            
  
    | 127 | 0 | properties.setProperty(DATABASE_PROPERTY, getDatabase()); | 
            
  
    | 128 | 0 | properties.setProperty(DATABASE_PW_PROPERTY, getDatabasePassword()); | 
            
  
    | 129 | 0 | properties.setProperty(DATABASE_USERNAME_PROPERTY, getDatabaseUser()); | 
            
  
    | 130 | 0 | return properties; | 
            
  
    | 131 |  | } | 
            
  
    | 132 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 7 (7) | Complexity: 2 | Complexity Density: 0.4 |  | 
  
  
    | 133 | 0 |  @Override... | 
            
  
    | 134 |  | protected Server getServerFromSettingsKey() { | 
            
  
    | 135 | 0 | Server server = getSettings().getServer(dbaSettingsKey); | 
            
  
    | 136 | 0 | if (server != null) { | 
            
  
    | 137 | 0 | return server; | 
            
  
    | 138 |  | } | 
            
  
    | 139 |  |  | 
            
  
    | 140 | 0 | String settingsKey = "impex.dba." + getUrl(); | 
            
  
    | 141 | 0 | return getSettings().getServer(settingsKey); | 
            
  
    | 142 |  | } | 
            
  
    | 143 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 5 (5) | Complexity: 2 | Complexity Density: 0.67 |  | 
  
  
    | 144 | 0 |  @Override... | 
            
  
    | 145 |  | protected void validateConfiguration() throws MojoExecutionException { | 
            
  
    | 146 | 0 | super.validateConfiguration(); | 
            
  
    | 147 | 0 | if (isEmpty(database)) { | 
            
  
    | 148 | 0 | throw new MojoExecutionException("\n\nNo database was specified.\nSpecify a database in the plugin configuration or as a system property.\n\nFor example:\n-Ddatabase=MYDB\n\n."); | 
            
  
    | 149 |  | } | 
            
  
    | 150 |  | } | 
            
  
    | 151 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 152 | 0 |  public String getDatabase() {... | 
            
  
    | 153 | 0 | return database; | 
            
  
    | 154 |  | } | 
            
  
    | 155 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 156 | 0 |  public void setDatabase(String schema) {... | 
            
  
    | 157 | 0 | this.database = schema; | 
            
  
    | 158 |  | } | 
            
  
    | 159 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 160 | 0 |  public String getDatabasePassword() {... | 
            
  
    | 161 | 0 | return databasePassword; | 
            
  
    | 162 |  | } | 
            
  
    | 163 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 164 | 0 |  public void setDatabasePassword(String databasePassword) {... | 
            
  
    | 165 | 0 | this.databasePassword = databasePassword; | 
            
  
    | 166 |  | } | 
            
  
    | 167 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 168 | 0 |  public String getDatabaseUser() {... | 
            
  
    | 169 | 0 | return databaseUser; | 
            
  
    | 170 |  | } | 
            
  
    | 171 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 172 | 0 |  public void setDatabaseUser(String databaseUsername) {... | 
            
  
    | 173 | 0 | this.databaseUser = databaseUsername; | 
            
  
    | 174 |  | } | 
            
  
    | 175 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 176 | 0 |  public String getServerUrl() {... | 
            
  
    | 177 | 0 | return serverUrl; | 
            
  
    | 178 |  | } | 
            
  
    | 179 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 180 | 0 |  public void setServerUrl(String serverUrl) {... | 
            
  
    | 181 | 0 | this.serverUrl = serverUrl; | 
            
  
    | 182 |  | } | 
            
  
    | 183 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 184 | 0 |  public String getDbaSettingsKey() {... | 
            
  
    | 185 | 0 | return dbaSettingsKey; | 
            
  
    | 186 |  | } | 
            
  
    | 187 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 188 | 0 |  public void setDbaSettingsKey(String dbaSettingsKey) {... | 
            
  
    | 189 | 0 | this.dbaSettingsKey = dbaSettingsKey; | 
            
  
    | 190 |  | } | 
            
  
    | 191 |  | } |