fix java version

This commit is contained in:
fixminer
2020-03-05 17:24:37 +01:00
parent 1daf627515
commit 2ea971f3e5
14 changed files with 163 additions and 101 deletions
@@ -8,6 +8,8 @@ import org.slf4j.LoggerFactory;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Properties; import java.util.Properties;
/** /**
@@ -22,16 +24,33 @@ public class Launcher {
Properties appProps = new Properties(); Properties appProps = new Properties();
String appConfigPath = "src/main/resource/app.properties"; String hostname = "Unknown";
try
{
InetAddress addr;
addr = InetAddress.getLocalHost();
hostname = addr.getHostName();
}
catch (UnknownHostException ex)
{
System.out.println("Hostname can not be resolved");
}
String appConfigPath;
if (hostname.equals("Unknown")){
appConfigPath = "src/main/resource/app.properties";
}
else{
appConfigPath = "src/main/resource/"+hostname+".app.properties";
}
// String appConfigPath = args[0]; // String appConfigPath = args[0];
appProps.load(new FileInputStream(appConfigPath)); appProps.load(new FileInputStream(appConfigPath));
String numOfWorkers = appProps.getProperty("numOfWorkers", "10"); String numOfWorkers = appProps.getProperty("numOfWorkers", "10");
String portDumps = appProps.getProperty("portDumps","6399"); String portDumps = appProps.getProperty("portDumps","6399");
String pjName = appProps.getProperty("pjName","allDataset"); String pjName = appProps.getProperty("pjName","allDataset");
String actionType = appProps.getProperty("actionType","ALL"); String projectType = appProps.getProperty("projectType","java");
String hostname = appProps.getProperty("hostname","localhost"); // String hostname = appProps.getProperty("hostname","localhost");
String hunkLimit = appProps.getProperty("hunkLimit","10"); String hunkLimit = appProps.getProperty("hunkLimit","10");
String patchSize = appProps.getProperty("patchSize","50"); String patchSize = appProps.getProperty("patchSize","50");
String projectL = appProps.getProperty("projectList",""); String projectL = appProps.getProperty("projectList","");
@@ -45,9 +64,8 @@ public class Launcher {
// String parameter = "if"; // String parameter = "if";
// String parameter = "add"; // String parameter = "add";
// String jobType = args[1]; // String jobType = args[1];
String jobType = "RICHEDITSCRIPT"; // String jobType = "RICHEDITSCRIPT";
// String jobType = "LOAD"; String jobType = "COMPARE";
// String jobType = "COMPARE";
// String parameters = String.format("\nportInner %s " + // String parameters = String.format("\nportInner %s " +
// "\nnumOfWorkers %s " + // "\nnumOfWorkers %s " +
@@ -58,12 +76,12 @@ public class Launcher {
// //
// log.info(parameters); // log.info(parameters);
mainLaunch( numOfWorkers, jobType, portDumps, pjName,actionType,input,redisPath,parameter, srcMLPath,hostname,hunkLimit,projectList,patchSize); mainLaunch( numOfWorkers, jobType, portDumps, pjName,projectType,input,redisPath,parameter, srcMLPath,hostname,hunkLimit,projectList,patchSize);
} }
public static void mainLaunch(String numOfWorkers, String jobType, String portDumps, String pjName, String actionType, String input, String redisPath,String parameter,String srcMLPath,String hostname,String hunkLimit,String[] projectList,String patchSize){ public static void mainLaunch(String numOfWorkers, String jobType, String portDumps, String pjName, String projectType, String input, String redisPath,String parameter,String srcMLPath,String hostname,String hunkLimit,String[] projectList,String patchSize){
String dbDir; String dbDir;
@@ -79,7 +97,7 @@ public class Launcher {
try { try {
switch (jobType) { switch (jobType) {
case "RICHEDITSCRIPT": case "RICHEDITSCRIPT":
EnhancedASTDiff.main(gumInput, pjName, portDumps, dbDir, actionType+dumpsName, srcMLPath,parameter,hunkLimit,projectList,patchSize); EnhancedASTDiff.main(gumInput, pjName, portDumps, dbDir, dumpsName, srcMLPath,parameter,hunkLimit,projectList,patchSize,projectType);
break; break;
case "COMPARE": case "COMPARE":
@@ -104,10 +122,10 @@ public class Launcher {
} }
CompareTrees.main(redisPath, portDumps,actionType+dumpsName, job,numOfWorkers,hostname); CompareTrees.main(redisPath, portDumps,dumpsName, job,numOfWorkers,hostname);
break; break;
case "PATTERN": case "PATTERN":
ClusterToPattern.main(portDumps,redisPath, actionType+dumpsName, parameter); ClusterToPattern.main(portDumps,redisPath, dumpsName, parameter);
break; break;
default: default:
throw new Error("unknown Job"); throw new Error("unknown Job");
@@ -22,7 +22,7 @@ public class EDiffHunkParser extends EDiffParser {
private static Logger logger = LoggerFactory.getLogger(EDiffHunkParser.class); private static Logger logger = LoggerFactory.getLogger(EDiffHunkParser.class);
@Override @Override
public void parseFixPatterns(File prevFile, File revFile, File diffentryFile, String project, JedisPool innerPool,String srcMLPath,String hunkLimit) { public void parseFixPatterns(File prevFile, File revFile, File diffentryFile, String project, JedisPool innerPool,String srcMLPath,String hunkLimit,boolean isJava) {
String datasetName = project; String datasetName = project;
String[] split1 = diffentryFile.getParent().split(datasetName); String[] split1 = diffentryFile.getParent().split(datasetName);
@@ -30,7 +30,7 @@ public class EDiffHunkParser extends EDiffParser {
String pj = split1[1].split("/")[1]; String pj = split1[1].split("/")[1];
List<HierarchicalActionSet> actionSets = parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); List<HierarchicalActionSet> actionSets = parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,isJava);
if (actionSets != null && actionSets.size() != 0) { if (actionSets != null && actionSets.size() != 0) {
@@ -59,9 +59,9 @@ public class EDiffHunkParser extends EDiffParser {
String key = astNodeType + "/" + String.valueOf(size) + "/" + pj + "_" + diffentryFile.getName() + "_" + String.valueOf(hunkSet); String key = astNodeType + "/" + String.valueOf(size) + "/" + pj + "_" + diffentryFile.getName() + "_" + String.valueOf(hunkSet);
ITree targetTree = EDiffHelper.getTargets(actionSet); ITree targetTree = EDiffHelper.getTargets(actionSet,isJava);
ITree actionTree = EDiffHelper.getActionTrees(actionSet); ITree actionTree = EDiffHelper.getActionTrees(actionSet);
ITree shapeTree = EDiffHelper.getShapeTree(actionSet); ITree shapeTree = EDiffHelper.getShapeTree(actionSet,isJava);
try (Jedis inner = innerPool.getResource()) { try (Jedis inner = innerPool.getResource()) {
inner.hset("dump", key, actionSet.toString()); inner.hset("dump", key, actionSet.toString());
@@ -39,21 +39,21 @@ public class EDiffParser extends Parser {
* @param revFile * @param revFile
* @return * @return
*/ */
protected List<HierarchicalActionSet> parseChangedSourceCodeWithGumTree2(File prevFile, File revFile,String srcMLPath) { protected List<HierarchicalActionSet> parseChangedSourceCodeWithGumTree2(File prevFile, File revFile,String srcMLPath,boolean isJava) {
List<HierarchicalActionSet> actionSets = new ArrayList<>(); List<HierarchicalActionSet> actionSets = new ArrayList<>();
// GumTree results // GumTree results
boolean isJava =false; // boolean isJava =false;
List<Action> gumTreeResults = null; List<Action> gumTreeResults = null;
if (true){ if (isJava){
// if (revFile.getName().endsWith(".c") & prevFile.getName().endsWith(".c") || revFile.getName().endsWith(".h") & prevFile.getName().endsWith(".h")){ // if (revFile.getName().endsWith(".c") & prevFile.getName().endsWith(".c") || revFile.getName().endsWith(".h") & prevFile.getName().endsWith(".h")){
// gumTreeResults = new GumTreeComparer().compareCFilesWithGumTree(prevFile, revFile); // gumTreeResults = new GumTreeComparer().compareCFilesWithGumTree(prevFile, revFile);
gumTreeResults = new GumTreeCComparer().compareCFilesWithGumTree(prevFile, revFile,srcMLPath);
}else{
gumTreeResults = new GumTreeComparer().compareTwoFilesWithGumTree(prevFile, revFile); gumTreeResults = new GumTreeComparer().compareTwoFilesWithGumTree(prevFile, revFile);
isJava = true;
}else{
gumTreeResults = new GumTreeCComparer().compareCFilesWithGumTree(prevFile, revFile,srcMLPath);
} }
if (gumTreeResults == null) { if (gumTreeResults == null) {
this.resultType = 1; this.resultType = 1;
@@ -83,7 +83,7 @@ public class EDiffParser extends Parser {
} }
@Override @Override
public void parseFixPatterns(File prevFile, File revFile, File diffEntryFile, String project, JedisPool innerPool, String srcMLPath,String rootType) { public void parseFixPatterns(File prevFile, File revFile, File diffEntryFile, String project, JedisPool innerPool, String srcMLPath,String rootType,boolean isJava) {
} }
@@ -59,7 +59,7 @@ public class EDiffWorker extends UntypedActor {
// schedule the work // schedule the work
final Future<?> future = executor.submit(new RunnableParser(prevFile, revFile, diffentryFile, parser,project,msg.getInnerPool(),srcMLPath,rootType)); final Future<?> future = executor.submit(new RunnableParser(prevFile, revFile, diffentryFile, parser,project,msg.getInnerPool(),srcMLPath,rootType,false));
try { try {
// wait for task to complete // wait for task to complete
future.get(msg.getSECONDS_TO_WAIT(), TimeUnit.SECONDS); future.get(msg.getSECONDS_TO_WAIT(), TimeUnit.SECONDS);
@@ -77,7 +77,7 @@ public class HunkParserTest {
String srcMLPath = "/usr/local/bin/srcml"; String srcMLPath = "/usr/local/bin/srcml";
// String srcMLPath = "/Users/anil.koyuncu/Downloads/srcML.0.9.5/bin/srcml"; // String srcMLPath = "/Users/anil.koyuncu/Downloads/srcML.0.9.5/bin/srcml";
parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false);
// ITree t = new SrcmlCppTreeGenerator().generateFromFile(input).getRoot(); // ITree t = new SrcmlCppTreeGenerator().generateFromFile(input).getRoot();
// Assert.assertEquals(148, t.getSize()); // Assert.assertEquals(148, t.getSize());
@@ -101,7 +101,7 @@ public class HunkParserTest {
File prevFile =new File(root + "prevFiles/prev_"+filename); File prevFile =new File(root + "prevFiles/prev_"+filename);
File diffFile = new File(root + "DiffEntries/"+filename+".txt"); File diffFile = new File(root + "DiffEntries/"+filename+".txt");
EDiffHunkParser parser = new EDiffHunkParser(); EDiffHunkParser parser = new EDiffHunkParser();
parser.parseFixPatterns(prevFile,revFile,diffFile,"gumInputLinux",null,srcMLPath,null); parser.parseFixPatterns(prevFile,revFile,diffFile,"gumInputLinux",null,srcMLPath,null,false);
} }
@@ -118,7 +118,7 @@ public class HunkParserTest {
EDiffHunkParser parser = new EDiffHunkParser(); EDiffHunkParser parser = new EDiffHunkParser();
parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile,""); parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile,"",true);
// ITree t = new SrcmlCppTreeGenerator().generateFromFile(input).getRoot(); // ITree t = new SrcmlCppTreeGenerator().generateFromFile(input).getRoot();
// Assert.assertEquals(148, t.getSize()); // Assert.assertEquals(148, t.getSize());
} }
@@ -137,7 +137,7 @@ public class HunkParserTest {
File prevFile =new File(root + "prevFiles/prev_"+filename); File prevFile =new File(root + "prevFiles/prev_"+filename);
File diffFile = new File(root + "DiffEntries/"+filename+".txt"); File diffFile = new File(root + "DiffEntries/"+filename+".txt");
String srcMLPath = "/Users/anil.koyuncu/Downloads/srcML/src2srcml"; String srcMLPath = "/Users/anil.koyuncu/Downloads/srcML/src2srcml";
parser.parseFixPatterns(prevFile,revFile,diffFile,"gumInputLinux",outerPool,srcMLPath,"if"); parser.parseFixPatterns(prevFile,revFile,diffFile,"gumInputLinux",outerPool,srcMLPath,"if",false);
String key = "if/3/linux_bb67dd_0922c7_sound#soc#sof#intel#hda.c.txt_0"; String key = "if/3/linux_bb67dd_0922c7_sound#soc#sof#intel#hda.c.txt_0";
File file2load = new File("/Users/anil.koyuncu/projects/fixminer/dumps/"+ key); File file2load = new File("/Users/anil.koyuncu/projects/fixminer/dumps/"+ key);
byte[] dump = FileUtils.readFileToByteArray(file2load); byte[] dump = FileUtils.readFileToByteArray(file2load);
@@ -244,11 +244,11 @@ public class HunkParserTest {
HierarchicalActionSet oldProject = oldPair.getValue1(); HierarchicalActionSet oldProject = oldPair.getValue1();
HierarchicalActionSet newProject = newPair.getValue1(); HierarchicalActionSet newProject = newPair.getValue1();
ITree oldShapeTree = EDiffHelper.getShapeTree(oldProject); ITree oldShapeTree = EDiffHelper.getShapeTree(oldProject,false);
ITree newShapeTree = EDiffHelper.getShapeTree(newProject); ITree newShapeTree = EDiffHelper.getShapeTree(newProject,false);
ITree oldTargetTree = EDiffHelper.getTargets(oldProject); ITree oldTargetTree = EDiffHelper.getTargets(oldProject,false);
ITree newTargetTree = EDiffHelper.getTargets(newProject); ITree newTargetTree = EDiffHelper.getTargets(newProject,false);
String oldShape = oldShapeTree.toStaticHashString(); String oldShape = oldShapeTree.toStaticHashString();
String newShape = newShapeTree.toStaticHashString(); String newShape = newShapeTree.toStaticHashString();
@@ -20,7 +20,7 @@ public abstract class Parser implements ParserInterface {
protected String originalTree = ""; // Guide of generating patches. protected String originalTree = ""; // Guide of generating patches.
protected String actionSets = ""; // Guide of generating patches. protected String actionSets = ""; // Guide of generating patches.
public abstract void parseFixPatterns(File prevFile, File revFile, File diffEntryFile, String project, JedisPool innerPool, String srcMLPath,String rootType); public abstract void parseFixPatterns(File prevFile, File revFile, File diffEntryFile, String project, JedisPool innerPool, String srcMLPath,String rootType,boolean isJava);
@Override @Override
@@ -14,6 +14,7 @@ public class RunnableParser implements Runnable {
private JedisPool pool; private JedisPool pool;
private String srcMLPath; private String srcMLPath;
private String rootType; private String rootType;
boolean isJava;
public RunnableParser(File prevFile, File revFile, File diffEntryFile, Parser parser) { public RunnableParser(File prevFile, File revFile, File diffEntryFile, Parser parser) {
this.prevFile = prevFile; this.prevFile = prevFile;
@@ -31,7 +32,7 @@ public class RunnableParser implements Runnable {
this.pool = innerPool; this.pool = innerPool;
} }
public RunnableParser(File prevFile, File revFile, File diffEntryFile, Parser parser, String project, JedisPool innerPool,String srcMLPath,String rootType) { public RunnableParser(File prevFile, File revFile, File diffEntryFile, Parser parser, String project, JedisPool innerPool,String srcMLPath,String rootType,boolean isJava) {
this.prevFile = prevFile; this.prevFile = prevFile;
this.revFile = revFile; this.revFile = revFile;
this.diffEntryFile = diffEntryFile; this.diffEntryFile = diffEntryFile;
@@ -40,10 +41,11 @@ public class RunnableParser implements Runnable {
this.pool = innerPool; this.pool = innerPool;
this.srcMLPath = srcMLPath; this.srcMLPath = srcMLPath;
this.rootType = rootType; this.rootType = rootType;
this.isJava = isJava;
} }
@Override @Override
public void run() { public void run() {
parser.parseFixPatterns(prevFile, revFile, diffEntryFile,project,pool,srcMLPath,rootType); parser.parseFixPatterns(prevFile, revFile, diffEntryFile,project,pool,srcMLPath,rootType,isJava);
} }
} }
@@ -42,7 +42,7 @@ public class TestInputCases {
EDiffHunkParser parser = new EDiffHunkParser(); EDiffHunkParser parser = new EDiffHunkParser();
List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false);
return hierarchicalActionSets; return hierarchicalActionSets;
} }
@@ -433,7 +433,7 @@ public class TestIntroClass {
EDiffHunkParser parser = new EDiffHunkParser(); EDiffHunkParser parser = new EDiffHunkParser();
List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false);
return hierarchicalActionSets; return hierarchicalActionSets;
} }
@@ -28,7 +28,7 @@ public class TestPredefinedCases {
List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false);
hierarchicalActionSets.size(); hierarchicalActionSets.size();
Assert.assertEquals(hierarchicalActionSets.size(),1); Assert.assertEquals(hierarchicalActionSets.size(),1);
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD if@@if x >= 5 y += 4 @TO@ if x > 5 y += 4 @AT@ 2 @LENGTH@ 16\n" + Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD if@@if x >= 5 y += 4 @TO@ if x > 5 y += 4 @AT@ 2 @LENGTH@ 16\n" +
@@ -52,7 +52,7 @@ public class TestPredefinedCases {
List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false);
hierarchicalActionSets.size(); hierarchicalActionSets.size();
Assert.assertEquals(hierarchicalActionSets.size(),1); Assert.assertEquals(hierarchicalActionSets.size(),1);
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD for@@i = 0 i < max i ++ if line ] == ' ' if line ] == '\\t' tab ++ @TO@ i = 0 i < max i ++ if line ] == ' ' space ++ if line ] == '\\t' tab ++ @AT@ 4 @LENGTH@ 60\n" + Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD for@@i = 0 i < max i ++ if line ] == ' ' if line ] == '\\t' tab ++ @TO@ i = 0 i < max i ++ if line ] == ' ' space ++ if line ] == '\\t' tab ++ @AT@ 4 @LENGTH@ 60\n" +
@@ -79,7 +79,7 @@ public class TestPredefinedCases {
EDiffHunkParser parser = new EDiffHunkParser(); EDiffHunkParser parser = new EDiffHunkParser();
List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false);
hierarchicalActionSets.size(); hierarchicalActionSets.size();
Assert.assertEquals(hierarchicalActionSets.size(), 1); Assert.assertEquals(hierarchicalActionSets.size(), 1);
@@ -109,7 +109,7 @@ public class TestPredefinedCases {
EDiffHunkParser parser = new EDiffHunkParser(); EDiffHunkParser parser = new EDiffHunkParser();
List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false);
hierarchicalActionSets.size(); hierarchicalActionSets.size();
// Assert.assertEquals(hierarchicalActionSets.size(),1); // Assert.assertEquals(hierarchicalActionSets.size(),1);
} }
@@ -126,7 +126,7 @@ public class TestPredefinedCases {
EDiffHunkParser parser = new EDiffHunkParser(); EDiffHunkParser parser = new EDiffHunkParser();
List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false);
hierarchicalActionSets.size(); hierarchicalActionSets.size();
// Assert.assertEquals(hierarchicalActionSets.size(),1); // Assert.assertEquals(hierarchicalActionSets.size(),1);
} }
@@ -144,7 +144,7 @@ public class TestPredefinedCases {
EDiffHunkParser parser = new EDiffHunkParser(); EDiffHunkParser parser = new EDiffHunkParser();
List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false);
hierarchicalActionSets.size(); hierarchicalActionSets.size();
// Assert.assertEquals(hierarchicalActionSets.size(),1); // Assert.assertEquals(hierarchicalActionSets.size(),1);
} }
@@ -653,9 +653,9 @@ public class TestRealCases {
"------UPD expr@@sum >= k @TO@ sum > k @AT@ 859 @LENGTH@ 8\n" + "------UPD expr@@sum >= k @TO@ sum > k @AT@ 859 @LENGTH@ 8\n" +
"---------UPD operator@@>= @TO@ > @AT@ 862 @LENGTH@ 2\n"); "---------UPD operator@@>= @TO@ > @AT@ 862 @LENGTH@ 2\n");
HierarchicalActionSet actionSet = hierarchicalActionSets.get(0); HierarchicalActionSet actionSet = hierarchicalActionSets.get(0);
ITree targetTree = EDiffHelper.getTargets(actionSet); ITree targetTree = EDiffHelper.getTargets(actionSet,false);
ITree actionTree = EDiffHelper.getActionTrees(actionSet); ITree actionTree = EDiffHelper.getActionTrees(actionSet);
ITree shapeTree = EDiffHelper.getShapeTree(actionSet); ITree shapeTree = EDiffHelper.getShapeTree(actionSet,false);
actionSet.getActionSize(); actionSet.getActionSize();
} }
//102-A-14574020-14574054 //102-A-14574020-14574054
@@ -705,7 +705,7 @@ public class TestRealCases {
EDiffHunkParser parser = new EDiffHunkParser(); EDiffHunkParser parser = new EDiffHunkParser();
List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false);
return hierarchicalActionSets; return hierarchicalActionSets;
} }
@@ -26,7 +26,7 @@ public class EnhancedASTDiff {
private static Logger log = LoggerFactory.getLogger(EnhancedASTDiff.class); private static Logger log = LoggerFactory.getLogger(EnhancedASTDiff.class);
public static void main(String inputPath, String project, String portInner, String dbDir, String chunkName,String srcMLPath,String parameter,String hunkLimit,String[] projectList,String patchSize) throws Exception { public static void main(String inputPath, String project, String portInner, String dbDir, String chunkName,String srcMLPath,String parameter,String hunkLimit,String[] projectList,String patchSize,String projectType) throws Exception {
String parameters = String.format("\nInput path %s",inputPath); String parameters = String.format("\nInput path %s",inputPath);
@@ -47,6 +47,11 @@ public class EnhancedASTDiff {
allPredicates.add(predicate); allPredicates.add(predicate);
} }
boolean isJava = false;
if (projectType.equals("java")){
isJava =true;
}
File folder = new File(inputPath); File folder = new File(inputPath);
File[] listOfFiles = folder.listFiles(); File[] listOfFiles = folder.listFiles();
Stream<File> stream = Arrays.stream(listOfFiles); Stream<File> stream = Arrays.stream(listOfFiles);
@@ -61,7 +66,7 @@ public class EnhancedASTDiff {
List<MessageFile> allMessageFiles = new ArrayList<>(); List<MessageFile> allMessageFiles = new ArrayList<>();
for (File target : folders) { for (File target : folders) {
List<MessageFile> msgFiles = getMessageFiles(target.toString() + "/",project,patchSize); //"/Users/anilkoyuncu/bugStudy/code/python/GumTreeInput/Apache/CAMEL/" List<MessageFile> msgFiles = getMessageFiles(target.toString() + "/",project,patchSize,isJava); //"/Users/anilkoyuncu/bugStudy/code/python/GumTreeInput/Apache/CAMEL/"
// msgFiles = msgFiles.subList(0,3000); // msgFiles = msgFiles.subList(0,3000);
if (msgFiles == null) if (msgFiles == null)
@@ -82,12 +87,13 @@ public class EnhancedASTDiff {
allMessageFiles = allMessageFiles.stream().filter(f -> !diffEntry.containsKey(f.getProject() + "_" + f.getDiffEntryFile().getName())).collect(Collectors.toList()); allMessageFiles = allMessageFiles.stream().filter(f -> !diffEntry.containsKey(f.getProject() + "_" + f.getDiffEntryFile().getName())).collect(Collectors.toList());
log.info("{} files to process ...", allMessageFiles.size()); log.info("{} files to process ...", allMessageFiles.size());
} }
boolean finalIsJava = isJava;
ProgressBar.wrap(allMessageFiles.stream(). ProgressBar.wrap(allMessageFiles.stream().
parallel(),"Task"). parallel(),"Task").
forEach(m -> forEach(m ->
{ {
EDiffHunkParser parser = new EDiffHunkParser(); EDiffHunkParser parser = new EDiffHunkParser();
parser.parseFixPatterns(m.getPrevFile(),m.getRevFile(), m.getDiffEntryFile(),project,innerPool,srcMLPath,hunkLimit); parser.parseFixPatterns(m.getPrevFile(),m.getRevFile(), m.getDiffEntryFile(),project,innerPool,srcMLPath,hunkLimit, finalIsJava);
} }
); );
@@ -95,7 +101,7 @@ public class EnhancedASTDiff {
private static List<MessageFile> getMessageFiles(String gumTreeInput,String datasetName,String patchSize) { private static List<MessageFile> getMessageFiles(String gumTreeInput,String datasetName,String patchSize,boolean isJava) {
String inputPath = gumTreeInput; // prevFiles revFiles diffentryFile positionsFile String inputPath = gumTreeInput; // prevFiles revFiles diffentryFile positionsFile
File revFilesPath = new File(inputPath + "revFiles/"); File revFilesPath = new File(inputPath + "revFiles/");
log.info(revFilesPath.getPath()); log.info(revFilesPath.getPath());
@@ -108,7 +114,11 @@ public class EnhancedASTDiff {
// for (File revFile : collect) { // for (File revFile : collect) {
String fileName = revFile.getName(); String fileName = revFile.getName();
File prevFile = new File(gumTreeInput + "prevFiles/prev_" + fileName);// previous file File prevFile = new File(gumTreeInput + "prevFiles/prev_" + fileName);// previous file
fileName = fileName + ".txt"; if (isJava){
fileName = fileName.replace(".java",".txt");
}else{
fileName = fileName + ".txt";
}
File diffentryFile = new File(gumTreeInput + "DiffEntries/" + fileName); // DiffEntry file File diffentryFile = new File(gumTreeInput + "DiffEntries/" + fileName); // DiffEntry file
String s = FileHelper.readFile(diffentryFile); String s = FileHelper.readFile(diffentryFile);
@@ -113,17 +113,23 @@ public class EDiffHelper {
public static ITree getTargetTree(HierarchicalActionSet actionSet, ITree parent, ITree children, TreeContext tc){ public static ITree getTargetTree(HierarchicalActionSet actionSet, ITree parent, ITree children, TreeContext tc,boolean isJava){
int newType = 0; int newType = 0;
String astNodeType = null; String astNodeType = null;
Map<Integer, String> nodeMap;
if(isJava){
nodeMap = ASTNodeMap.map;
}else{
nodeMap = NodeMap_new.map;
}
Action action = actionSet.getAction(); Action action = actionSet.getAction();
if (action instanceof Update){ if (action instanceof Update){
astNodeType = actionSet.getAstNodeType(); astNodeType = actionSet.getAstNodeType();
// List<Integer> keysByValue = getKeysByValue(ASTNodeMap.map, astNodeType);
List<Integer> keysByValue = getKeysByValue(NodeMap_new.map, astNodeType); List<Integer> keysByValue = getKeysByValue(nodeMap, astNodeType);
if(keysByValue.size() != 1){ if(keysByValue.size() != 1){
log.error("More than 1"); log.error("More than 1");
@@ -135,8 +141,8 @@ public class EDiffHelper {
newType = ((Move)action).getParent().getType(); newType = ((Move)action).getParent().getType();
}else if(action instanceof Delete){ }else if(action instanceof Delete){
astNodeType = actionSet.getAstNodeType(); astNodeType = actionSet.getAstNodeType();
// List<Integer> keysByValue = getKeysByValue(ASTNodeMap.map, astNodeType);
List<Integer> keysByValue = getKeysByValue(NodeMap_new.map, astNodeType); List<Integer> keysByValue = getKeysByValue(nodeMap, astNodeType);
if(keysByValue.size() != 1){ if(keysByValue.size() != 1){
log.error("More than 1"); log.error("More than 1");
@@ -165,7 +171,7 @@ public class EDiffHelper {
if(actionSet.getParent() == null){ if(actionSet.getParent() == null){
children = parent; children = parent;
} }
getTargetTree(subAction,children,null,tc); getTargetTree(subAction,children,null,tc,isJava);
} }
@@ -174,13 +180,18 @@ public class EDiffHelper {
return parent; return parent;
} }
public static ITree getASTTree(HierarchicalActionSet actionSet, ITree parent, ITree children, TreeContext tc){ public static ITree getASTTree(HierarchicalActionSet actionSet, ITree parent, ITree children, TreeContext tc,boolean isJava){
int newType = 0; int newType = 0;
Map<Integer, String> nodeMap;
if(isJava){
nodeMap = ASTNodeMap.map;
}else{
nodeMap = NodeMap_new.map;
}
String astNodeType = actionSet.getAstNodeType(); String astNodeType = actionSet.getAstNodeType();
// List<Integer> keysByValue = getKeysByValue(ASTNodeMap.map, astNodeType);
List<Integer> keysByValue = getKeysByValue(NodeMap_new.map, astNodeType); List<Integer> keysByValue = getKeysByValue(nodeMap, astNodeType);
if(keysByValue.size() != 1){ if(keysByValue.size() != 1){
log.error("More than 1"); log.error("More than 1");
@@ -205,7 +216,7 @@ public class EDiffHelper {
if(actionSet.getParent() == null){ if(actionSet.getParent() == null){
children = parent; children = parent;
} }
getASTTree(subAction,children,null,tc); getASTTree(subAction,children,null,tc,isJava);
} }
@@ -223,40 +234,40 @@ public class EDiffHelper {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public static ITree getSimpliedTree(String prefix, String fn, JedisPool outerPool) { // public static ITree getSimpliedTree(String prefix, String fn, JedisPool outerPool) {
//
ITree tree = null; // ITree tree = null;
Jedis inner = null; // Jedis inner = null;
try { // try {
inner = outerPool.getResource(); // inner = outerPool.getResource();
while (!inner.ping().equals("PONG")){ // while (!inner.ping().equals("PONG")){
log.info("wait"); // log.info("wait");
} // }
inner.select(1); // inner.select(1);
String dist2load = inner.get(prefix+"-"+fn); // String dist2load = inner.get(prefix+"-"+fn);
inner.select(0); // inner.select(0);
String s = inner.get(prefix.replace("-","/") +"/"+dist2load); // String s = inner.get(prefix.replace("-","/") +"/"+dist2load);
HierarchicalActionSet actionSet = (HierarchicalActionSet) EDiffHelper.fromString(s); // HierarchicalActionSet actionSet = (HierarchicalActionSet) EDiffHelper.fromString(s);
//
ITree parent = null; // ITree parent = null;
ITree children =null; // ITree children =null;
TreeContext tc = new TreeContext(); // TreeContext tc = new TreeContext();
tree = EDiffHelper.getASTTree(actionSet, parent, children,tc); // tree = EDiffHelper.getASTTree(actionSet, parent, children,tc);
tree.setParent(null); // tree.setParent(null);
tc.validate(); // tc.validate();
//
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} catch (ClassNotFoundException e) { // } catch (ClassNotFoundException e) {
e.printStackTrace(); // e.printStackTrace();
}finally { // }finally {
if (inner != null) { // if (inner != null) {
inner.close(); // inner.close();
} // }
} // }
return tree; // return tree;
//
} // }
// public static ITree getShapes(String prefix, String fn, JedisPool outerPool, HashMap<String, String> filenames) { // public static ITree getShapes(String prefix, String fn, JedisPool outerPool, HashMap<String, String> filenames) {
@@ -285,19 +296,19 @@ public class EDiffHelper {
// //
// } // }
public static ITree getShapeTree(HierarchicalActionSet actionSet) { public static ITree getShapeTree(HierarchicalActionSet actionSet,boolean isJava) {
ITree tree = null; ITree tree = null;
ITree parent = null; ITree parent = null;
ITree children = null; ITree children = null;
TreeContext tc = new TreeContext(); TreeContext tc = new TreeContext();
tree = EDiffHelper.getASTTree(actionSet, parent, children, tc); tree = EDiffHelper.getASTTree(actionSet, parent, children, tc, isJava);
//tree.setParent(null); //tree.setParent(null);
tc.validate(); tc.validate();
return tree; return tree;
} }
public static ITree getTargets(HierarchicalActionSet actionSet) { public static ITree getTargets(HierarchicalActionSet actionSet,boolean isJava) {
ITree tree = null; ITree tree = null;
try { try {
@@ -305,7 +316,7 @@ public class EDiffHelper {
ITree parent = null; ITree parent = null;
ITree children =null; ITree children =null;
TreeContext tc = new TreeContext(); TreeContext tc = new TreeContext();
tree = EDiffHelper.getTargetTree(actionSet, parent, children,tc); tree = EDiffHelper.getTargetTree(actionSet, parent, children,tc,isJava);
//tree.setParent(null); //tree.setParent(null);
tc.validate(); tc.validate();
} catch (Exception e) { } catch (Exception e) {
@@ -0,0 +1,21 @@
pjName = gumInput
portDumps = 6399
numOfWorkers = 14
hostname = localhost
hunkLimit = 10
patchSize = 50
#projectList = libtiff,php-src,cpython,wireshark,gzip,gmp,lighttpd1.4,lighttpd2
projectList = fuse,camel
#inputPath = /Users/anilkoyuncu/projects/gumInputLinux
inputPath = /Users/anilkoyuncu/projects/fixminer/fixminer-core/python/data/gumInput
#redisPath = /Users/anil.koyuncu/projects/fixminer/fixminer-core/python/data/redis
redisPath = /Users/anilkoyuncu/projects/fixminer/fixminer-core/python/data/redis
#srcMLPath= /Users/anil.koyuncu/Downloads/srcML/src2srcml
srcMLPath= /usr/local/bin/srcml
projectType = java
#ENHANCEDASTDIFF,CACHE,LEVEL1,LEVEL2,LEVEL3