Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/SukJinKim/AG-SZZ.git
Browse files Browse the repository at this point in the history
Conflicts:
	src/main/java/hgu/csee/isel/alinew/szz/trace/Tracer.java
  • Loading branch information
kimseokjin committed Jun 10, 2020
2 parents b16619d + 6f1b12e commit 0541a5d
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 88 deletions.
34 changes: 17 additions & 17 deletions src/main/java/hgu/csee/isel/alinew/szz/AGSZZ.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,56 +41,56 @@ public void run() throws IOException {
try {
// Clone
final String REMOTE_URI = GIT_URL + ".git";

// prepare a new folder for the cloned repository
localPath = File.createTempFile("TestGitRepository", "");
if (!localPath.delete()) {
throw new IOException("Could not delete temporary file " + localPath);
}

System.out.println("\nCloning from " + REMOTE_URI + " to " + localPath);

Git git = Git.cloneRepository()
.setURI(REMOTE_URI)
.setDirectory(localPath)
.call();
Git git = Git.cloneRepository().setURI(REMOTE_URI).setDirectory(localPath).call();

System.out.println("Having repository: " + git.getRepository().getDirectory());

Repository repo = git.getRepository();

// Pre-step for collecting BFCs
List<RevCommit> revs = GitUtils.getRevs(git);
List<String> issueKeys = Files.readAllLines(Paths.get(issueKeyFilePath), StandardCharsets.UTF_8);

// Colleting BFCs
ArrayList<RevCommit> bfcList = GitUtils.getBFCList(issueKeys, revs);

// Pre-step for building annotation graph
List<String> targetPaths = GitUtils.getTargetPaths(repo, bfcList);
RevsWithPath revsWithPath = GitUtils.collectRevsWithSpecificPath(GitUtils.configurePathRevisionList(repo, revs), targetPaths);

RevsWithPath revsWithPath = GitUtils
.collectRevsWithSpecificPath(GitUtils.configurePathRevisionList(repo, revs), targetPaths);

// Phase 1 : Build the annotation graph
final long startBuildingTime = System.currentTimeMillis();

AnnotationGraphBuilder agb = new AnnotationGraphBuilder();
AnnotationGraphModel agm = agb.buildAnnotationGraph(repo, revsWithPath, debug);

final long endBuildingTime = System.currentTimeMillis();
System.out.println("\nBuilding Annotation Graph takes " + (endBuildingTime - startBuildingTime) / 1000.0 + "s\n");
System.out.println(
"\nBuilding Annotation Graph takes " + (endBuildingTime - startBuildingTime) / 1000.0 + "s\n");

// Phase 2 : Trace and collect BIC candidates and filter out format changes, comments, etc among candidates
// Phase 2 : Trace and collect BIC candidates and filter out format changes,
// comments, etc among candidates
final long startTracingTime = System.currentTimeMillis();

Tracer tracer = new Tracer(analysis);
List<BICInfo> BILines = tracer.collectBILines(repo, bfcList, agm, revsWithPath, debug);

final long endTracingTime = System.currentTimeMillis();
System.out.println("\nCollecting BICs takes " + (endTracingTime - startTracingTime) / 1000.0 + "s\n");

// Sort BICs in the order FixSha1, BISha1, BIContent, biLineIdx
Collections.sort(BILines);

// Phase 3 : store outputs
Utils.storeOutputFile(GIT_URL, BILines);

Expand Down
45 changes: 14 additions & 31 deletions src/main/java/hgu/csee/isel/alinew/szz/AGSZZRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class AGSZZRunner {
public static void main(String[] args) {
AGSZZRunner agSZZRunner = new AGSZZRunner();
try {

agSZZRunner.run(args);

} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -35,34 +35,17 @@ public static void main(String[] args) {
private Options createOptions() {
Options options = new Options();

options.addOption(Option.builder("u")
.longOpt("url")
.desc("Git URL (ex. https://github.com/SukJinKim/AG-SZZ)")
.hasArg()
.required(true)
.build());

options.addOption(Option.builder("b")
.longOpt("bugFix")
.desc("Path of file that has bug fix issue keys")
.hasArg()
.required(true)
.build());

options.addOption(Option.builder("d")
.longOpt("debug")
.desc("Debug Mode")
.build());

options.addOption(Option.builder("a")
.longOpt("analysis")
.desc("Analysis Mode")
.build());

options.addOption(Option.builder("h")
.longOpt("help")
.desc("Help")
.build());
options.addOption(Option.builder("u").longOpt("url").desc("Git URL (ex. https://github.com/SukJinKim/AG-SZZ)")
.hasArg().required(true).build());

options.addOption(Option.builder("b").longOpt("bugFix").desc("Path of file that has bug fix issue keys")
.hasArg().required(true).build());

options.addOption(Option.builder("d").longOpt("debug").desc("Debug Mode").build());

options.addOption(Option.builder("a").longOpt("analysis").desc("Analysis Mode").build());

options.addOption(Option.builder("h").longOpt("help").desc("Help").build());

return options;
}
Expand Down Expand Up @@ -115,7 +98,7 @@ private void run(String[] args) throws IOException {
System.out.println("\tIssue Key File path : " + issueKeyFilePath);
System.out.println("\tDebug mode : " + debug);
System.out.println("\tAnalysis mode : " + analysis);

AGSZZ agSZZ = new AGSZZ(GIT_URL, issueKeyFilePath, debug, analysis);
agSZZ.run();

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hgu/csee/isel/alinew/szz/data/BICInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class BICInfo implements Comparable<BICInfo> {
String BIContent = "";
String commiter;
String author;

public BICInfo(String fixSha1, String path, String fixDate, Line line) {
super();
this.FixSha1 = fixSha1;
Expand All @@ -28,7 +28,7 @@ public BICInfo(String fixSha1, String path, String fixDate, Line line) {
this.commiter = line.getCommiter();
this.author = line.getAuthor();
}

// public void setLine(Line line) {
// this.BISha1 = line.getRev();
// this.biPath = line.getPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ public AnnotationGraphBuilderThread(Repository repo, RevsWithPath revsWithPath,
public void run() {
try {
partitionedAnnotationGraph = buildPartitionedAnnotationGraph(repo, revsWithPath, debug);

} catch (IOException | EmptyHunkTypeException e) {
e.printStackTrace();
} catch (IndexOutOfBoundsException e) {
// TODO Logging


}
}

private AnnotationGraphModel buildPartitionedAnnotationGraph(Repository repo, RevsWithPath revsWithPath, boolean debug)
throws IOException, EmptyHunkTypeException {
// Generate Annotation Graph
Expand All @@ -69,9 +69,9 @@ private AnnotationGraphModel buildPartitionedAnnotationGraph(Repository repo, Re
while (paths.hasNext()) {

String path = paths.next();

List<RevCommit> revs = revsWithPath.get(path);

// Skip building AG when the number of paths is 1 as it's not appropriate
if(revs.size() == 1) continue;

Expand All @@ -91,7 +91,7 @@ private AnnotationGraphModel buildPartitionedAnnotationGraph(Repository repo, Re
break;

RevCommit parentRev = revs.get(revs.indexOf(childRev) + 1);

String parentContent = Utils.removeComments(GitUtils.fetchBlob(repo, parentRev, path)).trim();
String childContent = Utils.removeComments(GitUtils.fetchBlob(repo, childRev, path)).trim();

Expand All @@ -100,7 +100,7 @@ private AnnotationGraphModel buildPartitionedAnnotationGraph(Repository repo, Re
System.out.println("\tparent rev : " + parentRev.getName());
System.out.println("\tchild rev : " + childRev.getName());
}


// get the parent line list from content
configureLineList(parentLineList, path, parentRev, parentContent);
Expand Down Expand Up @@ -306,7 +306,7 @@ private void configureLineList(ArrayList<Line> lst, String path, RevCommit rev,
String committer = rev.getCommitterIdent().getName();
String author = rev.getAuthorIdent().getName();
String StringDateTime = Utils.getStringDateTimeFromCommitTime(rev);

Line line = new Line(path, rev.getName(), contentArr[i], i, LineType.CONTEXT, ancestors, false, false, committer, author, StringDateTime);

lst.add(line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

import hgu.csee.isel.alinew.szz.model.Line;

public class AnnotationGraphModel extends HashMap<String, HashMap<RevCommit,ArrayList<Line>>>{
public class AnnotationGraphModel extends HashMap<String, HashMap<RevCommit, ArrayList<Line>>> {

}
2 changes: 1 addition & 1 deletion src/main/java/hgu/csee/isel/alinew/szz/model/Line.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Line {
private String commitDate;

public Line(String path, String rev, String content, int idx, LineType lineType, List<Line> ancestors,
boolean isFormatChange,boolean isWithinHunk, String commiter, String author, String commitDate) {
boolean isFormatChange, boolean isWithinHunk, String commiter, String author, String commitDate) {
super();
this.path = path;
this.rev = rev;
Expand Down
46 changes: 23 additions & 23 deletions src/main/java/hgu/csee/isel/alinew/szz/trace/Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Tracer {
private static ArrayList<Line> formatChangedLineList = new ArrayList<Line>();

static boolean flag = false;

public Tracer(boolean analysis) {
this.analysis = analysis;
}
Expand Down Expand Up @@ -67,14 +67,14 @@ public List<BICInfo> collectBILines(Repository repo, List<RevCommit> BFCList, An
// Ignore non-java file and test file
if (!path.endsWith(".java") || path.contains("test"))
continue;

// For Debugging
flag = (path.equals("zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java"));

if (debug || flag) {
System.out.println("\nParent Revision : " + parentRev.getName());
System.out.println("Child Revision (BFC) : " + BFC.getName());

System.out.println("\nChanged Path : " + path);
System.out.println("Graph contains " + path + "? " + annotationGraph.containsKey(path));

Expand Down Expand Up @@ -123,10 +123,10 @@ public List<BICInfo> collectBILines(Repository repo, List<RevCommit> BFCList, An

/*
* Get a revision just before BFC among changed revisions with path
*
*
* [REMARK] This list is sorted in chronological order.
*
* Latest ------------> Oldest
*
* Latest ------------> Oldest
* [][][][][][][][][][][][][][][]
*/
List<RevCommit> changeRevsWithPath = revsWithPath.get(path);
Expand Down Expand Up @@ -175,19 +175,19 @@ public List<BICInfo> collectBILines(Repository repo, List<RevCommit> BFCList, An
}
}
}
}
}

String fixSha1 = BFC.name() + "";
String fixDate = Utils.getStringDateTimeFromCommitTime(BFC);

for (Line line : BILines) {
BICInfo bicInfo = new BICInfo(fixSha1, path, fixDate, line);
bicList.add(bicInfo);
}

BILines.clear();
}
}
}
}

return bicList;
}
Expand All @@ -196,35 +196,35 @@ public void trace(Line line) {
if (!Utils.isWhitespace(line.getContent())) {
if(flag) {
System.out.println(String.format("Add line into BIC (Commit : %s, Line Idx : %s, content : %s, type : %s, cosmetic? : %s, in hunk? : %s\n"
, line.getRev(), line.getIdx(), line.getContent(), line.getLineType(), line.isFormatChange(), line.isWithinHunk()));
, line.getRev(), line.getIdx(), line.getContent(), line.getLineType(), line.isFormatChange(), line.isWithinHunk()));
}
BILines.add(line);
}
}

for (Line ancestor : line.getAncestors()) {
// Lines that are not white space, not format change, and within hunk are BI Lines.
if (!Utils.isWhitespace(ancestor.getContent())) {
if (ancestor.isFormatChange() || !ancestor.isWithinHunk()) {
// parent, child 표시
if(flag) {
System.out.println(String.format("From commit : %s, Lind idx : %s, content : %s, type : %s, cosmetic? : %s, in hunk? : %s\n=> To commit : %s, Lind idx : %s, content : %s, type : %s, cometic? : %s, in hunk? : %s",
System.out.println(String.format("From commit : %s, Lind idx : %s, content : %s, type : %s, cosmetic? : %s, in hunk? : %s\n=> To commit : %s, Lind idx : %s, content : %s, type : %s, cometic? : %s, in hunk? : %s",
line.getRev(), line.getIdx(), line.getContent(), line.getLineType(), line.isFormatChange(), line.isWithinHunk(),ancestor.getRev(), ancestor.getIdx(), ancestor.getContent(), ancestor.getLineType(), ancestor.isFormatChange(), ancestor.isWithinHunk()));

}
trace(ancestor);
} else {
if(flag) {
System.out.println(String.format("From commit : %s, Lind idx : %s, content : %s, type : %s, cosmetic? : %s, in hunk? : %s\n=>Add line into BIC (Commit : %s, Line Idx : %s, content : %s, type : %s, cosmetic? : %s, in hunk? : %s\n",
line.getRev(), line.getIdx(), line.getContent(), line.getLineType(), line.isFormatChange(), line.isWithinHunk(),ancestor.getRev(), ancestor.getIdx(), ancestor.getContent(), ancestor.getLineType(), ancestor.isFormatChange(), ancestor.isWithinHunk()));
line.getRev(), line.getIdx(), line.getContent(), line.getLineType(), line.isFormatChange(), line.isWithinHunk(),ancestor.getRev(), ancestor.getIdx(), ancestor.getContent(), ancestor.getLineType(), ancestor.isFormatChange(), ancestor.isWithinHunk()));
}
BILines.add(ancestor);
}
}
}

}

public void traceWithAnalysis(Line line, String BFC) {
for (Line ancestor : line.getAncestors()) {
// Lines that are not white space, not format change, and within hunk are BI Lines.
Expand All @@ -239,15 +239,15 @@ public void traceWithAnalysis(Line line, String BFC) {

formatChangedLineList.add(line);
}

traceWithAnalysis(ancestor, BFC);

} else if(!ancestor.isWithinHunk()) {
traceWithAnalysis(ancestor, BFC);

traceWithAnalysis(ancestor, BFC);
} else {
BILines.add(ancestor);
}
}
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/hgu/csee/isel/alinew/szz/util/GitUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static RevsWithPath collectRevsWithSpecificPath(List<PathRevision> pathRe
revsWithPath.put(path, lst);
}
}

return revsWithPath;
}

Expand Down Expand Up @@ -185,8 +185,9 @@ public static ArrayList<RevCommit> getBFCList(List<String> issueKeys, List<RevCo
HashSet<RevCommit> BFCSet = new HashSet<RevCommit>();

for (String issueKey : issueKeys) {
for (RevCommit rev : revs)
if (rev.getFullMessage().contains(issueKey)) BFCSet.add(rev);
for (RevCommit rev : revs)
if (rev.getFullMessage().contains(issueKey))
BFCSet.add(rev);
}

return new ArrayList<RevCommit>(BFCSet);
Expand All @@ -209,7 +210,7 @@ public static List<String> getTargetPaths(Repository repo, List<RevCommit> BFCLi
// get changed paths
for (DiffEntry diff : diffs) {
String path = diff.getNewPath();

// contains only files which are java files and not test files
if (path.endsWith(".java") && !path.contains("test")) {
targetPaths.add(path);
Expand Down

0 comments on commit 0541a5d

Please sign in to comment.