Skip to content

Commit f4ad19a

Browse files
Clean up the resources generated by HCR provider (#300)
* Clean up the resources generated by HCR provider Signed-off-by: Jinbo Wang <[email protected]> * Fix launch.json project name Signed-off-by: Jinbo Wang <[email protected]> * clean up hcr provider in noDebug mode Signed-off-by: Jinbo Wang <[email protected]>
1 parent c90a238 commit f4ad19a

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"sourcePaths": [
1515
"${workspaceRoot}/com.microsoft.java.debug.core/main/java",
1616
"${workspaceRoot}/com.microsoft.java.debug.plugin/src/main/java"
17-
]
17+
],
18+
"projectName": "com.microsoft.java.debug.plugin"
1819
}
1920
]
2021
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/IProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ public interface IProvider {
2424
*/
2525
default void initialize(IDebugAdapterContext debugContext, Map<String, Object> options) {
2626
}
27+
28+
/**
29+
* Close the provider and free all associated resources.
30+
*/
31+
default void close() {
32+
}
2733
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/AbstractDisconnectRequestHandler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.microsoft.java.debug.core.Configuration;
2424
import com.microsoft.java.debug.core.adapter.IDebugAdapterContext;
2525
import com.microsoft.java.debug.core.adapter.IDebugRequestHandler;
26+
import com.microsoft.java.debug.core.adapter.IHotCodeReplaceProvider;
2627
import com.microsoft.java.debug.core.adapter.LaunchMode;
2728
import com.microsoft.java.debug.core.protocol.Messages.Response;
2829
import com.microsoft.java.debug.core.protocol.Requests.Arguments;
@@ -50,6 +51,7 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
5051
* @param context the debug context
5152
*/
5253
private void destroyResource(IDebugAdapterContext context) {
54+
destroyProviders(context);
5355
if (shouldDestroyLaunchFiles(context)) {
5456
destroyLaunchFiles(context);
5557
}
@@ -97,4 +99,11 @@ private void destroyLaunchFiles(IDebugAdapterContext context) {
9799
}
98100

99101
protected abstract void destroyDebugSession(Command command, Arguments arguments, Response response, IDebugAdapterContext context);
102+
103+
protected void destroyProviders(IDebugAdapterContext context) {
104+
IHotCodeReplaceProvider hcrProvider = context.getProvider(IHotCodeReplaceProvider.class);
105+
if (hcrProvider != null) {
106+
hcrProvider.close();
107+
}
108+
}
100109
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/DisconnectRequestHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ public void destroyDebugSession(Command command, Arguments arguments, Response r
3232
}
3333
}
3434
}
35-
3635
}

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaHotCodeReplaceProvider.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,16 @@ public void initialize(IDebugAdapterContext context, Map<String, Object> options
265265
}
266266
this.context = context;
267267
currentDebugSession = context.getDebugSession();
268+
}
269+
270+
@Override
271+
public void close() {
272+
if (DebugSettings.getCurrent().hotCodeReplace != DebugSettings.HotCodeReplace.NEVER) {
273+
// Remove the listener.
274+
ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
275+
}
268276

269-
// TODO: Change IProvider interface for shutdown event
277+
eventSubject.onComplete();
270278
}
271279

272280
@Override

0 commit comments

Comments
 (0)