|
19 | 19 | import java.io.OutputStream; |
20 | 20 | import java.nio.file.Files; |
21 | 21 | import java.nio.file.Paths; |
| 22 | +import java.util.ArrayList; |
22 | 23 | import java.util.Arrays; |
23 | 24 | import java.util.List; |
24 | 25 |
|
25 | 26 | import org.apache.commons.io.IOUtils; |
| 27 | +import org.eclipse.core.resources.IMarker; |
| 28 | +import org.eclipse.core.resources.IProject; |
| 29 | +import org.eclipse.core.resources.IResource; |
| 30 | +import org.eclipse.core.resources.IWorkspaceRoot; |
| 31 | +import org.eclipse.core.resources.ResourcesPlugin; |
| 32 | +import org.eclipse.core.runtime.CoreException; |
26 | 33 | import org.eclipse.core.runtime.FileLocator; |
27 | 34 | import org.eclipse.core.runtime.NullProgressMonitor; |
28 | 35 | import org.eclipse.core.runtime.Platform; |
|
43 | 50 | public class Fabric8AnalyticsStreamConnectionProvider extends ProcessStreamConnectionProvider |
44 | 51 | implements StreamConnectionProvider { |
45 | 52 |
|
| 53 | + public static final String SERVER_ID = "com.redhat.fabric8analytics.lsp.eclipse.server"; |
| 54 | + |
| 55 | + private static final String LSP_SERVER_ID_ATTRIBUTE = "languageServerId"; |
| 56 | + |
46 | 57 | public static final String RECOMMENDER_API_TOKEN = "RECOMMENDER_API_TOKEN"; |
47 | 58 |
|
48 | 59 | public static final String RECOMMENDER_API_URL = "RECOMMENDER_API_URL"; |
@@ -104,8 +115,32 @@ public void start() throws IOException { |
104 | 115 | @Override |
105 | 116 | public void stop() { |
106 | 117 | super.stop(); |
| 118 | + removeMarkers(); |
107 | 119 | Fabric8AnalysisLSUIActivator.getDefault().logInfo("The Fabric8 analyses server is stopped"); |
108 | 120 | } |
| 121 | + |
| 122 | + private void removeMarkers() { |
| 123 | + IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); |
| 124 | + IProject[] projects = workspaceRoot.getProjects(); |
| 125 | + for (IProject project : projects) { |
| 126 | + try { |
| 127 | + List<IMarker> markersToDelete = new ArrayList<>(); |
| 128 | + IMarker[] markers = project.findMarkers(null, true, IResource.DEPTH_INFINITE); |
| 129 | + for (IMarker marker : markers) { |
| 130 | + if (marker.exists()) { |
| 131 | + Object serverId = marker.getAttribute(LSP_SERVER_ID_ATTRIBUTE); |
| 132 | + if (SERVER_ID.equals(serverId)) { |
| 133 | + markersToDelete.add(marker); |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + ResourcesPlugin.getWorkspace() |
| 138 | + .deleteMarkers(markersToDelete.toArray(new IMarker[markersToDelete.size()])); |
| 139 | + } catch (CoreException e) { |
| 140 | + Fabric8AnalysisLSUIActivator.getDefault().logError("Error occured while removing LSP markers", e); |
| 141 | + } |
| 142 | + } |
| 143 | + } |
109 | 144 |
|
110 | 145 | @Override |
111 | 146 | protected ProcessBuilder createProcessBuilder() { |
|
0 commit comments