diff --git a/src/main/java/edu/lu/uni/serval/fixminer/Launcher.java b/src/main/java/edu/lu/uni/serval/fixminer/Launcher.java index 88d5c32..b199287 100755 --- a/src/main/java/edu/lu/uni/serval/fixminer/Launcher.java +++ b/src/main/java/edu/lu/uni/serval/fixminer/Launcher.java @@ -8,6 +8,8 @@ import org.slf4j.LoggerFactory; import java.io.FileInputStream; import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.Properties; /** @@ -22,16 +24,33 @@ public class Launcher { 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]; appProps.load(new FileInputStream(appConfigPath)); String numOfWorkers = appProps.getProperty("numOfWorkers", "10"); String portDumps = appProps.getProperty("portDumps","6399"); 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 patchSize = appProps.getProperty("patchSize","50"); String projectL = appProps.getProperty("projectList",""); @@ -45,9 +64,8 @@ public class Launcher { // String parameter = "if"; // String parameter = "add"; // String jobType = args[1]; - String jobType = "RICHEDITSCRIPT"; -// String jobType = "LOAD"; -// String jobType = "COMPARE"; +// String jobType = "RICHEDITSCRIPT"; + String jobType = "COMPARE"; // String parameters = String.format("\nportInner %s " + // "\nnumOfWorkers %s " + @@ -58,12 +76,12 @@ public class Launcher { // // 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; @@ -79,7 +97,7 @@ public class Launcher { try { switch (jobType) { 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; 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; case "PATTERN": - ClusterToPattern.main(portDumps,redisPath, actionType+dumpsName, parameter); + ClusterToPattern.main(portDumps,redisPath, dumpsName, parameter); break; default: throw new Error("unknown Job"); diff --git a/src/main/java/edu/lu/uni/serval/fixminer/ediff/EDiffHunkParser.java b/src/main/java/edu/lu/uni/serval/fixminer/ediff/EDiffHunkParser.java index 7c8f141..3b7daf9 100755 --- a/src/main/java/edu/lu/uni/serval/fixminer/ediff/EDiffHunkParser.java +++ b/src/main/java/edu/lu/uni/serval/fixminer/ediff/EDiffHunkParser.java @@ -22,7 +22,7 @@ public class EDiffHunkParser extends EDiffParser { private static Logger logger = LoggerFactory.getLogger(EDiffHunkParser.class); @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[] split1 = diffentryFile.getParent().split(datasetName); @@ -30,7 +30,7 @@ public class EDiffHunkParser extends EDiffParser { String pj = split1[1].split("/")[1]; - List actionSets = parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + List actionSets = parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,isJava); 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); - ITree targetTree = EDiffHelper.getTargets(actionSet); + ITree targetTree = EDiffHelper.getTargets(actionSet,isJava); ITree actionTree = EDiffHelper.getActionTrees(actionSet); - ITree shapeTree = EDiffHelper.getShapeTree(actionSet); + ITree shapeTree = EDiffHelper.getShapeTree(actionSet,isJava); try (Jedis inner = innerPool.getResource()) { inner.hset("dump", key, actionSet.toString()); diff --git a/src/main/java/edu/lu/uni/serval/fixminer/ediff/EDiffParser.java b/src/main/java/edu/lu/uni/serval/fixminer/ediff/EDiffParser.java index 70bd7a5..7091b9d 100755 --- a/src/main/java/edu/lu/uni/serval/fixminer/ediff/EDiffParser.java +++ b/src/main/java/edu/lu/uni/serval/fixminer/ediff/EDiffParser.java @@ -39,21 +39,21 @@ public class EDiffParser extends Parser { * @param revFile * @return */ - protected List parseChangedSourceCodeWithGumTree2(File prevFile, File revFile,String srcMLPath) { + protected List parseChangedSourceCodeWithGumTree2(File prevFile, File revFile,String srcMLPath,boolean isJava) { List actionSets = new ArrayList<>(); // GumTree results - boolean isJava =false; +// boolean isJava =false; List gumTreeResults = null; - if (true){ + if (isJava){ // 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 GumTreeCComparer().compareCFilesWithGumTree(prevFile, revFile,srcMLPath); - }else{ gumTreeResults = new GumTreeComparer().compareTwoFilesWithGumTree(prevFile, revFile); - isJava = true; + + + }else{ + gumTreeResults = new GumTreeCComparer().compareCFilesWithGumTree(prevFile, revFile,srcMLPath); + } if (gumTreeResults == null) { this.resultType = 1; @@ -83,7 +83,7 @@ public class EDiffParser extends Parser { } @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) { } diff --git a/src/main/java/edu/lu/uni/serval/fixminer/ediff/EDiffWorker.java b/src/main/java/edu/lu/uni/serval/fixminer/ediff/EDiffWorker.java index 9882db1..afc3011 100755 --- a/src/main/java/edu/lu/uni/serval/fixminer/ediff/EDiffWorker.java +++ b/src/main/java/edu/lu/uni/serval/fixminer/ediff/EDiffWorker.java @@ -59,7 +59,7 @@ public class EDiffWorker extends UntypedActor { // 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 { // wait for task to complete future.get(msg.getSECONDS_TO_WAIT(), TimeUnit.SECONDS); diff --git a/src/main/java/edu/lu/uni/serval/fixminer/ediff/HunkParserTest.java b/src/main/java/edu/lu/uni/serval/fixminer/ediff/HunkParserTest.java index 1f60347..dfc0cb7 100644 --- a/src/main/java/edu/lu/uni/serval/fixminer/ediff/HunkParserTest.java +++ b/src/main/java/edu/lu/uni/serval/fixminer/ediff/HunkParserTest.java @@ -77,7 +77,7 @@ public class HunkParserTest { String srcMLPath = "/usr/local/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(); // Assert.assertEquals(148, t.getSize()); @@ -101,7 +101,7 @@ public class HunkParserTest { File prevFile =new File(root + "prevFiles/prev_"+filename); File diffFile = new File(root + "DiffEntries/"+filename+".txt"); 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(); - parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile,""); + parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile,"",true); // ITree t = new SrcmlCppTreeGenerator().generateFromFile(input).getRoot(); // Assert.assertEquals(148, t.getSize()); } @@ -137,7 +137,7 @@ public class HunkParserTest { File prevFile =new File(root + "prevFiles/prev_"+filename); File diffFile = new File(root + "DiffEntries/"+filename+".txt"); 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"; File file2load = new File("/Users/anil.koyuncu/projects/fixminer/dumps/"+ key); byte[] dump = FileUtils.readFileToByteArray(file2load); @@ -244,11 +244,11 @@ public class HunkParserTest { HierarchicalActionSet oldProject = oldPair.getValue1(); HierarchicalActionSet newProject = newPair.getValue1(); - ITree oldShapeTree = EDiffHelper.getShapeTree(oldProject); - ITree newShapeTree = EDiffHelper.getShapeTree(newProject); + ITree oldShapeTree = EDiffHelper.getShapeTree(oldProject,false); + ITree newShapeTree = EDiffHelper.getShapeTree(newProject,false); - ITree oldTargetTree = EDiffHelper.getTargets(oldProject); - ITree newTargetTree = EDiffHelper.getTargets(newProject); + ITree oldTargetTree = EDiffHelper.getTargets(oldProject,false); + ITree newTargetTree = EDiffHelper.getTargets(newProject,false); String oldShape = oldShapeTree.toStaticHashString(); String newShape = newShapeTree.toStaticHashString(); diff --git a/src/main/java/edu/lu/uni/serval/fixminer/ediff/Parser.java b/src/main/java/edu/lu/uni/serval/fixminer/ediff/Parser.java index b871882..c6ac037 100755 --- a/src/main/java/edu/lu/uni/serval/fixminer/ediff/Parser.java +++ b/src/main/java/edu/lu/uni/serval/fixminer/ediff/Parser.java @@ -20,7 +20,7 @@ public abstract class Parser implements ParserInterface { protected String originalTree = ""; // 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 diff --git a/src/main/java/edu/lu/uni/serval/fixminer/ediff/RunnableParser.java b/src/main/java/edu/lu/uni/serval/fixminer/ediff/RunnableParser.java index 2890219..7a05e23 100755 --- a/src/main/java/edu/lu/uni/serval/fixminer/ediff/RunnableParser.java +++ b/src/main/java/edu/lu/uni/serval/fixminer/ediff/RunnableParser.java @@ -14,6 +14,7 @@ public class RunnableParser implements Runnable { private JedisPool pool; private String srcMLPath; private String rootType; + boolean isJava; public RunnableParser(File prevFile, File revFile, File diffEntryFile, Parser parser) { this.prevFile = prevFile; @@ -31,7 +32,7 @@ public class RunnableParser implements Runnable { 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.revFile = revFile; this.diffEntryFile = diffEntryFile; @@ -40,10 +41,11 @@ public class RunnableParser implements Runnable { this.pool = innerPool; this.srcMLPath = srcMLPath; this.rootType = rootType; + this.isJava = isJava; } @Override public void run() { - parser.parseFixPatterns(prevFile, revFile, diffEntryFile,project,pool,srcMLPath,rootType); + parser.parseFixPatterns(prevFile, revFile, diffEntryFile,project,pool,srcMLPath,rootType,isJava); } } diff --git a/src/main/java/edu/lu/uni/serval/fixminer/ediff/TestInputCases.java b/src/main/java/edu/lu/uni/serval/fixminer/ediff/TestInputCases.java index cdae265..cb96a33 100644 --- a/src/main/java/edu/lu/uni/serval/fixminer/ediff/TestInputCases.java +++ b/src/main/java/edu/lu/uni/serval/fixminer/ediff/TestInputCases.java @@ -42,7 +42,7 @@ public class TestInputCases { EDiffHunkParser parser = new EDiffHunkParser(); - List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false); return hierarchicalActionSets; } diff --git a/src/main/java/edu/lu/uni/serval/fixminer/ediff/TestIntroClass.java b/src/main/java/edu/lu/uni/serval/fixminer/ediff/TestIntroClass.java index 119f5c1..fb980bd 100644 --- a/src/main/java/edu/lu/uni/serval/fixminer/ediff/TestIntroClass.java +++ b/src/main/java/edu/lu/uni/serval/fixminer/ediff/TestIntroClass.java @@ -433,7 +433,7 @@ public class TestIntroClass { EDiffHunkParser parser = new EDiffHunkParser(); - List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false); return hierarchicalActionSets; } diff --git a/src/main/java/edu/lu/uni/serval/fixminer/ediff/TestPredefinedCases.java b/src/main/java/edu/lu/uni/serval/fixminer/ediff/TestPredefinedCases.java index 1190f5e..f5d746c 100644 --- a/src/main/java/edu/lu/uni/serval/fixminer/ediff/TestPredefinedCases.java +++ b/src/main/java/edu/lu/uni/serval/fixminer/ediff/TestPredefinedCases.java @@ -28,7 +28,7 @@ public class TestPredefinedCases { - List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false); hierarchicalActionSets.size(); 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" + @@ -52,7 +52,7 @@ public class TestPredefinedCases { - List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false); hierarchicalActionSets.size(); 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" + @@ -79,7 +79,7 @@ public class TestPredefinedCases { EDiffHunkParser parser = new EDiffHunkParser(); - List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false); hierarchicalActionSets.size(); Assert.assertEquals(hierarchicalActionSets.size(), 1); @@ -109,7 +109,7 @@ public class TestPredefinedCases { EDiffHunkParser parser = new EDiffHunkParser(); - List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false); hierarchicalActionSets.size(); // Assert.assertEquals(hierarchicalActionSets.size(),1); } @@ -126,7 +126,7 @@ public class TestPredefinedCases { EDiffHunkParser parser = new EDiffHunkParser(); - List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false); hierarchicalActionSets.size(); // Assert.assertEquals(hierarchicalActionSets.size(),1); } @@ -144,7 +144,7 @@ public class TestPredefinedCases { EDiffHunkParser parser = new EDiffHunkParser(); - List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false); hierarchicalActionSets.size(); // Assert.assertEquals(hierarchicalActionSets.size(),1); } diff --git a/src/main/java/edu/lu/uni/serval/fixminer/ediff/TestRealCases.java b/src/main/java/edu/lu/uni/serval/fixminer/ediff/TestRealCases.java index cf5c326..8278f73 100644 --- a/src/main/java/edu/lu/uni/serval/fixminer/ediff/TestRealCases.java +++ b/src/main/java/edu/lu/uni/serval/fixminer/ediff/TestRealCases.java @@ -653,9 +653,9 @@ public class TestRealCases { "------UPD expr@@sum >= k @TO@ sum > k @AT@ 859 @LENGTH@ 8\n" + "---------UPD operator@@>= @TO@ > @AT@ 862 @LENGTH@ 2\n"); HierarchicalActionSet actionSet = hierarchicalActionSets.get(0); - ITree targetTree = EDiffHelper.getTargets(actionSet); + ITree targetTree = EDiffHelper.getTargets(actionSet,false); ITree actionTree = EDiffHelper.getActionTrees(actionSet); - ITree shapeTree = EDiffHelper.getShapeTree(actionSet); + ITree shapeTree = EDiffHelper.getShapeTree(actionSet,false); actionSet.getActionSize(); } //102-A-14574020-14574054 @@ -705,7 +705,7 @@ public class TestRealCases { EDiffHunkParser parser = new EDiffHunkParser(); - List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false); return hierarchicalActionSets; } diff --git a/src/main/java/edu/lu/uni/serval/fixminer/jobs/EnhancedASTDiff.java b/src/main/java/edu/lu/uni/serval/fixminer/jobs/EnhancedASTDiff.java index d07dd45..233e027 100755 --- a/src/main/java/edu/lu/uni/serval/fixminer/jobs/EnhancedASTDiff.java +++ b/src/main/java/edu/lu/uni/serval/fixminer/jobs/EnhancedASTDiff.java @@ -26,7 +26,7 @@ public class EnhancedASTDiff { 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); @@ -47,6 +47,11 @@ public class EnhancedASTDiff { allPredicates.add(predicate); } + boolean isJava = false; + if (projectType.equals("java")){ + isJava =true; + } + File folder = new File(inputPath); File[] listOfFiles = folder.listFiles(); Stream stream = Arrays.stream(listOfFiles); @@ -61,7 +66,7 @@ public class EnhancedASTDiff { List allMessageFiles = new ArrayList<>(); for (File target : folders) { - List msgFiles = getMessageFiles(target.toString() + "/",project,patchSize); //"/Users/anilkoyuncu/bugStudy/code/python/GumTreeInput/Apache/CAMEL/" + List msgFiles = getMessageFiles(target.toString() + "/",project,patchSize,isJava); //"/Users/anilkoyuncu/bugStudy/code/python/GumTreeInput/Apache/CAMEL/" // msgFiles = msgFiles.subList(0,3000); 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()); log.info("{} files to process ...", allMessageFiles.size()); } + boolean finalIsJava = isJava; ProgressBar.wrap(allMessageFiles.stream(). parallel(),"Task"). forEach(m -> { 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 getMessageFiles(String gumTreeInput,String datasetName,String patchSize) { + private static List getMessageFiles(String gumTreeInput,String datasetName,String patchSize,boolean isJava) { String inputPath = gumTreeInput; // prevFiles revFiles diffentryFile positionsFile File revFilesPath = new File(inputPath + "revFiles/"); log.info(revFilesPath.getPath()); @@ -108,7 +114,11 @@ public class EnhancedASTDiff { // for (File revFile : collect) { String fileName = revFile.getName(); 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 String s = FileHelper.readFile(diffentryFile); diff --git a/src/main/java/edu/lu/uni/serval/utils/EDiffHelper.java b/src/main/java/edu/lu/uni/serval/utils/EDiffHelper.java index fe09bc2..179f89b 100755 --- a/src/main/java/edu/lu/uni/serval/utils/EDiffHelper.java +++ b/src/main/java/edu/lu/uni/serval/utils/EDiffHelper.java @@ -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; String astNodeType = null; + Map nodeMap; + if(isJava){ + nodeMap = ASTNodeMap.map; + }else{ + nodeMap = NodeMap_new.map; + } Action action = actionSet.getAction(); if (action instanceof Update){ astNodeType = actionSet.getAstNodeType(); -// List keysByValue = getKeysByValue(ASTNodeMap.map, astNodeType); - List keysByValue = getKeysByValue(NodeMap_new.map, astNodeType); + + List keysByValue = getKeysByValue(nodeMap, astNodeType); if(keysByValue.size() != 1){ log.error("More than 1"); @@ -135,8 +141,8 @@ public class EDiffHelper { newType = ((Move)action).getParent().getType(); }else if(action instanceof Delete){ astNodeType = actionSet.getAstNodeType(); -// List keysByValue = getKeysByValue(ASTNodeMap.map, astNodeType); - List keysByValue = getKeysByValue(NodeMap_new.map, astNodeType); + + List keysByValue = getKeysByValue(nodeMap, astNodeType); if(keysByValue.size() != 1){ log.error("More than 1"); @@ -165,7 +171,7 @@ public class EDiffHelper { if(actionSet.getParent() == null){ children = parent; } - getTargetTree(subAction,children,null,tc); + getTargetTree(subAction,children,null,tc,isJava); } @@ -174,13 +180,18 @@ public class EDiffHelper { 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; - + Map nodeMap; + if(isJava){ + nodeMap = ASTNodeMap.map; + }else{ + nodeMap = NodeMap_new.map; + } String astNodeType = actionSet.getAstNodeType(); -// List keysByValue = getKeysByValue(ASTNodeMap.map, astNodeType); - List keysByValue = getKeysByValue(NodeMap_new.map, astNodeType); + + List keysByValue = getKeysByValue(nodeMap, astNodeType); if(keysByValue.size() != 1){ log.error("More than 1"); @@ -205,7 +216,7 @@ public class EDiffHelper { if(actionSet.getParent() == null){ children = parent; } - getASTTree(subAction,children,null,tc); + getASTTree(subAction,children,null,tc,isJava); } @@ -223,40 +234,40 @@ public class EDiffHelper { .collect(Collectors.toList()); } - public static ITree getSimpliedTree(String prefix, String fn, JedisPool outerPool) { - - ITree tree = null; - Jedis inner = null; - try { - inner = outerPool.getResource(); - while (!inner.ping().equals("PONG")){ - log.info("wait"); - } - inner.select(1); - String dist2load = inner.get(prefix+"-"+fn); - inner.select(0); - String s = inner.get(prefix.replace("-","/") +"/"+dist2load); - HierarchicalActionSet actionSet = (HierarchicalActionSet) EDiffHelper.fromString(s); - - ITree parent = null; - ITree children =null; - TreeContext tc = new TreeContext(); - tree = EDiffHelper.getASTTree(actionSet, parent, children,tc); - tree.setParent(null); - tc.validate(); - - } catch (IOException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - }finally { - if (inner != null) { - inner.close(); - } - } - return tree; - - } +// public static ITree getSimpliedTree(String prefix, String fn, JedisPool outerPool) { +// +// ITree tree = null; +// Jedis inner = null; +// try { +// inner = outerPool.getResource(); +// while (!inner.ping().equals("PONG")){ +// log.info("wait"); +// } +// inner.select(1); +// String dist2load = inner.get(prefix+"-"+fn); +// inner.select(0); +// String s = inner.get(prefix.replace("-","/") +"/"+dist2load); +// HierarchicalActionSet actionSet = (HierarchicalActionSet) EDiffHelper.fromString(s); +// +// ITree parent = null; +// ITree children =null; +// TreeContext tc = new TreeContext(); +// tree = EDiffHelper.getASTTree(actionSet, parent, children,tc); +// tree.setParent(null); +// tc.validate(); +// +// } catch (IOException e) { +// e.printStackTrace(); +// } catch (ClassNotFoundException e) { +// e.printStackTrace(); +// }finally { +// if (inner != null) { +// inner.close(); +// } +// } +// return tree; +// +// } // public static ITree getShapes(String prefix, String fn, JedisPool outerPool, HashMap 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 parent = null; ITree children = null; TreeContext tc = new TreeContext(); - tree = EDiffHelper.getASTTree(actionSet, parent, children, tc); + tree = EDiffHelper.getASTTree(actionSet, parent, children, tc, isJava); //tree.setParent(null); tc.validate(); return tree; } - public static ITree getTargets(HierarchicalActionSet actionSet) { + public static ITree getTargets(HierarchicalActionSet actionSet,boolean isJava) { ITree tree = null; try { @@ -305,7 +316,7 @@ public class EDiffHelper { ITree parent = null; ITree children =null; TreeContext tc = new TreeContext(); - tree = EDiffHelper.getTargetTree(actionSet, parent, children,tc); + tree = EDiffHelper.getTargetTree(actionSet, parent, children,tc,isJava); //tree.setParent(null); tc.validate(); } catch (Exception e) { diff --git a/src/main/resource/wmp00080.uni.lux.app.properties b/src/main/resource/wmp00080.uni.lux.app.properties new file mode 100644 index 0000000..716734e --- /dev/null +++ b/src/main/resource/wmp00080.uni.lux.app.properties @@ -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 + +