Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code tracker Workflow #690

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/code-tracker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CodeTracker Tests

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]


jobs:
build:
runs-on: ubuntu-latest

env:
OAuthToken: ${{ secrets.OAUTHTOKEN }}
releaseVersion: CI-CodeTracker-SNAPSHOT

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'temurin'

- name: Build project with Gradle
run: ./gradlew publishToMavenLocal -x test -x javadoc -PbuildVersion=${{ env.releaseVersion }}

- name: Clone CodeTracker and Run the tests
run: |
git clone https://github.com/jodavimehran/code-tracker &&
cd code-tracker &&
mvn -B package --file pom.xml -Drm.version=${{ env.releaseVersion }}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ private static void optimizeMappings(MappingStore match) {
addList.add(new Pair<>(mapping.first.getParent() , mapping.second.getParent()));
}
}
if (mapping.first.getType().name.equals(Constants.SIMPLE_TYPE))
{
if (mapping.first.getParent().getType().name.equals(Constants.CLASS_INSTANCE_CREATION)
&&
mapping.second.getParent().getType().name.equals(Constants.CLASS_INSTANCE_CREATION))
{
if (match.getDstForSrc(mapping.first.getParent()) != mapping.second.getParent())
addList.add(new Pair<>(mapping.first.getParent() , mapping.second.getParent()));
}
}
}
for (Pair<Tree, Tree> treeTreePair : addList) {
match.removeMapping(treeTreePair.first, match.getSrcForDst(treeTreePair.first));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MissingIdenticalSubtree extends GreedySubtreeMatcher implements Tre
protected Tree src;
protected Tree dst;
protected ExtendedMultiMappingStore mappings;

@Override
public void match(Tree src, Tree dst, ExtendedMultiMappingStore mappingStore) {
this.src = src;
Expand Down Expand Up @@ -66,7 +66,9 @@ public void match(Tree src, Tree dst, ExtendedMultiMappingStore mappingStore) {
public void filterMappings(MultiMappingStore multiMappings) {
List<Mapping> ambiguousList = new ArrayList<>();
Set<Tree> ignored = new HashSet<>();
for (var src : multiMappings.allMappedSrcs()) {
Set<Tree> trees = new TreeSet<>(Comparator.comparingInt(Tree::getPos));
trees.addAll(multiMappings.allMappedSrcs());
for (var src : trees) {
var isMappingUnique = false;
if (tinyTrees(src,multiMappings,minPriority))
continue;
Expand All @@ -91,7 +93,7 @@ public void filterMappings(MultiMappingStore multiMappings) {
}
Set<Tree> srcIgnored = new HashSet<>();
Set<Tree> dstIgnored = new HashSet<>();
Collections.sort(ambiguousList, new MappingComparators.FullMappingComparator(mappings.getMonoMappingStore()));
Collections.sort(ambiguousList, new CustomTopDownMatcher.ExtendedFullMappingComparator(mappings.getMonoMappingStore()));
// Select the best ambiguous mappings
retainBestMapping(ambiguousList, srcIgnored, dstIgnored);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public class RefactoringOracleProblematicCasesTest {
@ParameterizedTest(name= "{index}: {0}")
@JsonFileSource(resources = {"/astDiff/commits/cases-problematic.json"})
public void testSubTreeMappings(@ConvertWith(CaseInfo.CaseInfoConverter.class) CaseInfo info) throws Exception {
//TODO : Fix the flakiness for this case
if (info.makeURL().equals("https://github.com/infinispan/infinispan/commit/03573a655bcbb77f7a76d8e22d851cc22796b4f8")) return;

File mappingsDirFile = new File(getFinalFolderPath(dir, info.getRepo(), info.getCommit()));
String[] files = mappingsDirFile.list();
List<String> expectedFilesList = new ArrayList<>(List.of(Objects.requireNonNull(files)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package org.refactoringminer.astDiff.tests;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.github.gumtreediff.gen.SyntaxException;
import com.github.gumtreediff.gen.jdt.AbstractJdtVisitor;
import com.github.gumtreediff.gen.jdt.JdtTreeGenerator;
import com.github.gumtreediff.tree.Tree;
import com.github.gumtreediff.tree.TreeContext;
import org.apache.commons.io.FileUtils;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.ToolFactory;
import org.eclipse.jdt.core.compiler.IScanner;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTParser;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand All @@ -11,15 +21,19 @@
import org.refactoringminer.astDiff.utils.MappingExportModel;
import org.refactoringminer.astDiff.utils.TreeUtilFunctions;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.refactoringminer.astDiff.utils.UtilMethods.getTreesPath;


Expand Down Expand Up @@ -66,4 +80,47 @@ public static Stream<Arguments> initData() throws Exception {
}
return allCases.stream();
}
static class JdtPartialTreeGenerator extends JdtTreeGenerator{

private final int kind;
JdtPartialTreeGenerator(int kind)
{
this.kind = kind;
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public TreeContext generate(Reader r) throws IOException {
ASTParser parser = ASTParser.newParser(AST.JLS14);
parser.setKind(kind);
Map pOptions = JavaCore.getOptions();
pOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_14);
pOptions.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_14);
pOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_14);
pOptions.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
parser.setCompilerOptions(pOptions);
char[] source = readerToCharArray(r);
parser.setSource(source);
IScanner scanner = ToolFactory.createScanner(false, false, false, false);
scanner.setSource(source);
AbstractJdtVisitor v = createVisitor(scanner);
ASTNode node = parser.createAST(null);
if ((node.getFlags() & ASTNode.MALFORMED) != 0) // bitwise flag to check if the node has a syntax error
throw new SyntaxException(this, r, null);
node.accept(v);
return v.getTreeContext();
}
private static char[] readerToCharArray(Reader r) throws IOException {
StringBuilder fileData = new StringBuilder();
try (BufferedReader br = new BufferedReader(r)) {
char[] buf = new char[10];
int numRead = 0;
while ((numRead = br.read(buf)) != -1) {
String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
buf = new char[1024];
}
}
return fileData.toString().toCharArray();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5594,9 +5594,9 @@
"firstParentType" : "ArrayInitializer",
"secondParentType" : "ArrayInitializer",
"firstPos" : 4575,
"secondPos" : 4203,
"secondPos" : 4332,
"firstEndPos" : 4691,
"secondEndPos" : 4319
"secondEndPos" : 4449
}, {
"firstType" : "SimpleName",
"secondType" : "SimpleName",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" ?>
<root>
<context></context>
<tree type="ReturnStatement" pos="0" length="159">
<tree type="ClassInstanceCreation" pos="7" length="151">
<tree type="SimpleType" pos="11" length="23">
<tree type="SimpleName" label="AddMapConfigMessageTask" pos="11" length="23"></tree>
</tree>
<tree type="SimpleName" label="clientMessage" pos="35" length="13"></tree>
<tree type="SimpleName" label="logger" pos="50" length="6"></tree>
<tree type="SimpleName" label="mockNodeEngine" pos="58" length="14"></tree>
<tree type="MethodInvocation" pos="74" length="6">
<tree type="SimpleName" label="mock" pos="74" length="4"></tree>
</tree>
<tree type="SimpleName" label="mockClientEngine" pos="82" length="16"></tree>
<tree type="SimpleName" label="mockConnection" pos="100" length="14"></tree>
<tree type="SimpleName" label="mockNodeExtension" pos="116" length="17"></tree>
<tree type="MethodInvocation" pos="135" length="6">
<tree type="SimpleName" label="mock" pos="135" length="4"></tree>
</tree>
<tree type="SimpleName" label="config" pos="143" length="6"></tree>
<tree type="MethodInvocation" pos="151" length="6">
<tree type="SimpleName" label="mock" pos="151" length="4"></tree>
</tree>
</tree>
</tree>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[ {
"firstType" : "ClassInstanceCreation",
"secondType" : "ClassInstanceCreation",
"firstLabel" : "",
"secondLabel" : "",
"firstParentType" : "VariableDeclarationFragment",
"secondParentType" : "ReturnStatement",
"firstPos" : 48,
"secondPos" : 7,
"firstEndPos" : 126,
"secondEndPos" : 158
}, {
"firstType" : "SimpleName",
"secondType" : "SimpleName",
"firstLabel" : "AddMapConfigMessageTask",
"secondLabel" : "AddMapConfigMessageTask",
"firstParentType" : "SimpleType",
"secondParentType" : "SimpleType",
"firstPos" : 52,
"secondPos" : 11,
"firstEndPos" : 75,
"secondEndPos" : 34
}, {
"firstType" : "SimpleType",
"secondType" : "SimpleType",
"firstLabel" : "",
"secondLabel" : "",
"firstParentType" : "ClassInstanceCreation",
"secondParentType" : "ClassInstanceCreation",
"firstPos" : 52,
"secondPos" : 11,
"firstEndPos" : 75,
"secondEndPos" : 34
}, {
"firstType" : "SimpleName",
"secondType" : "SimpleName",
"firstLabel" : "mockConnection",
"secondLabel" : "mockConnection",
"firstParentType" : "ClassInstanceCreation",
"secondParentType" : "ClassInstanceCreation",
"firstPos" : 111,
"secondPos" : 100,
"firstEndPos" : 125,
"secondEndPos" : 114
} ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" ?>
<root>
<context></context>
<tree type="VariableDeclarationStatement" pos="0" length="127">
<tree type="SimpleType" pos="0" length="23">
<tree type="SimpleName" label="AddMapConfigMessageTask" pos="0" length="23"></tree>
</tree>
<tree type="VariableDeclarationFragment" pos="24" length="102">
<tree type="SimpleName" label="addMapConfigMessageTask" pos="24" length="23"></tree>
<tree type="ClassInstanceCreation" pos="48" length="78">
<tree type="SimpleType" pos="52" length="23">
<tree type="SimpleName" label="AddMapConfigMessageTask" pos="52" length="23"></tree>
</tree>
<tree type="SimpleName" label="addMapConfigClientMessage" pos="76" length="25"></tree>
<tree type="SimpleName" label="mockNode" pos="102" length="8"></tree>
<tree type="SimpleName" label="mockConnection" pos="111" length="14"></tree>
</tree>
</tree>
</tree>
</root>
Loading