Skip to content

Commit

Permalink
fully working initial IR/Delta merge
Browse files Browse the repository at this point in the history
  • Loading branch information
lukalelovic committed Mar 17, 2024
1 parent 08ed9fc commit bf12a08
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 18,145 deletions.
3,667 changes: 0 additions & 3,667 deletions out/intermediate-output-[1708549106365].json

This file was deleted.

7,221 changes: 0 additions & 7,221 deletions out/intermediate-output-[1709662488646].json

This file was deleted.

7,221 changes: 0 additions & 7,221 deletions out/intermediate-output-[1710188840120].json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private static void extractCallDestinations(Map<String, MsModel> msModelMap) {
.getRestCalls()
.forEach(
call -> {
String callUrl = call.getUrl();
String callUrl = call.getApi();
String httpMethod = call.getHttpMethod();

RestController matchingController = null;
Expand Down Expand Up @@ -191,7 +191,7 @@ private static void extractCallDestinations(Map<String, MsModel> msModelMap) {
}

if (Objects.nonNull(matchingController)) {
call.setDestFile(matchingController.getSourceFile());
call.setCallDest(matchingController.getSourceFile());
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@NoArgsConstructor
public class JavaClass {
private String className;
private String sourceFile;
private String classPath;

private List<JavaVariable> variables = new ArrayList<>();
private List<JavaMethod> methods = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.university.ecs.lab.common.models;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -11,6 +12,9 @@
@NoArgsConstructor
public class JavaMethod {
private String methodName;
private String parameter;

@SerializedName("arguments")
private String arguments;

private String returnType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
@AllArgsConstructor
@NoArgsConstructor
public class RestCall {
private String url;
private String api;
private String sourceFile;
private String destFile;
private String callDest;
private String httpMethod;
private String callMethod;
private String callClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.university.ecs.lab.common.models.rest;

import com.google.gson.annotations.SerializedName;
import edu.university.ecs.lab.common.config.InputConfig;
import edu.university.ecs.lab.common.models.JavaVariable;
import lombok.*;
Expand All @@ -19,6 +20,7 @@ public class RestController {
* The java source code file the endpoint was found in, path after {@link
* InputConfig#getClonePath()}
*/
@SerializedName("classPath")
private String sourceFile;

private List<RestEndpoint> restEndpoints = new ArrayList<>(); /* composes endpoints */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class RestDTO extends JavaClass {
public RestDTO(JavaClass javaClass) {
this.setClassName(javaClass.getClassName());
this.setSourceFile(javaClass.getSourceFile());
this.setClassPath(javaClass.getClassPath());
this.setVariables(javaClass.getVariables());
this.setMethods(javaClass.getMethods());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.university.ecs.lab.common.models.rest;

import com.google.gson.annotations.SerializedName;
import edu.university.ecs.lab.common.models.JavaMethod;
import edu.university.ecs.lab.common.models.JavaVariable;
import lombok.AllArgsConstructor;
Expand All @@ -18,17 +19,23 @@ public class RestEndpoint {
private String id;

/** URL of the endpoint including base from class: (ex: /api/v1/users/{id}) */
@SerializedName("api")
private String url;

/** JSF Mapping annotation */
@SerializedName("type")
private String decorator;

/** The HTTP method of the endpoint */
private String httpMethod;

/** The method that the endpoint is a part of as full class path a.b.c.methodName */
@SerializedName("parent-method")
private String parentMethod;

@SerializedName("method")
private JavaMethod method;

@SerializedName("method-variables")
private List<JavaVariable> methodVariables;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class RestEntity extends JavaClass {
public RestEntity(JavaClass javaClass) {
this.setClassName(javaClass.getClassName());
this.setSourceFile(javaClass.getSourceFile());
this.setClassPath(javaClass.getClassPath());
this.setVariables(javaClass.getVariables());
this.setMethods(javaClass.getMethods());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class RestRepository extends JavaClass {
public RestRepository(JavaClass javaClass) {
this.setClassName(javaClass.getClassName());
this.setSourceFile(javaClass.getSourceFile());
this.setClassPath(javaClass.getClassPath());
this.setVariables(javaClass.getVariables());
this.setMethods(javaClass.getMethods());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class RestService extends JavaClass {
public RestService(JavaClass javaClass) {
this.setClassName(javaClass.getClassName());
this.setSourceFile(javaClass.getSourceFile());
this.setClassPath(javaClass.getClassPath());
this.setVariables(javaClass.getVariables());
this.setMethods(javaClass.getMethods());
}
Expand Down
37 changes: 22 additions & 15 deletions src/main/java/edu/university/ecs/lab/common/utils/MsFileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ public static JsonObject constructJsonMsSystem(
JsonObjectBuilder msObjectBuilder = Json.createObjectBuilder();
String msName = microservice.getKey();

if (microservice.getKey().contains(File.separator)) {
if (microservice.getKey().contains("\\")) {
msName =
microservice.getKey().substring(microservice.getKey().lastIndexOf(File.separator) + 1);
microservice.getKey().substring(microservice.getKey().lastIndexOf("\\") + 1);
} else if (microservice.getKey().contains("/")) {
msName =
microservice.getKey().substring(microservice.getKey().lastIndexOf("/") + 1);
}

msObjectBuilder.add("id", microservice.getValue().getId().replaceAll("\\\\", "/"));
msObjectBuilder.add("msName", msName);
msObjectBuilder.add("msPath", microservice.getKey().replaceAll("\\\\", "/"));
//msObjectBuilder.add("msPath", microservice.getKey().replaceAll("\\\\", "/"));
msObjectBuilder.add("commitId", microservice.getValue().getCommit());

msObjectBuilder.add(
Expand Down Expand Up @@ -99,7 +102,7 @@ public static JsonArray buildRestControllers(
+ "."
+ restEndpoint.getMethod().getMethodName()
+ "#"
+ Math.abs(restEndpoint.getMethod().getParameter().hashCode()));
+ Math.abs(restEndpoint.getMethod().getArguments().hashCode()));

JsonObjectBuilder endpointBuilder = Json.createObjectBuilder();

Expand All @@ -108,12 +111,16 @@ public static JsonArray buildRestControllers(
endpointBuilder.add("type", restEndpoint.getDecorator());
endpointBuilder.add("httpMethod", restEndpoint.getHttpMethod());
endpointBuilder.add("parent-method", restEndpoint.getParentMethod());
endpointBuilder.add("methodName", restEndpoint.getMethod().getMethodName());
endpointBuilder.add("arguments", restEndpoint.getMethod().getParameter());
endpointBuilder.add("return", restEndpoint.getMethod().getReturnType());
endpointBuilder.add(
"method-variables", addVariableArray(restEndpoint.getMethodVariables()));

JsonObjectBuilder methodBuilder = Json.createObjectBuilder();
methodBuilder.add("methodName", restEndpoint.getMethod().getMethodName());
methodBuilder.add("arguments", restEndpoint.getMethod().getArguments());
methodBuilder.add("returnType", restEndpoint.getMethod().getReturnType());

endpointBuilder.add("method", methodBuilder.build());

endpointArrayBuilder.add(endpointBuilder.build());
}

Expand All @@ -136,7 +143,7 @@ public static JsonArray buildRestServices(List<RestService> restServices) {
for (RestService restService : restServices) {
JsonObjectBuilder serviceBuilder = Json.createObjectBuilder();
serviceBuilder.add("className", restService.getClassName());
serviceBuilder.add("classPath", restService.getSourceFile().replaceAll("\\\\", "/"));
serviceBuilder.add("classPath", restService.getClassPath().replaceAll("\\\\", "/"));

// write service methods
serviceBuilder.add("methods", addMethodArray(restService.getMethods()));
Expand All @@ -162,7 +169,7 @@ public static JsonArray buildJavaClass(List<? extends JavaClass> classList) {
for (JavaClass javaClass : classList) {
JsonObjectBuilder dtoBuilder = Json.createObjectBuilder();
dtoBuilder.add("className", javaClass.getClassName());
dtoBuilder.add("classPath", javaClass.getSourceFile().replaceAll("\\\\", "/"));
dtoBuilder.add("classPath", javaClass.getClassPath().replaceAll("\\\\", "/"));

dtoBuilder.add("variables", addVariableArray(javaClass.getVariables()));
dtoBuilder.add("methods", addMethodArray(javaClass.getMethods()));
Expand All @@ -185,11 +192,11 @@ public static JsonArray buildRestCalls(List<RestCall> restCalls) {
for (RestCall restCall : restCalls) {
JsonObjectBuilder restCallBuilder = Json.createObjectBuilder();

restCallBuilder.add("api", restCall.getUrl());
restCallBuilder.add("source-file", restCall.getSourceFile().replaceAll("\\\\", "/"));
restCallBuilder.add("call-dest", restCall.getDestFile().replaceAll("\\\\", "/"));
restCallBuilder.add("call-method", restCall.getCallMethod() + "()");
restCallBuilder.add("call-class", restCall.getCallClass());
restCallBuilder.add("api", restCall.getApi());
restCallBuilder.add("sourceFile", restCall.getSourceFile().replaceAll("\\\\", "/"));
restCallBuilder.add("callDest", restCall.getCallDest().replaceAll("\\\\", "/"));
restCallBuilder.add("callMethod", restCall.getCallMethod() + "()");
restCallBuilder.add("callClass", restCall.getCallClass());
restCallBuilder.add("httpMethod", restCall.getHttpMethod());

endpointsArrayBuilder.add(restCallBuilder.build());
Expand All @@ -205,7 +212,7 @@ public static JsonArray addMethodArray(List<JavaMethod> methodList) {
JsonObjectBuilder methodObjectBuilder = Json.createObjectBuilder();

methodObjectBuilder.add("methodName", method.getMethodName());
methodObjectBuilder.add("parameter", method.getParameter());
methodObjectBuilder.add("arguments", method.getArguments());
methodObjectBuilder.add("returnType", method.getReturnType());

methodArrayBuilder.add(methodObjectBuilder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public void processDifferences(String path, Repository repo, List<DiffEntry> dif
// String changeURL = gitFetchUtils.getGithubFileUrl(repo, entry);
System.out.println("Extracting changes from: " + path);

String localPath = path + "/" + entry.getOldPath();
String oldPath = path + "/" + entry.getOldPath();
String newPath = path + "/" + entry.getNewPath();

javax.json.JsonObject deltaChanges;

Expand All @@ -82,7 +83,7 @@ public void processDifferences(String path, Repository repo, List<DiffEntry> dif
// String fileContents = gitFetchUtils.fetchAndDecodeFile(changeURL);

// compare differences with local path
deltaChanges = comparisonUtils.extractDeltaChanges(localPath);
deltaChanges = comparisonUtils.extractDeltaChanges(oldPath);

// no changes found (likely an extra tail line not shown remotely)
if (deltaChanges.isEmpty()) {
Expand All @@ -103,7 +104,7 @@ public void processDifferences(String path, Repository repo, List<DiffEntry> dif
"Change impact of type " + entry.getChangeType() + " detected in " + entry.getNewPath());

JsonObjectBuilder jout = Json.createObjectBuilder();
jout.add("localPath", localPath);
jout.add("localPath", newPath);
jout.add("changeType", entry.getChangeType().name());
jout.add("changes", deltaChanges);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ public static void main(String[] args) throws IOException {
switch (delta.getChangeType()) {
case "ADD":
MsModel addModel = mergeService.extractNewModel(localPath);

if (addModel == null) {
continue;
}

addModel.setId(localPath.substring(localPath.lastIndexOf('/') + 1));
addModel.setCommit(""); // TODO

msModelMap.put(localPath, addModel);
break;
case "DELETE":
Expand All @@ -49,12 +53,16 @@ public static void main(String[] args) throws IOException {
break;
case "MODIFY":
MsModel changeModel = mergeService.extractNewModel(localPath);

if (changeModel == null) {
// TODO: same remove logic?
// TODO: remove logic?
msModelMap.remove(localPath);
continue;
}

changeModel.setId(localPath.substring(localPath.lastIndexOf('/') + 1));
changeModel.setCommit(""); // TODO

msModelMap.put(localPath, changeModel);
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private static void extractCallDestinations(Map<String, MsModel> msModelMap) {
.getRestCalls()
.forEach(
call -> {
String callUrl = call.getUrl();
String callUrl = call.getApi();
String httpMethod = call.getHttpMethod();

RestController matchingController = null;
Expand Down Expand Up @@ -199,7 +199,7 @@ private static void extractCallDestinations(Map<String, MsModel> msModelMap) {
}

if (Objects.nonNull(matchingController)) {
call.setDestFile(matchingController.getSourceFile());
call.setCallDest(matchingController.getSourceFile());
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ public static List<RestCall> parseCalls(File sourceFile) throws IOException {
}

// find url
restCall.setUrl(findUrl(mce, cid));
restCall.setApi(findUrl(mce, cid));

// skip empty urls
if (restCall.getUrl().equals("")) {
if (restCall.getApi().equals("")) {
continue;
}

restCall.setDestFile("");
restCall.setCallDest("");

// add to list of restCall
dependencies.add(restCall);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static JavaMethod extractJavaMethod(MethodDeclaration md) {

JavaMethod method = new JavaMethod();
method.setMethodName(methodName);
method.setParameter(parameter.toString());
method.setArguments(parameter.toString());
method.setReturnType(md.getTypeAsString());

return method;
Expand All @@ -51,7 +51,7 @@ public static JavaClass extractJavaClass(File sourceFile, ClassOrInterfaceDeclar
JavaClass javaClass = new JavaClass();

javaClass.setClassName(cid.getNameAsString());
javaClass.setSourceFile(sourceFile.getCanonicalPath());
javaClass.setClassPath(sourceFile.getCanonicalPath());
javaClass.setVariables(extractVariables(cid));
javaClass.setMethods(extractMethods(cid));

Expand Down

0 comments on commit bf12a08

Please sign in to comment.