Bug fixing

In the previous sections, we exposed the basic concepts and steps to accomplish CI's flowchart in the form of versioning, tagging, unit testing, and releasing. To complete the release phase, however, we need to integrate the bug-reporting system in order to mark the issues fixed by the current release as released/resolved.

Hudson (or Jenkins) integrates several plugins for popular bug-tracking systems such as JIRA, MantisBT, and Bugzilla.

Note

Unfortunately, these plugins are not under continuous development and support only old versions.

In Chapter 3, Writing Plugins, we learned how to develop a plugin to update MySQL DB. We will now extend this plugin to integrate MantisBT.

A case study with MantisBT

MantisBT is a popular bug-tracking system for multiteam environments. Generally speaking, it is based on an internal relational DB (typically, MySQL) and some PHP pages.

When a new component is released, it is a good idea to mark all resolved bugs as released and assign the version numbers; this step concludes the final stage of the release process before proceeding to the functional tests.

Firstly, we need to configure the plugin developed in Chapter 3, Writing Plugins. In the pom.xml file of the main project, configure mantis-maven-plugin as follows:

<project>
   […]
   <build>
    <plugins>
     <plugin>
  <artifactId>mantis-maven-plugin</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <configuration>        <databaseUrl>${dbUrl}</databaseUrl>    <jdbcDriver>${dbDriver}</jdbcDriver>
  <projectId>${project.artifactId}</projectId>  <dbUserName>${usr}</dbUserName>
  <dbPassword>${pswd}</dbPassword>
  <databaseName>${dbName}</databaseName>
  </configuration>
     </plugin>
   </plugins>
   </build>
   […]
</project>

Parameters of the DB should be defined in the properties section. The plugin developed in Chapter 3, Writing Plugins, is a generic plugin that does not need database access implementation, but for our purpose, we need a utility class to work with the DB.

The following code provides a short implementation of the proposed utility:

public class MySqlAccess {
  /* Parameters are : bug_id, tag_id */
  private final String INSERT_INTO_MANTIS_BUG_TAG_TABLE = "INSERT INTO mantis_bug_tag_table(?, ?)";

  /* Parameters are : projectId   */
  private final String SELECT_FROM_MANTIS_BUG_TABLE = "SELECT id, tagId FROM mantis_bug_table where status=80 and project_id = ?";

  /* Parameters are : versionName, projectId */
  private final String UPDATE_MANTIS_BUG_TABLE = "UPDATE mantis_bug_table SET status=85, fixed_in_version=? where status=80 and project_id = ?";

  /* Parameters are : versionName, projectId */
  private final String UPDATE_MANTIS_BUG_TABLE_2 = "UPDATE mantis_bug_table SET status=90, fixed_in_version= ? where status!=90 and project_id = ? and (category_id=34 OR category_id=35)";

  private Connection connect = null;
  private Statement statement = null;
  private PreparedStatement preparedStatement = null;
  private ResultSet resultSet = null;
  private String userName;
  private String password;
  private String dbUrl;
  private String dbName;
  private String jdbcDriver;

  public MySqlAccess(String userName, 
String password, String dbUrl, String dbName, String jdbcDriver) throws SQLException, ClassNotFoundException {
    this.userName = userName;
    this.password = password;
    this.dbUrl = dbUrl;
    this.dbName = dbName;
    this.jdbcDriver = jdbcDriver;

  
          Class.forName(jdbcDriver);
    this.connect = DriverManager.getConnection("jdbc:mysql://" + dbUrl
          + "/" + dbName + "?" + "user=" + userName + " &password="+ password);
  }

  public void updateStatus(String versionName, String projectId) throws SQLException {
    
          preparedStatement = connect.prepareStatement(UPDATE_MANTIS_BUG_TABLE);

    preparedStatement.setString(1, "versionName");
    preparedStatement.setString(2, "projectId");
    preparedStatement.executeUpdate();

          preparedStatement = connect.prepareStatement(UPDATE_MANTIS_BUG_TABLE_2);

    preparedStatement.setString(1, "versionName");
    preparedStatement.setString(2, "projectId");
    preparedStatement.executeUpdate();
  }

  
  }

With these settings, we just implemented a simple way to finalize the release process. Keep in mind that a CI process should be easy, fast, and automatic; the basic idea is to shorten the distance between the development and test with continuous and automatic build and release cycles.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset