[O] Reformat code for java

This commit is contained in:
Azalea (on HyDEV-Daisy)
2022-05-16 01:40:16 -04:00
parent 99c365076a
commit 40a2722a01
23 changed files with 2719 additions and 2370 deletions
@@ -17,7 +17,7 @@ import java.util.Properties;
*/ */
public class Launcher public class Launcher
{ {
private static Logger log = LoggerFactory.getLogger(Launcher.class); private static final Logger log = LoggerFactory.getLogger(Launcher.class);
public static void main(String[] args) throws IOException public static void main(String[] args) throws IOException
{ {
@@ -3,42 +3,51 @@ package edu.lu.uni.serval.richedit.ediff;
/** /**
* Created by anilkoyuncu on 18/09/2018. * Created by anilkoyuncu on 18/09/2018.
*/ */
public class BaseMessage { public class BaseMessage
{
private long SECONDS_TO_WAIT; private long SECONDS_TO_WAIT;
private int id; private int id;
private int threadPoolSize; private int threadPoolSize;
public BaseMessage(int id,Long timeout) { public BaseMessage(int id, Long timeout)
{
this.id = id; this.id = id;
this.SECONDS_TO_WAIT = timeout; this.SECONDS_TO_WAIT = timeout;
// this.threadPoolSize = threadPoolSize; // this.threadPoolSize = threadPoolSize;
} }
public int getId() { public int getId()
{
return id; return id;
} }
public void setId(int id) { public void setId(int id)
{
this.id = id; this.id = id;
} }
public long getSECONDS_TO_WAIT()
public long getSECONDS_TO_WAIT() { {
return SECONDS_TO_WAIT; return SECONDS_TO_WAIT;
} }
public void setSECONDS_TO_WAIT(long SECONDS_TO_WAIT) { public void setSECONDS_TO_WAIT(long SECONDS_TO_WAIT)
{
this.SECONDS_TO_WAIT = SECONDS_TO_WAIT; this.SECONDS_TO_WAIT = SECONDS_TO_WAIT;
} }
public int getThreadPoolSize() { public int getThreadPoolSize()
{
return threadPoolSize; return threadPoolSize;
} }
public void setThreadPoolSize(int threadPoolSize) { public void setThreadPoolSize(int threadPoolSize)
{
this.threadPoolSize = threadPoolSize; this.threadPoolSize = threadPoolSize;
} }
@@ -10,66 +10,84 @@ import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
public class EDiffActor extends UntypedActor { public class EDiffActor extends UntypedActor
{
private static Logger logger = LoggerFactory.getLogger(EDiffActor.class);
private ActorRef mineRouter; private static final Logger logger = LoggerFactory.getLogger(EDiffActor.class);
private final int numberOfWorkers;
private int counter = 0;
public EDiffActor(int numberOfWorkers, String project) {
mineRouter = this.getContext().actorOf(new RoundRobinPool(numberOfWorkers)
.props(EDiffWorker.props(project)), "mine-fix-pattern-router");
this.numberOfWorkers = numberOfWorkers;
}
public static Props props(final int numberOfWorkers, final String project) { private final ActorRef mineRouter;
return Props.create(new Creator<EDiffActor>() {
private static final long serialVersionUID = 9207427376110704705L; private final int numberOfWorkers;
@Override private int counter = 0;
public EDiffActor create() throws Exception {
return new EDiffActor(numberOfWorkers, project); public EDiffActor(int numberOfWorkers, String project)
} {
mineRouter = this.getContext().actorOf(new RoundRobinPool(numberOfWorkers)
}); .props(EDiffWorker.props(project)), "mine-fix-pattern-router");
} this.numberOfWorkers = numberOfWorkers;
}
@SuppressWarnings("deprecation")
@Override public static Props props(final int numberOfWorkers, final String project)
public void onReceive(Object message) throws Exception { {
if (message instanceof EDiffMessage) {
List<MessageFile> files = ((EDiffMessage) message).getMsgFiles(); return Props.create(new Creator<EDiffActor>()
int size = files.size(); {
int average = size / numberOfWorkers;
int reminder = size % numberOfWorkers; private static final long serialVersionUID = 9207427376110704705L;
int counter = 0;
@Override
for (int i = 0; i < numberOfWorkers; i ++) { public EDiffActor create() throws Exception
int fromIndex = i * average + counter; {
if (counter < reminder) counter ++; return new EDiffActor(numberOfWorkers, project);
int toIndex = (i + 1) * average + counter; }
List<MessageFile> filesOfWorkers = files.subList(fromIndex, toIndex); });
final EDiffMessage workMsg = new EDiffMessage(i + 1, filesOfWorkers,((EDiffMessage) message).getSECONDS_TO_WAIT(),((EDiffMessage) message).getInnerPool(),((EDiffMessage) message).getSrcMLPath(),((EDiffMessage) message).getRootType()); }
mineRouter.tell(workMsg, getSelf());
logger.info("Assign {} task to worker #" + (i + 1) ,filesOfWorkers.size()); @SuppressWarnings("deprecation")
} @Override
} else if ("STOP".equals(message.toString())) { public void onReceive(Object message) throws Exception
counter ++; {
logger.info(counter + " workers finalized their work..."); if (message instanceof EDiffMessage)
if (counter >= numberOfWorkers) { {
logger.info("All workers finalized their work..."); List<MessageFile> files = ((EDiffMessage) message).getMsgFiles();
this.getContext().stop(mineRouter); int size = files.size();
this.getContext().stop(getSelf()); int average = size / numberOfWorkers;
this.getContext().system().shutdown(); int reminder = size % numberOfWorkers;
} int counter = 0;
} else {
unhandled(message); for (int i = 0; i < numberOfWorkers; i++)
} {
} int fromIndex = i * average + counter;
if (counter < reminder)
{
counter++;
}
int toIndex = (i + 1) * average + counter;
List<MessageFile> filesOfWorkers = files.subList(fromIndex, toIndex);
final EDiffMessage workMsg = new EDiffMessage(i + 1, filesOfWorkers, ((EDiffMessage) message).getSECONDS_TO_WAIT(), ((EDiffMessage) message).getInnerPool(), ((EDiffMessage) message).getSrcMLPath(), ((EDiffMessage) message).getRootType());
mineRouter.tell(workMsg, getSelf());
logger.info("Assign {} task to worker #" + (i + 1), filesOfWorkers.size());
}
}
else if ("STOP".equals(message.toString()))
{
counter++;
logger.info(counter + " workers finalized their work...");
if (counter >= numberOfWorkers)
{
logger.info("All workers finalized their work...");
this.getContext().stop(mineRouter);
this.getContext().stop(getSelf());
this.getContext().system().shutdown();
}
}
else
{
unhandled(message);
}
}
} }
@@ -11,101 +11,110 @@ import java.io.File;
import java.util.List; import java.util.List;
/** /**
* Parse fix violations with GumTree in terms of multiple statements. * Parse fix violations with GumTree in terms of multiple statements.
* *
* @author kui.liu * @author kui.liu
*
*/ */
public class EDiffHunkParser extends EDiffParser { public class EDiffHunkParser extends EDiffParser
{
private static Logger logger = LoggerFactory.getLogger(EDiffHunkParser.class); private static final Logger logger = LoggerFactory.getLogger(EDiffHunkParser.class);
@Override
public void parseFixPatterns(File prevFile, File revFile, File diffentryFile, String project, JedisPool innerPool,String srcMLPath,String hunkLimit,boolean isJava) { @Override
try { 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); try
String root = split1[0]; {
String pj = split1[1].split("/")[1]; String datasetName = project;
String[] split1 = diffentryFile.getParent().split(datasetName);
String root = split1[0];
String pj = split1[1].split("/")[1];
List<HierarchicalActionSet> actionSets = parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath, isJava); List<HierarchicalActionSet> actionSets = parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath, isJava);
if (actionSets != null && actionSets.size() != 0) { if (actionSets != null && actionSets.size() != 0)
{
boolean processActionSet = true; boolean processActionSet = true;
if (actionSets.size() > Integer.valueOf(hunkLimit)) { if (actionSets.size() > Integer.valueOf(hunkLimit))
processActionSet = false; {
logger.debug("Skipping {} set size {}", diffentryFile.getName(), hunkLimit); processActionSet = false;
} logger.debug("Skipping {} set size {}", diffentryFile.getName(), hunkLimit);
}
int hunkSet = 0; int hunkSet = 0;
if (processActionSet) { if (processActionSet)
{
for (HierarchicalActionSet actionSet : actionSets) { for (HierarchicalActionSet actionSet : actionSets)
// FileOutputStream f = null; {
// FileOutputStream f = null;
// try { // try {
String astNodeType = actionSet.getAstNodeType(); String astNodeType = actionSet.getAstNodeType();
// if (astNodeType.equals(rootType)){ // if (astNodeType.equals(rootType)){
// //
// } // }
actionSet.toString(); actionSet.toString();
int size = actionSet.getActionSize(); int size = actionSet.getActionSize();
String key = astNodeType + "/" + String.valueOf(size) + "/" + pj + "_" + diffentryFile.getName() + "_" + String.valueOf(hunkSet); String key = astNodeType + "/" + size + "/" + pj + "_" + diffentryFile.getName() + "_" + hunkSet;
ITree targetTree = EDiffHelper.getTargets(actionSet, isJava); ITree targetTree = EDiffHelper.getTargets(actionSet, isJava);
ITree actionTree = EDiffHelper.getActionTrees(actionSet); ITree actionTree = EDiffHelper.getActionTrees(actionSet);
ITree shapeTree = EDiffHelper.getShapeTree(actionSet, isJava); ITree shapeTree = EDiffHelper.getShapeTree(actionSet, isJava);
ITree tokenTree = EDiffHelper.getTokenTree(actionSet,isJava); ITree tokenTree = EDiffHelper.getTokenTree(actionSet, isJava);
String tokens = EDiffHelper.getNames2(tokenTree); String tokens = EDiffHelper.getNames2(tokenTree);
// EDiffHelper.getTokenTree(actionSet, parent, children, tc); // EDiffHelper.getTokenTree(actionSet, parent, children, tc);
try (Jedis inner = innerPool.getResource()) { try (Jedis inner = innerPool.getResource())
{
inner.hset("dump", key, actionSet.toString()); inner.hset("dump", key, actionSet.toString());
inner.hset(key, "actionTree", actionTree.toStaticHashString()); inner.hset(key, "actionTree", actionTree.toStaticHashString());
inner.hset(key, "targetTree", targetTree.toStaticHashString()); inner.hset(key, "targetTree", targetTree.toStaticHashString());
inner.hset(key, "shapeTree", shapeTree.toStaticHashString()); inner.hset(key, "shapeTree", shapeTree.toStaticHashString());
inner.hset(key, "tokens", tokens); inner.hset(key, "tokens", tokens);
} }
// File f = new File(root+"dumps/"+astNodeType+"/"+String.valueOf(size)+"/"); // File f = new File(root+"dumps/"+astNodeType+"/"+String.valueOf(size)+"/");
// f.mkdirs(); // f.mkdirs();
// f = new File(root+"dumps/"+key); // f = new File(root+"dumps/"+key);
// //
// FileUtils.writeByteArrayToFile(f,EDiffHelper.kryoSerialize(actionSet)); // FileUtils.writeByteArrayToFile(f,EDiffHelper.kryoSerialize(actionSet));
// FileUtils.writeByteArrayToFile(f,EDiffHelper.commonsSerialize(actionSet)); // FileUtils.writeByteArrayToFile(f,EDiffHelper.commonsSerialize(actionSet));
// FileUtils.writeByteArrayToFile(f,actionSet.toString().getBytes()); // FileUtils.writeByteArrayToFile(f,actionSet.toString().getBytes());
// FileOutputStream fos = new FileOutputStream(f); // FileOutputStream fos = new FileOutputStream(f);
// ObjectOutputStream oos = new ObjectOutputStream(fos); // ObjectOutputStream oos = new ObjectOutputStream(fos);
// oos.writeObject(EDiffHelper.kryoSerialize(actionSet)); // oos.writeObject(EDiffHelper.kryoSerialize(actionSet));
// oos.flush(); // oos.flush();
// oos.close(); // oos.close();
// } catch (Exception e) { // } catch (Exception e) {
// logger.error("error", e); // logger.error("error", e);
//// e.printStackTrace(); //// e.printStackTrace();
// } // }
hunkSet++; hunkSet++;
} }
try (Jedis inner = innerPool.getResource()) { try (Jedis inner = innerPool.getResource())
inner.hset("diffEntry", pj + "_" + diffentryFile.getName(), "1"); {
} inner.hset("diffEntry", pj + "_" + diffentryFile.getName(), "1");
}
} }
} }
} catch (Exception e) { }
logger.error("error", e); catch (Exception e)
// e.printStackTrace(); {
} logger.error("error", e);
// e.printStackTrace();
}
} }
} }
@@ -4,63 +4,70 @@ import redis.clients.jedis.JedisPool;
import java.util.List; import java.util.List;
public class EDiffMessage extends BaseMessage{ public class EDiffMessage extends BaseMessage
{
private List<MessageFile> msgFiles; private final List<MessageFile> msgFiles;
public JedisPool getInnerPool() { public JedisPool getInnerPool()
return innerPool; {
} return innerPool;
}
public void setInnerPool(JedisPool innerPool) { public void setInnerPool(JedisPool innerPool)
this.innerPool = innerPool; {
} this.innerPool = innerPool;
}
private JedisPool innerPool; private JedisPool innerPool;
public String getSrcMLPath() { public String getSrcMLPath()
return srcMLPath; {
} return srcMLPath;
}
private String srcMLPath; private String srcMLPath;
public String getRootType() { public String getRootType()
return rootType; {
} return rootType;
}
private String rootType; private String rootType;
public EDiffMessage(int id, List<MessageFile> msgFiles, String eDiffTimeout, JedisPool pool, String srcMLPath, String rootType)
{
super(id, new Long(eDiffTimeout));
this.msgFiles = msgFiles;
this.innerPool = pool;
this.srcMLPath = srcMLPath;
this.rootType = rootType;
}
public EDiffMessage(int id, List<MessageFile> msgFiles, Long eDiffTimeout, JedisPool pool)
{
super(id, eDiffTimeout);
this.msgFiles = msgFiles;
this.innerPool = pool;
}
public EDiffMessage(int id, List<MessageFile> filesOfWorkers, long seconds_to_wait, JedisPool innerPool, String srcMLPath, String rootType)
public EDiffMessage(int id, List<MessageFile> msgFiles,String eDiffTimeout,JedisPool pool,String srcMLPath,String rootType) { {
super(id,new Long(eDiffTimeout));
this.msgFiles = msgFiles;
this.innerPool = pool;
this.srcMLPath = srcMLPath;
this.rootType = rootType;
}
public EDiffMessage(int id, List<MessageFile> msgFiles,Long eDiffTimeout,JedisPool pool) {
super(id,eDiffTimeout);
this.msgFiles = msgFiles;
this.innerPool = pool;
}
super(id, seconds_to_wait);
this.msgFiles = filesOfWorkers;
this.innerPool = innerPool;
this.srcMLPath = srcMLPath;
this.rootType = rootType;
}
public EDiffMessage(int id, List<MessageFile> filesOfWorkers, long seconds_to_wait, JedisPool innerPool, String srcMLPath,String rootType) { public List<MessageFile> getMsgFiles()
{
return msgFiles;
}
super(id,seconds_to_wait); }
this.msgFiles = filesOfWorkers;
this.innerPool = innerPool;
this.srcMLPath = srcMLPath;
this.rootType = rootType;
}
public List<MessageFile> getMsgFiles() {
return msgFiles;
}
}
@@ -3,8 +3,6 @@ package edu.lu.uni.serval.richedit.ediff;
import com.github.gumtreediff.actions.model.Action; import com.github.gumtreediff.actions.model.Action;
import com.github.gumtreediff.gen.srcml.GumTreeCComparer; import com.github.gumtreediff.gen.srcml.GumTreeCComparer;
import edu.lu.uni.serval.gumtree.GumTreeComparer; import edu.lu.uni.serval.gumtree.GumTreeComparer;
import edu.lu.uni.serval.utils.ListSorter; import edu.lu.uni.serval.utils.ListSorter;
import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPool;
@@ -18,87 +16,100 @@ import java.util.List;
* Parse fix patterns with GumTree. * Parse fix patterns with GumTree.
* *
* @author kui.liu * @author kui.liu
*
*/ */
public class EDiffParser extends Parser { public class EDiffParser extends Parser
{
/* /*
* ResultType: * ResultType:
* 0: normal GumTree results. * 0: normal GumTree results.
* 1: null GumTree result. * 1: null GumTree result.
* 2: No source code changes. * 2: No source code changes.
* 3: No Statement Change. * 3: No Statement Change.
* 4: useless violations * 4: useless violations
*/ */
public int resultType = 0; public int resultType = 0;
/**
* Regroup GumTree results without remove the modification of variable names.
*
* @param prevFile
* @param revFile
* @return
*/
public List<HierarchicalActionSet> parseChangedSourceCodeWithGumTree2(File prevFile, File revFile, String srcMLPath, boolean isJava)
{
List<HierarchicalActionSet> actionSets = new ArrayList<>();
// GumTree results
// boolean isJava =false;
List<Action> gumTreeResults = null;
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 GumTreeComparer().compareTwoFilesWithGumTree(prevFile, revFile);
* Regroup GumTree results without remove the modification of variable names.
*
* @param prevFile
* @param revFile
* @return
*/
public List<HierarchicalActionSet> parseChangedSourceCodeWithGumTree2(File prevFile, File revFile,String srcMLPath,boolean isJava) {
List<HierarchicalActionSet> actionSets = new ArrayList<>();
// GumTree results
// boolean isJava =false;
List<Action> gumTreeResults = null;
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 GumTreeComparer().compareTwoFilesWithGumTree(prevFile, revFile);
}else{ }
gumTreeResults = new GumTreeCComparer().compareCFilesWithGumTree(prevFile, revFile,srcMLPath); else
{
gumTreeResults = new GumTreeCComparer().compareCFilesWithGumTree(prevFile, revFile, srcMLPath);
} }
if (gumTreeResults == null) { if (gumTreeResults == null)
this.resultType = 1; {
return actionSets; this.resultType = 1;
} else if (gumTreeResults.size() == 0){ return actionSets;
this.resultType = 2; }
return actionSets; else if (gumTreeResults.size() == 0)
} else { {
// Regroup GumTre results. this.resultType = 2;
List<HierarchicalActionSet> allActionSets = null; return actionSets;
if (isJava){ }
allActionSets = new HierarchicalRegrouper().regroupGumTreeResults(gumTreeResults); else
}else{ {
HashSet<Integer> removeType = new HashSet<Integer>(Arrays.asList(131,132,133,134,135,136,137)); // Regroup GumTre results.
boolean b = gumTreeResults.stream().anyMatch(p -> removeType.contains(p.getNode().getType())); List<HierarchicalActionSet> allActionSets = null;
if(b){ if (isJava)
return actionSets; {
} allActionSets = new HierarchicalRegrouper().regroupGumTreeResults(gumTreeResults);
allActionSets = new HierarchicalRegrouperForC().regroupGumTreeResults(gumTreeResults); }
} else
{
HashSet<Integer> removeType = new HashSet<Integer>(Arrays.asList(131, 132, 133, 134, 135, 136, 137));
boolean b = gumTreeResults.stream().anyMatch(p -> removeType.contains(p.getNode().getType()));
if (b)
{
return actionSets;
}
allActionSets = new HierarchicalRegrouperForC().regroupGumTreeResults(gumTreeResults);
}
ListSorter<HierarchicalActionSet> sorter = new ListSorter<>(allActionSets); ListSorter<HierarchicalActionSet> sorter = new ListSorter<>(allActionSets);
actionSets = sorter.sortAscending(); actionSets = sorter.sortAscending();
if (actionSets.size() == 0) { if (actionSets.size() == 0)
this.resultType = 3; {
} this.resultType = 3;
}
return actionSets; return actionSets;
} }
} }
@Override @Override
public void parseFixPatterns(File prevFile, File revFile, File diffEntryFile, String project, JedisPool innerPool, String srcMLPath,String rootType,boolean isJava) { public void parseFixPatterns(File prevFile, File revFile, File diffEntryFile, String project, JedisPool innerPool, String srcMLPath, String rootType, boolean isJava)
{
} }
// @Override
// public void parseFixPatterns(File prevFile, File revFile, File diffEntryFile, String project, JedisPool innerPool) {
//
// }
// @Override
// public void parseFixPatterns(File prevFile, File revFile, File diffEntryFile, String project, JedisPool innerPool) {
//
// }
} }
@@ -11,82 +11,101 @@ import java.io.File;
import java.util.List; import java.util.List;
import java.util.concurrent.*; import java.util.concurrent.*;
public class EDiffWorker extends UntypedActor { public class EDiffWorker extends UntypedActor
private static Logger log = LoggerFactory.getLogger(EDiffActor.class); {
private static final Logger log = LoggerFactory.getLogger(EDiffActor.class);
private String project;
private final String project;
public EDiffWorker(String project) {
this.project = project;
}
public static Props props(final String project) {
return Props.create(new Creator<EDiffWorker>() {
private static final long serialVersionUID = -7615153844097275009L;
@Override
public EDiffWorker create() throws Exception {
return new EDiffWorker(project);
}
});
}
@Override
public void onReceive(Object message) throws Exception {
if (message instanceof EDiffMessage) {
EDiffMessage msg = (EDiffMessage) message;
List<MessageFile> files = msg.getMsgFiles();
int id = msg.getId();
int counter = 0;
JedisPool innerPool = msg.getInnerPool();
String srcMLPath = msg.getSrcMLPath();
String rootType = msg.getRootType();
for (MessageFile msgFile : files) {
File revFile = msgFile.getRevFile();
File prevFile = msgFile.getPrevFile();
File diffentryFile = msgFile.getDiffEntryFile();
public EDiffWorker(String project)
{
this.project = project;
}
EDiffHunkParser parser = new EDiffHunkParser(); public static Props props(final String project)
{
return Props.create(new Creator<EDiffWorker>()
{
final ExecutorService executor = Executors.newSingleThreadExecutor(); private static final long serialVersionUID = -7615153844097275009L;
// schedule the work
@Override
public EDiffWorker create() throws Exception
{
return new EDiffWorker(project);
}
});
}
@Override
public void onReceive(Object message) throws Exception
{
if (message instanceof EDiffMessage)
{
EDiffMessage msg = (EDiffMessage) message;
List<MessageFile> files = msg.getMsgFiles();
int id = msg.getId();
int counter = 0;
JedisPool innerPool = msg.getInnerPool();
String srcMLPath = msg.getSrcMLPath();
String rootType = msg.getRootType();
for (MessageFile msgFile : files)
{
File revFile = msgFile.getRevFile();
File prevFile = msgFile.getPrevFile();
File diffentryFile = msgFile.getDiffEntryFile();
final Future<?> future = executor.submit(new RunnableParser(prevFile, revFile, diffentryFile, parser,project,msg.getInnerPool(),srcMLPath,rootType,false)); EDiffHunkParser parser = new EDiffHunkParser();
try {
// wait for task to complete
future.get(msg.getSECONDS_TO_WAIT(), TimeUnit.SECONDS);
counter ++; final ExecutorService executor = Executors.newSingleThreadExecutor();
if (counter % 1000 == 0) { // schedule the work
log.info("Worker #" + id +" finalized parsing " + counter + " files... remaing "+ (files.size() - counter));
}
} catch (TimeoutException e) {
future.cancel(true);
System.err.println("#Timeout: " + revFile.getName());
} catch (InterruptedException e) {
System.err.println("#TimeInterrupted: " + revFile.getName());
e.printStackTrace();
} catch (ExecutionException e) {
System.err.println("#TimeAborted: " + revFile.getName());
e.printStackTrace();
} finally {
executor.shutdownNow();
}
}
log.info("Worker #" + id + " finalized the work...");
this.getSender().tell("STOP", getSelf()); final Future<?> future = executor.submit(new RunnableParser(prevFile, revFile, diffentryFile, parser, project, msg.getInnerPool(), srcMLPath, rootType, false));
} else { try
unhandled(message); {
} // wait for task to complete
} future.get(msg.getSECONDS_TO_WAIT(), TimeUnit.SECONDS);
counter++;
if (counter % 1000 == 0)
{
log.info("Worker #" + id + " finalized parsing " + counter + " files... remaing " + (files.size() - counter));
}
}
catch (TimeoutException e)
{
future.cancel(true);
System.err.println("#Timeout: " + revFile.getName());
}
catch (InterruptedException e)
{
System.err.println("#TimeInterrupted: " + revFile.getName());
e.printStackTrace();
}
catch (ExecutionException e)
{
System.err.println("#TimeAborted: " + revFile.getName());
e.printStackTrace();
}
finally
{
executor.shutdownNow();
}
}
log.info("Worker #" + id + " finalized the work...");
this.getSender().tell("STOP", getSelf());
}
else
{
unhandled(message);
}
}
} }
@@ -9,203 +9,256 @@ import java.util.List;
/** /**
* Hierarchical-level results of GumTree results * Hierarchical-level results of GumTree results
*
* @author kui.liu
* *
* @author kui.liu
*/ */
public class HierarchicalActionSet implements Comparable<HierarchicalActionSet>,Serializable { public class HierarchicalActionSet implements Comparable<HierarchicalActionSet>, Serializable
{
private String astNodeType;
private Action action;
private Action parentAction;
private String actionString;
private Integer startPosition;
private Integer length;
private int bugStartLineNum = 0;
private int bugEndLineNum;
private int fixStartLineNum;
private int fixEndLineNum;
private HierarchicalActionSet parent = null;
private List<HierarchicalActionSet> subActions = new ArrayList<>();
private ITree node;
// source code tree.
public int getBugEndPosition() { private String astNodeType;
return bugEndPosition;
}
public int getFixEndPosition() { private Action action;
return fixEndPosition;
}
private int bugEndPosition; private Action parentAction;
private int fixEndPosition;
public ITree getNode() { private String actionString;
return node;
}
public void setNode(ITree node) { private Integer startPosition;
this.node = node;
}
public void setAstNodeType(String astNodeType) { private Integer length;
this.astNodeType = astNodeType;
}
public String getAstNodeType() {
return astNodeType;
}
public Action getAction() { private int bugStartLineNum = 0;
return action;
}
public void setAction(Action action) { private int bugEndLineNum;
this.action = action;
}
public Action getParentAction() { private int fixStartLineNum;
return parentAction;
}
public void setParentAction(Action parentAction) { private int fixEndLineNum;
this.parentAction = parentAction;
}
public String getActionString() { private HierarchicalActionSet parent = null;
return actionString;
}
public void setActionString(String actionString) { private List<HierarchicalActionSet> subActions = new ArrayList<>();
this.actionString = actionString;
int atIndex = actionString.indexOf("@AT@") + 4;
int lengthIndex = actionString.indexOf("@LENGTH@");
if (lengthIndex == -1) {
this.startPosition = Integer.parseInt(actionString.substring(atIndex).trim());
this.length = 0;
} else {
this.startPosition = Integer.parseInt(actionString.substring(atIndex, lengthIndex).trim());
this.length = Integer.parseInt(actionString.substring(lengthIndex + 8).trim());
}
String nodeType = actionString.substring(0, actionString.indexOf("@@"));
nodeType = nodeType.substring(nodeType.indexOf(" ") + 1);
this.astNodeType = nodeType;
}
public int getStartPosition() { private ITree node;
return startPosition; // source code tree.
}
public int getLength() { public int getBugEndPosition()
return length; {
} return bugEndPosition;
}
public int getBugStartLineNum() { public int getFixEndPosition()
return bugStartLineNum; {
} return fixEndPosition;
}
public void setBugStartLineNum(int bugStartLineNum) { private int bugEndPosition;
this.bugStartLineNum = bugStartLineNum;
}
public int getBugEndLineNum() { private int fixEndPosition;
return bugEndLineNum;
}
public void setBugEndLineNum(int bugEndLineNum) { public ITree getNode()
this.bugEndLineNum = bugEndLineNum; {
} return node;
}
public int getFixStartLineNum() { public void setNode(ITree node)
return fixStartLineNum; {
} this.node = node;
}
public void setFixStartLineNum(int fixStartLineNum) { public void setAstNodeType(String astNodeType)
this.fixStartLineNum = fixStartLineNum; {
} this.astNodeType = astNodeType;
}
public int getFixEndLineNum() { public String getAstNodeType()
return fixEndLineNum; {
} return astNodeType;
}
public void setFixEndLineNum(int fixEndLineNum) { public Action getAction()
this.fixEndLineNum = fixEndLineNum; {
} return action;
}
public HierarchicalActionSet getParent() { public void setAction(Action action)
return parent; {
} this.action = action;
}
public void setParent(HierarchicalActionSet parent) { public Action getParentAction()
this.parent = parent; {
} return parentAction;
}
public List<HierarchicalActionSet> getSubActions() { public void setParentAction(Action parentAction)
return subActions; {
} this.parentAction = parentAction;
}
public void setSubActions(List<HierarchicalActionSet> subActions) { public String getActionString()
this.subActions = subActions; {
} return actionString;
}
public void setActionString(String actionString)
{
this.actionString = actionString;
int atIndex = actionString.indexOf("@AT@") + 4;
int lengthIndex = actionString.indexOf("@LENGTH@");
if (lengthIndex == -1)
{
this.startPosition = Integer.parseInt(actionString.substring(atIndex).trim());
this.length = 0;
}
else
{
this.startPosition = Integer.parseInt(actionString.substring(atIndex, lengthIndex).trim());
this.length = Integer.parseInt(actionString.substring(lengthIndex + 8).trim());
}
String nodeType = actionString.substring(0, actionString.indexOf("@@"));
nodeType = nodeType.substring(nodeType.indexOf(" ") + 1);
this.astNodeType = nodeType;
}
public int getStartPosition()
{
return startPosition;
}
public int getLength()
{
return length;
}
public int getBugStartLineNum()
{
return bugStartLineNum;
}
public void setBugStartLineNum(int bugStartLineNum)
{
this.bugStartLineNum = bugStartLineNum;
}
public int getBugEndLineNum()
{
return bugEndLineNum;
}
public void setBugEndLineNum(int bugEndLineNum)
{
this.bugEndLineNum = bugEndLineNum;
}
public int getFixStartLineNum()
{
return fixStartLineNum;
}
public void setFixStartLineNum(int fixStartLineNum)
{
this.fixStartLineNum = fixStartLineNum;
}
public int getFixEndLineNum()
{
return fixEndLineNum;
}
public void setFixEndLineNum(int fixEndLineNum)
{
this.fixEndLineNum = fixEndLineNum;
}
public HierarchicalActionSet getParent()
{
return parent;
}
public void setParent(HierarchicalActionSet parent)
{
this.parent = parent;
}
public List<HierarchicalActionSet> getSubActions()
{
return subActions;
}
public void setSubActions(List<HierarchicalActionSet> subActions)
{
this.subActions = subActions;
}
public void setBugEndPosition(int bugEndPosition) { public void setBugEndPosition(int bugEndPosition)
this.bugEndPosition = bugEndPosition; {
} this.bugEndPosition = bugEndPosition;
}
public void setFixEndPosition(int fixEndPosition)
{
this.fixEndPosition = fixEndPosition;
}
public void setFixEndPosition(int fixEndPosition) { @Override
this.fixEndPosition = fixEndPosition; public int compareTo(HierarchicalActionSet o)
} {
@Override return this.startPosition.compareTo(o.startPosition);//this.action.compareTo(o.action);
public int compareTo(HierarchicalActionSet o) { }
return this.startPosition.compareTo(o.startPosition);//this.action.compareTo(o.action); private final List<String> strList = new ArrayList<>();
}
private List<String> strList = new ArrayList<>(); public int getActionSize()
{
return strList.size();
}
public int getActionSize(){ @Override
return strList.size(); public String toString()
} {
String str = actionString;
if (strList.size() == 0)
{
strList.add(str);
for (HierarchicalActionSet actionSet : subActions)
{
actionSet.toString();
List<String> strList1 = actionSet.strList;
for (String str1 : strList1)
{
strList.add("---" + str1);
}
}
}
else
{
strList.clear();
strList.add(str);
for (HierarchicalActionSet actionSet : subActions)
{
actionSet.toString();
List<String> strList1 = actionSet.strList;
for (String str1 : strList1)
{
strList.add("---" + str1);
}
}
}
str = "";
for (String str1 : strList)
{
str += str1 + "\n";
}
return str;
}
@Override
public String toString() {
String str = actionString;
if (strList.size() == 0) {
strList.add(str);
for (HierarchicalActionSet actionSet : subActions) {
actionSet.toString();
List<String> strList1 = actionSet.strList;
for (String str1 : strList1) {
strList.add("---" + str1);
}
}
} else {
strList.clear();
strList.add(str);
for (HierarchicalActionSet actionSet : subActions) {
actionSet.toString();
List<String> strList1 = actionSet.strList;
for (String str1 : strList1) {
strList.add("---" + str1);
}
}
}
str = "";
for (String str1 : strList) {
str += str1 + "\n";
}
return str;
}
} }
@@ -5,7 +5,6 @@ import com.github.gumtreediff.tree.ITree;
import edu.lu.uni.serval.utils.ASTNodeMap; import edu.lu.uni.serval.utils.ASTNodeMap;
import edu.lu.uni.serval.utils.ListSorter; import edu.lu.uni.serval.utils.ListSorter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Predicate; import java.util.function.Predicate;
@@ -13,323 +12,395 @@ import java.util.stream.Collectors;
/** /**
* Regroup GumTree results to a hierarchical construction. * Regroup GumTree results to a hierarchical construction.
*
* @author kui.liu
* *
* @author kui.liu
*/ */
public class HierarchicalRegrouper { public class HierarchicalRegrouper
{
public List<HierarchicalActionSet> regroupGumTreeResults(List<Action> actions) { public List<HierarchicalActionSet> regroupGumTreeResults(List<Action> actions)
/* {
* First, sort actions by their positions. /*
*/ * First, sort actions by their positions.
actions = new ListSorter<Action>(actions).sortAscending(); */
actions = new ListSorter<Action>(actions).sortAscending();
/*
* Second, group actions by their positions.
*/
List<HierarchicalActionSet> actionSets = new ArrayList<>();
HierarchicalActionSet actionSet = null;
if(actions == null){
return actionSets;
}
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<HierarchicalActionSet> 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);
}
}
}
List<HierarchicalActionSet> reActionSets1 = new ArrayList<>();
ITree movDelNode = null;
for(HierarchicalActionSet a:reActionSets){
a = removeBlocks(a);
HierarchicalActionSet hierarchicalActionSet1 = postOrder(a).stream().collect(Collectors.toList()).get(0);
Action action = hierarchicalActionSet1.getAction();
if (hierarchicalActionSet1.getSubActions().size() == 0 && action instanceof Update){
List<ITree> collect = hierarchicalActionSet1.getNode().getChildren().stream().filter(x -> x.getType() == 14).collect(Collectors.toList());
// if(hierarchicalActionSet1.getNode().getChildren().size() == 1){
if(collect.size() == 1){
// if(hierarchicalActionSet1.getNode().getChild(0).getType() == 14){
if(collect.get(0).getType() == 14){
continue;
}
}
}
else{
Predicate<HierarchicalActionSet> predicate = x->x.getAction() instanceof Move;
List<HierarchicalActionSet> collect = postOrder(a).stream().filter(predicate).collect(Collectors.toList());
if(collect.size() == 1){
HierarchicalActionSet hierarchicalActionSet = collect.get(0);
movDelNode = hierarchicalActionSet.getNode().getParent();
reActionSets1.add(a);
continue;
}
}
if( movDelNode != null){
if(a.getNode().equals(movDelNode)){
continue;
}
}
reActionSets1.add(a);
}
/*
* Second, group actions by their positions.
*/
List<HierarchicalActionSet> actionSets = new ArrayList<>();
HierarchicalActionSet actionSet = null;
return reActionSets1; if (actions == null)
// return reActionSets; {
} return actionSets;
}
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<HierarchicalActionSet> 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);
}
}
}
List<HierarchicalActionSet> reActionSets1 = new ArrayList<>();
ITree movDelNode = null;
for (HierarchicalActionSet a : reActionSets)
{
a = removeBlocks(a);
HierarchicalActionSet hierarchicalActionSet1 = postOrder(a).stream().collect(Collectors.toList()).get(0);
Action action = hierarchicalActionSet1.getAction();
if (hierarchicalActionSet1.getSubActions().size() == 0 && action instanceof Update)
{
List<ITree> collect = hierarchicalActionSet1.getNode().getChildren().stream().filter(x -> x.getType() == 14).collect(Collectors.toList());
// if(hierarchicalActionSet1.getNode().getChildren().size() == 1){
if (collect.size() == 1)
{
// if(hierarchicalActionSet1.getNode().getChild(0).getType() == 14){
if (collect.get(0).getType() == 14)
{
continue;
}
}
}
else
{
Predicate<HierarchicalActionSet> predicate = x -> x.getAction() instanceof Move;
List<HierarchicalActionSet> collect = postOrder(a).stream().filter(predicate).collect(Collectors.toList());
if (collect.size() == 1)
{
HierarchicalActionSet hierarchicalActionSet = collect.get(0);
movDelNode = hierarchicalActionSet.getNode().getParent();
reActionSets1.add(a);
continue;
}
}
if (movDelNode != null)
{
if (a.getNode().equals(movDelNode))
{
continue;
}
}
reActionSets1.add(a);
}
private boolean isStatement(HierarchicalActionSet actSet){ return reActionSets1;
String astNodeType = actSet.getAstNodeType(); // return reActionSets;
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")) {
return true;
}
return false;
}
Predicate<HierarchicalActionSet> predicate = x-> isStatement(x);
private HierarchicalActionSet removeBlocks(HierarchicalActionSet actionSet){
List<HierarchicalActionSet> subActions = actionSet.getSubActions();
private boolean isStatement(HierarchicalActionSet actSet)
{
String astNodeType = actSet.getAstNodeType();
return astNodeType.endsWith("TypeDeclaration") || astNodeType.endsWith("FieldDeclaration") || astNodeType.endsWith("EnumDeclaration") ||
astNodeType.endsWith("MethodDeclaration") || astNodeType.endsWith("Statement") ||
astNodeType.endsWith("ConstructorInvocation") || astNodeType.endsWith("CatchClause") || astNodeType.endsWith("SwitchCase");
}
Action action = actionSet.getAction(); Predicate<HierarchicalActionSet> predicate = x -> isStatement(x);
if (subActions.size() == 1){
HierarchicalActionSet subaction = subActions.get(0);
List<HierarchicalActionSet> collect = postOrder(subaction).stream().filter(predicate).collect(Collectors.toList()); private HierarchicalActionSet removeBlocks(HierarchicalActionSet actionSet)
if(collect.size() == 0){ {
return actionSet; List<HierarchicalActionSet> subActions = actionSet.getSubActions();
}
boolean b = collect.stream().anyMatch(p -> p.getAction().getName().equals(subActions.get(0).getAction().getName()));
if(!b){
return actionSet;
}
Action action1 = subaction.getAction();
if(action.getClass().equals(action1.getClass()) && action.getName().equals("UPD")) {
subaction.setParent(null);
return removeBlocks(subaction);
}
}
return actionSet;
}
public List<HierarchicalActionSet> postOrder(HierarchicalActionSet a) {
List<HierarchicalActionSet> trees = new ArrayList<>();
getAllSubActions(a, trees);
return trees;
}
private void getAllSubActions(HierarchicalActionSet a,List<HierarchicalActionSet> as) {
List<HierarchicalActionSet> subActions = a.getSubActions();
if (subActions.size() != 0){
for (HierarchicalActionSet s : subActions) {
getAllSubActions(s, as);
}
}
as.add(a);
// List<HierarchicalActionSet> b = new ArrayList<HierarchicalActionSet>();
// for (HierarchicalActionSet child: this.getSubActions())
// b.add(child);
// return b;
}
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 (ASTNodeMap.map.containsKey(typeInt)) {
String type = ASTNodeMap.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<HierarchicalActionSet> 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<HierarchicalActionSet> sorter = new ListSorter<HierarchicalActionSet>(actionSet.getSubActions());
List<HierarchicalActionSet> subActions = sorter.sortAscending();
if (subActions != null) {
actionSet.setSubActions(subActions);
}
}
private boolean addToAactionSet(Action act, Action parentAct, List<HierarchicalActionSet> 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<HierarchicalActionSet> subActionSets = actionSet.getSubActions();
if (subActionSets.size() > 0) {
boolean added = addToAactionSet(act, parentAct, subActionSets);
if (added) {
return true;
} else {
continue;
}
}
}
}
}
return false;
}
private Action findParentAction(Action action, List<Action> actions) {
ITree parent = action.getNode().getParent();
if (action instanceof Addition) {
parent = ((Addition) action).getParent(); // parent in the fixed source code tree
}
if (parent.getType() == 55) {
int type = action.getNode().getType();
// Modifier, NormalAnnotation, MarkerAnnotation, SingleMemberAnnotation
if (type != 83 && type != 77 && type != 78 && type != 79
&& type != 5 && type != 39 && type != 43 && type != 74 && type != 75
&& type != 76 && type != 84 && type != 87 && type != 88 && type != 42) {
// ArrayType, PrimitiveType, SimpleType, ParameterizedType,
// QualifiedType, WildcardType, UnionType, IntersectionType, NameQualifiedType, SimpleName
return null;
}
} Action action = actionSet.getAction();
if (subActions.size() == 1)
for (Action act : actions) { {
if (act.getNode().equals(parent)) { HierarchicalActionSet subaction = subActions.get(0);
if (areRelatedActions(act, action)) {
return act; List<HierarchicalActionSet> collect = postOrder(subaction).stream().filter(predicate).collect(Collectors.toList());
} if (collect.size() == 0)
} {
} return actionSet;
return null; }
} boolean b = collect.stream().anyMatch(p -> p.getAction().getName().equals(subActions.get(0).getAction().getName()));
if (!b)
private boolean areRelatedActions(Action parent, Action child) { {
// if (parent instanceof Move && !(child instanceof Move)) {// If action is MOV, its children must be MOV. return actionSet;
// return false; }
// } Action action1 = subaction.getAction();
if (parent instanceof Delete && !(child instanceof Delete)) {// If action is INS, its children must be MOV or INS. if (action.getClass().equals(action1.getClass()) && action.getName().equals("UPD"))
return false; {
} subaction.setParent(null);
if (parent instanceof Insert && !(child instanceof Addition)) {// If action is DEL, its children must be DEL. return removeBlocks(subaction);
return false;
} }
return true; }
} return actionSet;
}
public List<HierarchicalActionSet> postOrder(HierarchicalActionSet a)
{
List<HierarchicalActionSet> trees = new ArrayList<>();
getAllSubActions(a, trees);
return trees;
}
private void getAllSubActions(HierarchicalActionSet a, List<HierarchicalActionSet> as)
{
List<HierarchicalActionSet> subActions = a.getSubActions();
if (subActions.size() != 0)
{
for (HierarchicalActionSet s : subActions)
{
getAllSubActions(s, as);
}
}
as.add(a);
// List<HierarchicalActionSet> b = new ArrayList<HierarchicalActionSet>();
// for (HierarchicalActionSet child: this.getSubActions())
// b.add(child);
// return b;
}
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 (ASTNodeMap.map.containsKey(typeInt))
{
String type = ASTNodeMap.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<HierarchicalActionSet> 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<HierarchicalActionSet> sorter = new ListSorter<HierarchicalActionSet>(actionSet.getSubActions());
List<HierarchicalActionSet> subActions = sorter.sortAscending();
if (subActions != null)
{
actionSet.setSubActions(subActions);
}
}
private boolean addToAactionSet(Action act, Action parentAct, List<HierarchicalActionSet> 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<HierarchicalActionSet> subActionSets = actionSet.getSubActions();
if (subActionSets.size() > 0)
{
boolean added = addToAactionSet(act, parentAct, subActionSets);
if (added)
{
return true;
}
else
{
continue;
}
}
}
}
}
return false;
}
private Action findParentAction(Action action, List<Action> actions)
{
ITree parent = action.getNode().getParent();
if (action instanceof Addition)
{
parent = ((Addition) action).getParent(); // parent in the fixed source code tree
}
if (parent.getType() == 55)
{
int type = action.getNode().getType();
// Modifier, NormalAnnotation, MarkerAnnotation, SingleMemberAnnotation
if (type != 83 && type != 77 && type != 78 && type != 79
&& type != 5 && type != 39 && type != 43 && type != 74 && type != 75
&& type != 76 && type != 84 && type != 87 && type != 88 && type != 42)
{
// ArrayType, PrimitiveType, SimpleType, ParameterizedType,
// QualifiedType, WildcardType, UnionType, IntersectionType, NameQualifiedType, SimpleName
return null;
}
}
for (Action act : actions)
{
if (act.getNode().equals(parent))
{
if (areRelatedActions(act, action))
{
return act;
}
}
}
return null;
}
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 INS, its children must be MOV or INS.
return false;
}
// If action is DEL, its children must be DEL.
return !(parent instanceof Insert) || child instanceof Addition;
}
} }
File diff suppressed because it is too large Load Diff
@@ -2,46 +2,62 @@ package edu.lu.uni.serval.richedit.ediff;
import java.io.File; import java.io.File;
public class MessageFile { public class MessageFile
{
private File revFile;
private File prevFile; private final File revFile;
private File diffEntryFile;
private File positionFile; private final File prevFile;
private final File diffEntryFile;
private File positionFile;
private String project;
private String project; public MessageFile(File revFile, File prevFile, File diffEntryFile, String project)
{
public MessageFile(File revFile, File prevFile, File diffEntryFile,String project) { super();
super(); this.revFile = revFile;
this.revFile = revFile; this.prevFile = prevFile;
this.prevFile = prevFile; this.diffEntryFile = diffEntryFile;
this.diffEntryFile = diffEntryFile; this.project = project;
this.project = project; }
}
public String getProject() { return project;} public String getProject()
{
return project;
}
public void setProject(String project) { this.project = project;} public void setProject(String project)
public File getRevFile() { {
return revFile; this.project = project;
} }
public File getPrevFile() {
return prevFile;
}
public File getDiffEntryFile() {
return diffEntryFile;
}
public File getPositionFile() { public File getRevFile()
return positionFile; {
} return revFile;
}
public File getPrevFile()
{
return prevFile;
}
public File getDiffEntryFile()
{
return diffEntryFile;
}
public File getPositionFile()
{
return positionFile;
}
public void setPositionFile(File positionFile)
{
this.positionFile = positionFile;
}
public void setPositionFile(File positionFile) {
this.positionFile = positionFile;
}
} }
@@ -6,55 +6,65 @@ import java.io.File;
/** /**
* Parse fix patterns with GumTree. * Parse fix patterns with GumTree.
*
* @author kui.liu
* *
* @author kui.liu
*/ */
public abstract class Parser implements ParserInterface { public abstract class Parser implements ParserInterface
{
protected String astEditScripts = ""; // it will be used for fix patterns mining.
protected String patchesSourceCode = ""; // testing
protected String buggyTrees = ""; // Compute similarity for bug localization.
protected String sizes = ""; // fix patterns' selection before mining.
protected String tokensOfSourceCode = ""; // Compute similarity for bug localization.
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,boolean isJava); protected String astEditScripts = ""; // it will be used for fix patterns mining.
@Override protected String patchesSourceCode = ""; // testing
public String getAstEditScripts() {
return astEditScripts;
}
@Override protected String buggyTrees = ""; // Compute similarity for bug localization.
public String getPatchesSourceCode() {
return patchesSourceCode;
}
// @Override protected String sizes = ""; // fix patterns' selection before mining.
// public String getBuggyTrees() {
// return buggyTrees;
// }
@Override protected String tokensOfSourceCode = ""; // Compute similarity for bug localization.
public String getSizes() {
return sizes;
}
@Override protected String originalTree = ""; // Guide of generating patches.
public String getTokensOfSourceCode() {
return tokensOfSourceCode;
}
// @Override protected String actionSets = ""; // Guide of generating patches.
// public String getOriginalTree() {
// return originalTree; public abstract void parseFixPatterns(File prevFile, File revFile, File diffEntryFile, String project, JedisPool innerPool, String srcMLPath, String rootType, boolean isJava);
// }
//
// @Override @Override
// public String getActionSets() { public String getAstEditScripts()
// return actionSets; {
// } return astEditScripts;
}
@Override
public String getPatchesSourceCode()
{
return patchesSourceCode;
}
// @Override
// public String getBuggyTrees() {
// return buggyTrees;
// }
@Override
public String getSizes()
{
return sizes;
}
@Override
public String getTokensOfSourceCode()
{
return tokensOfSourceCode;
}
// @Override
// public String getOriginalTree() {
// return originalTree;
// }
//
// @Override
// public String getActionSets() {
// return actionSets;
// }
} }
@@ -1,21 +1,22 @@
package edu.lu.uni.serval.richedit.ediff; package edu.lu.uni.serval.richedit.ediff;
public interface ParserInterface { public interface ParserInterface
{
// public void parseFixPatterns(File prevFile, File revFile, File diffEntryFile);
public String getAstEditScripts();
public String getPatchesSourceCode(); // public void parseFixPatterns(File prevFile, File revFile, File diffEntryFile);
// public String getBuggyTrees(); String getAstEditScripts();
public String getSizes(); String getPatchesSourceCode();
public String getTokensOfSourceCode(); // public String getBuggyTrees();
// public String getOriginalTree(); String getSizes();
// public String getActionSets(); String getTokensOfSourceCode();
// public String getOriginalTree();
// public String getActionSets();
} }
@@ -4,48 +4,61 @@ import redis.clients.jedis.JedisPool;
import java.io.File; import java.io.File;
public class RunnableParser implements Runnable { public class RunnableParser implements Runnable
{
private File prevFile; private final File prevFile;
private File revFile;
private File diffEntryFile;
private Parser parser;
private String project;
private JedisPool pool;
private String srcMLPath;
private String rootType;
boolean isJava;
public RunnableParser(File prevFile, File revFile, File diffEntryFile, Parser parser) { private final File revFile;
this.prevFile = prevFile;
this.revFile = revFile;
this.diffEntryFile = diffEntryFile;
this.parser = parser;
}
public RunnableParser(File prevFile, File revFile, File diffEntryFile, Parser parser, String project, JedisPool innerPool) { private final File diffEntryFile;
this.prevFile = prevFile;
this.revFile = revFile;
this.diffEntryFile = diffEntryFile;
this.parser = parser;
this.project = project;
this.pool = innerPool;
}
public RunnableParser(File prevFile, File revFile, File diffEntryFile, Parser parser, String project, JedisPool innerPool,String srcMLPath,String rootType,boolean isJava) { private final Parser parser;
this.prevFile = prevFile;
this.revFile = revFile;
this.diffEntryFile = diffEntryFile;
this.parser = parser;
this.project = project;
this.pool = innerPool;
this.srcMLPath = srcMLPath;
this.rootType = rootType;
this.isJava = isJava;
}
@Override private String project;
public void run() {
parser.parseFixPatterns(prevFile, revFile, diffEntryFile,project,pool,srcMLPath,rootType,isJava); private JedisPool pool;
}
private String srcMLPath;
private String rootType;
boolean isJava;
public RunnableParser(File prevFile, File revFile, File diffEntryFile, Parser parser)
{
this.prevFile = prevFile;
this.revFile = revFile;
this.diffEntryFile = diffEntryFile;
this.parser = parser;
}
public RunnableParser(File prevFile, File revFile, File diffEntryFile, Parser parser, String project, JedisPool innerPool)
{
this.prevFile = prevFile;
this.revFile = revFile;
this.diffEntryFile = diffEntryFile;
this.parser = parser;
this.project = project;
this.pool = innerPool;
}
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;
this.parser = parser;
this.project = project;
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, isJava);
}
} }
@@ -13,174 +13,83 @@ import redis.clients.jedis.JedisPool;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
/** /**
* Created by anilkoyuncu on 03/04/2018. * Created by anilkoyuncu on 03/04/2018.
*/ */
public class CompareTrees { public class CompareTrees
{
private static final Logger log = LoggerFactory.getLogger(CompareTrees.class);
private static Logger log = LoggerFactory.getLogger(CompareTrees.class); public static void main(String redisPath, String portDumps, String dumpsName, String numOfWorkers) throws Exception
{
public static void main(String redisPath, String portDumps, String dumpsName, String numOfWorkers) throws Exception {
// shape /Users/anil.koyuncu/projects/test/richedit-core/python/data/redis ALLdumps-gumInput.rdb clusterl0-gumInputALL.rdb /Users/anil.koyuncu/projects/test/richedit-core/python/data/richEditScript
// String portInner = "6380";
String port = portDumps; //"6399"; String port = portDumps; //"6399";
CallShell cs = new CallShell(); CallShell cs = new CallShell();
String cmd = "bash "+redisPath + "/" + "startServer.sh" +" %s %s %s"; String cmd = "bash " + redisPath + "/" + "startServer.sh" + " %s %s %s";
cmd = String.format(cmd, redisPath,dumpsName,Integer.valueOf(port)); cmd = String.format(cmd, redisPath, dumpsName, Integer.valueOf(port));
log.info(cmd); log.info(cmd);
cs.runShell(cmd, port); CallShell.runShell(cmd, port);
// String cmdInner = "bash "+redisPath + "/" + "startServer.sh" +" %s %s %s"; final JedisPool outerPool = new JedisPool(PoolBuilder.getPoolConfig(), "localhost", Integer.valueOf(port), 20000000);
// cmdInner = String.format(cmdInner, redisPath,compareDBName,Integer.valueOf(portInner));
// log.info(cmdInner);
// cs.runShell(cmdInner, portInner);
// String numOfWorkers = "100000000";//args[4];
// String host = "localhost";//args[5];
// -Djava.util.concurrent.ForkJoinPool.common.parallelism=256
// final JedisPool innerPool = new JedisPool(PoolBuilder.getPoolConfig(), host,Integer.valueOf(portInner),20000000);
final JedisPool outerPool = new JedisPool(PoolBuilder.getPoolConfig(), "localhost",Integer.valueOf(port),20000000);
// List<String> listOfPairs = AkkaTreeParser.getMessages(innerPool,Integer.valueOf(numOfWorkers));
HashMap<String, String> filenames = getFilenames(outerPool); HashMap<String, String> filenames = getFilenames(outerPool);
String job= getLevel(outerPool); String job = getLevel(outerPool);
// List<String> listOfPairs = AkkaTreeParser.files2compare(outerPool);
// ArrayList<String> samePairs = new ArrayList<>();
ArrayList<String> errorPairs = new ArrayList<>(); ArrayList<String> errorPairs = new ArrayList<>();
// Integer numberOfWorkers = Integer.valueOf(numOfWorkers);
// final ExecutorService executor = Executors.newWorkStealingPool(numberOfWorkers);
Long compare; Long compare;
try (Jedis inner = outerPool.getResource()) { try (Jedis inner = outerPool.getResource())
{
compare = inner.scard("compare"); compare = inner.scard("compare");
} }
IntStream stream = IntStream.range(0, compare.intValue()); IntStream stream = IntStream.range(0, compare.intValue());
String finalJob = job; String finalJob = job;
ProgressBar.wrap(stream. ProgressBar.wrap(stream.parallel(), "Task").forEach(m ->
parallel(),"Task"). {
newCoreCompare(finalJob, errorPairs, filenames, outerPool);
forEach(m -> }
{ );
newCoreCompare(finalJob, errorPairs, filenames, outerPool);
}
);
//
// ArrayList<Future<?>> results = new ArrayList<Future<?>>();
// for (int i = 0; i <numberOfWorkers ; i++) {
//
//
// // schedule the work
// log.info("Starting job {}",i);
// final Future<?> future = executor.submit(new RunnableCompare(job, errorPairs, filenames, outerPool, i));
// results.add(future);
// }
// for (Future<?> future : ProgressBar.wrap(results, "Comparing")){
//// for (Future<?> future:results){
// try {
// // wait for task to complete
// future.get();
//
// } catch (InterruptedException e) {
//
// e.printStackTrace();
// } catch (ExecutionException e) {
//
// e.printStackTrace();
// }
//// finally {
//// executor.shutdownNow();
//// }
// }
// executor.shutdownNow();
log.info("End process"); log.info("End process");
} }
public static boolean newCoreCompare(String treeType, ArrayList<String> errorPairs, HashMap<String, String> filenames, JedisPool outerPool)
// public static class RunnableCompare implements Runnable { {
// String job;
// ArrayList<String> errorPairs;
// HashMap<String, String> filenames;
// JedisPool outerPool;
// Integer threadID;
//
// public RunnableCompare(String treeType,ArrayList<String> errorPairs, HashMap<String, String> filenames,JedisPool outerPool,Integer threadID) {
// this.job = treeType;
// this.errorPairs = errorPairs;
// this.filenames = filenames;
// this.outerPool = outerPool;
// this.threadID = threadID;
// }
//
// @Override
// public void run() {
//// int dbsize = 1;
// boolean stop = true;
// while(stop) {
//// try (Jedis outer = outerPool.getResource()) {
//// dbsize = Math.toIntExact(outer.scard("compare"));
//// }
//// if (dbsize != 0){
// stop = newCoreCompare(job, errorPairs, filenames, outerPool);
//// }
// }
// log.info("Completed worker {}",threadID);
// }
// }
public static boolean newCoreCompare( String treeType,ArrayList<String> errorPairs, HashMap<String, String> filenames,JedisPool outerPool ) {
String pairName = null; String pairName = null;
try (Jedis outer = outerPool.getResource()) { try (Jedis outer = outerPool.getResource())
{
pairName = outer.spop("compare"); pairName = outer.spop("compare");
// } // }
if(pairName.equals("0")) if (pairName.equals("0"))
return true; {
String matchKey = null; return true;
// try { }
String matchKey = null;
String[] split = pairName.split("/"); String[] split = pairName.split("/");
String i = split[1]; String i = split[1];
String j = split[2]; String j = split[2];
String keyName = split[0]; String keyName = split[0];
matchKey = keyName + "/" + (String.valueOf(i)) + "/" + String.valueOf(j); matchKey = keyName + "/" + (i) + "/" + j;
if (matchKey == null){ if (matchKey == null)
{
return false; return false;
} }
Map<String, String> oldTreeString = EDiffHelper.getTreeString(keyName, i, outerPool, filenames); Map<String, String> oldTreeString = EDiffHelper.getTreeString(keyName, i, outerPool, filenames);
Map<String, String> newTreeString = EDiffHelper.getTreeString(keyName, j, outerPool, filenames); Map<String, String> newTreeString = EDiffHelper.getTreeString(keyName, j, outerPool, filenames);
switch (treeType) { switch (treeType)
{
case "single": case "single":
String oldShapeTree = oldTreeString.get("shapeTree");
String oldShapeTree =oldTreeString.get("shapeTree"); String newShapeTree = newTreeString.get("shapeTree");
String newShapeTree =newTreeString.get("shapeTree");
String oldActionTree = oldTreeString.get("actionTree"); String oldActionTree = oldTreeString.get("actionTree");
String newActionTree = newTreeString.get("actionTree"); String newActionTree = newTreeString.get("actionTree");
@@ -189,12 +98,14 @@ public class CompareTrees {
String newTargetTree = newTreeString.get("targetTree"); String newTargetTree = newTreeString.get("targetTree");
if (oldShapeTree.equals(newShapeTree)) { if (oldShapeTree.equals(newShapeTree))
if (oldActionTree.equals(newActionTree)) { {
if (oldTargetTree.equals(newTargetTree)) { if (oldActionTree.equals(newActionTree))
// samePairs.add(matchKey); {
try (Jedis jedis = outerPool.getResource()) { if (oldTargetTree.equals(newTargetTree))
//// jedis.del(matchKey); {
try (Jedis jedis = outerPool.getResource())
{
jedis.select(2); jedis.select(2);
jedis.set(matchKey, "1"); jedis.set(matchKey, "1");
} }
@@ -206,61 +117,54 @@ public class CompareTrees {
String oldTokens = oldTreeString.get("tokens"); String oldTokens = oldTreeString.get("tokens");
String newTokens = newTreeString.get("tokens"); String newTokens = newTreeString.get("tokens");
// EDiffHelper.getTokens(keyName, i, outerPool, filenames);
// newTree = EDiffHelper.getTokens(keyName, j, outerPool, innerPool);
// String oldTokens = EDiffHelper.getNames2(oldTree);
// String newTokens = EDiffHelper.getNames2(newTree);
//
JaroWinklerDistance jwd = new JaroWinklerDistance(); JaroWinklerDistance jwd = new JaroWinklerDistance();
//
//
Double overallSimi = Double.valueOf(0); Double overallSimi = Double.valueOf(0);
// if (!(oldTokens.trim().isEmpty() || newTokens.trim().isEmpty()))
if (!(oldTokens.trim().isEmpty() || newTokens.trim().isEmpty())) { {
overallSimi = jwd.apply(oldTokens, newTokens); overallSimi = jwd.apply(oldTokens, newTokens);
} }
int retval = Double.compare(overallSimi, Double.valueOf(1)); int retval = Double.compare(overallSimi, Double.valueOf(1));
if (retval >= 0) { if (retval >= 0)
try (Jedis jedis = outerPool.getResource()) { {
try (Jedis jedis = outerPool.getResource())
{
jedis.select(3); jedis.select(3);
jedis.set(matchKey, "1"); jedis.set(matchKey, "1");
} }
} }
return true; return true;
default: default:
return true; return true;
// break;
} }
}catch (Exception e) { }
catch (Exception e)
{
errorPairs.add(pairName); errorPairs.add(pairName);
if (pairName == null) if (pairName == null) return false;
return false;
log.debug("{} not comparable", pairName); log.debug("{} not comparable", pairName);
} }
return true; return true;
} }
public static String getLevel(JedisPool innerPool)
{
HashMap<String, String> fileMap = new HashMap<String, String>();
public static String getLevel(JedisPool innerPool){ try (Jedis inner = innerPool.getResource())
{
while (!inner.ping().equals("PONG"))
HashMap<String, String> fileMap =new HashMap<String, String>(); {
try (Jedis inner = innerPool.getResource()) {
while (!inner.ping().equals("PONG")){
log.info("wait"); log.info("wait");
} }
inner.select(1); inner.select(1);
String level = inner.get("level"); String level = inner.get("level");
switch (level){ switch (level)
{
case "l1": case "l1":
return "single"; return "single";
case "l2": case "l2":
@@ -268,47 +172,29 @@ public class CompareTrees {
default: default:
return ""; return "";
} }
} }
} }
public static HashMap<String, String> getFilenames(JedisPool innerPool){ public static HashMap<String, String> getFilenames(JedisPool innerPool)
{
HashMap<String, String> fileMap = new HashMap<String, String>();
try (Jedis inner = innerPool.getResource())
HashMap<String, String> fileMap =new HashMap<String, String>(); {
while (!inner.ping().equals("PONG"))
try (Jedis inner = innerPool.getResource()) { {
while (!inner.ping().equals("PONG")){
log.info("wait"); log.info("wait");
} }
inner.select(1); inner.select(1);
Map<String, String> filenames = inner.hgetAll("filenames"); Map<String, String> filenames = inner.hgetAll("filenames");
for (Map.Entry<String, String> stringStringEntry : filenames.entrySet().stream().collect(Collectors.toList()))
for (Map.Entry<String, String> stringStringEntry : filenames.entrySet().stream().collect(Collectors.toList())) { {
fileMap.put(stringStringEntry.getKey(),stringStringEntry.getValue()); fileMap.put(stringStringEntry.getKey(), stringStringEntry.getValue());
} }
} }
// log.info("Getting results %d",fileMap.s); return fileMap;
return fileMap;
} }
} }
@@ -1,9 +1,9 @@
package edu.lu.uni.serval.richedit.jobs; package edu.lu.uni.serval.richedit.jobs;
import edu.lu.uni.serval.richedit.ediff.EDiffHunkParser; import edu.lu.uni.serval.richedit.ediff.EDiffHunkParser;
import edu.lu.uni.serval.utils.FileHelper;
import edu.lu.uni.serval.richedit.ediff.MessageFile; import edu.lu.uni.serval.richedit.ediff.MessageFile;
import edu.lu.uni.serval.utils.CallShell; import edu.lu.uni.serval.utils.CallShell;
import edu.lu.uni.serval.utils.FileHelper;
import edu.lu.uni.serval.utils.PoolBuilder; import edu.lu.uni.serval.utils.PoolBuilder;
import me.tongfei.progressbar.ProgressBar; import me.tongfei.progressbar.ProgressBar;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -25,7 +25,7 @@ import java.util.stream.Stream;
public class EnhancedASTDiff public class EnhancedASTDiff
{ {
private static Logger log = LoggerFactory.getLogger(EnhancedASTDiff.class); private static final Logger log = LoggerFactory.getLogger(EnhancedASTDiff.class);
public static void main(String inputPath, String redisPort, String dbDir, String chunkName, String srcMLPath, String hunkLimit, public static void main(String inputPath, String redisPort, String dbDir, String chunkName, String srcMLPath, String hunkLimit,
String[] projectList, String patchSize, String projectType, String srcPath) throws Exception String[] projectList, String patchSize, String projectType, String srcPath) throws Exception
@@ -35,19 +35,12 @@ public class EnhancedASTDiff
CallShell cs = new CallShell(); CallShell cs = new CallShell();
String cmd = String.format("redis-server %s/redis.conf --dir %s --dbfilename redis.rdb --port %s --daemonize yes", srcPath, dbDir, redisPort); String cmd = String.format("redis-server %s/redis.conf --dir %s --dbfilename redis.rdb --port %s --daemonize yes", srcPath, dbDir, redisPort);
// String cmd = "bash " + dbDir + "/" + "startServer.sh" + " %s %s %s";
// cmd = String.format(cmd, dbDir, chunkName, Integer.valueOf(redisPort)); CallShell.runShell(cmd, redisPort);
cs.runShell(cmd, redisPort);
JedisPool innerPool = new JedisPool(PoolBuilder.getPoolConfig(), "127.0.0.1", Integer.valueOf(redisPort), 20000000); JedisPool innerPool = new JedisPool(PoolBuilder.getPoolConfig(), "127.0.0.1", Integer.valueOf(redisPort), 20000000);
boolean isJava = false; boolean isJava = projectType.equals("java");
if (projectType.equals("java"))
{
isJava = true;
}
File folder = new File(inputPath); File folder = new File(inputPath);
File[] listOfFiles = folder.listFiles(); File[] listOfFiles = folder.listFiles();
if (listOfFiles == null) if (listOfFiles == null)
@@ -80,22 +73,17 @@ public class EnhancedASTDiff
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
String project = folder.getName(); String project = folder.getName();
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, isJava); //"/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); if (msgFiles == null)
if (msgFiles == null) {
{ continue;
continue; }
}
allMessageFiles.addAll(msgFiles); allMessageFiles.addAll(msgFiles);
} }
Map<String, String> diffEntry; Map<String, String> diffEntry;
@@ -112,24 +100,12 @@ public class EnhancedASTDiff
log.info("{} files to process ...", allMessageFiles.size()); log.info("{} files to process ...", allMessageFiles.size());
} }
boolean finalIsJava = isJava; boolean finalIsJava = isJava;
ProgressBar.wrap(allMessageFiles.stream(). ProgressBar.wrap(allMessageFiles.stream().parallel(), "Task").forEach(m ->
parallel(), "Task").
forEach(m ->
{ {
EDiffHunkParser parser = new EDiffHunkParser(); EDiffHunkParser parser = new EDiffHunkParser();
parser.parseFixPatterns(m.getPrevFile(), m.getRevFile(), m.getDiffEntryFile(), project, innerPool, srcMLPath, hunkLimit, finalIsJava); parser.parseFixPatterns(m.getPrevFile(), m.getRevFile(), m.getDiffEntryFile(), project, innerPool, srcMLPath, hunkLimit, finalIsJava);
} }
); );
// allMessageFiles.stream().
// parallel().
// forEach(m ->
// {
// EDiffHunkParser parser = new EDiffHunkParser();
// parser.parseFixPatterns(m.getPrevFile(), m.getRevFile(), m.getDiffEntryFile(), project, innerPool, srcMLPath, hunkLimit, finalIsJava);
// }
// );
} }
@@ -141,19 +117,11 @@ public class EnhancedASTDiff
File[] revFiles = revFilesPath.listFiles(); File[] revFiles = revFilesPath.listFiles();
if (revFiles != null) if (revFiles != null)
{ {
// List<File> 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<MessageFile> msgFiles = new ArrayList<>(); List<MessageFile> msgFiles = new ArrayList<>();
for (File revFile : revFiles) for (File revFile : revFiles)
{ {
// 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
// if (isJava){
// fileName = fileName.replace(".java",".txt");
// }else{
// fileName = fileName + ".txt";
// }
fileName = fileName + ".txt"; 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);
@@ -161,19 +129,11 @@ public class EnhancedASTDiff
Pattern pattern = Pattern.compile("^[\\+|\\-]\\s*", Pattern.MULTILINE); Pattern pattern = Pattern.compile("^[\\+|\\-]\\s*", Pattern.MULTILINE);
Matcher matcher = pattern.matcher(s); Matcher matcher = pattern.matcher(s);
int count = 0; int count = 0;
while (matcher.find()) while (matcher.find())
{ {
count++; count++;
} }
if (count >= Integer.valueOf(patchSize)) if (count >= Integer.valueOf(patchSize)) continue;
// if(count>201)
{
continue;
}
// if(FileHelper.readFile(diffentryFile).split("@@\\s\\-\\d+,*\\d*\\s\\+\\d+,*\\d*\\s@@").length > 2)
// continue;
// String datasetName = project;
String[] split1 = diffentryFile.getParent().split(datasetName); String[] split1 = diffentryFile.getParent().split(datasetName);
String root = split1[0]; String root = split1[0];
String pj = split1[1].split("/")[1]; String pj = split1[1].split("/")[1];
@@ -181,16 +141,10 @@ public class EnhancedASTDiff
MessageFile msgFile = new MessageFile(revFile, prevFile, diffentryFile, pj); MessageFile msgFile = new MessageFile(revFile, prevFile, diffentryFile, pj);
msgFiles.add(msgFile); msgFiles.add(msgFile);
} }
return msgFiles; return msgFiles;
} }
else else return null;
{
return null;
}
} }
} }
@@ -3,114 +3,114 @@ package edu.lu.uni.serval.utils;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class ASTNodeMap { public class ASTNodeMap
{
public static Map<Integer, String> map; public static Map<Integer, String> map;
static {
map = new HashMap<Integer, String>();
map.put(-3, "Instanceof");
map.put(-2, "New");
map.put(-1, "Operator");
map.put(0, "ASTNode");
map.put(1, "AnonymousClassDeclaration");
map.put(2, "ArrayAccess");
map.put(3, "ArrayCreation");
map.put(4, "ArrayInitializer");
map.put(5, "ArrayType");
map.put(6, "AssertStatement");
map.put(7, "Assignment");
map.put(8, "Block");
map.put(9, "BooleanLiteral");
map.put(10, "BreakStatement");
map.put(11, "CastExpression");
map.put(12, "CatchClause");
map.put(13, "CharacterLiteral");
map.put(14, "ClassInstanceCreation");
map.put(15, "CompilationUnit");
map.put(16, "ConditionalExpression");
map.put(17, "ConstructorInvocation");
map.put(18, "ContinueStatement");
map.put(19, "DoStatement");
map.put(20, "EmptyStatement");
map.put(21, "ExpressionStatement");
map.put(22, "FieldAccess");
map.put(23, "FieldDeclaration");
map.put(24, "ForStatement");
map.put(25, "IfStatement");
map.put(26, "ImportDeclaration");
map.put(27, "InfixExpression");
map.put(28, "Initializer");
map.put(29, "Javadoc");
map.put(30, "LabeledStatement");
map.put(31, "MethodDeclaration");
map.put(32, "MethodInvocation");
map.put(33, "NullLiteral");
map.put(34, "NumberLiteral");
map.put(35, "PackageDeclaration");
map.put(36, "ParenthesizedExpression");
map.put(37, "PostfixExpression");
map.put(38, "PrefixExpression");
map.put(39, "PrimitiveType");
map.put(40, "QualifiedName");
map.put(41, "ReturnStatement");
map.put(42, "SimpleName");
map.put(43, "SimpleType");
map.put(44, "SingleVariableDeclaration");
map.put(45, "StringLiteral");
map.put(46, "SuperConstructorInvocation");
map.put(47, "SuperFieldAccess");
map.put(48, "SuperMethodInvocation");
map.put(49, "SwitchCase");
map.put(50, "SwitchStatement");
map.put(51, "SynchronizedStatement");
map.put(52, "ThisExpression");
map.put(53, "ThrowStatement");
map.put(54, "TryStatement");
map.put(55, "TypeDeclaration");
map.put(56, "TypeDeclarationStatement");
map.put(57, "TypeLiteral");
map.put(58, "VariableDeclarationExpression");
map.put(59, "VariableDeclarationFragment");
map.put(60, "VariableDeclarationStatement");
map.put(61, "WhileStatement");
map.put(62, "InstanceofExpression");
map.put(63, "LineComment");
map.put(64, "BlockComment");
map.put(65, "TagElement");
map.put(66, "TextElement");
map.put(67, "MemberRef");
map.put(68, "MethodRef");
map.put(69, "MethodRefParameter");
map.put(70, "EnhancedForStatement");
map.put(71, "EnumDeclaration");
map.put(72, "EnumConstantDeclaration");
map.put(73, "TypeParameter");
map.put(74, "ParameterizedType");
map.put(75, "QualifiedType");
map.put(76, "WildcardType");
map.put(77, "NormalAnnotation");
map.put(78, "MarkerAnnotation");
map.put(79, "SingleMemberAnnotation");
map.put(80, "MemberValuePair");
map.put(81, "AnnotationTypeDeclaration");
map.put(82, "AnnotationTypeMemberDeclaration");
map.put(83, "Modifier");
map.put(84, "UnionType");
map.put(85, "Dimension");
map.put(86, "LambdaExpression");
map.put(87, "IntersectionType");
map.put(88, "NameQualifiedType");
map.put(89, "CreationReference");
map.put(90, "ExpressionMethodReference");
map.put(91, "SuperMethodReference");
map.put(92, "TypeMethodReference");
static
{
map = new HashMap<>();
map.put(-3, "Instanceof");
map.put(-2, "New");
map.put(-1, "Operator");
map.put(0, "ASTNode");
map.put(1, "AnonymousClassDeclaration");
map.put(2, "ArrayAccess");
map.put(3, "ArrayCreation");
map.put(4, "ArrayInitializer");
map.put(5, "ArrayType");
map.put(6, "AssertStatement");
map.put(7, "Assignment");
map.put(8, "Block");
map.put(9, "BooleanLiteral");
map.put(10, "BreakStatement");
map.put(11, "CastExpression");
map.put(12, "CatchClause");
map.put(13, "CharacterLiteral");
map.put(14, "ClassInstanceCreation");
map.put(15, "CompilationUnit");
map.put(16, "ConditionalExpression");
map.put(17, "ConstructorInvocation");
map.put(18, "ContinueStatement");
map.put(19, "DoStatement");
map.put(20, "EmptyStatement");
map.put(21, "ExpressionStatement");
map.put(22, "FieldAccess");
map.put(23, "FieldDeclaration");
map.put(24, "ForStatement");
map.put(25, "IfStatement");
map.put(26, "ImportDeclaration");
map.put(27, "InfixExpression");
map.put(28, "Initializer");
map.put(29, "Javadoc");
map.put(30, "LabeledStatement");
map.put(31, "MethodDeclaration");
map.put(32, "MethodInvocation");
map.put(33, "NullLiteral");
map.put(34, "NumberLiteral");
map.put(35, "PackageDeclaration");
map.put(36, "ParenthesizedExpression");
map.put(37, "PostfixExpression");
map.put(38, "PrefixExpression");
map.put(39, "PrimitiveType");
map.put(40, "QualifiedName");
map.put(41, "ReturnStatement");
map.put(42, "SimpleName");
map.put(43, "SimpleType");
map.put(44, "SingleVariableDeclaration");
map.put(45, "StringLiteral");
map.put(46, "SuperConstructorInvocation");
map.put(47, "SuperFieldAccess");
map.put(48, "SuperMethodInvocation");
map.put(49, "SwitchCase");
map.put(50, "SwitchStatement");
map.put(51, "SynchronizedStatement");
map.put(52, "ThisExpression");
map.put(53, "ThrowStatement");
map.put(54, "TryStatement");
map.put(55, "TypeDeclaration");
map.put(56, "TypeDeclarationStatement");
map.put(57, "TypeLiteral");
map.put(58, "VariableDeclarationExpression");
map.put(59, "VariableDeclarationFragment");
map.put(60, "VariableDeclarationStatement");
map.put(61, "WhileStatement");
map.put(62, "InstanceofExpression");
map.put(63, "LineComment");
map.put(64, "BlockComment");
map.put(65, "TagElement");
map.put(66, "TextElement");
map.put(67, "MemberRef");
map.put(68, "MethodRef");
map.put(69, "MethodRefParameter");
map.put(70, "EnhancedForStatement");
map.put(71, "EnumDeclaration");
map.put(72, "EnumConstantDeclaration");
map.put(73, "TypeParameter");
map.put(74, "ParameterizedType");
map.put(75, "QualifiedType");
map.put(76, "WildcardType");
map.put(77, "NormalAnnotation");
map.put(78, "MarkerAnnotation");
map.put(79, "SingleMemberAnnotation");
map.put(80, "MemberValuePair");
map.put(81, "AnnotationTypeDeclaration");
map.put(82, "AnnotationTypeMemberDeclaration");
map.put(83, "Modifier");
map.put(84, "UnionType");
map.put(85, "Dimension");
map.put(86, "LambdaExpression");
map.put(87, "IntersectionType");
map.put(88, "NameQualifiedType");
map.put(89, "CreationReference");
map.put(90, "ExpressionMethodReference");
map.put(91, "SuperMethodReference");
map.put(92, "TypeMethodReference");
map.put(100,"Insert"); map.put(100, "Insert");
map.put(101,"Update"); map.put(101, "Update");
map.put(102,"Delete"); map.put(102, "Delete");
map.put(103,"Move"); map.put(103, "Move");
map.put(104,"NoChange"); map.put(104, "NoChange");
} }
} }
@@ -1,9 +1,5 @@
package edu.lu.uni.serval.utils; package edu.lu.uni.serval.utils;
/**
* Created by anilkoyuncu on 17/04/2018.
*/
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -12,109 +8,83 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class CallShell { /**
* Created by anilkoyuncu on 17/04/2018.
private static Logger log = LoggerFactory.getLogger(CallShell.class); */
public class CallShell
{
private static final Logger log = LoggerFactory.getLogger(CallShell.class);
public void runShell(String command) throws Exception {
public void runShell(String command) throws Exception
{
Process process = Runtime.getRuntime().exec(command); Process process = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader( BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
process.getInputStream()));
String s; String s;
while ((s = reader.readLine()) != null) { while ((s = reader.readLine()) != null)
{
System.out.println("Script output: " + s); System.out.println("Script output: " + s);
} }
} }
public static void runShell(String command, String port) throws Exception { public static void runShell(String command, String port) throws Exception
{
log.trace(command); log.trace(command);
Process process = Runtime.getRuntime().exec(command); Process process = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader( BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
process.getInputStream()));
String s; String s;
while ((s = reader.readLine()) != null) { while ((s = reader.readLine()) != null)
// System.out.println("Script output: " + s); {
log.trace("Script output: " + s); log.trace("Script output: " + s);
} }
// Thread.sleep(Integer.valueOf(serverWait));
String cmd = "redis-cli -p %s ping"; String cmd = "redis-cli -p %s ping";
String cmd1 = String.format(cmd,Integer.valueOf(port)); String cmd1 = String.format(cmd, Integer.valueOf(port));
runPing(cmd1); runPing(cmd1);
} }
public static void runPing(String command) throws Exception { public static void runPing(String command) throws Exception
try{ {
StringBuffer output = new StringBuffer(); try
Process process = Runtime.getRuntime().exec(command); {
BufferedReader reader = new BufferedReader(new InputStreamReader( StringBuffer output = new StringBuffer();
process.getInputStream())); Process process = Runtime.getRuntime().exec(command);
String s; BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String s;
BufferedReader stdError = new BufferedReader(new BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
InputStreamReader(process.getErrorStream()));
// read the output from the command
// System.out.println("Here is the standard output of the command:\n");
// while ((s = reader.readLine()) != null && !s.equals("PONG")) {
// System.out.println(s);
// }
// while(true){
s = reader.readLine(); s = reader.readLine();
if(s !=null && s.equals("PONG")){ if (s != null && s.equals("PONG"))
// System.out.println(s); {
log.trace(s); log.trace(s);
}
}else{ else
{
String e; String e;
if((e = stdError.readLine()) == null) { if ((e = stdError.readLine()) == null)
{
TimeUnit.MINUTES.sleep(1); TimeUnit.MINUTES.sleep(1);
runPing(command); runPing(command);
}else{ }
else
{
TimeUnit.MINUTES.sleep(1); TimeUnit.MINUTES.sleep(1);
System.out.println(e); System.out.println(e);
} }
} }
// System.out.println(s); while ((s = stdError.readLine()) != null)
// } System.out.print(s);
// read any errors from the attempted command }
// System.out.println("Here is the standard error of the command (if any):\n"); catch (IOException e)
while ((s = stdError.readLine()) != null) { {
System.out.print(s); System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
} }
// System.exit(0);
} }
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}
}
public static void main(String[] args) throws Exception {
// runPing("redis-cli -p 6380 ping");
runShell("bash /Users/anilkoyuncu/bugStudy/release/code/redis/startServer.sh /Users/anilkoyuncu/bugStudy/release/code/redis Defects4JALL0.txt.rdb 6380","6380");
}
} }
@@ -6,44 +6,45 @@ import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPool;
public class ClusterToPattern { public class ClusterToPattern
private static Logger log = LoggerFactory.getLogger(ClusterToPattern.class); {
private static final Logger log = LoggerFactory.getLogger(ClusterToPattern.class);
public static void main(String port,String redisPath, String dumpsName, String parameter) throws Exception { public static void main(String port, String redisPath, String dumpsName, String parameter) throws Exception
{
CallShell cs = new CallShell(); CallShell cs = new CallShell();
String cmd = "bash "+redisPath + "/" + "startServer.sh" +" %s %s %s"; String cmd = "bash " + redisPath + "/" + "startServer.sh" + " %s %s %s";
cmd = String.format(cmd, redisPath,dumpsName,Integer.valueOf(port)); cmd = String.format(cmd, redisPath, dumpsName, Integer.valueOf(port));
log.trace(cmd); log.trace(cmd);
cs.runShell(cmd, port); CallShell.runShell(cmd, port);
String host = "localhost";//args[5]; String host = "localhost";//args[5];
final JedisPool outerPool = new JedisPool(PoolBuilder.getPoolConfig(), host,Integer.valueOf(port),20000000); final JedisPool outerPool = new JedisPool(PoolBuilder.getPoolConfig(), host, Integer.valueOf(port), 20000000);
String export = export(parameter, outerPool); String export = export(parameter, outerPool);
System.out.println(export); System.out.println(export);
} }
private static String export(String filename,JedisPool outerPool){ private static String export(String filename, JedisPool outerPool)
{
try (Jedis outer = outerPool.getResource()) { try (Jedis outer = outerPool.getResource())
while (!outer.ping().equals("PONG")) { {
while (!outer.ping().equals("PONG"))
{
log.info("wait"); log.info("wait");
} }
// byte[] s = outer.hget("dump".getBytes(), filename.getBytes()); // byte[] s = outer.hget("dump".getBytes(), filename.getBytes());
// HierarchicalActionSet actionSet = (HierarchicalActionSet) EDiffHelper.kryoDeseerialize(s); // HierarchicalActionSet actionSet = (HierarchicalActionSet) EDiffHelper.kryoDeseerialize(s);
// if (actionSet == null){ // if (actionSet == null){
// throw new Error(filename +" not found"); // throw new Error(filename +" not found");
// } // }
String s1 = outer.hget("dump",filename); String s1 = outer.hget("dump", filename);
// outer.close(); // outer.close();
return s1; return s1;
} }
} }
File diff suppressed because it is too large Load Diff
@@ -1,104 +1,138 @@
package edu.lu.uni.serval.utils; package edu.lu.uni.serval.utils;
import java.io.BufferedInputStream;
import java.io.BufferedWriter; import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class FileHelper { public class FileHelper
{
/** /**
* @param filePath * @param filePath
*/ */
public static void createDirectory(String filePath) { public static void createDirectory(String filePath)
{
File file = new File(filePath); File file = new File(filePath);
if (file.exists()) { if (file.exists())
{
deleteDirectory(filePath); deleteDirectory(filePath);
} }
file.mkdirs(); file.mkdirs();
} }
public static void createFile(File file, String content) { public static void createFile(File file, String content)
{
FileWriter writer = null; FileWriter writer = null;
BufferedWriter bw = null; BufferedWriter bw = null;
try { try
if (!file.getParentFile().exists()) { {
if (!file.getParentFile().exists())
{
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
} }
if (!file.exists()) file.createNewFile(); if (!file.exists())
{
file.createNewFile();
}
writer = new FileWriter(file); writer = new FileWriter(file);
bw = new BufferedWriter(writer); bw = new BufferedWriter(writer);
bw.write(content); bw.write(content);
bw.flush(); bw.flush();
} catch (IOException e) { }
catch (IOException e)
{
e.printStackTrace(); e.printStackTrace();
} finally { }
finally
{
close(bw); close(bw);
close(writer); close(writer);
} }
} }
public static void deleteDirectory(String dir) { public static void deleteDirectory(String dir)
{
File file = new File(dir); File file = new File(dir);
if (file.exists()) { if (file.exists())
if (file.isDirectory()) { {
if (file.isDirectory())
{
File[] files = file.listFiles(); File[] files = file.listFiles();
if (files.length > 0) { if (files.length > 0)
for (File f : files) { {
if (f.isFile()) { for (File f : files)
{
if (f.isFile())
{
deleteFile(f.getAbsolutePath()); deleteFile(f.getAbsolutePath());
} else { }
else
{
deleteDirectory(f.getAbsolutePath()); deleteDirectory(f.getAbsolutePath());
} }
} }
} }
file.delete(); file.delete();
} else { }
else
{
deleteFile(dir); deleteFile(dir);
} }
} }
} }
public static void deleteFiles(String dir) { public static void deleteFiles(String dir)
{
File file = new File(dir); File file = new File(dir);
if (file.exists()) { if (file.exists())
if (file.isDirectory()) { {
if (file.isDirectory())
{
File[] files = file.listFiles(); File[] files = file.listFiles();
if (files.length > 0) { if (files.length > 0)
for (File f : files) { {
if (f.isFile()) { for (File f : files)
{
if (f.isFile())
{
deleteFile(f.getAbsolutePath()); deleteFile(f.getAbsolutePath());
} else { }
else
{
deleteFiles(f.getAbsolutePath()); deleteFiles(f.getAbsolutePath());
} }
} }
} }
} else { }
else
{
deleteFile(dir); deleteFile(dir);
} }
} }
} }
public static void deleteFile(String fileName) { public static void deleteFile(String fileName)
{
File file = new File(fileName); File file = new File(fileName);
if (file.exists()) { if (file.exists())
if (file.isFile()) { {
if (file.isFile())
{
file.delete(); file.delete();
} else { }
else
{
deleteDirectory(fileName); deleteDirectory(fileName);
} }
} }
} }
public static List<File> getAllDirectories(String filePath) { public static List<File> getAllDirectories(String filePath)
{
return listAllDirectories(new File(filePath)); return listAllDirectories(new File(filePath));
} }
@@ -109,26 +143,33 @@ public class FileHelper {
* @param type * @param type
* @return * @return
*/ */
public static List<File> getAllFiles(String filePath, String type) { public static List<File> getAllFiles(String filePath, String type)
{
return listAllFiles(new File(filePath), type); return listAllFiles(new File(filePath), type);
} }
public static List<File> getAllFilesInCurrentDiectory(String filePath, String type) { public static List<File> getAllFilesInCurrentDiectory(String filePath, String type)
{
return getAllFilesInCurrentDiectory(new File(filePath), type); return getAllFilesInCurrentDiectory(new File(filePath), type);
} }
public static List<File> getAllFilesInCurrentDiectory(File directory, String type) { public static List<File> getAllFilesInCurrentDiectory(File directory, String type)
{
List<File> fileList = new ArrayList<>(); List<File> fileList = new ArrayList<>();
if (!directory.exists()) { if (!directory.exists())
{
return null; return null;
} }
File[] files = directory.listFiles(); File[] files = directory.listFiles();
for (File file : files) { for (File file : files)
if (file.isFile()) { {
if (file.toString().endsWith(type)) { if (file.isFile())
{
if (file.toString().endsWith(type))
{
fileList.add(file); fileList.add(file);
} }
} }
@@ -137,36 +178,47 @@ public class FileHelper {
return fileList; return fileList;
} }
public static String getFileName(String filePath) { public static String getFileName(String filePath)
{
File file = new File(filePath); File file = new File(filePath);
if (file.exists()) { if (file.exists())
{
return file.getName(); return file.getName();
} else { }
else
{
return null; return null;
} }
} }
public static String getFileNameWithoutExtension(File file) { public static String getFileNameWithoutExtension(File file)
if (file.exists()) { {
if (file.exists())
{
String fileName = file.getName(); String fileName = file.getName();
fileName = fileName.substring(0, fileName.lastIndexOf(".")); fileName = fileName.substring(0, fileName.lastIndexOf("."));
return fileName; return fileName;
} else { }
else
{
return null; return null;
} }
} }
public static String getFileExtension(File file) { public static String getFileExtension(File file)
{
String fileName = file.getName(); String fileName = file.getName();
String extension = fileName.substring(fileName.lastIndexOf(".")); String extension = fileName.substring(fileName.lastIndexOf("."));
return extension; return extension;
} }
public static String getFileParentPath(String filePath) { public static String getFileParentPath(String filePath)
{
File file = new File(filePath); File file = new File(filePath);
if (file.exists()) { if (file.exists())
{
return file.getParent() + "/"; return file.getParent() + "/";
} }
return ""; return "";
@@ -176,17 +228,13 @@ public class FileHelper {
* Check whether a file path is valid or not. * Check whether a file path is valid or not.
* *
* @param path, file path. * @param path, file path.
* @return true, the file path is valid. * @return true, the file path is valid. false, the file path is invalid.
* false, the file path is invalid.
*/ */
public static boolean isValidPath(String path) { public static boolean isValidPath(String path)
{
File file = new File(path); File file = new File(path);
if (file.exists()) { return file.exists();
return true;
}
return false;
} }
/** /**
@@ -195,23 +243,31 @@ public class FileHelper {
* @param file * @param file
* @return * @return
*/ */
private static List<File> listAllFiles(File file, String type) { private static List<File> listAllFiles(File file, String type)
{
List<File> fileList = new ArrayList<>(); List<File> fileList = new ArrayList<>();
if (!file.exists()) { if (!file.exists())
{
return null; return null;
} }
File[] files = file.listFiles(); File[] files = file.listFiles();
for (File f : files) { for (File f : files)
if (f.isFile()) { {
if (f.toString().endsWith(type)) { if (f.isFile())
{
if (f.toString().endsWith(type))
{
fileList.add(f); fileList.add(f);
} }
} else { }
else
{
List<File> fl = listAllFiles(f, type); List<File> fl = listAllFiles(f, type);
if (fl != null && fl.size() > 0) { if (fl != null && fl.size() > 0)
{
fileList.addAll(fl); fileList.addAll(fl);
} }
} }
@@ -226,13 +282,16 @@ public class FileHelper {
* @param file * @param file
* @return * @return
*/ */
private static List<File> listAllDirectories(File file) { private static List<File> listAllDirectories(File file)
{
List<File> fileList = new ArrayList<>(); List<File> fileList = new ArrayList<>();
File[] files = file.listFiles(); File[] files = file.listFiles();
for (File f : files) { for (File f : files)
if (f.isDirectory()) { {
if (f.isDirectory())
{
fileList.add(f); fileList.add(f);
fileList.addAll(listAllDirectories(f)); fileList.addAll(listAllDirectories(f));
} }
@@ -241,10 +300,12 @@ public class FileHelper {
return fileList; return fileList;
} }
public static void makeDirectory(String fileName) { public static void makeDirectory(String fileName)
{
deleteFile(fileName); deleteFile(fileName);
File file = new File(fileName).getParentFile(); File file = new File(fileName).getParentFile();
if (!file.exists()) { if (!file.exists())
{
file.mkdirs(); file.mkdirs();
} }
} }
@@ -255,7 +316,8 @@ public class FileHelper {
* @param fileName * @param fileName
* @return String, the content of a file. * @return String, the content of a file.
*/ */
public static String readFile(String fileName) { public static String readFile(String fileName)
{
return readFile(new File(fileName)); return readFile(new File(fileName));
} }
@@ -265,26 +327,35 @@ public class FileHelper {
* @param file * @param file
* @return String, the content of a file. * @return String, the content of a file.
*/ */
public static String readFile(File file) { public static String readFile(File file)
{
byte[] input = null; byte[] input = null;
BufferedInputStream bis = null; BufferedInputStream bis = null;
try { try
{
bis = new BufferedInputStream(new FileInputStream(file)); bis = new BufferedInputStream(new FileInputStream(file));
input = new byte[bis.available()]; input = new byte[bis.available()];
bis.read(input); bis.read(input);
} catch (FileNotFoundException e) { }
catch (FileNotFoundException e)
{
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { }
catch (IOException e)
{
e.printStackTrace(); e.printStackTrace();
} finally { }
finally
{
close(bis); close(bis);
} }
String sourceCode = null; String sourceCode = null;
if (input != null) { if (input != null)
{
sourceCode = new String(input); sourceCode = new String(input);
} }
@@ -295,89 +366,119 @@ public class FileHelper {
* Output output into a file. * Output output into a file.
* *
* @param fileName, output file name. * @param fileName, output file name.
* @param data, output data. * @param data, output data.
* @param append, the output data will be appended previous data in the file or not. * @param append, the output data will be appended previous data in the file or not.
*/ */
public static void outputToFile(String fileName, StringBuilder data, boolean append) { public static void outputToFile(String fileName, StringBuilder data, boolean append)
{
outputToFile(fileName, data.toString(), append); outputToFile(fileName, data.toString(), append);
} }
public static void outputToFile(File file, StringBuilder data, boolean append) { public static void outputToFile(File file, StringBuilder data, boolean append)
{
outputToFile(file, data.toString(), append); outputToFile(file, data.toString(), append);
} }
public static void outputToFile(String fileName, String data, boolean append) { public static void outputToFile(String fileName, String data, boolean append)
{
File file = new File(fileName); File file = new File(fileName);
outputToFile(file, data, append); outputToFile(file, data, append);
} }
public static void outputToFile(File file, String data, boolean append) { public static void outputToFile(File file, String data, boolean append)
{
FileWriter writer = null; FileWriter writer = null;
BufferedWriter bw = null; BufferedWriter bw = null;
try { try
if (!file.getParentFile().exists()) { {
if (!file.getParentFile().exists())
{
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
} }
if (!file.exists()) { if (!file.exists())
{
file.createNewFile(); file.createNewFile();
} }
writer = new FileWriter(file, append); writer = new FileWriter(file, append);
bw = new BufferedWriter(writer); bw = new BufferedWriter(writer);
bw.write(data); bw.write(data);
bw.flush(); bw.flush();
} catch (IOException e) { }
catch (IOException e)
{
e.printStackTrace(); e.printStackTrace();
} finally { }
finally
{
close(bw); close(bw);
close(writer); close(writer);
} }
} }
private static void close(FileWriter writer) { private static void close(FileWriter writer)
try { {
if (writer != null) { try
{
if (writer != null)
{
writer.close(); writer.close();
writer = null; writer = null;
} }
} catch (IOException e) { }
catch (IOException e)
{
e.printStackTrace(); e.printStackTrace();
} }
} }
private static void close(BufferedWriter bw) { private static void close(BufferedWriter bw)
try { {
if (bw != null) { try
{
if (bw != null)
{
bw.close(); bw.close();
bw = null; bw = null;
} }
} catch (IOException e) { }
catch (IOException e)
{
e.printStackTrace(); e.printStackTrace();
} }
} }
private static void close(BufferedInputStream bis) { private static void close(BufferedInputStream bis)
try { {
if (bis != null) { try
{
if (bis != null)
{
bis.close(); bis.close();
bis = null; bis = null;
} }
} catch (IOException e) { }
catch (IOException e)
{
e.printStackTrace(); e.printStackTrace();
} }
} }
public static List<File> getAllSubDirectories(String fileName) { public static List<File> getAllSubDirectories(String fileName)
{
File file = new File(fileName); File file = new File(fileName);
List<File> subDirectories = new ArrayList<>(); List<File> subDirectories = new ArrayList<>();
if (file.exists()) { if (file.exists())
{
File[] files = file.listFiles(); File[] files = file.listFiles();
for (File f : files) { for (File f : files)
if (f.isDirectory()) { {
if (f.isDirectory())
{
subDirectories.add(f); subDirectories.add(f);
} }
} }
} }
return subDirectories; return subDirectories;
} }
} }
@@ -5,41 +5,53 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
public class ListSorter<T extends Comparable<? super T>> { public class ListSorter<T extends Comparable<? super T>>
{
private List<T> list; private final List<T> list;
public ListSorter(List<T> list) { public ListSorter(List<T> list)
{
this.list = new ArrayList<>(); this.list = new ArrayList<>();
this.list.addAll(list); this.list.addAll(list);
} }
public List<T> getList() { public List<T> getList()
{
return this.list; return this.list;
} }
public List<T> sortAscending() { public List<T> sortAscending()
try { {
if (list != null && list.size() > 0) { try
Collections.sort(this.list, new Comparator<T>() { {
if (list != null && list.size() > 0)
{
Collections.sort(this.list, new Comparator<T>()
{
@Override @Override
public int compare(T t1, T t2) { public int compare(T t1, T t2)
{
return t1.compareTo(t2); return t1.compareTo(t2);
} }
}); });
} }
} catch (Exception e) { }
catch (Exception e)
{
return null; return null;
} }
return this.list; return this.list;
} }
public List<T> sortDescending() { public List<T> sortDescending()
if (list != null && list.size() > 0) { {
if (list != null && list.size() > 0)
{
Collections.sort(this.list, Collections.reverseOrder()); Collections.sort(this.list, Collections.reverseOrder());
} }
return this.list; return this.list;
} }
} }
@@ -7,25 +7,25 @@ import java.time.Duration;
/** /**
* Created by anilkoyuncu on 17/09/2018. * Created by anilkoyuncu on 17/09/2018.
*/ */
public class PoolBuilder { public class PoolBuilder
public static JedisPoolConfig getPoolConfig() { {
public static JedisPoolConfig getPoolConfig()
{
return poolConfig; return poolConfig;
} }
static final JedisPoolConfig poolConfig = buildPoolConfig(); static final JedisPoolConfig poolConfig = buildPoolConfig();
private static JedisPoolConfig buildPoolConfig()
{
private static JedisPoolConfig buildPoolConfig() {
final JedisPoolConfig poolConfig = new JedisPoolConfig(); final JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxTotal(1024); poolConfig.setMaxTotal(1024);
poolConfig.setMaxIdle(1024); poolConfig.setMaxIdle(1024);
// poolConfig.setMinIdle(16); // poolConfig.setMinIdle(16);
// poolConfig.setTestOnBorrow(true); // poolConfig.setTestOnBorrow(true);
// poolConfig.setTestOnReturn(true); // poolConfig.setTestOnReturn(true);
// poolConfig.setTestWhileIdle(true); // poolConfig.setTestWhileIdle(true);
poolConfig.setMinEvictableIdleTimeMillis(Duration.ofMinutes(60).toMillis()); poolConfig.setMinEvictableIdleTimeMillis(Duration.ofMinutes(60).toMillis());
poolConfig.setTimeBetweenEvictionRunsMillis(Duration.ofHours(30).toMillis()); poolConfig.setTimeBetweenEvictionRunsMillis(Duration.ofHours(30).toMillis());
poolConfig.setNumTestsPerEvictionRun(3); poolConfig.setNumTestsPerEvictionRun(3);