Skip to content

Commit

Permalink
remove unnecessary code and add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan-Thurner committed Aug 13, 2024
1 parent 4157768 commit 01748c4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,29 @@
import com.fasterxml.jackson.databind.ObjectMapper;

public class EndpointAnalyzer {
private static String EndpointAnalysisResultPath = "endpointAnalysisResult.json";

public static void main(String[] args) {
System.out.println("working directory: " + System.getProperty("user.dir"));
analyzeEndpoints();
printEndpointAnalysisResult();
}

/**
* Analyzes endpoints and matches them with REST calls.
*
* This method reads endpoint and REST call information from JSON files,
* compares them to find matching REST calls for each endpoint, and writes
* the analysis result to a JSON file. Endpoints without matching REST calls
* are also recorded.
*/
private static void analyzeEndpoints() {
final String endpointsJsonPath = "endpoints.json";
ObjectMapper mapper = new ObjectMapper();

try {
List<EndpointClassInformation> endpointClasses = mapper.readValue(new File(endpointsJsonPath),
List<EndpointClassInformation> endpointClasses = mapper.readValue(new File(EndpointParser.EndpointParsingResultPath),
new TypeReference<List<EndpointClassInformation>>() {
});
List<RestCallFileInformation> restCallFiles = mapper.readValue(new File("restCalls.json"),
List<RestCallFileInformation> restCallFiles = mapper.readValue(new File(EndpointParser.RestCallParsingResultPath),
new TypeReference<List<RestCallFileInformation>>() {
});

Expand Down Expand Up @@ -57,21 +64,26 @@ private static void analyzeEndpoints() {
}

EndpointAnalysis endpointAnalysis = new EndpointAnalysis(endpointsAndMatchingRestCalls, unusedEndpoints);
System.out.println("working directory: " + System.getProperty("user.dir"));
mapper.writeValue(new File("endpointAnalysisResult.json"), endpointAnalysis);
System.out.println("Endpoint analysis result written to file: endpointAnalysisResult.json");
mapper.writeValue(new File(EndpointAnalysisResultPath), endpointAnalysis);
}
catch (IOException e) {
e.printStackTrace();
}
}

/**
* Prints the endpoint analysis result.
*
* This method reads the endpoint analysis result from a JSON file and prints
* the details of unused endpoints to the console. The details include the
* endpoint URI, HTTP method, file path, and line number. If no matching REST
* call is found for an endpoint, it prints a message indicating this.
*/
private static void printEndpointAnalysisResult() {
ObjectMapper mapper = new ObjectMapper();
EndpointAnalysis endpointsAndMatchingRestCalls = null;
try {
System.out.println("trying to read file: endpointAnalysisResult.json");
endpointsAndMatchingRestCalls = mapper.readValue(new File("endpointAnalysisResult.json"),
endpointsAndMatchingRestCalls = mapper.readValue(new File(EndpointAnalysisResultPath),
new TypeReference<EndpointAnalysis>() {
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

public class EndpointParser {

static String EndpointParsingResultPath = "endpoints.json";
static String RestCallParsingResultPath = "restCalls.json";

public static void main(String[] args) {
final String relativeDirectoryPath = ".." + File.separator + ".." + File.separator + "src" + File.separator + "main" + File.separator + "java";
final Path absoluteDirectoryPath = Paths.get(relativeDirectoryPath).toAbsolutePath().normalize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,29 @@

public class RestCallAnalyzer {

private static String RestCallAnalysisResultPath = "restCallAnalysisResult.json";

public static void main(String[] args) {
analyzeRestCalls();
printRestCallAnalysisResult();
}

/**
* Analyzes REST calls and matches them with endpoints.
*
* This method reads endpoint and REST call information from JSON files,
* compares them to find matching endpoints for each REST call, and writes
* the analysis result to a JSON file. REST calls without matching endpoints
* are also recorded.
*/
private static void analyzeRestCalls() {
ObjectMapper mapper = new ObjectMapper();

try {
List<EndpointClassInformation> endpointClasses = mapper.readValue(new File("endpoints.json"),
List<EndpointClassInformation> endpointClasses = mapper.readValue(new File(EndpointParser.EndpointParsingResultPath),
new TypeReference<List<EndpointClassInformation>>() {
});
List<RestCallFileInformation> restCalls = mapper.readValue(new File("restCalls.json"),
List<RestCallFileInformation> restCalls = mapper.readValue(new File(EndpointParser.RestCallParsingResultPath),
new TypeReference<List<RestCallFileInformation>>() {
});

Expand Down Expand Up @@ -54,20 +64,28 @@ private static void analyzeRestCalls() {
}
}
RestCallAnalysis restCallAnalysis = new RestCallAnalysis(restCallsWithMatchingEndpoint, restCallsWithoutMatchingEndpoint);
mapper.writeValue(new File("restCallAnalysisResult.json"), restCallAnalysis);
mapper.writeValue(new File(RestCallAnalysisResultPath), restCallAnalysis);
}
catch (IOException e) {
e.printStackTrace();
}
}

/**
* Prints the endpoint analysis result.
*
* This method reads the endpoint analysis result from a JSON file and prints
* the details of unused endpoints to the console. The details include the
* endpoint URI, HTTP method, file path, and line number. If no matching REST
* call is found for an endpoint, it prints a message indicating this.
*/
private static void printRestCallAnalysisResult() {
ObjectMapper mapper = new ObjectMapper();

RestCallAnalysis restCallsAndMatchingEndpoints = null;

try {
restCallsAndMatchingEndpoints = mapper.readValue(new File("restCallAnalysisResult.json"),
restCallsAndMatchingEndpoints = mapper.readValue(new File(RestCallAnalysisResultPath),
new TypeReference<RestCallAnalysis>() {
});
}
Expand Down

0 comments on commit 01748c4

Please sign in to comment.