[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,28 +10,35 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EDiffActor extends UntypedActor {
|
||||
public class EDiffActor extends UntypedActor
|
||||
{
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(EDiffActor.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(EDiffActor.class);
|
||||
|
||||
private final ActorRef mineRouter;
|
||||
|
||||
private ActorRef mineRouter;
|
||||
private final int numberOfWorkers;
|
||||
|
||||
private int counter = 0;
|
||||
|
||||
public EDiffActor(int numberOfWorkers, String project) {
|
||||
public EDiffActor(int numberOfWorkers, String project)
|
||||
{
|
||||
mineRouter = this.getContext().actorOf(new RoundRobinPool(numberOfWorkers)
|
||||
.props(EDiffWorker.props(project)), "mine-fix-pattern-router");
|
||||
this.numberOfWorkers = numberOfWorkers;
|
||||
}
|
||||
|
||||
public static Props props(final int numberOfWorkers, final String project) {
|
||||
public static Props props(final int numberOfWorkers, final String project)
|
||||
{
|
||||
|
||||
return Props.create(new Creator<EDiffActor>() {
|
||||
return Props.create(new Creator<EDiffActor>()
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 9207427376110704705L;
|
||||
|
||||
@Override
|
||||
public EDiffActor create() throws Exception {
|
||||
public EDiffActor create() throws Exception
|
||||
{
|
||||
return new EDiffActor(numberOfWorkers, project);
|
||||
}
|
||||
|
||||
@@ -40,34 +47,45 @@ public class EDiffActor extends UntypedActor {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onReceive(Object message) throws Exception {
|
||||
if (message instanceof EDiffMessage) {
|
||||
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 ++) {
|
||||
for (int i = 0; i < numberOfWorkers; i++)
|
||||
{
|
||||
int fromIndex = i * average + counter;
|
||||
if (counter < reminder) 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());
|
||||
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());
|
||||
logger.info("Assign {} task to worker #" + (i + 1), filesOfWorkers.size());
|
||||
}
|
||||
} else if ("STOP".equals(message.toString())) {
|
||||
counter ++;
|
||||
}
|
||||
else if ("STOP".equals(message.toString()))
|
||||
{
|
||||
counter++;
|
||||
logger.info(counter + " workers finalized their work...");
|
||||
if (counter >= numberOfWorkers) {
|
||||
if (counter >= numberOfWorkers)
|
||||
{
|
||||
logger.info("All workers finalized their work...");
|
||||
this.getContext().stop(mineRouter);
|
||||
this.getContext().stop(getSelf());
|
||||
this.getContext().system().shutdown();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
unhandled(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,19 +11,21 @@ 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 final Logger logger = LoggerFactory.getLogger(EDiffHunkParser.class);
|
||||
|
||||
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 {
|
||||
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];
|
||||
@@ -32,40 +34,45 @@ public class EDiffHunkParser extends EDiffParser {
|
||||
|
||||
List<HierarchicalActionSet> actionSets = parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath, isJava);
|
||||
|
||||
if (actionSets != null && actionSets.size() != 0) {
|
||||
if (actionSets != null && actionSets.size() != 0)
|
||||
{
|
||||
|
||||
boolean processActionSet = true;
|
||||
|
||||
if (actionSets.size() > Integer.valueOf(hunkLimit)) {
|
||||
if (actionSets.size() > Integer.valueOf(hunkLimit))
|
||||
{
|
||||
processActionSet = false;
|
||||
logger.debug("Skipping {} set size {}", diffentryFile.getName(), hunkLimit);
|
||||
}
|
||||
|
||||
int hunkSet = 0;
|
||||
if (processActionSet) {
|
||||
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)){
|
||||
//
|
||||
// }
|
||||
// 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);
|
||||
ITree tokenTree = EDiffHelper.getTokenTree(actionSet, isJava);
|
||||
String tokens = EDiffHelper.getNames2(tokenTree);
|
||||
// EDiffHelper.getTokenTree(actionSet, parent, children, tc);
|
||||
try (Jedis inner = innerPool.getResource()) {
|
||||
// EDiffHelper.getTokenTree(actionSet, parent, children, tc);
|
||||
try (Jedis inner = innerPool.getResource())
|
||||
{
|
||||
|
||||
inner.hset("dump", key, actionSet.toString());
|
||||
inner.hset(key, "actionTree", actionTree.toStaticHashString());
|
||||
@@ -73,39 +80,41 @@ public class EDiffHunkParser extends EDiffParser {
|
||||
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();
|
||||
// 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();
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// logger.error("error", e);
|
||||
//// e.printStackTrace();
|
||||
// }
|
||||
hunkSet++;
|
||||
}
|
||||
try (Jedis inner = innerPool.getResource()) {
|
||||
try (Jedis inner = innerPool.getResource())
|
||||
{
|
||||
inner.hset("diffEntry", pj + "_" + diffentryFile.getName(), "1");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.error("error", e);
|
||||
// e.printStackTrace();
|
||||
// e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,62 +4,69 @@ 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() {
|
||||
public JedisPool getInnerPool()
|
||||
{
|
||||
return innerPool;
|
||||
}
|
||||
|
||||
public void setInnerPool(JedisPool innerPool) {
|
||||
public void setInnerPool(JedisPool innerPool)
|
||||
{
|
||||
this.innerPool = innerPool;
|
||||
}
|
||||
|
||||
private JedisPool innerPool;
|
||||
|
||||
public String getSrcMLPath() {
|
||||
public String getSrcMLPath()
|
||||
{
|
||||
return srcMLPath;
|
||||
}
|
||||
|
||||
private String srcMLPath;
|
||||
|
||||
public String getRootType() {
|
||||
public String getRootType()
|
||||
{
|
||||
return rootType;
|
||||
}
|
||||
|
||||
private String rootType;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public EDiffMessage(int id, List<MessageFile> msgFiles,String eDiffTimeout,JedisPool pool,String srcMLPath,String rootType) {
|
||||
super(id,new Long(eDiffTimeout));
|
||||
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);
|
||||
|
||||
public EDiffMessage(int id, List<MessageFile> msgFiles, Long eDiffTimeout, JedisPool pool)
|
||||
{
|
||||
super(id, eDiffTimeout);
|
||||
this.msgFiles = msgFiles;
|
||||
this.innerPool = pool;
|
||||
}
|
||||
|
||||
|
||||
public EDiffMessage(int id, List<MessageFile> filesOfWorkers, long seconds_to_wait, JedisPool innerPool, String srcMLPath,String rootType) {
|
||||
public EDiffMessage(int id, List<MessageFile> filesOfWorkers, long seconds_to_wait, JedisPool innerPool, String srcMLPath, String rootType)
|
||||
{
|
||||
|
||||
super(id,seconds_to_wait);
|
||||
super(id, seconds_to_wait);
|
||||
this.msgFiles = filesOfWorkers;
|
||||
this.innerPool = innerPool;
|
||||
this.srcMLPath = srcMLPath;
|
||||
this.rootType = rootType;
|
||||
}
|
||||
|
||||
public List<MessageFile> getMsgFiles() {
|
||||
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,9 +16,9 @@ import java.util.List;
|
||||
* Parse fix patterns with GumTree.
|
||||
*
|
||||
* @author kui.liu
|
||||
*
|
||||
*/
|
||||
public class EDiffParser extends Parser {
|
||||
public class EDiffParser extends Parser
|
||||
{
|
||||
|
||||
/*
|
||||
* ResultType:
|
||||
@@ -33,7 +31,6 @@ public class EDiffParser extends Parser {
|
||||
public int resultType = 0;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Regroup GumTree results without remove the modification of variable names.
|
||||
*
|
||||
@@ -41,37 +38,50 @@ public class EDiffParser extends Parser {
|
||||
* @param revFile
|
||||
* @return
|
||||
*/
|
||||
public List<HierarchicalActionSet> parseChangedSourceCodeWithGumTree2(File prevFile, File revFile,String srcMLPath,boolean isJava) {
|
||||
public List<HierarchicalActionSet> parseChangedSourceCodeWithGumTree2(File prevFile, File revFile, String srcMLPath, boolean isJava)
|
||||
{
|
||||
List<HierarchicalActionSet> actionSets = new ArrayList<>();
|
||||
// GumTree results
|
||||
// boolean isJava =false;
|
||||
// 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);
|
||||
if (isJava)
|
||||
{
|
||||
// if (revFile.getName().endsWith(".c") & prevFile.getName().endsWith(".c") || revFile.getName().endsWith(".h") & prevFile.getName().endsWith(".h")){
|
||||
// gumTreeResults = new GumTreeComparer().compareCFilesWithGumTree(prevFile, revFile);
|
||||
|
||||
gumTreeResults = new GumTreeComparer().compareTwoFilesWithGumTree(prevFile, revFile);
|
||||
|
||||
|
||||
}else{
|
||||
gumTreeResults = new GumTreeCComparer().compareCFilesWithGumTree(prevFile, revFile,srcMLPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
gumTreeResults = new GumTreeCComparer().compareCFilesWithGumTree(prevFile, revFile, srcMLPath);
|
||||
|
||||
}
|
||||
if (gumTreeResults == null) {
|
||||
if (gumTreeResults == null)
|
||||
{
|
||||
this.resultType = 1;
|
||||
return actionSets;
|
||||
} else if (gumTreeResults.size() == 0){
|
||||
}
|
||||
else if (gumTreeResults.size() == 0)
|
||||
{
|
||||
this.resultType = 2;
|
||||
return actionSets;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// Regroup GumTre results.
|
||||
List<HierarchicalActionSet> allActionSets = null;
|
||||
if (isJava){
|
||||
if (isJava)
|
||||
{
|
||||
allActionSets = new HierarchicalRegrouper().regroupGumTreeResults(gumTreeResults);
|
||||
}else{
|
||||
HashSet<Integer> removeType = new HashSet<Integer>(Arrays.asList(131,132,133,134,135,136,137));
|
||||
}
|
||||
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){
|
||||
if (b)
|
||||
{
|
||||
return actionSets;
|
||||
}
|
||||
allActionSets = new HierarchicalRegrouperForC().regroupGumTreeResults(gumTreeResults);
|
||||
@@ -81,7 +91,8 @@ public class EDiffParser extends Parser {
|
||||
ListSorter<HierarchicalActionSet> sorter = new ListSorter<>(allActionSets);
|
||||
actionSets = sorter.sortAscending();
|
||||
|
||||
if (actionSets.size() == 0) {
|
||||
if (actionSets.size() == 0)
|
||||
{
|
||||
this.resultType = 3;
|
||||
}
|
||||
|
||||
@@ -90,15 +101,15 @@ public class EDiffParser extends Parser {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseFixPatterns(File prevFile, File revFile, File diffEntryFile, String project, JedisPool innerPool, String srcMLPath,String rootType,boolean isJava) {
|
||||
public void parseFixPatterns(File prevFile, File revFile, File diffEntryFile, String project, JedisPool innerPool, String srcMLPath, String rootType, boolean isJava)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void parseFixPatterns(File prevFile, File revFile, File diffEntryFile, String project, JedisPool innerPool) {
|
||||
//
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public void parseFixPatterns(File prevFile, File revFile, File diffEntryFile, String project, JedisPool innerPool) {
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -11,23 +11,28 @@ 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);
|
||||
public class EDiffWorker extends UntypedActor
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(EDiffActor.class);
|
||||
|
||||
private String project;
|
||||
private final String project;
|
||||
|
||||
|
||||
public EDiffWorker(String project) {
|
||||
public EDiffWorker(String project)
|
||||
{
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public static Props props(final String project) {
|
||||
return Props.create(new Creator<EDiffWorker>() {
|
||||
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 {
|
||||
public EDiffWorker create() throws Exception
|
||||
{
|
||||
return new EDiffWorker(project);
|
||||
}
|
||||
|
||||
@@ -35,8 +40,10 @@ public class EDiffWorker extends UntypedActor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Object message) throws Exception {
|
||||
if (message instanceof EDiffMessage) {
|
||||
public void onReceive(Object message) throws Exception
|
||||
{
|
||||
if (message instanceof EDiffMessage)
|
||||
{
|
||||
EDiffMessage msg = (EDiffMessage) message;
|
||||
List<MessageFile> files = msg.getMsgFiles();
|
||||
|
||||
@@ -46,45 +53,57 @@ public class EDiffWorker extends UntypedActor {
|
||||
String srcMLPath = msg.getSrcMLPath();
|
||||
String rootType = msg.getRootType();
|
||||
|
||||
for (MessageFile msgFile : files) {
|
||||
for (MessageFile msgFile : files)
|
||||
{
|
||||
File revFile = msgFile.getRevFile();
|
||||
File prevFile = msgFile.getPrevFile();
|
||||
File diffentryFile = msgFile.getDiffEntryFile();
|
||||
|
||||
|
||||
|
||||
EDiffHunkParser parser = new EDiffHunkParser();
|
||||
|
||||
final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
// schedule the work
|
||||
|
||||
|
||||
final Future<?> future = executor.submit(new RunnableParser(prevFile, revFile, diffentryFile, parser,project,msg.getInnerPool(),srcMLPath,rootType,false));
|
||||
try {
|
||||
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));
|
||||
counter++;
|
||||
if (counter % 1000 == 0)
|
||||
{
|
||||
log.info("Worker #" + id + " finalized parsing " + counter + " files... remaing " + (files.size() - counter));
|
||||
}
|
||||
} catch (TimeoutException e) {
|
||||
}
|
||||
catch (TimeoutException e)
|
||||
{
|
||||
future.cancel(true);
|
||||
System.err.println("#Timeout: " + revFile.getName());
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
System.err.println("#TimeInterrupted: " + revFile.getName());
|
||||
e.printStackTrace();
|
||||
} catch (ExecutionException e) {
|
||||
}
|
||||
catch (ExecutionException e)
|
||||
{
|
||||
System.err.println("#TimeAborted: " + revFile.getName());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
}
|
||||
finally
|
||||
{
|
||||
executor.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Worker #" + id + " finalized the work...");
|
||||
this.getSender().tell("STOP", getSelf());
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
unhandled(message);
|
||||
}
|
||||
}
|
||||
|
||||
+97
-44
@@ -11,82 +11,109 @@ import java.util.List;
|
||||
* Hierarchical-level results of GumTree results
|
||||
*
|
||||
* @author kui.liu
|
||||
*
|
||||
*/
|
||||
public class HierarchicalActionSet implements Comparable<HierarchicalActionSet>,Serializable {
|
||||
public class HierarchicalActionSet implements Comparable<HierarchicalActionSet>, Serializable
|
||||
{
|
||||
|
||||
private String astNodeType;
|
||||
|
||||
private Action action;
|
||||
|
||||
private Action parentAction;
|
||||
|
||||
private String actionString;
|
||||
|
||||
private Integer startPosition;
|
||||
|
||||
private Integer length;
|
||||
|
||||
private int bugStartLineNum = 0;
|
||||
|
||||
private int bugEndLineNum;
|
||||
|
||||
private int fixStartLineNum;
|
||||
|
||||
private int fixEndLineNum;
|
||||
|
||||
private HierarchicalActionSet parent = null;
|
||||
|
||||
private List<HierarchicalActionSet> subActions = new ArrayList<>();
|
||||
|
||||
private ITree node;
|
||||
// source code tree.
|
||||
|
||||
public int getBugEndPosition() {
|
||||
public int getBugEndPosition()
|
||||
{
|
||||
return bugEndPosition;
|
||||
}
|
||||
|
||||
public int getFixEndPosition() {
|
||||
public int getFixEndPosition()
|
||||
{
|
||||
return fixEndPosition;
|
||||
}
|
||||
|
||||
private int bugEndPosition;
|
||||
|
||||
private int fixEndPosition;
|
||||
|
||||
public ITree getNode() {
|
||||
public ITree getNode()
|
||||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
public void setNode(ITree node) {
|
||||
public void setNode(ITree node)
|
||||
{
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public void setAstNodeType(String astNodeType) {
|
||||
public void setAstNodeType(String astNodeType)
|
||||
{
|
||||
this.astNodeType = astNodeType;
|
||||
}
|
||||
|
||||
public String getAstNodeType() {
|
||||
public String getAstNodeType()
|
||||
{
|
||||
return astNodeType;
|
||||
}
|
||||
|
||||
public Action getAction() {
|
||||
public Action getAction()
|
||||
{
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(Action action) {
|
||||
public void setAction(Action action)
|
||||
{
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public Action getParentAction() {
|
||||
public Action getParentAction()
|
||||
{
|
||||
return parentAction;
|
||||
}
|
||||
|
||||
public void setParentAction(Action parentAction) {
|
||||
public void setParentAction(Action parentAction)
|
||||
{
|
||||
this.parentAction = parentAction;
|
||||
}
|
||||
|
||||
public String getActionString() {
|
||||
public String getActionString()
|
||||
{
|
||||
return actionString;
|
||||
}
|
||||
|
||||
public void setActionString(String actionString) {
|
||||
public void setActionString(String actionString)
|
||||
{
|
||||
this.actionString = actionString;
|
||||
|
||||
int atIndex = actionString.indexOf("@AT@") + 4;
|
||||
int lengthIndex = actionString.indexOf("@LENGTH@");
|
||||
if (lengthIndex == -1) {
|
||||
if (lengthIndex == -1)
|
||||
{
|
||||
this.startPosition = Integer.parseInt(actionString.substring(atIndex).trim());
|
||||
this.length = 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
this.startPosition = Integer.parseInt(actionString.substring(atIndex, lengthIndex).trim());
|
||||
this.length = Integer.parseInt(actionString.substring(lengthIndex + 8).trim());
|
||||
}
|
||||
@@ -96,111 +123,137 @@ public class HierarchicalActionSet implements Comparable<HierarchicalActionSet>,
|
||||
this.astNodeType = nodeType;
|
||||
}
|
||||
|
||||
public int getStartPosition() {
|
||||
public int getStartPosition()
|
||||
{
|
||||
return startPosition;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
public int getLength()
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
||||
public int getBugStartLineNum() {
|
||||
public int getBugStartLineNum()
|
||||
{
|
||||
return bugStartLineNum;
|
||||
}
|
||||
|
||||
public void setBugStartLineNum(int bugStartLineNum) {
|
||||
public void setBugStartLineNum(int bugStartLineNum)
|
||||
{
|
||||
this.bugStartLineNum = bugStartLineNum;
|
||||
}
|
||||
|
||||
public int getBugEndLineNum() {
|
||||
public int getBugEndLineNum()
|
||||
{
|
||||
return bugEndLineNum;
|
||||
}
|
||||
|
||||
public void setBugEndLineNum(int bugEndLineNum) {
|
||||
public void setBugEndLineNum(int bugEndLineNum)
|
||||
{
|
||||
this.bugEndLineNum = bugEndLineNum;
|
||||
}
|
||||
|
||||
public int getFixStartLineNum() {
|
||||
public int getFixStartLineNum()
|
||||
{
|
||||
return fixStartLineNum;
|
||||
}
|
||||
|
||||
public void setFixStartLineNum(int fixStartLineNum) {
|
||||
public void setFixStartLineNum(int fixStartLineNum)
|
||||
{
|
||||
this.fixStartLineNum = fixStartLineNum;
|
||||
}
|
||||
|
||||
public int getFixEndLineNum() {
|
||||
public int getFixEndLineNum()
|
||||
{
|
||||
return fixEndLineNum;
|
||||
}
|
||||
|
||||
public void setFixEndLineNum(int fixEndLineNum) {
|
||||
public void setFixEndLineNum(int fixEndLineNum)
|
||||
{
|
||||
this.fixEndLineNum = fixEndLineNum;
|
||||
}
|
||||
|
||||
public HierarchicalActionSet getParent() {
|
||||
public HierarchicalActionSet getParent()
|
||||
{
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(HierarchicalActionSet parent) {
|
||||
public void setParent(HierarchicalActionSet parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public List<HierarchicalActionSet> getSubActions() {
|
||||
public List<HierarchicalActionSet> getSubActions()
|
||||
{
|
||||
return subActions;
|
||||
}
|
||||
|
||||
public void setSubActions(List<HierarchicalActionSet> subActions) {
|
||||
public void setSubActions(List<HierarchicalActionSet> subActions)
|
||||
{
|
||||
this.subActions = subActions;
|
||||
}
|
||||
|
||||
|
||||
public void setBugEndPosition(int bugEndPosition) {
|
||||
public void setBugEndPosition(int bugEndPosition)
|
||||
{
|
||||
this.bugEndPosition = bugEndPosition;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setFixEndPosition(int fixEndPosition) {
|
||||
public void setFixEndPosition(int fixEndPosition)
|
||||
{
|
||||
this.fixEndPosition = fixEndPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(HierarchicalActionSet o) {
|
||||
public int compareTo(HierarchicalActionSet o)
|
||||
{
|
||||
|
||||
return this.startPosition.compareTo(o.startPosition);//this.action.compareTo(o.action);
|
||||
}
|
||||
|
||||
private List<String> strList = new ArrayList<>();
|
||||
private final List<String> strList = new ArrayList<>();
|
||||
|
||||
public int getActionSize(){
|
||||
public int getActionSize()
|
||||
{
|
||||
return strList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
public String toString()
|
||||
{
|
||||
String str = actionString;
|
||||
if (strList.size() == 0) {
|
||||
if (strList.size() == 0)
|
||||
{
|
||||
strList.add(str);
|
||||
for (HierarchicalActionSet actionSet : subActions) {
|
||||
for (HierarchicalActionSet actionSet : subActions)
|
||||
{
|
||||
actionSet.toString();
|
||||
List<String> strList1 = actionSet.strList;
|
||||
for (String str1 : strList1) {
|
||||
for (String str1 : strList1)
|
||||
{
|
||||
strList.add("---" + str1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
strList.clear();
|
||||
strList.add(str);
|
||||
for (HierarchicalActionSet actionSet : subActions) {
|
||||
for (HierarchicalActionSet actionSet : subActions)
|
||||
{
|
||||
actionSet.toString();
|
||||
List<String> strList1 = actionSet.strList;
|
||||
for (String str1 : strList1) {
|
||||
for (String str1 : strList1)
|
||||
{
|
||||
strList.add("---" + str1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
str = "";
|
||||
for (String str1 : strList) {
|
||||
for (String str1 : strList)
|
||||
{
|
||||
str += str1 + "\n";
|
||||
}
|
||||
|
||||
|
||||
+174
-103
@@ -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;
|
||||
@@ -15,11 +14,12 @@ import java.util.stream.Collectors;
|
||||
* Regroup GumTree results to a hierarchical construction.
|
||||
*
|
||||
* @author kui.liu
|
||||
*
|
||||
*/
|
||||
public class HierarchicalRegrouper {
|
||||
public class HierarchicalRegrouper
|
||||
{
|
||||
|
||||
public List<HierarchicalActionSet> regroupGumTreeResults(List<Action> actions) {
|
||||
public List<HierarchicalActionSet> regroupGumTreeResults(List<Action> actions)
|
||||
{
|
||||
/*
|
||||
* First, sort actions by their positions.
|
||||
*/
|
||||
@@ -32,17 +32,23 @@ public class HierarchicalRegrouper {
|
||||
List<HierarchicalActionSet> actionSets = new ArrayList<>();
|
||||
HierarchicalActionSet actionSet = null;
|
||||
|
||||
if(actions == null){
|
||||
if (actions == null)
|
||||
{
|
||||
return actionSets;
|
||||
}
|
||||
|
||||
for(Action act : actions){
|
||||
for (Action act : actions)
|
||||
{
|
||||
Action parentAct = findParentAction(act, actions);
|
||||
if (parentAct == null) {
|
||||
if (parentAct == null)
|
||||
{
|
||||
actionSet = createActionSet(act, parentAct, null);
|
||||
actionSets.add(actionSet);
|
||||
} else {
|
||||
if (!addToAactionSet(act, parentAct, actionSets)) {
|
||||
}
|
||||
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);
|
||||
@@ -54,17 +60,22 @@ public class HierarchicalRegrouper {
|
||||
* Third, add the subActionSet to its parent ActionSet.
|
||||
*/
|
||||
List<HierarchicalActionSet> reActionSets = new ArrayList<>();
|
||||
for (HierarchicalActionSet actSet : actionSets) {
|
||||
for (HierarchicalActionSet actSet : actionSets)
|
||||
{
|
||||
Action parentAct = actSet.getParentAction();
|
||||
if (parentAct != null) {
|
||||
if (parentAct != null)
|
||||
{
|
||||
addToActionSets(actSet, parentAct, actionSets);
|
||||
} else {
|
||||
}
|
||||
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")) {
|
||||
astNodeType.endsWith("ConstructorInvocation") || astNodeType.endsWith("CatchClause") || astNodeType.endsWith("SwitchCase"))
|
||||
{
|
||||
reActionSets.add(actSet);
|
||||
}
|
||||
}
|
||||
@@ -74,25 +85,31 @@ public class HierarchicalRegrouper {
|
||||
|
||||
ITree movDelNode = null;
|
||||
|
||||
for(HierarchicalActionSet a:reActionSets){
|
||||
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){
|
||||
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){
|
||||
// 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;
|
||||
else
|
||||
{
|
||||
Predicate<HierarchicalActionSet> predicate = x -> x.getAction() instanceof Move;
|
||||
List<HierarchicalActionSet> collect = postOrder(a).stream().filter(predicate).collect(Collectors.toList());
|
||||
if(collect.size() == 1){
|
||||
if (collect.size() == 1)
|
||||
{
|
||||
HierarchicalActionSet hierarchicalActionSet = collect.get(0);
|
||||
movDelNode = hierarchicalActionSet.getNode().getParent();
|
||||
reActionSets1.add(a);
|
||||
@@ -100,8 +117,10 @@ public class HierarchicalRegrouper {
|
||||
}
|
||||
|
||||
}
|
||||
if( movDelNode != null){
|
||||
if(a.getNode().equals(movDelNode)){
|
||||
if (movDelNode != null)
|
||||
{
|
||||
if (a.getNode().equals(movDelNode))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -110,42 +129,44 @@ public class HierarchicalRegrouper {
|
||||
}
|
||||
|
||||
|
||||
|
||||
return reActionSets1;
|
||||
// return reActionSets;
|
||||
// return reActionSets;
|
||||
}
|
||||
|
||||
|
||||
private boolean isStatement(HierarchicalActionSet actSet){
|
||||
private boolean isStatement(HierarchicalActionSet actSet)
|
||||
{
|
||||
String astNodeType = actSet.getAstNodeType();
|
||||
if (astNodeType.endsWith("TypeDeclaration") || astNodeType.endsWith("FieldDeclaration") || astNodeType.endsWith("EnumDeclaration") ||
|
||||
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")) {
|
||||
return true;
|
||||
astNodeType.endsWith("ConstructorInvocation") || astNodeType.endsWith("CatchClause") || astNodeType.endsWith("SwitchCase");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Predicate<HierarchicalActionSet> predicate = x-> isStatement(x);
|
||||
|
||||
private HierarchicalActionSet removeBlocks(HierarchicalActionSet actionSet){
|
||||
Predicate<HierarchicalActionSet> predicate = x -> isStatement(x);
|
||||
|
||||
private HierarchicalActionSet removeBlocks(HierarchicalActionSet actionSet)
|
||||
{
|
||||
List<HierarchicalActionSet> subActions = actionSet.getSubActions();
|
||||
|
||||
|
||||
|
||||
Action action = actionSet.getAction();
|
||||
if (subActions.size() == 1){
|
||||
if (subActions.size() == 1)
|
||||
{
|
||||
HierarchicalActionSet subaction = subActions.get(0);
|
||||
|
||||
List<HierarchicalActionSet> collect = postOrder(subaction).stream().filter(predicate).collect(Collectors.toList());
|
||||
if(collect.size() == 0){
|
||||
if (collect.size() == 0)
|
||||
{
|
||||
return actionSet;
|
||||
}
|
||||
boolean b = collect.stream().anyMatch(p -> p.getAction().getName().equals(subActions.get(0).getAction().getName()));
|
||||
if(!b){
|
||||
if (!b)
|
||||
{
|
||||
return actionSet;
|
||||
}
|
||||
Action action1 = subaction.getAction();
|
||||
if(action.getClass().equals(action1.getClass()) && action.getName().equals("UPD")) {
|
||||
if (action.getClass().equals(action1.getClass()) && action.getName().equals("UPD"))
|
||||
{
|
||||
subaction.setParent(null);
|
||||
return removeBlocks(subaction);
|
||||
|
||||
@@ -155,27 +176,34 @@ public class HierarchicalRegrouper {
|
||||
|
||||
}
|
||||
|
||||
public List<HierarchicalActionSet> postOrder(HierarchicalActionSet a) {
|
||||
public List<HierarchicalActionSet> postOrder(HierarchicalActionSet a)
|
||||
{
|
||||
List<HierarchicalActionSet> trees = new ArrayList<>();
|
||||
getAllSubActions(a, trees);
|
||||
return trees;
|
||||
}
|
||||
private void getAllSubActions(HierarchicalActionSet a,List<HierarchicalActionSet> as) {
|
||||
|
||||
private void getAllSubActions(HierarchicalActionSet a, List<HierarchicalActionSet> as)
|
||||
{
|
||||
|
||||
List<HierarchicalActionSet> subActions = a.getSubActions();
|
||||
if (subActions.size() != 0){
|
||||
for (HierarchicalActionSet s : subActions) {
|
||||
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;
|
||||
// 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) {
|
||||
|
||||
private HierarchicalActionSet createActionSet(Action act, Action parentAct, HierarchicalActionSet parent)
|
||||
{
|
||||
HierarchicalActionSet actionSet = new HierarchicalActionSet();
|
||||
actionSet.setAction(act);
|
||||
actionSet.setActionString(parseAction(act.toString()));
|
||||
@@ -185,24 +213,32 @@ public class HierarchicalRegrouper {
|
||||
return actionSet;
|
||||
}
|
||||
|
||||
private String parseAction(String actStr1) {
|
||||
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 ++) {
|
||||
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 {
|
||||
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)) {
|
||||
if (ASTNodeMap.map.containsKey(typeInt))
|
||||
{
|
||||
String type = ASTNodeMap.map.get(Integer.parseInt(nodeType));
|
||||
nodeType = type;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
nodeType = actStrFrag.substring(index);
|
||||
}
|
||||
}
|
||||
@@ -214,20 +250,32 @@ public class HierarchicalRegrouper {
|
||||
return actStr;
|
||||
}
|
||||
|
||||
private void addToActionSets(HierarchicalActionSet actionSet, Action parentAct, List<HierarchicalActionSet> actionSets) {
|
||||
private void addToActionSets(HierarchicalActionSet actionSet, Action parentAct, List<HierarchicalActionSet> actionSets)
|
||||
{
|
||||
Action act = actionSet.getAction();
|
||||
for (HierarchicalActionSet actSet : actionSets) {
|
||||
if (actSet.equals(actionSet)) continue;
|
||||
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.
|
||||
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)) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isPossibileSubAction(action, act))
|
||||
{
|
||||
// SubAction range: startPosition2 <= startPosition && startPosition + length <= startPosition2 + length2
|
||||
addToActionSets(actionSet, parentAct, actSet.getSubActions());
|
||||
}
|
||||
@@ -235,51 +283,67 @@ public class HierarchicalRegrouper {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
// }
|
||||
// }
|
||||
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) {
|
||||
private void sortSubActions(HierarchicalActionSet actionSet)
|
||||
{
|
||||
ListSorter<HierarchicalActionSet> sorter = new ListSorter<HierarchicalActionSet>(actionSet.getSubActions());
|
||||
List<HierarchicalActionSet> subActions = sorter.sortAscending();
|
||||
if (subActions != null) {
|
||||
if (subActions != null)
|
||||
{
|
||||
actionSet.setSubActions(subActions);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean addToAactionSet(Action act, Action parentAct, List<HierarchicalActionSet> actionSets) {
|
||||
for(HierarchicalActionSet actionSet : actionSets) {
|
||||
private boolean addToAactionSet(Action act, Action parentAct, List<HierarchicalActionSet> actionSets)
|
||||
{
|
||||
for (HierarchicalActionSet actionSet : actionSets)
|
||||
{
|
||||
Action action = actionSet.getAction();
|
||||
|
||||
if (!areRelatedActions(action, act)) continue;
|
||||
if (!areRelatedActions(action, act))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (action.equals(parentAct)) { // actionSet is the parent of actSet.
|
||||
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)) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isPossibileSubAction(action, act))
|
||||
{
|
||||
// SubAction range: startPosition2 <= startPosition && startPosition + length <= startP + length2
|
||||
List<HierarchicalActionSet> subActionSets = actionSet.getSubActions();
|
||||
if (subActionSets.size() > 0) {
|
||||
if (subActionSets.size() > 0)
|
||||
{
|
||||
boolean added = addToAactionSet(act, parentAct, subActionSets);
|
||||
if (added) {
|
||||
if (added)
|
||||
{
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -289,19 +353,23 @@ public class HierarchicalRegrouper {
|
||||
return false;
|
||||
}
|
||||
|
||||
private Action findParentAction(Action action, List<Action> actions) {
|
||||
private Action findParentAction(Action action, List<Action> actions)
|
||||
{
|
||||
|
||||
ITree parent = action.getNode().getParent();
|
||||
if (action instanceof Addition) {
|
||||
if (action instanceof Addition)
|
||||
{
|
||||
parent = ((Addition) action).getParent(); // parent in the fixed source code tree
|
||||
}
|
||||
|
||||
if (parent.getType() == 55) {
|
||||
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) {
|
||||
&& type != 76 && type != 84 && type != 87 && type != 88 && type != 42)
|
||||
{
|
||||
// ArrayType, PrimitiveType, SimpleType, ParameterizedType,
|
||||
// QualifiedType, WildcardType, UnionType, IntersectionType, NameQualifiedType, SimpleName
|
||||
return null;
|
||||
@@ -310,9 +378,12 @@ public class HierarchicalRegrouper {
|
||||
|
||||
}
|
||||
|
||||
for (Action act : actions) {
|
||||
if (act.getNode().equals(parent)) {
|
||||
if (areRelatedActions(act, action)) {
|
||||
for (Action act : actions)
|
||||
{
|
||||
if (act.getNode().equals(parent))
|
||||
{
|
||||
if (areRelatedActions(act, action))
|
||||
{
|
||||
return act;
|
||||
}
|
||||
}
|
||||
@@ -320,16 +391,16 @@ public class HierarchicalRegrouper {
|
||||
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.
|
||||
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;
|
||||
// If action is DEL, its children must be DEL.
|
||||
return !(parent instanceof Insert) || child instanceof Addition;
|
||||
}
|
||||
}
|
||||
|
||||
+437
-357
File diff suppressed because it is too large
Load Diff
@@ -2,18 +2,22 @@ package edu.lu.uni.serval.richedit.ediff;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class MessageFile {
|
||||
public class MessageFile
|
||||
{
|
||||
|
||||
private final File revFile;
|
||||
|
||||
private final File prevFile;
|
||||
|
||||
private final File diffEntryFile;
|
||||
|
||||
private File revFile;
|
||||
private File prevFile;
|
||||
private File diffEntryFile;
|
||||
private File positionFile;
|
||||
|
||||
|
||||
|
||||
private String project;
|
||||
|
||||
public MessageFile(File revFile, File prevFile, File diffEntryFile,String project) {
|
||||
public MessageFile(File revFile, File prevFile, File diffEntryFile, String project)
|
||||
{
|
||||
super();
|
||||
this.revFile = revFile;
|
||||
this.prevFile = prevFile;
|
||||
@@ -21,26 +25,38 @@ public class MessageFile {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public String getProject() { return project;}
|
||||
public String getProject()
|
||||
{
|
||||
return project;
|
||||
}
|
||||
|
||||
public void setProject(String project) { this.project = project;}
|
||||
public File getRevFile() {
|
||||
public void setProject(String project)
|
||||
{
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public File getRevFile()
|
||||
{
|
||||
return revFile;
|
||||
}
|
||||
|
||||
public File getPrevFile() {
|
||||
public File getPrevFile()
|
||||
{
|
||||
return prevFile;
|
||||
}
|
||||
|
||||
public File getDiffEntryFile() {
|
||||
public File getDiffEntryFile()
|
||||
{
|
||||
return diffEntryFile;
|
||||
}
|
||||
|
||||
public File getPositionFile() {
|
||||
public File getPositionFile()
|
||||
{
|
||||
return positionFile;
|
||||
}
|
||||
|
||||
public void setPositionFile(File positionFile) {
|
||||
public void setPositionFile(File positionFile)
|
||||
{
|
||||
this.positionFile = positionFile;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,53 +8,63 @@ import java.io.File;
|
||||
* Parse fix patterns with GumTree.
|
||||
*
|
||||
* @author kui.liu
|
||||
*
|
||||
*/
|
||||
public abstract class Parser implements ParserInterface {
|
||||
public abstract class Parser implements ParserInterface
|
||||
{
|
||||
|
||||
protected String astEditScripts = ""; // it will be used for fix patterns mining.
|
||||
|
||||
protected String patchesSourceCode = ""; // testing
|
||||
|
||||
protected String buggyTrees = ""; // Compute similarity for bug localization.
|
||||
|
||||
protected String sizes = ""; // fix patterns' selection before mining.
|
||||
|
||||
protected String tokensOfSourceCode = ""; // Compute similarity for bug localization.
|
||||
|
||||
protected String originalTree = ""; // Guide of generating patches.
|
||||
|
||||
protected String actionSets = ""; // Guide of generating patches.
|
||||
|
||||
public abstract void parseFixPatterns(File prevFile, File revFile, File diffEntryFile, String project, JedisPool innerPool, String srcMLPath,String rootType,boolean isJava);
|
||||
public abstract void parseFixPatterns(File prevFile, File revFile, File diffEntryFile, String project, JedisPool innerPool, String srcMLPath, String rootType, boolean isJava);
|
||||
|
||||
|
||||
@Override
|
||||
public String getAstEditScripts() {
|
||||
public String getAstEditScripts()
|
||||
{
|
||||
return astEditScripts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPatchesSourceCode() {
|
||||
public String getPatchesSourceCode()
|
||||
{
|
||||
return patchesSourceCode;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String getBuggyTrees() {
|
||||
// return buggyTrees;
|
||||
// }
|
||||
// @Override
|
||||
// public String getBuggyTrees() {
|
||||
// return buggyTrees;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String getSizes() {
|
||||
public String getSizes()
|
||||
{
|
||||
return sizes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTokensOfSourceCode() {
|
||||
public String getTokensOfSourceCode()
|
||||
{
|
||||
return tokensOfSourceCode;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String getOriginalTree() {
|
||||
// return originalTree;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getActionSets() {
|
||||
// return actionSets;
|
||||
// }
|
||||
// @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 void parseFixPatterns(File prevFile, File revFile, File diffEntryFile);
|
||||
|
||||
public String getAstEditScripts();
|
||||
String getAstEditScripts();
|
||||
|
||||
public String getPatchesSourceCode();
|
||||
String getPatchesSourceCode();
|
||||
|
||||
// public String getBuggyTrees();
|
||||
// public String getBuggyTrees();
|
||||
|
||||
public String getSizes();
|
||||
String getSizes();
|
||||
|
||||
public String getTokensOfSourceCode();
|
||||
String getTokensOfSourceCode();
|
||||
|
||||
// public String getOriginalTree();
|
||||
// public String getOriginalTree();
|
||||
|
||||
// public String getActionSets();
|
||||
// public String getActionSets();
|
||||
}
|
||||
|
||||
@@ -4,26 +4,37 @@ import redis.clients.jedis.JedisPool;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class RunnableParser implements Runnable {
|
||||
public class RunnableParser implements Runnable
|
||||
{
|
||||
|
||||
private final File prevFile;
|
||||
|
||||
private final File revFile;
|
||||
|
||||
private final File diffEntryFile;
|
||||
|
||||
private final Parser parser;
|
||||
|
||||
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;
|
||||
|
||||
public RunnableParser(File prevFile, File revFile, File diffEntryFile, Parser parser) {
|
||||
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) {
|
||||
public RunnableParser(File prevFile, File revFile, File diffEntryFile, Parser parser, String project, JedisPool innerPool)
|
||||
{
|
||||
this.prevFile = prevFile;
|
||||
this.revFile = revFile;
|
||||
this.diffEntryFile = diffEntryFile;
|
||||
@@ -32,7 +43,8 @@ public class RunnableParser implements Runnable {
|
||||
this.pool = innerPool;
|
||||
}
|
||||
|
||||
public RunnableParser(File prevFile, File revFile, File diffEntryFile, Parser parser, String project, JedisPool innerPool,String srcMLPath,String rootType,boolean isJava) {
|
||||
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;
|
||||
@@ -45,7 +57,8 @@ public class RunnableParser implements Runnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
parser.parseFixPatterns(prevFile, revFile, diffEntryFile,project,pool,srcMLPath,rootType,isJava);
|
||||
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 ->
|
||||
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();
|
||||
|
||||
|
||||
|
||||
|
||||
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"))
|
||||
// }
|
||||
if (pairName.equals("0"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
String matchKey = null;
|
||||
// try {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
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);
|
||||
@@ -165,15 +133,7 @@ public class EnhancedASTDiff
|
||||
{
|
||||
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;
|
||||
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,12 +3,13 @@ package edu.lu.uni.serval.utils;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ASTNodeMap {
|
||||
|
||||
public class ASTNodeMap
|
||||
{
|
||||
public static Map<Integer, String> map;
|
||||
|
||||
static {
|
||||
map = new HashMap<Integer, String>();
|
||||
static
|
||||
{
|
||||
map = new HashMap<>();
|
||||
map.put(-3, "Instanceof");
|
||||
map.put(-2, "New");
|
||||
map.put(-1, "Operator");
|
||||
@@ -106,11 +107,10 @@ public class ASTNodeMap {
|
||||
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{
|
||||
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()));
|
||||
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) {
|
||||
while ((s = stdError.readLine()) != null)
|
||||
System.out.print(s);
|
||||
}
|
||||
|
||||
// System.exit(0);
|
||||
}
|
||||
catch (IOException e) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,57 +21,67 @@ import java.util.stream.Collectors;
|
||||
/**
|
||||
* Created by anilkoyuncu on 17/09/2018.
|
||||
*/
|
||||
public class EDiffHelper {
|
||||
private static Logger log = LoggerFactory.getLogger(EDiffHelper.class);
|
||||
public class EDiffHelper
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(EDiffHelper.class);
|
||||
|
||||
/** Read the object from Base64 string. */
|
||||
public static Object fromString( String s ) throws IOException,
|
||||
ClassNotFoundException {
|
||||
byte [] data = Base64.getDecoder().decode( s );
|
||||
public static Object fromString(String s) throws IOException,
|
||||
ClassNotFoundException
|
||||
{
|
||||
byte[] data = Base64.getDecoder().decode(s);
|
||||
ObjectInputStream ois = new ObjectInputStream(
|
||||
new ByteArrayInputStream( data ) );
|
||||
new ByteArrayInputStream(data));
|
||||
Object o = ois.readObject();
|
||||
ois.close();
|
||||
return o;
|
||||
}
|
||||
|
||||
/** Write the object to a Base64 string. */
|
||||
public static String toString( Serializable o ) throws IOException {
|
||||
public static String toString(Serializable o) throws IOException
|
||||
{
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream( baos );
|
||||
oos.writeObject( o );
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(o);
|
||||
oos.close();
|
||||
return Base64.getEncoder().encodeToString(baos.toByteArray());
|
||||
}
|
||||
|
||||
|
||||
public static Object fromByteArray( byte[] data ) throws IOException,
|
||||
ClassNotFoundException {
|
||||
// byte [] data = Base64.getDecoder().decode( s );
|
||||
public static Object fromByteArray(byte[] data) throws IOException,
|
||||
ClassNotFoundException
|
||||
{
|
||||
// byte [] data = Base64.getDecoder().decode( s );
|
||||
ObjectInputStream ois = new ObjectInputStream(
|
||||
new ByteArrayInputStream( data ) );
|
||||
new ByteArrayInputStream(data));
|
||||
Object o = ois.readObject();
|
||||
ois.close();
|
||||
return o;
|
||||
}
|
||||
|
||||
/** Write the object to a Base64 string. */
|
||||
public static byte[] toByteArray(Serializable o ) throws IOException {
|
||||
public static byte[] toByteArray(Serializable o) throws IOException
|
||||
{
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream( baos );
|
||||
oos.writeObject( o );
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(o);
|
||||
oos.close();
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
public static byte[] commonsSerialize(Serializable o){
|
||||
public static byte[] commonsSerialize(Serializable o)
|
||||
{
|
||||
return SerializationUtils.serialize(o);
|
||||
}
|
||||
|
||||
public static Object commonsDeserialize(byte[] data){
|
||||
public static Object commonsDeserialize(byte[] data)
|
||||
{
|
||||
return SerializationUtils.deserialize(data);
|
||||
}
|
||||
|
||||
|
||||
public static ITree getTokenTree(HierarchicalActionSet actionSet, ITree parent, ITree children,TreeContext tc,boolean isJava){
|
||||
public static ITree getTokenTree(HierarchicalActionSet actionSet, ITree parent, ITree children, TreeContext tc, boolean isJava)
|
||||
{
|
||||
|
||||
int newType = 0;
|
||||
|
||||
@@ -80,36 +90,46 @@ public class EDiffHelper {
|
||||
String label = actionSet.getAction().toString();
|
||||
|
||||
Map<Integer, String> nodeMap;
|
||||
if(isJava){
|
||||
if (isJava)
|
||||
{
|
||||
nodeMap = ASTNodeMap.map;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeMap = NodeMap_new.map;
|
||||
}
|
||||
// List<Integer> keysByValue = getKeysByValue(ASTNodeMap.map, astNodeType);
|
||||
// List<Integer> keysByValue = getKeysByValue(ASTNodeMap.map, astNodeType);
|
||||
List<Integer> keysByValue = getKeysByValue(nodeMap, astNodeType);
|
||||
|
||||
if(keysByValue.size() != 1){
|
||||
if (keysByValue.size() != 1)
|
||||
{
|
||||
log.error("More than 1");
|
||||
}
|
||||
newType = keysByValue.get(0);
|
||||
if(actionSet.getParent() == null){
|
||||
if (actionSet.getParent() == null)
|
||||
{
|
||||
//root
|
||||
|
||||
parent = tc.createTree(newType, label, null);
|
||||
tc.setRoot(parent);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
children = tc.createTree(newType, label, null);
|
||||
children.setParentAndUpdateChildren(parent);
|
||||
}
|
||||
List<HierarchicalActionSet> subActions = actionSet.getSubActions();
|
||||
if (subActions.size() != 0){
|
||||
for (HierarchicalActionSet subAction : subActions) {
|
||||
if (subActions.size() != 0)
|
||||
{
|
||||
for (HierarchicalActionSet subAction : subActions)
|
||||
{
|
||||
|
||||
if(actionSet.getParent() == null){
|
||||
if (actionSet.getParent() == null)
|
||||
{
|
||||
children = parent;
|
||||
}
|
||||
getTokenTree(subAction,children,null,tc,isJava);
|
||||
getTokenTree(subAction, children, null, tc, isJava);
|
||||
|
||||
}
|
||||
|
||||
@@ -119,66 +139,83 @@ public class EDiffHelper {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static ITree getTargetTree(HierarchicalActionSet actionSet, ITree parent, ITree children, TreeContext tc,boolean isJava){
|
||||
public static ITree getTargetTree(HierarchicalActionSet actionSet, ITree parent, ITree children, TreeContext tc, boolean isJava)
|
||||
{
|
||||
|
||||
int newType = 0;
|
||||
|
||||
String astNodeType = null;
|
||||
Map<Integer, String> nodeMap;
|
||||
if(isJava){
|
||||
if (isJava)
|
||||
{
|
||||
nodeMap = ASTNodeMap.map;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeMap = NodeMap_new.map;
|
||||
}
|
||||
|
||||
Action action = actionSet.getAction();
|
||||
if (action instanceof Update){
|
||||
if (action instanceof Update)
|
||||
{
|
||||
astNodeType = actionSet.getAstNodeType();
|
||||
|
||||
List<Integer> keysByValue = getKeysByValue(nodeMap, astNodeType);
|
||||
|
||||
if(keysByValue.size() != 1){
|
||||
if (keysByValue.size() != 1)
|
||||
{
|
||||
log.error("More than 1");
|
||||
}
|
||||
newType = keysByValue.get(0);
|
||||
}else if(action instanceof Insert){
|
||||
newType = ((Insert)action).getParent().getType();
|
||||
}else if(action instanceof Move){
|
||||
newType = ((Move)action).getParent().getType();
|
||||
}else if(action instanceof Delete){
|
||||
}
|
||||
else if (action instanceof Insert)
|
||||
{
|
||||
newType = ((Insert) action).getParent().getType();
|
||||
}
|
||||
else if (action instanceof Move)
|
||||
{
|
||||
newType = ((Move) action).getParent().getType();
|
||||
}
|
||||
else if (action instanceof Delete)
|
||||
{
|
||||
astNodeType = actionSet.getAstNodeType();
|
||||
|
||||
List<Integer> keysByValue = getKeysByValue(nodeMap, astNodeType);
|
||||
|
||||
if(keysByValue.size() != 1){
|
||||
if (keysByValue.size() != 1)
|
||||
{
|
||||
log.error("More than 1");
|
||||
}
|
||||
newType = keysByValue.get(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(actionSet.getParent() == null){
|
||||
if (actionSet.getParent() == null)
|
||||
{
|
||||
//root
|
||||
|
||||
// parent = new Tree(newType,"");
|
||||
// parent = new Tree(newType,"");
|
||||
parent = tc.createTree(newType, "", null);
|
||||
tc.setRoot(parent);
|
||||
}else{
|
||||
// children = new Tree(newType,"");
|
||||
// parent.addChild(children);
|
||||
}
|
||||
else
|
||||
{
|
||||
// children = new Tree(newType,"");
|
||||
// parent.addChild(children);
|
||||
children = tc.createTree(newType, "", null);
|
||||
children.setParentAndUpdateChildren(parent);
|
||||
}
|
||||
List<HierarchicalActionSet> subActions = actionSet.getSubActions();
|
||||
if (subActions.size() != 0){
|
||||
for (HierarchicalActionSet subAction : subActions) {
|
||||
if (subActions.size() != 0)
|
||||
{
|
||||
for (HierarchicalActionSet subAction : subActions)
|
||||
{
|
||||
|
||||
if(actionSet.getParent() == null){
|
||||
if (actionSet.getParent() == null)
|
||||
{
|
||||
children = parent;
|
||||
}
|
||||
getTargetTree(subAction,children,null,tc,isJava);
|
||||
getTargetTree(subAction, children, null, tc, isJava);
|
||||
|
||||
}
|
||||
|
||||
@@ -187,43 +224,54 @@ public class EDiffHelper {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public static ITree getASTTree(HierarchicalActionSet actionSet, ITree parent, ITree children, TreeContext tc,boolean isJava){
|
||||
public static ITree getASTTree(HierarchicalActionSet actionSet, ITree parent, ITree children, TreeContext tc, boolean isJava)
|
||||
{
|
||||
|
||||
int newType = 0;
|
||||
Map<Integer, String> nodeMap;
|
||||
if(isJava){
|
||||
if (isJava)
|
||||
{
|
||||
nodeMap = ASTNodeMap.map;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeMap = NodeMap_new.map;
|
||||
}
|
||||
String astNodeType = actionSet.getAstNodeType();
|
||||
|
||||
List<Integer> keysByValue = getKeysByValue(nodeMap, astNodeType);
|
||||
|
||||
if(keysByValue.size() != 1){
|
||||
if (keysByValue.size() != 1)
|
||||
{
|
||||
log.error("More than 1");
|
||||
}
|
||||
newType = keysByValue.get(0);
|
||||
if(actionSet.getParent() == null){
|
||||
if (actionSet.getParent() == null)
|
||||
{
|
||||
//root
|
||||
|
||||
// parent = new Tree(newType,"");
|
||||
// parent = new Tree(newType,"");
|
||||
parent = tc.createTree(newType, "", null);
|
||||
tc.setRoot(parent);
|
||||
}else{
|
||||
// children = new Tree(newType,"");
|
||||
// parent.addChild(children);
|
||||
}
|
||||
else
|
||||
{
|
||||
// children = new Tree(newType,"");
|
||||
// parent.addChild(children);
|
||||
children = tc.createTree(newType, "", null);
|
||||
children.setParentAndUpdateChildren(parent);
|
||||
}
|
||||
List<HierarchicalActionSet> subActions = actionSet.getSubActions();
|
||||
if (subActions.size() != 0){
|
||||
for (HierarchicalActionSet subAction : subActions) {
|
||||
if (subActions.size() != 0)
|
||||
{
|
||||
for (HierarchicalActionSet subAction : subActions)
|
||||
{
|
||||
|
||||
if(actionSet.getParent() == null){
|
||||
if (actionSet.getParent() == null)
|
||||
{
|
||||
children = parent;
|
||||
}
|
||||
getASTTree(subAction,children,null,tc,isJava);
|
||||
getASTTree(subAction, children, null, tc, isJava);
|
||||
|
||||
}
|
||||
|
||||
@@ -233,7 +281,8 @@ public class EDiffHelper {
|
||||
}
|
||||
|
||||
|
||||
public static <T, E> List<T> getKeysByValue(Map<T, E> map, E value) {
|
||||
public static <T, E> List<T> getKeysByValue(Map<T, E> map, E value)
|
||||
{
|
||||
return map.entrySet()
|
||||
.stream()
|
||||
.filter(entry -> Objects.equals(entry.getValue(), value))
|
||||
@@ -241,69 +290,70 @@ public class EDiffHelper {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// public static ITree getSimpliedTree(String prefix, String fn, JedisPool outerPool) {
|
||||
//
|
||||
// ITree tree = null;
|
||||
// Jedis inner = null;
|
||||
// try {
|
||||
// inner = outerPool.getResource();
|
||||
// while (!inner.ping().equals("PONG")){
|
||||
// log.info("wait");
|
||||
// }
|
||||
// inner.select(1);
|
||||
// String dist2load = inner.get(prefix+"-"+fn);
|
||||
// inner.select(0);
|
||||
// String s = inner.get(prefix.replace("-","/") +"/"+dist2load);
|
||||
// HierarchicalActionSet actionSet = (HierarchicalActionSet) EDiffHelper.fromString(s);
|
||||
//
|
||||
// ITree parent = null;
|
||||
// ITree children =null;
|
||||
// TreeContext tc = new TreeContext();
|
||||
// tree = EDiffHelper.getASTTree(actionSet, parent, children,tc);
|
||||
// tree.setParent(null);
|
||||
// tc.validate();
|
||||
//
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (ClassNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// }finally {
|
||||
// if (inner != null) {
|
||||
// inner.close();
|
||||
// }
|
||||
// }
|
||||
// return tree;
|
||||
//
|
||||
// }
|
||||
// public static ITree getSimpliedTree(String prefix, String fn, JedisPool outerPool) {
|
||||
//
|
||||
// ITree tree = null;
|
||||
// Jedis inner = null;
|
||||
// try {
|
||||
// inner = outerPool.getResource();
|
||||
// while (!inner.ping().equals("PONG")){
|
||||
// log.info("wait");
|
||||
// }
|
||||
// inner.select(1);
|
||||
// String dist2load = inner.get(prefix+"-"+fn);
|
||||
// inner.select(0);
|
||||
// String s = inner.get(prefix.replace("-","/") +"/"+dist2load);
|
||||
// HierarchicalActionSet actionSet = (HierarchicalActionSet) EDiffHelper.fromString(s);
|
||||
//
|
||||
// ITree parent = null;
|
||||
// ITree children =null;
|
||||
// TreeContext tc = new TreeContext();
|
||||
// tree = EDiffHelper.getASTTree(actionSet, parent, children,tc);
|
||||
// tree.setParent(null);
|
||||
// tc.validate();
|
||||
//
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (ClassNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// }finally {
|
||||
// if (inner != null) {
|
||||
// inner.close();
|
||||
// }
|
||||
// }
|
||||
// return tree;
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
// public static ITree getShapes(String prefix, String fn, JedisPool outerPool, HashMap<String, String> filenames) {
|
||||
//
|
||||
// ITree tree = null;
|
||||
//
|
||||
// try (Jedis outer = outerPool.getResource()) {
|
||||
// try {
|
||||
// while (!outer.ping().equals("PONG")) {
|
||||
// log.info("wait");
|
||||
// }
|
||||
// String dist2load = filenames.get(prefix + "-" + fn);
|
||||
//
|
||||
// String key = prefix.replace("-", "/") + "/" + dist2load;
|
||||
//
|
||||
// byte[] s = outer.hget("dump".getBytes(), key.getBytes());
|
||||
// HierarchicalActionSet actionSet = (HierarchicalActionSet) EDiffHelper.kryoDeseerialize(s);
|
||||
//
|
||||
// tree = getShapeTree(actionSet);
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// return tree;
|
||||
//
|
||||
// }
|
||||
// public static ITree getShapes(String prefix, String fn, JedisPool outerPool, HashMap<String, String> filenames) {
|
||||
//
|
||||
// ITree tree = null;
|
||||
//
|
||||
// try (Jedis outer = outerPool.getResource()) {
|
||||
// try {
|
||||
// while (!outer.ping().equals("PONG")) {
|
||||
// log.info("wait");
|
||||
// }
|
||||
// String dist2load = filenames.get(prefix + "-" + fn);
|
||||
//
|
||||
// String key = prefix.replace("-", "/") + "/" + dist2load;
|
||||
//
|
||||
// byte[] s = outer.hget("dump".getBytes(), key.getBytes());
|
||||
// HierarchicalActionSet actionSet = (HierarchicalActionSet) EDiffHelper.kryoDeseerialize(s);
|
||||
//
|
||||
// tree = getShapeTree(actionSet);
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// return tree;
|
||||
//
|
||||
// }
|
||||
|
||||
public static ITree getShapeTree(HierarchicalActionSet actionSet,boolean isJava) {
|
||||
public static ITree getShapeTree(HierarchicalActionSet actionSet, boolean isJava)
|
||||
{
|
||||
ITree tree = null;
|
||||
ITree parent = null;
|
||||
ITree children = null;
|
||||
@@ -314,40 +364,49 @@ public class EDiffHelper {
|
||||
return tree;
|
||||
}
|
||||
|
||||
public static ITree getTokenTree(HierarchicalActionSet actionSet,boolean isJava) {
|
||||
public static ITree getTokenTree(HierarchicalActionSet actionSet, boolean isJava)
|
||||
{
|
||||
ITree tree = null;
|
||||
ITree parent = null;
|
||||
ITree children = null;
|
||||
TreeContext tc = new TreeContext();
|
||||
tree = EDiffHelper.getTokenTree(actionSet, parent, children, tc,isJava);
|
||||
tree = EDiffHelper.getTokenTree(actionSet, parent, children, tc, isJava);
|
||||
//tree.setParent(null);
|
||||
tc.validate();
|
||||
return tree;
|
||||
}
|
||||
|
||||
|
||||
public static ITree getTargets(HierarchicalActionSet actionSet,boolean isJava) {
|
||||
public static ITree getTargets(HierarchicalActionSet actionSet, boolean isJava)
|
||||
{
|
||||
|
||||
ITree tree = null;
|
||||
try {
|
||||
try
|
||||
{
|
||||
|
||||
ITree parent = null;
|
||||
ITree children =null;
|
||||
ITree children = null;
|
||||
TreeContext tc = new TreeContext();
|
||||
tree = EDiffHelper.getTargetTree(actionSet, parent, children,tc,isJava);
|
||||
tree = EDiffHelper.getTargetTree(actionSet, parent, children, tc, isJava);
|
||||
//tree.setParent(null);
|
||||
tc.validate();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return tree;
|
||||
|
||||
}
|
||||
|
||||
public static Map<String, String> getTreeString(String prefix, String fn, JedisPool outerPool, HashMap<String, String> filenames) {
|
||||
try (Jedis outer = outerPool.getResource()) {
|
||||
try {
|
||||
while (!outer.ping().equals("PONG")) {
|
||||
public static Map<String, String> getTreeString(String prefix, String fn, JedisPool outerPool, HashMap<String, String> filenames)
|
||||
{
|
||||
try (Jedis outer = outerPool.getResource())
|
||||
{
|
||||
try
|
||||
{
|
||||
while (!outer.ping().equals("PONG"))
|
||||
{
|
||||
log.info("wait");
|
||||
}
|
||||
|
||||
@@ -358,47 +417,50 @@ public class EDiffHelper {
|
||||
String key = split[0] + "/" + split[1] + "/" + dist2load;
|
||||
Map<String, String> treeMap = outer.hgetAll(key);
|
||||
return treeMap;
|
||||
}catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// public static Pair<ITree,HierarchicalActionSet> getActions(String prefix, String fn, JedisPool outerPool, HashMap<String, String> filenames) {
|
||||
//
|
||||
//
|
||||
// ITree tree = null;
|
||||
// HierarchicalActionSet actionSet = null;
|
||||
//
|
||||
// try (Jedis outer = outerPool.getResource()) {
|
||||
// try {
|
||||
// while (!outer.ping().equals("PONG")) {
|
||||
// log.info("wait");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// String dist2load = filenames.get(prefix + "-" + fn);
|
||||
//
|
||||
// String[] split = prefix.split("-");
|
||||
// String key = split[0] + "/"+split[1]+"/" + dist2load;
|
||||
//
|
||||
// byte[] s = outer.hget("dump".getBytes(), key.getBytes());
|
||||
// actionSet = (HierarchicalActionSet) EDiffHelper.kryoDeseerialize(s);
|
||||
//
|
||||
//
|
||||
// tree = getActionTrees(actionSet);
|
||||
// }catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Pair<ITree, HierarchicalActionSet> pair = new Pair<>(tree,actionSet);
|
||||
// return pair;
|
||||
//
|
||||
// }
|
||||
// public static Pair<ITree,HierarchicalActionSet> getActions(String prefix, String fn, JedisPool outerPool, HashMap<String, String> filenames) {
|
||||
//
|
||||
//
|
||||
// ITree tree = null;
|
||||
// HierarchicalActionSet actionSet = null;
|
||||
//
|
||||
// try (Jedis outer = outerPool.getResource()) {
|
||||
// try {
|
||||
// while (!outer.ping().equals("PONG")) {
|
||||
// log.info("wait");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// String dist2load = filenames.get(prefix + "-" + fn);
|
||||
//
|
||||
// String[] split = prefix.split("-");
|
||||
// String key = split[0] + "/"+split[1]+"/" + dist2load;
|
||||
//
|
||||
// byte[] s = outer.hget("dump".getBytes(), key.getBytes());
|
||||
// actionSet = (HierarchicalActionSet) EDiffHelper.kryoDeseerialize(s);
|
||||
//
|
||||
//
|
||||
// tree = getActionTrees(actionSet);
|
||||
// }catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Pair<ITree, HierarchicalActionSet> pair = new Pair<>(tree,actionSet);
|
||||
// return pair;
|
||||
//
|
||||
// }
|
||||
|
||||
public static ITree getActionTrees(HierarchicalActionSet actionSet) {
|
||||
public static ITree getActionTrees(HierarchicalActionSet actionSet)
|
||||
{
|
||||
ITree tree = null;
|
||||
ITree parent = null;
|
||||
ITree children = null;
|
||||
@@ -409,95 +471,114 @@ public class EDiffHelper {
|
||||
return tree;
|
||||
}
|
||||
|
||||
public static void getLeaves(ITree tc){
|
||||
public static void getLeaves(ITree tc)
|
||||
{
|
||||
|
||||
int height = tc.getHeight();
|
||||
if(height == 0){
|
||||
if (height == 0)
|
||||
{
|
||||
log.info(tc.getLabel());
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
List<ITree> children = tc.getChildren();
|
||||
for (ITree child:children){
|
||||
for (ITree child : children)
|
||||
{
|
||||
getLeaves(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// public static ITree getTokens(String prefix, String fn, JedisPool outerPool, HashMap<String, String> filenames) {
|
||||
//
|
||||
//
|
||||
// ITree tree = null;
|
||||
//
|
||||
// HierarchicalActionSet actionSet = null;
|
||||
// try (Jedis outer = outerPool.getResource()) {
|
||||
// try {
|
||||
// while (!outer.ping().equals("PONG")) {
|
||||
// log.info("wait");
|
||||
// }
|
||||
// String dist2load = filenames.get(prefix + "-" + fn);
|
||||
//
|
||||
// String[] split = prefix.split("-");
|
||||
// String key = split[0] + "/"+split[1]+"/" + dist2load;
|
||||
//
|
||||
// String s = outer.hget("dump", key);
|
||||
// actionSet = (HierarchicalActionSet) EDiffHelper.fromString(s);
|
||||
//
|
||||
//// actionSet = (HierarchicalActionSet) EDiffHelper.kryoDeseerialize(s);
|
||||
//
|
||||
// ITree parent = null;
|
||||
// ITree children = null;
|
||||
// TreeContext tc = new TreeContext();
|
||||
// tree = EDiffHelper.getTokenTree(actionSet, parent, children, tc,is);
|
||||
// tree.setParent(null);
|
||||
// tc.validate();
|
||||
//// getLeaves(tree);
|
||||
//
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return tree;
|
||||
// }
|
||||
// public static ITree getTokens(String prefix, String fn, JedisPool outerPool, HashMap<String, String> filenames) {
|
||||
//
|
||||
//
|
||||
// ITree tree = null;
|
||||
//
|
||||
// HierarchicalActionSet actionSet = null;
|
||||
// try (Jedis outer = outerPool.getResource()) {
|
||||
// try {
|
||||
// while (!outer.ping().equals("PONG")) {
|
||||
// log.info("wait");
|
||||
// }
|
||||
// String dist2load = filenames.get(prefix + "-" + fn);
|
||||
//
|
||||
// String[] split = prefix.split("-");
|
||||
// String key = split[0] + "/"+split[1]+"/" + dist2load;
|
||||
//
|
||||
// String s = outer.hget("dump", key);
|
||||
// actionSet = (HierarchicalActionSet) EDiffHelper.fromString(s);
|
||||
//
|
||||
//// actionSet = (HierarchicalActionSet) EDiffHelper.kryoDeseerialize(s);
|
||||
//
|
||||
// ITree parent = null;
|
||||
// ITree children = null;
|
||||
// TreeContext tc = new TreeContext();
|
||||
// tree = EDiffHelper.getTokenTree(actionSet, parent, children, tc,is);
|
||||
// tree.setParent(null);
|
||||
// tc.validate();
|
||||
//// getLeaves(tree);
|
||||
//
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return tree;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
public static ITree getActionTree(HierarchicalActionSet actionSet, ITree parent, ITree children,TreeContext tc){
|
||||
public static ITree getActionTree(HierarchicalActionSet actionSet, ITree parent, ITree children, TreeContext tc)
|
||||
{
|
||||
|
||||
int newType = 0;
|
||||
|
||||
Action action = actionSet.getAction();
|
||||
if (action instanceof Update){
|
||||
if (action instanceof Update)
|
||||
{
|
||||
newType = 101;
|
||||
}else if(action instanceof Insert){
|
||||
newType =100;
|
||||
}else if(action instanceof Move){
|
||||
}
|
||||
else if (action instanceof Insert)
|
||||
{
|
||||
newType = 100;
|
||||
}
|
||||
else if (action instanceof Move)
|
||||
{
|
||||
newType = 102;
|
||||
}else if(action instanceof Delete){
|
||||
newType=103;
|
||||
}else{
|
||||
}
|
||||
else if (action instanceof Delete)
|
||||
{
|
||||
newType = 103;
|
||||
}
|
||||
else
|
||||
{
|
||||
new Exception("unknow action");
|
||||
}
|
||||
if(actionSet.getParent() == null){
|
||||
if (actionSet.getParent() == null)
|
||||
{
|
||||
//root
|
||||
|
||||
parent = tc.createTree(newType, "", null);
|
||||
tc.setRoot(parent);
|
||||
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
children = tc.createTree(newType, "", null);
|
||||
children.setParentAndUpdateChildren(parent);
|
||||
|
||||
}
|
||||
List<HierarchicalActionSet> subActions = actionSet.getSubActions();
|
||||
if (subActions.size() != 0){
|
||||
for (HierarchicalActionSet subAction : subActions) {
|
||||
if (subActions.size() != 0)
|
||||
{
|
||||
for (HierarchicalActionSet subAction : subActions)
|
||||
{
|
||||
|
||||
if(actionSet.getParent() == null){
|
||||
if (actionSet.getParent() == null)
|
||||
{
|
||||
children = parent;
|
||||
}
|
||||
getActionTree(subAction,children,null,tc);
|
||||
getActionTree(subAction, children, null, tc);
|
||||
|
||||
}
|
||||
|
||||
@@ -507,40 +588,50 @@ public class EDiffHelper {
|
||||
}
|
||||
|
||||
|
||||
public static List<ITree> retainLeaves(List<ITree> trees) {
|
||||
public static List<ITree> retainLeaves(List<ITree> trees)
|
||||
{
|
||||
Iterator<ITree> tIt = trees.iterator();
|
||||
while (tIt.hasNext()) {
|
||||
while (tIt.hasNext())
|
||||
{
|
||||
ITree t = tIt.next();
|
||||
if (!t.isLeaf()) tIt.remove();
|
||||
if (!t.isLeaf())
|
||||
{
|
||||
tIt.remove();
|
||||
}
|
||||
}
|
||||
return trees;
|
||||
}
|
||||
|
||||
public static String getTokenAtNode(ITree leaf,String token){
|
||||
// if (leaf.getParent() == null) {
|
||||
public static String getTokenAtNode(ITree leaf, String token)
|
||||
{
|
||||
// if (leaf.getParent() == null) {
|
||||
String label = leaf.getLabel();
|
||||
String key = label.split(String.valueOf(leaf.getType()))[0];
|
||||
String group="";
|
||||
String group = "";
|
||||
Pattern pattern;
|
||||
java.util.regex.Matcher matcher;
|
||||
|
||||
List<ITree> parents;
|
||||
List<String> actionList = new ArrayList<>();
|
||||
Set<String> uniqueGas = new HashSet<String>(actionList);
|
||||
switch (key.trim()) {
|
||||
switch (key.trim())
|
||||
{
|
||||
|
||||
case "DEL":
|
||||
parents = leaf.getParents();
|
||||
|
||||
for (ITree parent : parents) {
|
||||
for (ITree parent : parents)
|
||||
{
|
||||
String s = parent.getLabel().split(String.valueOf(parent.getType()))[0];
|
||||
actionList.add(s);
|
||||
}
|
||||
actionList.add(key);
|
||||
|
||||
if (uniqueGas.size() == 1){
|
||||
if (uniqueGas.size() == 1)
|
||||
{
|
||||
Optional<ITree> first = parents.stream().filter(p -> p.isRoot()).findFirst();
|
||||
if(first.isPresent()){
|
||||
if (first.isPresent())
|
||||
{
|
||||
ITree parent = first.get();
|
||||
label = parent.getLabel();
|
||||
}
|
||||
@@ -548,7 +639,8 @@ public class EDiffHelper {
|
||||
|
||||
pattern = Pattern.compile(delPattern);
|
||||
matcher = pattern.matcher(label);
|
||||
if (matcher.matches()) {
|
||||
if (matcher.matches())
|
||||
{
|
||||
group = matcher.group(2);
|
||||
|
||||
}
|
||||
@@ -556,24 +648,28 @@ public class EDiffHelper {
|
||||
case "INS":
|
||||
parents = leaf.getParents();
|
||||
|
||||
for (ITree parent : parents) {
|
||||
for (ITree parent : parents)
|
||||
{
|
||||
String s = parent.getLabel().split(String.valueOf(parent.getType()))[0];
|
||||
actionList.add(s);
|
||||
}
|
||||
actionList.add(key);
|
||||
|
||||
if (uniqueGas.size() == 1){
|
||||
if (uniqueGas.size() == 1)
|
||||
{
|
||||
Optional<ITree> first = parents.stream().filter(p -> p.isRoot()).findFirst();
|
||||
if(first.isPresent()){
|
||||
if (first.isPresent())
|
||||
{
|
||||
ITree parent = first.get();
|
||||
label = parent.getLabel();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
pattern = Pattern.compile(insPattern);
|
||||
matcher = pattern.matcher(label);
|
||||
if (matcher.matches()) {
|
||||
if (matcher.matches())
|
||||
{
|
||||
group = matcher.group(2);// +" " + matcher.group(3);
|
||||
|
||||
}
|
||||
@@ -581,15 +677,18 @@ public class EDiffHelper {
|
||||
case "MOV":
|
||||
parents = leaf.getParents();
|
||||
|
||||
for (ITree parent : parents) {
|
||||
for (ITree parent : parents)
|
||||
{
|
||||
String s = parent.getLabel().split(String.valueOf(parent.getType()))[0];
|
||||
actionList.add(s);
|
||||
}
|
||||
actionList.add(key);
|
||||
|
||||
if (uniqueGas.size() == 1){
|
||||
if (uniqueGas.size() == 1)
|
||||
{
|
||||
Optional<ITree> first = parents.stream().filter(p -> p.isRoot()).findFirst();
|
||||
if(first.isPresent()){
|
||||
if (first.isPresent())
|
||||
{
|
||||
ITree parent = first.get();
|
||||
label = parent.getLabel();
|
||||
}
|
||||
@@ -597,7 +696,8 @@ public class EDiffHelper {
|
||||
|
||||
pattern = Pattern.compile(movPattern);
|
||||
matcher = pattern.matcher(label);
|
||||
if (matcher.matches()) {
|
||||
if (matcher.matches())
|
||||
{
|
||||
group = matcher.group(2);
|
||||
String group1 = matcher.group(3);
|
||||
|
||||
@@ -606,8 +706,9 @@ public class EDiffHelper {
|
||||
case "UPD":
|
||||
pattern = Pattern.compile(updPattern);
|
||||
matcher = pattern.matcher(label);
|
||||
if (matcher.matches()) {
|
||||
group = matcher.group(2) +" " + matcher.group(3);
|
||||
if (matcher.matches())
|
||||
{
|
||||
group = matcher.group(2) + " " + matcher.group(3);
|
||||
|
||||
}
|
||||
break;
|
||||
@@ -615,40 +716,47 @@ public class EDiffHelper {
|
||||
}
|
||||
token = group;
|
||||
return group;
|
||||
// }else{
|
||||
// getTokenAtNode(leaf.getParent(),token);
|
||||
// return token;
|
||||
// }
|
||||
// }else{
|
||||
// getTokenAtNode(leaf.getParent(),token);
|
||||
// return token;
|
||||
// }
|
||||
}
|
||||
|
||||
static String movPattern = "MOV (.*)@@(.*)@TO@ (.*)@@(.*)@AT@.*";
|
||||
|
||||
static String delPattern = "DEL (.*)@@(.*)@AT@.*";
|
||||
|
||||
static String insPattern = "INS (.*)@@(.*)@TO@ (.*)@@(.*)@AT@.*";
|
||||
|
||||
static String updPattern = "UPD (.*)@@(.*)@TO@(.*)@AT@.*";
|
||||
|
||||
public static String getNames2(ITree oldTree){
|
||||
public static String getNames2(ITree oldTree)
|
||||
{
|
||||
|
||||
List<ITree> leaves = retainLeaves(TreeUtils.postOrder(oldTree));
|
||||
List<String> res = new ArrayList<>();
|
||||
String resu="";
|
||||
for (ITree leaf : leaves) {
|
||||
String resu = "";
|
||||
for (ITree leaf : leaves)
|
||||
{
|
||||
String tokenAtNode = getTokenAtNode(leaf, resu);
|
||||
|
||||
res.add(tokenAtNode);
|
||||
}
|
||||
|
||||
// log.info("s");
|
||||
// log.info("s");
|
||||
|
||||
if (res.size() == 1){
|
||||
if (res.size() == 1)
|
||||
{
|
||||
final String regex = "MethodName:([a-zA-Z0-9]+):.*MethodName:([a-zA-Z0-9]+):.*";
|
||||
Pattern compile = Pattern.compile(regex);
|
||||
Matcher matcher = compile.matcher(res.get(0));
|
||||
if(matcher.matches()){
|
||||
res.set(0,matcher.group(1) +" " + matcher.group(2));
|
||||
if (matcher.matches())
|
||||
{
|
||||
res.set(0, matcher.group(1) + " " + matcher.group(2));
|
||||
}
|
||||
}
|
||||
|
||||
return String.join(" ",res);
|
||||
return String.join(" ", res);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -298,82 +369,112 @@ public class FileHelper {
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,39 +5,51 @@ 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