Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace RMiner with GumTree for block tracking #1

Draft
wants to merge 63 commits into
base: coping-with-RMiner-changes
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
878e5da
sort changes in a commit based on change Type enum
flozender Jan 31, 2023
9500ced
change List to LinkedHashSet
flozender Feb 1, 2023
f8199c5
sort by ChangeType in case of identical CommitTime
flozender Feb 1, 2023
604d3a9
Merge branch 'coping-with-RMiner-changes' of https://github.com/floze…
flozender Feb 5, 2023
05e770a
Merge branch 'coping-with-RMiner-changes' of https://github.com/floze…
flozender Feb 21, 2023
214f96c
replace RMiner with GumTree for block tracking
flozender Feb 26, 2023
2ba3004
add expression change support
flozender Feb 28, 2023
928ee55
update tool name
flozender Feb 28, 2023
6504327
obtain mapping - block was mapped but not method
flozender Mar 1, 2023
7e0e227
switch from git checkout to file content
flozender Mar 1, 2023
82a5781
switch parameter position and clean up ranges
flozender Mar 2, 2023
6d85999
extend LineReader API
flozender Mar 2, 2023
37607be
add catch/finally change type detection
flozender Mar 2, 2023
5867716
improve matching for chains of if/else blocks
flozender Mar 7, 2023
ee7afcf
fix comment
flozender Mar 7, 2023
b8a32db
add move method support
flozender Mar 8, 2023
9835b3f
separate gumtree and regular block tracker
flozender Mar 8, 2023
ca52f7f
improve mapping for enhanced-for
flozender Mar 8, 2023
b9d44c4
fix NPE
flozender Mar 9, 2023
2e0cc2d
improve move method matching when file rename is not detected by git
flozender Mar 9, 2023
182b22e
improve matching for catch clause
flozender Mar 9, 2023
83c83e4
include finally block
flozender Mar 9, 2023
e384b33
Merge branch 'coping-with-RMiner-changes' of https://github.com/floze…
flozender Mar 10, 2023
f283bae
Merge branch 'coping-with-RMiner-changes' of https://github.com/floze…
flozender Mar 10, 2023
74af289
Merge branch 'sort-changes' of https://github.com/flozender/code-trac…
flozender Mar 10, 2023
52a0060
support tracking finally blocks
flozender Mar 11, 2023
47dac41
bug fix: finally block ch on wrong statement types
flozender Mar 15, 2023
8f87aaf
modify experiment to use gumtree
flozender Mar 15, 2023
8483fa0
fix missing insert/delete action cases
flozender Mar 20, 2023
7f004f6
fix missing expression changes
flozender Mar 23, 2023
beee687
get method moves from RMiner
flozender Mar 29, 2023
507247b
fix mapping order
flozender Mar 29, 2023
7b1e431
handle expression change for enhanced-for-loops
flozender Mar 29, 2023
50db134
handle special if case
flozender Mar 29, 2023
747d499
handle split class refactoring and improve recall
flozender Mar 29, 2023
3f2bafc
add caching for RMiner method move detection
flozender Mar 30, 2023
edab8d7
add cache of method move
flozender Mar 31, 2023
0c398e6
fix cache retrieval
flozender Mar 31, 2023
79891e1
experiment results
flozender Mar 31, 2023
40df566
retire the use of gumtree actions for changes
flozender Mar 31, 2023
64b9dfe
update experiment
flozender Mar 31, 2023
96ecc3a
Merge branch 'coping-with-RMiner-changes' of https://github.com/floze…
flozender Apr 4, 2023
121e4f4
fix set to linkedhashset merge
flozender Apr 4, 2023
6679ce9
fix type for miner
flozender Jul 25, 2023
f5f205a
update processIdenticalFiles() parameters
flozender Jul 26, 2023
cd42954
Merge branch 'update-RMiner-version' of https://github.com/flozender/…
flozender Jul 30, 2023
b483c8b
update oracle to final version
flozender Jul 30, 2023
3f9900b
fix NPE on blockBefore == null
flozender Jul 30, 2023
a315420
Merge branch 'fix-npe-beforeBlock' of https://github.com/flozender/co…
flozender Jul 30, 2023
4f0e7d3
fix incorrect history
flozender Jul 31, 2023
6314de1
checkpoint test experiment
flozender Jul 31, 2023
71cd6f3
add test file moves to cache
flozender Jul 31, 2023
d34666c
update cache
flozender Jul 31, 2023
8a18001
update cache
flozender Aug 1, 2023
19e02ac
final metrics
flozender Aug 1, 2023
e47a0e7
update oracle
flozender Oct 18, 2023
a6976e4
update cache
flozender Oct 19, 2023
be7d9dd
update precision and recall
flozender Oct 19, 2023
7280128
update oracle
flozender Nov 13, 2023
5a92ee5
add debugging statements
flozender Nov 13, 2023
83e929f
add historyreport tracking
flozender Nov 16, 2023
3b188f9
update experiment to add commit breakdown
flozender Nov 16, 2023
ff645e2
update oracle
flozender May 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ hs_err_pid*

# target folder
target/
result/
result/
tmp/
1,141 changes: 1,141 additions & 0 deletions experiments/tracking-accuracy/block/gumtree/detailed-gumtree-test.csv

Large diffs are not rendered by default.

5,566 changes: 5,566 additions & 0 deletions experiments/tracking-accuracy/block/gumtree/detailed-gumtree-training.csv

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions experiments/tracking-accuracy/block/gumtree/final.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tool,oracle,level,processing_time_avg,processing_time_median,tp,fp,fn,precision,recall
gumtree,training,change,23052.319502,14215,3928,498,1139,88.748305,77.521216
gumtree,training,commit,23052.319502,14215,3871,222,841,94.576106,82.151952
gumtree,test,change,5839.246835,3873,865,114,161,88.355465,84.307992
gumtree,test,commit,5839.246835,3873,862,51,89,94.414020,90.641430
3 changes: 3 additions & 0 deletions experiments/tracking-accuracy/block/gumtree/matcher-usage.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Oracle,Analyzed Commits,Staged Tree Matching,Default Matching,No Matching,Staged Tree Percentage,Default Percentage,No Matching Percentage
Training,57172,19,20681,36472,0.033233051,36.17330162,63.79346533
Test,15152,11,2416,12725,0.072597677,15.94508976,83.98231257
317 changes: 317 additions & 0 deletions experiments/tracking-accuracy/block/gumtree/processed-gumtree-test.csv

Large diffs are not rendered by default.

Large diffs are not rendered by default.

317 changes: 317 additions & 0 deletions experiments/tracking-accuracy/block/gumtree/summary-gumtree-test.csv

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>io.github.jodavimehran</groupId>
<artifactId>code-tracker</artifactId>
<packaging>jar</packaging>
<version>1.1</version>
<version>1.1-SNAPSHOT</version>
<name>Code Tracker</name>
<description>A refactoring-aware tool that can generate the commit change history of code elements with a very high accuracy.</description>
<url>https://github.com/jodavimehran/code-tracker</url>
Expand Down Expand Up @@ -36,7 +36,7 @@
<dependency>
<groupId>com.github.tsantalis</groupId>
<artifactId>refactoring-miner</artifactId>
<version>2.3.2</version>
<version>2.4.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -119,6 +119,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/codetracker/BaseTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ private CommitModel getCommitModel(RevCommit parentCommit1, RevCommit parentComm

Map<String, String> fileContentsBeforeTrimmed = new HashMap<>(fileContentsBefore);
Map<String, String> fileContentsCurrentTrimmed = new HashMap<>(fileContentsCurrent);
List<MoveSourceFolderRefactoring> moveSourceFolderRefactorings = GitHistoryRefactoringMinerImpl.processIdenticalFiles(fileContentsBeforeTrimmed, fileContentsCurrentTrimmed, renamedFilesHint);
List<MoveSourceFolderRefactoring> moveSourceFolderRefactorings = GitHistoryRefactoringMinerImpl.processIdenticalFiles(fileContentsBeforeTrimmed, fileContentsCurrentTrimmed, renamedFilesHint, false);

return new CommitModel(repositoryDirectoriesBefore, fileContentsBefore, fileContentsBeforeTrimmed, repositoryDirectoriesCurrent, fileContentsCurrent, fileContentsCurrentTrimmed, renamedFilesHint, moveSourceFolderRefactorings);
}
Expand Down
566 changes: 566 additions & 0 deletions src/main/java/org/codetracker/BlockTrackerGumTreeImpl.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/java/org/codetracker/BlockTrackerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ private Set<Block> analyseBlockRefactorings(Collection<Refactoring> refactorings
break;
}
}
if (changeType != null) {
if (changeType != null && blockBefore != null) {
if (equalOperator.test(blockAfter)) {
blockChangeHistory.addChange(blockBefore, blockAfter, ChangeFactory.forBlock(changeType).refactoring(refactoring));
leftBlockSet.add(blockBefore);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/codetracker/ChangeHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public Graph<T, Edge> findSubGraph(T start) {
return GraphImpl.subGraph(changeHistoryGraph, start);
}

public Graph<T, Edge> getCompleteGraph() {return GraphImpl.of(changeHistoryGraph);}

public Set<T> predecessors(T codeElement) {
return changeHistoryGraph.predecessors(codeElement);
}
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/org/codetracker/HistoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ public static class HistoryReportImpl implements HistoryReport {
private int step3 = 0;
private int step4 = 0;
private int step5 = 0;
private int stagedTreeMatching = 0;
private int sameFileUnchanged = 0;
private int sameFileChanged = 0;


public int getAnalysedCommits() {
return analysedCommits;
Expand Down Expand Up @@ -202,5 +206,29 @@ public void step4PlusPlus() {
public void step5PlusPlus() {
step5++;
}

public int getStagedTreeMatching() {
return stagedTreeMatching;
}

public void stagedTreeMatchingPlusPlus() {
stagedTreeMatching++;
}

public int getSameFileUnchanged() {
return sameFileUnchanged;
}

public void sameFileUnchangedPlusPlus() {
sameFileUnchanged++;
}

public int getSameFileChanged() {
return sameFileChanged;
}

public void sameFileChangedPlusPlus() {
sameFileChanged++;
}
}
}
80 changes: 14 additions & 66 deletions src/main/java/org/codetracker/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import org.codetracker.api.*;
import org.codetracker.change.Change;
import org.codetracker.element.Attribute;
import org.codetracker.element.Block;
import org.codetracker.element.Method;
import org.codetracker.element.Variable;
import org.codetracker.util.CodeElementLocator;
import gr.uom.java.xmi.LocationInfo;
import org.eclipse.jgit.lib.Repository;
import org.refactoringminer.api.GitService;
import org.refactoringminer.util.GitServiceImpl;
Expand All @@ -17,80 +20,25 @@ public class Main {

public static void main(String args[]) throws Exception {
GitService gitService = new GitServiceImpl();
// METHOD TRACKING EXAMPLE
try (Repository repository = gitService.cloneIfNotExists(FOLDER_TO_CLONE + "checkstyle\\checkstyle",
"https://github.com/checkstyle/checkstyle.git")){

MethodTracker methodTracker = CodeTracker.methodTracker()
.repository(repository)
.filePath("src/main/java/com/puppycrawl/tools/checkstyle/Checker.java")
.startCommitId("119fd4fb33bef9f5c66fc950396669af842c21a3")
.methodName("fireErrors")
.methodDeclarationLineNumber(384)
.build();

History<Method> methodHistory = methodTracker.track();

for (History.HistoryInfo<Method> historyInfo : methodHistory.getHistoryInfoList()) {
System.out.println("======================================================");
System.out.println("Commit ID: " + historyInfo.getCommitId());
System.out.println("Date: " +
LocalDateTime.ofEpochSecond(historyInfo.getCommitTime(), 0, ZoneOffset.UTC));
System.out.println("Before: " + historyInfo.getElementBefore().getName());
System.out.println("After: " + historyInfo.getElementAfter().getName());

for (Change change : historyInfo.getChangeList()) {
System.out.println(change.getType().getTitle() + ": " + change);
}
}
System.out.println("======================================================");
}
// VARIABLE TRACKING EXAMPLE
try (Repository repository = gitService.cloneIfNotExists(FOLDER_TO_CLONE + "checkstyle\\checkstyle",
"https://github.com/checkstyle/checkstyle.git")){

VariableTracker variableTracker = CodeTracker.variableTracker()
.repository(repository)
.filePath("src/main/java/com/puppycrawl/tools/checkstyle/Checker.java")
.startCommitId("119fd4fb33bef9f5c66fc950396669af842c21a3")
.methodName("fireErrors")
.methodDeclarationLineNumber(384)
.variableName("stripped")
.variableDeclarationLineNumber(385)
.build();

History<Variable> variableHistory = variableTracker.track();

for (History.HistoryInfo<Variable> historyInfo : variableHistory.getHistoryInfoList()) {
System.out.println("======================================================");
System.out.println("Commit ID: " + historyInfo.getCommitId());
System.out.println("Date: " +
LocalDateTime.ofEpochSecond(historyInfo.getCommitTime(), 0, ZoneOffset.UTC));
System.out.println("Before: " + historyInfo.getElementBefore().getName());
System.out.println("After: " + historyInfo.getElementAfter().getName());

for (Change change : historyInfo.getChangeList()) {
System.out.println(change.getType().getTitle() + ": " + change);
}
}
System.out.println("======================================================");
}

// ATTRIBUTE TRACKING EXAMPLE

// BLOCK TRACKING EXAMPLE
try (Repository repository = gitService.cloneIfNotExists(FOLDER_TO_CLONE + "checkstyle\\checkstyle",
"https://github.com/checkstyle/checkstyle.git")) {

AttributeTracker attributeTracker = CodeTracker.attributeTracker()
BlockTrackerGumTree blockTracker = CodeTracker.blockTrackerGumTree()
.repository(repository)
.filePath("src/main/java/com/puppycrawl/tools/checkstyle/Checker.java")
.filePath("src/main/java/com/puppycrawl/tools/checkstyle/Main.java")
.startCommitId("119fd4fb33bef9f5c66fc950396669af842c21a3")
.attributeName("cacheFile")
.attributeDeclarationLineNumber(132)
.methodName("main")
.methodDeclarationLineNumber(174)
.codeElementType(LocationInfo.CodeElementType.TRY_STATEMENT)
.blockStartLineNumber(188)
.blockEndLineNumber(243)
.build();

History<Attribute> attributeHistory = attributeTracker.track();
History<Block> blockHistory = blockTracker.track();

for (History.HistoryInfo<Attribute> historyInfo : attributeHistory.getHistoryInfoList()) {
for (History.HistoryInfo<Block> historyInfo : blockHistory.getHistoryInfoList()) {
System.out.println("======================================================");
System.out.println("Commit ID: " + historyInfo.getCommitId());
System.out.println("Date: " +
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/org/codetracker/api/BlockTrackerGumTree.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.codetracker.api;

import gr.uom.java.xmi.LocationInfo.CodeElementType;
import org.codetracker.element.Block;
import org.codetracker.BlockTrackerGumTreeImpl;
import org.codetracker.util.MethodCache;
import org.eclipse.jgit.lib.Repository;

public interface BlockTrackerGumTree extends CodeTracker {

History<Block> track() throws Exception;

class Builder {
private Repository repository;
private String startCommitId;
private String filePath;
private String methodName;
private int methodDeclarationLineNumber;
private CodeElementType codeElementType;
private int blockStartLineNumber;
private int blockEndLineNumber;
private MethodCache cache;

public BlockTrackerGumTree.Builder repository(Repository repository) {
this.repository = repository;
return this;
}

public BlockTrackerGumTree.Builder startCommitId(String startCommitId) {
this.startCommitId = startCommitId;
return this;
}

public BlockTrackerGumTree.Builder filePath(String filePath) {
this.filePath = filePath;
return this;
}

public BlockTrackerGumTree.Builder methodName(String methodName) {
this.methodName = methodName;
return this;
}

public BlockTrackerGumTree.Builder methodDeclarationLineNumber(int methodDeclarationLineNumber) {
this.methodDeclarationLineNumber = methodDeclarationLineNumber;
return this;
}

public Builder codeElementType(CodeElementType codeElementType) {
this.codeElementType = codeElementType;
return this;
}

public BlockTrackerGumTree.Builder blockStartLineNumber(int blockStartLineNumber) {
this.blockStartLineNumber = blockStartLineNumber;
return this;
}

public BlockTrackerGumTree.Builder blockEndLineNumber(int blockEndLineNumber) {
this.blockEndLineNumber = blockEndLineNumber;
return this;
}

public BlockTrackerGumTree.Builder cache(MethodCache cache) {
this.cache = cache;
return this;
}

private void checkInput() {

}

public BlockTrackerGumTree build() {
checkInput();
return new BlockTrackerGumTreeImpl(repository, startCommitId, filePath, methodName, methodDeclarationLineNumber,
codeElementType, blockStartLineNumber, blockEndLineNumber, cache);
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/org/codetracker/api/CodeTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ static BlockTracker.Builder blockTracker() {
return new BlockTracker.Builder();
}

static BlockTrackerGumTree.Builder blockTrackerGumTree() {
return new BlockTrackerGumTree.Builder();
}

static ClassTracker.Builder classTracker() {
return new ClassTracker.Builder();
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/codetracker/api/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ interface HistoryReport {
int getStep4();

int getStep5();

int getStagedTreeMatching();

int getSameFileUnchanged();

int getSameFileChanged();
}

interface HistoryInfo<C extends CodeElement> extends Comparable<HistoryInfo<C>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import static org.codetracker.util.FileUtil.writeToFile;

public abstract class AbstractExperimentStarter {
protected final static String FOLDER_TO_CLONE = "tmp/";
protected final static String FOLDER_TO_CLONE = "../CodeTracker-API/tmp/";
protected static final String SUMMARY_RESULT_FILE_NAME_FORMAT = "experiments/tracking-accuracy/%s/%s/summary-%s-%s.csv";
protected final static String SUMMARY_RESULT_HEADER;
protected static final String DETAILED_RESULT_HEADER = "file_name, repository,element_key,parent_commit_id,commit_id,commit_time, change_type,element_file_before,element_file_after,element_name_before,element_name_after,result,comment" + System.lineSeparator();
Expand All @@ -47,7 +47,7 @@ public abstract class AbstractExperimentStarter {

static {
StringBuilder header = new StringBuilder();
header.append("instance,processing_time,analysed_commits,git_log_command_calls,step2,step3,step4,step5,");
header.append("instance,processing_time,analysed_commits,stagedTreeMatching,sameFileChanged,sameFileUnchanged,");
for (Change.Type changeType : Change.Type.values()) {
if (Change.Type.NO_CHANGE.equals(changeType) || Change.Type.MULTI_CHANGE.equals(changeType) || Change.Type.REMOVED.equals(changeType))
continue;
Expand Down Expand Up @@ -282,11 +282,9 @@ protected <H extends AbstractHistoryInfo, E extends CodeElement> void codeTracke
content.append("\"").append(historyInfo.getElementKey()).append("\",")
.append(refactoringMinerProcessingTime).append(",")
.append(historyReport.getAnalysedCommits()).append(",")
.append(historyReport.getGitLogCommandCalls()).append(",")
.append(historyReport.getStep2()).append(",")
.append(historyReport.getStep3()).append(",")
.append(historyReport.getStep4()).append(",")
.append(historyReport.getStep5()).append(",")
.append(historyReport.getStagedTreeMatching()).append(",")
.append(historyReport.getSameFileChanged()).append(",")
.append(historyReport.getSameFileUnchanged()).append(",")
;

for (Change.Type changeType : Change.Type.values()) {
Expand Down
Loading