-
Notifications
You must be signed in to change notification settings - Fork 17
Introduce a new resource to fetch all resources belonging to a project #535
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -407,6 +407,11 @@ public Map<String, ResourceResponse> getDependentResourcesMap() { | |||||||||||||||||||||||||||||||
| return dependentResourcesMap; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| public Map<String, ResourceResponse> getAllResources(String projectPath) { | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return new HashMap<>(); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+410
to
+413
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log Improvement Suggestion No: 3
Suggested change
Comment on lines
+410
to
+413
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid an empty default implementation for Returning an empty map here can silently produce incorrect results when a finder does not override this method. Use Suggested fix public Map<String, ResourceResponse> getAllResources(String projectPath) {
-
- return new HashMap<>();
+ return findAllResources(projectPath);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| private String getFullyQualifiedName(OverviewPageDetailsResponse pomDetailsResponse, Resource resource) { | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // For DataServices and proxy services, the name remains unchanged as by default MI server won't expose versioned services | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -140,6 +140,25 @@ private void filterResourcesForUnitTestRegistry(List<Resource> resourcesInRegist | |||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Returns all resources in the project, including artifacts, local entries, and registry | ||||||||||||||||||||
| * resources from both the main project and resolved dependent projects. | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * @param projectPath the root directory of the project | ||||||||||||||||||||
| * @return a map where the key is the resource type and the value is the corresponding ResourceResponse | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| @Override | ||||||||||||||||||||
| public Map<String, ResourceResponse> getAllResources(String projectPath) { | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Map<String, ResourceResponse> allResources = findAllResources(projectPath); | ||||||||||||||||||||
|
Comment on lines
+150
to
+153
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log Improvement Suggestion No: 4
Suggested change
|
||||||||||||||||||||
| Map<String, ResourceResponse> dependentResources = getDependentResourcesMap(); | ||||||||||||||||||||
| for (Map.Entry<String, ResourceResponse> entry : dependentResources.entrySet()) { | ||||||||||||||||||||
|
Comment on lines
+153
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log Improvement Suggestion No: 5
Suggested change
|
||||||||||||||||||||
| allResources.computeIfAbsent(entry.getKey(), k -> new ResourceResponse()); | ||||||||||||||||||||
| mergeResourceResponses(allResources.get(entry.getKey()), entry.getValue()); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| return allResources; | ||||||||||||||||||||
|
Comment on lines
+143
to
+159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This method merges Suggested fix `@Override`
public Map<String, ResourceResponse> getAllResources(String projectPath) {
-
- Map<String, ResourceResponse> allResources = findAllResources(projectPath);
- Map<String, ResourceResponse> dependentResources = getDependentResourcesMap();
- for (Map.Entry<String, ResourceResponse> entry : dependentResources.entrySet()) {
- allResources.computeIfAbsent(entry.getKey(), k -> new ResourceResponse());
- mergeResourceResponses(allResources.get(entry.getKey()), entry.getValue());
- }
- return allResources;
+ return findAllResources(projectPath);
}🤖 Prompt for AI Agents |
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @Override | ||||||||||||||||||||
| protected String getArtifactFolder(String type) { | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,7 +15,10 @@ | |||||||||
| package org.eclipse.lemminx.synapse.resource.finder; | ||||||||||
|
|
||||||||||
| import org.eclipse.lemminx.customservice.synapse.resourceFinder.AbstractResourceFinder; | ||||||||||
| import org.eclipse.lemminx.customservice.synapse.resourceFinder.NewProjectResourceFinder; | ||||||||||
| import org.eclipse.lemminx.customservice.synapse.resourceFinder.ResourceFinderFactory; | ||||||||||
| import org.eclipse.lemminx.customservice.synapse.resourceFinder.pojo.ArtifactResource; | ||||||||||
| import org.eclipse.lemminx.customservice.synapse.resourceFinder.pojo.RegistryResource; | ||||||||||
| import org.eclipse.lemminx.customservice.synapse.resourceFinder.pojo.RequestedResource; | ||||||||||
| import org.eclipse.lemminx.customservice.synapse.resourceFinder.pojo.Resource; | ||||||||||
| import org.eclipse.lemminx.customservice.synapse.resourceFinder.pojo.ResourceResponse; | ||||||||||
|
|
@@ -448,6 +451,51 @@ public void testRequestMultipleRegistryResource() { | |||||||||
| assertEqualResourceNames(expectedResourceNames, multipleResources.getRegistryResources()); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| @Test | ||||||||||
| public void testGetAllResources() { | ||||||||||
|
|
||||||||||
| TestNewProjectResourceFinder finder = new TestNewProjectResourceFinder(); | ||||||||||
|
|
||||||||||
| // Simulate a dependent project that contributes a sequence artifact and a sequence registry resource | ||||||||||
| ArtifactResource depSequence = new ArtifactResource(); | ||||||||||
| depSequence.setName("depSequence1"); | ||||||||||
| ResourceResponse depSequenceResponse = new ResourceResponse(); | ||||||||||
| depSequenceResponse.setResources(new ArrayList<>(List.of(depSequence))); | ||||||||||
|
|
||||||||||
| RegistryResource depSequenceRegistry = new RegistryResource(); | ||||||||||
| depSequenceRegistry.setName("depSequenceRegistry1"); | ||||||||||
| depSequenceResponse.setRegistryResources(new ArrayList<>(List.of(depSequenceRegistry))); | ||||||||||
| finder.addDependentResources("sequence", depSequenceResponse); | ||||||||||
|
|
||||||||||
| // Simulate a dependent project that contributes an api artifact | ||||||||||
| ArtifactResource depApi = new ArtifactResource(); | ||||||||||
| depApi.setName("depApi1"); | ||||||||||
| ResourceResponse depApiResponse = new ResourceResponse(); | ||||||||||
| depApiResponse.setResources(new ArrayList<>(List.of(depApi))); | ||||||||||
| finder.addDependentResources("api", depApiResponse); | ||||||||||
|
|
||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log Improvement Suggestion No: 6
Suggested change
|
||||||||||
| Map<String, ResourceResponse> allResources = finder.getAllResources(projectPath); | ||||||||||
|
|
||||||||||
| // api: 1 from main project + 1 from dependent project | ||||||||||
| ResourceResponse apiResources = allResources.get("api"); | ||||||||||
| assertEquals(2, apiResources.getResources().size()); | ||||||||||
| assertEqualResourceNames(new String[]{"testApi", "depApi1"}, apiResources.getResources()); | ||||||||||
|
|
||||||||||
| // sequence: 1 artifact from main + 1 from dep; 2 registry from main + 1 from dep | ||||||||||
| ResourceResponse sequenceResources = allResources.get("sequence"); | ||||||||||
| assertEquals(2, sequenceResources.getResources().size()); | ||||||||||
| assertEquals(3, sequenceResources.getRegistryResources().size()); | ||||||||||
| assertEqualResourceNames(new String[]{"testSequence1", "depSequence1"}, sequenceResources.getResources()); | ||||||||||
| assertEqualResourceNames(new String[]{"testSequence1", "testSequence2", "depSequenceRegistry1"}, | ||||||||||
| sequenceResources.getRegistryResources()); | ||||||||||
|
|
||||||||||
| // endpoint: main project resources unaffected by dependent resources | ||||||||||
| ResourceResponse endpointResources = allResources.get("endpoint"); | ||||||||||
| assertEquals(2, endpointResources.getResources().size()); | ||||||||||
| assertEquals(4, endpointResources.getRegistryResources().size()); | ||||||||||
| assertEqualResourceNames(new String[]{"testEndpoint1", "testEndpoint2"}, endpointResources.getResources()); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private void assertEqualResourceNames(String[] expectedResourceNames, List<Resource> resources) { | ||||||||||
|
|
||||||||||
| List<String> actualResourceNames = | ||||||||||
|
|
@@ -464,4 +512,11 @@ public static boolean areListsEqual(List<String> list1, List<String> list2) { | |||||||||
| Collections.sort(list2); | ||||||||||
| return list1.equals(list2); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private static class TestNewProjectResourceFinder extends NewProjectResourceFinder { | ||||||||||
|
|
||||||||||
| void addDependentResources(String type, ResourceResponse response) { | ||||||||||
| dependentResourcesMap.put(type, response); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 1