package refdiff.evaluation.c;

import java.util.Set;
import java.util.stream.Collectors;

import refdiff.core.diff.RastComparator;
import refdiff.core.diff.RastDiff;
import refdiff.core.diff.Relationship;
import refdiff.core.diff.RelationshipType;
import refdiff.evaluation.EvaluationUtils;
import refdiff.parsers.c.CParser;

public class RunRefDiffExample {
	
	public static void main(String[] args) throws Exception {
		
		CParser parser = new CParser();
		RastComparator rastComparator = new RastComparator(parser, parser);
		EvaluationUtils evaluationUtils = new EvaluationUtils(rastComparator, System.getProperty("java.io.tmpdir"));
		
		RastDiff diff = evaluationUtils.computeDiff("https://github.com/douban/beansdb.git", "e670a421928cfc5a842b355d096eb660d53743ea");
		
		Set<Relationship> relationships = diff.getRelationships().stream()
				.filter(relationship -> !relationship.getType().equals(RelationshipType.SAME))
				.collect(Collectors.toSet());
		
		System.out.println("Number of relationships found which are not of type SAME: " + relationships.size());
		
		relationships.stream()
			.forEach(relationship -> {System.out.println(relationship.toString());});
	}
	
}

@@ -22,24 +22,46 @@
 ation.c;%0D%0A%0D%0A
+import java.io.File;%0D%0A
 import java.
@@ -106,24 +106,67 @@
 lectors;%0D%0A%0D%0A
+import org.eclipse.jgit.lib.Repository;%0D%0A%0D%0A
 import refdi
@@ -334,33 +334,150 @@
 iff.
-evaluation.EvaluationUtil
+core.io.GitHelper;%0D%0Aimport refdiff.core.io.SourceFileSet;%0D%0Aimport refdiff.core.util.PairBeforeAfter;%0D%0Aimport refdiff.evaluation.ExternalProces
 s;%0D%0A
@@ -726,259 +726,685 @@
 %0D%0A%09%09
-EvaluationUtils evaluationUtils = new EvaluationUtils(rastComparator, System.getProperty(%22java.io.tmpdir%22));
+%0D%0A%09%09String tempFolder = %22D:/tmp%22;%0D%0A%09%09String cloneUrl = %22https://github.com/torvalds/linux.git%22;%0D%0A%09%09File repoFolder = new File(tempFolder, %22linux.git%22);%0D%0A%09%09%0D%0A%09%09if (!repoFolder.exists()) %7B%0D%0A%09%09%09ExternalProcess.execute(new File(tempFolder), %22git%22, %22clone%22, cloneUrl, repoFolder.getPath(), %22--bare%22, %22--depth=1000%22);%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09GitHelper gh = new GitHelper();%0D%0A%09%09try (Repository repo = gh.openRepository(repoFolder)) %7B
 %0D%0A%09%09
+%09
 %0D%0A%09%09
-RastDiff diff = evaluationUtils.computeDiff(%22https://github.com/douban/beansdb.git%22, %22e670a421928cfc5a842b355d096eb660d53743ea%22
+%09PairBeforeAfter%3CSourceFileSet%3E sources = gh.getSourcesBeforeAndAfterCommit(repo, %22f72c3ab791ac0b2b75b5b5d4d51d8eb89ea1e515%22, parser.getAllowedFileExtensions());%0D%0A%09%09%09RastDiff diff = rastComparator.compare(sources.getBefore(), sources.getAfter()
 );%0D%0A%09%09
+%09
 %0D%0A
+%09
 %09%09Se
@@ -1594,123 +1594,13 @@
 %0D%0A%09%09
-%0D%0A%09%09System.out.println(%22Number of relationships found which are not of type SAME: %22 + relationships.size());
+%09
 %0D%0A%09%09
-%0D%0A%09
 %09rel
@@ -1620,16 +1620,17 @@
 ream()%0D%0A
+%09
 %09%09%09.forE
@@ -1650,16 +1650,23 @@
 hip -%3E %7B
+%0D%0A%09%09%09%09%09
 System.o
@@ -1705,11 +1705,26 @@
 ());
-%7D);
+%0D%0A%09%09%09%09%7D);%0D%0A%09%09%7D%0D%0A%09%09
 %0D%0A%09%7D

Fix bug