Implement multiple dependency resolution endpoint for C & Python
@@ -51,6 +51,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Timestamp;
+import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@@ -198,8 +199,10 @@ public class ResolutionApi {
}
@PostMapping(value = "/resolve_dependencies", produces = MediaType.APPLICATION_JSON_VALUE)
- ResponseEntity<String> resolveMultipleDependencies(@RequestBody List<String> mavenCoordinates) {
- var revisions = mavenCoordinates.stream().map(c -> {
+ ResponseEntity<String> resolveMultipleDependencies(@RequestBody List<String> coordinates) {
+ switch (KnowledgeBaseConnector.forge) {
+ case "mvn": {
+ var revisions = coordinates.stream().map(c -> {
var groupId = c.split(Constants.mvnCoordinateSeparator)[0];
var artifactId = c.split(Constants.mvnCoordinateSeparator)[1];
var version = c.split(Constants.mvnCoordinateSeparator)[2];
@@ -221,6 +224,26 @@ public class ResolutionApi {
result = result.replace("\\/", "/");
return new ResponseEntity<>(result, HttpStatus.OK);
}
+ default: {
+ ObjectLinkedOpenHashSet deps = new ObjectLinkedOpenHashSet<String>();
+ coordinates.forEach(c -> {
+ var packageName = c.split(Constants.mvnCoordinateSeparator)[0];
+ var packageVersion = c.split(Constants.mvnCoordinateSeparator)[1];
+ var query = "http://"+ KnowledgeBaseConnector.dependencyResolverAddress + "/dependencies/"+ packageName+"/"+packageVersion;
+ var requestResult = MavenUtilities.sendGetRequest(query);
+ var depList = new JSONArray(requestResult);
+ depList.forEach(item -> {
+ JSONObject obj = (JSONObject) item;
+ if (!deps.contains(obj.toString())) {
+ deps.add(obj.toString());
+ }
+ });
+ });
+ List<String> result = new ArrayList<String>(deps);
+ return new ResponseEntity<>(result.toString(), HttpStatus.OK);
+ }
+ }
+ }
@GetMapping(value = "/__INTERNAL__/packages/{pkg_version_id}/directedgraph", produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<String> getDirectedGraph(@PathVariable("pkg_version_id") long packageVersionId,
