diff --git a/FixPatternMiner.iml b/FixPatternMiner.iml new file mode 100644 index 0000000..b309440 --- /dev/null +++ b/FixPatternMiner.iml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5eb9b1c..174b076 100755 --- a/pom.xml +++ b/pom.xml @@ -50,6 +50,12 @@ 2.0.0-SNAPSHOT + + com.github.gumtreediff + gen.srcml + 2.0.0-SNAPSHOT + + org.slf4j @@ -157,6 +163,7 @@ + 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 80ccf6e..66c909e 100755 --- a/src/main/java/edu/lu/uni/serval/fixminer/Launcher.java +++ b/src/main/java/edu/lu/uni/serval/fixminer/Launcher.java @@ -22,8 +22,8 @@ public class Launcher { Properties appProps = new Properties(); -// String appConfigPath = "/Users/anilkoyuncu/bugStudy/release/code/app.properties"; - String appConfigPath = args[0]; + String appConfigPath = "/Users/haoyetian/Documents/Lu_code/FixMiner/fixminer_source/src/main/resource/app.properties"; +// String appConfigPath = args[0]; appProps.load(new FileInputStream(appConfigPath)); String portInner = appProps.getProperty("portInner","6380"); @@ -36,8 +36,10 @@ public class Launcher { String input = appProps.getProperty("inputPath","FORKJOIN"); String redisPath = appProps.getProperty("redisPath","FORKJOIN"); - String parameter = args[2]; - String jobType = args[1]; +// String parameter = args[2]; + String parameter = null; +// String jobType = args[1]; + String jobType = "RICHEDITSCRIPT"; // String parameters = String.format("\nportInner %s " + // "\nnumOfWorkers %s " + diff --git a/src/main/java/edu/lu/uni/serval/fixminer/akka/ediff/EDiffParser.java b/src/main/java/edu/lu/uni/serval/fixminer/akka/ediff/EDiffParser.java index 1f8d203..0578771 100755 --- a/src/main/java/edu/lu/uni/serval/fixminer/akka/ediff/EDiffParser.java +++ b/src/main/java/edu/lu/uni/serval/fixminer/akka/ediff/EDiffParser.java @@ -1,7 +1,9 @@ package edu.lu.uni.serval.fixminer.akka.ediff; import com.github.gumtreediff.actions.model.Action; +import com.github.gumtreediff.gen.srcml.GumTreeCComparer; import edu.lu.uni.serval.gumtree.GumTreeComparer; + import edu.lu.uni.serval.utils.ListSorter; import redis.clients.jedis.JedisPool; @@ -39,7 +41,16 @@ public class EDiffParser extends Parser { protected List parseChangedSourceCodeWithGumTree2(File prevFile, File revFile) { List actionSets = new ArrayList<>(); // GumTree results - List gumTreeResults = new GumTreeComparer().compareTwoFilesWithGumTree(prevFile, revFile); + boolean isJava =false; + List gumTreeResults = null; + if (revFile.getName().endsWith(".c") & prevFile.getName().endsWith(".c")){ +// gumTreeResults = new GumTreeComparer().compareCFilesWithGumTree(prevFile, revFile); + + gumTreeResults = new GumTreeCComparer().compareCFilesWithGumTree(prevFile, revFile); + }else{ + gumTreeResults = new GumTreeComparer().compareTwoFilesWithGumTree(prevFile, revFile); + isJava = true; + } if (gumTreeResults == null) { this.resultType = 1; return null; @@ -48,16 +59,21 @@ public class EDiffParser extends Parser { return actionSets; } else { // Regroup GumTre results. - List allActionSets = new HierarchicalRegrouper().regroupGumTreeResults(gumTreeResults); + List allActionSets = null; + if (isJava){ + allActionSets = new HierarchicalRegrouper().regroupGumTreeResults(gumTreeResults); + }else{ + allActionSets = new HierarchicalRegrouperForC().regroupGumTreeResults(gumTreeResults); + } + - ListSorter sorter = new ListSorter<>(allActionSets); actionSets = sorter.sortAscending(); - + if (actionSets.size() == 0) { this.resultType = 3; } - + return actionSets; } } diff --git a/src/main/java/edu/lu/uni/serval/fixminer/akka/ediff/HierarchicalRegrouperForC.java b/src/main/java/edu/lu/uni/serval/fixminer/akka/ediff/HierarchicalRegrouperForC.java new file mode 100644 index 0000000..b0754c8 --- /dev/null +++ b/src/main/java/edu/lu/uni/serval/fixminer/akka/ediff/HierarchicalRegrouperForC.java @@ -0,0 +1,268 @@ +package edu.lu.uni.serval.fixminer.akka.ediff; + + +import com.github.gumtreediff.actions.model.Action; +import com.github.gumtreediff.actions.model.*; +import com.github.gumtreediff.io.CNodeMap; +import com.github.gumtreediff.tree.ITree; +import edu.lu.uni.serval.gumtree.GumTreeComparer; +import edu.lu.uni.serval.utils.ListSorter; + +import java.util.ArrayList; +import java.util.List; + +/** + * Regroup GumTree results to a hierarchical construction. + * + * @author kui.liu + * + */ +public class HierarchicalRegrouperForC { + +// public static void main(String[] args) { +// GumTreeComparer com = new GumTreeComparer(); +// File cFile1 = new File("/Users/anilkoyuncu/bugStudy/dataset/GumTreeInput/linux-stable/prevFiles/prev_0a3d00_b404bc_drivers#pci#iov.c"); +// File cFile2 = new File("/Users/anilkoyuncu/bugStudy/dataset/GumTreeInput/linux-stable/revFiles/0a3d00_b404bc_drivers#pci#iov.c"); +// List action = com.compareTwoFilesWithGumTreeForCCode(cFile1, cFile2); +// List actionSet = new HierarchicalRegrouperForC().regroupGumTreeResults(action); +// System.out.println(actionSet); +// } + + List actionSets = new ArrayList<>(); + + public List regroupGumTreeResults(List actions) { + /* + * First, sort actions by their positions. + */ +// List actions = new ListSorter(actionsArgu).sortAscending(); +// if (actions == null) { +// actions = actionsArgu; +// } + + /* + * Second, group actions by their positions. + */ + HierarchicalActionSet actionSet = null; + for(Action act : actions){ + Action parentAct = findParentAction(act, actions); + + if (parentAct == null) { + actionSet = createActionSet(act, parentAct, null); + actionSets.add(actionSet); + } else { + if (!addToAactionSet(act, parentAct, actionSets)) { + // The index of the parent action in the actions' list is larger than the index of this action. + actionSet = createActionSet(act, parentAct, null); + actionSets.add(actionSet); + } + } + } + + /* + * Third, add the subActionSet to its parent ActionSet. + */ + List reActionSets = new ArrayList<>(); + for (HierarchicalActionSet actSet : actionSets) { + Action parentAct = actSet.getParentAction(); + if (parentAct != null) { + addToActionSets(actSet, parentAct, actionSets); + } else { + // TypeDeclaration, FieldDeclaration, MethodDeclaration, Statement. + // CatchClause, ConstructorInvocation, SuperConstructorInvocation, SwitchCase +// String astNodeType = actSet.getAstNodeType(); +// if (astNodeType.endsWith("TypeDeclaration") || astNodeType.endsWith("FieldDeclaration") || astNodeType.endsWith("EnumDeclaration") || +// astNodeType.endsWith("MethodDeclaration") || astNodeType.endsWith("Statement") || +// astNodeType.endsWith("ConstructorInvocation") || astNodeType.endsWith("CatchClause") || astNodeType.endsWith("SwitchCase")) { + reActionSets.add(actSet); +// } + } + } + return reActionSets; + } + + private HierarchicalActionSet createActionSet(Action act, Action parentAct, HierarchicalActionSet parent) { + HierarchicalActionSet actionSet = new HierarchicalActionSet(); + actionSet.setAction(act); + actionSet.setActionString(parseAction(act.toString())); + actionSet.setParentAction(parentAct); + actionSet.setNode(act.getNode()); + actionSet.setParent(parent); + return actionSet; + } + + private String parseAction(String actStr1) { + // UPD 25@@!a from !a to isTrue(a) at 69 + String[] actStrArrays = actStr1.split("@@"); + String actStr = ""; + int length = actStrArrays.length; + for (int i =0; i < length - 1; i ++) { + String actStrFrag = actStrArrays[i]; + int index = actStrFrag.lastIndexOf(" ") + 1; + String nodeType = actStrFrag.substring(index); + if (!"".equals(nodeType)) { + if (Character.isDigit(nodeType.charAt(0)) || (nodeType.startsWith("-") && Character.isDigit(nodeType.charAt(1)))) { + try { + int typeInt = Integer.parseInt(nodeType); + if (CNodeMap.map.containsKey(typeInt)) { + String type = CNodeMap.map.get(Integer.parseInt(nodeType)); + nodeType = type; + } + } catch (NumberFormatException e) { + nodeType = actStrFrag.substring(index); + } + } + } + actStrFrag = actStrFrag.substring(0, index) + nodeType + "@@"; + actStr += actStrFrag; + } + actStr += actStrArrays[length - 1]; + return actStr; + } + + private void addToActionSets(HierarchicalActionSet actionSet, Action parentAct, List actionSets) { + Action act = actionSet.getAction(); + for (HierarchicalActionSet actSet : actionSets) { + if (actSet.equals(actionSet)) continue; + Action action = actSet.getAction(); + + if (!areRelatedActions(action, act)) continue; + if (action.equals(parentAct)) { // actSet is the parent of actionSet. + actionSet.setParent(actSet); + actSet.getSubActions().add(actionSet); + sortSubActions(actSet); + break; + } else { + if (isPossibileSubAction(action, act)) { + // SubAction range: startPosition2 <= startPosition && startPosition + length <= startPosition2 + length2 + addToActionSets(actionSet, parentAct, actSet.getSubActions()); + } + } + } + } + + private boolean isPossibileSubAction(Action parent, Action child) { + if ((parent instanceof Update && !(child instanceof Addition)) + || (parent instanceof Delete && child instanceof Delete) + || (parent instanceof Insert && (child instanceof Insert))) { + int startPosition = child.getPosition(); + int length = child.getLength(); + int startPosition2 = parent.getPosition(); + int length2 = parent.getLength(); + + if (!(startPosition2 <= startPosition && startPosition + length <= startPosition2 + length2)) { + // when act is not the sub-set of action. + return false; + } + } + return true; + } + + private void sortSubActions(HierarchicalActionSet actionSet) { + ListSorter sorter = new ListSorter(actionSet.getSubActions()); + List subActions = sorter.sortAscending(); + if (subActions != null) { + actionSet.setSubActions(subActions); + } + } + + private boolean addToAactionSet(Action act, Action parentAct, List actionSets) { + for(HierarchicalActionSet actionSet : actionSets) { + Action action = actionSet.getAction(); + + if (!areRelatedActions(action, act)) continue; + + if (action.equals(parentAct)) { // actionSet is the parent of actSet. + HierarchicalActionSet actSet = createActionSet(act, actionSet.getAction(), actionSet); + actionSet.getSubActions().add(actSet); + sortSubActions(actionSet); + return true; + } else { + if (isPossibileSubAction(action, act)) { + // SubAction range: startPosition2 <= startPosition && startPosition + length <= startP + length2 + List subActionSets = actionSet.getSubActions(); + if (subActionSets.size() > 0) { + boolean added = addToAactionSet(act, parentAct, subActionSets); + if (added) { + return true; + } else { + continue; + } + } + } + } + } + return false; + } + + List newParentActions = new ArrayList<>(); + private Action findParentAction(Action action, List actions) { + + ITree parent = action.getNode().getParent(); + if (parent == null) return null; + if (action instanceof Addition) { + parent = ((Addition) action).getParent(); // parent in the fixed source code tree + } + + for (Action act : actions) { + if (act.getNode().equals(parent)) { + if (areRelatedActions(act, action)) { + return act; + } + } + } + for (Action act : newParentActions) { + if (act.getNode().equals(parent)) { + if (areRelatedActions(act, action)) { + return act; + } + } + } + + ITree tree = action.getNode(); + Action parentAction = null; + if (!isStatement(tree)) { + parentAction = new Update(parent, action.getNode().getParent()); + newParentActions.add(parentAction); + + Action higherParentAct = findParentAction(parentAction, actions); + HierarchicalActionSet actionSet = null; + if (higherParentAct == null) { + actionSet = createActionSet(parentAction, higherParentAct, null); + actionSets.add(actionSet); + } else { + if (!addToAactionSet(parentAction, higherParentAct, actionSets)) { + // The index of the parent action in the actions' list is larger than the index of this action. + actionSet = createActionSet(parentAction, higherParentAct, null); + actionSets.add(actionSet); + } + } + } + return parentAction; + } + + private boolean isStatement(ITree tree) { + int nodeType = tree.getType(); + + if (nodeType == 11 || nodeType == 16 || nodeType == 18 || nodeType == 21 + || nodeType == 22 || nodeType == 23 || nodeType == 24 || nodeType == 84 + || 30 == nodeType || nodeType == 31 || nodeType == 32 || nodeType == 33 + || nodeType == 34 || nodeType == 35 || nodeType == 36 || nodeType == 40 + || nodeType == 41 || nodeType == 49 || nodeType == 73) {// TODO + return true; + } + return false; + } + + private boolean areRelatedActions(Action parent, Action child) { + if (parent instanceof Move && !(child instanceof Move)) {// If action is MOV, its children must be MOV. + return false; + } + if (parent instanceof Delete && !(child instanceof Delete)) {// If action is DEL, its children must be DEL. + return false; + } + if (parent instanceof Insert && !(child instanceof Addition)) {// If action is INS, its children must be MOV or INS. + return false; + } + return true; + } +} 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 fd097cb..7c7e690 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 @@ -118,7 +118,7 @@ public class EnhancedASTDiff { log.info(revFilesPath.getPath()); File[] revFiles = revFilesPath.listFiles(); if (revFiles!= null ){ - // List collect = Arrays.stream(revFiles).filter(x -> x.getName().startsWith("b50867_6e80c3_src#main#java#org#apache#hadoop#hbase#regionserver#HRegion")) + // List collect = Arrays.stream(revFiles).filter(x -> x.getName().startsWith("0a2756_7598f8_components#camel-cxf#src#main#java#org#apache#camel#component#cxf#CxfHeaderFilterStrategy")) // .collect(Collectors.toList());// project folders List msgFiles = new ArrayList<>(); for (File revFile : revFiles) { diff --git a/src/main/resource/app.properties b/src/main/resource/app.properties index 5e48335..8e57561 100755 --- a/src/main/resource/app.properties +++ b/src/main/resource/app.properties @@ -1,14 +1,14 @@ -jobType = LEVEL2 -pjName = BugsDotJar +jobType = RICHEDITSCRIPT +pjName = gumInput portInner = 6380 -dbNo = 0 -port = 6399 -serverWait = 10000 -numOfWorkers = 100 -pythonPath = /Users/anilkoyuncu/bugStudy/code/python -datasetPath = /Users/anilkoyuncu/bugStudy/release/code -actionType =UPD -threshold = 9 +portDumps = 6399 +parallelism = AKKA +numOfWorkers = 1 +#inputPath = /Users/haoyetian/Documents/Lu_code/FixMiner/fixminer-core/python/data/gumInput +inputPath = /Users/haoyetian/Documents/Lu_code/test +redisPath = /Users/haoyetian/Documents/Lu_code/FixMiner/fixminer-core/python/data/redis +actionType =ALL +eDiffTimeout = 900 #ENHANCEDASTDIFF,CACHE,LEVEL1,LEVEL2,LEVEL3