Week 6 (6/24 - 6/28)

This week, I reworked the task of converting the Defects4J bugs into Maven projects after discovering issues with my previous script. Then, I began working on the task of making all the patches pass their failed tests. To do this, I modified the source codes and then applied the patches to see if they would pass the tests.

Progress Update for this Week:

  • 6/25/2024
    • Discussing with Dr. Ghanbari, I realized that my previous script for converting projects to Maven form was incomplete. It lacked some essential components of a Maven project.
    • Researching on the internet, I discovered what constitutes a complete Maven project. A Maven project requires more than just a pom.xml file. It should also include the following directories:
      • src/main/java:
        • Purpose:
          • This directory is intended for the main Java source code of the application. It is where all the core functionality of the project is implemented.
        • Functions:
          • Houses all the Java classes and interfaces that form the application’s business logic.
          • The directory is organized into packages, which help in grouping related classes and managing the codebase efficiently.
          • During compilation process, the source code in this directory is transformed into bytecode and placed in the target/classes directory.
      • src/main/resources:
        • Purpose:
          • This directory contains non-Java resource files needed by the application. These can include configuration files, properties files, XML files, and other types of files that the application might need at runtime.
        • Functions:
          • Provides a central location for storing resources that the application will use during its execution.
          • Commonly used for configuration files (e.g., application.properties, log4j.properties) which control various aspects of the application’s behavior.
          • During the build process, these resources are copied to the same output directory as the compiled Java classes (target/classes), making them accessible at runtime.
      • src/test/java:
        • Purpose:
          • This directory is dedicated to Java test code. It contains the unit tests and integration tests for the application.
        • Functions:
          • Stores test classes that verify the functionality of the code in src/main/java. These tests are executed during the build process to ensure the correctness of the code.
          • Frameworks like JUnit are often used to write tests in this directory.
      • src/test/resources:
        • Purpose:
          • This directory contains resource files needed specifically for testing, such as test data or configuration files for tests.
        • Functions:
          • Stores resources required for executing tests, such as data files, mock configuration files, and other test-specific assets.
          • Resources in this directory are kept separate from the main application resources to ensure a clean separation between test and production environments.
          • During the test phase, these resources are copied to the target/test-classes directory, making them available to the test classes.
  • 6/26/2024
    • Applying the knowledge gained through research, I developed the following Bourne Shell Script to convert Defects4J bugs into Maven projects:

                                  # Define the base directory
                                  BASE_DIR="/home/jwangj001/patches-dataset"
                                          
                                  # Function to create a basic pom.xml file
                                  create_pom() {
                                      local project_dir=$1
                                      cat <<EOL > "$project_dir/pom.xml"
                                  <project xmlns="http://maven.apache.org/POM/4.0.0"
                                           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://www.w3.org/2001/XMLSchema-instance">
                                      <modelVersion>4.0.0</modelVersion>
                                          
                                      <groupId>com.example</groupId>
                                      <artifactId>$(basename "$project_dir")</artifactId>
                                      <version>1.0-SNAPSHOT</version>
                                          
                                      <properties>
                                          <maven.compiler.source>1.8</maven.compiler.source>
                                          <maven.compiler.target>1.8</maven.compiler.target>
                                      </properties>
                                          
                                      <dependencies>
                                          <dependency>
                                              <groupId>junit</groupId>
                                              <artifactId>junit</artifactId>
                                              <version>4.13.2</version>
                                              <scope>test</scope>
                                          </dependency>
                                          <!-- Add other dependencies here -->
                                      </dependencies>
                                          
                                      <build>
                                          <plugins>
                                              <plugin>
                                                  <groupId>org.apache.maven.plugins</groupId>
                                                  <artifactId>maven-compiler-plugin</artifactId>
                                                  <version>3.8.1</version>
                                                  <configuration>
                                                      <source>1.8</source>
                                                      <target>1.8</target>
                                                  </configuration>
                                              </plugin>
                                              <plugin>
                                                  <groupId>org.apache.maven.plugins</groupId>
                                                  <artifactId>maven-surefire-plugin</artifactId>
                                                  <version>2.22.2</version>
                                                  <configuration>
                                                      <includes>
                                                          <include>**/*Test.java</include>
                                                      </includes>
                                                  </configuration>
                                              </plugin>
                                              <plugin>
                                                  <groupId>org.pitest</groupId>
                                                  <artifactId>pitest-maven</artifactId>
                                                  <version>1.9.11</version>
                                                  <executions>
                                                      <execution>
                                                          <goals>
                                                              <goal>mutationCoverage</goal>
                                                          </goals>
                                                      </execution>
                                                  </executions>
                                                  <configuration>
                                                      <targetClasses>
                                                          <param>com.example.*</param>
                                                      </targetClasses>
                                                      <targetTests>
                                                          <param>com.example.*Test</param>
                                                      </targetTests>
                                                  </configuration>
                                              </plugin>
                                          </plugins>
                                      </build>
                                  </project>
                                  EOL
                                  }
                                          
                                  # Function to convert a project to Maven project form
                                  convert_to_maven_project() {
                                      local project_dir=$1
                                          
                                      # Create the pom.xml if it doesn't exist
                                      if [ ! -f "$project_dir/pom.xml" ]; then
                                          create_pom "$project_dir"
                                          echo "Created pom.xml in $project_dir."
                                      fi
                                          
                                      # Ensure the necessary Maven directories exist
                                      mkdir -p "$project_dir/src/main/java" "$project_dir/src/main/resources"
                                      mkdir -p "$project_dir/src/test/java" "$project_dir/src/test/resources"
                                          
                                      # Move java files to the appropriate Maven directories
                                      find "$project_dir" -maxdepth 1 -name "*.java" -exec mv {} "$project_dir/src/main/java/" \;
                                          
                                      echo "Converted $project_dir to Maven project form."
                                  }
                                          
                                  # Iterate over each directory in the base directory
                                  for project_dir in "$BASE_DIR"/*/; do
                                      convert_to_maven_project "$project_dir"
                                  done
                                          
                                  echo "Conversion completed."
      
    • Executing this script, I successfully converted all the Defects4J bugs into Maven projects.

  • 6/27/2024
    • Started working on the next task of ensuring all patches pass their test cases by modifying the buggy programs.
  • 6/28/2024
    • Continued the task from yesterday. I had a hard time getting the patches to pass their test cases, especially since I did not fully understand the source codes. I started to suspect that my approach of modifying the buggy programs might not be the correct approach.