[O] Reformat code for java
This commit is contained in:
@@ -17,7 +17,7 @@ import java.util.Properties;
|
||||
*/
|
||||
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
|
||||
{
|
||||
|
||||
@@ -3,42 +3,51 @@ package edu.lu.uni.serval.richedit.ediff;
|
||||
/**
|
||||
* Created by anilkoyuncu on 18/09/2018.
|
||||
*/
|
||||
public class BaseMessage {
|
||||
public class BaseMessage
|
||||
{
|
||||
|
||||
private long SECONDS_TO_WAIT;
|
||||
|
||||
private int id;
|
||||
|
||||
private int threadPoolSize;
|
||||
|
||||
|
||||
public BaseMessage(int id,Long timeout) {
|
||||
public BaseMessage(int id, Long timeout)
|
||||
{
|
||||
this.id = id;
|
||||
this.SECONDS_TO_WAIT = timeout;
|
||||
// this.threadPoolSize = threadPoolSize;
|
||||
// this.threadPoolSize = threadPoolSize;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
public int getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
public void setId(int id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public long getSECONDS_TO_WAIT() {
|
||||
public long getSECONDS_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;
|
||||
}
|
||||
|
||||
public int getThreadPoolSize() {
|
||||
public int getThreadPoolSize()
|
||||
{
|
||||
return threadPoolSize;
|
||||
}
|
||||
|
||||
public void setThreadPoolSize(int threadPoolSize) {
|
||||
public void setThreadPoolSize(int threadPoolSize)
|
||||
{
|
||||
this.threadPoolSize = threadPoolSize;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,66 +10,84 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EDiffActor extends UntypedActor {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(EDiffActor.class);
|
||||
public class EDiffActor extends UntypedActor
|
||||
{
|
||||
|
||||
private ActorRef mineRouter;
|
||||
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;
|
||||
}
|
||||
private static final Logger logger = LoggerFactory.getLogger(EDiffActor.class);
|
||||
|
||||
public static Props props(final int numberOfWorkers, final String project) {
|
||||
|
||||
return Props.create(new Creator<EDiffActor>() {
|
||||
private final ActorRef mineRouter;
|
||||
|
||||
private static final long serialVersionUID = 9207427376110704705L;
|
||||
private final int numberOfWorkers;
|
||||
|
||||
@Override
|
||||
public EDiffActor create() throws Exception {
|
||||
return new EDiffActor(numberOfWorkers, project);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onReceive(Object message) throws Exception {
|
||||
if (message instanceof EDiffMessage) {
|
||||
List<MessageFile> files = ((EDiffMessage) message).getMsgFiles();
|
||||
int size = files.size();
|
||||
int average = size / numberOfWorkers;
|
||||
int reminder = size % numberOfWorkers;
|
||||
int counter = 0;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
||||
return Props.create(new Creator<EDiffActor>()
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 9207427376110704705L;
|
||||
|
||||
@Override
|
||||
public EDiffActor create() throws Exception
|
||||
{
|
||||
return new EDiffActor(numberOfWorkers, project);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onReceive(Object message) throws Exception
|
||||
{
|
||||
if (message instanceof EDiffMessage)
|
||||
{
|
||||
List<MessageFile> files = ((EDiffMessage) message).getMsgFiles();
|
||||
int size = files.size();
|
||||
int average = size / numberOfWorkers;
|
||||
int reminder = size % numberOfWorkers;
|
||||
int counter = 0;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Parse fix violations with GumTree in terms of multiple statements.
|
||||
*
|
||||
* @author kui.liu
|
||||
*
|
||||
*/
|
||||
public class EDiffHunkParser extends EDiffParser {
|
||||
public class EDiffHunkParser extends EDiffParser
|
||||
{
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(EDiffHunkParser.class);
|
||||
@Override
|
||||
public void parseFixPatterns(File prevFile, File revFile, File diffentryFile, String project, JedisPool innerPool,String srcMLPath,String hunkLimit,boolean isJava) {
|
||||
try {
|
||||
String datasetName = project;
|
||||
String[] split1 = diffentryFile.getParent().split(datasetName);
|
||||
String root = split1[0];
|
||||
String pj = split1[1].split("/")[1];
|
||||
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)
|
||||
{
|
||||
try
|
||||
{
|
||||
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)) {
|
||||
processActionSet = false;
|
||||
logger.debug("Skipping {} set size {}", diffentryFile.getName(), hunkLimit);
|
||||
}
|
||||
if (actionSets.size() > Integer.valueOf(hunkLimit))
|
||||
{
|
||||
processActionSet = false;
|
||||
logger.debug("Skipping {} set size {}", diffentryFile.getName(), hunkLimit);
|
||||
}
|
||||
|
||||
int hunkSet = 0;
|
||||
if (processActionSet) {
|
||||
int hunkSet = 0;
|
||||
if (processActionSet)
|
||||
{
|
||||
|
||||
for (HierarchicalActionSet actionSet : actionSets) {
|
||||
// FileOutputStream f = null;
|
||||
for (HierarchicalActionSet actionSet : actionSets)
|
||||
{
|
||||
// FileOutputStream f = null;
|
||||
|
||||
// try {
|
||||
// try {
|
||||
|
||||
String astNodeType = actionSet.getAstNodeType();
|
||||
// if (astNodeType.equals(rootType)){
|
||||
//
|
||||
// }
|
||||
actionSet.toString();
|
||||
int size = actionSet.getActionSize();
|
||||
String astNodeType = actionSet.getAstNodeType();
|
||||
// if (astNodeType.equals(rootType)){
|
||||
//
|
||||
// }
|
||||
actionSet.toString();
|
||||
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 actionTree = EDiffHelper.getActionTrees(actionSet);
|
||||
ITree shapeTree = EDiffHelper.getShapeTree(actionSet, isJava);
|
||||
ITree tokenTree = EDiffHelper.getTokenTree(actionSet,isJava);
|
||||
String tokens = EDiffHelper.getNames2(tokenTree);
|
||||
// EDiffHelper.getTokenTree(actionSet, parent, children, tc);
|
||||
try (Jedis inner = innerPool.getResource()) {
|
||||
ITree targetTree = EDiffHelper.getTargets(actionSet, isJava);
|
||||
ITree actionTree = EDiffHelper.getActionTrees(actionSet);
|
||||
ITree shapeTree = EDiffHelper.getShapeTree(actionSet, isJava);
|
||||
ITree tokenTree = EDiffHelper.getTokenTree(actionSet, isJava);
|
||||
String tokens = EDiffHelper.getNames2(tokenTree);
|
||||
// EDiffHelper.getTokenTree(actionSet, parent, children, tc);
|
||||
try (Jedis inner = innerPool.getResource())
|
||||
{
|
||||
|
||||
inner.hset("dump", key, actionSet.toString());
|
||||
inner.hset(key, "actionTree", actionTree.toStaticHashString());
|
||||
inner.hset(key, "targetTree", targetTree.toStaticHashString());
|
||||
inner.hset(key, "shapeTree", shapeTree.toStaticHashString());
|
||||
inner.hset(key, "tokens", tokens);
|
||||
}
|
||||
// File f = new File(root+"dumps/"+astNodeType+"/"+String.valueOf(size)+"/");
|
||||
// f.mkdirs();
|
||||
// f = new File(root+"dumps/"+key);
|
||||
//
|
||||
// FileUtils.writeByteArrayToFile(f,EDiffHelper.kryoSerialize(actionSet));
|
||||
// FileUtils.writeByteArrayToFile(f,EDiffHelper.commonsSerialize(actionSet));
|
||||
// FileUtils.writeByteArrayToFile(f,actionSet.toString().getBytes());
|
||||
// FileOutputStream fos = new FileOutputStream(f);
|
||||
// ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||
// oos.writeObject(EDiffHelper.kryoSerialize(actionSet));
|
||||
// oos.flush();
|
||||
// oos.close();
|
||||
inner.hset("dump", key, actionSet.toString());
|
||||
inner.hset(key, "actionTree", actionTree.toStaticHashString());
|
||||
inner.hset(key, "targetTree", targetTree.toStaticHashString());
|
||||
inner.hset(key, "shapeTree", shapeTree.toStaticHashString());
|
||||
inner.hset(key, "tokens", tokens);
|
||||
}
|
||||
// File f = new File(root+"dumps/"+astNodeType+"/"+String.valueOf(size)+"/");
|
||||
// f.mkdirs();
|
||||
// f = new File(root+"dumps/"+key);
|
||||
//
|
||||
// FileUtils.writeByteArrayToFile(f,EDiffHelper.kryoSerialize(actionSet));
|
||||
// FileUtils.writeByteArrayToFile(f,EDiffHelper.commonsSerialize(actionSet));
|
||||
// FileUtils.writeByteArrayToFile(f,actionSet.toString().getBytes());
|
||||
// FileOutputStream fos = new FileOutputStream(f);
|
||||
// ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||
// oos.writeObject(EDiffHelper.kryoSerialize(actionSet));
|
||||
// oos.flush();
|
||||
// oos.close();
|
||||
|
||||
// } catch (Exception e) {
|
||||
// logger.error("error", e);
|
||||
//// e.printStackTrace();
|
||||
// }
|
||||
hunkSet++;
|
||||
}
|
||||
try (Jedis inner = innerPool.getResource()) {
|
||||
inner.hset("diffEntry", pj + "_" + diffentryFile.getName(), "1");
|
||||
}
|
||||
// } catch (Exception e) {
|
||||
// logger.error("error", e);
|
||||
//// e.printStackTrace();
|
||||
// }
|
||||
hunkSet++;
|
||||
}
|
||||
try (Jedis inner = innerPool.getResource())
|
||||
{
|
||||
inner.hset("diffEntry", pj + "_" + diffentryFile.getName(), "1");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("error", e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.error("error", e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,63 +4,70 @@ import redis.clients.jedis.JedisPool;
|
||||
|
||||
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() {
|
||||
return innerPool;
|
||||
}
|
||||
public JedisPool getInnerPool()
|
||||
{
|
||||
return innerPool;
|
||||
}
|
||||
|
||||
public void setInnerPool(JedisPool innerPool) {
|
||||
this.innerPool = innerPool;
|
||||
}
|
||||
public void setInnerPool(JedisPool innerPool)
|
||||
{
|
||||
this.innerPool = innerPool;
|
||||
}
|
||||
|
||||
private JedisPool innerPool;
|
||||
private JedisPool innerPool;
|
||||
|
||||
public String getSrcMLPath() {
|
||||
return srcMLPath;
|
||||
}
|
||||
public String getSrcMLPath()
|
||||
{
|
||||
return srcMLPath;
|
||||
}
|
||||
|
||||
private String srcMLPath;
|
||||
private String srcMLPath;
|
||||
|
||||
public String getRootType() {
|
||||
return rootType;
|
||||
}
|
||||
public String getRootType()
|
||||
{
|
||||
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> 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)
|
||||
{
|
||||
|
||||
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.gen.srcml.GumTreeCComparer;
|
||||
import edu.lu.uni.serval.gumtree.GumTreeComparer;
|
||||
|
||||
|
||||
import edu.lu.uni.serval.utils.ListSorter;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
@@ -18,87 +16,100 @@ import java.util.List;
|
||||
* Parse fix patterns with GumTree.
|
||||
*
|
||||
* @author kui.liu
|
||||
*
|
||||
*/
|
||||
public class EDiffParser extends Parser {
|
||||
public class EDiffParser extends Parser
|
||||
{
|
||||
|
||||
/*
|
||||
* ResultType:
|
||||
* 0: normal GumTree results.
|
||||
* 1: null GumTree result.
|
||||
* 2: No source code changes.
|
||||
* 3: No Statement Change.
|
||||
* 4: useless violations
|
||||
*/
|
||||
public int resultType = 0;
|
||||
/*
|
||||
* ResultType:
|
||||
* 0: normal GumTree results.
|
||||
* 1: null GumTree result.
|
||||
* 2: No source code changes.
|
||||
* 3: No Statement Change.
|
||||
* 4: useless violations
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
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) {
|
||||
this.resultType = 1;
|
||||
return actionSets;
|
||||
} else if (gumTreeResults.size() == 0){
|
||||
this.resultType = 2;
|
||||
return actionSets;
|
||||
} else {
|
||||
// Regroup GumTre results.
|
||||
List<HierarchicalActionSet> allActionSets = null;
|
||||
if (isJava){
|
||||
allActionSets = new HierarchicalRegrouper().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);
|
||||
}
|
||||
}
|
||||
if (gumTreeResults == null)
|
||||
{
|
||||
this.resultType = 1;
|
||||
return actionSets;
|
||||
}
|
||||
else if (gumTreeResults.size() == 0)
|
||||
{
|
||||
this.resultType = 2;
|
||||
return actionSets;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Regroup GumTre results.
|
||||
List<HierarchicalActionSet> allActionSets = null;
|
||||
if (isJava)
|
||||
{
|
||||
allActionSets = new HierarchicalRegrouper().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);
|
||||
actionSets = sorter.sortAscending();
|
||||
ListSorter<HierarchicalActionSet> sorter = new ListSorter<>(allActionSets);
|
||||
actionSets = sorter.sortAscending();
|
||||
|
||||
if (actionSets.size() == 0) {
|
||||
this.resultType = 3;
|
||||
}
|
||||
if (actionSets.size() == 0)
|
||||
{
|
||||
this.resultType = 3;
|
||||
}
|
||||
|
||||
return actionSets;
|
||||
}
|
||||
}
|
||||
return actionSets;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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, 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.concurrent.*;
|
||||
|
||||
public class EDiffWorker extends UntypedActor {
|
||||
private static Logger log = LoggerFactory.getLogger(EDiffActor.class);
|
||||
|
||||
private String project;
|
||||
public class EDiffWorker extends UntypedActor
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(EDiffActor.class);
|
||||
|
||||
|
||||
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();
|
||||
private final String project;
|
||||
|
||||
|
||||
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();
|
||||
// schedule the work
|
||||
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();
|
||||
|
||||
|
||||
final Future<?> future = executor.submit(new RunnableParser(prevFile, revFile, diffentryFile, parser,project,msg.getInnerPool(),srcMLPath,rootType,false));
|
||||
try {
|
||||
// wait for task to complete
|
||||
future.get(msg.getSECONDS_TO_WAIT(), TimeUnit.SECONDS);
|
||||
EDiffHunkParser parser = new EDiffHunkParser();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
// schedule the work
|
||||
|
||||
log.info("Worker #" + id + " finalized the work...");
|
||||
this.getSender().tell("STOP", getSelf());
|
||||
} else {
|
||||
unhandled(message);
|
||||
}
|
||||
}
|
||||
|
||||
final Future<?> future = executor.submit(new RunnableParser(prevFile, revFile, diffentryFile, parser, project, msg.getInnerPool(), srcMLPath, rootType, false));
|
||||
try
|
||||
{
|
||||
// wait for task to complete
|
||||
future.get(msg.getSECONDS_TO_WAIT(), TimeUnit.SECONDS);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+213
-160
@@ -9,203 +9,256 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Hierarchical-level results of GumTree results
|
||||
*
|
||||
* @author kui.liu
|
||||
*
|
||||
* @author kui.liu
|
||||
*/
|
||||
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 class HierarchicalActionSet implements Comparable<HierarchicalActionSet>, Serializable
|
||||
{
|
||||
|
||||
public int getBugEndPosition() {
|
||||
return bugEndPosition;
|
||||
}
|
||||
private String astNodeType;
|
||||
|
||||
public int getFixEndPosition() {
|
||||
return fixEndPosition;
|
||||
}
|
||||
private Action action;
|
||||
|
||||
private int bugEndPosition;
|
||||
private int fixEndPosition;
|
||||
private Action parentAction;
|
||||
|
||||
public ITree getNode() {
|
||||
return node;
|
||||
}
|
||||
private String actionString;
|
||||
|
||||
public void setNode(ITree node) {
|
||||
this.node = node;
|
||||
}
|
||||
private Integer startPosition;
|
||||
|
||||
public void setAstNodeType(String astNodeType) {
|
||||
this.astNodeType = astNodeType;
|
||||
}
|
||||
|
||||
public String getAstNodeType() {
|
||||
return astNodeType;
|
||||
}
|
||||
private Integer length;
|
||||
|
||||
public Action getAction() {
|
||||
return action;
|
||||
}
|
||||
private int bugStartLineNum = 0;
|
||||
|
||||
public void setAction(Action action) {
|
||||
this.action = action;
|
||||
}
|
||||
private int bugEndLineNum;
|
||||
|
||||
public Action getParentAction() {
|
||||
return parentAction;
|
||||
}
|
||||
private int fixStartLineNum;
|
||||
|
||||
public void setParentAction(Action parentAction) {
|
||||
this.parentAction = parentAction;
|
||||
}
|
||||
private int fixEndLineNum;
|
||||
|
||||
public String getActionString() {
|
||||
return actionString;
|
||||
}
|
||||
private HierarchicalActionSet parent = null;
|
||||
|
||||
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;
|
||||
}
|
||||
private List<HierarchicalActionSet> subActions = new ArrayList<>();
|
||||
|
||||
public int getStartPosition() {
|
||||
return startPosition;
|
||||
}
|
||||
private ITree node;
|
||||
// source code tree.
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
public int getBugEndPosition()
|
||||
{
|
||||
return bugEndPosition;
|
||||
}
|
||||
|
||||
public int getBugStartLineNum() {
|
||||
return bugStartLineNum;
|
||||
}
|
||||
public int getFixEndPosition()
|
||||
{
|
||||
return fixEndPosition;
|
||||
}
|
||||
|
||||
public void setBugStartLineNum(int bugStartLineNum) {
|
||||
this.bugStartLineNum = bugStartLineNum;
|
||||
}
|
||||
private int bugEndPosition;
|
||||
|
||||
public int getBugEndLineNum() {
|
||||
return bugEndLineNum;
|
||||
}
|
||||
private int fixEndPosition;
|
||||
|
||||
public void setBugEndLineNum(int bugEndLineNum) {
|
||||
this.bugEndLineNum = bugEndLineNum;
|
||||
}
|
||||
public ITree getNode()
|
||||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
public int getFixStartLineNum() {
|
||||
return fixStartLineNum;
|
||||
}
|
||||
public void setNode(ITree node)
|
||||
{
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public void setFixStartLineNum(int fixStartLineNum) {
|
||||
this.fixStartLineNum = fixStartLineNum;
|
||||
}
|
||||
public void setAstNodeType(String astNodeType)
|
||||
{
|
||||
this.astNodeType = astNodeType;
|
||||
}
|
||||
|
||||
public int getFixEndLineNum() {
|
||||
return fixEndLineNum;
|
||||
}
|
||||
public String getAstNodeType()
|
||||
{
|
||||
return astNodeType;
|
||||
}
|
||||
|
||||
public void setFixEndLineNum(int fixEndLineNum) {
|
||||
this.fixEndLineNum = fixEndLineNum;
|
||||
}
|
||||
public Action getAction()
|
||||
{
|
||||
return action;
|
||||
}
|
||||
|
||||
public HierarchicalActionSet getParent() {
|
||||
return parent;
|
||||
}
|
||||
public void setAction(Action action)
|
||||
{
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public void setParent(HierarchicalActionSet parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
public Action getParentAction()
|
||||
{
|
||||
return parentAction;
|
||||
}
|
||||
|
||||
public List<HierarchicalActionSet> getSubActions() {
|
||||
return subActions;
|
||||
}
|
||||
public void setParentAction(Action parentAction)
|
||||
{
|
||||
this.parentAction = parentAction;
|
||||
}
|
||||
|
||||
public void setSubActions(List<HierarchicalActionSet> subActions) {
|
||||
this.subActions = subActions;
|
||||
}
|
||||
public String getActionString()
|
||||
{
|
||||
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) {
|
||||
this.bugEndPosition = bugEndPosition;
|
||||
}
|
||||
public void setBugEndPosition(int bugEndPosition)
|
||||
{
|
||||
this.bugEndPosition = bugEndPosition;
|
||||
}
|
||||
|
||||
|
||||
public void setFixEndPosition(int fixEndPosition)
|
||||
{
|
||||
this.fixEndPosition = fixEndPosition;
|
||||
}
|
||||
|
||||
public void setFixEndPosition(int fixEndPosition) {
|
||||
this.fixEndPosition = fixEndPosition;
|
||||
}
|
||||
@Override
|
||||
public int compareTo(HierarchicalActionSet o)
|
||||
{
|
||||
|
||||
@Override
|
||||
public int compareTo(HierarchicalActionSet o) {
|
||||
return this.startPosition.compareTo(o.startPosition);//this.action.compareTo(o.action);
|
||||
}
|
||||
|
||||
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(){
|
||||
return strList.size();
|
||||
}
|
||||
@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;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+377
-306
@@ -5,7 +5,6 @@ import com.github.gumtreediff.tree.ITree;
|
||||
import edu.lu.uni.serval.utils.ASTNodeMap;
|
||||
import edu.lu.uni.serval.utils.ListSorter;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
@@ -13,323 +12,395 @@ import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
/*
|
||||
* First, sort actions by their positions.
|
||||
*/
|
||||
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);
|
||||
|
||||
}
|
||||
public List<HierarchicalActionSet> regroupGumTreeResults(List<Action> actions)
|
||||
{
|
||||
/*
|
||||
* First, sort actions by their positions.
|
||||
*/
|
||||
actions = new ListSorter<Action>(actions).sortAscending();
|
||||
|
||||
|
||||
/*
|
||||
* Second, group actions by their positions.
|
||||
*/
|
||||
List<HierarchicalActionSet> actionSets = new ArrayList<>();
|
||||
HierarchicalActionSet actionSet = null;
|
||||
|
||||
return reActionSets1;
|
||||
// return reActionSets;
|
||||
}
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private boolean isStatement(HierarchicalActionSet actSet){
|
||||
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")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Predicate<HierarchicalActionSet> predicate = x-> isStatement(x);
|
||||
|
||||
private HierarchicalActionSet removeBlocks(HierarchicalActionSet actionSet){
|
||||
List<HierarchicalActionSet> subActions = actionSet.getSubActions();
|
||||
return reActionSets1;
|
||||
// return reActionSets;
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
if (subActions.size() == 1){
|
||||
HierarchicalActionSet subaction = subActions.get(0);
|
||||
Predicate<HierarchicalActionSet> predicate = x -> isStatement(x);
|
||||
|
||||
List<HierarchicalActionSet> collect = postOrder(subaction).stream().filter(predicate).collect(Collectors.toList());
|
||||
if(collect.size() == 0){
|
||||
return actionSet;
|
||||
}
|
||||
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;
|
||||
}
|
||||
private HierarchicalActionSet removeBlocks(HierarchicalActionSet actionSet)
|
||||
{
|
||||
List<HierarchicalActionSet> subActions = actionSet.getSubActions();
|
||||
|
||||
|
||||
}
|
||||
|
||||
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 (parent instanceof Insert && !(child instanceof Addition)) {// If action is DEL, its children must be DEL.
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Action action = actionSet.getAction();
|
||||
if (subActions.size() == 1)
|
||||
{
|
||||
HierarchicalActionSet subaction = subActions.get(0);
|
||||
|
||||
List<HierarchicalActionSet> collect = postOrder(subaction).stream().filter(predicate).collect(Collectors.toList());
|
||||
if (collect.size() == 0)
|
||||
{
|
||||
return actionSet;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+620
-540
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;
|
||||
|
||||
public class MessageFile {
|
||||
|
||||
private File revFile;
|
||||
private File prevFile;
|
||||
private File diffEntryFile;
|
||||
private File positionFile;
|
||||
public class MessageFile
|
||||
{
|
||||
|
||||
private final File revFile;
|
||||
|
||||
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) {
|
||||
super();
|
||||
this.revFile = revFile;
|
||||
this.prevFile = prevFile;
|
||||
this.diffEntryFile = diffEntryFile;
|
||||
this.project = project;
|
||||
}
|
||||
public MessageFile(File revFile, File prevFile, File diffEntryFile, String project)
|
||||
{
|
||||
super();
|
||||
this.revFile = revFile;
|
||||
this.prevFile = prevFile;
|
||||
this.diffEntryFile = diffEntryFile;
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public String getProject() { return project;}
|
||||
public String getProject()
|
||||
{
|
||||
return project;
|
||||
}
|
||||
|
||||
public void setProject(String project) { this.project = project;}
|
||||
public File getRevFile() {
|
||||
return revFile;
|
||||
}
|
||||
|
||||
public File getPrevFile() {
|
||||
return prevFile;
|
||||
}
|
||||
|
||||
public File getDiffEntryFile() {
|
||||
return diffEntryFile;
|
||||
}
|
||||
public void setProject(String project)
|
||||
{
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public File getPositionFile() {
|
||||
return positionFile;
|
||||
}
|
||||
public File getRevFile()
|
||||
{
|
||||
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.
|
||||
*
|
||||
* @author kui.liu
|
||||
*
|
||||
* @author kui.liu
|
||||
*/
|
||||
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 class Parser implements ParserInterface
|
||||
{
|
||||
|
||||
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
|
||||
public String getAstEditScripts() {
|
||||
return astEditScripts;
|
||||
}
|
||||
protected String patchesSourceCode = ""; // testing
|
||||
|
||||
@Override
|
||||
public String getPatchesSourceCode() {
|
||||
return patchesSourceCode;
|
||||
}
|
||||
protected String buggyTrees = ""; // Compute similarity for bug localization.
|
||||
|
||||
// @Override
|
||||
// public String getBuggyTrees() {
|
||||
// return buggyTrees;
|
||||
// }
|
||||
protected String sizes = ""; // fix patterns' selection before mining.
|
||||
|
||||
@Override
|
||||
public String getSizes() {
|
||||
return sizes;
|
||||
}
|
||||
protected String tokensOfSourceCode = ""; // Compute similarity for bug localization.
|
||||
|
||||
@Override
|
||||
public String getTokensOfSourceCode() {
|
||||
return tokensOfSourceCode;
|
||||
}
|
||||
protected String originalTree = ""; // Guide of generating patches.
|
||||
|
||||
// @Override
|
||||
// public String getOriginalTree() {
|
||||
// return originalTree;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getActionSets() {
|
||||
// return actionSets;
|
||||
// }
|
||||
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);
|
||||
|
||||
|
||||
@Override
|
||||
public String getAstEditScripts()
|
||||
{
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
public class RunnableParser implements Runnable {
|
||||
public class RunnableParser implements Runnable
|
||||
{
|
||||
|
||||
private 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;
|
||||
private final File prevFile;
|
||||
|
||||
public RunnableParser(File prevFile, File revFile, File diffEntryFile, Parser parser) {
|
||||
this.prevFile = prevFile;
|
||||
this.revFile = revFile;
|
||||
this.diffEntryFile = diffEntryFile;
|
||||
this.parser = parser;
|
||||
}
|
||||
private final File revFile;
|
||||
|
||||
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;
|
||||
}
|
||||
private final File diffEntryFile;
|
||||
|
||||
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;
|
||||
}
|
||||
private final Parser parser;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
parser.parseFixPatterns(prevFile, revFile, diffEntryFile,project,pool,srcMLPath,rootType,isJava);
|
||||
}
|
||||
private String project;
|
||||
|
||||
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.HashMap;
|
||||
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.IntStream;
|
||||
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
// 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";
|
||||
public static void main(String redisPath, String portDumps, String dumpsName, String numOfWorkers) throws Exception
|
||||
{
|
||||
String port = portDumps; //"6399";
|
||||
CallShell cs = new CallShell();
|
||||
String cmd = "bash "+redisPath + "/" + "startServer.sh" +" %s %s %s";
|
||||
cmd = String.format(cmd, redisPath,dumpsName,Integer.valueOf(port));
|
||||
String cmd = "bash " + redisPath + "/" + "startServer.sh" + " %s %s %s";
|
||||
cmd = String.format(cmd, redisPath, dumpsName, Integer.valueOf(port));
|
||||
log.info(cmd);
|
||||
cs.runShell(cmd, port);
|
||||
CallShell.runShell(cmd, port);
|
||||
|
||||
// String cmdInner = "bash "+redisPath + "/" + "startServer.sh" +" %s %s %s";
|
||||
// cmdInner = String.format(cmdInner, redisPath,compareDBName,Integer.valueOf(portInner));
|
||||
// log.info(cmdInner);
|
||||
// cs.runShell(cmdInner, portInner);
|
||||
final JedisPool outerPool = new JedisPool(PoolBuilder.getPoolConfig(), "localhost", Integer.valueOf(port), 20000000);
|
||||
|
||||
// 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);
|
||||
String job= getLevel(outerPool);
|
||||
// List<String> listOfPairs = AkkaTreeParser.files2compare(outerPool);
|
||||
String job = getLevel(outerPool);
|
||||
|
||||
|
||||
// ArrayList<String> samePairs = new ArrayList<>();
|
||||
ArrayList<String> errorPairs = new ArrayList<>();
|
||||
|
||||
// Integer numberOfWorkers = Integer.valueOf(numOfWorkers);
|
||||
// final ExecutorService executor = Executors.newWorkStealingPool(numberOfWorkers);
|
||||
Long compare;
|
||||
try (Jedis inner = outerPool.getResource()) {
|
||||
try (Jedis inner = outerPool.getResource())
|
||||
{
|
||||
compare = inner.scard("compare");
|
||||
}
|
||||
IntStream stream = IntStream.range(0, compare.intValue());
|
||||
|
||||
String finalJob = job;
|
||||
ProgressBar.wrap(stream.
|
||||
parallel(),"Task").
|
||||
|
||||
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();
|
||||
|
||||
|
||||
|
||||
ProgressBar.wrap(stream.parallel(), "Task").forEach(m ->
|
||||
{
|
||||
newCoreCompare(finalJob, errorPairs, filenames, outerPool);
|
||||
}
|
||||
);
|
||||
|
||||
log.info("End process");
|
||||
}
|
||||
|
||||
|
||||
// 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 ) {
|
||||
|
||||
public static boolean newCoreCompare(String treeType, ArrayList<String> errorPairs, HashMap<String, String> filenames, JedisPool outerPool)
|
||||
{
|
||||
String pairName = null;
|
||||
try (Jedis outer = outerPool.getResource()) {
|
||||
try (Jedis outer = outerPool.getResource())
|
||||
{
|
||||
pairName = outer.spop("compare");
|
||||
// }
|
||||
if(pairName.equals("0"))
|
||||
return true;
|
||||
String matchKey = null;
|
||||
// try {
|
||||
// }
|
||||
if (pairName.equals("0"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
String matchKey = null;
|
||||
|
||||
String[] split = pairName.split("/");
|
||||
|
||||
|
||||
String i = split[1];
|
||||
String j = split[2];
|
||||
String keyName = split[0];
|
||||
matchKey = keyName + "/" + (String.valueOf(i)) + "/" + String.valueOf(j);
|
||||
matchKey = keyName + "/" + (i) + "/" + j;
|
||||
|
||||
if (matchKey == null){
|
||||
if (matchKey == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Map<String, String> oldTreeString = EDiffHelper.getTreeString(keyName, i, outerPool, filenames);
|
||||
Map<String, String> newTreeString = EDiffHelper.getTreeString(keyName, j, outerPool, filenames);
|
||||
|
||||
switch (treeType) {
|
||||
switch (treeType)
|
||||
{
|
||||
case "single":
|
||||
|
||||
|
||||
|
||||
String oldShapeTree =oldTreeString.get("shapeTree");
|
||||
String newShapeTree =newTreeString.get("shapeTree");
|
||||
String oldShapeTree = oldTreeString.get("shapeTree");
|
||||
String newShapeTree = newTreeString.get("shapeTree");
|
||||
|
||||
String oldActionTree = oldTreeString.get("actionTree");
|
||||
String newActionTree = newTreeString.get("actionTree");
|
||||
@@ -189,12 +98,14 @@ public class CompareTrees {
|
||||
String newTargetTree = newTreeString.get("targetTree");
|
||||
|
||||
|
||||
if (oldShapeTree.equals(newShapeTree)) {
|
||||
if (oldActionTree.equals(newActionTree)) {
|
||||
if (oldTargetTree.equals(newTargetTree)) {
|
||||
// samePairs.add(matchKey);
|
||||
try (Jedis jedis = outerPool.getResource()) {
|
||||
//// jedis.del(matchKey);
|
||||
if (oldShapeTree.equals(newShapeTree))
|
||||
{
|
||||
if (oldActionTree.equals(newActionTree))
|
||||
{
|
||||
if (oldTargetTree.equals(newTargetTree))
|
||||
{
|
||||
try (Jedis jedis = outerPool.getResource())
|
||||
{
|
||||
jedis.select(2);
|
||||
jedis.set(matchKey, "1");
|
||||
}
|
||||
@@ -206,61 +117,54 @@ public class CompareTrees {
|
||||
|
||||
String oldTokens = oldTreeString.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();
|
||||
//
|
||||
//
|
||||
Double overallSimi = Double.valueOf(0);
|
||||
//
|
||||
if (!(oldTokens.trim().isEmpty() || newTokens.trim().isEmpty())) {
|
||||
if (!(oldTokens.trim().isEmpty() || newTokens.trim().isEmpty()))
|
||||
{
|
||||
overallSimi = jwd.apply(oldTokens, newTokens);
|
||||
|
||||
}
|
||||
int retval = Double.compare(overallSimi, Double.valueOf(1));
|
||||
|
||||
if (retval >= 0) {
|
||||
try (Jedis jedis = outerPool.getResource()) {
|
||||
if (retval >= 0)
|
||||
{
|
||||
try (Jedis jedis = outerPool.getResource())
|
||||
{
|
||||
jedis.select(3);
|
||||
jedis.set(matchKey, "1");
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return true;
|
||||
// break;
|
||||
}
|
||||
}catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
errorPairs.add(pairName);
|
||||
if (pairName == null)
|
||||
return false;
|
||||
if (pairName == null) return false;
|
||||
log.debug("{} not comparable", pairName);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String getLevel(JedisPool innerPool)
|
||||
{
|
||||
HashMap<String, String> fileMap = new HashMap<String, String>();
|
||||
|
||||
public static String getLevel(JedisPool innerPool){
|
||||
|
||||
|
||||
HashMap<String, String> fileMap =new HashMap<String, String>();
|
||||
|
||||
try (Jedis inner = innerPool.getResource()) {
|
||||
while (!inner.ping().equals("PONG")){
|
||||
try (Jedis inner = innerPool.getResource())
|
||||
{
|
||||
while (!inner.ping().equals("PONG"))
|
||||
{
|
||||
log.info("wait");
|
||||
}
|
||||
|
||||
inner.select(1);
|
||||
String level = inner.get("level");
|
||||
|
||||
switch (level){
|
||||
switch (level)
|
||||
{
|
||||
case "l1":
|
||||
return "single";
|
||||
case "l2":
|
||||
@@ -268,47 +172,29 @@ public class CompareTrees {
|
||||
default:
|
||||
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>();
|
||||
|
||||
|
||||
HashMap<String, String> fileMap =new HashMap<String, String>();
|
||||
|
||||
try (Jedis inner = innerPool.getResource()) {
|
||||
while (!inner.ping().equals("PONG")){
|
||||
try (Jedis inner = innerPool.getResource())
|
||||
{
|
||||
while (!inner.ping().equals("PONG"))
|
||||
{
|
||||
log.info("wait");
|
||||
}
|
||||
|
||||
inner.select(1);
|
||||
Map<String, String> filenames = inner.hgetAll("filenames");
|
||||
|
||||
|
||||
for (Map.Entry<String, String> stringStringEntry : filenames.entrySet().stream().collect(Collectors.toList())) {
|
||||
fileMap.put(stringStringEntry.getKey(),stringStringEntry.getValue());
|
||||
for (Map.Entry<String, String> stringStringEntry : filenames.entrySet().stream().collect(Collectors.toList()))
|
||||
{
|
||||
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;
|
||||
|
||||
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.utils.CallShell;
|
||||
import edu.lu.uni.serval.utils.FileHelper;
|
||||
import edu.lu.uni.serval.utils.PoolBuilder;
|
||||
import me.tongfei.progressbar.ProgressBar;
|
||||
import org.slf4j.Logger;
|
||||
@@ -25,7 +25,7 @@ import java.util.stream.Stream;
|
||||
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,
|
||||
String[] projectList, String patchSize, String projectType, String srcPath) throws Exception
|
||||
@@ -35,19 +35,12 @@ public class EnhancedASTDiff
|
||||
|
||||
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 = "bash " + dbDir + "/" + "startServer.sh" + " %s %s %s";
|
||||
|
||||
// cmd = String.format(cmd, dbDir, chunkName, Integer.valueOf(redisPort));
|
||||
|
||||
cs.runShell(cmd, redisPort);
|
||||
CallShell.runShell(cmd, redisPort);
|
||||
|
||||
JedisPool innerPool = new JedisPool(PoolBuilder.getPoolConfig(), "127.0.0.1", Integer.valueOf(redisPort), 20000000);
|
||||
|
||||
boolean isJava = false;
|
||||
if (projectType.equals("java"))
|
||||
{
|
||||
isJava = true;
|
||||
}
|
||||
boolean isJava = projectType.equals("java");
|
||||
File folder = new File(inputPath);
|
||||
File[] listOfFiles = folder.listFiles();
|
||||
if (listOfFiles == null)
|
||||
@@ -80,22 +73,17 @@ public class EnhancedASTDiff
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
String project = folder.getName();
|
||||
List<MessageFile> allMessageFiles = new ArrayList<>();
|
||||
for (File target : folders)
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (msgFiles == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
allMessageFiles.addAll(msgFiles);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Map<String, String> diffEntry;
|
||||
@@ -112,24 +100,12 @@ public class EnhancedASTDiff
|
||||
log.info("{} files to process ...", allMessageFiles.size());
|
||||
}
|
||||
boolean finalIsJava = isJava;
|
||||
ProgressBar.wrap(allMessageFiles.stream().
|
||||
parallel(), "Task").
|
||||
forEach(m ->
|
||||
ProgressBar.wrap(allMessageFiles.stream().parallel(), "Task").forEach(m ->
|
||||
{
|
||||
EDiffHunkParser parser = new EDiffHunkParser();
|
||||
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();
|
||||
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<>();
|
||||
for (File revFile : revFiles)
|
||||
{
|
||||
// for (File revFile : collect) {
|
||||
String fileName = revFile.getName();
|
||||
File prevFile = new File(gumTreeInput + "prevFiles/prev_" + fileName);// previous file
|
||||
// if (isJava){
|
||||
// fileName = fileName.replace(".java",".txt");
|
||||
// }else{
|
||||
// fileName = fileName + ".txt";
|
||||
// }
|
||||
File prevFile = new File(gumTreeInput + "prevFiles/prev_" + fileName); // previous file
|
||||
fileName = fileName + ".txt";
|
||||
File diffentryFile = new File(gumTreeInput + "DiffEntries/" + fileName); // DiffEntry file
|
||||
String s = FileHelper.readFile(diffentryFile);
|
||||
@@ -161,19 +129,11 @@ public class EnhancedASTDiff
|
||||
Pattern pattern = Pattern.compile("^[\\+|\\-]\\s*", Pattern.MULTILINE);
|
||||
Matcher matcher = pattern.matcher(s);
|
||||
int count = 0;
|
||||
while (matcher.find())
|
||||
{
|
||||
count++;
|
||||
}
|
||||
if (count >= Integer.valueOf(patchSize))
|
||||
// if(count>201)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// if(FileHelper.readFile(diffentryFile).split("@@\\s\\-\\d+,*\\d*\\s\\+\\d+,*\\d*\\s@@").length > 2)
|
||||
// continue;
|
||||
|
||||
// String datasetName = project;
|
||||
while (matcher.find())
|
||||
{
|
||||
count++;
|
||||
}
|
||||
if (count >= Integer.valueOf(patchSize)) continue;
|
||||
String[] split1 = diffentryFile.getParent().split(datasetName);
|
||||
String root = split1[0];
|
||||
String pj = split1[1].split("/")[1];
|
||||
@@ -181,16 +141,10 @@ public class EnhancedASTDiff
|
||||
MessageFile msgFile = new MessageFile(revFile, prevFile, diffentryFile, pj);
|
||||
|
||||
msgFiles.add(msgFile);
|
||||
|
||||
}
|
||||
|
||||
return msgFiles;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,114 +3,114 @@ package edu.lu.uni.serval.utils;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ASTNodeMap {
|
||||
|
||||
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");
|
||||
public class ASTNodeMap
|
||||
{
|
||||
public static Map<Integer, String> map;
|
||||
|
||||
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(101,"Update");
|
||||
map.put(102,"Delete");
|
||||
map.put(103,"Move");
|
||||
map.put(104,"NoChange");
|
||||
}
|
||||
map.put(100, "Insert");
|
||||
map.put(101, "Update");
|
||||
map.put(102, "Delete");
|
||||
map.put(103, "Move");
|
||||
map.put(104, "NoChange");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package edu.lu.uni.serval.utils;
|
||||
|
||||
/**
|
||||
* Created by anilkoyuncu on 17/04/2018.
|
||||
*/
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -12,109 +8,83 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class CallShell {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CallShell.class);
|
||||
|
||||
|
||||
|
||||
public void runShell(String command) throws Exception {
|
||||
/**
|
||||
* Created by anilkoyuncu on 17/04/2018.
|
||||
*/
|
||||
public class CallShell
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(CallShell.class);
|
||||
|
||||
public void runShell(String command) throws Exception
|
||||
{
|
||||
Process process = Runtime.getRuntime().exec(command);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||
process.getInputStream()));
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String s;
|
||||
while ((s = reader.readLine()) != null) {
|
||||
while ((s = reader.readLine()) != null)
|
||||
{
|
||||
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);
|
||||
|
||||
Process process = Runtime.getRuntime().exec(command);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||
process.getInputStream()));
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String s;
|
||||
while ((s = reader.readLine()) != null) {
|
||||
// System.out.println("Script output: " + s);
|
||||
while ((s = reader.readLine()) != null)
|
||||
{
|
||||
log.trace("Script output: " + s);
|
||||
}
|
||||
// Thread.sleep(Integer.valueOf(serverWait));
|
||||
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void runPing(String command) throws Exception {
|
||||
try{
|
||||
StringBuffer output = new StringBuffer();
|
||||
Process process = Runtime.getRuntime().exec(command);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||
process.getInputStream()));
|
||||
String s;
|
||||
public static void runPing(String command) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
StringBuffer output = new StringBuffer();
|
||||
Process process = Runtime.getRuntime().exec(command);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String s;
|
||||
|
||||
BufferedReader stdError = new BufferedReader(new
|
||||
InputStreamReader(process.getErrorStream()));
|
||||
BufferedReader stdError = new BufferedReader(new 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();
|
||||
|
||||
if(s !=null && s.equals("PONG")){
|
||||
// System.out.println(s);
|
||||
if (s != null && s.equals("PONG"))
|
||||
{
|
||||
log.trace(s);
|
||||
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
String e;
|
||||
if((e = stdError.readLine()) == null) {
|
||||
if ((e = stdError.readLine()) == null)
|
||||
{
|
||||
TimeUnit.MINUTES.sleep(1);
|
||||
|
||||
runPing(command);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
TimeUnit.MINUTES.sleep(1);
|
||||
System.out.println(e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// System.out.println(s);
|
||||
// }
|
||||
// read any errors from the attempted command
|
||||
// System.out.println("Here is the standard error of the command (if any):\n");
|
||||
while ((s = stdError.readLine()) != null) {
|
||||
System.out.print(s);
|
||||
while ((s = stdError.readLine()) != null)
|
||||
System.out.print(s);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
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;
|
||||
|
||||
|
||||
public class ClusterToPattern {
|
||||
private static Logger log = LoggerFactory.getLogger(ClusterToPattern.class);
|
||||
public class ClusterToPattern
|
||||
{
|
||||
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();
|
||||
String cmd = "bash "+redisPath + "/" + "startServer.sh" +" %s %s %s";
|
||||
cmd = String.format(cmd, redisPath,dumpsName,Integer.valueOf(port));
|
||||
String cmd = "bash " + redisPath + "/" + "startServer.sh" + " %s %s %s";
|
||||
cmd = String.format(cmd, redisPath, dumpsName, Integer.valueOf(port));
|
||||
log.trace(cmd);
|
||||
cs.runShell(cmd, port);
|
||||
CallShell.runShell(cmd, port);
|
||||
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);
|
||||
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()) {
|
||||
while (!outer.ping().equals("PONG")) {
|
||||
try (Jedis outer = outerPool.getResource())
|
||||
{
|
||||
while (!outer.ping().equals("PONG"))
|
||||
{
|
||||
log.info("wait");
|
||||
}
|
||||
// byte[] s = outer.hget("dump".getBytes(), filename.getBytes());
|
||||
// HierarchicalActionSet actionSet = (HierarchicalActionSet) EDiffHelper.kryoDeseerialize(s);
|
||||
// if (actionSet == null){
|
||||
// throw new Error(filename +" not found");
|
||||
// }
|
||||
String s1 = outer.hget("dump",filename);
|
||||
// outer.close();
|
||||
// byte[] s = outer.hget("dump".getBytes(), filename.getBytes());
|
||||
// HierarchicalActionSet actionSet = (HierarchicalActionSet) EDiffHelper.kryoDeseerialize(s);
|
||||
// if (actionSet == null){
|
||||
// throw new Error(filename +" not found");
|
||||
// }
|
||||
String s1 = outer.hget("dump", filename);
|
||||
// outer.close();
|
||||
return s1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,104 +1,138 @@
|
||||
package edu.lu.uni.serval.utils;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FileHelper {
|
||||
public class FileHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* @param filePath
|
||||
*/
|
||||
public static void createDirectory(String filePath) {
|
||||
public static void createDirectory(String filePath)
|
||||
{
|
||||
File file = new File(filePath);
|
||||
if (file.exists()) {
|
||||
if (file.exists())
|
||||
{
|
||||
deleteDirectory(filePath);
|
||||
}
|
||||
file.mkdirs();
|
||||
}
|
||||
|
||||
public static void createFile(File file, String content) {
|
||||
public static void createFile(File file, String content)
|
||||
{
|
||||
FileWriter writer = null;
|
||||
BufferedWriter bw = null;
|
||||
|
||||
try {
|
||||
if (!file.getParentFile().exists()) {
|
||||
try
|
||||
{
|
||||
if (!file.getParentFile().exists())
|
||||
{
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
if (!file.exists()) file.createNewFile();
|
||||
if (!file.exists())
|
||||
{
|
||||
file.createNewFile();
|
||||
}
|
||||
writer = new FileWriter(file);
|
||||
bw = new BufferedWriter(writer);
|
||||
bw.write(content);
|
||||
bw.flush();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
}
|
||||
finally
|
||||
{
|
||||
close(bw);
|
||||
close(writer);
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteDirectory(String dir) {
|
||||
public static void deleteDirectory(String dir)
|
||||
{
|
||||
File file = new File(dir);
|
||||
|
||||
if (file.exists()) {
|
||||
if (file.isDirectory()) {
|
||||
if (file.exists())
|
||||
{
|
||||
if (file.isDirectory())
|
||||
{
|
||||
File[] files = file.listFiles();
|
||||
if (files.length > 0) {
|
||||
for (File f : files) {
|
||||
if (f.isFile()) {
|
||||
if (files.length > 0)
|
||||
{
|
||||
for (File f : files)
|
||||
{
|
||||
if (f.isFile())
|
||||
{
|
||||
deleteFile(f.getAbsolutePath());
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
deleteDirectory(f.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
file.delete();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
deleteFile(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteFiles(String dir) {
|
||||
public static void deleteFiles(String dir)
|
||||
{
|
||||
File file = new File(dir);
|
||||
|
||||
if (file.exists()) {
|
||||
if (file.isDirectory()) {
|
||||
if (file.exists())
|
||||
{
|
||||
if (file.isDirectory())
|
||||
{
|
||||
File[] files = file.listFiles();
|
||||
if (files.length > 0) {
|
||||
for (File f : files) {
|
||||
if (f.isFile()) {
|
||||
if (files.length > 0)
|
||||
{
|
||||
for (File f : files)
|
||||
{
|
||||
if (f.isFile())
|
||||
{
|
||||
deleteFile(f.getAbsolutePath());
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
deleteFiles(f.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
deleteFile(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteFile(String fileName) {
|
||||
public static void deleteFile(String fileName)
|
||||
{
|
||||
File file = new File(fileName);
|
||||
|
||||
if (file.exists()) {
|
||||
if (file.isFile()) {
|
||||
if (file.exists())
|
||||
{
|
||||
if (file.isFile())
|
||||
{
|
||||
file.delete();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
deleteDirectory(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<File> getAllDirectories(String filePath) {
|
||||
public static List<File> getAllDirectories(String filePath)
|
||||
{
|
||||
return listAllDirectories(new File(filePath));
|
||||
}
|
||||
|
||||
@@ -109,26 +143,33 @@ public class FileHelper {
|
||||
* @param type
|
||||
* @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);
|
||||
}
|
||||
|
||||
public static List<File> getAllFilesInCurrentDiectory(String filePath, String type) {
|
||||
public static List<File> getAllFilesInCurrentDiectory(String filePath, String 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<>();
|
||||
|
||||
if (!directory.exists()) {
|
||||
if (!directory.exists())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
File[] files = directory.listFiles();
|
||||
|
||||
for (File file : files) {
|
||||
if (file.isFile()) {
|
||||
if (file.toString().endsWith(type)) {
|
||||
for (File file : files)
|
||||
{
|
||||
if (file.isFile())
|
||||
{
|
||||
if (file.toString().endsWith(type))
|
||||
{
|
||||
fileList.add(file);
|
||||
}
|
||||
}
|
||||
@@ -137,36 +178,47 @@ public class FileHelper {
|
||||
return fileList;
|
||||
}
|
||||
|
||||
public static String getFileName(String filePath) {
|
||||
public static String getFileName(String filePath)
|
||||
{
|
||||
File file = new File(filePath);
|
||||
|
||||
if (file.exists()) {
|
||||
if (file.exists())
|
||||
{
|
||||
return file.getName();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFileNameWithoutExtension(File file) {
|
||||
if (file.exists()) {
|
||||
public static String getFileNameWithoutExtension(File file)
|
||||
{
|
||||
if (file.exists())
|
||||
{
|
||||
String fileName = file.getName();
|
||||
fileName = fileName.substring(0, fileName.lastIndexOf("."));
|
||||
return fileName;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFileExtension(File file) {
|
||||
public static String getFileExtension(File file)
|
||||
{
|
||||
String fileName = file.getName();
|
||||
String extension = fileName.substring(fileName.lastIndexOf("."));
|
||||
return extension;
|
||||
}
|
||||
|
||||
public static String getFileParentPath(String filePath) {
|
||||
public static String getFileParentPath(String filePath)
|
||||
{
|
||||
File file = new File(filePath);
|
||||
|
||||
if (file.exists()) {
|
||||
if (file.exists())
|
||||
{
|
||||
return file.getParent() + "/";
|
||||
}
|
||||
return "";
|
||||
@@ -176,17 +228,13 @@ public class FileHelper {
|
||||
* Check whether a file path is valid or not.
|
||||
*
|
||||
* @param path, file path.
|
||||
* @return true, the file path is valid.
|
||||
* false, the file path is invalid.
|
||||
* @return true, the file path is valid. false, the file path is invalid.
|
||||
*/
|
||||
public static boolean isValidPath(String path) {
|
||||
public static boolean isValidPath(String path)
|
||||
{
|
||||
File file = new File(path);
|
||||
|
||||
if (file.exists()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,23 +243,31 @@ public class FileHelper {
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
private static List<File> listAllFiles(File file, String type) {
|
||||
private static List<File> listAllFiles(File file, String type)
|
||||
{
|
||||
List<File> fileList = new ArrayList<>();
|
||||
|
||||
if (!file.exists()) {
|
||||
if (!file.exists())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
File[] files = file.listFiles();
|
||||
|
||||
for (File f : files) {
|
||||
if (f.isFile()) {
|
||||
if (f.toString().endsWith(type)) {
|
||||
for (File f : files)
|
||||
{
|
||||
if (f.isFile())
|
||||
{
|
||||
if (f.toString().endsWith(type))
|
||||
{
|
||||
fileList.add(f);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
List<File> fl = listAllFiles(f, type);
|
||||
if (fl != null && fl.size() > 0) {
|
||||
if (fl != null && fl.size() > 0)
|
||||
{
|
||||
fileList.addAll(fl);
|
||||
}
|
||||
}
|
||||
@@ -226,13 +282,16 @@ public class FileHelper {
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
private static List<File> listAllDirectories(File file) {
|
||||
private static List<File> listAllDirectories(File file)
|
||||
{
|
||||
List<File> fileList = new ArrayList<>();
|
||||
|
||||
File[] files = file.listFiles();
|
||||
|
||||
for (File f : files) {
|
||||
if (f.isDirectory()) {
|
||||
for (File f : files)
|
||||
{
|
||||
if (f.isDirectory())
|
||||
{
|
||||
fileList.add(f);
|
||||
fileList.addAll(listAllDirectories(f));
|
||||
}
|
||||
@@ -241,10 +300,12 @@ public class FileHelper {
|
||||
return fileList;
|
||||
}
|
||||
|
||||
public static void makeDirectory(String fileName) {
|
||||
public static void makeDirectory(String fileName)
|
||||
{
|
||||
deleteFile(fileName);
|
||||
File file = new File(fileName).getParentFile();
|
||||
if (!file.exists()) {
|
||||
if (!file.exists())
|
||||
{
|
||||
file.mkdirs();
|
||||
}
|
||||
}
|
||||
@@ -255,7 +316,8 @@ public class FileHelper {
|
||||
* @param fileName
|
||||
* @return String, the content of a file.
|
||||
*/
|
||||
public static String readFile(String fileName) {
|
||||
public static String readFile(String fileName)
|
||||
{
|
||||
return readFile(new File(fileName));
|
||||
}
|
||||
|
||||
@@ -265,26 +327,35 @@ public class FileHelper {
|
||||
* @param file
|
||||
* @return String, the content of a file.
|
||||
*/
|
||||
public static String readFile(File file) {
|
||||
public static String readFile(File file)
|
||||
{
|
||||
byte[] input = null;
|
||||
BufferedInputStream bis = null;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
|
||||
bis = new BufferedInputStream(new FileInputStream(file));
|
||||
input = new byte[bis.available()];
|
||||
bis.read(input);
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
}
|
||||
finally
|
||||
{
|
||||
close(bis);
|
||||
}
|
||||
|
||||
String sourceCode = null;
|
||||
if (input != null) {
|
||||
if (input != null)
|
||||
{
|
||||
sourceCode = new String(input);
|
||||
}
|
||||
|
||||
@@ -295,89 +366,119 @@ public class FileHelper {
|
||||
* Output output into a file.
|
||||
*
|
||||
* @param fileName, output file name.
|
||||
* @param data, output data.
|
||||
* @param append, the output data will be appended previous data in the file or not.
|
||||
* @param data, output data.
|
||||
* @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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
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;
|
||||
BufferedWriter bw = null;
|
||||
|
||||
try {
|
||||
if (!file.getParentFile().exists()) {
|
||||
try
|
||||
{
|
||||
if (!file.getParentFile().exists())
|
||||
{
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
if (!file.exists()) {
|
||||
if (!file.exists())
|
||||
{
|
||||
file.createNewFile();
|
||||
}
|
||||
writer = new FileWriter(file, append);
|
||||
bw = new BufferedWriter(writer);
|
||||
bw.write(data);
|
||||
bw.flush();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
}
|
||||
finally
|
||||
{
|
||||
close(bw);
|
||||
close(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private static void close(FileWriter writer) {
|
||||
try {
|
||||
if (writer != null) {
|
||||
private static void close(FileWriter writer)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (writer != null)
|
||||
{
|
||||
writer.close();
|
||||
writer = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void close(BufferedWriter bw) {
|
||||
try {
|
||||
if (bw != null) {
|
||||
private static void close(BufferedWriter bw)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (bw != null)
|
||||
{
|
||||
bw.close();
|
||||
bw = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void close(BufferedInputStream bis) {
|
||||
try {
|
||||
if (bis != null) {
|
||||
private static void close(BufferedInputStream bis)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (bis != null)
|
||||
{
|
||||
bis.close();
|
||||
bis = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<File> getAllSubDirectories(String fileName) {
|
||||
public static List<File> getAllSubDirectories(String fileName)
|
||||
{
|
||||
File file = new File(fileName);
|
||||
List<File> subDirectories = new ArrayList<>();
|
||||
if (file.exists()) {
|
||||
if (file.exists())
|
||||
{
|
||||
File[] files = file.listFiles();
|
||||
for (File f : files) {
|
||||
if (f.isDirectory()) {
|
||||
for (File f : files)
|
||||
{
|
||||
if (f.isDirectory())
|
||||
{
|
||||
subDirectories.add(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
return subDirectories;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,41 +5,53 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
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.addAll(list);
|
||||
}
|
||||
|
||||
public List<T> getList() {
|
||||
public List<T> getList()
|
||||
{
|
||||
return this.list;
|
||||
}
|
||||
|
||||
public List<T> sortAscending() {
|
||||
try {
|
||||
if (list != null && list.size() > 0) {
|
||||
Collections.sort(this.list, new Comparator<T>() {
|
||||
public List<T> sortAscending()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (list != null && list.size() > 0)
|
||||
{
|
||||
Collections.sort(this.list, new Comparator<T>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public int compare(T t1, T t2) {
|
||||
public int compare(T t1, T t2)
|
||||
{
|
||||
return t1.compareTo(t2);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return this.list;
|
||||
}
|
||||
|
||||
public List<T> sortDescending() {
|
||||
if (list != null && list.size() > 0) {
|
||||
public List<T> sortDescending()
|
||||
{
|
||||
if (list != null && list.size() > 0)
|
||||
{
|
||||
Collections.sort(this.list, Collections.reverseOrder());
|
||||
}
|
||||
return this.list;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,25 +7,25 @@ import java.time.Duration;
|
||||
/**
|
||||
* Created by anilkoyuncu on 17/09/2018.
|
||||
*/
|
||||
public class PoolBuilder {
|
||||
public static JedisPoolConfig getPoolConfig() {
|
||||
public class PoolBuilder
|
||||
{
|
||||
public static JedisPoolConfig getPoolConfig()
|
||||
{
|
||||
return poolConfig;
|
||||
}
|
||||
|
||||
static final JedisPoolConfig poolConfig = buildPoolConfig();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private static JedisPoolConfig buildPoolConfig() {
|
||||
private static JedisPoolConfig buildPoolConfig()
|
||||
{
|
||||
final JedisPoolConfig poolConfig = new JedisPoolConfig();
|
||||
poolConfig.setMaxTotal(1024);
|
||||
poolConfig.setMaxIdle(1024);
|
||||
// poolConfig.setMinIdle(16);
|
||||
// poolConfig.setTestOnBorrow(true);
|
||||
// poolConfig.setTestOnReturn(true);
|
||||
// poolConfig.setTestWhileIdle(true);
|
||||
// poolConfig.setMinIdle(16);
|
||||
// poolConfig.setTestOnBorrow(true);
|
||||
// poolConfig.setTestOnReturn(true);
|
||||
// poolConfig.setTestWhileIdle(true);
|
||||
poolConfig.setMinEvictableIdleTimeMillis(Duration.ofMinutes(60).toMillis());
|
||||
poolConfig.setTimeBetweenEvictionRunsMillis(Duration.ofHours(30).toMillis());
|
||||
poolConfig.setNumTestsPerEvictionRun(3);
|
||||
|
||||
Reference in New Issue
Block a user