forked from eclipse-che/che
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 8721 - Update Libraries, etc. based on JDT notifications eclips…
…e-che#8721 Added a listener for CLASSPATH change events that updates External Libraries nodes accordingly Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
- Loading branch information
Showing
10 changed files
with
308 additions
and
3 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...-ide-app/src/main/java/org/eclipse/che/ide/project/node/ExternalLibrariesUpdateEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.ide.project.node; | ||
|
||
import com.google.gwt.event.shared.EventHandler; | ||
import com.google.gwt.event.shared.GwtEvent; | ||
|
||
/** @author V. Rubezhny */ | ||
public class ExternalLibrariesUpdateEvent | ||
extends GwtEvent<ExternalLibrariesUpdateEvent.ExternalLibrariesUpdateHandler> { | ||
|
||
private String projectPath; | ||
|
||
public interface ExternalLibrariesUpdateHandler extends EventHandler { | ||
void onExternalLibrariesUpdate(ExternalLibrariesUpdateEvent event); | ||
} | ||
|
||
private static Type<ExternalLibrariesUpdateHandler> TYPE; | ||
|
||
public static Type<ExternalLibrariesUpdateHandler> getType() { | ||
if (TYPE == null) { | ||
TYPE = new Type<>(); | ||
} | ||
return TYPE; | ||
} | ||
|
||
public ExternalLibrariesUpdateEvent(String projectPath) { | ||
this.projectPath = projectPath; | ||
} | ||
|
||
public String getProject() { | ||
return projectPath; | ||
} | ||
|
||
@Override | ||
public Type<ExternalLibrariesUpdateHandler> getAssociatedType() { | ||
return TYPE; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
protected void dispatch(ExternalLibrariesUpdateHandler handler) { | ||
handler.onExternalLibrariesUpdate(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...va/org/eclipse/che/plugin/java/languageserver/ExecuteClientCommandJsonRpcTransmitter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.plugin.java.languageserver; | ||
|
||
import static org.eclipse.che.ide.ext.java.shared.Constants.EXECUTE_CLIENT_COMMAND; | ||
import static org.eclipse.che.ide.ext.java.shared.Constants.EXECUTE_CLIENT_COMMAND_SUBSCRIBE; | ||
import static org.eclipse.che.ide.ext.java.shared.Constants.EXECUTE_CLIENT_COMMAND_UNSUBSCRIBE; | ||
|
||
import java.util.Set; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CopyOnWriteArraySet; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator; | ||
import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter; | ||
import org.eclipse.che.api.core.notification.EventService; | ||
import org.eclipse.che.api.languageserver.server.dto.DtoServerImpls; | ||
import org.eclipse.che.api.languageserver.server.dto.DtoServerImpls.ExecuteCommandParamsDto; | ||
import org.eclipse.lsp4j.ExecuteCommandParams; | ||
|
||
/** Transmits 'workspace/executeClientCommand' over the JSON-RPC */ | ||
@Singleton | ||
public class ExecuteClientCommandJsonRpcTransmitter { | ||
private final Set<String> endpointIds = new CopyOnWriteArraySet<>(); | ||
|
||
private final RequestTransmitter requestTransmitter; | ||
|
||
@Inject | ||
public ExecuteClientCommandJsonRpcTransmitter(RequestTransmitter requestTransmitter) { | ||
this.requestTransmitter = requestTransmitter; | ||
} | ||
|
||
@Inject | ||
private void subscribe(EventService eventService, RequestTransmitter requestTransmitter) { | ||
eventService.subscribe( | ||
event -> | ||
endpointIds.forEach( | ||
endpointId -> | ||
requestTransmitter | ||
.newRequest() | ||
.endpointId(endpointId) | ||
.methodName(EXECUTE_CLIENT_COMMAND) | ||
.paramsAsDto(new ExecuteCommandParamsDto(event)) | ||
.sendAndSkipResult()), | ||
ExecuteCommandParams.class); | ||
} | ||
|
||
@Inject | ||
private void configureSubscribeHandler(RequestHandlerConfigurator requestHandler) { | ||
requestHandler | ||
.newConfiguration() | ||
.methodName(EXECUTE_CLIENT_COMMAND_SUBSCRIBE) | ||
.noParams() | ||
.noResult() | ||
.withConsumer(endpointIds::add); | ||
} | ||
|
||
@Inject | ||
private void configureUnSubscribeHandler(RequestHandlerConfigurator requestHandler) { | ||
requestHandler | ||
.newConfiguration() | ||
.methodName(EXECUTE_CLIENT_COMMAND_UNSUBSCRIBE) | ||
.noParams() | ||
.noResult() | ||
.withConsumer(endpointIds::remove); | ||
} | ||
|
||
public CompletableFuture<Object> executeClientCommand(ExecuteCommandParams requestParams) { | ||
ExecuteCommandParamsDto paramsDto = | ||
(ExecuteCommandParamsDto) DtoServerImpls.makeDto(requestParams); | ||
|
||
CompletableFuture<Object> result = new CompletableFuture<>(); | ||
for (String endpointId : endpointIds) { | ||
requestTransmitter | ||
.newRequest() | ||
.endpointId(endpointId) | ||
.methodName(EXECUTE_CLIENT_COMMAND) | ||
.paramsAsDto(paramsDto) | ||
.sendAndSkipResult(); | ||
} | ||
result.complete(null); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...java/org/eclipse/che/plugin/languageserver/ide/service/ExecuteClientCommandProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.plugin.languageserver.ide.service; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
import com.google.web.bindery.event.shared.EventBus; | ||
import org.eclipse.che.ide.project.node.ExternalLibrariesUpdateEvent; | ||
import org.eclipse.lsp4j.ExecuteCommandParams; | ||
|
||
/** | ||
* A processor for incoming <code>workspace/ClasspathChanged</code> notifications sent by a language | ||
* server. | ||
* | ||
* @author V. Rubezhny | ||
*/ | ||
@Singleton | ||
public class ExecuteClientCommandProcessor { | ||
public static final String FILE_PROJECTS = "file:///projects"; | ||
private static final String CLIENT_UPDATE_PROJECTS_CLASSPATH = | ||
"che.jdt.ls.extension.workspace.clientUpdateProjectsClasspath"; | ||
|
||
private EventBus eventBus; | ||
|
||
@Inject | ||
public ExecuteClientCommandProcessor(EventBus eventBus) { | ||
this.eventBus = eventBus; | ||
} | ||
|
||
public void execute(ExecuteCommandParams params) { | ||
if (CLIENT_UPDATE_PROJECTS_CLASSPATH.equals(params.getCommand())) { | ||
for (Object project : params.getArguments()) { | ||
eventBus.fireEvent( | ||
new ExternalLibrariesUpdateEvent(removePrefixUri(String.valueOf(project)))); | ||
} | ||
} | ||
} | ||
|
||
private static String removePrefixUri(String uri) { | ||
String projectPath = uri.startsWith("\"") ? uri.substring("\"".length()) : uri; | ||
projectPath = | ||
projectPath.endsWith("\"") | ||
? projectPath.substring(0, projectPath.length() - "\"".length()) | ||
: projectPath; | ||
|
||
projectPath = | ||
projectPath.startsWith(FILE_PROJECTS) ? projectPath.substring(FILE_PROJECTS.length()) : uri; | ||
return projectPath; | ||
} | ||
} |
Oops, something went wrong.